/* ==================================================================
   Once Upon a Voice — a leather-bound heirloom that reads itself aloud
   cognac leather · gilt embossing · aged parchment · candlelight
================================================================== */

/* Fraunces lives with the book — no font network call at bedtime */
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 300 600;
  font-display: swap;
  src: url("fonts/fraunces.woff2") format("woff2");
}
@font-face {
  font-family: "Fraunces";
  font-style: italic;
  font-weight: 300 600;
  font-display: swap;
  src: url("fonts/fraunces-italic.woff2") format("woff2");
}

:root {
  --leather-0: #2c160d;
  --leather-1: #4b2617;
  --leather-2: #6a3820;
  --leather-hi: #8a5030;
  --gilt-0: #f6e6a8;
  --gilt-1: #dcb455;
  --gilt-2: #a6781f;
  --gilt-deep: #6e4b16;
  --paper-0: #efe4c8;
  --paper-1: #e4d3ad;
  --paper-2: #d3bd8e;
  /* one ink palette, used everywhere for consistency */
  --ink: #3a2410;        /* primary: headings + story text */
  --ink-soft: #5e4426;   /* secondary: italic lines, hints */
  --ink-label: #7a5416;  /* small-caps labels: kickers, page numbers */
  --display: "Fraunces", serif;
  /* one type scale, used everywhere */
  --fs-heading: clamp(1.5rem, 3.6vw, 2.25rem);  /* section titles */
  --fs-story:   clamp(1.15rem, 2.6vw, 1.95rem); /* the story text */
  --fs-line:    clamp(.92rem, 1.9vw, 1.12rem);  /* secondary italic lines */
  --fs-label:   clamp(.62rem, 1.3vw, .74rem);   /* small-caps labels */
  --ls-label: .26em;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);

  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  background: radial-gradient(120% 100% at 50% 118%, #241209 0%, #160b06 55%, #0c0603 100%);
  color: var(--paper-0);
  font-family: var(--display);
  overflow: hidden;
  display: grid;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom delay; pinch zoom still works */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ---------- candlelight + dust ---------- */
#candle {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(60% 45% at 50% 28%, rgba(255,197,120,.22) 0%, rgba(255,170,80,.06) 42%, transparent 72%);
  animation: flicker 5.5s ease-in-out infinite;
}
@keyframes flicker { 0%,100% { opacity: .85; } 45% { opacity: 1; } 70% { opacity: .78; } }
#motes { position: fixed; inset: 0; pointer-events: none; }
#motes i {
  position: absolute; width: 3px; height: 3px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,222,160,.9), transparent 70%);
  animation: mote 14s linear infinite;
}
#motes i:nth-child(1){ left:18%; bottom:-4%; animation-delay:0s; }
#motes i:nth-child(2){ left:34%; bottom:-4%; animation-delay:-3s; }
#motes i:nth-child(3){ left:52%; bottom:-4%; animation-delay:-6s; }
#motes i:nth-child(4){ left:67%; bottom:-4%; animation-delay:-9s; }
#motes i:nth-child(5){ left:79%; bottom:-4%; animation-delay:-2s; }
#motes i:nth-child(6){ left:88%; bottom:-4%; animation-delay:-11s; }
@keyframes mote { 0% { transform: translateY(0) translateX(0); opacity: 0; } 10% { opacity: .8; } 90% { opacity: .5; } 100% { transform: translateY(-108vh) translateX(24px); opacity: 0; } }

/* ==================================================================
   THE SCENE — a closed book that opens onto the spread
================================================================== */
#scene { position: relative; display: grid; place-items: center; perspective: 2800px; }
#scene > * { grid-area: 1 / 1; }

/* ---------- the closed book ---------- */
#closed {
  position: relative; z-index: 40; cursor: pointer; /* the whole cover answers a small hand */
  width: min(52vw, 62vh, 440px); aspect-ratio: 0.72 / 1;
  border-radius: 5px 14px 14px 5px;
  background:
    radial-gradient(140% 120% at 32% 12%, var(--leather-hi) 0%, transparent 46%),
    radial-gradient(120% 120% at 85% 95%, var(--leather-0) 0%, transparent 55%),
    linear-gradient(150deg, var(--leather-2) 0%, var(--leather-1) 52%, var(--leather-0) 100%);
  box-shadow: 0 40px 80px -30px rgba(0,0,0,.85), inset 0 0 70px rgba(0,0,0,.5), inset 0 2px 3px rgba(255,220,180,.15);
  transform-origin: left center;
  transition: transform .85s cubic-bezier(.5,.02,.35,1), opacity .7s ease .15s;
}
#closed::before { content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: var(--grain); background-size: 150px; opacity: .7; mix-blend-mode: overlay; pointer-events: none; }
#closed::after { content: ""; position: absolute; inset: 5% 6%; border-radius: 8px;
  border: 1.5px solid rgba(246,230,168,.32); box-shadow: inset 0 0 0 3px rgba(0,0,0,.25), inset 0 0 0 4.5px rgba(246,230,168,.12);
  pointer-events: none; }
