/* ==========================================================================
   A Letter for You — site styles
   One stylesheet for every page. Sections:
   1. Tokens   2. Base   3. Forest backdrop   4. Top bar   5. Paper
   6. Type     7. Buttons & links   8. Chapter tracker   9. Home / envelope
   10. Question page   11. Quotes   12. Poetry   13. Motion   14. Utilities
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  --forest-950: #07100b;
  --forest-900: #0d1a12;
  --forest-700: #1f3527;
  --moss: #5d7a4f;
  --gold: #c9a15b;
  --gold-soft: #e7cf9c;
  --wax: #8f2430;
  --wax-deep: #5e1219;

  --paper: #f7f0e1;
  --paper-edge: #e9dcc2;
  --paper-shade: rgba(92, 64, 30, .10);
  --ink: #2c221b;
  --ink-soft: #5c4a3c;
  --ink-faint: #8d7865;
  --rule: rgba(92, 64, 30, .22);
  --accent: #8f2430;

  --glass: rgba(10, 20, 14, .55);
  --glass-line: rgba(231, 207, 156, .22);
  --on-dark: #f3e9d4;
  --on-dark-soft: rgba(243, 233, 212, .72);

  --serif-display: "Cormorant Garamond", "Cormorant", "Lora", Georgia, "Times New Roman", serif;
  --serif-body: "Lora", Georgia, "Times New Roman", serif;
  --ui: "Lora", Georgia, serif;

  --radius: 6px;
  --shadow-paper: 0 1px 0 rgba(255,255,255,.6) inset, 0 30px 60px -20px rgba(0,0,0,.55), 0 12px 24px -12px rgba(0,0,0,.4);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-soft: cubic-bezier(.4, 0, .2, 1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #231d16;
    --paper-edge: #2e261d;
    --paper-shade: rgba(0, 0, 0, .25);
    --ink: #efe3cb;
    --ink-soft: #cdbb9d;
    --ink-faint: #9c8a70;
    --rule: rgba(231, 207, 156, .18);
    --accent: #e39a8f;
    --shadow-paper: 0 30px 60px -20px rgba(0,0,0,.8), 0 12px 24px -12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}

/* 2. Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  background: var(--forest-950);
  color: var(--on-dark);
  font-family: var(--serif-body);
  font-size: clamp(1.02rem, .96rem + .3vw, 1.14rem);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
img, svg, canvas { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
a { color: inherit; }
::selection { background: rgba(201, 161, 91, .35); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 4px; }

.skip-link {
  position: absolute; left: 1rem; top: -3rem; z-index: 100;
  background: var(--paper); color: var(--ink); padding: .5rem .9rem; border-radius: var(--radius);
  text-decoration: none; transition: top .2s;
}
.skip-link:focus { top: 1rem; }

/* 3. Living forest --------------------------------------------------------- */
/* Layers, back to front: photo (+ night sky through the canopy gaps), light
   rays, mist, foreground trees, colour grade. JS feeds --px/--py (-1..1) from
   the mouse or phone tilt; html[data-time] picks dawn / day / dusk / night. */
