:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;   /* current course, men */
  --series-2: #eb6834;   /* changes, women */
  --series-3: #1baf7a;
  --ghost: #52514e;
  --seq-100: #cde2fb; --seq-200: #9ec5f4; --seq-300: #6da7ec; --seq-400: #3987e5;
  --seq-500: #256abf; --seq-600: #184f95; --seq-700: #0d366b;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --ghost: #c3c2b7;
    --seq-100: #1b2a3d; --seq-200: #184f95; --seq-300: #256abf; --seq-400: #3987e5;
    --seq-500: #6da7ec; --seq-600: #9ec5f4; --seq-700: #cde2fb;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --ghost: #c3c2b7;
  --seq-100: #1b2a3d; --seq-200: #184f95; --seq-300: #256abf; --seq-400: #3987e5;
  --seq-500: #6da7ec; --seq-600: #9ec5f4; --seq-700: #cde2fb;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--series-1); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(22px, 3.2vw, 32px); font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 650; }
button { font: inherit; color: inherit; }

.site-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  max-width: 1440px; margin: 0 auto; padding: 24px 24px 12px;
}
.lede { margin: 6px 0 0; color: var(--ink-2); max-width: 68ch; }

main { max-width: 1440px; margin: 0 auto; padding: 0 24px 24px; }