#closed.open { transform: rotateY(-128deg); opacity: 0; pointer-events: none; }
.closed-spine { position: absolute; left: 0; top: 0; bottom: 0; width: 8%; border-radius: 5px 0 0 5px;
  background: linear-gradient(90deg, rgba(0,0,0,.45), rgba(0,0,0,.05)); }
.closed-face {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.1rem;
  padding: 12% 10%; text-align: center;
}
.closed-kicker { font-size: var(--fs-label); letter-spacing: var(--ls-label); text-transform: uppercase;
  color: var(--gilt-1); opacity: .78; font-style: italic; }
.closed-title {
  font-size: clamp(1.9rem, 5.4vw, 3rem); line-height: 1; font-weight: 500;
  font-variation-settings: "opsz" 144, "WONK" 1;
  background: linear-gradient(176deg, #fbeeb8, var(--gilt-1) 44%, var(--gilt-2) 68%, #efd489);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 1px 0 rgba(255,255,255,.25)) drop-shadow(0 2px 4px rgba(0,0,0,.5));
}
.closed-title em { font-style: italic; font-variation-settings: "opsz" 144, "SOFT" 100, "WONK" 1; }
.closed-engrave { font-size: var(--fs-label); letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--gilt-1); opacity: .7; }

/* ==================================================================
   THE BOOK
================================================================== */
#book {
  position: relative;
  /* leave a band below the book for the child's subtitle + top room for controls */
  width: min(92vw, 80vh * 1.52, 1120px);
  aspect-ratio: 1.52 / 1;
  border-radius: 16px 20px 20px 16px;
  perspective: 2600px;
  transition: opacity .6s ease .2s, transform .7s cubic-bezier(.23,1,.32,1) .2s;
  background:
    radial-gradient(140% 120% at 30% 12%, var(--leather-hi) 0%, transparent 45%),
    radial-gradient(120% 120% at 85% 95%, var(--leather-0) 0%, transparent 55%),
    linear-gradient(150deg, var(--leather-2) 0%, var(--leather-1) 52%, var(--leather-0) 100%);
  box-shadow:
    0 3px 0 2px rgba(0,0,0,.35),
    0 44px 90px -34px rgba(0,0,0,.85),
    inset 0 0 70px rgba(0,0,0,.55),
    inset 0 2px 3px rgba(255,220,180,.15);
}
#book.shut { opacity: 0; transform: scale(.9); pointer-events: none; }
#book::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: var(--grain); background-size: 150px; opacity: .7; mix-blend-mode: overlay;
  pointer-events: none;
}
#book::after {
  content: ""; position: absolute; inset: 1.6%; border-radius: 10px;
  border: 1.5px solid rgba(246,230,168,.32);
  box-shadow: inset 0 0 0 3px rgba(0,0,0,.25), inset 0 0 0 4.5px rgba(246,230,168,.12);
  pointer-events: none; z-index: 6;
}

/* ---------- the two pages ---------- */
.page {
  position: absolute; top: 4.2%; bottom: 5.4%;
  background: radial-gradient(120% 90% at 50% 0%, var(--paper-0), var(--paper-1) 62%, var(--paper-2) 100%);
  overflow: hidden;
}
#leftpage  { left: 3.6%; right: 50.7%; border-radius: 7px 3px 3px 7px;
  box-shadow: -2px 0 0 rgba(211,189,142,.9), -4px 0 0 rgba(198,175,128,.8), -6px 0 0 rgba(184,161,114,.7), inset -14px 0 26px -12px rgba(90,60,24,.5); }
#rightpage { left: 50.7%; right: 3.6%; border-radius: 3px 7px 7px 3px;
  box-shadow: 2px 0 0 rgba(211,189,142,.9), 4px 0 0 rgba(198,175,128,.8), 6px 0 0 rgba(184,161,114,.7), inset 14px 0 26px -12px rgba(90,60,24,.5); }
.page .paper { position: absolute; inset: 0; pointer-events: none;
  background: var(--grain); background-size: 160px; opacity: .26; mix-blend-mode: multiply; }
.page::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 60px -18px rgba(107,74,40,.5); }

/* ---------- spine / gutter ---------- */
#spine {
  position: absolute; top: 3.4%; bottom: 4.6%; left: 49.3%; width: 1.4%;
  background: linear-gradient(90deg, rgba(20,8,3,.05), rgba(20,8,3,.5) 45%, rgba(20,8,3,.5) 55%, rgba(20,8,3,.05));
  z-index: 3; pointer-events: none;
}
#spine::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; transform: translateX(-50%);
  background: linear-gradient(180deg, transparent, rgba(246,230,168,.32), transparent); }

