/* Historical explorer: the map-first overview. Tokens come from styles.css.
   Desktop: map and timeline on the left, layer, key and region on the right.
   Narrow: map, timeline, then layer, key and region, in reading order. */

.explorer-root { padding-top: var(--s6); }
.explorer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 340px);
  /* The timeline row is flexible, so a tall region panel adds space below the
     timeline rather than between it and the map. */
  grid-template-rows: auto auto 1fr auto auto;
  grid-template-areas:
    "head  head"
    "map   side"
    "tl    side"
    "lower lower"
    "table table";
  column-gap: var(--gap);
  align-items: start;
}
.ex-stage { display: contents; }
.ex-head { grid-area: head; padding-bottom: var(--s4); display: flex; flex-wrap: wrap; align-items: baseline; column-gap: var(--s6); row-gap: var(--s1); }
.ex-map-col { grid-area: map; min-width: 0; }
.ex-side { grid-area: side; min-width: 0; }
.ex-timeline { grid-area: tl; min-width: 0; margin-top: var(--s3); }
.ex-lower { grid-area: lower; min-width: 0; }
.ex-table-block { grid-area: table; min-width: 0; margin-top: var(--s10); border-top: 1px solid var(--rule); padding-top: var(--s6); }

.ex-title { font: 600 32px/40px var(--serif); letter-spacing: -0.01em; width: fit-content; max-width: 100%; }
.ex-deck { flex: 1 1 28em; font-size: 15px; line-height: 22px; color: var(--muted); }
.ex-deck strong { color: var(--ink); font-weight: 600; }
.ex-deck-period { font-family: var(--mono); color: var(--amber); font-size: 14px; }
.ex-jump { font-size: 14px; line-height: 20px; white-space: nowrap; }
.ex-jump:empty { display: none; }
.ex-title + .ex-deck { flex-basis: 100%; }
.ex-help > summary { cursor: pointer; color: var(--accent); width: fit-content; }
.ex-help > p { margin-top: var(--s1); }
.ex-muted { color: var(--muted); font-size: 13px; line-height: 20px; }
.ex-hint { margin-top: var(--s3); font-size: 14px; line-height: 20px; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); }

/* ------------------------------------------------------------------ map */

.ex-map-wrap {
  position: relative;
  height: clamp(400px, 58vh, 600px);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
}
.ex-map { position: absolute; inset: 0; }
/* MapLibre's own stylesheet loads later and sets .maplibregl-map to position: relative,
   which would collapse the holder to zero height; this selector outranks it. */
