:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1d1f23;
  --muted: #5f6570;
  --line: #e2ded5;
  --sea: #dce9f2;
  --land: #ece8df;
  --land-line: #cfc9bc;
  --isr: #7f9cc0;
  --opt: #c9b27a;
  --syr: #a99ac0;
  --free: #16804a;
  --free-ink: #ffffff;
  --accent: #b3261e;
  --warn-bg: #fff4dc;
  --warn-line: #e6c16a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 6px 20px rgba(0, 0, 0, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171b; --card: #1e2126; --ink: #eceae5; --muted: #a2a7b0; --line: #2e3238;
    --sea: #1a2733; --land: #25282d; --land-line: #3a3e45;
    --isr: #4f6f96; --opt: #8f7c4c; --syr: #6f6389; --free: #25a765;
    --accent: #ff6b5f; --warn-bg: #2d2615; --warn-line: #7a6326;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171b; --card: #1e2126; --ink: #eceae5; --muted: #a2a7b0; --line: #2e3238;
  --sea: #1a2733; --land: #25282d; --land-line: #3a3e45;
  --isr: #4f6f96; --opt: #8f7c4c; --syr: #6f6389; --free: #25a765;
  --accent: #ff6b5f; --warn-bg: #2d2615; --warn-line: #7a6326;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: env(safe-area-inset-top, 0) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom, 0) max(16px, env(safe-area-inset-left));
}

/* ---------- Hero ---------- */
.hero { max-width: 1180px; margin: 0 auto; padding-block: 36px 20px; }
.eyebrow { margin: 0 0 6px; text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 600; color: var(--muted); }
h1 { margin: 0; font-size: clamp(34px, 6vw, 56px); line-height: 1.02; letter-spacing: -.02em; font-weight: 800; }
h1 span { color: var(--accent); }
.lede { max-width: 640px; margin: 14px 0 0; font-size: clamp(16px, 2vw, 18px); color: var(--muted); }
.lede b { color: var(--ink); }

/* ---------- Layout ---------- */
.layout {
  max-width: 1180px; margin: 0 auto;
  display: grid; gap: 24px;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  align-items: start;
}
.map-col { position: sticky; top: 12px; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .map-col { position: static; }
}

/* ---------- Map ---------- */
.map-wrap {
  position: relative;
  background: var(--sea);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
#map { display: block; width: 100%; height: auto; max-height: calc(100vh - 80px); margin: 0 auto; }
@media (max-width: 860px) {
  #map { max-height: 78vh; }
}
.ctx path { fill: var(--land); stroke: var(--land-line); stroke-width: .8; }
.lakes path { fill: var(--sea); stroke: none; pointer-events: none; }

.region {
  stroke: var(--card); stroke-width: 1.2; stroke-linejoin: round;
  cursor: pointer; transition: fill .18s ease, opacity .18s ease;
  outline: none;
}
.region.g-isr { fill: var(--isr); }
.region.g-opt { fill: var(--opt); }
.region.g-syr { fill: var(--syr); }
.region:hover { opacity: .82; }
.region.on { fill: var(--free); }
.region.focus { stroke: var(--ink); stroke-width: 2; }
.region:focus-visible { stroke: var(--accent); stroke-width: 2.5; }
#inset .region { stroke-width: .25; }
#inset .region.focus { stroke-width: .5; }
#inset .ctx path { stroke-width: .2; }

.labels { pointer-events: none; }
.city { fill: var(--ink); stroke: var(--card); stroke-width: 1; }
.city-label {
  font-size: 12px; font-weight: 600; fill: var(--ink);
  paint-order: stroke; stroke: var(--card); stroke-width: 3px; stroke-linejoin: round;
}
.water-label { font-size: 13px; font-style: italic; fill: var(--muted); opacity: .8; letter-spacing: .04em; }
.country-label { font-size: 12px; font-weight: 700; letter-spacing: .18em; fill: var(--muted); opacity: .6; }
.inset-label { font-size: 3.4px; font-weight: 700; fill: var(--ink); pointer-events: none; }

.inset-wrap {
  position: absolute; top: 12px; left: 12px; margin: 0;
  width: 34%; max-width: 170px;
  background: var(--card); border-radius: 12px; padding: 6px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
#inset { display: block; width: 100%; height: auto; border-radius: 8px; background: var(--land); }
.inset-wrap figcaption { font-size: 11px; color: var(--muted); text-align: center; margin-top: 4px; }

.source { font-size: 12px; color: var(--muted); margin: 8px 4px 0; }

/* ---------- Cards ---------- */
.panel { display: grid; gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; box-shadow: var(--shadow);
}
.step { margin: 0 0 12px; font-size: 18px; }

.chip-group + .chip-group { margin-top: 14px; }
.chip-group-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; }
.chip-group-title small { flex-basis: 100%; font-weight: 400; color: var(--muted); font-size: 12px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; }
.swatch.g-isr { background: var(--isr); }
.swatch.g-opt { background: var(--opt); }
.swatch.g-syr { background: var(--syr); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

button { font: inherit; cursor: pointer; }
.chip, .preset, .share {
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 500;
  min-height: 40px; transition: background .15s, border-color .15s, color .15s;
}
.chip:hover, .preset:hover, .share:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--free); border-color: var(--free); color: var(--free-ink); }
.chip[aria-pressed="true"]::before { content: "✓ "; }
.chip:focus-visible, .preset:focus-visible, .share:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.presets-label { margin: 18px 0 8px; font-size: 13px; color: var(--muted); }
#presets { display: flex; flex-wrap: wrap; gap: 8px; }
.preset { background: var(--bg); }
.preset.ghost { background: transparent; border-style: dashed; color: var(--muted); }