/* ---------- verso decorative mark (during the rites) ---------- */
#leftmark { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
#leftmark svg { width: 16%; opacity: .16; fill: var(--gilt-2); filter: drop-shadow(0 1px 0 rgba(255,255,255,.3)); }
#book[data-mode="story"] #leftmark, #book[data-mode="end"] #leftmark { display: none; }

/* ---------- caption (verso, story mode) ---------- */
.caption {
  position: absolute; inset: 13% 12% 15% 12%;
  display: flex; align-items: center; justify-content: center; text-align: center;
  color: var(--ink);
  font-size: var(--fs-story); font-weight: 400;
  font-variation-settings: "opsz" 60, "SOFT" 50; line-height: 1.5;
}
.caption .lines { display: block; text-align: center; text-wrap: pretty; }
.caption.smudge { color: #9a3b2a; font-style: italic; font-size: clamp(.95rem, 2vw, 1.3rem); }
.caption .w {
  display: inline-block; margin-right: .3em; opacity: 0;
  animation: inkword .6s ease forwards;
}
@keyframes inkword {
  0%   { opacity: 0; color: var(--gilt-1); text-shadow: 0 0 12px rgba(240,190,90,.9); }
  55%  { opacity: 1; color: #7a5a1e; text-shadow: 0 0 10px rgba(240,190,90,.6); }
  100% { opacity: 1; color: var(--ink); text-shadow: none; }
}
.pagenum { position: absolute; bottom: 6%; left: 0; right: 0; text-align: center;
  font-size: var(--fs-label); letter-spacing: var(--ls-label); color: var(--ink-label); opacity: .7; }

/* ---------- illustration (recto) ---------- */
.sheet { position: absolute; inset: 5%; border-radius: 4px; overflow: hidden; opacity: 0; transition: opacity .5s ease;
  background: radial-gradient(80% 80% at 50% 42%, #f3e6c4, var(--paper-1) 60%, var(--paper-2));
  box-shadow: 0 6px 22px -8px rgba(60,38,16,.6), 0 0 0 1px rgba(110,75,22,.22), 0 0 0 7px rgba(239,228,200,.7); }
.sheet.on { opacity: 1; }
/* candlelit shimmer while the picture is still being painted */
.sheet.painting::after { content: ""; position: absolute; inset: 0; z-index: 0;
  background: radial-gradient(44% 44% at 50% 45%, rgba(255,196,110,.5), rgba(240,184,96,.12) 45%, transparent 72%);
  animation: sealbreathe 3s ease-in-out infinite; }
.sheet img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity .7s ease; }
.sheet img.lit { opacity: 1; }

/* ---------- the turning leaf: a real two-sided page, hinged at the spine ---------- */
#flip {
  position: absolute; top: 4.2%; bottom: 5.4%; left: 50.7%; right: 3.6%;
  transform-origin: left center; transform-style: preserve-3d;
  opacity: 0; pointer-events: none; z-index: 7;
  /* no filter here — a filter flattens preserve-3d and the hidden back face
     shows the front's picture mirrored; the shadow lives on the faces instead */
}
#flip.turning { animation: pageturn var(--turn, 1100ms) cubic-bezier(.42,.02,.34,1) forwards; }
/* transform only — animating opacity here (even held at 1) makes the browser
   flatten preserve-3d mid-flight, and the hidden back face shows the front
   mirrored; opacity is handled from the script instead */
@keyframes pageturn {
  0%   { transform: rotateY(0deg);    }
  100% { transform: rotateY(-179deg); }
}
.flip-face {
  position: absolute; inset: 0; border-radius: 3px 7px 7px 3px; backface-visibility: hidden;
  background: radial-gradient(120% 90% at 0% 0%, var(--paper-0), var(--paper-1) 62%, var(--paper-2) 100%);
  background-size: cover; background-position: center; overflow: hidden;
  box-shadow: 0 0 34px rgba(0,0,0,.4);
}
.flip-front { z-index: 2; }
.flip-back { transform: rotateY(180deg); box-shadow: inset 0 0 60px -18px rgba(107,74,40,.5), 0 0 34px rgba(0,0,0,.4); }
.flip-sheen { position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(105deg, rgba(255,255,255,.02) 0%, rgba(255,247,220,.4) 44%, rgba(120,80,40,.3) 60%, rgba(40,20,10,.2) 100%); }

/* ==================================================================
   STAGE — title + rites, on the recto (never straddling the spine)
================================================================== */
/* flex + margin:auto is the safe-center: a card taller than the page can
   still be scrolled to its edges instead of clipping below the fold */
#stage { position: absolute; inset: 0; z-index: 5; display: flex; overflow-y: auto; }
.card {
  width: min(84%, 26rem);
  margin: auto;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 1rem;
  padding: 8% 6%;
}
.card > * { animation: cardin .5s var(--ease-out) both; }
.card > *:nth-child(2) { animation-delay: 40ms; }
.card > *:nth-child(3) { animation-delay: 80ms; }
.card > *:nth-child(4) { animation-delay: 120ms; }
.card > *:nth-child(5) { animation-delay: 160ms; }
.card > *:nth-child(6) { animation-delay: 200ms; }
.card > *:nth-child(n+7) { animation-delay: 240ms; }
@keyframes cardin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* on the cream pages, ink — not gilt — for readability (gilt lives on the leather) */
.kicker { font-size: var(--fs-label); letter-spacing: var(--ls-label); text-transform: uppercase;
  color: var(--ink-label); font-style: italic; font-weight: 500; }

.rite-title { color: var(--ink); font-weight: 500; font-variation-settings: "opsz" 96, "WONK" 1;
  font-size: var(--fs-heading); line-height: 1.1; text-wrap: balance; text-shadow: 0 1px 0 rgba(255,252,240,.55); }

.rite-line { color: var(--ink-soft); line-height: 1.5; font-size: var(--fs-line); font-style: italic;
  max-width: 30ch; text-wrap: balance; }
.rite-sub { font-size: .78rem; font-style: italic; color: var(--ink-label); opacity: .85;
  margin-top: -.55rem; white-space: nowrap; }
.hero-mark svg { width: clamp(46px, 7vw, 66px); fill: var(--gilt-2); opacity: .5;
  filter: drop-shadow(0 1px 0 rgba(255,255,255,.35)); animation: breathe 3.6s ease-in-out infinite; }
@keyframes breathe { 0%,100% { opacity: .4; transform: scale(1); } 50% { opacity: .62; transform: scale(1.05); } }
@media (prefers-reduced-motion: reduce) { .hero-mark svg { animation: none; } }
.engrave { font-size: var(--fs-label); letter-spacing: var(--ls-label); text-transform: uppercase;
  color: var(--ink-label); font-style: italic; }

/* ---------- the seal (wax/brass button) ---------- */
.seal {
  --sz: clamp(76px, 11vw, 112px);
  width: var(--sz); height: var(--sz); border: 0; border-radius: 50%; cursor: pointer;
  position: relative; color: #3a230c;
  background: radial-gradient(60% 60% at 38% 32%, #ffe9a8 0%, var(--gilt-1) 40%, var(--gilt-2) 72%, var(--gilt-deep) 100%);
  box-shadow: inset 0 2px 5px rgba(255,247,214,.7), inset 0 -6px 12px rgba(84,54,12,.55),
    0 8px 20px -6px rgba(0,0,0,.55), 0 0 30px -6px rgba(255,196,110,.45);
  display: grid; place-items: center;
  transition: transform .14s ease, box-shadow .25s ease, filter .2s ease;
}
.seal.small { --sz: clamp(56px, 7.5vw, 74px); }
.seal::after { content: ""; position: absolute; inset: 10%; border-radius: 50%; border: 1px solid rgba(58,35,12,.4); }
.seal svg { width: 46%; height: 46%; fill: #3a230c; }
.seal svg path[fill="none"], .seal svg circle { stroke: #3a230c; }
.seal:active { transform: scale(.95); }
.seal:disabled { filter: grayscale(.5) brightness(.9); opacity: .55; cursor: default; }
.seal:focus-visible { outline: 2px solid var(--gilt-0); outline-offset: 5px; }
.card[data-card="invocation"] .seal { animation: sealbreathe 3.4s ease-in-out infinite; }
@keyframes sealbreathe {
  0%,100% { box-shadow: inset 0 2px 5px rgba(255,247,214,.7), inset 0 -6px 12px rgba(84,54,12,.55), 0 8px 20px -6px rgba(0,0,0,.55), 0 0 26px -6px rgba(255,196,110,.4); }
  50%     { box-shadow: inset 0 2px 5px rgba(255,247,214,.8), inset 0 -6px 12px rgba(84,54,12,.55), 0 10px 26px -6px rgba(0,0,0,.55), 0 0 48px 0 rgba(255,196,110,.7); }
}

.rite-actions { display: flex; flex-direction: column; align-items: center; gap: .7rem; }
.engrave-btn { background: none; border: 0; cursor: pointer; font-family: var(--display); font-style: italic;
  font-size: clamp(.8rem, 1.6vw, .96rem); color: var(--ink-soft);
  text-decoration: underline; text-decoration-color: rgba(106,86,58,.45); text-underline-offset: 4px;
  display: inline-block; transition: transform 160ms var(--ease-out), color 150ms ease;
  /* small print, but a full finger's worth of tap target */
  padding: .6rem .7rem; margin: -.45rem -.5rem; }
.engrave-btn:active { transform: scale(.97); }
.engrave-btn:focus-visible { outline: 2px solid var(--gilt-2); outline-offset: 2px; border-radius: 6px; }
.rite-error { color: #9a3b2a; font-style: italic; font-size: .84rem; line-height: 1.4; max-width: 28ch; }
.rite-promise { font-size: .74rem; font-style: italic; color: var(--ink-label); opacity: .85; max-width: 34ch; line-height: 1.5; }

/* ---------- the storyteller's key (the grown-up's page) ---------- */
.key-input {
  width: min(100%, 21rem);
  font-family: var(--display); font-style: italic; font-size: .95rem; text-align: center;
  color: var(--ink); background: rgba(255,255,255,.35);
  border: 1px solid rgba(110,75,22,.35); border-radius: 999px;
  padding: .7rem 1.1rem; outline: none;
  box-shadow: inset 0 1px 3px rgba(90,60,24,.15);
  transition: border-color .2s ease, box-shadow .2s ease;
}
.key-input::placeholder { color: var(--ink-soft); opacity: .6; }
.key-input:focus-visible { border-color: var(--gilt-2); box-shadow: inset 0 1px 3px rgba(90,60,24,.15), 0 0 0 3px rgba(220,180,85,.25); }
.set-keyrow { display: flex; align-items: baseline; gap: .9rem; margin-top: .4rem;
  font-size: .9rem; font-style: italic; color: var(--ink-soft); }

/* ---------- the cameo (tap the frame to grant the camera) ---------- */
#cameo {
  --cz: clamp(150px, 22vw, 208px);
  width: var(--cz); height: calc(var(--cz) * 1.14);
  border: 0; padding: 0; cursor: pointer;
  border-radius: 50%; position: relative; overflow: hidden;
  background: radial-gradient(120% 120% at 50% 30%, #7a4a28, #43260f 70%);
  box-shadow: 0 0 0 5px var(--gilt-2), 0 0 0 7px var(--gilt-deep), 0 0 0 8px rgba(255,240,200,.3),
    0 14px 30px -10px rgba(0,0,0,.6), inset 0 0 30px rgba(0,0,0,.5);
  transition: box-shadow .25s ease;
}
#cameo:focus-visible { outline: 2px solid var(--gilt-0); outline-offset: 6px; }
#cam { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); opacity: 0; transition: opacity .5s ease; }
#cameo.live #cam { opacity: 1; }
#cameo.live .cameo-face { display: none; }
/* the kept portrait — shown the instant the camera is stopped */
#kept { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
#cameo.kept #cam, #cameo.kept .cameo-face, #cameo.kept #cameo-ring { display: none; }
.cameo-face { position: absolute; inset: 0; display: grid; place-items: center; }
.cameo-face svg { width: 42%; color: rgba(255,236,190,.55); }
#cameo-ring { position: absolute; inset: 15% 18%; border: 2px dashed rgba(255,236,180,.7); border-radius: 50%; pointer-events: none; opacity: 0; }
#cameo.live #cameo-ring { opacity: 1; animation: ring 2.4s ease-in-out infinite; }
@keyframes ring { 0%,100% { opacity: .45; } 50% { opacity: .9; } }
.cameo-hint { text-align: center; margin-top: -.2rem;
  font-size: var(--fs-line); color: var(--ink-soft); font-style: italic; }

/* ==================================================================
   OPENING SHIMMER · EMBER · SUBTITLES · THE END
================================================================== */
/* the pre-page-one page: a clean title-page feel, not a glowing blob */
#opening {
  position: absolute; inset: 0; z-index: 4; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.3rem;
  transition: opacity .7s ease;
  background: radial-gradient(120% 90% at 50% 0%, var(--paper-0), var(--paper-1) 62%, var(--paper-2));
}
#opening.gone { opacity: 0; pointer-events: none; }
.opening-mark svg { width: clamp(42px, 6vw, 60px); fill: var(--gilt-2); opacity: .45;
  filter: drop-shadow(0 1px 0 rgba(255,255,255,.35)); animation: breathe 3.6s ease-in-out infinite; }
#opening-line { font-style: italic; color: var(--ink-soft); font-size: var(--fs-line); letter-spacing: .02em; }

/* the pause button's ring breathes with the child's voice — kept snug so it
   never crowds the "done" control */
#hush { position: relative; }
#hush::after {
  content: ""; position: absolute; inset: -2px; border-radius: 50%; pointer-events: none;
  box-shadow: 0 0 0 1.5px rgba(255,196,110, calc(.14 + var(--amp, 0) * .55)),
              0 0 8px 1px rgba(255,196,110, calc(var(--amp, 0) * .45));
  transform: scale(calc(1 + var(--amp, 0) * .22));
  transition: transform .08s ease-out, box-shadow .1s ease-out;
}
#hush.on::after { box-shadow: 0 0 0 1.5px rgba(246,230,168,.22); transform: none; }

/* the finish → confirm cluster */
#confirm { display: flex; align-items: center; gap: .7rem;
  background: rgba(30,16,8,.5); border: 1px solid rgba(246,230,168,.22); border-radius: 999px;
  padding: .3rem .4rem .3rem .95rem; backdrop-filter: blur(4px); }
.confirm-q { font-style: italic; font-size: clamp(.8rem, 1.6vw, .92rem); color: #f3e6c9; }
.confirm-yes {
  border: 0; cursor: pointer; border-radius: 999px; padding: .45rem 1rem;
  font-family: var(--display); font-style: italic; font-size: clamp(.8rem, 1.6vw, .92rem); color: #3a230c;
  background: radial-gradient(60% 60% at 38% 32%, #ffe9a8, var(--gilt-1) 55%, var(--gilt-2));
  box-shadow: inset 0 1px 2px rgba(255,247,214,.7);
}
.confirm-yes { transition: transform 160ms var(--ease-out), filter .2s ease; }
.confirm-yes:active { transform: scale(.97); }
#confirm-no { border: 0; background: none; cursor: pointer; padding: .45rem .5rem;
  color: #e4cf9f; font-family: var(--display); font-style: italic; font-size: clamp(.8rem, 1.6vw, .92rem);
  text-decoration: underline dotted; text-underline-offset: 3px; }
.confirm-yes:focus-visible, #confirm-no:focus-visible { outline: 2px solid var(--gilt-0); outline-offset: 2px; }

/* the child's words, echoed in the band below the book */
#subs {
  position: fixed; left: 50%; bottom: max(2.2vh, env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(80vw, 720px); text-align: center; z-index: 20; pointer-events: none;
}
#subs:empty { display: none; }
.sub {
  display: inline-flex; align-items: baseline; gap: .55rem;
  padding: .5rem 1.15rem; border-radius: 999px; line-height: 1.4;
  background: rgba(28,15,7,.62); color: #ffe7c2; font-style: italic;
  font-size: var(--fs-line); text-wrap: pretty;
  box-shadow: 0 0 0 1px rgba(246,230,168,.22), 0 8px 22px -10px rgba(0,0,0,.7);
  animation: sayin .28s cubic-bezier(0.23,1,0.32,1);
}
.sub::before { letter-spacing: .16em; text-transform: uppercase; white-space: nowrap;
  font-size: .58em; font-style: normal; color: var(--gilt-1); opacity: .85; }
.sub.you::before { content: "you"; }
.sub.note::before { content: "the book"; }
@keyframes sayin { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* persistent controls — hush or finish, always reachable */
#controls {
  position: fixed; top: max(16px, env(safe-area-inset-top)); right: 16px; z-index: 30;
  display: flex; align-items: center; gap: .95rem;
}
.ctl-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; color: var(--gilt-0);
  background: rgba(30,16,8,.58);
  box-shadow: 0 0 0 1px rgba(246,230,168,.28), 0 6px 16px -6px rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  transition: background .2s ease, transform .1s ease, box-shadow .2s ease, color .2s ease;
}
.ctl-btn:active { transform: scale(.95); }
.ctl-btn svg { width: 20px; height: 20px; fill: currentColor; }
.ctl-btn svg[class*="ic-"] { grid-area: 1 / 1; }
.ctl-btn .ic-play, .ctl-btn .ic-micoff { display: none; }
#hush.on .ic-pause { display: none; }
#hush.on .ic-play { display: block; }
#micmute.on .ic-mic { display: none; }
#micmute.on .ic-micoff { display: block; }
#micmute.on { color: #eba3a3; box-shadow: 0 0 0 1px rgba(235,163,163,.4), 0 6px 16px -6px rgba(0,0,0,.6); }
#finish {
  border: 1px solid rgba(246,230,168,.28); border-radius: 999px; cursor: pointer;
  padding: .5rem 1rem; color: #f3e6c9; background: rgba(30,16,8,.5);
  font-family: var(--display); font-style: italic; font-size: clamp(.82rem, 1.6vw, .94rem);
  backdrop-filter: blur(4px); transition: background .2s ease;
}
.ctl-btn:focus-visible, #finish:focus-visible { outline: 2px solid var(--gilt-0); outline-offset: 2px; }

#endplate { position: absolute; inset: 4.2% 3.6% 5.4%; z-index: 9; display: grid; place-content: center; justify-items: center; gap: .9rem;
  border-radius: 4px; overflow: hidden;
  background: radial-gradient(120% 90% at 50% 0%, var(--paper-0), var(--paper-1) 62%, var(--paper-2));
  box-shadow: inset 0 0 70px -18px rgba(107,74,40,.5); }