.ex-map > .webgl-map,
.ex-map > .webgl-map.maplibregl-map { position: absolute; inset: 0; width: 100%; height: 100%; }
.webgl-map .maplibregl-canvas:focus-visible { outline: 2px solid var(--amber); outline-offset: -2px; }
.ex-map-wrap[data-renderer="svg"] .ex-map { padding: var(--s3); }
.svg-map { display: block; width: 100%; height: 100%; }
.svg-map-region { stroke: var(--bg); stroke-width: 1; vector-effect: non-scaling-stroke; cursor: pointer; }
.svg-map-region:hover { stroke: var(--ink); stroke-width: 1.5; }
.svg-map-selected { fill: none; stroke: var(--amber); stroke-width: 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.svg-map-hatch-base { fill: var(--surface); }
.svg-map-hatch-line { stroke: var(--muted); stroke-width: 1.5; }

.ex-tools { position: absolute; top: var(--s3); right: var(--s3); display: flex; flex-direction: column; gap: var(--s1); align-items: flex-end; }
.ex-tool {
  min-width: 36px; height: 36px; padding: 0 var(--s2);
  background: var(--surface); color: var(--ink); border: 1px solid var(--control); border-radius: 4px;
  font: 500 18px/1 var(--sans); cursor: pointer;
}
.ex-tool:hover { border-color: var(--ink); }
.ex-tool-wide { font-size: 13px; }

.ex-tooltip {
  position: absolute; top: 0; left: 0; z-index: 2; pointer-events: none;
  max-width: 220px; padding: var(--s2) var(--s3);
  background: var(--surface); border: 1px solid var(--control); border-radius: 4px;
  font-size: 13px; line-height: 18px;
}
.ex-tooltip strong { display: block; font-weight: 600; }
.ex-tooltip span { display: block; color: var(--muted); font-family: var(--mono); font-size: 12px; }

.ex-map-overlay {
  position: absolute; left: var(--s3); bottom: var(--s3); right: var(--s3); z-index: 1;
  max-width: 380px; padding: var(--s3) var(--s4);
  background: rgba(11, 17, 25, 0.94); border-left: 2px solid var(--amber);
  font-size: 14px; line-height: 20px;
}
.ex-map-overlay .button-quiet { margin-top: var(--s2); }
.ex-map-wrap[data-renderer="none"] .ex-map-overlay { position: static; max-width: none; }
.ex-renderer-note { margin-top: var(--s2); font-size: 13px; line-height: 20px; color: var(--muted); }
.ex-mini-key { display: none; list-style: none; margin-top: var(--s2); flex-wrap: wrap; gap: var(--s1) var(--s3); font-size: 12px; line-height: 16px; color: var(--muted); }
.ex-mini-key li { display: inline-flex; align-items: center; gap: 6px; }
.ex-mini-key .ex-swatch { width: 12px; height: 12px; }

/* ------------------------------------------------------------- side */

.ex-side > * + * { margin-top: var(--s5); }
.ex-layers { border: 0; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; }
.ex-layers legend { font: 600 13px/20px var(--sans); color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; padding: 0; margin-bottom: var(--s2); }
.ex-layer { position: relative; }
.ex-layer input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.ex-layer label {
  display: flex; align-items: center; justify-content: center; text-align: center; height: 100%;
  min-height: 40px; padding: var(--s2) var(--s3);
  border: 1px solid var(--control); font-size: 13px; line-height: 17px; color: var(--muted); cursor: pointer;
}
.ex-layer + .ex-layer label { border-left: 0; }
.ex-layer:first-of-type label { border-radius: 4px 0 0 4px; }
.ex-layer:last-of-type label { border-radius: 0 4px 4px 0; }
.ex-layer input:checked + label { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 600; }
.ex-layer input:focus-visible + label { outline: 2px solid var(--amber); outline-offset: 2px; }
.ex-layer input:hover + label { color: var(--ink); border-color: var(--ink); }
.ex-layer input:checked:hover + label { color: var(--bg); }

.ex-key { border-top: 1px solid var(--rule); padding-top: var(--s4); }
.ex-legend-title { font: 600 15px/20px var(--sans); }
.ex-legend { list-style: none; margin-top: var(--s3); display: grid; gap: var(--s2); font-size: 13px; line-height: 18px; }
.ex-legend li { display: flex; align-items: center; gap: var(--s2); }
.ex-swatch { width: 16px; height: 16px; flex: none; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(228, 237, 245, 0.18); }
.ex-swatch-hatch { background: repeating-linear-gradient(45deg, var(--muted) 0 1.5px, var(--surface) 1.5px 5px); }
.ex-legend-source { margin-top: var(--s3); font-size: 13px; line-height: 20px; color: var(--muted); }

.ex-field label { display: block; font: 600 13px/20px var(--sans); color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: var(--s1); }
.ex-field select { width: 100%; }

.ex-region { border-top: 1px solid var(--rule); padding-top: var(--s4); }
.ex-region-name { font: 600 24px/30px var(--serif); }
.ex-facts { margin-top: var(--s3); }
.ex-facts > div { padding: var(--s2) 0; border-top: 1px solid var(--rule); }
.ex-facts > div:first-child { border-top: 0; padding-top: 0; }
.ex-facts dt { font-size: 13px; line-height: 20px; color: var(--muted); }
.ex-facts dd { font-size: 15px; line-height: 22px; }
.ex-reading-value { font: 600 22px/28px var(--sans); }
.ex-reading-missing, .ex-reading-none { color: var(--muted); }
.ex-reading-no-single { color: var(--amber); }
.ex-cases { margin-top: var(--s5); }
.ex-cases > .ex-muted { margin-bottom: var(--s2); }
.case-compact { padding: var(--s4) 0; border-top: 1px solid var(--rule); }
.case-compact .case-meta { display: flex; gap: var(--s3); align-items: baseline; }
.case-compact .case-city { margin-top: 0; font-size: 15px; line-height: 20px; }
.case-compact .case-title { font-size: 17px; line-height: 24px; margin: var(--s2) 0 0; }
.case-compact .case-body > * + * { margin-top: var(--s2); }
.case-compact .case-sources { grid-template-columns: minmax(0, 1fr); gap: var(--s3); }

/* --------------------------------------------------------- timeline */

.timeline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "track     track"
    "settings  transport"
    "status    status"
    "gaps      gaps";
  gap: var(--s3) var(--s6);
  padding: var(--s4);
  background: var(--surface);
  border-radius: 4px;
}
.tl-settings { grid-area: settings; display: flex; flex-wrap: wrap; gap: var(--s3); align-items: end; }
.tl-transport { grid-area: transport; display: flex; flex-wrap: wrap; gap: var(--s2); align-items: end; justify-content: flex-end; }
.tl-track { grid-area: track; }
.tl-status { grid-area: status; font-size: 14px; line-height: 20px; }
.tl-gaps { grid-area: gaps; font-size: 13px; line-height: 20px; }
.tl-field label { display: block; font-size: 12px; line-height: 16px; color: var(--muted); margin-bottom: var(--s1); }
.tl-field select, .tl-field input { min-height: 40px; }
.tl-field input[type="date"] {
  font: 400 14px/20px var(--mono); color: var(--ink); background: var(--bg);
  border: 1px solid var(--control); border-radius: 2px; padding: var(--s2);
}
.tl-field input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.8); }
.tl-button {
  min-height: 40px; padding: 0 var(--s4); border: 1px solid var(--control); border-radius: 4px;
  background: var(--bg); color: var(--ink); cursor: pointer; font-size: 14px; white-space: nowrap;
}
.tl-button:hover:not(:disabled) { border-color: var(--ink); }
.tl-button:disabled { opacity: 0.45; cursor: default; }
.tl-play { min-width: 84px; background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 600; }
.tl-play:hover:not(:disabled) { background: #FFFFFF; }
.timeline.is-playing .tl-play { background: var(--amber); border-color: var(--amber); }

.tl-slider-label { display: block; font: 600 13px/20px var(--sans); color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.tl-slider { display: block; width: 100%; margin: var(--s2) 0 0; height: 28px; background: transparent; accent-color: var(--amber); cursor: pointer; }
.tl-slider:disabled { cursor: default; }
.tl-slider::-webkit-slider-runnable-track { height: 4px; background: var(--control); border-radius: 2px; }
.tl-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; margin-top: -8px; border-radius: 50%; background: var(--amber); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--amber); }
.tl-slider::-moz-range-track { height: 4px; background: var(--control); border-radius: 2px; }
.tl-slider::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--amber); border: 2px solid var(--bg); }
.tl-slider { -webkit-appearance: none; appearance: none; }
.tl-slider:focus-visible { outline: 2px solid var(--amber); outline-offset: 4px; }
/* The strip is inset by half a thumb so each mark sits under its slider position. */
.tl-strip { position: relative; height: 8px; margin-top: var(--s1); overflow: hidden; }
.tl-marks { position: absolute; inset: 0 10px; }
.tl-marks span { position: absolute; top: 0; height: 8px; transform: translateX(-50%); border-radius: 1px; }
.tl-marks .tl-on { background: var(--accent); }
.tl-marks .tl-off { top: 5px; height: 3px; background: var(--control); }
.tl-ends { display: flex; justify-content: space-between; font: 400 12px/16px var(--mono); color: var(--muted); margin-top: var(--s1); }
.tl-gaps > summary { cursor: pointer; color: var(--accent); width: fit-content; }
.tl-gap-list { list-style: none; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); margin-top: var(--s2); }
.tl-gap-go { background: none; border: 1px dashed var(--control); border-radius: 2px; color: var(--ink); padding: 2px var(--s2); cursor: pointer; font: 400 13px/20px var(--sans); }
.tl-gap-go:hover { border-color: var(--ink); }

