:root {
  color-scheme: dark;
  --page: #060607;
  --panel: rgba(15, 15, 17, 0.82);
  --panel-solid: #111113;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8d8b84;
  --fire: #ff8a2a;
  --fire-hot: #ffd27a;
  --fire-deep: #c8361a;
  --ember: #7a2412;
  --gutter: 16px;
  --left-w: 300px;
  --right-w: 320px;
  --tl-h: 206px;
  --brand-h: 150px;
  --radius: 14px;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--page); color: var(--text); font-family: var(--sans); font-size: 13px; line-height: 1.4; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }

#map { position: fixed; inset: 0; }

.panel {
  position: fixed;
  z-index: 2;
  background: var(--panel);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

/* Brand */
.brand { top: var(--gutter); left: var(--gutter); width: var(--left-w); padding: 16px 18px 14px; }
.eyebrow { font-size: 10.5px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--fire); font-weight: 600; }
h1 { margin: 4px 0 6px; font-size: 26px; line-height: 1.05; letter-spacing: -0.02em; font-weight: 700; }
.lede { margin: 0; color: var(--text-2); font-size: 12.5px; }

/* Controls */
.controls {
  top: calc(var(--gutter) * 1.6 + var(--brand-h));
  left: var(--gutter);
  width: var(--left-w);
  max-height: calc(100vh - var(--brand-h) - var(--tl-h) - var(--gutter) * 4);
  overflow-y: auto;
  padding: 6px 18px 14px;
  scrollbar-width: thin;
}
.group { padding: 11px 0; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group[hidden] { display: none; }
.label { display: flex; justify-content: space-between; align-items: baseline; font-size: 11px; color: var(--muted); margin-bottom: 7px; font-weight: 500; letter-spacing: 0.02em; }
.label output { font-family: var(--mono); font-size: 11px; color: var(--text-2); }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 11.5px; }

.seg { display: flex; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px 6px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-weight: 500; white-space: nowrap; transition: background 0.15s, color 0.15s; }
.seg button:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.seg button.on { background: rgba(255, 138, 42, 0.16); color: var(--fire-hot); box-shadow: inset 0 0 0 1px rgba(255, 138, 42, 0.35); }
.seg.small button { padding: 5px 4px; font-size: 12px; }
.seg.tiny button { padding: 3px 7px; font-size: 11.5px; flex: 0 0 auto; }
.seg.tiny { display: inline-flex; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px 5px 7px; border-radius: 999px; border: 1px solid var(--line-2); background: transparent; cursor: pointer; color: var(--muted); font-size: 12px; }
.chip i { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid currentColor; }
.chip.on { color: var(--text); border-color: rgba(255, 138, 42, 0.45); }
.chip.on i { background: var(--fire); border-color: var(--fire); box-shadow: 0 0 8px rgba(255, 138, 42, 0.8); }
.chip small { color: var(--muted); font-size: 10.5px; }

