/* Theme tokens. Light is the default. Dark applies only when the reader picks
   it (stored per browser). The map's canvas layers read --map-bg,
   --particle and --overlay-alpha from here (see js/theme.js), so map and
   page always switch together.
   Text colors meet 4.5:1 contrast against --bg in both themes. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #f3f4f6;
  --ink: #121417;          /* 18.6:1 on white */
  --ink-muted: #4b5260;    /* 7.9:1 on white */
  --line: #d9dce1;
  --focus: #2b59c3;
  --button-bg: #121417;
  --button-ink: #ffffff;
  --hrrr: #dfe5f0;
  --gfs: #eceef2;

  /* Map */
  --map-bg: #ffffff;
  /* White trails in both themes. In light mode the fill is drawn at full
     strength (no blending toward white, which turned viridis a muddy
     lavender), using a palette dark enough for white lines; see theme.js. */
  --particle: #ffffff;  /* fully opaque, so trails read as white, not gray */
  /* Dark edge under white trails, drawn ONLY where the fill is too light for
     white alone (below 3:1, i.e. the yellow-orange band, or the plain white
     map when the color layer is off). See overlay.js / particles.js. */
  --particle-casing: rgba(20, 28, 40, 0.28);
  --overlay-alpha: 1;
  /* The map is a mid-to-dark teal/navy field in light mode too, so boundary
     lines are white, as in dark mode. */
  --state-line: #ffffff;
  --coast-line: rgba(255, 255, 255, 0.95);
  --border-casing: rgba(15, 25, 40, 0.55);
  /* County lines are thin and secondary: dark at low opacity reads on both
     the blues and the yellows without competing with state lines. */
  --county-line: rgba(15, 25, 40, 0.28);
  /* White labels with a dark halo: dark-on-white-halo labels got lost among
     the white particle trails. */
  --label-ink: #ffffff;
  --label-halo: rgba(8, 22, 34, 0.85);
  --readout-bg: rgba(255, 255, 255, 0.95);

  /* Fonts: Inquirer faces from fonts.css. They load only on inquirer.com
     (the font server's CORS policy allows that origin only), so the fallbacks
     are chosen to match their style:
       Grot 10: grotesque sans -> Helvetica Neue / Helvetica / Arial
       Inquirer Headline: serif -> Georgia / Times New Roman */
  --font-sans: "Grot 10", "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --font-head: "Inquirer Headline", Georgia, "Times New Roman", Times, serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #181b21;
  --ink: #eceef1;          /* 16.9:1 on --bg */
  --ink-muted: #a9b0bb;    /* 8.6:1 on --bg */
  --line: #2c313a;
  --focus: #fde725;
  --button-bg: #eceef1;
  --button-ink: #0f1115;
  --hrrr: #3b4a63;
  --gfs: #2a3140;

  --map-bg: #07080a;
  --particle: rgba(255, 255, 255, 0.85);
  --particle-casing: ;  /* none: the dark fill already gives white trails contrast */
  --overlay-alpha: 0.55;
  --state-line: rgba(255, 255, 255, 0.85);
  --county-line: rgba(255, 255, 255, 0.16);
  --coast-line: rgba(255, 255, 255, 0.8);
  --border-casing: rgba(0, 0, 0, 0.6);
  --label-ink: #ffffff;
  --label-halo: rgba(0, 0, 0, 0.85);
  --readout-bg: rgba(15, 17, 21, 0.92);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-sans); }
body { line-height: 1.45; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }

.masthead { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
h1 { font-family: var(--font-head); font-weight: 600; font-size: clamp(1.4rem, 3.4vw, 2.1rem); line-height: 1.15; margin: 0 0 6px; }
.dek { margin: 0 0 14px; color: var(--ink-muted); max-width: 60ch; }

#theme-toggle {
  flex: none; font: inherit; font-size: 0.85rem; font-weight: 500; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; min-height: 36px; cursor: pointer; white-space: nowrap;
}

/* --- Time controls ------------------------------------------------------ */
.time-panel { background: var(--panel); border-radius: 8px; padding: 10px 12px 8px; margin-bottom: 10px; }
.time-row { display: flex; gap: 12px; align-items: center; }
#play {
  font: inherit; font-weight: bold; color: var(--button-ink); background: var(--button-bg);
  border: 0; border-radius: 6px; padding: 8px 14px; min-width: 72px; min-height: 40px; cursor: pointer;
}
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.valid-time { font-size: 1.15rem; font-weight: bold; }
.time-meta { font-size: 0.85rem; color: var(--ink-muted); }