/* ---------- explorer ---------- */
.explorer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-areas: "map panel" "timeline timeline";
  gap: 12px;
}
.map-wrap {
  grid-area: map; position: relative; min-height: 560px; height: 68vh;
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border);
  background: var(--surface);
}
#map { position: absolute; inset: 0; background: var(--surface-2); }
.layer-toggles {
  position: absolute; top: 10px; right: 10px; z-index: 500;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.layer-toggles label { display: flex; gap: 6px; align-items: center; cursor: pointer; white-space: nowrap; }
.map-legend {
  position: absolute; left: 10px; bottom: 22px; z-index: 500;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; color: var(--ink-2);
  display: flex; flex-direction: column; gap: 3px; box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.map-legend .row { display: flex; align-items: center; gap: 8px; }
.map-legend .sw { width: 22px; height: 0; border-top: 3px solid; border-radius: 2px; }
.year-watermark {
  position: absolute; left: 14px; top: 10px; z-index: 450; pointer-events: none;
  font-size: 44px; font-weight: 800; color: var(--ink); opacity: .85;
  text-shadow: 0 0 6px var(--surface), 0 0 2px var(--surface);
}

.panel {
  grid-area: panel; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; overflow-y: auto; max-height: 68vh; min-height: 560px;
}
.panel .year { font-size: 44px; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.panel .sub { color: var(--ink-2); margin-top: 4px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 12px;
  padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border);
}
.badge .dot { width: 10px; height: 10px; border-radius: 50%; }
.change-line { color: var(--ink-2); font-size: 13px; margin-top: 6px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.tile { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.tile .label { font-size: 12px; color: var(--ink-2); }
.tile .value { font-size: 20px; font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.tile .note { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wr { font-size: 11px; font-weight: 700; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--series-2); color: var(--ink); margin-left: 4px; vertical-align: 3px; }
.facts { margin: 14px 0 0; padding: 0; list-style: none; font-size: 13px; }
.facts li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--grid); }
.facts li span:first-child { color: var(--ink-2); }
.facts li span:last-child { text-align: right; }
.notes { font-size: 13px; color: var(--ink-2); margin-top: 12px; }
.source-map { margin-top: 12px; }
.source-map img { width: 100%; border-radius: 6px; border: 1px solid var(--border); cursor: zoom-in; display: block; }
.source-map figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }

.timeline {
  grid-area: timeline; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px 6px;
  display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center;
}
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-size: 20px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn:hover, .play-btn:hover { filter: brightness(0.96); }
.play-btn {
  width: 48px; height: 48px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--series-1); color: #fff; font-size: 18px;
}
.speed { font-size: 13px; color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center; }
.speed select { font: inherit; background: var(--surface-2); color: var(--ink); border: 1px solid var(--border); border-radius: 6px; padding: 3px 4px; }
.scrubber-wrap { min-width: 0; }
#scrubber { width: 100%; height: 86px; display: block; cursor: pointer; touch-action: none; outline: none; }
#scrubber:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; border-radius: 6px; }
.scrubber-caption { margin: 0; font-size: 12px; color: var(--muted); }

/* ---------- charts ---------- */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card header p { margin: 4px 0 0; color: var(--ink-2); font-size: 13px; max-width: 90ch; }
.card header { position: relative; }
.chart { margin-top: 10px; position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.axis text, .axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.axis path, .axis line { stroke: var(--axis); }
.grid line { stroke: var(--grid); }
.grid path { display: none; }
.direct-label { fill: var(--ink-2); font-size: 12px; }
.seg { display: inline-flex; margin-top: 8px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-btn { border: none; background: var(--surface); padding: 4px 12px; cursor: pointer; font-size: 13px; }
.seg-btn.active { background: var(--surface-2); font-weight: 650; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend .ln { width: 16px; height: 0; border-top: 2px solid; display: inline-block; }

.ranked { margin-top: 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.ranked .item { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; font-size: 13px; cursor: pointer; border: 1px solid transparent; }
.ranked .item:hover { border-color: var(--series-1); }
.ranked .item b { font-size: 15px; }
.ranked .item .muted { color: var(--ink-2); }

.table-wrap { overflow-x: auto; margin-top: 10px; }
table { border-collapse: collapse; font-size: 13px; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 5px 8px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
th { color: var(--ink-2); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
details summary { cursor: pointer; color: var(--series-1); margin-top: 8px; }

.tooltip {
  position: fixed; z-index: 2000; pointer-events: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; max-width: 280px;
  box-shadow: 0 4px 16px rgba(0,0,0,.14);
}
.tooltip b { font-size: 13px; }
.tooltip .muted { color: var(--ink-2); }

.lightbox { position: fixed; inset: 0; z-index: 3000; background: rgba(0,0,0,.82); display: flex; align-items: center; justify-content: center; padding: 24px; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; background: #fff; }
.lightbox-close { position: absolute; top: 16px; right: 16px; background: #fff; color: #000; }

.site-footer { max-width: 1440px; margin: 0 auto; padding: 8px 24px 40px; color: var(--muted); font-size: 12px; }

/* Leaflet theming */
.leaflet-container { font: 12px/1.4 var(--font); background: var(--surface-2); }
.leaflet-bar a { background: var(--surface); color: var(--ink); border-color: var(--border); }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--ink-2); }
.leaflet-tooltip.street-tip { background: var(--surface); color: var(--ink); border: 1px solid var(--border); box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.leaflet-tooltip.street-tip::before { display: none; }
.pin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px rgba(0,0,0,.3); }
.pin-label { font-size: 11px; font-weight: 700; color: var(--ink); text-shadow: 0 0 3px var(--surface), 0 0 3px var(--surface); white-space: nowrap; }

@media (max-width: 960px) {
  .explorer { grid-template-columns: minmax(0, 1fr); grid-template-areas: "map" "timeline" "panel"; }
  .map-wrap { height: 62vh; min-height: 420px; }
  .panel { max-height: none; min-height: 0; }
  .timeline { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .charts { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .site-header { padding: 16px 16px 8px; }
  main { padding: 0 16px 16px; }
  .site-footer { padding: 8px 16px 32px; }
  .map-wrap { height: auto; min-height: 0; display: flex; flex-direction: column; }
  #map { position: relative; inset: auto; height: 56vh; min-height: 340px; }
  .layer-toggles, .map-legend {
    position: static; box-shadow: none; border: none; border-top: 1px solid var(--border); border-radius: 0;
  }
  .layer-toggles { flex-direction: row; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }
  .map-legend { flex-direction: row; flex-wrap: wrap; gap: 4px 14px; }
  .year-watermark { font-size: 32px; }
  .tiles { grid-template-columns: 1fr 1fr; }
}