.toggle { display: flex; align-items: center; gap: 9px; padding: 4px 0; cursor: pointer; color: var(--text-2); }
.toggle input { appearance: none; width: 28px; height: 16px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); position: relative; cursor: pointer; flex: 0 0 auto; transition: background 0.15s; margin: 0; }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: #d8d6cf; transition: transform 0.15s; }
.toggle input:checked { background: rgba(255, 138, 42, 0.75); }
.toggle input:checked::after { transform: translateX(12px); background: #fff; }

input[type="range"] { width: 100%; accent-color: var(--fire); }
select { width: 100%; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 8px; }
select option { background: var(--panel-solid); }

.legend .ramp { height: 8px; border-radius: 4px; margin: 2px 0 4px; }
.legend .ticks { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.legend .note { color: var(--muted); font-size: 11px; margin-top: 7px; display: flex; align-items: center; gap: 6px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }

/* Stats */
.stats {
  top: var(--gutter);
  right: var(--gutter);
  width: var(--right-w);
  max-height: calc(100vh - var(--tl-h) - var(--gutter) * 3);
  overflow-y: auto;
  padding: 16px 18px;
  scrollbar-width: thin;
}
.period { font-size: 12px; color: var(--text-2); }
.hero { display: flex; align-items: baseline; gap: 8px; margin: 2px 0 10px; }
.hero #count { font-size: 40px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; color: var(--text); }
.hero .unit { color: var(--muted); font-size: 12px; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 0 0 6px; }
.kv div { background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); border-radius: 9px; padding: 7px 8px; }
.kv dt { font-size: 10.5px; color: var(--muted); }
.kv dd { margin: 2px 0 0; font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kv.two { grid-template-columns: repeat(2, 1fr); }
.kv dd.sub { font-size: 11px; font-weight: 500; color: var(--text-2); margin-top: 1px; }
.muted-note { color: var(--muted); font-weight: 400; }
.landbar { margin: 8px 0 2px; }
.landbar .track { display: flex; gap: 2px; height: 8px; border-radius: 4px; overflow: hidden; background: rgba(255, 255, 255, 0.05); }
.landbar .track i { display: block; height: 100%; }
.landbar .lg { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin-top: 7px; font-size: 11.5px; color: var(--text-2); }
.landbar .lg span:nth-child(odd) { display: flex; align-items: center; gap: 6px; }
.landbar .lg b { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.landbar .lg .sw { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 auto; }
#annual { width: 100%; height: 210px; display: block; overflow: visible; }
#annual .lbl { font-size: 10.5px; fill: var(--text-2); }
#annual .axis { fill: var(--muted); font-size: 9.5px; font-family: var(--mono); }
#annual .base { stroke: rgba(255, 255, 255, 0.14); stroke-width: 1; }
#annual .hit { fill: transparent; cursor: pointer; }
#annual .hit:hover { fill: rgba(255, 255, 255, 0.05); }
h2 { font-size: 12px; font-weight: 600; margin: 16px 0 8px; color: var(--text); }
h2 .muted { color: var(--muted); font-weight: 400; }

.bars { list-style: none; margin: 0; padding: 0; }
.bars li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 4px 6px; margin: 0 -6px; border-radius: 7px; cursor: pointer; }
.bars li:hover { background: rgba(255, 255, 255, 0.05); }
.bars .name { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bars .val { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 500; }
.bars .bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.05); overflow: hidden; }
.bars .bar i { display: block; height: 100%; border-radius: 2px; background: linear-gradient(90deg, var(--fire-deep), var(--fire)); }
.bars .empty { color: var(--muted); cursor: default; }

.yc-readout { font-size: 11.5px; color: var(--text-2); min-height: 17px; margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.yc-readout b { color: var(--fire-hot); font-weight: 600; }
#yearchart { width: 100%; height: 150px; display: block; overflow: visible; }
#yearchart .grid { stroke: rgba(255, 255, 255, 0.07); stroke-width: 1; }
#yearchart .axis { fill: var(--muted); font-size: 10px; font-family: var(--mono); }
#yearchart .yr { fill: none; stroke: rgba(195, 194, 183, 0.22); stroke-width: 1; }
#yearchart .yr.rec { stroke: rgba(240, 239, 236, 0.75); stroke-width: 1.5; }
#yearchart .yr.cur { stroke: var(--fire); stroke-width: 2.25; }
#yearchart .lbl { font-size: 10.5px; fill: var(--text-2); }
#yearchart .lbl.cur { fill: var(--fire-hot); font-weight: 600; }
#yearchart .cross { stroke: rgba(255, 255, 255, 0.35); stroke-width: 1; }
#yearchart .band { fill: rgba(195, 194, 183, 0.16); }
#yearchart .med { fill: none; stroke: rgba(240, 239, 236, 0.6); stroke-width: 1.25; stroke-dasharray: 3 3; }
#yearchart .evt { stroke: rgba(240, 239, 236, 0.85); stroke-width: 1.5; }
#yearchart .elec { stroke: rgba(240, 239, 236, 0.55); stroke-width: 1; stroke-dasharray: 2 3; }
#yearchart .elec-l { fill: var(--text-2); font-size: 9.5px; }
.yc-ctrl { display: flex; flex-wrap: wrap; gap: 6px; }
.yc-note { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; font-size: 11px; color: var(--muted); }
.yc-note span { display: inline-flex; align-items: center; gap: 5px; }
.yc-note .k { display: inline-block; width: 14px; height: 0; border-top: 2px solid var(--fire); }
.yc-note .k.med { border-top: 1.5px dashed rgba(240, 239, 236, 0.7); }
.yc-note .k.band { height: 8px; border: 0; background: rgba(195, 194, 183, 0.3); border-radius: 2px; }
.yc-note .k.rec { border-top: 1.5px solid rgba(240, 239, 236, 0.75); }
.yc-note .k.oth { border-top: 1px solid rgba(195, 194, 183, 0.5); }

/* Timeline */
.timeline { left: var(--gutter); right: var(--gutter); bottom: var(--gutter); height: var(--tl-h); padding: 10px 14px 8px; display: flex; flex-direction: column; gap: 6px; }
.tl-top { display: flex; align-items: center; gap: 14px; }
.play { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--fire); color: #1a0a02; display: grid; place-items: center; cursor: pointer; flex: 0 0 auto; box-shadow: 0 0 18px rgba(255, 138, 42, 0.45); }
.play svg { width: 18px; height: 18px; fill: currentColor; }
.play .i-pause { display: none; }
.play.on .i-play { display: none; }
.play.on .i-pause { display: block; }
.now { min-width: 230px; }
.now-date { font-size: 19px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.now-sub { font-size: 11.5px; color: var(--muted); }
.tl-opts { display: flex; gap: 16px; margin-left: auto; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.opt { display: flex; align-items: center; gap: 8px; }
.opt .label { margin: 0; }

.years { display: flex; gap: 2px; align-items: flex-end; }
.years button { flex: 1 1 0; min-width: 0; border: 0; background: transparent; cursor: pointer; padding: 0 0 2px; display: flex; flex-direction: column; align-items: stretch; gap: 2px; border-radius: 4px; color: var(--muted); font-size: 10px; font-family: var(--mono); }
.years button .b { height: 14px; display: flex; align-items: flex-end; justify-content: center; }
.years button .b i { display: block; width: min(70%, 22px); min-height: 1px; border-radius: 2px 2px 0 0; background: rgba(195, 194, 183, 0.45); }
.years button:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.years button.on { color: var(--fire-hot); background: rgba(255, 138, 42, 0.1); }
.years button.on .b i { background: var(--fire); }
.years button.all { flex: 0 0 auto; padding: 0 8px 2px; justify-content: flex-end; font-family: var(--sans); font-size: 11px; }
.tl-canvas-wrap { flex: 1; position: relative; min-height: 0; }
#tl { position: absolute; inset: 0; width: 100%; height: 100%; cursor: ew-resize; touch-action: none; }

/* Tooltip */
#tooltip { position: fixed; z-index: 10; pointer-events: none; display: none; background: rgba(12, 12, 14, 0.94); border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 11px; font-size: 12px; max-width: 280px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); }
#tooltip .t-h { font-weight: 600; margin-bottom: 4px; }
#tooltip .t-r { display: flex; justify-content: space-between; gap: 14px; color: var(--text-2); }
#tooltip .t-r b { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
#tooltip .t-s { color: var(--muted); font-size: 11px; margin-top: 4px; }

/* Loading */
#loading { position: fixed; z-index: 20; left: 50%; top: 46%; transform: translate(-50%, -50%); background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(14px); border-radius: 12px; padding: 14px 18px; width: 300px; transition: opacity 0.4s; }
#loading.done { opacity: 0; pointer-events: none; }
.ld-text { font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.ld-bar { height: 3px; background: rgba(255, 255, 255, 0.08); border-radius: 2px; overflow: hidden; }
.ld-bar i { display: block; height: 100%; width: 0; background: var(--fire); transition: width 0.2s; }

/* MapLibre controls */
.maplibregl-ctrl-bottom-right { bottom: calc(var(--tl-h) + var(--gutter) * 2 - 8px); right: calc(var(--right-w) + var(--gutter) * 2 - 8px); }
.maplibregl-ctrl-top-right { right: calc(var(--right-w) + var(--gutter) * 2 - 8px); top: 6px; }
.maplibregl-ctrl-attrib { background: rgba(10, 10, 12, 0.7) !important; color: var(--muted); font-size: 10.5px; }
.maplibregl-ctrl-attrib a { color: var(--text-2); }
.maplibregl-ctrl-attrib-button { filter: invert(1); }
.maplibregl-ctrl-group { background: var(--panel); border: 1px solid var(--line); }
.maplibregl-ctrl-group button + button { border-top-color: var(--line); }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(0.9); }

@media (max-width: 1100px) {
  :root { --right-w: 280px; --left-w: 270px; }
  .now { min-width: 0; }
}

@media (max-width: 820px) {
  :root { --gutter: 16px; --tl-h: 224px; }
  html, body { overflow: auto; }
  .brand { width: auto; right: var(--gutter); padding: 12px 14px; }
  .lede { display: none; }
  h1 { font-size: 21px; }
  .controls { top: auto; bottom: calc(var(--tl-h) + var(--gutter) * 2); max-height: 38vh; width: auto; right: var(--gutter); }
  .stats { display: none; }
  .tl-opts .opt:last-child { display: none; }
  .years button { font-size: 0; }
  .years button.all { font-size: 11px; }
  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-top-right { right: 0; }
}

/* Controls: hidden until the reader asks for them */
.controls { display: none; }
body.controls-on .controls { display: block; }
.brand-btns { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.ctl-toggle { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line-2); border-radius: 999px; padding: 6px 13px 6px 10px; background: transparent; color: var(--text-2); font-weight: 500; cursor: pointer; }
.ctl-toggle svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.ctl-toggle:hover, body.controls-on .ctl-toggle { color: var(--text); border-color: rgba(255, 138, 42, 0.45); }

/* Story: only the map and the story card are on the screen */
.story-open { display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 999px; padding: 7px 14px 7px 11px; background: var(--fire); color: #1a0a02; font-weight: 600; cursor: pointer; box-shadow: 0 0 16px rgba(255, 138, 42, 0.35); }
.story-open svg { width: 12px; height: 12px; fill: currentColor; }
body.story-on .brand, body.story-on .controls, body.story-on .stats, body.story-on .timeline, body.story-on .maplibregl-ctrl-top-right { display: none; }
body.story-on .maplibregl-ctrl-bottom-right { bottom: 0; right: 0; }
.story { top: var(--gutter); left: var(--gutter); width: min(440px, calc(100vw - var(--gutter) * 2)); max-height: calc(100vh - var(--gutter) * 2); overflow-y: auto; padding: 18px 22px 16px; display: flex; flex-direction: column; gap: 12px; z-index: 3; scrollbar-width: thin; }
.story[hidden] { display: none; }
.st-top { display: flex; justify-content: space-between; align-items: center; }
.st-step { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--fire); font-weight: 600; }
.st-close { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 12.5px; padding: 4px 0; }
.st-close:hover { color: var(--text); }
.st-title { font-size: 27px; line-height: 1.1; letter-spacing: -0.02em; margin: 0; font-weight: 700; }
.st-num:empty, .st-chart:empty { display: none; }
.st-num .v { display: block; font-size: 54px; line-height: 1; font-weight: 700; letter-spacing: -0.035em; color: var(--fire-hot); font-variant-numeric: tabular-nums; }
.st-num .r { display: block; margin-top: 4px; font-size: 14.5px; line-height: 1.35; color: var(--text); }
.st-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.st-chart text { font-family: var(--sans); }
.st-chart .ax { fill: var(--muted); font-size: 11px; }
.st-chart .lb { fill: var(--text-2); font-size: 12px; }
.st-chart .lb.hot { fill: var(--fire-hot); font-weight: 700; }
.st-chart .lb.strong { fill: var(--text); font-weight: 600; }
.st-key { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 12px; color: var(--text-2); }
.st-key span { display: inline-flex; align-items: center; gap: 6px; }
.st-key i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; }
.st-key i.line { height: 0; border-radius: 0; border-top: 2px solid; width: 16px; }
.st-key i.dash { height: 0; border-radius: 0; border-top: 2px dashed; width: 16px; }
.st-body { color: var(--text-2); font-size: 15px; line-height: 1.5; }
.st-body p { margin: 0 0 8px; }
.st-body p:last-child { margin-bottom: 0; }
.st-body b, .st-body strong { color: var(--text); font-weight: 600; }
.st-body .caveat { font-size: 12.5px; color: var(--muted); }
.st-body ol, .st-body ul { margin: 0 0 8px; padding-left: 0; list-style: none; }
.st-body li { margin: 6px 0; display: flex; gap: 9px; align-items: baseline; }
.st-body li .n { flex: 0 0 auto; width: 19px; height: 19px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; color: #111; transform: translateY(-1px); }
.st-body li .ic { flex: 0 0 auto; width: 18px; text-align: center; font-weight: 700; }
.st-src { font-size: 11.5px; color: var(--muted); }
.st-src summary { cursor: pointer; width: max-content; }
.st-src summary:hover { color: var(--text-2); }
.st-src div { margin-top: 5px; line-height: 1.5; }
.st-src a { color: var(--text-2); }
.st-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 2px; }
.st-nav button { border: 1px solid var(--line-2); background: transparent; border-radius: 9px; padding: 9px 14px; cursor: pointer; color: var(--text-2); font-weight: 500; font-size: 13.5px; }
.st-nav button.primary { background: var(--fire); border-color: var(--fire); color: #1a0a02; font-weight: 700; padding: 9px 18px; }
.st-nav button:disabled { opacity: 0.35; cursor: default; }
.st-dots { display: flex; gap: 6px; }
.st-dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, 0.18); cursor: pointer; }
.st-dots i.on { background: var(--fire); }

/* Date of the map, during the story */
.map-date { position: fixed; z-index: 2; top: var(--gutter); left: calc(var(--gutter) * 2 + min(440px, 100vw - var(--gutter) * 2)); right: var(--gutter); display: none; flex-direction: column; align-items: center; pointer-events: none; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.9); }
body.story-on .map-date { display: flex; }
.map-date b { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.map-date span { font-size: 13px; color: var(--text-2); }

@media (max-width: 820px) {
  .tl-top { gap: 10px; }
  .now { flex: 1 1 auto; }
  .now-date { font-size: 15px; white-space: nowrap; }
  .now-sub { display: none; }
  .tl-opts .opt .label { display: none; }
  .tl-opts .seg.tiny button { padding: 3px 6px; }
  .st-dots { display: none; }
  .st-nav button { white-space: nowrap; padding: 8px 12px; }
  .st-nav button.primary { padding: 8px 16px; }
  /* Long chapters scroll inside the card; the buttons stay in view. */
  .st-nav { position: sticky; bottom: -12px; margin: 0 -16px -12px; padding: 10px 16px 12px; background: var(--panel-solid); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
  .story { top: auto; bottom: var(--gutter); max-height: 64vh; padding: 14px 16px 12px; gap: 9px; }
  .st-title { font-size: 21px; }
  .st-num .v { font-size: 40px; }
  .st-body { font-size: 14px; }
  .map-date { left: var(--gutter); }
  .map-date b { font-size: 19px; }
  body.controls-on .controls { display: block; }
}