/* ------------------------------------------------------ lower panels */

.ex-lower { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--gap); margin-top: var(--s10); }
.ex-national, .ex-availability { border-top: 1px solid var(--rule); padding-top: var(--s6); }
.ex-national > .block-title, .ex-availability > .block-title { margin-bottom: var(--s4); }
.ex-stats { list-style: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s6) var(--gap); }
.ex-stat { border-top: 2px solid var(--ink); padding-top: var(--s3); min-width: 0; }
.ex-stat-withheld { border-top-color: var(--error); }
.ex-stat > * + * { margin-top: var(--s2); }
.ex-stat-label { font: 600 15px/20px var(--sans); }
.ex-period { font-size: 13px; line-height: 20px; color: var(--muted); }
.ex-period-offslot { color: var(--ink); border-left: 2px solid var(--amber); padding-left: var(--s2); }
.ex-figure { color: var(--muted); }
.ex-number { font: 600 40px/48px var(--sans); letter-spacing: -0.02em; color: var(--ink); }
.ex-figure-words { font: 600 18px/26px var(--sans); color: var(--amber); }
.ex-stat-withheld .ex-figure-words { color: var(--error); }
.ex-evidence { list-style: none; font-size: 13px; line-height: 20px; color: var(--muted); }
.ex-evidence li + li { margin-top: var(--s1); }
.ex-national .state { margin-top: 0; }
.ex-api { list-style: none; margin-top: var(--s2); }
.ex-api li + li { margin-top: var(--s1); }
.ex-api code { font-size: 12px; line-height: 18px; color: var(--accent); word-break: break-all; }
.ex-availability > p { margin-top: var(--s3); }
.ex-permalink { font-weight: 600; }
.ex-boundaries { margin-top: var(--s4) !important; }