#endplate::before { content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background: var(--grain); background-size: 160px; opacity: .26; mix-blend-mode: multiply; }
#endplate::after { content: ""; position: absolute; left: 50%; top: 8%; bottom: 8%; width: 1px; pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(107,74,40,.16), transparent); }
#endplate > * { position: relative; z-index: 1; }
.end-mark svg { width: clamp(34px, 4.5vw, 44px); fill: var(--gilt-2); opacity: .4;
  filter: drop-shadow(0 1px 0 rgba(255,255,255,.35)); }
.end-title { color: var(--ink); font-size: var(--fs-heading); font-weight: 500;
  font-variation-settings: "opsz" 96, "WONK" 1; text-wrap: balance; text-align: center; }
.the-end { font-style: italic; color: var(--ink-soft); font-size: clamp(2rem, 6vw, 3.4rem);
  font-variation-settings: "opsz" 144, "SOFT" 100; margin-top: -.4rem; }
.end-actions { display: flex; gap: 1.4rem; align-items: center; margin-top: 1rem; }
#endplate > .bookbinder { position: absolute; left: 0; right: 0; bottom: 5.5%; text-align: center; margin: 0;
  font-size: .78rem; opacity: .7; text-decoration-color: rgba(106,86,58,.35); }
#keep { font-family: var(--display); font-style: italic; font-size: 1rem; color: #3a230c; text-decoration: none;
  transition: transform 160ms var(--ease-out); display: inline-block;
  padding: .7rem 1.7rem; border-radius: 999px;
  background: radial-gradient(60% 60% at 38% 32%, #ffe9a8 0%, var(--gilt-1) 45%, var(--gilt-2) 80%);
  box-shadow: inset 0 1px 3px rgba(255,247,214,.7), 0 6px 16px -6px rgba(0,0,0,.5); }
