/*
 * Above the Hook: coastal, editorial, understated.
 * Deep navy ink, sea-glass accents, sand ground, off-white cards.
 * Mobile-first — every layout rule starts at phone width and widens from there.
 */

:root {
  color-scheme: light;
  --sand:        #f4f0e8;
  --surface-1:   #fcfcfb;   /* chart surface the palette was validated against */
  --navy:        #0d1a24;
  --sea-glass:   #8fb8b0;
  --rule:        #e6e2d8;
  --text-primary:   #16242e;
  --text-secondary: #4d5b66;
  --text-muted:     #6f7d88;
  --shadow: 0 1px 2px rgb(13 26 36 / 6%), 0 8px 24px -12px rgb(13 26 36 / 14%);
  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --sand:      #08131b;
    --surface-1: #0d1a24;   /* validated dark surface */
    --navy:      #e8eef2;
    --sea-glass: #6f9b93;
    --rule:      #22323f;
    --text-primary:   #eaf1f5;
    --text-secondary: #b3c3ce;
    --text-muted:     #8b9ca8;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px -12px rgb(0 0 0 / 60%);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --sand: #08131b; --surface-1: #0d1a24; --navy: #e8eef2; --sea-glass: #6f9b93;
  --rule: #22323f; --text-primary: #eaf1f5; --text-secondary: #b3c3ce; --text-muted: #8b9ca8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--sand);
  color: var(--text-primary);
  font: 15px/1.55 var(--sans);
  -webkit-text-size-adjust: 100%;
}

.viz-root { max-width: 62rem; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

/* ---------- masthead ---------- */

.masthead { padding: 0.5rem 0 1.5rem; border-bottom: 1px solid var(--rule); margin-bottom: 1.5rem; }

.eyebrow {
  margin: 0 0 0.5rem;
  font: 600 11px/1 var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sea-glass);
}

.masthead h1 {
  margin: 0;
  font: 400 clamp(1.9rem, 7vw, 2.9rem)/1.1 var(--serif);
  letter-spacing: -0.015em;
  color: var(--text-primary);
}

.station {
  margin: 0.6rem 0 0;
  font: 400 13px/1.4 var(--sans);
  color: var(--text-muted);
}

/* ---------- panels ---------- */

.panel {
  background: var(--surface-1);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.25rem 1rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.panel-head h2 {
  margin: 0;
  font: 600 1.0625rem/1.3 var(--sans);
  letter-spacing: -0.01em;
}

.lede {
  margin: 0.4rem 0 0;
  max-width: 46ch;
  font-size: 13.5px;
  color: var(--text-secondary);
}

/* ---------- controls: one row above the chart ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  margin: 1.1rem 0 0.85rem;
}

.control { display: flex; align-items: center; gap: 0.5rem; }

.control-label {
  font: 600 10px/1 var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.segmented {
  display: inline-flex;
  background: var(--sand);
  border: 1px solid var(--rule);
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}

.seg {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: 500 12.5px/1 var(--sans);
  padding: 0.5rem 0.7rem;      /* >=44px tall touch target with line-height */
  min-height: 34px;
  border-radius: 5px;
  cursor: pointer;
}

.seg[aria-pressed="true"] {
  background: var(--surface-1);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgb(13 26 36 / 10%);
}

.seg:focus-visible, .chip:focus-visible { outline: 2px solid var(--sea-glass); outline-offset: 2px; }

/* ---------- legend: always present, doubles as the on/off control ---------- */

.legend { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.9rem; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 34px;
  padding: 0.35rem 0.6rem;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  cursor: pointer;
  font: 500 12.5px/1 var(--sans);
  color: var(--text-secondary);
}

.chip[aria-pressed="true"] { border-color: var(--text-muted); color: var(--text-primary); }
.chip[aria-pressed="false"] { opacity: 0.6; }

.chip-swatch {
  width: 10px; height: 10px; border-radius: 3px;
  border: 1.5px solid transparent; flex: none;
}

.chip-year { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 11.5px; }

/* ---------- chart ---------- */

.chart-holder { position: relative; }

