/* A Crown of Salt — Belle Époque interface */
:root {
  --ink: #0b1215;
  --night: #0f181c;
  --teal: #16323a;
  --gold: #c9a36a;
  --gold2: #ead2a0;
  --gold-dim: rgba(201, 163, 106, .38);
  --ivory: #efe5d1;
  --ivory2: #d9cdb5;
  --muted: #a39a89;
  --rose: #c98b7a;
  --wine: #7a2433;
  --up: #9fd4a8;
  --down: #e38d7f;
  --serif: "Cormorant Garamond", "Garamond", "Georgia", serif;
  --sc: "Cormorant SC", "Cormorant Garamond", serif;
  --caps: "Cinzel", "Cormorant SC", serif;
  --fs: 1.24rem;
  --page-bg: linear-gradient(180deg, rgba(12, 19, 23, .90), rgba(9, 14, 17, .94));
  --page-fg: #ece3cf;
  --page-dim: #b9ae99;
  --page-border: rgba(201, 163, 106, .30);
  --choice-bg: rgba(22, 40, 46, .55);
  --choice-hover: rgba(38, 64, 70, .75);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--ink); color: var(--ivory); overflow: hidden; }
body { font-family: var(--serif); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
img { display: block; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#app.size-s { --fs: 1.1rem; } #app.size-l { --fs: 1.4rem; } #app.size-xl { --fs: 1.58rem; }

/* parchment theme for the page */
#app.theme-ivory {
  --page-bg: linear-gradient(180deg, rgba(244, 236, 218, .96), rgba(234, 223, 199, .97));
  --page-fg: #2b241e;
  --page-dim: #6f6353;
  --page-border: rgba(120, 90, 50, .35);
  --choice-bg: rgba(255, 252, 244, .55);
  --choice-hover: rgba(255, 250, 236, .95);
}

/* ---------- background ---------- */
#bg { position: absolute; inset: 0; overflow: hidden; background: var(--ink); }
.bgimg { position: absolute; inset: -4%; background-size: cover; background-position: center; opacity: 0; transition: opacity 1.6s ease; will-change: opacity, transform; }
.bgimg.on { opacity: 1; animation: drift 46s ease-in-out infinite alternate; }
@keyframes drift { from { transform: scale(1.02) translate(0, 0); } to { transform: scale(1.09) translate(-1.6%, -1.2%); } }
.veil { position: absolute; inset: 0; background:
  radial-gradient(120% 90% at 50% 40%, transparent 30%, rgba(5, 9, 11, .55) 75%, rgba(5, 9, 11, .9) 100%),
  linear-gradient(180deg, rgba(5, 9, 11, .55) 0%, transparent 14%, transparent 60%, rgba(5, 9, 11, .7) 100%); }
.grain { position: absolute; inset: 0; opacity: .07; mix-blend-mode: overlay; pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"); }

/* ---------- top bar ---------- */
#top { position: relative; z-index: 5; display: flex; align-items: center; gap: .6rem; padding: calc(.55rem + var(--safe-t)) .9rem .55rem;
  background: linear-gradient(180deg, rgba(6, 10, 12, .78), rgba(6, 10, 12, 0)); }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--gold2); transition: background .2s; flex: none; }