.ex-table { min-width: 560px; }
.ex-row-select {
  background: none; border: 0; padding: 0; color: var(--accent); font: 500 14px/20px var(--sans);
  text-align: left; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
}
.ex-row-select:hover { color: var(--ink); }
.ex-row-select[aria-pressed="true"] { color: var(--ink); text-decoration: none; font-weight: 600; }
.ex-row-select[aria-pressed="true"]::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: var(--s2); background: var(--amber); border-radius: 50%; vertical-align: 1px; }
.ex-table tr.is-selected th, .ex-table tr.is-selected td { background: rgba(231, 198, 91, 0.07); }

/* The latest national month follows the explorer. */
.latest { margin-top: var(--s12); border-top: 2px solid var(--ink); }
.latest-title { font-size: 32px; line-height: 40px; }
.ov-state-slot { padding-top: var(--s4); }

/* ------------------------------------------------------- breakpoints */

@media (max-width: 1023px) {
  .explorer {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "head" "map" "tl" "side" "lower" "table";
  }
  .ex-side { margin-top: var(--s6); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s5) var(--gap); align-items: start; }
  .ex-side > * + * { margin-top: 0; }
  .ex-layers { grid-column: 1; }
  .ex-key { grid-column: 1; grid-row: 2 / span 2; }
  .ex-field { grid-column: 2; grid-row: 1; }
  .ex-region { grid-column: 2; grid-row: 2 / span 2; }
  .ex-map-wrap { height: clamp(360px, 56vw, 520px); }
  .ex-mini-key { display: flex; }
}

@media (max-width: 767px) {
  .ex-side { display: block; }
  .ex-side > * + * { margin-top: var(--s5); }
  .ex-lower { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .ex-availability { margin-top: var(--s8); }
  .timeline { grid-template-columns: minmax(0, 1fr); grid-template-areas: "track" "transport" "settings" "status" "gaps"; padding: var(--s3); }
  .tl-transport { justify-content: stretch; }
  .tl-transport .tl-button { flex: 1; }
  .tl-speed { flex-basis: 100%; }
  .tl-speed select { width: 100%; }
  .tl-settings .tl-field { flex: 1 1 140px; }
  .tl-settings input, .tl-settings select { width: 100%; }
}

@media (max-width: 599px) {
  .explorer-root { padding-top: var(--s4); }
  .ex-title { font-size: 26px; line-height: 32px; }
  .ex-deck { font-size: 14px; line-height: 20px; }
  .ex-jump { white-space: normal; }
  .ex-map-wrap { height: auto; aspect-ratio: 4 / 3; min-height: 260px; }
  .ex-tools { top: var(--s2); right: var(--s2); }
  .ex-tool-wide { display: none; }
  .tl-button-word { display: none; }
  .tl-button { min-width: 48px; }
  .latest-title { font-size: 26px; line-height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  .explorer *, .explorer *::before, .explorer *::after { transition: none !important; animation: none !important; }
}

@media (forced-colors: active) {
  .ex-swatch, .ex-layer label { forced-color-adjust: none; }
  .tl-marks span { forced-color-adjust: none; }
  .tl-marks .tl-on { background: CanvasText; }
  .tl-marks .tl-off { background: GrayText; }
}

/* Head: title and latest-month link on one line, the live deck beneath. */
.ex-title { order: 0; }
.ex-jump { order: 1; margin-left: auto; }
.ex-deck { order: 2; }
@media (max-width: 599px) { .ex-jump { margin-left: 0; order: 3; } }
