:root, [data-theme="dark"] {
  --bg-deep: #060a10;
  --bg: #0b1119;
  --panel: #0f1622;
  --ink: #e9eff5;
  --muted: #94a5b8;
  --line: #1f2b3b;
  --accent: #5eead4;
  --link: #7dd3fc;
  --card: #0d1420;
  --shadow: 0 18px 50px rgba(0,0,0,.45);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg-deep: #efe9dc;
  --bg: #f7f4ec;
  --panel: #fffdf7;
  --ink: #1d2530;
  --muted: #5b6b7e;
  --line: #ddd3bf;
  --accent: #0d7d6c;
  --link: #0369a1;
  --card: #ffffff;
  --shadow: 0 18px 50px rgba(60,50,30,.14);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; }
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1.0625rem/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
html:not(.js) .needs-js { display: none !important; }
.skip {
  position: absolute; left: -999px; top: 0; z-index: 50;
  background: var(--accent); color: #04211c; padding: .5rem 1rem; border-radius: 0 0 .5rem 0;
}
.skip:focus { left: 0; }
a { color: var(--link); }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; line-height: 1.12; text-wrap: balance; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: .9rem;
  padding: .55rem 1rem;
  background: color-mix(in srgb, var(--bg-deep) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.home { color: var(--ink); text-decoration: none; font-weight: 650; white-space: nowrap; }
.topnav { display: flex; gap: .15rem; overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
  color: var(--muted); text-decoration: none; font-size: .85rem; white-space: nowrap;
  padding: .3rem .55rem; border-radius: 2rem;
}
.topnav a[aria-current="true"] { color: var(--ink); background: var(--line); }
.spacer { flex: 1; }
.chip {
  border: 1px solid var(--line); border-radius: 2rem; padding: .25rem .8rem;
  color: var(--ink); text-decoration: none; font-size: .85rem; white-space: nowrap;
}
.icon-btn {
  background: none; border: 1px solid var(--line); border-radius: 50%;
  width: 2.75rem; height: 2.75rem; display: grid; place-items: center;
  color: var(--ink); cursor: pointer;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.icon-btn svg[hidden] { display: none; }

/* hero */
.hero-wrap {
  max-width: 60rem; margin: 0 auto; padding: 4.5rem 1.25rem 1rem; text-align: center;
}
.kicker {
  color: var(--muted); text-transform: uppercase; letter-spacing: .14em;
  font-size: .8rem; font-weight: 700; margin: 0 0 1rem;
}
.hero-text h1 { font-size: clamp(2.4rem, 6vw, 4.2rem); margin: 0 0 1.2rem; }
.deck { font-size: clamp(1.1rem, 2.4vw, 1.35rem); color: var(--muted); max-width: 46rem; margin: 0 auto; }
.hero-cta { margin: 2rem 0 0; }
.cta, .btn {
  display: inline-block; background: var(--accent); color: #04211c;
  font-weight: 700; text-decoration: none; border: none; cursor: pointer;
  padding: .7rem 1.5rem; border-radius: 2rem; font-size: 1rem;
}
[data-theme="light"] .cta, [data-theme="light"] .btn { color: #fff; }
.btn.ghost { background: none; border: 1px solid var(--line); color: var(--ink); font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }

/* story grid */
.story {
  max-width: 84rem; margin: 0 auto; padding: 2rem 1.25rem 0;
  display: grid; grid-template-columns: 1fr; gap: 2rem;
}
.story-text { min-width: 0; max-width: 46rem; }
.story-map { position: sticky; top: 3.75rem; align-self: start; order: -1; }
@media (min-width: 60rem) {
  .story { grid-template-columns: minmax(0, 7fr) minmax(0, 6fr); gap: 3rem; }
  .story-map { order: 0; }
}
.map-frame {
  background: var(--card); border: 1px solid var(--line); border-radius: 1rem;
  box-shadow: var(--shadow); padding: .75rem; position: relative;
}
.hud {
  position: absolute; top: 1.1rem; left: 1.1rem; z-index: 2;
  display: flex; align-items: baseline; gap: .6rem;
  background: color-mix(in srgb, var(--bg-deep) 82%, transparent);
  border: 1px solid var(--line); border-radius: .6rem; padding: .35rem .8rem;
}
.hud-no { font: 700 1rem ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--accent); }
.hud-name { font-size: .9rem; font-weight: 600; }
.ro-map { width: 100%; height: auto; display: block; }
.ro-map .land { fill: color-mix(in srgb, var(--accent) 7%, transparent); stroke: var(--muted); stroke-width: 1.4; stroke-linejoin: round; opacity: .9; }
.mk { cursor: pointer; }
.mk .hit { pointer-events: all; }
.mk .halo, .mk text { pointer-events: none; }
.mk .dot { fill: var(--mc, var(--accent)); stroke: var(--bg-deep); stroke-width: 1.5; transition: opacity .3s; }
.mk .halo { fill: none; stroke: var(--mc, var(--accent)); stroke-width: 1.5; opacity: 0; }
.mk text {
  fill: var(--muted); font-size: 12.5px; text-anchor: middle; font-weight: 600;
  paint-order: stroke; stroke: var(--card); stroke-width: 3px; transition: opacity .3s;
}
.mk[data-ch="pestera"] { --mc: #5eead4; } .mk[data-ch="asprete"] { --mc: #7dd3fc; }
.mk[data-ch="subteran"] { --mc: #d9a066; } .mk[data-ch="sarpe"] { --mc: #86efac; }
.mk[data-ch="nisetru"] { --mc: #60a5fa; } .mk[data-ch="sacal"] { --mc: #fbbf24; }
.mk[data-ch="pelican"] { --mc: #f9a8d4; }
.map-frame[data-active] .mk { opacity: .28; }
.map-frame[data-active] .mk.lit { opacity: 1; }
.mk.lit .halo { opacity: 1; animation: ping 2s ease-out infinite; transform-origin: center; transform-box: fill-box; }
@keyframes ping { 0% { transform: scale(.45); opacity: .9; } 100% { transform: scale(1.15); opacity: 0; } }
.mk.flash .dot { animation: flash .9s ease-out 2; }
@keyframes flash { 50% { r: 9; } }
.map-hint { color: var(--muted); font-size: .85rem; margin: .6rem .25rem 0; }

/* chapters */
.chapter { margin: 0 0 6rem; }
.chapter:last-child { margin-bottom: 2rem; }
.ch-no {
  display: inline-block; font: 700 .8rem ui-monospace, monospace;
  border: 1px solid var(--line); border-radius: .4rem; padding: .1rem .45rem; margin-right: .5rem;
  color: var(--accent); vertical-align: .1em;
}
.chapter h2 { font-size: clamp(1.7rem, 3.6vw, 2.5rem); margin: .4rem 0 .3rem; }
.sci { color: var(--muted); font-style: italic; margin: 0 0 1rem; }
.lede { font-size: 1.2rem; line-height: 1.55; margin: 0 0 1.5rem; }
.ch-pestera { --accent: #5eead4; } .ch-asprete { --accent: #7dd3fc; }
.ch-subteran { --accent: #d9a066; } .ch-sarpe { --accent: #86efac; }
.ch-nisetru { --accent: #60a5fa; } .ch-sacal { --accent: #fbbf24; }
.ch-pelican { --accent: #f9a8d4; }
[data-theme="light"] .ch-sacal { --accent: #b45309; }
[data-theme="light"] .ch-pelican { --accent: #be185d; }
[data-theme="light"] .ch-sarpe { --accent: #15803d; }
.figure { margin: 0 0 1.5rem; }
.figure img { width: 100%; height: auto; display: block; border-radius: .9rem; box-shadow: var(--shadow); }
.figure.small img { border-radius: .7rem; }
figcaption { color: var(--muted); font-size: .88rem; margin-top: .55rem; }
.credit { opacity: .85; }
.fig-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1.25rem; }
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .7rem;
  margin: 1.5rem 0; padding: 0;
}
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: .7rem; padding: .7rem .9rem; }
.stats dt { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; }
.stats dd { margin: .15rem 0 0; font-weight: 700; font-size: 1.05rem; }
.mapnote {
  color: var(--muted); font-size: .92rem; font-style: italic;
  border-left: 3px solid var(--accent); padding-left: .9rem; margin-top: 1.5rem;
}

/* river strip */
.river { background: var(--card); border: 1px solid var(--line); border-radius: 1rem; padding: 1.25rem 1.25rem 1rem; margin: 2rem 0 0; }
.river h3, .tl h3 { margin: 0 0 .3rem; font-size: 1.25rem; font-family: Georgia, serif; }
.river-lede, .tl-lede { color: var(--muted); margin: 0 0 1rem; font-size: .95rem; }
.river-track { position: relative; height: 7.5rem; margin: 0 2.75rem; }
.river-line { position: absolute; left: 0; right: 0; top: 1.2rem; height: .35rem; border-radius: 1rem; background: linear-gradient(90deg, var(--accent), var(--link)); opacity: .7; }
.river-stop { position: absolute; top: 0; transform: translateX(-50%); text-align: center; width: 8.5rem; }
.river-stop[data-x="0"] { left: 0%; } .river-stop[data-x="60"] { left: 60%; } .river-stop[data-x="100"] { left: 100%; }
.chapter, .finder, .quiz, .closing, .sources { scroll-margin-top: 3.5rem; }
.river-dot { display: block; width: .9rem; height: .9rem; border-radius: 50%; background: var(--bg); border: 3px solid var(--link); margin: .85rem auto .3rem; }
.river-stop.wall .river-dot { border-radius: .2rem; background: repeating-linear-gradient(45deg, #f87171 0 4px, #7f1d1d 4px 8px); border-color: #f87171; width: 1rem; height: 1.6rem; margin-top: .5rem; border-radius: .2rem; }
.river-lab { display: block; font-weight: 700; font-size: .85rem; }
.river-sub { display: block; color: var(--muted); font-size: .75rem; }
.swimmer { position: absolute; top: .35rem; left: 100%; transform: translateX(-50%); font-size: 1.6rem; color: var(--accent); transition: none; }
.swimmer .fish { display: inline-block; transform: scaleX(-1); }
.river.bump .swimmer { animation: bump .5s ease-out 2; }
@keyframes bump { 30% { transform: translateX(-50%) translateX(.8rem); } }
.river-ctl { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin: .5rem 0 0; }
.river-out { font-weight: 600; }
.river-fallback { color: var(--muted); }

/* timeline */
.tl { background: var(--card); border: 1px solid var(--line); border-radius: 1rem; padding: 1.25rem; margin: 2rem 0 0; }
.tl-read { display: flex; align-items: baseline; gap: 1rem; margin-bottom: .5rem; flex-wrap: wrap; }
.tl-year { font: 700 2.2rem ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--accent); min-width: 5.5rem; }
.tl-count { font-size: 1.1rem; font-weight: 600; }
.tl-bars { position: relative; display: flex; align-items: flex-end; gap: 4%; height: 10rem; border-bottom: 2px solid var(--line); padding: 0 2%; }
.tl-bar { flex: 1; height: 1.4rem; min-height: 4px; background: color-mix(in srgb, var(--accent) 30%, transparent); border: 1px solid var(--accent); border-bottom: none; border-radius: .4rem .4rem 0 0; position: relative; transition: background .3s; }
.tl-bar.passed { background: var(--accent); }
.tl-v { position: absolute; top: -1.4rem; left: 50%; transform: translateX(-50%); font-size: .75rem; font-weight: 700; white-space: nowrap; }
.tl-y { position: absolute; bottom: -1.5rem; left: 50%; transform: translateX(-50%); font-size: .8rem; color: var(--muted); }
.tl-bars { margin-bottom: 1.8rem; }
.tl-cursor { position: absolute; top: -8%; bottom: 0; width: 2px; background: var(--ink); left: 2%; opacity: .8; }
.tl-ctl { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin: 0; }
.tl-note { color: var(--muted); font-size: .85rem; flex: 1; min-width: 12rem; }

/* sections after the story */
.finder, .quiz, .closing, .sources { max-width: 60rem; margin: 0 auto; padding: 4rem 1.25rem 0; }
.finder h2, .quiz h2, .closing h2, .sources h2 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 .6rem; }
.finder > .lede, .quiz > .lede { color: var(--muted); margin: 0 0 1.5rem; }
.finder-grid { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
@media (min-width: 60rem) { .finder-grid { grid-template-columns: 1.2fr 1fr; } }
.finder-tabs { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.finder-tab { background: var(--card); border: 1px solid var(--line); color: var(--ink); border-radius: 2rem; padding: .65rem 1.1rem; cursor: pointer; font-size: .9rem; min-height: 2.75rem; }
.finder-tab[aria-pressed="true"] { background: var(--accent); color: #04211c; border-color: var(--accent); font-weight: 700; }
[data-theme="light"] .finder-tab[aria-pressed="true"] { color: #fff; }
.js .finder-panel > summary { display: none; }
.finder-panel { border: 1px solid var(--line); border-radius: .9rem; padding: 1rem 1.25rem; margin-bottom: .7rem; background: var(--card); }
.js .finder-panel { display: none; }
.js .finder-panel.open { display: block; }
.finder-panel summary { cursor: pointer; font-weight: 700; }
.finder-panel ul { list-style: none; margin: .5rem 0 0; padding: 0; }
.js .finder-panel ul { margin-top: 0; }
.finder-panel li { padding: .6rem 0; border-top: 1px solid var(--line); }
.finder-panel li:first-child { border-top: none; }
.finder-link { font-weight: 700; font-size: 1.05rem; }
.badge { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; border-radius: 2rem; padding: .1rem .6rem; margin-left: .5rem; white-space: nowrap; }
.badge.home { background: var(--accent); color: #04211c; font-weight: 700; }
[data-theme="light"] .badge.home { color: #fff; }
.badge.neighbour { border: 1px solid var(--line); color: var(--muted); }
.why { display: block; color: var(--muted); font-size: .92rem; }
.ch-ref { display: block; font-size: .78rem; color: var(--muted); }
.finder-map .map-frame, .finder-map .ro-map { background: var(--card); border-radius: 1rem; }
.finder-map { border: 1px solid var(--line); border-radius: 1rem; padding: .75rem; background: var(--card); align-self: start; }
.finder-map .mk text { display: none; }

/* quiz */
#quiz-form { display: grid; gap: 1rem; }
.qcard { border: 1px solid var(--line); border-radius: 1rem; padding: 1.1rem 1.25rem; background: var(--card); margin: 0; }
.qcard legend { padding: 0 .5rem; font-weight: 600; }
.qno { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--line); font-size: .85rem; margin-right: .4rem; }
.opt { display: block; margin: .45rem 0; cursor: pointer; }
.opt input { position: absolute; opacity: 0; }
.opt span { display: block; border: 1px solid var(--line); border-radius: .7rem; padding: .55rem .9rem; transition: border-color .2s, background .2s; }
.opt input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 600; }
.opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.qcard.right { border-color: #22c55e; }
.qcard.wrong { border-color: #f87171; }
.qverdict { margin: .6rem 0 0; font-weight: 700; }
.qcard.right .qverdict { color: #22c55e; }
.qcard.wrong .qverdict { color: #f87171; }
[data-theme="light"] .qcard.right { border-color: #15803d; }
[data-theme="light"] .qcard.wrong { border-color: #b91c1c; }
[data-theme="light"] .qcard.right .qverdict { color: #15803d; }
[data-theme="light"] .qcard.wrong .qverdict { color: #b91c1c; }
.scoreboard { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1.25rem; background: var(--card); border: 1px solid var(--line); border-radius: 1rem; padding: 1rem 1.25rem; }
.score-line b { font-size: 1.3rem; color: var(--accent); }
.score-verdict { font-weight: 600; flex: 1; min-width: 12rem; }
.score-btns { display: flex; gap: .6rem; }
.score-note { width: 100%; color: var(--muted); font-size: .9rem; }
.answers { margin-top: 1rem; color: var(--muted); }

/* closing, sources, footer */
.closing p { font-size: 1.15rem; }
.source-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1.5rem; margin-bottom: 2.5rem; }
.source-grid h3 { font-size: 1rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 0 0 .5rem; }
.source-grid ul { list-style: none; margin: 0; padding: 0; }
.source-grid li { margin-bottom: .6rem; font-size: .93rem; }
.fig-note { color: var(--muted); }
.site-footer { text-align: center; color: var(--muted); padding: 3rem 1rem 2.5rem; margin-top: 2rem; border-top: 1px solid var(--line); }
.footernav { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem 1.1rem; margin-bottom: 1.2rem; }
.footernav a { color: var(--muted); font-size: .9rem; }
.missing { max-width: 40rem; margin: 20vh auto; text-align: center; padding: 0 1.25rem; }

@media (max-width: 59.99rem) {
  .topbar { flex-wrap: wrap; row-gap: .35rem; }
  .topnav { display: flex; order: 10; flex: 1 1 100%; padding-bottom: .15rem; }
  .story-map { top: 6.6rem; max-height: 46svh; overflow: hidden; }
  .chapter, .finder, .quiz, .closing, .sources { scroll-margin-top: calc(46svh + 7.5rem); }
  .map-hint { display: none; }
  .ro-map { max-height: 34svh; }
}
@media (min-width: 60rem) {
  .hero-wrap { padding-top: 5.5rem; }
}
