:root {
  --bg: #faf8f3;
  --surface: #ffffff;
  --ink: #1d1c1a;
  --muted: #5f5b53;
  --line: #3a3833;
  --ring: #b9b2a3;
  --accent: #8a5a12;
  --accent-soft: #f3e6cf;
  --heaven: #2f6d8f;
  --hell: #9a2f23;
  --cross: #2b2926;
  --halo: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513;
    --surface: #211f1c;
    --ink: #eeeae2;
    --muted: #aaa396;
    --line: #d6d0c4;
    --ring: #5b564d;
    --accent: #e0b366;
    --accent-soft: #3a2f1c;
    --heaven: #7cc0e3;
    --hell: #eb7f71;
    --cross: #cfc9bd;
    --halo: #211f1c;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  --bg: #161513;
  --surface: #211f1c;
  --ink: #eeeae2;
  --muted: #aaa396;
  --line: #d6d0c4;
  --ring: #5b564d;
  --accent: #e0b366;
  --accent-soft: #3a2f1c;
  --heaven: #7cc0e3;
  --hell: #eb7f71;
  --cross: #cfc9bd;
  --halo: #211f1c;
  --shadow: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.55;
}

.site-header {
  max-width: 1320px;
  margin: 0 auto;
  padding: 32px 16px 8px;
}

.site-header h1 {
  font-family: "EB Garamond", Georgia, serif;
  font-weight: 700;
  font-size: clamp(2rem, 5vw, 3rem);
  margin: 0;
  letter-spacing: .01em;
}

.lede { color: var(--muted); margin: 4px 0 0; }

.layout {
  max-width: 1320px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.diagram-wrap {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px;
}

#diagram { width: 100%; height: auto; display: block; }

.controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 0 4px;
  flex-wrap: wrap;
}

button {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--ring);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
}

button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.panel {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 32px);
  overflow: hidden;
  min-width: 0;
}

.panel-content { padding: 24px; overflow-y: auto; flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; }

@media (max-width: 860px) {
  .panel { position: relative; top: 0; max-height: none; }
}

.panel-kicker {
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .75rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0;
}

.panel h2 {
  font-family: "EB Garamond", Georgia, serif;
  font-size: 2rem;
  margin: 4px 0 12px;
}

.refs { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 12px; }

.refs li {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
  padding: 10px 14px;
}

.refs a { color: var(--ink); font-weight: 600; text-decoration-color: var(--accent); }
.refs blockquote { margin: 6px 0 0; font-family: "EB Garamond", Georgia, serif; font-size: 1.15rem; line-height: 1.6; }
blockquote sup { font-family: Inter, system-ui, sans-serif; font-size: .62em; font-weight: 600; color: var(--accent); margin-right: 3px; }
blockquote strong { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent-soft); border-radius: 2px; }
.refs li blockquote strong { background: var(--surface); box-shadow: 0 0 0 2px var(--surface); }
.ref-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; font-size: .95rem; }

.site-footer {
  max-width: 1320px;
  margin: 0 auto;
  padding: 8px 16px 32px;
  color: var(--muted);
  font-size: .85rem;
}

/* ---------- SVG diagram ---------- */

.ring { fill: none; stroke: var(--ring); stroke-width: 2; stroke-dasharray: 2 8; stroke-linecap: round; }

.arc { fill: none; stroke: var(--line); stroke-width: 3; transition: stroke .2s, stroke-width .2s; }
.arc.to-heaven { stroke: var(--heaven); }
.arc.to-hell { stroke: var(--hell); }
.arrowhead { fill: var(--line); }
.arrowhead.to-heaven { fill: var(--heaven); }
.arrowhead.to-hell { fill: var(--hell); }

.cross rect { fill: var(--cross); }

.stairs { fill: none; stroke: var(--line); stroke-width: 3; stroke-linejoin: round; }
.stairs-lit { fill: none; stroke: var(--accent); stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transition: opacity .3s; }
.stairs-lit.on { opacity: .4; }

.hit { cursor: pointer; outline: none; }
.hit .node-circle { fill: var(--surface); stroke: var(--line); stroke-width: 2.5; transition: fill .2s, stroke .2s, stroke-width .2s; }
.hit.heaven .node-circle { stroke: var(--heaven); }
.hit.hell .node-circle { stroke: var(--hell); }
.hit:hover .node-circle, .hit:focus-visible .node-circle { stroke-width: 4; }
.hit.active .node-circle { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 5; }

