:root {
  --desk: #15100b;
  --paper: #f1e7d2;
  --paper-2: #e6d8bb;
  --ink: #2b1f14;
  --ink-soft: #5c4a37;
  --gold: #d9b36c;
  --gold-deep: #9a7432;
  --leather: #24382c;
  --leather-2: #1a2a20;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--desk); color: var(--paper); font: 15px/1.55 var(--sans); overflow: hidden; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; }
kbd { display: inline-block; min-width: 22px; padding: 1px 6px; border: 1px solid currentColor; border-bottom-width: 2px; border-radius: 4px; font: 600 12px/1.4 var(--sans); text-align: center; opacity: .9; margin-right: 2px; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.linkish { color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px; font-size: 13px; padding: 12px 6px; }

/* ---------- stage ---------- */
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; transition: opacity .8s ease; touch-action: none; }
body.playing #stage { opacity: 1; }
#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(10,6,3,.55) 100%); opacity: 0; transition: opacity .8s; }
body.playing #vignette { opacity: 1; }
body.torn #stage { animation: torn .5s steps(2) 2; filter: sepia(.6) contrast(1.1); }
@keyframes torn { 0% { transform: translate(0) } 50% { transform: translate(-6px, 3px) skewX(-1deg) } 100% { transform: translate(4px, -2px) } }
body.torn #vignette { background: linear-gradient(100deg, transparent 47%, #f3ead7 48%, #d8c9a8 49%, transparent 50.5%), radial-gradient(120% 90% at 50% 45%, transparent 40%, rgba(60,20,10,.6) 100%); }

/* ---------- bar ---------- */
#bar { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; z-index: 20; pointer-events: none; opacity: 0; transform: translateY(-8px); transition: opacity .5s, transform .5s; }
body.playing #bar { opacity: 1; transform: none; }
#bar > * { pointer-events: auto; }
.bar-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 14px; border-radius: 999px; background: rgba(21,16,11,.55); border: 1px solid rgba(241,231,210,.18); backdrop-filter: blur(8px); font-size: 13px; text-decoration: none; color: var(--paper); }
.bar-btn:hover { border-color: var(--gold); }
.bar-right { display: flex; gap: 8px; }
#chapter-label { margin: 0; font: italic 600 17px/1.2 var(--serif); color: var(--paper); text-shadow: 0 1px 12px rgba(0,0,0,.6); text-align: center; letter-spacing: .3px; }
#chapter-label small { display: block; font: 500 11px/1.4 var(--sans); letter-spacing: 2px; text-transform: uppercase; color: var(--gold); font-style: normal; }
#btn-sound[aria-pressed="false"] { opacity: .6; text-decoration: line-through; }

/* ---------- anchored prompts ---------- */
#anchors { position: fixed; inset: 0; pointer-events: none; z-index: 8; }
#anchors > * { position: absolute; left: 0; top: 0; will-change: transform; }
.prompt { display: flex; align-items: center; gap: 10px; margin: -22px 0 0 -22px; opacity: 0; transition: opacity .3s; filter: drop-shadow(0 3px 10px rgba(0,0,0,.45)); }
.prompt.in { opacity: 1; }
.prompt.out { opacity: 0; }
.prompt svg { width: 44px; height: 44px; transform: rotate(-90deg); flex: none; }
.prompt .track { fill: rgba(21,16,11,.72); stroke: rgba(241,231,210,.35); stroke-width: 2; }
.prompt .fill { fill: none; stroke: var(--gold); stroke-width: 3.5; stroke-linecap: round; transition: stroke-dashoffset .05s linear; }
.prompt .key { position: absolute; left: 0; top: 0; width: 44px; height: 44px; display: grid; place-items: center; color: var(--gold); font-size: 18px; animation: pulse 1.6s ease-in-out infinite; }
.prompt.holding .key { animation: none; transform: scale(1.15); }
.prompt .label { background: rgba(241,231,210,.95); color: var(--ink); padding: 6px 12px; border-radius: 6px; font: 600 13px/1.3 var(--sans); white-space: nowrap; }
@keyframes pulse { 50% { transform: scale(1.18); opacity: .75; } }

