.viz-root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --control-bg: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --hover-wash: rgba(11, 11, 11, 0.04);
  --row-hover: rgba(42, 120, 214, 0.06);
  --legend-bg: rgba(252, 252, 251, 0.95);
  --nodata: #e7e6e1;
  --code-bg: #f0efec;
  --map-bg: #eef0f2;
  --loading-bg: rgba(249, 249, 247, 0.9);
  --accent: #2a78d6;
}
/* Dark: OS setting (unless the viewer picked light) or the explicit toggle */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #222220;
    --control-bg: #222220;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --hover-wash: rgba(255, 255, 255, 0.06);
    --row-hover: rgba(57, 135, 229, 0.14);
    --legend-bg: rgba(26, 26, 25, 0.94);
    --nodata: #2c2c2a;
    --code-bg: #2c2c2a;
    --map-bg: #1f2022;
    --loading-bg: rgba(13, 13, 13, 0.9);
    --accent: #3987e5;
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #222220;
  --control-bg: #222220;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --hover-wash: rgba(255, 255, 255, 0.06);
  --row-hover: rgba(57, 135, 229, 0.14);
  --legend-bg: rgba(26, 26, 25, 0.94);
  --nodata: #2c2c2a;
  --code-bg: #2c2c2a;
  --map-bg: #1f2022;
  --loading-bg: rgba(13, 13, 13, 0.9);
  --accent: #3987e5;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page); color: var(--text-primary); font-size: 14px;
}
header {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 8px 24px; padding: 14px 20px 0; background: var(--surface-1); border-bottom: 1px solid var(--border);
}
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 18px; margin: 0 0 2px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.sub { color: var(--text-secondary); font-size: 12.5px; display: block; margin-top: 2px; }
.title { padding-bottom: 10px; }
nav { display: flex; gap: 2px; }
nav button {
  border: 0; background: transparent; padding: 10px 14px; font: inherit; color: var(--text-secondary);
  border-bottom: 2px solid transparent; cursor: pointer;
}
nav button:hover { color: var(--text-primary); background: var(--hover-wash); }
nav button.active { color: var(--text-primary); border-bottom-color: var(--accent); font-weight: 600; }
.tab { display: none; padding: 12px 20px 24px; }
.tab.active { display: block; }
.filters {
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: flex-end;
  padding: 10px 12px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 12px;
}
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-secondary); }
.filters label.check { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 6px; }
.filters select, .filters input[type=range] { font: inherit; font-size: 13px; padding: 4px 6px; border: 1px solid var(--axis); border-radius: 6px; background: var(--control-bg); color: var(--text-primary); }
.grid { display: grid; gap: 12px; margin-bottom: 12px; }
.grid.two { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid.two { grid-template-columns: 1fr; } }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; min-width: 0; }
.map-card { padding: 0; overflow: hidden; display: flex; }
.map { flex: 1; min-height: 620px; width: 100%; background: var(--map-bg); }
.chart { height: 300px; width: 100%; }
.chart.tall { height: 420px; }
.chart.short { height: 220px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.note { margin-top: 6px; line-height: 1.4; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 10px 0; }
.tile { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--surface-2); }
.tile .k { font-size: 11.5px; color: var(--text-secondary); }
.tile .v { font-size: 20px; font-weight: 600; margin-top: 2px; }
.tile .d { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.table-wrap { max-height: 320px; overflow: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 5px 8px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
table.data th:first-child, table.data td:first-child, table.data th:nth-child(2), table.data td:nth-child(2) { text-align: left; }
table.data th { position: sticky; top: 0; background: var(--surface-1); color: var(--text-secondary); font-weight: 600; cursor: pointer; }
table.data tr:hover td { background: var(--row-hover); cursor: pointer; }
.legend {
  background: var(--legend-bg); padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-secondary); line-height: 1.3; min-width: 200px;
}
.legend .bar { height: 10px; border-radius: 2px; margin: 4px 0 2px; }
.legend .ends { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.legend .nodata { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.legend .nodata i { width: 14px; height: 10px; background: var(--nodata); border: 1px solid var(--axis); display: inline-block; }
.leaflet-tooltip.unit-tip { font-family: inherit; font-size: 12px; padding: 6px 8px; border-radius: 6px; }
.unit-tip b { font-weight: 600; }
.prose { max-width: 980px; line-height: 1.55; }
.prose h2 { margin-top: 16px; }
.prose code { background: var(--code-bg); padding: 1px 4px; border-radius: 4px; }
.prose table { border-collapse: collapse; margin: 8px 0; }
.prose td, .prose th { border-bottom: 1px solid var(--grid); padding: 4px 10px; text-align: left; font-size: 13px; }
#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--loading-bg); color: var(--text-primary); font-size: 16px; z-index: 9999; }
.theme-switch { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); padding: 0 4px 8px 12px; }
.theme-switch select { font: inherit; font-size: 12.5px; padding: 3px 6px; border: 1px solid var(--axis); border-radius: 6px; background: var(--control-bg); color: var(--text-primary); }
.header-right { display: flex; align-items: flex-end; gap: 4px; flex-wrap: wrap; }
/* Leaflet chrome follows the theme */
.leaflet-tooltip.unit-tip { background: var(--surface-2); color: var(--text-primary); border-color: var(--axis); }
.leaflet-tooltip.unit-tip::before { display: none; }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--surface-2); color: var(--text-primary); border-bottom-color: var(--axis); }
.leaflet-container .leaflet-control-attribution { background: var(--legend-bg); color: var(--muted); }
.leaflet-container .leaflet-control-attribution a { color: var(--text-secondary); }
.leaflet-container { background: var(--map-bg); }
