:root {
  color-scheme: light;
  --paper: #f3eee4;
  --ink: #2e2925;
  --muted: #8d8378;
  --line: rgba(46, 41, 37, 0.16);
  --accent: #a53f35;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(255,255,255,.7), transparent 28%),
    linear-gradient(135deg, rgba(111,87,62,.035) 25%, transparent 25%) 0 0 / 5px 5px,
    var(--paper);
  font-family: "Manrope", sans-serif;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .28;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.92' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.08'/%3E%3C/svg%3E");
}

button { font: inherit; }

.reader {
  position: relative;
  width: min(100%, 520px);
  height: 100svh;
  min-height: 540px;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 28px max(22px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
}

.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: .66rem;
  letter-spacing: .19em;
}

.page-number { font-variant-numeric: tabular-nums; letter-spacing: .1em; }

.pages { position: relative; min-height: 0; touch-action: pan-y; }

.page {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  visibility: hidden;
  opacity: 0;
  transform: translateX(22px);
  transition: opacity .42s ease, transform .42s ease, visibility .42s;
}

.page p {
  width: 100%;
  margin: 0;
  font-family: "GFS Didot", Georgia, serif;
  font-size: clamp(2.15rem, 10vw, 3.65rem);
  line-height: 1.12;
  letter-spacing: -.025em;
}

.page.is-active { visibility: visible; opacity: 1; transform: translateX(0); }
.page.was-active { transform: translateX(-22px); }
.signature p { color: var(--accent); font-style: italic; }
.heart { position: absolute; right: 4px; bottom: 8%; color: var(--accent); font-size: 3.2rem; transform: rotate(-8deg); }

.controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.controls button {
  border: 0;
  cursor: pointer;
  height: 52px;
  transition: opacity .2s, transform .2s, background .2s;
}

.controls button:active { transform: scale(.97); }
.controls button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.nav-button {
  width: 52px;
  border: 1px solid var(--line) !important;
  border-radius: 50%;
  color: var(--ink);
  background: transparent;
}

.nav-button:disabled { opacity: .2; cursor: default; }

.next {
  min-width: 152px;
  padding: 0 21px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 25px;
  border-radius: 99px;
  background: var(--ink);
  color: var(--paper);
  font-size: .78rem;
  letter-spacing: .04em;
}

.next.is-finished { background: var(--accent); }

.progress { height: 1px; margin-top: 22px; background: var(--line); }
.progress span { display: block; width: 8.33%; height: 100%; background: var(--accent); transition: width .42s ease; }

.swipe-hint {
  margin: 12px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: .61rem;
  letter-spacing: .04em;
  transition: opacity .3s;
}

.swipe-hint.is-hidden { opacity: 0; }

@media (min-width: 700px) {
  body { display: grid; place-items: center; padding: 24px; }
  .reader { height: min(840px, calc(100svh - 48px)); border: 1px solid var(--line); box-shadow: 0 26px 70px rgba(46,41,37,.12); padding-inline: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .page, .progress span, .controls button { transition: none; }
}