.icon-btn:hover { background: rgba(201, 163, 106, .14); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
#chap { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: .55rem; white-space: nowrap; overflow: hidden; }
#chap .num { font-family: var(--caps); color: var(--gold); font-size: 1rem; letter-spacing: .08em; }
#chap .name { font-family: var(--sc); font-size: 1.08rem; color: var(--ivory); letter-spacing: .04em; overflow: hidden; text-overflow: ellipsis; }
#chap .date { font-style: italic; color: var(--muted); font-size: .95rem; overflow: hidden; text-overflow: ellipsis; }
#gauges { display: flex; align-items: center; gap: .75rem; padding: .25rem .75rem; border-radius: 999px; border: 1px solid var(--gold-dim);
  background: rgba(8, 14, 17, .55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
#gauges:hover { border-color: var(--gold); }
.candle { width: 15px; height: 26px; display: block; }
.candle svg { width: 100%; height: 100%; overflow: visible; }
.candle .wax { fill: #efe3c8; transition: y .8s, height .8s; }
.candle .flame { transform-origin: 12px 12px; animation: flicker 1.7s infinite ease-in-out alternate; }
.candle .glow { animation: glow 2.3s infinite ease-in-out alternate; transform-origin: 12px 9px; }
@keyframes flicker { 0% { transform: scale(1, 1) rotate(-2deg); } 50% { transform: scale(.92, 1.08) rotate(2deg); } 100% { transform: scale(1.04, .95) rotate(-1deg); } }
@keyframes glow { from { opacity: .25; transform: scale(.9); } to { opacity: .5; transform: scale(1.1); } }
.candle.low .flame { animation-duration: .6s; }
.candle.out .flame, .candle.out .glow { display: none; }
.g { display: flex; align-items: center; gap: .3rem; font-size: .95rem; color: var(--ivory); }
.g .ico { font-style: normal; color: var(--gold); width: 16px; height: 16px; display: grid; place-items: center; }
.g .ico svg { width: 16px; height: 16px; fill: none; stroke: var(--gold); stroke-width: 1.5; }
.g b { font-weight: 600; font-family: var(--caps); font-size: .85rem; letter-spacing: .03em; }
.g b.neg { color: var(--down); }
.g em { display: block; width: 30px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .14); overflow: hidden; }
.g em s { display: block; height: 100%; width: 50%; background: linear-gradient(90deg, var(--gold), var(--gold2)); transition: width .8s; }
.g.flash-up em s, .g.flash-up b { background-color: var(--up); color: var(--up); }
.g.flash-down em s, .g.flash-down b { background-color: var(--down); color: var(--down); }

/* ---------- stage ---------- */
#stage { position: relative; z-index: 2; flex: 1; min-height: 0; display: flex; align-items: stretch; justify-content: center; gap: 2.2vw; padding: .4rem 2.2vw calc(1.2rem + var(--safe-b)); }
#portrait { flex: 0 0 auto; width: min(31vw, 430px); align-self: flex-end; display: flex; flex-direction: column; align-items: center;
  opacity: 0; transform: translateY(14px); transition: opacity .7s ease, transform .7s ease; margin-bottom: 1rem; }
#portrait.on { opacity: 1; transform: none; }
#portrait .frame { position: relative; width: 100%; aspect-ratio: 3 / 4; border-radius: 48% 48% 4px 4px / 22% 22% 4px 4px; overflow: hidden;
  border: 1px solid rgba(234, 210, 160, .55); box-shadow: 0 0 0 6px rgba(10, 16, 19, .55), 0 0 0 7px rgba(201, 163, 106, .35), 0 30px 60px rgba(0, 0, 0, .6); background: #111; }
#portrait .frame img { width: 100%; height: 100%; object-fit: cover; transition: opacity .5s; }
#portrait .frame::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 60px rgba(0, 0, 0, .55); border-radius: inherit; pointer-events: none; }
#portrait .corner { position: absolute; width: 22px; height: 22px; border: 1px solid var(--gold2); opacity: .7; z-index: 2; }
#portrait .corner.bl { left: 7px; bottom: 7px; border-right: 0; border-top: 0; }
#portrait .corner.br { right: 7px; bottom: 7px; border-left: 0; border-top: 0; }
#portrait .corner.tl, #portrait .corner.tr { display: none; }
#portrait .plate { margin-top: 1rem; text-align: center; padding: .45rem 1.3rem .5rem; background: rgba(8, 13, 16, .78); border: 1px solid var(--gold-dim); border-radius: 2px; min-width: 60%; }
#portrait .plate b { display: block; font-family: var(--sc); font-weight: 600; font-size: 1.22rem; letter-spacing: .05em; color: var(--gold2); }
#portrait .plate i { display: block; font-size: .95rem; color: var(--muted); }

#page { position: relative; flex: 0 1 700px; min-width: 0; display: flex; flex-direction: column; border-radius: 3px;
  background: var(--page-bg); color: var(--page-fg); border: 1px solid var(--page-border);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(255, 255, 255, .02); outline: none; overflow: hidden; }
#page::before, #page::after { content: ""; position: absolute; left: 22px; right: 22px; height: 1px; background: linear-gradient(90deg, transparent, var(--gold-dim), transparent); pointer-events: none; z-index: 2; }
#page::before { top: 9px; } #page::after { bottom: 9px; }
#log { flex: 1; overflow-y: auto; padding: 1.6rem 2.2rem .6rem; overscroll-behavior: contain;
  mask-image: linear-gradient(180deg, transparent 0, #000 2.2rem); -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 2.2rem); }
#log::-webkit-scrollbar { width: 6px; } #log::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 3px; }
.p { font-size: var(--fs); line-height: 1.56; margin: 0 0 .85em; text-wrap: pretty; hyphens: auto; }
.p.old { opacity: .62; transition: opacity .6s; }
.p em { font-style: italic; }
.p strong { font-weight: 700; }
.p.say .who { font-family: var(--sc); font-weight: 700; letter-spacing: .05em; margin-right: .45em; font-size: .92em; }
#app.theme-ivory .p.say .who { filter: brightness(.55) saturate(1.3); }
.p.say.elena { padding-left: .9rem; border-left: 2px solid var(--gold-dim); }
.p.pick { color: var(--gold2); font-style: italic; padding-left: 1.1rem; position: relative; }
#app.theme-ivory .p.pick { color: #7b5a26; }
.p.pick::before { content: "❯"; position: absolute; left: 0; font-style: normal; font-size: .8em; top: .18em; opacity: .8; }
.p.letter { font-style: italic; background: rgba(239, 229, 209, .06); border-left: 2px solid var(--rose); padding: .55rem .9rem; border-radius: 0 3px 3px 0; }
#app.theme-ivory .p.letter { background: rgba(120, 80, 40, .06); }
.p.frame-text { font-size: calc(var(--fs) * 1.05); text-align: center; color: var(--gold2); }
.w { opacity: 0; animation: wordIn .55s ease forwards; }
@keyframes wordIn { from { opacity: 0; filter: blur(2px); } to { opacity: 1; filter: none; } }
.done .w { animation: none; opacity: 1; }
a.cx { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--gold); cursor: help; }
#app.theme-night a.cx { color: var(--gold2); }
#app.theme-ivory a.cx { color: #6a4b1c; border-bottom-color: #a4793a; }
.sep { text-align: center; color: var(--gold); opacity: .6; margin: .2rem 0 1rem; letter-spacing: .6em; font-size: .9rem; }