#keep:active { transform: scale(.98); }
#keep:focus-visible { outline: 2px solid var(--gilt-0); outline-offset: 4px; }

/* ---------- settings ---------- */
#gear {
  position: fixed; top: max(16px, env(safe-area-inset-top)); left: 16px; z-index: 30;
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; color: var(--gilt-0); background: rgba(30,16,8,.5);
  box-shadow: 0 0 0 1px rgba(246,230,168,.22), 0 6px 16px -6px rgba(0,0,0,.55);
  backdrop-filter: blur(4px); transition: background .2s ease, transform .1s ease;
}
#gear:active { transform: scale(.95); }
#gear svg { width: 20px; height: 20px; }
#gear:focus-visible { outline: 2px solid var(--gilt-0); outline-offset: 2px; }

#settings { position: fixed; inset: 0; z-index: 60; background: rgba(10,6,3,.5); display: grid; place-items: center; }
.settings-card {
  width: min(90vw, 340px); max-height: min(84vh, 34rem); overflow-y: auto; color: var(--ink);
  background: radial-gradient(120% 100% at 50% 0%, var(--paper-0), var(--paper-1));
  border-radius: 14px; padding: 1.3rem 1.4rem 1.5rem;
  box-shadow: 0 30px 70px -24px rgba(0,0,0,.7), 0 0 0 1px rgba(110,75,22,.25), inset 0 0 0 1px rgba(255,255,255,.3);
  display: flex; flex-direction: column; gap: .35rem; animation: cardin .3s ease;
}
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.settings-head span { font-size: 1.2rem; font-weight: 500; color: var(--ink); font-variation-settings: "opsz" 90, "WONK" 1; }
#settings-close { border: 0; background: none; cursor: pointer; color: var(--ink-soft); font-size: 1rem; padding: .6rem .8rem; margin: -.4rem -.55rem; border-radius: 6px; line-height: 1; }
.set-label { font-size: var(--fs-label); letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--ink-label); margin-top: .7rem; font-style: italic; }
.set-select {
  font-family: var(--display); font-size: 1rem; color: var(--ink);
  background: rgba(255,255,255,.4); border: 1px solid rgba(110,75,22,.3); border-radius: 9px;
  padding: .55rem .7rem; cursor: pointer; margin-top: .3rem;
}
.set-range { width: 100%; accent-color: var(--gilt-2); cursor: pointer; margin-top: .5rem; }
.set-check { display: flex; align-items: center; gap: .55rem; margin-top: .45rem; cursor: pointer;
  font-size: .9rem; font-style: italic; color: var(--ink-soft); }