.node-label {
  font-family: "EB Garamond", Georgia, serif;
  font-weight: 700;
  fill: var(--ink);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.ref-text { font-size: 22px; fill: var(--muted); }

.step-label {
  font-weight: 700;
  font-size: 22px;
  fill: var(--ink);
  paint-order: stroke;
  stroke: var(--halo);
  stroke-width: 6px;
  stroke-linejoin: round;
}
.step-ref { font-size: 19px; fill: var(--muted); paint-order: stroke; stroke: var(--halo); stroke-width: 5px; stroke-linejoin: round; }
.step-hitbox { fill: transparent; }
.hit.step:hover .step-label, .hit.step:focus-visible .step-label, .hit.step.active .step-label { fill: var(--accent); }
.hit.step.active .step-hitbox { fill: var(--accent-soft); }

.church-icon { fill: var(--line); }

.road.lit .arc, .road.preview .arc, .road:hover .arc, .road:focus-visible .arc, .road.active .arc { stroke-width: 7; }
.arc-hit { fill: none; stroke: transparent; stroke-width: 30; pointer-events: stroke; }
.hitbox { fill: transparent; }
.church-door { fill: var(--surface); }
.ref-text, .step-ref { cursor: help; }
.ref-text:hover, .step-ref:hover { fill: var(--accent); text-decoration: underline; }

.traveler { pointer-events: none; transition: opacity .3s; }
.traveler-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 3; }
.traveler-glow { fill: var(--accent); opacity: .25; animation: pulse 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 50% { transform: scale(1.5); opacity: .08; } }
@media (prefers-reduced-motion: reduce) { .traveler-glow { animation: none; } }

/* ---------- Journeys ---------- */
.journeys { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 4px 4px 8px; }
.journeys-label { font-weight: 600; color: var(--muted); font-size: .9rem; margin-right: 4px; }
.chip { padding: 6px 14px; font-size: .9rem; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.hint { text-align: center; color: var(--muted); font-size: .85rem; margin: 4px 0 0; }
kbd { font: inherit; font-size: .8rem; border: 1px solid var(--ring); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }
@media (hover: none) { .hint { display: none; } }

/* ---------- Glossary terms & tooltip ---------- */
.term { text-decoration: underline dotted var(--accent) 2px; text-underline-offset: 3px; cursor: help; border-radius: 3px; }
.term:hover, .term:focus-visible { background: var(--accent-soft); outline: none; }

.tip {
  position: fixed;
  z-index: 50;
  max-width: min(320px, calc(100vw - 24px));
  background: var(--ink);
  color: var(--bg);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .25);
  pointer-events: none;
  font-size: .9rem;
  line-height: 1.45;
}
.tip p { margin: 0; }
.tip-title { font-weight: 700; margin-bottom: 2px !important; }
.tip-body { font-family: "EB Garamond", Georgia, serif; font-size: 1.05rem; }
.tip-foot { margin-top: 6px !important; font-size: .8rem; opacity: .75; }

.howto { padding-left: 1.2em; color: var(--muted); }
.howto li { margin: 4px 0; }

/* ---------- Quizzes ---------- */
.quiz-wrap { max-width: 1320px; margin: 0 auto; padding: 8px 16px 16px; }
.quiz-wrap > h2 { font-family: "EB Garamond", Georgia, serif; font-size: 2rem; margin: 8px 0 12px; }
.quiz-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 24px; }
.card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 24px; }
.card h3 { margin: 0 0 8px; font-size: 1.15rem; }
.muted { color: var(--muted); }
.slots { list-style: none; padding: 0; margin: 16px 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; counter-reset: slot; }
.slot { counter-increment: slot; border: 2px dashed var(--ring); border-radius: 10px; min-height: 56px; display: grid; place-items: center; text-align: center; font-weight: 600; color: var(--muted); font-size: .9rem; padding: 18px 4px 6px; position: relative; }
.slot::before { content: counter(slot); position: absolute; top: 3px; left: 7px; font-size: .7rem; color: var(--muted); }
.slot.filled { border-style: solid; border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
@media (max-width: 480px) { .slot { font-size: .72rem; } }
.choices { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.choice:disabled { opacity: .35; cursor: default; }
.choice.correct { background: var(--heaven); border-color: var(--heaven); color: var(--bg); }
.choice.wrong { background: var(--hell); border-color: var(--hell); color: var(--bg); }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.feedback { min-height: 1.5em; font-weight: 600; margin: 8px 0; }
.feedback.good { color: var(--heaven); }
.feedback.bad { color: var(--hell); }
.score { color: var(--muted); margin: 0 0 12px; }
#verse-quote { font-family: "EB Garamond", Georgia, serif; font-size: 1.25rem; margin: 12px 0 4px; border-left: 3px solid var(--accent); padding-left: 14px; }

@media (max-width: 420px) {
  button { padding: 8px 12px; font-size: .9rem; }
  .panel { padding: 18px; }
}

[hidden] { display: none !important; }

/* ---------- Guided walk ---------- */
.tour-close {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 40px; height: 40px; padding: 0; font-size: 1.5rem; line-height: 1;
  background: var(--surface);
}
.panel-content.enter-next { animation: enter-next .35s ease both; }
.panel-content.enter-back { animation: enter-back .35s ease both; }
@keyframes enter-next { from { opacity: 0; transform: translateX(24px); } }
@keyframes enter-back { from { opacity: 0; transform: translateX(-24px); } }

.guide {
  font-family: "EB Garamond", Georgia, serif;
  font-size: 1.2rem;
  line-height: 1.5;
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  margin: 0 0 12px;
}

.tour-nav {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--ring);
  background: var(--surface);
}
.tour-nav { flex-wrap: wrap; }
.tour-nav #tour-next { margin-left: auto; }
.dots { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; flex: 1 1 100%; order: -1; padding-bottom: 2px; }
.dot { width: 10px; height: 10px; padding: 0 !important; flex: 0 0 auto; border-radius: 50%; border: none; background: var(--ring); min-width: 0; }
.dot.done { background: var(--accent); opacity: .5; }
.dot.on { background: var(--accent); transform: scale(1.35); }

.route { padding-left: 1.4em; margin: 12px 0; }
.route li { margin: 6px 0; }
.route li::marker { color: var(--accent); font-weight: 700; }
.legend { color: var(--muted); font-size: .9rem; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; margin-right: 12px; white-space: nowrap; }
.swatch { display: inline-block; width: 22px; height: 4px; border-radius: 2px; }
.swatch.heaven { background: var(--heaven); }
.swatch.hell { background: var(--hell); }
.welcome-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 16px; }
button.big { font-size: 1.1rem; padding: 12px 22px; }
button.linkish { border: none; text-decoration: underline; color: var(--muted); padding: 8px 4px; }
.finish-actions { display: grid; gap: 8px; margin-top: 16px; }
.finish-actions button { text-align: left; border-radius: 12px; }