/* ---------- Verdict ---------- */
.verdict .empty { text-align: center; padding: 18px 6px; color: var(--muted); }
.empty-title { font-size: 20px; font-weight: 700; color: var(--ink); margin: 0 0 6px; }
.verdict h2 { margin: 10px 0 14px; font-size: clamp(22px, 3vw, 28px); line-height: 1.15; letter-spacing: -.01em; }
.verdict p { margin: 0 0 12px; }
.tag {
  display: inline-block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  padding: 4px 10px; border-radius: 999px; color: #fff;
}
.tone-mainstream { background: var(--free); }
.tone-neutral { background: var(--muted); }
.tone-maximal { background: var(--accent); }

.facts { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 12px; }
.facts > div {
  flex: 1 1 110px; background: var(--bg); border-radius: 10px; padding: 10px 12px;
  display: flex; flex-direction: column;
}
.facts b { font-size: 18px; }
.facts.big b { font-size: 22px; }
.facts span { font-size: 12px; color: var(--muted); line-height: 1.3; }
.meter { height: 8px; border-radius: 99px; background: var(--bg); overflow: hidden; margin: 0 0 16px; }
.meter i { display: block; height: 100%; background: var(--free); border-radius: 99px; transition: width .3s ease; }

.callout { padding: 12px 14px; border-radius: 10px; font-size: 15px; }
.callout.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); }
.share { margin-top: 6px; }

/* ---------- History ---------- */
.hist-head { display: flex; align-items: center; gap: 10px; }
.hist-head h3 { margin: 0; font-size: 20px; }
.hist-summary { color: var(--muted); margin: 8px 0 12px; }
.timeline { list-style: none; padding: 0; margin: 0 0 12px; border-left: 2px solid var(--line); }
.timeline li { display: grid; grid-template-columns: 92px 1fr; gap: 10px; padding: 6px 0 6px 14px; position: relative; font-size: 15px; }
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--card); border: 2px solid var(--muted);
}
.yr { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; }
@media (max-width: 480px) {
  .timeline li { grid-template-columns: 1fr; gap: 0; }
}
.today { margin: 0; padding: 12px 14px; background: var(--bg); border-radius: 10px; font-size: 15px; }

.foot { max-width: 1180px; margin: 0 auto; padding-block: 28px 40px; font-size: 13px; color: var(--muted); }