/* memoir mode: Teodor's voice, centred on the dark */
#page.memoir { background: transparent; border-color: transparent; box-shadow: none; }
#page.memoir::before, #page.memoir::after { display: none; }
#page.memoir #log { display: flex; flex-direction: column; justify-content: center; text-align: center; mask-image: none; -webkit-mask-image: none; }
#page.memoir .p { font-size: calc(var(--fs) * 1.12); color: var(--gold2); max-width: 34em; margin-left: auto; margin-right: auto; }
#page.memoir .p.old { opacity: .5; }
#more { position: absolute; right: 1.4rem; bottom: .9rem; color: var(--gold); font-size: 1.4rem; opacity: 0; transition: opacity .3s; pointer-events: none; }
#more.on { opacity: .9; animation: bob 1.4s infinite ease-in-out; }
@keyframes bob { 50% { transform: translateY(-4px); } }

#choices { padding: .2rem 1.6rem 1.4rem; display: flex; flex-direction: column; gap: .5rem; }
#choices:empty { display: none; }
.ch { position: relative; text-align: left; font-size: calc(var(--fs) * .96); line-height: 1.35; padding: .7rem 1rem .7rem 2.35rem; border-radius: 3px;
  background: var(--choice-bg); border: 1px solid var(--page-border); color: var(--page-fg); transition: background .2s, border-color .2s, transform .15s;
  opacity: 0; animation: chIn .45s ease forwards; }
.ch:hover, .ch:focus-visible { background: var(--choice-hover); border-color: var(--gold); outline: none; }
.ch:active { transform: scale(.995); }
.ch .k { position: absolute; left: .75rem; top: .78rem; font-family: var(--caps); font-size: .78rem; color: var(--gold); opacity: .85; }
.ch.locked { opacity: .5 !important; cursor: not-allowed; }
.ch.locked .why { display: block; font-family: var(--sc); font-size: .85rem; color: var(--rose); margin-top: .15rem; letter-spacing: .03em; }
.ch.seen { border-style: dashed; }
.ch .stat-tag { position: absolute; right: .55rem; top: .4rem; font-family: var(--sc); font-size: .72rem; letter-spacing: .08em; color: var(--gold); opacity: .55; }
@keyframes chIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- toasts ---------- */
#toasts { position: absolute; z-index: 20; top: calc(4rem + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: .4rem; pointer-events: none; width: min(92vw, 520px); }
.toast { padding: .45rem 1.1rem; border-radius: 999px; background: rgba(8, 13, 16, .9); border: 1px solid var(--gold-dim); color: var(--ivory); font-size: 1rem; text-align: center;
  animation: toastIn .45s ease, toastOut .6s ease 3.6s forwards; box-shadow: 0 8px 30px rgba(0, 0, 0, .5); }
.toast.long { border-radius: 6px; font-size: 1.02rem; line-height: 1.4; animation: toastIn .45s ease, toastOut .6s ease 7.5s forwards; }
.toast.note { font-style: italic; color: var(--gold2); }
.toast .up { color: var(--up); } .toast .down { color: var(--down); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px); } }

