@font-face { font-family: 'EB Garamond'; src: url('/fonts/EBGaramond-Regular.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'EB Garamond'; src: url('/fonts/EBGaramond-Italic.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: 'EB Garamond'; src: url('/fonts/EBGaramond-Medium.woff2') format('woff2'); font-weight: 500 700; font-style: normal; font-display: swap; }

:root {
  --bg: #08070b;
  --ink: #0d0c14;
  --panel: rgba(17, 14, 22, 0.86);
  --panel-solid: #15111b;
  --line: rgba(216, 180, 106, 0.28);
  --gold: #d9b86f;
  --gold-hi: #f1d79a;
  --gold-dim: #a88a52;
  --text: #f0e7d8;
  --muted: #b3a690;
  --paper: #f1e6cf;
  --paper-ink: #2a2017;
  --wax: #7c1d22;
  --serif: 'EB Garamond', 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --orb-a: #f0a64a; --orb-b: #ffe0a8;
  --pad: 16px;
  --narr-h: 0px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body { overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; outline: none; }
.vignette { position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(115% 85% at 50% 45%, transparent 45%, rgba(4, 3, 6, 0.72) 100%); }


/* ---------- caption ---------- */
.caption { position: fixed; left: var(--pad); right: var(--pad); bottom: max(28px, env(safe-area-inset-bottom)); z-index: 20;
  text-align: center; pointer-events: none; animation: fadeUp .7s ease-out both; }
.caption-main { margin: 0; font: 500 clamp(24px, 6vw, 34px)/1.15 var(--serif); color: var(--gold-hi); letter-spacing: .02em;
  text-shadow: 0 2px 18px rgba(0,0,0,.8); }
.caption-sub { margin: 8px auto 0; max-width: 34em; font: 400 15px/1.5 var(--sans); color: var(--text); opacity: .9;
  text-shadow: 0 1px 10px rgba(0,0,0,.9); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } }

/* ---------- buttons ---------- */
.btn { appearance: none; border: 1px solid var(--line); background: rgba(255,255,255,.04); color: var(--text);
  padding: 12px 18px; border-radius: 12px; font: 500 15px/1.1 var(--sans); cursor: pointer; min-height: 44px;
  transition: background .2s, border-color .2s, opacity .2s, transform .1s; }
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary { background: linear-gradient(180deg, #e2c27c, #b8934e); color: #1b130a; border-color: transparent; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: linear-gradient(180deg, #ecd08f, #c4a05c); }
.btn-quiet { background: transparent; }
.btn-small { padding: 8px 12px; min-height: 36px; font-size: 14px; }
.btn-voice { margin-left: auto; }
.btn-voice[aria-pressed=true] { border-color: var(--gold); color: var(--gold-hi); }
.btn-voice + #narrNext { margin-left: 0; }
.btn.recommended { border-color: var(--gold); color: var(--gold-hi); box-shadow: 0 0 0 1px rgba(217,184,111,.25), 0 0 24px rgba(217,184,111,.18); }
:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }

/* ---------- sheets (question, end) ---------- */
.sheet { position: fixed; z-index: 25; left: 0; right: 0; bottom: 0; background: var(--panel); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); border-radius: 22px 22px 0 0; padding: 22px var(--pad) max(18px, env(safe-area-inset-bottom));
  box-shadow: 0 -20px 60px rgba(0,0,0,.5); animation: sheetIn .55s cubic-bezier(.2,.8,.2,1) both; max-height: 82vh; overflow: auto; }
@keyframes sheetIn { from { opacity: 0; transform: translateY(24px); } }
.sheet-title { margin: 0 0 12px; font: 500 25px/1.2 var(--serif); color: var(--gold-hi); letter-spacing: .01em; }
.sheet-note { margin: -4px 0 14px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.mini-label { display: block; font: 600 11px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--gold-dim); margin: 0 0 8px; }
textarea, input[type=text] { width: 100%; background: rgba(0,0,0,.35); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font: 400 17px/1.4 var(--serif); resize: none; }
textarea::placeholder, input::placeholder { color: #7f7464; }
textarea:focus, input:focus { outline: none; border-color: var(--gold); }
.spreads { border: 0; padding: 0; margin: 16px 0 0; display: grid; gap: 8px; }
.spread-opt { display: block; cursor: pointer; }
.spread-opt input { position: absolute; opacity: 0; pointer-events: none; }
.spread-card { display: block; border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; transition: border-color .2s, background .2s; }
.spread-name { display: block; font: 500 18px/1.2 var(--serif); color: var(--text); }
.spread-desc { display: block; font-size: 13.5px; line-height: 1.4; color: var(--muted); margin-top: 3px; }
.spread-opt input:checked + .spread-card { border-color: var(--gold); background: rgba(217,184,111,.09); }
.spread-opt input:checked + .spread-card .spread-name { color: var(--gold-hi); }
.spread-opt input:focus-visible + .spread-card { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 10px 16px; min-height: 44px; cursor: pointer;
  font: 400 17px/1 var(--serif); color: var(--text); }
.chip[aria-checked=true] { border-color: var(--gold); background: rgba(217,184,111,.14); color: var(--gold-hi); }
.name-row { margin-top: 14px; display: grid; gap: 8px; }
.name-row .mini-label { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; width: max-content; }
.seg-btn { border: 0; background: transparent; padding: 9px 14px; min-height: 40px; cursor: pointer; font-size: 14px; color: var(--muted); }
.seg-btn[aria-checked=true] { background: rgba(217,184,111,.16); color: var(--gold-hi); }

/* ---------- HUD (shuffle, cut) ---------- */
.hud { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; text-align: center; padding: 18px var(--pad) max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(6,5,9,.82) 34%); animation: fadeUp .5s ease-out both; }
.hud-count { margin: 0; font: 500 24px/1.2 var(--serif); color: var(--gold-hi); letter-spacing: .02em; }
.hud-line { margin: 4px auto 0; font: italic 400 17px/1.35 var(--serif); color: var(--text); opacity: .92; max-width: 30em; min-height: 1.35em; }
.hud-hint { margin: 10px auto 0; font-size: 13.5px; color: var(--muted); max-width: 32em; line-height: 1.4; }
.hud-note { margin: 6px auto 0; max-width: 30em; font: italic 400 15px/1.35 var(--serif); color: var(--gold-hi); min-height: 0; }
.hud-note:empty { display: none; }
.btn-turn[aria-pressed=true] { border-color: var(--gold); color: var(--gold-hi); background: rgba(217,184,111,.14); box-shadow: 0 0 18px rgba(217,184,111,.2); }
.hud-actions { display: flex; gap: 10px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.hud-line.changed { animation: lineIn .6s ease both; }
.hud-count .hud-line { display: inline; margin: 0; font-size: 17px; min-height: 0; }
@keyframes lineIn { from { opacity: 0; transform: translateY(4px); } }

/* ---------- seal ---------- */
.seal-stage { position: fixed; z-index: 26; left: 0; right: 0; top: 30%; text-align: center; pointer-events: none; }
.wax { --s: 128px; width: var(--s); height: var(--s); margin: 0 auto; border-radius: 50%; display: grid; place-items: center; position: relative;
  background: radial-gradient(circle at 36% 30%, #b8434a 0%, #8a2229 34%, #5d1217 72%, #3d0a0e 100%);
  box-shadow: inset 0 0 0 calc(var(--s) * .07) rgba(0,0,0,.18), inset 0 0 0 calc(var(--s) * .085) rgba(255,190,170,.12),
    inset 0 -6px 14px rgba(0,0,0,.45), 0 10px 26px rgba(0,0,0,.55); }
.wax::before { content: ''; position: absolute; inset: -5%; border-radius: 46% 54% 50% 50% / 52% 46% 54% 48%;
  background: radial-gradient(circle at 40% 35%, #9b2c33, #5a1116 75%); z-index: -1; box-shadow: 0 6px 18px rgba(0,0,0,.5); }
.wax::after { content: ''; position: absolute; inset: 14%; border-radius: 50%; border: 1.5px solid rgba(255, 210, 190, .22);
  box-shadow: inset 0 2px 3px rgba(0,0,0,.35); }
.wax-code { font: 600 calc(var(--s) * .135)/1 var(--serif); letter-spacing: .06em; color: #f4d0c4; text-shadow: 0 -1px 0 rgba(0,0,0,.55), 0 1px 0 rgba(255,220,210,.25); z-index: 1; }
.seal-label { margin: 18px 0 0; font: 500 26px/1.2 var(--serif); color: var(--gold-hi); text-shadow: 0 2px 14px rgba(0,0,0,.9); }
.seal-sub { margin: 6px auto 0; max-width: 26em; padding: 0 var(--pad); color: var(--text); font-size: 15px; line-height: 1.45; text-shadow: 0 1px 10px rgba(0,0,0,.95); }
.seal-stage.stamp .wax { animation: stamp .55s cubic-bezier(.3,1.6,.5,1) both; }
.seal-stage.stamp .seal-label, .seal-stage.stamp .seal-sub { animation: fadeUp .6s .35s ease-out both; }
.seal-stage.leave { animation: fadeOut .6s ease-in both; }
@keyframes stamp { 0% { transform: scale(1.9) rotate(-8deg); opacity: 0; } 60% { opacity: 1; } 100% { transform: scale(1) rotate(0); } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-14px); } }

/* ---------- narration ---------- */
.narr { position: fixed; z-index: 22; left: 0; right: 0; bottom: 0; background: var(--panel); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; padding: 14px var(--pad) max(12px, env(safe-area-inset-bottom));
  max-height: 44vh; overflow: auto; cursor: pointer; transition: background .4s, border-color .4s; animation: sheetIn .6s ease-out both; }
.narr-head { display: flex; align-items: center; gap: 10px; min-height: 26px; }
.narr-kind { font: 600 11.5px/1.2 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--gold-dim); }
.narr-title { margin: 6px 0 0; font: 500 23px/1.2 var(--serif); color: var(--gold-hi); min-height: 0; }
.narr-title:empty { display: none; }
.narr-title .rev { font: italic 400 16px/1 var(--serif); color: var(--muted); margin-left: 6px; }
.narr-text { margin: 8px 0 0; font: 400 18px/1.55 var(--serif); color: var(--text); user-select: text; cursor: text; max-height: 34vh; overflow-y: auto; overscroll-behavior: contain; }
.narr-text .unshown { color: transparent; }
.narr-text.waiting .shown { color: var(--muted); font-style: italic; }
.narr-foot { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.narr-progress { flex: 1; height: 2px; background: rgba(217,184,111,.12); border-radius: 2px; overflow: hidden; }
.narr-progress i { display: block; height: 100%; width: 0; background: var(--gold-dim); }
.narr.care { background: #f3efe8; color: #1d1a16; border-color: #d6cfc2; cursor: default; }
.narr.care .narr-text { color: #1d1a16; font: 400 17px/1.55 var(--sans); }
.narr.care .narr-kind { color: #5a5248; }
.narr.care .orb { display: none; }
.narr.care .narr-progress { background: #ddd5c8; } .narr.care .narr-progress i { background: #8a7f70; }
.narr.care .btn { border-color: #b9ae9c; color: #1d1a16; }

/* presence: a breathing orb, tinted by tone */
.orb { --sz: 22px; width: var(--sz); height: var(--sz); border-radius: 50%; position: relative; flex: none;
  background: radial-gradient(circle at 50% 45%, var(--orb-b) 0%, var(--orb-a) 45%, transparent 72%);
  box-shadow: 0 0 14px 2px color-mix(in srgb, var(--orb-a) 55%, transparent), 0 0 34px 8px color-mix(in srgb, var(--orb-a) 22%, transparent);
  animation: breathe 4.2s ease-in-out infinite; transition: background 1.2s, box-shadow 1.2s; }
.orb i { position: absolute; inset: 30%; border-radius: 50%; background: var(--orb-b); filter: blur(2px); opacity: .9; }
.orb.speaking { animation: speak 0.9s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: scale(.82); opacity: .75; } 50% { transform: scale(1.05); opacity: 1; } }
@keyframes speak { 0%, 100% { transform: scale(.92); } 30% { transform: scale(1.12); } 60% { transform: scale(.98); } 80% { transform: scale(1.08); } }
body[data-tone=warm] { --orb-a: #ec9a3e; --orb-b: #ffe0a8; }
body[data-tone=playful] { --orb-a: #f2d36a; --orb-b: #fff6cf; }
body[data-tone=grave] { --orb-a: #6a3aa6; --orb-b: #c9a9f2; }
body[data-tone=calm] { --orb-a: #7f95ad; --orb-b: #dde6ef; }

/* ---------- authority card (quote) ---------- */
.quote { position: fixed; z-index: 23; left: 12px; right: 12px; bottom: calc(var(--narr-h) + 10px); max-height: calc(100dvh - var(--narr-h) - 76px);
  display: flex; perspective: 900px; pointer-events: auto; }
.qc { flex: 1; overflow: auto; position: relative; color: var(--paper-ink); border-radius: 14px; padding: 16px 18px 14px;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255,255,255,.35), transparent 60%),
    linear-gradient(180deg, #f4ead4, #e8dab9);
  box-shadow: 0 0 0 1px #b4955a, inset 0 0 0 5px #f4ead4, inset 0 0 0 6px #b99a5e, 0 18px 40px rgba(0,0,0,.6);
  animation: cardIn .7s cubic-bezier(.2,.8,.2,1) both; transform-origin: 50% 100%; }
.quote.leave .qc { animation: cardOut .45s ease-in both; }
@keyframes cardIn { from { opacity: 0; transform: rotateX(-70deg) translateY(30px); } }
@keyframes cardOut { to { opacity: 0; transform: translateY(20px) scale(.97); } }
.qc-top { display: flex; justify-content: space-between; align-items: center; }
.qc-kicker { font: 600 10.5px/1 var(--sans); letter-spacing: .2em; text-transform: uppercase; color: #8a6a32; }
.qc-sigil { width: 26px; height: 26px; fill: none; stroke: #9c7a3c; stroke-width: 1.3; }
.qc-name { margin: 4px 0 0; font: 500 22px/1.15 var(--serif); color: #23180e; }
.qc-years { font-weight: 400; font-size: 17px; color: #6b5435; white-space: nowrap; }
.qc-book { margin: 2px 0 0; font: 400 16px/1.3 var(--serif); color: #4b3a24; }
.qc-about { margin: 4px 0 0; font: 500 11.5px/1.3 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: #8a6a32; }
.qc-about:empty { display: none; }
.qc-rule { display: flex; align-items: center; gap: 10px; margin: 10px 0 8px; color: #a4844a; font-size: 12px; }
.qc-rule::before, .qc-rule::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, transparent, #b99a5e, transparent); }
.qc-text { margin: 0; font: 400 19px/1.5 var(--serif); color: #24190f; hyphens: auto; user-select: text; }
.qc-text em { font-style: italic; }
.qc-text.long { font-size: 17px; }
.qc-cite { margin: 10px 0 0; font: 400 11.5px/1.4 var(--sans); color: #6e5a3e; }

/* ---------- thread labels, zoom ---------- */
.thread-labels { position: fixed; inset: 0; pointer-events: none; z-index: 21; }
.thread-label { position: absolute; transform: translate(-50%, -100%); white-space: nowrap; max-width: 70vw; overflow: hidden; text-overflow: ellipsis;
  font: italic 400 16px/1.2 var(--serif); color: #fff1c9; padding: 5px 12px; border-radius: 999px;
  background: rgba(20, 14, 6, .72); border: 1px solid rgba(241, 215, 154, .5); box-shadow: 0 0 18px rgba(241,215,154,.25);
  transition: opacity .6s; }
.zoom-label { position: fixed; z-index: 24; transform: translateX(-50%); width: max-content; max-width: 90vw; text-align: center; pointer-events: none;
  animation: zoomIn .4s ease-out both; text-shadow: 0 2px 12px rgba(0,0,0,.95); padding: 6px 14px; border-radius: 12px; background: rgba(8,7,11,.55); }
.zoom-label p { margin: 0; }
@keyframes zoomIn { from { opacity: 0; transform: translate(-50%, 10px); } }
.zoom-pos { font: 600 11.5px/1.3 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--gold-dim); }
.zoom-name { font: 500 26px/1.2 var(--serif); color: var(--gold-hi); }
.zoom-rev { font: italic 400 16px/1.2 var(--serif); color: var(--muted); }
.zoom-hint { font-size: 12.5px; color: var(--muted); margin-top: 4px !important; }

/* ---------- end ---------- */
.end-seal { display: flex; gap: 16px; align-items: center; }
.wax-small { --s: 84px; flex: none; margin: 4px 6px; }
.verify { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.verify-ok { margin: 0 0 8px; font: 500 18px/1.35 var(--serif); color: #bfe3b4; }
.verify-ok::before { content: '✓ '; }
.verify-ok.bad { color: #f0a59a; } .verify-ok.bad::before { content: '✗ '; }
.verify-list { margin: 0; padding-left: 22px; columns: 2; column-gap: 24px; font: 400 16px/1.5 var(--serif); }
.verify-list li { break-inside: avoid; }
.verify-list .pl { color: var(--muted); font: 400 12.5px/1.3 var(--sans); display: block; }
.verify-list .rv { color: var(--muted); font-style: italic; }
.verify-rec { margin: 10px 0 0; font-size: 12px; color: var(--muted); word-break: break-all; }
.verify-rec code, .how code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--gold); }

/* ---------- how it works ---------- */
.how { border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--panel-solid); color: var(--text);
  width: min(620px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); box-shadow: 0 30px 80px rgba(0,0,0,.7); }
.how::backdrop { background: rgba(4,3,6,.7); backdrop-filter: blur(3px); }
.how-inner { padding: 22px 22px 18px; position: relative; }
.how h2 { margin: 0 0 12px; font: 500 28px/1.2 var(--serif); color: var(--gold-hi); }
.how-close { position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: transparent; color: var(--text); font-size: 24px; line-height: 1; cursor: pointer; }
.how-list { margin: 0; padding-left: 20px; display: grid; gap: 10px; font-size: 15.5px; line-height: 1.5; }
.how-list b { font: 500 18px/1.3 var(--serif); color: var(--gold-hi); display: block; }
.how-list li::marker { color: var(--gold-dim); font-family: var(--serif); }
.how-honest { margin: 16px 0 0; padding: 12px 14px; border-radius: 12px; background: rgba(255,255,255,.04); border: 1px solid var(--line);
  font-size: 14.5px; line-height: 1.5; color: var(--text); }
.how-more { margin-top: 12px; font-size: 14px; line-height: 1.55; color: var(--muted); }
.how-more summary { cursor: pointer; color: var(--gold); font-weight: 500; padding: 6px 0; }
.how-record code { word-break: break-all; }

.fatal { position: fixed; inset: auto var(--pad) 40% var(--pad); z-index: 40; text-align: center; padding: 18px; border-radius: 14px;
  background: var(--panel-solid); border: 1px solid var(--line); font: 400 18px/1.5 var(--serif); }
.fatal .btn { margin-top: 12px; }
.fatal-static { color: #eee; text-align: center; margin-top: 40vh; font-family: Georgia, serif; }

/* ---------- desktop ---------- */
@media (min-width: 760px) {
  :root { --pad: 28px; }
  .sheet.ask { left: auto; right: 32px; top: 50%; bottom: auto; width: 440px; transform: translateY(-50%); border-radius: 20px;
    border: 1px solid var(--line); animation: sideIn .6s cubic-bezier(.2,.8,.2,1) both; }
  @keyframes sideIn { from { opacity: 0; transform: translate(20px, -50%); } }
  .sheet.endp { left: auto; right: 28px; top: 76px; bottom: auto; width: 440px; max-height: calc(100vh - 104px); border-radius: 20px; border: 1px solid var(--line);
    animation: sideIn2 .6s cubic-bezier(.2,.8,.2,1) both; }
  @keyframes sideIn2 { from { opacity: 0; transform: translateX(20px); } }
  .end-seal { flex-direction: column; text-align: center; }
  .narr { left: 32px; right: auto; bottom: 28px; width: min(660px, calc(100vw - 480px)); border-radius: 18px; border: 1px solid var(--line);
    max-height: 290px; padding: 16px 22px 14px; }
  .narr-text { font-size: 20px; }
  .quote { left: auto; right: 28px; top: 76px; bottom: auto; width: 390px; max-height: calc(100vh - 110px); }
  .qc { padding: 20px 24px 16px; }
  .qc-name { font-size: 25px; }
  .qc-text { font-size: 21px; }
  .qc-text.long { font-size: 18.5px; }
  .hud { background: none; bottom: 18px; }
  .hud > * { text-shadow: 0 1px 12px rgba(0,0,0,.9); }
  .caption { bottom: 48px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01s !important; animation-iteration-count: 1 !important; transition-duration: .01s !important; }
  .orb { animation: none; }
}

.kod-err { color: #e9a08c; font-size: 14px; margin: 6px 0 0; }