/* Welcome: point at Born */
.start-here { opacity: 0; transition: opacity .3s; pointer-events: none; }
body.welcome .start-here { opacity: 1; }
.start-here-text { font-weight: 700; font-size: 24px; fill: var(--accent); paint-order: stroke; stroke: var(--halo); stroke-width: 6px; }
.start-here-arrow { fill: var(--accent); }
body.welcome .hit[data-id="born"] .node-circle { animation: beckon 1.6s ease-in-out infinite; stroke: var(--accent); }
@keyframes beckon { 50% { stroke-width: 10; } }
@media (prefers-reduced-motion: reduce) {
  body.welcome .hit[data-id="born"] .node-circle { animation: none; stroke-width: 6; }
  .panel-content.enter-next, .panel-content.enter-back { animation: none; }
}

/* Phones: each stop of the guided walk is its own full-screen page,
   with the circle kept in view at the top. */
@media (max-width: 760px) {
  body.tour { overflow: hidden; }
  body.tour .layout {
    position: fixed; inset: 0; z-index: 30;
    display: flex; flex-direction: column; gap: 0;
    max-width: none; padding: 0;
    background: var(--bg);
  }
  body.tour .diagram-wrap { flex: 0 0 auto; height: 40vh; height: 40dvh; border-radius: 0; box-shadow: none; padding: 4px 8px; background: var(--bg); }
  body.tour .journeys, body.tour .controls, body.tour .hint { display: none; }
  body.tour #diagram { width: 100%; height: 100%; }
  body.tour .panel {
    flex: 1 1 auto; min-height: 0; max-height: none;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, .10);
  }
  body.tour .panel-content { padding: 20px 16px 16px; }
  body.tour .panel h2 { font-size: 1.75rem; padding-right: 36px; }
  body.tour .tour-nav { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  body.tour #tour-back, body.tour #tour-next { padding: 10px 14px; }
  body.tour .dots { gap: 4px; }
  body.tour .dot { width: 8px; height: 8px; }
}

/* Drawing the circle in during the walk */
#diagram .hit { transition: opacity .6s ease; }
#diagram .hit.veiled { opacity: 0; pointer-events: none; }
.stairs, .stairs-lit { transition: stroke-dasharray .9s ease, opacity .3s; }
body.tour .journeys, body.tour .controls, body.tour .hint, body.tour .quiz-wrap { display: none; }
.notice { font-size: .75rem; color: var(--muted); margin-top: 20px; }
.other-roads { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.other-roads li { line-height: 1.5; }
.other-roads .swatch { margin-right: 8px; vertical-align: middle; }
@media (prefers-reduced-motion: reduce) { #diagram .hit, .stairs, .stairs-lit { transition: none; } }

.game-link {
  display: inline-block; margin-top: 8px; padding: 6px 14px; border-radius: 999px;
  background: var(--accent-soft); color: var(--ink); font-weight: 600; text-decoration: none;
}
.game-link:hover { background: var(--accent); color: var(--bg); }