/* ---------- overlays ---------- */
#overlay { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(4, 7, 9, .72); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); animation: fadeIn .35s ease; padding: 1rem; }
@keyframes fadeIn { from { opacity: 0; } }
.panel { position: relative; width: min(860px, 100%); max-height: calc(100% - 1rem); display: flex; flex-direction: column; background: linear-gradient(180deg, #121c21, #0c1316);
  border: 1px solid var(--gold-dim); border-radius: 4px; box-shadow: 0 40px 100px rgba(0, 0, 0, .7); overflow: hidden; }
.panel > header { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.4rem .8rem; border-bottom: 1px solid rgba(201, 163, 106, .18); }
.panel > header h2 { flex: 1; margin: 0; font-family: var(--caps); font-weight: 500; font-size: 1.15rem; letter-spacing: .14em; color: var(--gold2); }
.panel .body { overflow-y: auto; padding: 1.1rem 1.4rem 1.4rem; }
.x { width: 36px; height: 36px; border-radius: 50%; color: var(--gold2); font-size: 1.4rem; line-height: 1; }
.x:hover { background: rgba(201, 163, 106, .15); }
.tabs { display: flex; gap: .25rem; padding: 0 1.1rem; border-bottom: 1px solid rgba(201, 163, 106, .18); overflow-x: auto; }
.tabs button { padding: .65rem .9rem; font-family: var(--sc); font-size: 1.02rem; letter-spacing: .05em; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--gold2); border-bottom-color: var(--gold); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; padding: .7rem 1.4rem; border: 1px solid var(--gold); color: var(--gold2); border-radius: 2px;
  font-family: var(--caps); font-size: .92rem; letter-spacing: .14em; background: rgba(201, 163, 106, .06); transition: background .2s, color .2s; }