.scene {
  --px: 0; --py: 0;
  position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
  background: var(--forest-900);
}
.scene__layer { position: absolute; will-change: transform; }
.scene__far {
  inset: -5%;
  transform: translate3d(calc(var(--px) * -14px), calc(var(--py) * -8px), 0) scale(1.02);
  transition: filter .8s var(--ease-soft);
}
.scene__photo, .scene__sky {
  position: absolute; inset: 0;
  animation: drift 50s var(--ease-soft) infinite alternate;
}
.scene__photo {
  background-image: url("../img/forest-1100.webp");
  background-image: image-set(url("../img/forest-1100.webp") 1x, url("../img/forest-1920.webp") 2x);
  background-size: cover; background-position: 50% 60%;
  filter: var(--photo-filter, saturate(.85) brightness(.62));
  transition: filter 1.2s var(--ease-soft);
}
@media (min-width: 1100px) { .scene__photo { background-image: url("../img/forest-1920.webp"); } }
/* Night sky, visible only where the canopy opens (mask made from the photo) */
.scene__sky {
  opacity: 0; transition: opacity 1.2s var(--ease-soft);
  background: linear-gradient(to bottom, #0a1633, #14254a 60%, #1d2f55);
  -webkit-mask: url("../img/sky-mask.webp") 50% 60% / cover no-repeat;
  mask: url("../img/sky-mask.webp") 50% 60% / cover no-repeat;
}
.scene__stars { position: absolute; inset: 0; width: 100%; height: 100%; }
.scene__moon {
  position: absolute; left: 36%; top: 9%; width: 70px; height: 70px; border-radius: 50%;
  background: radial-gradient(circle at 42% 40%, #fffdf2, #f1e6c6 55%, #d8c99f 100%);
  box-shadow: 0 0 40px 10px rgba(255,248,220,.45), 0 0 140px 40px rgba(190,210,255,.25);
}
.scene__rays {
  position: absolute; inset: -20% -10% 10% -10%;
  background:
    repeating-linear-gradient(105deg, transparent 0 60px, var(--ray, rgba(255,232,170,.10)) 90px, transparent 140px, transparent 190px, var(--ray, rgba(255,232,170,.10)) 205px, transparent 240px);
  -webkit-mask: radial-gradient(70% 80% at 36% 0%, #000 0%, rgba(0,0,0,.5) 45%, transparent 75%);
  mask: radial-gradient(70% 80% at 36% 0%, #000 0%, rgba(0,0,0,.5) 45%, transparent 75%);
  filter: blur(10px);
  mix-blend-mode: screen;
  opacity: var(--rays, .8);
  transform: translate3d(calc(var(--px) * -24px), 0, 0) skewX(-6deg);
  animation: shimmer 9s ease-in-out infinite alternate;
  transition: opacity 1.2s var(--ease-soft);
}
.scene__mist {
  position: absolute; left: -30%; right: -30%; height: 42%;
  background:
    radial-gradient(40% 50% at 25% 60%, var(--mist, rgba(210,225,210,.16)), transparent 70%),
    radial-gradient(35% 45% at 70% 50%, var(--mist, rgba(210,225,210,.16)), transparent 70%);
  filter: blur(20px);
  opacity: var(--mist-o, .8);
  transition: opacity 1.2s var(--ease-soft);
}
.scene__mist--a { bottom: 6%; animation: mist 70s linear infinite alternate; transform: translate3d(calc(var(--px) * -30px), 0, 0); }
.scene__mist--b { bottom: -4%; animation: mist 55s linear infinite alternate-reverse; opacity: calc(var(--mist-o, .8) * .8); }
.scene__near {
  inset: -7% -9% -4%;
  background: url("../img/foreground.svg") 50% 100% / cover no-repeat;
  filter: blur(1.6px) brightness(var(--near-b, 1));
  transform: translate3d(calc(var(--px) * -46px), calc(var(--py) * -14px), 0);
}
.scene__grade {
  position: absolute; inset: 0;
  background:
    var(--grade, linear-gradient(transparent, transparent)),
    radial-gradient(120% 80% at 50% 110%, var(--ground-glow, rgba(201,161,91,.16)), transparent 55%),
    radial-gradient(90% 70% at 50% 40%, transparent 30%, rgba(4,10,6,.72) 100%),
    linear-gradient(to bottom, rgba(7,16,11,.3), rgba(7,16,11,.1) 40%, rgba(7,16,11,.65));
}
.scene__grade::after {
  content: ""; position: absolute; inset: 0; background: #040906; opacity: 0;
  transition: opacity .8s var(--ease-soft);
}
#particles { position: fixed; inset: 0; z-index: 1; pointer-events: none; width: 100%; height: 100%; transition: opacity .8s var(--ease-soft); }

/* Times of day */
html[data-time="dawn"] {
  --photo-filter: saturate(.75) brightness(.7) hue-rotate(-10deg) contrast(.95);
  --ray: rgba(255, 205, 190, .10); --rays: .7;
  --mist: rgba(255, 225, 220, .22); --mist-o: 1;
  --grade: linear-gradient(to bottom, rgba(255,170,160,.18), rgba(120,110,160,.10) 50%, transparent);
  --ground-glow: rgba(255,190,170,.14);
}
html[data-time="day"] {
  --photo-filter: saturate(1) brightness(.8);
  --ray: rgba(255, 244, 200, .13); --rays: 1;
  --mist: rgba(230, 240, 220, .12); --mist-o: .6;
  --grade: linear-gradient(to bottom, rgba(255,250,220,.08), transparent 50%);
}
html[data-time="dusk"] {
  --photo-filter: saturate(.95) brightness(.62) sepia(.28);
  --ray: rgba(255, 180, 90, .14); --rays: .95;
  --mist: rgba(255, 200, 150, .14); --mist-o: .8;
  --grade: linear-gradient(to bottom, rgba(255,140,60,.16), rgba(120,40,60,.10) 55%, transparent);
  --ground-glow: rgba(255,160,80,.2);
}
html[data-time="night"] {
  --photo-filter: saturate(.45) brightness(.3) hue-rotate(18deg);
  --rays: 0;
  --mist: rgba(150, 175, 230, .12); --mist-o: .7;
  --grade: radial-gradient(60% 50% at 38% 8%, rgba(190,210,255,.14), transparent 70%), linear-gradient(to bottom, rgba(20,40,90,.28), rgba(8,14,40,.2));
  --ground-glow: rgba(120,150,255,.08);
  --near-b: .7;
}
html[data-time="night"] .scene__sky { opacity: 1; }
html[data-time="night"] .envelope { filter: drop-shadow(0 30px 40px rgba(0,0,0,.6)) brightness(.8) saturate(.85); }

/* Rain mood (the apology page): cooler, quieter, no sun */
body.mood-rain {
  --photo-filter: saturate(.4) brightness(.42) hue-rotate(20deg) contrast(.95);
  --rays: 0;
  --mist: rgba(170, 185, 205, .2); --mist-o: 1;
  --grade: linear-gradient(to bottom, rgba(40,55,80,.35), rgba(20,28,45,.3));
  --ground-glow: rgba(140,160,190,.08);
  --near-b: .75;
}
body.mood-rain .scene__sky { opacity: 0; }

/* Reading pages: the forest steps back behind the paper */
.is-reading .scene__far { filter: blur(2.5px); }
.is-reading .scene__near { opacity: .55; }
.is-reading .scene__grade::after { opacity: .38; }
body.focus-mode .scene__grade::after { opacity: .82; }
body.focus-mode #particles { opacity: 0; }

@keyframes drift {
  from { transform: scale(1.02) translate3d(0, 0, 0); }
  to   { transform: scale(1.08) translate3d(-1.2%, -1%, 0); }
}
@keyframes shimmer { from { opacity: calc(var(--rays, .8) * .55); } to { opacity: var(--rays, .8); } }
@keyframes mist { from { translate: -6% 0; } to { translate: 6% 0; } }

/* 4. Top bar --------------------------------------------------------------- */
.topbar {
  position: fixed; top: max(12px, env(safe-area-inset-top)); left: 50%; z-index: 40;
  translate: -50% 0;
  display: flex; align-items: center; gap: 2px;
  padding: 4px;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  transition: translate .45s var(--ease-out), opacity .45s var(--ease-out);
  view-transition-name: topbar;
}
.topbar.is-tucked { translate: -50% calc(-100% - 20px); opacity: 0; }
.topbar a, .topbar button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font-family: var(--ui); font-size: .82rem; letter-spacing: .04em;
  color: var(--on-dark-soft); text-decoration: none;
  padding: .42rem .9rem; border-radius: 999px;
  transition: color .2s, background-color .2s;
}
.topbar a:hover, .topbar button:hover { color: var(--on-dark); background: rgba(255,255,255,.07); }
.topbar a[aria-current="page"], .topbar a.is-active { color: var(--forest-950); background: var(--gold-soft); }
.topbar button[aria-pressed="true"] { color: var(--gold-soft); }
.topbar .sep { width: 1px; height: 18px; background: var(--glass-line); margin: 0 4px; }

.progress {
  position: fixed; top: 0; left: 0; z-index: 50; height: 2px; width: 100%;
  transform-origin: 0 50%; transform: scaleX(0);
  background: linear-gradient(90deg, var(--gold), var(--gold-soft));
  box-shadow: 0 0 12px rgba(231,207,156,.6);
}

/* 5. Paper ----------------------------------------------------------------- */
.stage {
  position: relative; z-index: 2;
  min-height: 100vh; min-height: 100svh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(84px + env(safe-area-inset-top)) 16px calc(56px + env(safe-area-inset-bottom));
}
.paper {
  position: relative;
  width: min(100%, 680px);
  padding: clamp(2.2rem, 5vw, 4rem) clamp(1.4rem, 6vw, 4.2rem) clamp(2rem, 4vw, 3.2rem);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(140% 90% at 50% 0%, transparent 60%, var(--paper-shade) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .12 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  border-radius: 3px;
  box-shadow: var(--shadow-paper);
  view-transition-name: paper;
}
.paper--wide { width: min(100%, 860px); }
.paper > :first-child { margin-top: 0; }
.paper > :last-child { margin-bottom: 0; }

/* 6. Type ------------------------------------------------------------------ */
.eyebrow {
  display: block;
  font-family: var(--ui); font-size: .74rem; letter-spacing: .28em; text-transform: uppercase;
  color: var(--ink-faint); text-align: center; margin: 0 0 1rem;
}
.title {
  font-family: var(--serif-display);
  font-weight: 500; font-style: italic;
  font-size: clamp(2.3rem, 1.6rem + 3.4vw, 3.8rem);
  line-height: 1.05; letter-spacing: -.01em;
  text-align: center; margin: 0 0 1.2rem;
  color: var(--ink);
  text-wrap: balance;
}
.title--sm { font-size: clamp(1.9rem, 1.4rem + 2.2vw, 2.9rem); }
.subtitle {
  font-family: var(--serif-display); font-style: italic; font-weight: 500;
  font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.2rem); line-height: 1.15;
  text-align: center; margin: 3rem 0 1.4rem; color: var(--ink);
}
.dedication {
  font-family: var(--serif-display); font-style: italic;
  font-size: clamp(1.2rem, 1.05rem + .7vw, 1.5rem); line-height: 1.45;
  color: var(--ink-soft); text-align: center; margin: 0 auto 1.5rem; max-width: 30ch;
  text-wrap: balance;
}
.flourish {
  display: flex; align-items: center; justify-content: center; gap: .8rem;
  color: var(--gold); margin: 1.4rem auto 1.8rem; max-width: 220px;
}
.flourish::before, .flourish::after { content: ""; flex: 1; height: 1px; background: currentColor; opacity: .55; }
.flourish svg { width: 18px; height: 18px; flex: none; }

.prose p { margin: 0 0 1.3em; text-wrap: pretty; hyphens: manual; }
.prose--letter p:first-of-type::first-letter {
  float: left; font-family: var(--serif-display); font-weight: 600; font-style: normal;
  font-size: 3.6em; line-height: .82; margin: .08em .1em 0 0; color: var(--accent);
}
.lead { text-align: center; color: var(--ink-soft); margin: 0 auto 1.2rem; max-width: 46ch; }

/* 7. Buttons & links -------------------------------------------------------- */
.btn {
  --b-bg: var(--ink); --b-fg: var(--paper);
  appearance: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .55em;
  min-height: 48px; padding: .8rem 1.5rem;
  border: 1px solid transparent; border-radius: 999px;
  background: var(--b-bg); color: var(--b-fg);
  font-family: var(--ui); font-size: .92rem; letter-spacing: .06em;
  text-decoration: none; text-align: center; line-height: 1.2;
  transition: transform .35s var(--ease-out), box-shadow .35s var(--ease-out), background-color .25s, color .25s, border-color .25s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 10px 22px -10px rgba(0,0,0,.45); }
.btn:active { transform: translateY(0) scale(.98); }
.btn--ghost { --b-bg: transparent; --b-fg: var(--ink); border-color: var(--rule); }
.btn--ghost:hover { border-color: var(--ink-soft); }
.btn--wax { --b-bg: var(--wax); --b-fg: #fbeee6; }
.btn--small { min-height: 38px; padding: .45rem 1rem; font-size: .8rem; }
.btn .arrow { transition: transform .35s var(--ease-out); }
.btn:hover .arrow--r { transform: translateX(3px); }
.btn:hover .arrow--l { transform: translateX(-3px); }

.actions { display: flex; flex-wrap: wrap; gap: .8rem; justify-content: center; margin-top: 2.2rem; }
.pager {
  display: flex; justify-content: space-between; align-items: center; gap: .8rem;
  margin-top: 2.6rem; padding-top: 1.6rem; border-top: 1px solid var(--rule);
}
.pager > :only-child { margin-left: auto; margin-right: auto; }
.pager .spacer { flex: 1; }
.apology .poem-block + .poem-block { margin-top: 3.2rem; padding-top: 2.4rem; border-top: 1px solid var(--rule); }
.apology .poem { margin-top: 1.4rem; }
.apology .poem-block .subtitle { margin-top: .2rem; }
.apology .closing { text-align: center; font-family: var(--serif-display); font-style: italic; font-size: clamp(1.15rem, 1rem + .6vw, 1.4rem); color: var(--ink-soft); margin: 3rem auto 0; max-width: 32ch; }
.pager__end { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: flex-end; }

.tools { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; margin-top: 2rem; }

.credit {
  position: relative; z-index: 2;
  font-family: var(--ui); font-size: .78rem; letter-spacing: .08em; color: var(--on-dark-soft);
  text-align: center; margin: 2rem 0 0; padding: 0 16px;
}

/* 8. Chapter tracker -------------------------------------------------------- */
.chapters {
  display: flex; justify-content: center; align-items: center; gap: 0;
  margin: 0 auto 2rem; padding: 0; list-style: none;
}
.chapters li { display: flex; align-items: center; }
.chapters li + li::before {
  content: ""; width: clamp(14px, 4vw, 30px); height: 1px; background: var(--rule);
}
.chapters span {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  font-family: var(--serif-display); font-size: .9rem; font-weight: 600;
  color: var(--ink-faint); border: 1px solid var(--rule);
}
.chapters .is-done span { color: var(--ink-soft); border-color: var(--ink-faint); }
.chapters .is-current span { color: var(--paper); background: var(--accent); border-color: var(--accent); }
.chapters .is-done + li::before, .chapters .is-current::before { background: var(--ink-faint); }

/* 9. Home / envelope -------------------------------------------------------- */
.home .stage { padding-top: calc(40px + env(safe-area-inset-top)); }
.home-scene { position: relative; width: min(100%, 560px); display: grid; place-items: center; }

.envelope-wrap { display: grid; place-items: center; gap: 1.6rem; transition: opacity .7s var(--ease-soft), transform .9s var(--ease-out); }
.envelope-wrap .for {
  font-family: var(--serif-display); font-style: italic; font-size: clamp(1.4rem, 1.1rem + 1.4vw, 2rem);
  color: var(--on-dark); text-shadow: 0 2px 20px rgba(0,0,0,.6); margin: 0; text-align: center;
}
.envelope {
  --w: min(84vw, 420px);
  position: relative; width: var(--w); aspect-ratio: 1.55;
  perspective: 1200px;
  filter: drop-shadow(0 30px 40px rgba(0,0,0,.55));
  animation: float 6s ease-in-out infinite;
}
.envelope__back, .envelope__front, .envelope__flap { position: absolute; inset: 0; }
.envelope__back { background: #d9c7a3; border-radius: 4px; }
.envelope__card {
  position: absolute; z-index: 1; left: 7%; right: 7%; top: 8%; height: 84%;
  background: var(--paper); border-radius: 2px;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  display: grid; place-items: center;
  transition: transform 1s var(--ease-out) .35s;
}
.envelope__card::after {
  content: ""; width: 60%; height: 40%;
  background: repeating-linear-gradient(to bottom, var(--rule) 0 1px, transparent 1px 14px);
  opacity: .8;
}
.envelope__front {
  z-index: 2; border-radius: 4px;
  background: linear-gradient(170deg, #efe2c5, #e2cfa8);
  clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%);
  box-shadow: inset 0 -20px 30px -20px rgba(92,64,30,.25);
}
.envelope__flap {
  z-index: 3; height: 62%;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  transition: transform .8s var(--ease-out), z-index 0s .4s;
}
.envelope__flap::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom, #d4c09a, #e3d1ad);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  backface-visibility: hidden;
}
.envelope__flap::after {
  content: ""; position: absolute; inset: 0;
  background: #cdb88f;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform: rotateX(180deg);
  backface-visibility: hidden;
}
.seal {
  position: absolute; z-index: 4; left: 50%; top: 62%;
  width: 74px; height: 74px; translate: -50% -50%;
  border: 0; padding: 0; cursor: pointer; border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,.35), transparent 38%),
    radial-gradient(circle at 50% 50%, var(--wax) 0 55%, var(--wax-deep) 100%);
  box-shadow: 0 4px 10px rgba(0,0,0,.35), inset 0 -3px 6px rgba(0,0,0,.35), inset 0 2px 3px rgba(255,255,255,.2);
  color: #f5d9c9; font-family: var(--serif-display); font-style: italic; font-weight: 600; font-size: 2.1rem;
  display: grid; place-items: center;
  transition: transform .4s var(--ease-out), opacity .4s, filter .4s;
  -webkit-tap-highlight-color: transparent;
}
.seal::before {
  content: ""; position: absolute; inset: 7px; border-radius: 50%;
  border: 1.5px dashed rgba(245,217,201,.35);
}
.seal::after {
  content: ""; position: absolute; inset: -10px; border-radius: 50%;
  border: 1px solid rgba(231,207,156,.6);
  animation: halo 2.4s ease-out infinite;
}
.seal:hover { transform: scale(1.07); }
.seal:active { transform: scale(.94); }
.hint {
  font-family: var(--ui); font-size: .78rem; letter-spacing: .24em; text-transform: uppercase;
  color: var(--on-dark-soft); margin: 0;
}

/* Opened state */
.home-scene.is-open .envelope { animation: none; }
.home-scene.is-open .seal { opacity: 0; transform: scale(1.4) rotate(-12deg); filter: blur(2px); pointer-events: none; }
.home-scene.is-open .envelope__flap { transform: rotateX(180deg); z-index: 0; }
.home-scene.is-open .envelope__card { transform: translateY(-55%); }
.home-scene.is-open .envelope-wrap { opacity: 0; transform: translateY(40px) scale(.94); pointer-events: none; transition-delay: 1.15s, 1.15s; }

.letter-card {
  position: absolute; inset: auto; width: min(100%, 560px);
  opacity: 0; transform: translateY(46px) scale(.97); pointer-events: none; visibility: hidden;
  transition: opacity .9s var(--ease-soft) 1.35s, transform 1.1s var(--ease-out) 1.35s, visibility 0s 1.35s;
  text-align: center;
}
.home-scene.is-open .letter-card { position: relative; opacity: 1; transform: none; pointer-events: auto; visibility: visible; }
.home-scene.is-open { display: block; }
.home-scene.is-open .envelope-wrap { position: absolute; inset: 0; margin: auto; height: max-content; }
.home-scene.is-instant .envelope-wrap, .home-scene.is-instant .letter-card { transition: none !important; }

.letter-card .title { font-size: clamp(2.6rem, 1.8rem + 4vw, 4.4rem); }
.letter-card .actions { flex-direction: column; align-items: stretch; max-width: 320px; margin-inline: auto; }
@media (min-width: 560px) { .letter-card .actions { flex-direction: row; max-width: none; } }

.typing { min-height: 1.45em; }
.typing .caret {
  display: inline-block; width: 1px; height: 1em; background: currentColor; margin-left: 2px;
  vertical-align: -.12em; animation: blink 1s steps(1) infinite;
}

.bookmark {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 30;
  translate: -50% 0;
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .6rem 1.1rem; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--glass-line); color: var(--on-dark);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  font-family: var(--ui); font-size: .82rem; letter-spacing: .04em; text-decoration: none;
  transition: background-color .2s;
}
.bookmark:hover { background: rgba(10,20,14,.75); }
.bookmark[hidden] { display: none; }

/* 10. Question page -------------------------------------------------------- */
.question {
  font-family: var(--serif-display); font-style: italic; font-weight: 500;
  font-size: clamp(1.9rem, 1.4rem + 2.4vw, 2.8rem); line-height: 1.15;
  text-align: center; color: var(--ink); margin: 1.6rem 0 0; text-wrap: balance;
}
.arena {
  position: relative; margin: 2rem auto 0; min-height: 190px; max-width: 520px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 1rem;
}
.arena { min-height: 240px; }
.arena[hidden] { display: none; }
.arena .btn { white-space: nowrap; }
.no-ghost { visibility: hidden; display: inline-block; flex: none; }
#no-btn.is-running {
  position: absolute; margin: 0;
  transition: left .45s var(--ease-out), top .45s var(--ease-out), transform .45s var(--ease-out), opacity .3s;
}
#no-btn.is-gone { opacity: 0; transform: scale(.4) rotate(-20deg); pointer-events: none; }
.yes-btn { position: relative; z-index: 2; }
.yes-btn::after {
  content: ""; position: absolute; inset: -6px; border-radius: inherit;
  border: 1px solid var(--wax); opacity: .5; animation: halo-sm 2.2s ease-out infinite;
}
.response { text-align: center; min-height: 3rem; margin-top: .8rem; }
.response p {
  font-family: var(--serif-display); font-style: italic; font-weight: 500;
  font-size: clamp(1.35rem, 1.1rem + 1vw, 1.7rem); line-height: 1.3; margin: 0 0 1rem;
  animation: rise .6s var(--ease-out) both;
}
.response .tone-warm { color: #b25a1a; }
.response .tone-alert { color: var(--accent); }
.response .tone-joy { color: #3f7a45; }
@media (prefers-color-scheme: dark) {
  .response .tone-warm { color: #f0a868; }
  .response .tone-joy { color: #9fd49a; }
}
.response .btn { animation: rise .6s var(--ease-out) .25s both; }
#burst { position: fixed; inset: 0; z-index: 60; pointer-events: none; width: 100%; height: 100%; }

/* 11. Quotes --------------------------------------------------------------- */
.quotes { display: grid; gap: 1rem; margin: 2rem 0 0; padding: 0; list-style: none; }
@media (min-width: 720px) { .quotes--grid { grid-template-columns: 1fr 1fr; } }
.quote {
  position: relative; margin: 0;
  padding: 1.2rem 1.4rem 1.2rem 1.5rem;
  border-left: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: linear-gradient(to bottom right, rgba(255,255,255,.28), transparent);
  font-family: var(--serif-display); font-style: italic; font-size: 1.26rem; line-height: 1.45;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) { .quote { background: linear-gradient(to bottom right, rgba(255,255,255,.03), transparent); } }
.quotes > .is-finale { grid-column: 1 / -1; }
.quote--finale {
  text-align: center; padding: 1.8rem 1.4rem;
  font-size: clamp(1.45rem, 1.2rem + 1vw, 1.8rem);
  border: 1px solid var(--accent);
  border-left-width: 1px;
}

/* 12. Poetry --------------------------------------------------------------- */
.toc { list-style: none; margin: 1.6rem 0 0; padding: 0; counter-reset: none; }
.toc li + li { border-top: 1px dashed var(--rule); }
.toc a {
  display: grid; grid-template-columns: 3.2rem 1fr auto; align-items: baseline; gap: .6rem;
  padding: .9rem .4rem; text-decoration: none; color: var(--ink);
  transition: background-color .25s, padding .35s var(--ease-out);
  border-radius: 4px;
}
.toc a:hover { background: var(--paper-shade); padding-left: .9rem; }
.toc .num { font-family: var(--serif-display); font-weight: 600; color: var(--accent); font-size: 1.05rem; }
.toc .name { font-family: var(--serif-display); font-size: clamp(1.2rem, 1.05rem + .5vw, 1.4rem); line-height: 1.3; }
.toc .go { color: var(--ink-faint); transition: transform .35s var(--ease-out), color .25s; }
.toc a:hover .go { transform: translateX(4px); color: var(--accent); }
.toc-heading { font-family: var(--ui); font-size: .74rem; letter-spacing: .28em; text-transform: uppercase; color: var(--ink-faint); text-align: center; margin: 2.4rem 0 0; font-weight: 400; }

.poem-num {
  display: block; text-align: center; font-family: var(--serif-display); font-weight: 600;
  font-size: 1rem; letter-spacing: .3em; color: var(--accent); margin-bottom: .6rem;
}
.poem { margin: 2rem auto 0; max-width: 34em; }
.poem .stanza { margin: 0 0 1.6em; }
.poem .ln { display: block; padding-left: 1.4em; text-indent: -1.4em; }
.poem-index { font-family: var(--ui); font-size: .78rem; letter-spacing: .12em; color: var(--ink-faint); text-align: center; margin-top: 1.6rem; }
.poem-index kbd { font-family: var(--ui); font-size: .72rem; border: 1px solid var(--rule); border-radius: 4px; padding: 0 .35rem; }
@media (hover: none), (pointer: coarse) { .poem-index .keys { display: none; } }

.letter-poem { margin: 1.6rem auto 0; max-width: 30em; }
.letter-poem .stanza { margin: 0 0 1.4em; }
.letter-poem .ln { display: block; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 70;
  translate: -50% 20px; opacity: 0;
  background: var(--ink); color: var(--paper); padding: .6rem 1.1rem; border-radius: 999px;
  font-family: var(--ui); font-size: .85rem;
  transition: opacity .3s, translate .4s var(--ease-out); pointer-events: none;
}
.toast.is-shown { opacity: 1; translate: -50% 0; }

/* 13. Motion --------------------------------------------------------------- */
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-.6deg); } 50% { transform: translateY(-10px) rotate(.6deg); } }
@keyframes halo { 0% { transform: scale(.9); opacity: .7; } 100% { transform: scale(1.35); opacity: 0; } }
@keyframes halo-sm { 0% { transform: scale(.98); opacity: .6; } 100% { transform: scale(1.12, 1.3); opacity: 0; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* Reveal on scroll (only when JS runs; content is visible without it) */
.js [data-reveal] { opacity: 0; transform: translateY(18px); transition: opacity .9s var(--ease-soft), transform 1s var(--ease-out); transition-delay: var(--d, 0s); }
.js [data-reveal].is-in { opacity: 1; transform: none; }
.js .poem .ln { opacity: 0; transform: translateY(6px); transition: opacity .7s var(--ease-soft), transform .8s var(--ease-out); transition-delay: var(--d, 0s); }
.js .poem .stanza.is-in .ln { opacity: 1; transform: none; }

/* Paper entrance on first load (view transitions handle page-to-page) */
.js .paper.enter { animation: paperIn 1s var(--ease-out) both; }
@keyframes paperIn { from { opacity: 0; transform: translateY(28px) rotate(-.4deg); } to { opacity: 1; transform: none; } }

/* Cross-document view transitions (Chrome/Edge/Safari 18+) */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .5s; }
::view-transition-group(paper) { animation-duration: .6s; animation-timing-function: cubic-bezier(.16,1,.3,1); }
::view-transition-old(paper) { animation: vtOut .35s var(--ease-soft) both; }
::view-transition-new(paper) { animation: vtIn .6s var(--ease-out) both; }
@keyframes vtOut { to { opacity: 0; transform: translateY(-10px); } }
@keyframes vtIn { from { opacity: 0; transform: translateY(14px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; transition-delay: 0s !important; scroll-behavior: auto !important; }
  .js [data-reveal], .js .poem .ln { opacity: 1; transform: none; }
  @view-transition { navigation: none; }
}

/* 14. Utilities ------------------------------------------------------------ */
.center { text-align: center; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 480px) {
  .topbar a, .topbar button { padding: .4rem .7rem; font-size: .78rem; }
  .pager { flex-wrap: wrap; }
  .pager .btn { flex: 1 1 auto; }
  .pager__end { flex: 1 1 100%; }
  .quote { font-size: 1.16rem; }
}

@media print {
  .scene, #particles, .topbar, .progress, .tools, .pager, .bookmark { display: none !important; }
  body { background: #fff; }
  .paper { box-shadow: none; background: #fff; color: #000; }
}

/* Without JavaScript the seal can't be broken, so show the letter straight away */
html:not(.js) .envelope-wrap { display: none; }
html:not(.js) .letter-card { position: relative; opacity: 1; visibility: visible; transform: none; pointer-events: auto; }