.set-check input { accent-color: var(--gilt-2); width: 1.05rem; height: 1.05rem; cursor: pointer; }
.set-check input:focus-visible { outline: 2px solid var(--gilt-2); outline-offset: 2px; }
.set-help { font-size: .78rem; line-height: 1.45; color: var(--ink-soft); font-style: italic; margin-top: .45rem; }
.set-select:focus-visible, .set-range:focus-visible, #settings-close:focus-visible { outline: 2px solid var(--gilt-2); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  #candle, #motes i, #cameo-ring, .opening-mark svg, .card > *,
  .card[data-card="invocation"] .seal, .sheet.painting::after { animation: none !important; }
  #flip.turning { animation-duration: .01s; }
  .caption .w, .sub { animation: none; }
  /* the ink animation is what makes words visible — without it, show them plainly */
  .caption .w { opacity: 1; }
  #closed, #book { transition-duration: .01s; }
  #hush::after { transition: none; transform: none; }
}
@media (max-aspect-ratio: 1/1) { #book { width: 96vw; } .card { width: 90%; } }

/* ---------- the shelf: keepsakes from other nights ---------- */
#shelf {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(3vh, env(safe-area-inset-bottom)); z-index: 22;
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  max-width: min(86vw, 720px); text-align: center;
}
.shelf-label { font-size: var(--fs-label); letter-spacing: var(--ls-label); text-transform: uppercase;
  color: var(--gilt-1); opacity: .6; font-style: italic; }
