:root {
  --bg: #f4efe6;
  --surface: #fffaf2;
  --ink: #2a2622;
  --muted: #6d655c;
  --line: #ddd3c4;
  --accent: #b85c24;
  --accent-ink: #fff;
  --warm: #d97a3a;
  --cold: #c9c2b6;
  --best: #2f7d4f;
  --good: #3a6ea5;
  --ok: #9a7420;
  --bad: #a83a32;
  --radius: 12px;
  --past: #6f665c;
  --up: #2f7d4f;
  --down: #a83a32;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c; --surface: #1e2128; --ink: #e9e4da; --muted: #a49c90; --line: #333843;
    --accent: #e08a4c; --accent-ink: #1a1208; --cold: #3b404b;
    --best: #5cbf85; --good: #79a8de; --ok: #d4ad55; --bad: #e0766d; --past: #a9a194; --up: #6fcf97; --down: #ec8a80;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171c; --surface: #1e2128; --ink: #e9e4da; --muted: #a49c90; --line: #333843;
  --accent: #e08a4c; --accent-ink: #1a1208; --cold: #3b404b;
  --best: #5cbf85; --good: #79a8de; --ok: #d4ad55; --bad: #e0766d; --past: #a9a194; --up: #6fcf97; --down: #ec8a80;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  /* PT Serif has full Bulgarian Cyrillic (ѝ); Georgia does not. */
  font: 19px/1.6 "PT Serif", Cambria, "Times New Roman", serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#app { max-width: 680px; margin: 0 auto; padding: 0 16px 64px; }

.top {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 0; margin-bottom: 8px; border-bottom: 1px solid var(--line);
  font: 15px/1.2 system-ui, sans-serif;
}
.brand { color: var(--muted); letter-spacing: .04em; text-transform: uppercase; font-size: 13px; }
.link { background: none; border: 0; padding: 4px 0; color: var(--muted); }
.link:hover { color: var(--ink); }
.seg { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.seg button {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 4px 11px; font: 13px/1.4 system-ui, sans-serif; color: var(--muted);
}
.seg button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* title screen */
.title { padding-top: 24px; }
.audience { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 28px; }
.section h1 { font-size: 40px; line-height: 1.1; margin: 0 0 8px; letter-spacing: -.01em; }
.section-blurb { color: var(--muted); margin: 0 0 24px; }
.cards { display: grid; gap: 14px; }
.story-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px 20px;
}
.story-card h2 { font-size: 26px; line-height: 1.15; margin: 0 0 8px; }
.story-card .blurb { font-size: 17px; margin-bottom: 8px; }
.story-card .actions { margin-top: 14px; }
.tag {
  margin: 0 0 6px; font: 600 11px/1.3 system-ui, sans-serif; text-transform: uppercase;
  letter-spacing: .07em; color: var(--accent);
}
.blurb { font-size: 21px; color: var(--muted); margin: 0 0 16px; }
.meta { font: 14px/1.4 system-ui, sans-serif; color: var(--muted); margin: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.primary, .secondary {
  border-radius: 999px; padding: 10px 22px; font: 600 16px/1.2 system-ui, sans-serif;
  border: 1px solid var(--accent);
}
.primary { background: var(--accent); color: var(--accent-ink); }
.secondary { background: transparent; color: var(--accent); }

/* passage */
.status {
  display: flex; flex-wrap: wrap; gap: 6px 20px; align-items: center;
  font: 13px/1.4 system-ui, sans-serif; color: var(--muted); padding: 6px 0 18px;
}
.stat { display: flex; align-items: center; gap: 8px; }
.stat-label { text-transform: uppercase; letter-spacing: .05em; font-size: 11px; }
.dots { display: inline-flex; gap: 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cold); transition: background .4s; }
.dot.on { background: var(--warm); }

.scene:empty { display: none; }
.text p { margin: 0 0 1em; }
.text p:first-child::first-letter { font-size: 1.15em; }

.choices { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 10px; }
.choice {
  width: 100%; text-align: left; display: flex; gap: 14px; align-items: baseline;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; font-size: 17px; line-height: 1.45;
  transition: border-color .15s, transform .15s;
}
.choice:hover, .choice:focus-visible { border-color: var(--accent); transform: translateX(2px); outline: none; }
.num {
  flex: none; font: 600 13px/1 system-ui, sans-serif; color: var(--accent);
  border: 1px solid currentColor; border-radius: 50%; width: 22px; height: 22px;
  display: inline-grid; place-items: center; transform: translateY(-1px);
}

/* endings */
.ending-card {
  margin-top: 28px; padding: 20px 22px; background: var(--surface);
  border: 1px solid var(--line); border-left: 5px solid var(--kind, var(--accent)); border-radius: var(--radius);
}
.kind-best { --kind: var(--best); } .kind-good { --kind: var(--good); }
.kind-ok { --kind: var(--ok); } .kind-bad { --kind: var(--bad); }
.ending-card .kind { margin: 0; font: 600 12px/1 system-ui, sans-serif; text-transform: uppercase; letter-spacing: .08em; color: var(--kind); }
.ending-card h2 { margin: 6px 0 12px; font-size: 30px; line-height: 1.15; }
.ending-card h3 { margin: 16px 0 4px; font: 600 13px/1.3 system-ui, sans-serif; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.ending-card p { margin: 0; }
.learn ul { margin: 4px 0 0; padding-left: 20px; font-size: 17px; }
.ending-card .actions { margin-top: 20px; }
.sources { margin-top: 28px; font-size: 16px; }
.traps ul { margin: 4px 0 0; padding-left: 20px; font-size: 17px; }
.traps li { margin-bottom: 6px; }
.traps a { white-space: nowrap; font-size: 15px; }

/* household setup */
.setup { padding-top: 24px; }
.setup h1 { font-size: 34px; margin: 0 0 8px; }
.setup-rows { display: grid; gap: 14px; margin-top: 20px; font: 16px/1.4 system-ui, sans-serif; }
.setup .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.setup .row > span { min-width: 180px; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.setup .row.sub { padding-left: 28px; margin-top: -6px; }
.setup .who { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.setup input.name { font: inherit; padding: 6px 10px; border: 1px solid var(--line, #ccc); border-radius: 8px; background: var(--bg); color: var(--ink); min-width: 0; width: 220px; max-width: 100%; }
.sources h3 { font: 600 13px/1.3 system-ui, sans-serif; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 4px; }

.passage { animation: fade .35s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .passage { animation: none; } .choice { transition: none; } }

@media (max-width: 520px) {
  body { font-size: 18px; }
  .story-card h1 { font-size: 34px; }
  .title { padding-top: 6vh; }
}
.error, .loading { color: var(--muted); padding: 40px 0; }
a.primary, a.secondary, a.link { text-decoration: none; display: inline-block; }
.guides-link { margin-top: 48px; font: 15px/1.4 system-ui, sans-serif; }

/* guide pages */
.guide { animation: fade .35s ease-out; }
.guide h1 { font-size: 34px; line-height: 1.15; margin: 16px 0 10px; }
.guide h2 { font-size: 22px; margin: 28px 0 8px; }
.guide p, .guide li { margin: 0 0 .7em; }
.guide ul, .guide ol { padding-left: 22px; }
.guide .note {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 12px 16px; margin-top: 20px;
}
.guide .disclaimer { margin-top: 36px; border-top: 1px solid var(--line); padding-top: 14px; }
.guide-list { list-style: none; padding: 0 !important; }
.guide-list li { padding: 14px 0; border-bottom: 1px solid var(--line); margin: 0; }
.guide-list a { font-size: 20px; font-weight: 700; text-decoration: none; }
.guide-list p { margin: 4px 0 0; color: var(--muted); font-size: 17px; }

/* ---------- play view: scene band + transcript ---------- */
html[data-size="s"] body { font-size: 17px; }
html[data-size="l"] body { font-size: 21px; }
.play { padding-bottom: 24px; }
.scene-host {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding-top: max(8px, env(safe-area-inset-top, 0px)); padding-bottom: 8px; margin: 0 -2px;
}
.play .status { padding: 4px 0 14px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.kit-item {
  display: inline-block; padding: 1px 8px; margin: 2px 4px 2px 0; border: 1px solid var(--line);
  border-radius: 999px; font-size: 12px; color: var(--ink);
}
.muted { color: var(--muted); }

.transcript { display: grid; gap: 4px; }
.beat { scroll-margin-top: calc(34vh + 24px); }
.beat.past .text p { color: var(--past); }
.beat.past .text p { margin: 0 0 .7em; }
.echo {
  margin: 2px 0 6px; padding-left: 12px; border-left: 3px solid var(--accent);
  font: 600 15px/1.45 system-ui, sans-serif; color: var(--accent);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px 12px; }
.chip {
  font: 12px/1.3 system-ui, sans-serif; padding: 3px 9px; border-radius: 999px;
  border: 1px solid currentColor; font-variant-numeric: tabular-nums;
}
.chip.up { color: var(--up); } .chip.down { color: var(--down); }
.beat.past + .beat.now { margin-top: 10px; padding-top: 18px; border-top: 1px dashed var(--line); }

/* reveal: paragraphs fade in one by one, choices after them; a tap shows all */
@keyframes beat-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
/* --step: time between paragraphs. The first paragraph starts at once, so a click always shows something. */
.beat { --step: .3s; }
.beat.revealing .reveal { opacity: 0; animation: beat-rise .4s ease-out forwards; animation-delay: calc(var(--i) * var(--step)); }
.beat.revealing .choices, .beat.revealing .ending-card { opacity: 0; animation: beat-rise .4s ease-out forwards; animation-delay: calc(var(--n) * var(--step) + .15s); }
/* "more is coming": pulsing dots until the options arrive; a tap shows everything at once */
.reveal-more { display: none; margin: 6px 0 0; font: 13px/1.4 system-ui, sans-serif; color: var(--muted); }
.beat.revealing .reveal-more { display: flex; align-items: center; gap: 8px; animation: more-out .2s forwards; animation-delay: calc(var(--n) * var(--step) + .1s); }
@keyframes more-out { to { opacity: 0; visibility: hidden; height: 0; margin: 0; } }
.pulse { display: inline-flex; gap: 4px; }
.pulse i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: dot 1s infinite ease-in-out; }
.pulse i:nth-child(2) { animation-delay: .15s; } .pulse i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 80%, 100% { opacity: .25; transform: none; } 40% { opacity: 1; transform: translateY(-2px); } }
.thinking { display: flex; align-items: center; gap: 8px; margin: 6px 0 4px; font: 13px/1.4 system-ui, sans-serif; color: var(--muted); }
html[data-speed="instant"] .beat.revealing .reveal-more { display: none; }
html[data-speed="instant"] .beat.revealing .reveal,
html[data-speed="instant"] .beat.revealing .choices,
html[data-speed="instant"] .beat.revealing .ending-card { animation: none; opacity: 1; }
html.motion-off .beat.revealing * { animation-duration: .01s !important; animation-delay: 0s !important; }
@media (prefers-reduced-motion: reduce) { .beat.revealing * { animation: none !important; opacity: 1 !important; } .beat.revealing .reveal-more { display: none; } .pulse i { animation: none; opacity: .6; } }
html.motion-off .beat.revealing .reveal-more { display: none; }

.choice.locked { opacity: .6; cursor: not-allowed; transform: none !important; }
.choice.locked .num { border: 0; }
.needs { display: block; font: 12px/1.3 system-ui, sans-serif; color: var(--muted); margin-top: 3px; }

.trail ol { margin: 4px 0 0; padding-left: 22px; font-size: 16px; }
.trail li { margin-bottom: 4px; }

/* endings collection on the story card */
.endings-map { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.endings-map li {
  font: 12px/1.3 system-ui, sans-serif; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line);
}
.endings-map li.unknown { color: var(--muted); border-style: dashed; min-width: 30px; text-align: center; }
.endings-map li.found { color: var(--kind, var(--accent)); border-color: currentColor; }

/* settings */
.settings { margin-top: 36px; font: 14px/1.4 system-ui, sans-serif; color: var(--muted); }
.settings summary { cursor: pointer; }
.settings-rows { display: grid; gap: 10px; margin-top: 12px; }
.settings .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.settings .row > span { min-width: 120px; }

/* wide screens: picture on the left, story on the right */
@media (min-width: 960px) {
  #app:has(.play) { max-width: 1180px; }
  .play { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 640px); column-gap: 40px; align-items: start; }
  .play .scene-host { grid-column: 1; grid-row: 1 / span 3; top: 16px; padding-top: 0; }
  .play .scene-band { max-height: none; }
  .play .status, .play .ai-bar, .play .transcript, .play .settings { grid-column: 2; }
  .beat { scroll-margin-top: 24px; }
}

/* confidence question */
.choice.asking { border-color: var(--accent); }
.ask-sure {
  margin: 8px 0 4px 36px; padding: 10px 12px; border-left: 3px solid var(--accent);
  font: 14px/1.4 system-ui, sans-serif; animation: beat-rise .3s ease-out;
}
.ask-sure p { margin: 0 0 8px; color: var(--ink); }
.ask-sure .seg button { padding: 6px 12px; font-size: 14px; color: var(--ink); }
.ask-sure .seg .skip { color: var(--muted); border-style: dashed; }
.sure-tag { font-weight: 400; color: var(--muted); }
.sure ul { margin: 4px 0 0; padding-left: 20px; font-size: 16px; }
.sure .verdict { font: 600 12px/1 system-ui, sans-serif; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.sure .verdict.good { color: var(--up); } .sure .verdict.trap { color: var(--down); }
.calib p { margin: 10px 0 2px; font-size: 15px; color: var(--muted); }
.calib ul { font-size: 15px; }

/* clocks */
.stat.clock { gap: 6px; }
.clock-ring svg path { fill: var(--cold); transition: fill .4s; }
.clock-ring svg path.on { fill: var(--accent); }
.stat.clock.full .clock-ring svg path.on { fill: var(--bad); }
.clock-full { font: 600 11px/1 system-ui, sans-serif; color: var(--bad); text-transform: uppercase; letter-spacing: .05em; }
.chip.clock { color: var(--accent); }

/* --- fellow travellers --------------------------------------------------- */
.companions { margin: 4px 0 10px; }
.companion-line {
  margin: 0 0 .55em; padding: 4px 0 4px 12px; border-left: 3px solid var(--line);
  font-style: italic;
}
.companion-line.argue { border-left-color: var(--accent); }
.companion-line .who {
  display: inline-block; font: 600 12px/1.6 system-ui, sans-serif; font-style: normal;
  letter-spacing: .04em; text-transform: uppercase; color: var(--accent); margin-right: 4px;
}
.companion-line[data-mood="scared"] .who, .companion-line[data-mood="worried"] .who { color: var(--muted, #777); }
.companion-line .by-ai {
  margin-left: 6px; padding: 0 5px; border: 1px solid var(--line); border-radius: 8px;
  font: 600 10px/1.5 system-ui, sans-serif; font-style: normal; color: var(--muted, #777); vertical-align: 1px;
}
.beat.past .companion-line { color: var(--past); }
.companion-line.arrive, .event-line.arrive { animation: beat-rise .4s ease-out; }
.event-line {
  margin: 0 0 .55em; padding: 4px 0 4px 12px; border-left: 3px dotted var(--muted);
}
.event-line .tag {
  font: 600 11px/1.6 system-ui, sans-serif; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-right: 4px;
}
.event-line .by-ai {
  margin-left: 6px; padding: 0 5px; border: 1px solid var(--line); border-radius: 8px;
  font: 600 10px/1.5 system-ui, sans-serif; color: var(--muted); vertical-align: 1px;
}
.beat.past .event-line { color: var(--past); }
.choices.waiting .choice { opacity: .55; cursor: progress; }
.choice .pushed {
  display: inline-block; margin-left: 8px; padding: 0 6px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font: 600 11px/1.6 system-ui, sans-serif; vertical-align: 1px;
}
.ai-note { grid-column: 1 / -1; margin: 2px 0 0; }
.ai-note progress { width: 100%; }
html.motion-off .companion-line.arrive, html.motion-off .event-line.arrive { animation: none; }
@media (prefers-reduced-motion: reduce) { .companion-line.arrive, .event-line.arrive { animation: none; } }

/* --- AI companion switch (iOS-style: grey off, green on) -------------------- */
.ai-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 8px 0 4px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 12px; font: 14px/1.35 system-ui, sans-serif; }
.switch { position: relative; flex: none; width: 46px; height: 28px; padding: 0; border: 0; border-radius: 999px;
  background: #d1d1d6; cursor: pointer; transition: background .2s ease; }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 1px rgba(0,0,0,.08); transition: transform .2s ease; }
.switch[aria-checked="true"] { background: #34c759; }
.switch[aria-checked="true"] .knob { transform: translateX(18px); }
.switch:disabled { opacity: .45; cursor: not-allowed; }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ai-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ai-label { font-weight: 600; color: var(--ink); }
.ai-status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.ai-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: #c7c7cc; }
.tone-on .ai-dot { background: #34c759; }
.tone-wait .ai-dot { background: #ff9f0a; animation: dot 1.2s infinite ease-in-out; }
.ai-bar progress { width: 100%; height: 6px; }
.ai-download { padding: 4px 12px; font-size: 13px; border-radius: 999px; }
html.motion-off .switch, html.motion-off .switch .knob { transition: none; }
@media (prefers-reduced-motion: reduce) { .switch, .switch .knob { transition: none; } .tone-wait .ai-dot { animation: none; } }

/* Footer with the legal links (not shown during play). */
.site-foot { max-width: 720px; margin: 48px auto 24px; padding: 16px 20px 0; border-top: 1px solid var(--line);
  font: 13px/1.4 system-ui, sans-serif; color: var(--muted); text-align: center; }
.site-foot a { color: var(--muted); }
.legal .address { line-height: 1.5; }