.btn:hover { background: rgba(201, 163, 106, .2); color: #fff6df; }
.btn.solid { background: linear-gradient(180deg, #d5b075, #b48c4f); color: #1a120a; border-color: #e8cc93; }
.btn.solid:hover { background: linear-gradient(180deg, #e2c088, #c39a5a); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.lead { font-size: 1.12rem; color: var(--ivory2); line-height: 1.5; margin: 0 0 1rem; }

/* ledger */
.gauge-row { display: grid; grid-template-columns: 9.5rem 1fr 6.5rem; gap: .8rem; align-items: center; margin: .55rem 0; }
.gauge-row .lab { font-family: var(--sc); font-size: 1.08rem; letter-spacing: .03em; color: var(--ivory); }
.bar { height: 7px; border-radius: 4px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.bar s { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold2)); }
.bar.warn s { background: linear-gradient(90deg, #a2463a, var(--down)); }
.gauge-row .word { font-style: italic; color: var(--muted); font-size: 1rem; text-align: right; }
.axis { margin: 1.1rem 0 .4rem; }
.axis .ends { display: flex; justify-content: space-between; font-family: var(--sc); color: var(--muted); font-size: .98rem; }
.axis .track { position: relative; height: 2px; background: linear-gradient(90deg, #6f9cc0, rgba(255, 255, 255, .25), #c86a5a); margin: .55rem 0; }
.axis .track i { position: absolute; top: -6px; width: 14px; height: 14px; border-radius: 50%; background: var(--gold2); border: 2px solid #0c1316; transform: translateX(-50%); box-shadow: 0 0 0 1px var(--gold); }
.sec-title { font-family: var(--caps); letter-spacing: .14em; color: var(--gold); font-size: .85rem; margin: 1.3rem 0 .6rem; }
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .8rem; }
.person { text-align: center; }
.person img, .person .noimg { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 40% 40% 3px 3px / 18% 18% 3px 3px; border: 1px solid var(--gold-dim); background: #182227; }
.person b { display: block; font-family: var(--sc); font-size: 1rem; color: var(--gold2); margin-top: .35rem; line-height: 1.15; }
.person i { display: block; font-size: .92rem; color: var(--muted); }
.person .heart { display: block; height: 3px; margin: .3rem auto 0; width: 70%; background: rgba(255, 255, 255, .1); border-radius: 2px; overflow: hidden; }
.person .heart s { display: block; height: 100%; background: var(--gold); }
.person .heart.neg s { background: var(--down); }
.clue { display: flex; gap: .8rem; padding: .7rem .2rem; border-bottom: 1px solid rgba(201, 163, 106, .12); }
.clue .pin { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--gold-dim); color: var(--gold); font-family: var(--caps); }
.clue.missing { opacity: .4; }
.clue b { font-family: var(--sc); color: var(--gold2); font-size: 1.05rem; }
.clue p { margin: .15rem 0 0; color: var(--ivory2); line-height: 1.4; }

/* codex */
.codex { display: grid; grid-template-columns: 240px 1fr; gap: 1.4rem; min-height: 50vh; }
.codex .list { border-right: 1px solid rgba(201, 163, 106, .15); padding-right: 1rem; }
.codex .list h4 { font-family: var(--caps); color: var(--gold); font-weight: 500; letter-spacing: .14em; font-size: .78rem; margin: 1rem 0 .3rem; }
.codex .list button { display: block; width: 100%; text-align: left; padding: .28rem .4rem; font-size: 1.08rem; color: var(--ivory2); border-radius: 2px; }
.codex .list button.on, .codex .list button:hover { background: rgba(201, 163, 106, .12); color: var(--gold2); }
.codex .entry h3 { font-family: var(--sc); font-weight: 600; font-size: 1.7rem; color: var(--gold2); margin: 0 0 .6rem; }
.codex .entry p { font-size: 1.18rem; line-height: 1.6; color: var(--ivory); }
.tip { position: absolute; z-index: 40; max-width: min(380px, 88vw); padding: .85rem 1rem; background: #0e171b; border: 1px solid var(--gold); border-radius: 3px; box-shadow: 0 20px 50px rgba(0, 0, 0, .7); font-size: 1.05rem; line-height: 1.45; color: var(--ivory); animation: fadeIn .2s; }
.tip b { display: block; font-family: var(--sc); color: var(--gold2); font-size: 1.12rem; margin-bottom: .25rem; }

/* settings */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 0; border-bottom: 1px solid rgba(201, 163, 106, .12); }
.set-row label { font-family: var(--sc); font-size: 1.1rem; }
.seg { display: inline-flex; border: 1px solid var(--gold-dim); border-radius: 2px; overflow: hidden; }
.seg button { padding: .4rem .8rem; font-size: 1rem; color: var(--muted); }
.seg button.on { background: rgba(201, 163, 106, .2); color: var(--gold2); }
input[type=range] { accent-color: var(--gold); width: 180px; }

/* menu */
.menu-list { display: flex; flex-direction: column; gap: .55rem; padding: 1.2rem 1.4rem 1.5rem; }
.menu-list .btn { width: 100%; }
.slots { display: grid; gap: .6rem; }
.slot { display: flex; align-items: center; gap: .8rem; padding: .7rem .9rem; border: 1px solid var(--gold-dim); border-radius: 3px; background: rgba(255, 255, 255, .02); }
.slot .meta { flex: 1; min-width: 0; }
.slot .meta b { display: block; font-family: var(--sc); color: var(--gold2); font-size: 1.05rem; }
.slot .meta i { display: block; color: var(--muted); font-size: .95rem; }
.slot .btn { padding: .45rem .8rem; font-size: .78rem; }

/* ---------- chapter card ---------- */
#cardlayer { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; background: #05080a; cursor: pointer; animation: fadeIn 1s ease; }
.card { text-align: center; padding: 2rem; }
.card .rn { font-family: var(--caps); font-size: clamp(2.6rem, 9vw, 5rem); color: var(--gold); letter-spacing: .1em; opacity: 0; animation: rise 1.4s ease .2s forwards; }
.card .ttl { font-family: var(--sc); font-weight: 500; font-size: clamp(1.8rem, 6vw, 3.4rem); color: var(--ivory); letter-spacing: .06em; margin-top: .4rem; opacity: 0; animation: rise 1.4s ease .7s forwards; }
.card .dt { font-style: italic; color: var(--muted); font-size: 1.2rem; margin-top: 1rem; opacity: 0; animation: rise 1.4s ease 1.2s forwards; }
.card .orn { width: 180px; height: 1px; margin: 1.4rem auto 0; background: linear-gradient(90deg, transparent, var(--gold), transparent); opacity: 0; animation: rise 1.4s ease 1.5s forwards; }
.card .hint { margin-top: 2.6rem; font-family: var(--sc); letter-spacing: .2em; color: var(--muted); font-size: .9rem; opacity: 0; animation: rise 1s ease 2.6s forwards; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); letter-spacing: .3em; } to { opacity: 1; transform: none; } }

/* ---------- desk ---------- */
.desk { width: min(1060px, 100%); background: radial-gradient(120% 120% at 50% 0%, #2a1d14, #120c08 70%); border-color: rgba(201, 163, 106, .5); }
.desk .body { padding-top: .4rem; }
.desk-top { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: center; justify-content: space-between; padding: .8rem 1.4rem; border-bottom: 1px solid rgba(201, 163, 106, .18); }
.desk-top .seals { font-family: var(--sc); font-size: 1.15rem; color: var(--gold2); display: flex; align-items: center; gap: .4rem; }
.wax-dot { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #c2453f, #7a1820 70%); box-shadow: 0 1px 2px rgba(0, 0, 0, .6); display: inline-block; }
.wax-dot.used { background: rgba(255, 255, 255, .12); box-shadow: none; }
.desk-top .money { font-family: var(--caps); color: var(--ivory); }
.desk-top .money .neg { color: var(--down); }
.decrees { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; padding: 1.2rem 1.4rem; }
.decree { position: relative; display: flex; flex-direction: column; text-align: left; padding: 1rem; min-height: 210px; border-radius: 2px; color: #2b2119;
  background: linear-gradient(180deg, #f3ead6, #e5d6b6); box-shadow: 0 10px 24px rgba(0, 0, 0, .5), inset 0 0 40px rgba(140, 100, 50, .18); transition: transform .2s, box-shadow .2s; }
.decree:hover { transform: translateY(-3px) rotate(-.3deg); box-shadow: 0 16px 30px rgba(0, 0, 0, .6), inset 0 0 40px rgba(140, 100, 50, .18); }
.decree h4 { margin: 0 3.4rem .45rem 0; font-family: var(--sc); font-weight: 700; font-size: 1.12rem; line-height: 1.15; color: #3a2614; }
.decree p { margin: 0; font-size: 1rem; line-height: 1.38; color: #4a3b2c; }
.decree .fx { margin-top: auto; padding-top: .7rem; display: flex; flex-wrap: wrap; gap: .25rem .55rem; font-family: var(--sc); font-size: .9rem; }
.decree .fx .up { color: #2f6b3b; } .decree .fx .down { color: #9a2e22; } .decree .fx .cost { color: #3a2614; font-weight: 700; }
.decree.sealed::after { content: ""; position: absolute; right: .7rem; top: .6rem; width: 54px; height: 54px; border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #d65a4f, #8e1c25 55%, #5e0f16); box-shadow: 0 3px 6px rgba(0, 0, 0, .45), inset 0 0 0 4px rgba(0, 0, 0, .12);
  animation: stamp .35s cubic-bezier(.3, 1.6, .5, 1); }
.decree.sealed::before { content: "E"; position: absolute; z-index: 2; right: .7rem; top: .6rem; width: 54px; height: 54px; display: grid; place-items: center; font-family: var(--caps); font-size: 1.5rem; color: rgba(255, 220, 210, .55); animation: stamp .35s cubic-bezier(.3, 1.6, .5, 1); }
.decree.na { opacity: .45; cursor: not-allowed; }
@keyframes stamp { from { transform: scale(1.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.desk-foot { display: flex; justify-content: flex-end; padding: 0 1.4rem 1.3rem; }

/* ---------- newspaper ---------- */
.paper { width: min(780px, 100%); max-height: calc(100% - 1rem); overflow-y: auto; color: #1e1a15; padding: 1.4rem 1.6rem 1.8rem;
  background: #ece2cc url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='3'/><feColorMatrix values='0 0 0 0 .45  0 0 0 0 .38  0 0 0 0 .28  0 0 0 .16 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  box-shadow: 0 40px 90px rgba(0, 0, 0, .75); font-family: "Old Standard TT", Georgia, serif; transform: rotate(-.6deg); animation: paperIn .7s cubic-bezier(.2, .9, .3, 1.1); cursor: pointer; }
@keyframes paperIn { from { transform: rotate(-8deg) scale(.6); opacity: 0; } }
.paper .mast { text-align: center; font-family: "UnifrakturMaguntia", serif; font-size: clamp(2.1rem, 7vw, 3.6rem); line-height: 1; letter-spacing: .01em; }
.paper .rule { display: flex; justify-content: space-between; border-top: 3px double #1e1a15; border-bottom: 1px solid #1e1a15; margin: .5rem 0 1rem; padding: .25rem 0; font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; }
.paper .h1 { font-weight: 700; text-align: center; font-size: clamp(1.7rem, 5.5vw, 2.6rem); line-height: 1.05; text-transform: uppercase; letter-spacing: .01em; }
.paper .h1sub { text-align: center; font-style: italic; font-size: 1.12rem; margin: .4rem 0 .8rem; }
.paper .leadtxt { font-size: 1.04rem; line-height: 1.5; column-count: 2; column-gap: 1.6rem; column-rule: 1px solid rgba(30, 26, 21, .4); text-align: justify; hyphens: auto; }
.paper .leadtxt::first-letter { font-size: 2.6em; float: left; line-height: .9; margin: .05em .08em 0 0; font-weight: 700; }
.paper .cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; border-top: 1px solid #1e1a15; margin-top: 1rem; padding-top: .8rem; }
.paper .cols div { font-size: .95rem; line-height: 1.4; }
.paper .cols b { display: block; font-size: .92rem; text-transform: uppercase; letter-spacing: .02em; margin-bottom: .25rem; line-height: 1.2; }
.paper .ad { margin-top: 1rem; border: 2px solid #1e1a15; padding: .5rem .8rem; text-align: center; font-size: .9rem; }
.paper .ad b { display: block; font-size: 1.05rem; letter-spacing: .08em; }
.paper .close-hint { text-align: center; font-family: var(--sc); font-size: .9rem; color: #6a5b45; margin-top: 1rem; letter-spacing: .15em; }

/* ---------- reflection ---------- */
.reflect .pick-row { padding: .9rem 0; border-bottom: 1px solid rgba(201, 163, 106, .14); }
.reflect .q { font-family: var(--sc); letter-spacing: .05em; color: var(--muted); font-size: .98rem; }
.reflect .mine { font-size: 1.2rem; color: var(--gold2); margin: .2rem 0 .45rem; font-style: italic; }
.reflect .dist { display: grid; gap: .3rem; }
.reflect .dist div { display: grid; grid-template-columns: 1fr 3.5rem; gap: .6rem; align-items: center; font-size: .96rem; color: var(--ivory2); }
.reflect .dist div span { position: relative; padding: .15rem .5rem; overflow: hidden; border-radius: 2px; white-space: nowrap; text-overflow: ellipsis; }
.reflect .dist div span s { position: absolute; inset: 0 auto 0 0; background: rgba(201, 163, 106, .18); z-index: -1; }
.reflect .dist div.me span s { background: rgba(201, 163, 106, .38); }
.reflect .dist div b { text-align: right; font-family: var(--caps); font-size: .85rem; color: var(--gold); }
.reflect .dist span { z-index: 0; }

/* ---------- boot ---------- */
#boot { position: absolute; inset: 0; z-index: 60; display: grid; place-items: center; background: #05080a; transition: opacity .8s; }
#boot.gone { opacity: 0; pointer-events: none; }
#boot div { font-family: var(--caps); letter-spacing: .3em; color: var(--gold); font-size: .9rem; animation: glow 1.6s infinite alternate; }

/* ---------- title ---------- */
#title { position: absolute; inset: 0; z-index: 40; overflow: hidden; background: #05080a; }
#title .art { position: absolute; inset: 0; background: url("../img/title.webp") center / cover; animation: titleDrift 60s ease-in-out infinite alternate; }
@keyframes titleDrift { from { transform: scale(1.04); } to { transform: scale(1.14) translate(1.5%, -1%); } }
#title .shade { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(4, 7, 9, .88) 0%, rgba(4, 7, 9, .55) 38%, rgba(4, 7, 9, 0) 70%), linear-gradient(0deg, rgba(4, 7, 9, .8), transparent 40%); }
#title .inner { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 6vh 7vw; max-width: 640px; }
#title h1 { margin: 0; font-family: var(--caps); font-weight: 400; font-size: clamp(2.5rem, 7vw, 4.6rem); line-height: 1; letter-spacing: .08em; color: var(--ivory);
  text-shadow: 0 2px 30px rgba(0, 0, 0, .6); opacity: 0; animation: rise 2s ease .3s forwards; }
#title h1 small { display: block; font-size: .36em; letter-spacing: .5em; color: var(--gold); margin-bottom: .7rem; }
#title .sub { font-style: italic; font-size: clamp(1.1rem, 2.5vw, 1.4rem); color: var(--ivory2); margin: 1rem 0 2.2rem; opacity: 0; animation: rise 2s ease .9s forwards; }
#title .menu { display: flex; flex-direction: column; align-items: flex-start; gap: .25rem; opacity: 0; animation: rise 1.6s ease 1.5s forwards; }
#title .menu button { font-family: var(--sc); font-size: clamp(1.25rem, 3vw, 1.5rem); letter-spacing: .08em; color: var(--ivory); padding: .3rem 0; transition: color .2s, padding .2s; }
#title .menu button:hover, #title .menu button:focus-visible { color: var(--gold2); padding-left: .5rem; outline: none; }
#title .menu button.dim { color: var(--muted); }
#title .menu button small { font-family: var(--serif); font-style: italic; font-size: .7em; color: var(--muted); letter-spacing: 0; margin-left: .5rem; }
#title .lang { position: absolute; right: 1.4rem; top: calc(1.2rem + var(--safe-t)); }
#title .foot { position: absolute; left: 7vw; bottom: calc(1.4rem + var(--safe-b)); font-size: .95rem; color: var(--muted); font-style: italic; }

/* ---------- ending ---------- */
.ending { position: absolute; inset: 0; z-index: 45; background: #05080a; overflow-y: auto; animation: fadeIn 2s; }
.ending .stage { min-height: 100%; display: grid; place-items: center; padding: 2rem 1.2rem 4.5rem; }
.end-art { width: min(440px, 80vw, calc(60vh * .75)); aspect-ratio: 3 / 4; border: 1px solid var(--gold-dim); box-shadow: 0 30px 80px rgba(0, 0, 0, .8); object-fit: cover; margin: 0 auto; animation: fadeIn 3s; }
.end-title { text-align: center; margin-top: 1.4rem; }
.end-title small { display: block; font-family: var(--caps); letter-spacing: .4em; color: var(--gold); font-size: .85rem; }
.end-title h2 { font-family: var(--sc); font-weight: 500; font-size: clamp(2rem, 6vw, 3rem); color: var(--ivory); margin: .4rem 0 .6rem; }
.end-text { max-width: 640px; margin: 0 auto; font-size: 1.24rem; line-height: 1.6; color: var(--ivory2); text-align: center; }
.epi { max-width: 640px; display: grid; grid-template-columns: 110px 1fr; gap: 1.2rem; align-items: center; animation: fadeIn 1.2s; }
.epi img, .epi .noimg { width: 110px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 40% 40% 3px 3px / 18% 18% 3px 3px; border: 1px solid var(--gold-dim); background: #182227; }
.epi h3 { margin: 0 0 .35rem; font-family: var(--sc); color: var(--gold2); font-size: 1.35rem; font-weight: 600; }
.epi p { margin: 0; font-size: 1.18rem; line-height: 1.55; color: var(--ivory); }
.memoir { max-width: 620px; font-size: 1.3rem; line-height: 1.7; font-style: italic; color: var(--ivory); text-align: center; animation: fadeIn 2s; }
.memoir p { margin: 0 0 1em; }
.memoir .sig { font-style: normal; font-family: var(--sc); color: var(--gold2); letter-spacing: .1em; }
.cap { text-align: center; color: var(--muted); font-style: italic; margin-top: 1rem; font-size: 1.05rem; }
.next-hint { position: fixed; bottom: calc(1.2rem + var(--safe-b)); left: 0; right: 0; text-align: center; font-family: var(--sc); letter-spacing: .25em; color: var(--muted); font-size: .85rem; pointer-events: none; animation: fadeIn 2s 2s both; }

/* tapestry */
.tap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1rem; }
.tap { text-align: center; }
.tap .pic { aspect-ratio: 3 / 4; border: 1px solid var(--gold-dim); background: #10181c center / cover; display: grid; place-items: center; color: rgba(201, 163, 106, .35); font-family: var(--caps); font-size: 2rem; }
.tap b { display: block; font-family: var(--sc); color: var(--gold2); margin-top: .4rem; font-size: 1.02rem; line-height: 1.2; }
.tap i { display: block; color: var(--muted); font-size: .92rem; }
.tap.locked b { color: var(--muted); }

/* ---------- mobile ---------- */
@media (max-width: 900px), (orientation: portrait) {
  #top { padding: calc(.4rem + var(--safe-t)) .5rem .4rem; gap: .35rem; }
  #chap .date { display: none; }
  #chap .name { font-size: 1rem; }
  #gauges { gap: .5rem; padding: .2rem .55rem; }
  .g em { width: 20px; }
  #stage { flex-direction: column; justify-content: flex-end; padding: 0 0 0; gap: 0; }
  #portrait { position: absolute; left: 3vw; top: 0; width: auto; height: calc(34vh - 3.5rem); margin: 0; flex-direction: row; align-items: flex-end; gap: .6rem; z-index: 1; }
  #portrait .frame { height: 100%; width: auto; aspect-ratio: 3 / 4; box-shadow: 0 0 0 4px rgba(10, 16, 19, .55), 0 0 0 5px rgba(201, 163, 106, .35), 0 20px 40px rgba(0, 0, 0, .6); }
  #portrait .plate { margin: 0 0 .4rem; min-width: 0; padding: .3rem .7rem; text-align: left; }
  #portrait .plate b { font-size: 1.05rem; }
  #portrait .plate i { font-size: .85rem; max-width: 42vw; }
  #page { flex: 0 0 auto; height: calc(66vh - 1rem); max-width: none; width: 100%; border-radius: 14px 14px 0 0; border-left: 0; border-right: 0; border-bottom: 0; margin-top: auto; }
  #log { padding: 1.3rem 1.2rem .4rem; }
  #choices { padding: .1rem .8rem calc(1rem + var(--safe-b)); gap: .4rem; }
  .ch { font-size: calc(var(--fs) * .9); padding: .6rem .8rem .6rem 2rem; }
  .ch .k { left: .6rem; top: .68rem; }
  .p { line-height: 1.5; }
  .codex { grid-template-columns: 1fr; }
  .codex .list { border-right: 0; padding-right: 0; max-height: 30vh; overflow-y: auto; border-bottom: 1px solid rgba(201, 163, 106, .15); }
  .gauge-row { grid-template-columns: 7rem 1fr; }
  .gauge-row .word { grid-column: 1 / -1; text-align: left; margin-top: -.4rem; font-size: .95rem; }
  .paper .leadtxt { column-count: 1; }
  .paper .cols { grid-template-columns: 1fr; }
  #title .inner { justify-content: flex-end; padding-bottom: 12vh; }
  #title .art { background-position: 74% center; }
  #title .shade { background: linear-gradient(0deg, rgba(4, 7, 9, .95) 0%, rgba(4, 7, 9, .6) 50%, rgba(4, 7, 9, .1) 80%); }
  .epi { grid-template-columns: 80px 1fr; }
  .epi img, .epi .noimg { width: 80px; }
  .panel { max-height: 100%; }
  #overlay { padding: .5rem; }
}
@media (max-width: 420px) { #gauges .g-court, #gauges .g-army { display: none; } }
@media (prefers-reduced-motion: reduce) { .bgimg.on, #title .art { animation: none; } .w { animation-duration: .01s; } }