#shelf-list { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem 1.4rem; }
#shelf-list a { font-style: italic; color: #e4cf9f; opacity: .85; font-size: clamp(.82rem, 1.7vw, .95rem);
  text-decoration: underline dotted; text-decoration-color: rgba(228,207,159,.5); text-underline-offset: 3px;
  padding: .3rem .2rem; /* enough to tap */ }
#shelf-list a:focus-visible { outline: 2px solid var(--gilt-0); outline-offset: 3px; border-radius: 4px; }

/* ---------- the sideways nudge (upright phones only) ---------- */
#turnme {
  display: none; position: fixed; left: 50%; transform: translateX(-50%);
  top: max(18px, env(safe-area-inset-top)); z-index: 25;
  flex-direction: row; align-items: center; gap: .55rem;
  color: var(--gilt-1); opacity: .75; pointer-events: none;
}
#turnme svg { width: 22px; height: 22px; animation: turnphone 2.6s ease-in-out infinite; }
@keyframes turnphone {
  0%, 100% { transform: rotate(0deg); }
  35%, 70% { transform: rotate(-90deg); }
}
#turnme span { font-size: var(--fs-label); letter-spacing: .2em; text-transform: uppercase; font-style: italic; white-space: nowrap; }
@media (max-width: 620px) and (orientation: portrait) {
  #turnme { display: flex; } /* top center — the gear and controls keep to the corners */
}
@media (prefers-reduced-motion: reduce) { #turnme svg { animation: none; transform: rotate(-90deg); } }

/* ---------- the wind-down: the room grows sleepy with the goodnight ---------- */
#nightfall { position: fixed; inset: 0; z-index: 15; pointer-events: none; opacity: 0;
  background: radial-gradient(90% 80% at 50% 40%, rgba(8,4,2,.15), rgba(8,4,2,.6) 100%);
  transition: opacity 9s ease; }
