:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --muted: #555555;
  --line: #d0d0d0;
  --accent: #0b5cad;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); }
header, main { max-width: 960px; margin: 0 auto; padding: 0 16px; }
h1 { font-size: 1.6rem; margin: 24px 0 4px; }
.dataset { margin: 0 0 16px; color: var(--muted); }
.intro { margin: 0 0 20px; line-height: 1.5; max-width: 70ch; }
.controls { margin: 0 0 12px; }
label { font-weight: 600; margin-right: 8px; }
.controls { display: block; }
.year-value { display: block; text-align: center; margin: 0 0 6px; font-weight: 400; color: var(--muted); }
.year-value label { font-weight: 400; margin: 0; }
.year-nudge { display: flex; justify-content: center; align-items: center; gap: 16px; }
.year-nudge output { font-size: 1.6rem; font-weight: 700; color: var(--text); min-width: 4ch; }
.year-nudge button { font: inherit; font-size: 1.6rem; line-height: 1; width: 44px; height: 44px;
  border: 1px solid var(--line); border-radius: 50%; background: var(--bg); color: var(--text); cursor: pointer; }
.year-nudge button:disabled { opacity: 0.3; cursor: default; }
.year-nudge button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.slider { width: 100%; }
.slider input { width: 100%; margin: 0; accent-color: var(--accent); }
.slider input:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.ticks { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); }
.map-wrap { position: relative; }
#map { height: 420px; border: 1px solid var(--line); border-radius: 4px; }
table { width: 100%; border-collapse: collapse; margin: 8px 0 32px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); }
td:nth-child(n+3), th:nth-child(n+3) { text-align: right; }   /* number columns */
.question { font-size: 1.25rem; font-weight: 600; margin: 0 0 12px; max-width: 40ch; }
.view-choice { border: 0; margin: 12px 0 4px; padding: 0; }
.view-choice legend { font-weight: 600; padding: 0; margin-bottom: 4px; }
.view-choice label { font-weight: 400; margin: 0; display: flex; align-items: center; gap: 8px; min-height: 44px; }
.view-choice input { width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.more-views summary, .all-figures summary { cursor: pointer; color: var(--accent); min-height: 44px;
  display: flex; align-items: center; }
.more-views[open] { padding-left: 12px; border-left: 3px solid var(--line); }
.caption { color: var(--muted); margin: 4px 0 12px; max-width: 70ch; }
.table-scroll { overflow-x: auto; }
table.story thead th { text-align: right; }
table.story thead th:first-child { text-align: left; }
tr.group th { text-align: left; background: #f3f5f8; font-size: 0.9rem; padding-top: 14px; }
.limits { margin: 24px 0 40px; }
.limits h2 { font-size: 1.1rem; }
/* Legend floats over the map's top-left corner (it is page text, outside the map's role="img"). */
.legend { position: absolute; top: 10px; left: 10px; z-index: 2; max-width: calc(100% - 100px);
  font-size: 0.8rem; color: var(--text); background: rgba(255,255,255,0.9); border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25); }
.legend summary { cursor: pointer; font-weight: 600; padding: 0 10px; min-height: 44px;
  display: flex; align-items: center; gap: 6px; list-style: none; }
.legend summary::-webkit-details-marker { display: none; }
.legend summary::before { content: "\25B8"; transition: transform 0.15s; }
.legend[open] summary::before { transform: rotate(90deg); }
.legend summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.legend ul { list-style: none; margin: 0; padding: 0 10px 8px; display: flex; flex-direction: column; gap: 4px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend li[hidden] { display: none; }
.legend svg { color: var(--text); flex: none; }
.orbit { background: transparent !important; box-shadow: none !important; }
.orbit-ball { display: block; padding: 0; border: 0; background: rgba(255,255,255,0.75); border-radius: 50%;
  color: var(--accent); cursor: grab; touch-action: none; width: 64px; height: 64px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3); }
.orbit-ball:active { cursor: grabbing; }
.orbit-ball:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.map-fallback { margin: 0; padding: 24px; color: var(--muted); }
table.story td { text-align: right; }

/* ---- story ---------------------------------------------------------------------- */
:root {
  --near: #2a78d6;          /* categorical slot 1 (validated pair with slot 2) */
  --nearby: #eb6834;        /* categorical slot 2 */
  --context: #8f8e89;       /* the region: grey context, not a series hue */
  --grid: #e6e5e1;
  --break: #f1f0ec;
}
.eyebrow { margin: 24px 0 0; color: var(--muted); font-size: 0.9rem; letter-spacing: 0.02em; }
header h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); line-height: 1.15; margin: 4px 0 12px; max-width: 22ch; }
header .question { font-size: 1.15rem; font-weight: 600; max-width: 46ch; margin: 0 0 8px; }
header .answer { font-size: 1.05rem; line-height: 1.55; max-width: 62ch; margin: 0 0 12px; }
.how-to-read { margin: 0 0 8px; max-width: 70ch; }
.how-to-read summary { cursor: pointer; color: var(--accent); min-height: 44px; display: flex; align-items: center; }
.how-to-read li { margin: 4px 0; line-height: 1.45; }
.chapter { margin: 36px 0; max-width: 620px; }
.chapter h2 { font-size: 1.35rem; margin: 0 0 8px; display: flex; align-items: baseline; gap: 10px; }
.kicker { display: inline-flex; align-items: center; justify-content: center; width: 1.6em; height: 1.6em;
  border-radius: 50%; background: var(--text); color: var(--bg); font-size: 0.8em; flex: none; }