/* Height includes the x-axis band, so the axis labels are never cropped. */
#chart { width: 100%; height: 340px; }
@media (min-width: 40rem) { #chart { height: 420px; } }

.tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--rule);
  border-radius: 7px;
  padding: 0.5rem 0.6rem;
  box-shadow: var(--shadow);
  font-size: 12px;
  min-width: 13rem;
}

.tt-head {
  font: 600 10px/1 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-bottom: 0.4rem;
  margin-bottom: 0.35rem;
  border-bottom: 1px solid var(--rule);
}

.tt-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.15rem 0;
}

.tt-swatch { width: 10px; height: 10px; border-radius: 3px; }
.tt-name { color: var(--text-secondary); }
.tt-value { font: 600 12.5px/1 var(--mono); font-variant-numeric: tabular-nums; color: var(--text-primary); }
.tt-time { grid-column: 2 / -1; font-size: 11px; color: var(--text-muted); }

/* ---------- threshold key + notes ---------- */

.threshold-key {
  display: flex; flex-wrap: wrap; gap: 0.35rem 1rem;
  margin: 0.9rem 0 0;
  font-size: 12px; color: var(--text-secondary);
}

.key-item { display: inline-flex; align-items: center; gap: 0.3rem; }
.key-icon { font-size: 13px; }
.key-num { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--text-muted); }

.footnote { margin: 0.65rem 0 0; font-size: 12px; color: var(--text-muted); max-width: 60ch; }

.forecast-slot {
  display: flex; gap: 0.65rem; align-items: flex-start;
  margin-top: 1.1rem; padding-top: 1rem;
  border-top: 1px dashed var(--rule);
  font-size: 12.5px; color: var(--text-secondary);
}

.forecast-slot strong { color: var(--text-primary); }

.forecast-dash {
  flex: none; width: 26px; height: 0;
  margin-top: 0.55rem;
  border-top: 2px dashed var(--sea-glass);
}

/* ---------- table ---------- */

.table-scroll { overflow-x: auto; margin-top: 1rem; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th, td {
  text-align: left;
  padding: 0.55rem 0.7rem 0.55rem 0;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

thead th {
  font: 600 10px/1.3 var(--sans);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  vertical-align: bottom;
}

.unit { display: block; font-weight: 400; letter-spacing: 0; text-transform: none; font-size: 10px; opacity: 0.8; }

tbody th {
  font-weight: 500;
  color: var(--text-primary);
  display: flex; align-items: center; gap: 0.45rem;
  border-bottom: 0;
}

tbody tr { border-bottom: 1px solid var(--rule); }
tbody th, tbody td { border-bottom: 0; }

.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
thead .num { text-align: right; }

.row-off { opacity: 0.45; }

.plus { color: #d03b3b; font-weight: 700; }

.flag {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: rgb(208 59 59 / 12%);
  color: #d03b3b;
  font: 600 10px/1.4 var(--sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---------- caveats, credits ---------- */

.caveats { margin: 0.9rem 0 0; padding-left: 1.1rem; font-size: 13px; color: var(--text-secondary); }
.caveats li { margin-bottom: 0.6rem; max-width: 66ch; }
.caveats li:last-child { margin-bottom: 0; }
.caveats.static { margin-top: 0.6rem; }
.caveats strong { color: var(--text-primary); }

.credits {
  margin-top: 1.75rem; padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-size: 12px; color: var(--text-muted);
}

.credits p { margin: 0 0 0.6rem; max-width: 70ch; }
.credits strong { color: var(--text-secondary); font-weight: 600; }
.credits a { color: var(--sea-glass); text-decoration: underline; text-underline-offset: 2px; }
.fineprint { font-style: italic; }

.error {
  padding: 0.9rem 1rem;
  border: 1px solid #d03b3b;
  border-radius: 8px;
  background: rgb(208 59 59 / 8%);
  color: var(--text-primary);
  font-size: 13.5px;
}

/* uPlot chrome should recede into the page, not assert itself. */
.uplot, .uplot * { font-family: var(--sans) !important; }
.u-axis { color: var(--text-muted); }