.slider-wrap { position: relative; margin-top: 8px; }
#time-slider { width: 100%; margin: 0; accent-color: var(--ink); height: 28px; }
.day-ticks { position: relative; height: 16px; font-size: 0.72rem; color: var(--ink-muted); }
.day-tick { position: absolute; top: 0; transform: translateX(-1px); padding-left: 3px; border-left: 1px solid var(--line); white-space: nowrap; }
.segments { display: flex; gap: 2px; margin-top: 4px; font-size: 0.72rem; color: var(--ink-muted); }
.segment { border-radius: 4px; padding: 1px 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-width: 0; }
.segment-hrrr { background: var(--hrrr); }
.segment-gfs { background: var(--gfs); }

/* --- Map ---------------------------------------------------------------- */
.map {
  position: relative; width: 100%; background: var(--map-bg); border-radius: 8px;
  border: 1px solid var(--line); overflow: hidden; cursor: crosshair; touch-action: manipulation;
}
.map canvas, .map svg { position: absolute; inset: 0; display: block; }
#particles { pointer-events: none; }

/* Borders. State lines and coastline are a white core over a dark casing
   (same idea as the trail edges), so they read on blue, yellow and red alike.
   stroke-linejoin round keeps the casing from spiking at sharp corners. */
.county-lines { fill: none; stroke: var(--county-line); stroke-width: 0.6; }
.border-casing { fill: none; stroke: var(--border-casing); stroke-linejoin: round; stroke-linecap: round; }
.state-casing { stroke-width: 3.2; }
.coast-casing { stroke-width: 2.6; }
.state-lines { fill: none; stroke: var(--state-line); stroke-width: 1.4; stroke-linejoin: round; }
.coast-lines { fill: none; stroke: var(--coast-line); stroke-width: 1.1; stroke-linejoin: round; }
.city circle { fill: var(--label-ink); stroke: var(--label-halo); stroke-width: 1.5; }
.city text {
  fill: var(--label-ink); font-family: var(--font-sans); font-size: 12px; font-weight: 500;
  paint-order: stroke; stroke: var(--label-halo); stroke-width: 3px; stroke-linejoin: round;
}
.city-focus text { font-size: 14px; font-weight: bold; }
/* Light mode with the color layer off: the map is plain white, so boundary
   lines switch back to dark (white lines would vanish). */
:root:not([data-theme="dark"]) .map.is-unfilled {
  --state-line: rgba(18, 20, 23, 0.7);
  --county-line: rgba(18, 20, 23, 0.16);
  --coast-line: rgba(18, 20, 23, 0.8);
  --border-casing: transparent;
}
#readout-marker { fill: none; stroke: var(--label-ink); stroke-width: 2; }

.readout {
  position: absolute; z-index: 2; pointer-events: none;
  background: var(--readout-bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 9px; font-size: 0.85rem; line-height: 1.35; white-space: nowrap;
}
.status { position: absolute; left: 10px; bottom: 8px; font-size: 0.85rem; color: var(--label-ink); text-shadow: 0 0 3px var(--label-halo); }

/* --- Legend and layer control ------------------------------------------- */
.controls { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-end; justify-content: space-between; margin-top: 10px; }
.legend { width: min(320px, 100%); }
.legend-title { font-size: 0.85rem; color: var(--ink-muted); margin-bottom: 4px; }
#legend-canvas { width: 100%; height: 10px; display: block; border-radius: 2px; border: 1px solid var(--line); }
.legend-ticks { position: relative; height: 16px; font-size: 0.75rem; color: var(--ink-muted); }
.legend-ticks span { position: absolute; transform: translateX(-50%); top: 2px; }
.legend-ticks span:first-child { transform: none; }
.legend-ticks span:last-child { transform: translateX(-100%); }
.legend.is-off { opacity: 0.35; }
.layer-control { font-size: 0.9rem; color: var(--ink-muted); display: flex; gap: 8px; align-items: center; }
select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-height: 36px; }

.summary { font-size: 1rem; margin: 14px 0 12px; min-height: 1.5em; }

/* Footer spans the full width of the map (no max-width), so the source line
   isn't cut short on the right. overflow-wrap guards long tokens on phones. */
footer { border-top: 1px solid var(--line); padding-top: 10px; font-size: 0.82rem; color: var(--ink-muted); }
footer p { margin: 0 0 6px; overflow-wrap: anywhere; }
.source strong { color: var(--ink); font-weight: bold; }
.credit { color: var(--ink); font-weight: 500; }

@media (max-width: 480px) {
  .wrap { padding: 12px 16px; }
  .valid-time { font-size: 1rem; }
  .time-meta { font-size: 0.78rem; }
}