.chapter p { line-height: 1.55; margin: 0 0 10px; }
.figure { margin: 14px 0 0; }
.chart-title { font-size: 0.95rem; margin: 0 0 4px; }
.chart-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 4px; padding: 0;
  font-size: 0.85rem; color: var(--muted); }
.chart-legend li { display: flex; align-items: center; gap: 6px; }
.key { width: 18px; height: 2px; border-radius: 1px; background: var(--context); }
.key-near { background: var(--near); } .key-nearby { background: var(--nearby); }
.key-bar { height: 10px; width: 12px; border-radius: 2px; }
.key-break { height: 12px; width: 12px; background: var(--break); border: 1px solid var(--grid); }
.chart-wrap { width: 100%; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font-family: system-ui, sans-serif; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: #b9b8b3; stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .cat { fill: var(--text); font-size: 12px; }
.chart .break { fill: var(--break); }
.chart .marker { stroke: #b9b8b3; stroke-width: 1; }
.chart .marker-label { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .end-label { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart .dot { stroke: var(--bg); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .line.s-near { stroke: var(--near); } .chart .dot.s-near, .chart .bar.s-near { fill: var(--near); }
.chart .line.s-nearby { stroke: var(--nearby); } .chart .dot.s-nearby, .chart .bar.s-nearby { fill: var(--nearby); }
.chart .line.s-context { stroke: var(--context); } .chart .dot.s-context { fill: var(--context); }
.chart .bar { cursor: pointer; }
.chart .bar.active { opacity: 0.8; }
.chart-tip { position: absolute; z-index: 10; pointer-events: none; background: var(--text); color: var(--bg);
  font-size: 0.85rem; padding: 4px 8px; border-radius: 4px; white-space: nowrap; }
.chart-figures summary { cursor: pointer; color: var(--accent); min-height: 44px; display: flex; align-items: center;
  font-size: 0.9rem; }
.chart-figures table { margin: 0 0 8px; font-size: 0.9rem; }
.chart-figures td { text-align: right; }
.stats { display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0; }
.stat { flex: 1 1 200px; border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; }
.stat-value { font-size: 2rem; font-weight: 600; line-height: 1.1; }
.stat-label { font-size: 0.9rem; margin-top: 4px; }
.stat-note { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }
.explore-heading { margin: 48px 0 4px; padding-top: 24px; border-top: 1px solid var(--line); font-size: 1.35rem; }
.trust { margin: 32px 0 48px; max-width: 70ch; }
.trust li { margin: 6px 0; line-height: 1.45; }
.trust h3 { font-size: 1rem; margin: 18px 0 4px; }

/* ---- scrolling story with a pinned map ------------------------------------------- */
main.scrolly { max-width: 1280px; display: grid; grid-template-columns: minmax(0, 1fr); }
.map-panel { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 6px 0 8px;
  border-bottom: 1px solid var(--line); }
.map-panel .controls { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; }
.map-panel .year-value { flex: none; margin: 0; }
.map-panel .year-value label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.map-panel .year-nudge { gap: 4px; }
.map-panel .year-nudge output { font-size: 1.25rem; min-width: 3.2em; text-align: center; }
.map-panel .slider { flex: 1; }
/* Phone: the map takes about a third of the screen, so the story keeps the rest. Its
   caption moves into the text: each chapter's "On the map" note, and under the view choice. */
.map-panel #map { height: 27vh; min-height: 170px; }
.map-panel .caption { display: none; }
.map-panel .orbit-ball { width: 48px; height: 48px; }
.map-cue { font-size: 0.95rem; color: var(--text); background: #f3f5f8; border-radius: 4px; padding: 10px 12px;
  line-height: 1.5; }
.map-cue strong { font-weight: 600; }
@media (min-width: 960px) {
  .map-panel .caption { display: block; font-size: 0.85rem; margin: 6px 0 0; line-height: 1.35; }
  .map-panel .orbit-ball { width: 64px; height: 64px; }
  .phone-only { display: none; }
  main.scrolly { grid-template-columns: minmax(0, 600px) minmax(0, 1fr); column-gap: 40px; }
  .story-col { grid-column: 1; grid-row: 1; }
  .map-panel { grid-column: 2; grid-row: 1; align-self: start; height: 100vh; display: flex;
    flex-direction: column; border-bottom: 0; padding: 12px 0; }
  .map-panel .map-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
  .map-panel #map { flex: 1; height: auto; }
}