body.winddown #nightfall { opacity: .5; }
body.winddown #candle { transition: opacity 9s ease; opacity: .3; animation: none; }

/* ---------- short landscape phones: every rite fits above the fold ---------- */
@media (max-height: 540px) {
  #endplate > .bookbinder { position: static; margin-top: .4rem; }
  .card { gap: .5rem; padding: 3% 6%; }
  .rite-title { font-size: clamp(1.1rem, 5.5vh, 1.6rem); }
  .rite-line { font-size: clamp(.78rem, 3.4vh, 1rem); }
  .rite-line br { display: none; }
  .seal { --sz: clamp(52px, 15vh, 88px); }
  .seal.small { --sz: clamp(44px, 12vh, 64px); }
  #cameo { --cz: clamp(104px, 30vh, 168px); }
  .hero-mark svg { width: clamp(30px, 8vh, 48px); }
  .key-input { padding: .5rem .9rem; font-size: .88rem; }
  .cameo-hint { margin-top: 0; }
}

/* hovers only where a real pointer hovers; taps must not stick */
@media (hover: hover) and (pointer: fine) {
  .seal:hover { filter: brightness(1.06); box-shadow: inset 0 2px 5px rgba(255,247,214,.8), inset 0 -6px 12px rgba(84,54,12,.55), 0 10px 24px -6px rgba(0,0,0,.6), 0 0 40px -2px rgba(255,196,110,.7); }
  .engrave-btn:hover { color: var(--gilt-2); }
  #cameo:hover { box-shadow: 0 0 0 5px var(--gilt-1), 0 0 0 7px var(--gilt-deep), 0 0 0 8px rgba(255,240,200,.45), 0 16px 34px -10px rgba(0,0,0,.65), 0 0 34px -6px rgba(255,196,110,.5), inset 0 0 30px rgba(0,0,0,.5); }
  #confirm-no:hover { color: #fff2d6; }
  .ctl-btn:hover { background: rgba(52,29,13,.72); box-shadow: 0 0 0 1px rgba(246,230,168,.45), 0 6px 16px -6px rgba(0,0,0,.65); }
  #finish:hover { background: rgba(52,29,13,.66); }
  #gear:hover { background: rgba(52,29,13,.68); }
  #settings-close:hover { color: var(--ink); }
  #shelf-list a:hover { color: #fff2d6; opacity: 1; }
}