.inkword { transform-origin: center; font: italic 600 clamp(34px, 5vw, 58px)/1 var(--serif); color: #fff6df; text-shadow: 0 2px 18px rgba(217,179,108,.9), 0 0 2px #3b2a1a; white-space: nowrap; translate: -50% 0; }
.inkword span { display: inline-block; opacity: 0; animation: ink .7s cubic-bezier(.2,.8,.2,1) forwards; }
.inkword.out { transition: opacity .4s; opacity: 0; }
.inkword.small { font-size: clamp(22px, 3vw, 32px); }
@keyframes ink { from { opacity: 0; transform: translateY(10px) scale(.6); filter: blur(4px); } to { opacity: 1; transform: none; filter: none; } }
.float-label { translate: -50% -100%; font: 600 12px/1.2 var(--sans); letter-spacing: 1.5px; text-transform: uppercase; color: var(--gold); text-shadow: 0 1px 8px #000; white-space: nowrap; }

.rings { width: 0; height: 0; }
.rings i { position: absolute; left: 0; top: 0; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 2px solid rgba(255,238,200,.9); box-shadow: 0 0 18px rgba(217,179,108,.7); opacity: 0; }
.rings.on i { animation: ring 1.5s ease-out infinite; }
.rings.on i:nth-child(2) { animation-delay: .5s; }
.rings.on i:nth-child(3) { animation-delay: 1s; }
@keyframes ring { from { transform: scale(.2); opacity: .95; } to { transform: scale(1.6); opacity: 0; } }

/* ---------- caption ---------- */
#caption { position: fixed; left: 50%; top: 76px; transform: translate(-50%, -8px); width: min(760px, calc(100% - 32px)); text-align: center; z-index: 9; pointer-events: none; opacity: 0; transition: opacity .6s, transform .6s; }
#caption.show { opacity: 1; transform: translate(-50%, 0); }
#caption p { display: inline; margin: 0; font: italic 500 clamp(19px, 2.3vw, 26px)/1.45 var(--serif); color: #fff8e8; text-shadow: 0 1px 2px rgba(0,0,0,.8), 0 2px 24px rgba(0,0,0,.75); box-decoration-break: clone; -webkit-box-decoration-break: clone; }

/* ---------- dialogue ---------- */
#dialogue { position: fixed; left: 50%; bottom: calc(22px + var(--safe-b)); width: min(760px, calc(100% - 24px)); transform: translate(-50%, 30px); display: flex; gap: 16px; align-items: center; padding: 14px 44px 14px 14px; background: var(--paper); color: var(--ink); border-radius: 6px; box-shadow: 0 18px 50px rgba(0,0,0,.5), inset 0 0 0 1px rgba(90,70,40,.25), inset 0 0 60px rgba(160,120,60,.18); z-index: 12; opacity: 0; pointer-events: none; transition: opacity .3s, transform .35s cubic-bezier(.2,.9,.3,1.2); cursor: pointer; }
#dialogue.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#dialogue::before { content: ""; position: absolute; inset: 5px; border: 1px solid rgba(154,116,50,.35); border-radius: 3px; pointer-events: none; }
#dialogue .face { width: 86px; height: 86px; border-radius: 50%; object-fit: cover; object-position: 50% 20%; background: #e9dcc0; border: 3px solid #fff8ea; box-shadow: 0 3px 10px rgba(0,0,0,.3); flex: none; }
.dlg-body { min-width: 0; flex: 1; }
#dialogue .who { margin: 0 0 2px; font: 600 12px/1.3 var(--sans); letter-spacing: 2px; text-transform: uppercase; color: var(--gold-deep); }
#dialogue .text { margin: 0; font: 500 clamp(18px, 2vw, 22px)/1.4 var(--serif); min-height: 2.8em; }
#dialogue[data-person="book"] .text, #dialogue[data-person="voice"] .text { font-style: italic; }
#dialogue .next { position: absolute; right: 18px; bottom: 14px; color: var(--gold-deep); opacity: 0; font-size: 20px; }
#dialogue.ready .next { opacity: 1; animation: nudge 1s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateX(4px); } }

/* ---------- choices ---------- */
#choices { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translate(-50%, 20px); width: min(640px, calc(100% - 24px)); display: grid; gap: 10px; z-index: 13; opacity: 0; pointer-events: none; transition: opacity .3s, transform .35s; }
#choices.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.choice-prompt { margin: 0 0 4px; text-align: center; font: italic 600 22px/1.3 var(--serif); color: #fff6df; text-shadow: 0 2px 16px #000; }
.choice { display: flex; gap: 14px; align-items: center; text-align: left; min-height: 56px; padding: 12px 16px; background: rgba(241,231,210,.95); color: var(--ink); border-radius: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.4); transition: transform .15s, background .15s, box-shadow .15s; }
.choice strong { display: block; font: 600 19px/1.25 var(--serif); }
.choice small { display: block; font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.choice-key { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--gold-deep); color: var(--gold-deep); font: 600 12px var(--sans); }
.choice.sel, .choice:hover { transform: translateX(6px); background: #fff9ea; box-shadow: 0 10px 30px rgba(0,0,0,.45), inset 4px 0 0 var(--gold); }
.choice.dark { background: rgba(38,28,44,.94); color: #efe4f6; }
.choice.dark small { color: #c5b6d2; }
.choice.dark .choice-key { border-color: #b69ad6; color: #b69ad6; }
.choice.dark.sel, .choice.dark:hover { background: rgba(58,40,70,.96); box-shadow: 0 10px 30px rgba(0,0,0,.45), inset 4px 0 0 #b69ad6; }

/* ---------- minigame overlays ---------- */
#minigame { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#minigame > * { pointer-events: auto; }
.beat { position: fixed; left: 50%; top: 30%; width: 200px; height: 200px; margin: -100px 0 0 -100px; border-radius: 50%; display: grid; place-items: center; touch-action: none; }
.beat .core { width: 86px; height: 86px; border-radius: 50%; background: radial-gradient(circle, #fff3d4, #d9b36c 60%, #9a7432); box-shadow: 0 0 40px rgba(217,179,108,.7); display: grid; place-items: center; font: italic 600 30px var(--serif); color: var(--ink); transition: transform .1s; }
.beat .target { position: absolute; inset: 46px; border-radius: 50%; border: 2px dashed rgba(255,246,223,.7); }
.beat .ring { position: absolute; left: 50%; top: 50%; border-radius: 50%; border: 4px solid #fff3d4; box-shadow: 0 0 20px #d9b36c; translate: -50% -50%; }
.beat .count { position: absolute; bottom: -44px; left: 0; right: 0; text-align: center; font: 600 13px var(--sans); letter-spacing: 3px; color: #fff3d4; text-shadow: 0 1px 8px #000; }
.beat .verdict { position: absolute; top: -48px; left: 0; right: 0; text-align: center; font: italic 600 26px var(--serif); color: #fff3d4; text-shadow: 0 2px 12px #000; }
.beat.hit .core { transform: scale(1.18); }
.notes { position: fixed; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translateX(-50%); display: flex; gap: 12px; z-index: 11; }
.notes button { width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center; gap: 0; background: rgba(21,33,38,.82); border: 2px solid rgba(190,220,215,.5); color: #e9f2ee; font: italic 600 26px var(--serif); box-shadow: 0 8px 26px rgba(0,0,0,.45); transition: transform .12s, background .12s, box-shadow .12s; touch-action: none; }
.notes button small { font: 600 11px var(--sans); opacity: .7; margin-top: -6px; }
.notes button.lit { background: #e7f3ec; color: #173139; transform: scale(1.1); box-shadow: 0 0 34px rgba(190,240,230,.9); }
.notes button:disabled { opacity: .55; cursor: default; }
.meter { position: fixed; left: 50%; top: 128px; transform: translateX(-50%); display: flex; gap: 8px; z-index: 11; }
.meter i { width: 26px; height: 8px; border-radius: 4px; background: rgba(241,231,210,.25); box-shadow: inset 0 0 0 1px rgba(241,231,210,.35); transition: background .3s, box-shadow .3s; }
.meter i.on { background: var(--gold); box-shadow: 0 0 12px rgba(217,179,108,.8); }
.grip { position: fixed; left: 50%; bottom: calc(120px + var(--safe-b)); transform: translateX(-50%); padding: 10px 18px; border-radius: 999px; background: rgba(21,16,11,.7); border: 1px solid rgba(241,231,210,.25); font: 600 13px var(--sans); letter-spacing: 1px; text-transform: uppercase; color: var(--paper); transition: background .2s, color .2s; }
.grip.warn { background: #b8483a; color: #fff; animation: pulse 0.5s ease-in-out infinite; }
.grip.ok { background: rgba(63,90,58,.85); }

/* ---------- hints & touch ---------- */
#hint { position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%); display: flex; gap: 22px; font-size: 12.5px; color: rgba(241,231,210,.8); text-shadow: 0 1px 6px #000; z-index: 6; opacity: 0; transition: opacity .6s; white-space: nowrap; }
body.playing.can-move #hint { opacity: 1; }
body.touch #hint { display: none; }
#dialogue.show ~ #hint, #choices.show ~ #hint { opacity: 0 !important; }
#touch { display: none; position: fixed; left: 0; right: 0; bottom: calc(14px + var(--safe-b)); padding: 0 14px; justify-content: space-between; align-items: flex-end; z-index: 11; pointer-events: none; }
body.touch.playing #touch { display: flex; }
#touch button { pointer-events: auto; touch-action: none; width: 68px; height: 68px; border-radius: 50%; background: rgba(21,16,11,.55); border: 1px solid rgba(241,231,210,.3); color: var(--paper); font-size: 22px; backdrop-filter: blur(6px); transition: transform .08s, background .08s; }
#touch .pad { display: flex; gap: 12px; }
#touch .act { width: 84px; height: 84px; font-size: 30px; color: var(--gold); border-color: rgba(217,179,108,.6); }
#touch button.on { transform: scale(.92); background: rgba(217,179,108,.35); }
body.touch #dialogue, body.touch #choices { bottom: calc(112px + var(--safe-b)); }
body.touch:not(.can-move) #touch .pad { opacity: .25; }

#flash { position: fixed; inset: 0; pointer-events: none; z-index: 30; opacity: 0; }
#flash.go { animation: flash .5s ease-out; }
@keyframes flash { from { opacity: .95; } to { opacity: 0; } }

/* ---------- the book (cover + toc) ---------- */
#book { position: fixed; inset: 0; z-index: 25; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 24px 16px; perspective: 2200px; background: radial-gradient(60% 55% at 50% 45%, #3a2a1a 0%, #1c140d 55%, #0f0a06 100%); transition: opacity .7s ease, visibility .7s; }
body:not(.at-book) #book { opacity: 0; visibility: hidden; pointer-events: none; }
.desk-glow { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(40% 35% at 50% 40%, rgba(255,210,140,.14), transparent 70%); }
.book3d { --pw: min(430px, 44vw); --ph: min(600px, 74vh, calc(var(--pw) * 1.42)); position: relative; width: calc(var(--pw) * 2); height: var(--ph); transform-style: preserve-3d; transform: translateX(calc(var(--pw) * -.5)) rotateX(8deg); transition: transform 1.2s cubic-bezier(.3,.8,.2,1); }
.book3d.open { transform: translateX(0) rotateX(6deg); }
.leaf, .cover { position: absolute; top: 0; left: 50%; width: var(--pw); height: var(--ph); }
.leaf { background: var(--paper); color: var(--ink); border-radius: 2px 8px 8px 2px; box-shadow: 0 30px 70px rgba(0,0,0,.6), inset 14px 0 30px -12px rgba(90,60,20,.35), inset 0 0 90px rgba(160,120,60,.16); overflow: hidden; }
.leaf::after { content: ""; position: absolute; right: -6px; top: 6px; bottom: 6px; width: 6px; background: repeating-linear-gradient(90deg, #e2d4b6 0 1px, #cdbd9d 1px 2px); border-radius: 0 3px 3px 0; }
.page-inner { position: absolute; inset: 0; padding: clamp(22px, 4vh, 40px) clamp(22px, 3vw, 38px); display: flex; flex-direction: column; overflow: auto; }
.kicker { margin: 0 0 6px; font: 600 11.5px/1.4 var(--sans); letter-spacing: 3px; color: var(--gold-deep); }
.toc-title { margin: 0 0 14px; font: italic 600 clamp(22px, 2.4vw, 30px)/1.15 var(--serif); }
#toc { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
#toc button { width: 100%; display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 10px; text-align: left; padding: 10px 8px; min-height: 56px; border-radius: 6px; border-bottom: 1px dotted rgba(90,70,40,.35); transition: background .2s, transform .2s; }
#toc button:hover:not(:disabled), #toc button:focus-visible { background: rgba(217,179,108,.2); transform: translateX(4px); }
#toc .num { font: italic 600 24px/1 var(--serif); color: var(--gold-deep); }
#toc strong { display: block; font: 600 clamp(17px, 1.6vw, 20px)/1.2 var(--serif); }
#toc small { display: block; font-size: 12px; color: var(--ink-soft); }
#toc .state { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
#toc .state.new { color: #8a3a2a; font-weight: 600; }
#toc .state.done { color: #3f6a45; font-weight: 600; }
#toc button:disabled { opacity: .45; cursor: default; }
.toc-foot { margin: auto 0 0; padding-top: 12px; display: flex; justify-content: space-between; flex-wrap: wrap; }

.cover { transform-origin: left center; transform-style: preserve-3d; transition: transform 1.3s cubic-bezier(.4,.1,.2,1); padding: 0; z-index: 2; text-align: center; }
.book3d.open .cover { transform: rotateY(-178deg); pointer-events: none; }
.book3d.open .cover .cover-back { pointer-events: auto; }
.cover-front, .cover-back { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 3px 10px 10px 3px; }
.cover-front { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 36px 28px; color: var(--gold); background: radial-gradient(90% 70% at 50% 35%, #2f4a38 0%, var(--leather) 45%, var(--leather-2) 100%); box-shadow: 0 40px 80px rgba(0,0,0,.65), inset 10px 0 18px -6px rgba(0,0,0,.6), inset 0 0 0 1px rgba(217,179,108,.2); }
.cover-front::before { content: ""; position: absolute; inset: 0; border-radius: inherit; opacity: .35; mix-blend-mode: overlay; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E"); }
.cover-frame { position: absolute; inset: 18px; border: 1.5px solid rgba(217,179,108,.55); border-radius: 4px 8px 8px 4px; box-shadow: inset 0 0 0 5px rgba(0,0,0,.12), inset 0 0 0 6px rgba(217,179,108,.25); }
.cover-sigil { font-size: 54px; line-height: 1; text-shadow: 0 0 24px rgba(217,179,108,.6); animation: glow 4s ease-in-out infinite; }
@keyframes glow { 50% { text-shadow: 0 0 40px rgba(255,220,150,.95); transform: scale(1.06); } }
.cover-kicker { font: 600 11.5px/1.5 var(--sans); letter-spacing: 3.5px; text-transform: uppercase; color: #cdb07a; max-width: 240px; }
.cover-title { font: 600 clamp(46px, 6vw, 76px)/.92 var(--serif); color: #ecd29a; text-shadow: 0 2px 0 rgba(0,0,0,.4), 0 0 30px rgba(217,179,108,.25); }
.cover-title em { font-style: italic; color: #f5e2b3; }
.cover-author { font: italic 500 18px var(--serif); color: #cdb07a; }
.cover-open { margin-top: 18px; display: inline-flex; gap: 10px; align-items: center; min-height: 48px; padding: 10px 22px; border-radius: 999px; background: var(--gold); color: #1d160e; font: 600 14px var(--sans); box-shadow: 0 8px 24px rgba(0,0,0,.4); transition: transform .2s, background .2s; }
.cover:hover .cover-open { transform: translateY(-2px); background: #ecc988; }
.cover:hover .cover-front { box-shadow: 0 50px 90px rgba(0,0,0,.7), inset 10px 0 18px -6px rgba(0,0,0,.6), inset 0 0 0 1px rgba(217,179,108,.35); }
.cover-back { transform: rotateY(180deg); background: var(--paper-2); color: var(--ink); text-align: left; box-shadow: inset -14px 0 30px -12px rgba(90,60,20,.35), inset 0 0 90px rgba(160,120,60,.2); }
.cover-back .page-inner { gap: 16px; }
.cover-back .intro { font: italic 500 clamp(18px, 1.8vw, 22px)/1.45 var(--serif); }
.cover-back .how { display: grid; gap: 8px; font-size: 13.5px; color: var(--ink-soft); }
.cover-back .note { margin-top: auto; font-size: 12.5px; color: var(--ink-soft); border-top: 1px solid rgba(90,70,40,.25); padding-top: 12px; }
.book-foot { display: flex; gap: 22px; align-items: center; margin: 0; font-size: 13px; color: rgba(241,231,210,.75); z-index: 1; }
.book-foot a { text-decoration: none; padding: 12px 4px; }
.book-foot a:hover { color: var(--gold); }
.book-foot .linkish { color: rgba(241,231,210,.75); }

/* ---------- page turn ---------- */
#flip { position: fixed; inset: 0; z-index: 40; pointer-events: none; perspective: 2400px; visibility: hidden; }
#flip.on { visibility: visible; pointer-events: auto; }
.flip-leaf { position: absolute; inset: 0; transform-origin: 0 50%; transform-style: preserve-3d; transform: rotateY(100deg); }
.flip-front, .flip-back { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flip-front { background: radial-gradient(80% 80% at 60% 50%, #f5ecd9, #e7d9bb 80%, #d6c49f); color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center; box-shadow: inset 30px 0 60px -30px rgba(90,60,20,.5); }
.flip-front::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .25; mix-blend-mode: multiply; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E"); }
.flip-back { transform: rotateY(180deg); background: linear-gradient(90deg, #d8c7a3, #efe3c8); }
.flip-num { font: italic 600 clamp(64px, 10vw, 120px)/1 var(--serif); color: var(--gold-deep); }
.flip-title { font: 600 clamp(34px, 5vw, 58px)/1.05 var(--serif); }
.flip-sub { font: 600 12px/1.4 var(--sans); letter-spacing: 3px; text-transform: uppercase; color: var(--ink-soft); }
.flip-epi { max-width: 520px; font: italic 500 clamp(18px, 2vw, 23px)/1.45 var(--serif); color: var(--ink-soft); margin-top: 14px; }
.flip-leaf.cover-in { animation: leafIn .6s cubic-bezier(.3,.7,.3,1) forwards; }
.flip-leaf.turn-out { animation: leafOut 1.05s cubic-bezier(.5,0,.3,1) forwards; }
@keyframes leafIn { from { transform: rotateY(100deg); } to { transform: rotateY(0); } }
@keyframes leafOut { from { transform: rotateY(0); } to { transform: rotateY(-180deg); } }

/* ---------- end card / pause ---------- */
#endcard, #pause, #nogl { position: fixed; inset: 0; z-index: 35; display: grid; place-items: center; padding: 16px; background: rgba(12,8,5,.55); backdrop-filter: blur(4px); }
#endcard[hidden], #pause[hidden], #nogl[hidden] { display: none; }
.end-paper { position: relative; width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto; padding: clamp(24px, 4vw, 40px); background: var(--paper); color: var(--ink); border-radius: 6px; box-shadow: 0 30px 80px rgba(0,0,0,.6), inset 0 0 90px rgba(160,120,60,.2); text-align: center; animation: rise .5s cubic-bezier(.2,.9,.3,1.1); }
.end-paper::before { content: ""; position: absolute; inset: 8px; border: 1px solid rgba(154,116,50,.4); border-radius: 3px; pointer-events: none; }
.end-paper.small { width: min(420px, 100%); }
.end-paper h2 { margin: 4px 0 12px; font: 600 clamp(30px, 4vw, 42px)/1.1 var(--serif); }
.end-text { font: italic 500 clamp(18px, 2vw, 21px)/1.5 var(--serif); color: var(--ink-soft); margin: 0 0 14px; }
.end-stat { font-size: 13px; color: var(--ink-soft); margin: 0 0 18px; }
.end-stat:empty { display: none; }
.end-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; position: relative; }
.end-actions.col { flex-direction: column; align-items: stretch; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 48px; padding: 10px 20px; border-radius: 999px; border: 1px solid rgba(90,70,40,.35); color: var(--ink); text-decoration: none; font: 600 14px var(--sans); background: transparent; transition: background .2s, transform .2s; }
.btn:hover { background: rgba(217,179,108,.2); transform: translateY(-1px); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #1d160e; }
.btn.gold:hover { background: #ecc988; }
.toggle { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 44px; font-size: 13.5px; color: var(--ink-soft); cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--gold-deep); }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.97); } to { opacity: 1; transform: none; } }
.noscript { position: fixed; inset: auto 0 0; padding: 16px; background: #532b1b; text-align: center; margin: 0; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .book3d { --pw: min(92vw, 420px); --ph: min(78vh, 640px); width: var(--pw); transform: rotateX(4deg); }
  .book3d.open { transform: rotateX(3deg); }
  .leaf, .cover { left: 0; }
  .book3d.open .cover { transform: rotateY(-100deg); opacity: 0; transition: transform 1.1s cubic-bezier(.4,.1,.2,1), opacity .5s .6s; }
  .book-foot { gap: 12px; font-size: 12px; flex-wrap: wrap; justify-content: center; }
  #bar { padding: 10px; }
  .bar-btn .lbl { display: none; }
  .bar-btn { padding: 8px 12px; }
  #chapter-label { font-size: 15px; }
  #chapter-label small { font-size: 10px; letter-spacing: 1.5px; }
  #caption { top: 66px; }
  #dialogue { gap: 12px; padding: 12px 34px 12px 12px; }
  #dialogue .face { width: 60px; height: 60px; }
  .notes button { width: 64px; height: 64px; }
  .meter { top: 112px; }
  #toc button { grid-template-columns: 32px 1fr auto; padding: 8px 4px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .book3d { --ph: 82vh; --pw: min(40vw, calc(82vh / 1.3)); }
  .book-foot { display: none; }
  #caption { top: 60px; }
  #dialogue .face { width: 56px; height: 56px; }
  #dialogue .text { min-height: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
body.reduced *, body.reduced *::before, body.reduced *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