/* ---------- River-to-the-sea mode: the "nuclear option" ---------- */
.rts-btn {
  --hazard-a: #f2c200; --hazard-b: #141414;
  position: relative; overflow: hidden; isolation: isolate;
  width: 100%; display: block; padding: 7px; border: 0; border-radius: 16px; text-align: left;
  background: var(--hazard-b);
  box-shadow: 0 6px 22px rgba(179, 38, 30, .28);
  transition: transform .12s ease, box-shadow .25s ease;
}
/* Hazard stripes live on an oversized layer so they can crawl without a seam. */
.rts-btn::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: -40px; right: -40px; z-index: -1;
  background: repeating-linear-gradient(-45deg, var(--hazard-a) 0 14px, var(--hazard-b) 14px 28px);
}
.rts-inner {
  position: relative;
  display: flex; align-items: center; gap: 16px;
  padding: 18px 18px; border-radius: 11px; color: #fff;
  background: linear-gradient(160deg, #3a0d0b 0%, #1a0706 100%);
}
.rts-btn:hover { box-shadow: 0 8px 30px rgba(220, 40, 30, .5); }
.rts-btn:active { transform: scale(.985); }
.rts-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* The big red button */
.rts-nuke {
  flex: none; position: relative; width: 64px; height: 64px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #2a2a2a 0 58%, #0c0c0c 60% 100%);
  box-shadow: inset 0 0 0 3px #555, 0 2px 0 #000;
}
.rts-nuke::after {
  content: ""; position: absolute; inset: 9px; border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #ff8a80 0 12%, #e5251b 34%, #9c0f08 78%, #6b0703 100%);
  box-shadow: 0 5px 0 #5a0602, 0 8px 14px rgba(0, 0, 0, .6);
  transition: transform .12s ease, box-shadow .12s ease;
}
.rts-btn:hover .rts-nuke::after { box-shadow: 0 5px 0 #5a0602, 0 0 22px rgba(255, 60, 40, .75); }
.rts-btn:active .rts-nuke::after { transform: translateY(4px); box-shadow: 0 1px 0 #5a0602, 0 0 12px rgba(255, 60, 40, .6); }

.rts-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.rts-text b {
  font-size: clamp(18px, 2.4vw, 22px); font-weight: 900; text-transform: uppercase;
  letter-spacing: .03em;
}
.rts-text b span { color: #ff5a4e; }
.rts-text small { color: #f2c200; font-size: 13px; font-weight: 600; margin-top: 6px; letter-spacing: .02em; }
.rts-state {
  flex: none; font: 800 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; text-transform: uppercase;
  padding: 7px 10px; border-radius: 6px; color: #7d7d7d; background: #0c0c0c; border: 1px solid #333;
}

/* Engaged */
.rts-btn[aria-pressed="true"]::before { animation: hazard-crawl 1.2s linear infinite; }
.rts-btn[aria-pressed="true"] .rts-inner { background: linear-gradient(160deg, #c8211a 0%, #7d0c07 100%); }
.rts-btn[aria-pressed="true"] .rts-text b span { color: #fff; }
.rts-btn[aria-pressed="true"] .rts-state { color: #ff3b30; border-color: #ff3b30; text-shadow: 0 0 8px rgba(255, 59, 48, .9); }
.rts-btn[aria-pressed="true"] .rts-inner { animation: rts-pulse 1.6s ease-in-out infinite; }
/* 28px stripe period at 45° = 39.6px horizontally */
@keyframes hazard-crawl { to { transform: translateX(39.6px); } }
@keyframes rts-pulse {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(255, 200, 190, 0); }
  50% { box-shadow: inset 0 0 24px 2px rgba(255, 200, 190, .35); }
}

/* Launch effect on the map */
.map-wrap::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 60% 45%, rgba(255, 240, 200, .9), rgba(255, 70, 40, .55) 45%, rgba(255, 40, 20, 0) 80%);
}
.map-wrap.launch::after { animation: launch-flash .9s ease-out; }
.map-wrap.launch { animation: launch-shake .45s ease-in-out; }
@keyframes launch-flash { 0% { opacity: 0; } 12% { opacity: 1; } 100% { opacity: 0; } }
@keyframes launch-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-5px, 2px); } 40% { transform: translate(5px, -2px); }
  60% { transform: translate(-3px, 1px); } 80% { transform: translate(2px, -1px); }
}
@media (prefers-reduced-motion: reduce) {
  .rts-btn[aria-pressed="true"]::before, .rts-btn[aria-pressed="true"] .rts-inner,
  .map-wrap.launch, .map-wrap.launch::after { animation: none; }
}
@media (max-width: 480px) {
  .rts-inner { gap: 12px; padding: 14px 12px; }
  .rts-nuke { width: 52px; height: 52px; }
  .rts-nuke::after { inset: 7px; }
  .rts-state { padding: 6px 7px; font-size: 11px; }
}
.or {
  display: flex; align-items: center; gap: 10px; margin: 22px 0 16px;
  font-size: 13px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .2em;
}
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.river-label { font-size: 11px; }
body.rts .map-wrap { box-shadow: 0 0 0 3px var(--accent), var(--shadow); }
body.rts .river-label, body.rts .water-label { fill: var(--accent); opacity: 1; font-weight: 700; }
body.rts .region.on { stroke: var(--free); }

/* ---------- Slogan explainer ---------- */
.explainer { padding: 0; }
.explainer summary {
  cursor: pointer; list-style: none; padding: 18px 20px; font-weight: 700; font-size: 17px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.explainer summary::-webkit-details-marker { display: none; }
.explainer summary::after { content: "+"; font-size: 22px; font-weight: 400; color: var(--muted); line-height: 1; }
.explainer[open] summary::after { content: "–"; }
.explainer summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 16px; }
.explainer-body { padding: 0 20px 20px; }
.explainer-body p, .explainer-body li { font-size: 15px; }
.explainer-body p { margin: 0 0 12px; }
.explainer-body h4 { margin: 18px 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.explainer-body ul { margin: 0 0 12px; padding-left: 20px; }
.explainer-body li { margin-bottom: 8px; }
.explainer blockquote { margin: 0 0 14px; padding: 14px 16px; background: var(--bg); border-left: 4px solid var(--accent); border-radius: 0 10px 10px 0; }
.explainer blockquote p { margin: 0; }
.explainer .ar { font-size: 22px; margin-bottom: 6px; }
.bottom-line { padding: 12px 14px; background: var(--bg); border-radius: 10px; }
.verdict a { color: var(--accent); }
.explainer .timeline { margin-top: 4px; }
.explainer .timeline li { grid-template-columns: 104px 1fr; }
@media (max-width: 480px) {
  .explainer .timeline li { grid-template-columns: 1fr; }
}

/* ---------- Selected pieces list ---------- */
.hist-head .count {
  font-size: 13px; font-weight: 700; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center; background: var(--free); color: var(--free-ink);
}
.pieces { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.piece + .piece { border-top: 1px solid var(--line); }
.piece-row {
  width: 100%; display: flex; align-items: flex-start; gap: 12px; text-align: left;
  padding: 14px; border: 0; background: transparent; color: var(--ink);
}
.piece-row:hover { background: var(--bg); }
.piece-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.piece-row .swatch { margin-top: 5px; }
.piece-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.piece-main b { font-size: 16px; }
.piece-stats { font-size: 13px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.piece-sum { font-size: 14px; color: var(--muted); line-height: 1.45; margin-top: 2px; }
.chev {
  flex: none; width: 10px; height: 10px; margin: 6px 4px 0 0;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform .15s ease;
}
.piece.open .chev { transform: rotate(-135deg); margin-top: 10px; }
.piece.open .piece-row { background: var(--bg); }
.piece-body { padding: 4px 14px 16px 38px; background: var(--bg); }
.piece-body .today { background: var(--card); }
.piece-body .timeline li::before { background: var(--bg); }
@media (max-width: 480px) {
  .piece-body { padding-left: 14px; }
}

/* ---------- Region thumbnails ---------- */
.thumb {
  flex: none; display: block; width: 64px; height: 64px;
  border-radius: 10px; border: 1px solid var(--line); overflow: hidden;
}
.thumb-lg { width: 104px; height: 104px; border-radius: 12px; }
.t-sea { fill: var(--sea); }
.t-ctx { fill: var(--land); stroke: var(--land-line); stroke-width: .75; }
.t-other { stroke: var(--card); stroke-width: .75; opacity: .45; }
.t-other.g-isr { fill: var(--isr); }
.t-other.g-opt { fill: var(--opt); }
.t-other.g-syr { fill: var(--syr); }
.t-target { fill: var(--free); stroke: #fff; stroke-width: 1.5; }
.t-lake { fill: var(--sea); }
.piece-row { align-items: center; }
.hist-hero { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.hist-hero h3 { margin: 0; font-size: 20px; }
.hist-hero .hist-summary { margin: 4px 0 0; }
.piece-body { padding-left: 90px; }
@media (max-width: 480px) {
  .thumb { width: 56px; height: 56px; }
  .thumb-lg { width: 84px; height: 84px; }
  .hist-hero { align-items: flex-start; }
  .piece-row { align-items: flex-start; }
  .piece-body { padding-left: 14px; }
}

/* ---------- Famous-map presets ---------- */
.preset.on { background: var(--ink); color: var(--card); border-color: var(--ink); }
.about-map {
  margin: -4px 0 18px; padding: 14px 16px; border-radius: 12px;
  background: var(--bg); border-left: 4px solid var(--ink);
}
.about-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.about-map h3 { margin: 2px 0 8px; font-size: 17px; }
.about-map p { font-size: 14.5px; margin: 0 0 8px; }
.about-map p:last-child { margin-bottom: 0; }
