:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f2f2ef;
  --border: #d8d8d2;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #767570;
  /* series slots 1 & 2 (validated adjacent + all-pairs, both modes) */
  --fcst: #2a78d6;
  --fcst-r: #8ab5e8;
  --obs: #eb6834;
  --vmgd: #767570;
  --critical: #c02526;
  --aoi: #1baf7a;
  /* trigger-design colors, carried over from the marimo explorer */
  --wind: #8b4513;
  --rain: #4682b4;
  --zone: #d4a500;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #262625;
    --border: #3d3d3a;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #9a998f;
    --fcst: #3987e5;
    --fcst-r: #5f93cf;
    --obs: #d95926;
    --vmgd: #9a998f;
    --critical: #e66767;
    --aoi: #199e70;
    --wind: #c98a55;
    --rain: #7aa9d6;
    --zone: #e0b420;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #262625;
  --border: #3d3d3a;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #9a998f;
  --fcst: #3987e5;
  --fcst-r: #5f93cf;
  --obs: #d95926;
  --vmgd: #9a998f;
  --critical: #e66767;
  --aoi: #199e70;
  --wind: #c98a55;
  --rain: #7aa9d6;
  --zone: #e0b420;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 0 1.25rem 3rem;
  background: var(--surface-1);
  color: var(--text-primary);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  max-width: 1180px;
  margin-inline: auto;
}
h1 { font-size: 1.6rem; margin: 1.5rem 0 .4rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 2rem 0 .25rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; color: var(--text-secondary); }
.lede { color: var(--text-secondary); max-width: 68ch; margin: 0 0 .75rem; }
.hint { color: var(--text-muted); font-size: .85rem; margin: .1rem 0 .75rem; }

.caveat { border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); max-width: 78ch; }
.caveat > summary { cursor: pointer; padding: .5rem .75rem; font-weight: 600; font-size: .9rem; }
.caveat > div { padding: 0 .75rem .25rem; font-size: .875rem; color: var(--text-secondary); }
.caveat p { margin: 0 0 .7rem; }

.controls {
  display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: center;
  padding: .75rem 0; margin-top: 1rem;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  font-size: .875rem;
}
.controls label { display: flex; align-items: center; gap: .4rem; color: var(--text-secondary); }
.controls input[type=number] { width: 7rem; }
.controls input, .controls select {
  font: inherit; padding: .25rem .4rem; border: 1px solid var(--border);
  border-radius: 4px; background: var(--surface-1); color: var(--text-primary);
}
.controls .unit { color: var(--text-muted); }
.controls .check { gap: .35rem; }

.stat-row { display: flex; flex-wrap: wrap; gap: 2.5rem; margin: 1.1rem 0 .25rem; }
.stat { min-width: 8rem; }
.stat .v { font-size: 1.75rem; font-weight: 650; letter-spacing: -.02em; }
.stat .k { font-size: .8rem; color: var(--text-secondary); }
.stat.alert .v { color: var(--critical); }
.note { font-size: .85rem; color: var(--text-secondary); margin: .3rem 0 0; max-width: 82ch; }

#chart svg, #cycleChart svg { display: block; width: 100%; height: auto; overflow: visible; }
.bar-row:hover rect.hit { fill: var(--surface-2); }
.bar-row { cursor: pointer; }
.bar-row.sel rect.hit { fill: var(--surface-2); }
.axis-label { fill: var(--text-muted); font-size: 10px; }
.storm-label { fill: var(--text-primary); font-size: 11px; }
.storm-label.over { font-weight: 650; }
.val-label { fill: var(--text-secondary); font-size: 10px; }
.gridline { stroke: var(--border); stroke-width: 1; }
.threshline { stroke: var(--critical); stroke-width: 2; stroke-dasharray: 4 3; }
.threshlabel { fill: var(--critical); font-size: 10px; font-weight: 600; }

.tableview { margin-top: 1rem; font-size: .85rem; }
.tableview summary { cursor: pointer; color: var(--text-secondary); }
table { border-collapse: collapse; margin-top: .6rem; width: 100%; }
th, td { text-align: right; padding: .3rem .5rem; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-secondary); font-weight: 600; }
td.over { color: var(--critical); font-weight: 650; }

.detail-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 1.5rem; }
@media (max-width: 860px) { .detail-grid { grid-template-columns: 1fr; } }
#map { height: 430px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); }
.cycle-ctl { display: flex; align-items: center; gap: .6rem; margin-top: .6rem; }
.cycle-ctl input[type=range] { flex: 1; }
#playBtn {
  font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-primary); border-radius: 4px; width: 2rem; height: 1.85rem; line-height: 1;
}
.cycle-label { font-variant-numeric: tabular-nums; font-size: .82rem; color: var(--text-secondary); min-width: 12.5rem; }

.legend { list-style: none; padding: 0; margin: .7rem 0 0; display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; font-size: .78rem; color: var(--text-secondary); }
.legend li { display: flex; align-items: center; gap: .35rem; }
.legend em { color: var(--text-muted); font-style: normal; }
.sw { width: 14px; height: 10px; border-radius: 2px; display: inline-block; }
.sw-fcst { background: color-mix(in srgb, var(--fcst) 35%, transparent); border: 1.5px solid var(--fcst); }
.sw-obs { background: color-mix(in srgb, var(--obs) 25%, transparent); border: 1.5px solid var(--obs); }
.sw-aoi { background: color-mix(in srgb, var(--aoi) 18%, transparent); border: 1.5px solid var(--aoi); }
.ln { width: 16px; height: 0; border-top: 2.5px solid; display: inline-block; }
.ln-fcst { border-color: var(--fcst); }
.ln-obs { border-color: var(--obs); }
.ln-vmgd { border-color: var(--vmgd); border-top-style: dashed; }

.cycle-info { margin-top: .8rem; font-size: .85rem; color: var(--text-secondary); }
.cycle-info dl { display: grid; grid-template-columns: auto 1fr; gap: .2rem .8rem; margin: 0; }
.cycle-info dt { color: var(--text-muted); }
.cycle-info dd { margin: 0; font-variant-numeric: tabular-nums; }

.page-foot { margin-top: 2.5rem; padding-top: .9rem; border-top: 1px solid var(--border); font-size: .78rem; color: var(--text-muted); }
.page-foot code { font-size: .95em; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 999;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 4px;
  padding: .4rem .55rem; font-size: .78rem; color: var(--text-primary);
  box-shadow: 0 2px 8px rgb(0 0 0 / .16); white-space: nowrap;
}
.leaflet-container { background: var(--surface-2); }

/* -------- tabs -------- */
.tabs { display: flex; gap: .25rem; margin: .75rem 0 0; border-bottom: 1px solid var(--border); }
.tab {
  font: inherit; font-size: .92rem; cursor: pointer;
  padding: .5rem .9rem; border: 1px solid transparent; border-bottom: none;
  background: none; color: var(--text-secondary); border-radius: 6px 6px 0 0;
}
.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--text-primary); font-weight: 650;
  border-color: var(--border); background: var(--surface-1);
  margin-bottom: -1px; padding-bottom: calc(.5rem + 1px);
}
.tabpanel > .lede { margin-top: 1rem; }

/* -------- trigger designer -------- */
.caveat.block { margin-top: 1.5rem; max-width: none; }
.wind-lab { color: var(--wind); font-weight: 600; }
.rain-lab { color: var(--rain); font-weight: 600; }
.radio-group { display: flex; gap: .9rem; align-items: center; color: var(--text-secondary); }

.zone-label { fill: var(--zone); font-size: 12px; font-weight: 700; }
.axis-title { fill: var(--text-secondary); font-size: 11px; }
.pt-label { font-size: 8.5px; }
.pt-label.trig { font-weight: 700; font-size: 9.5px; }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; opacity: .55; }

.chip {
  display: inline-block; padding: 0 .5em; border-radius: 3px;
  font-size: .78rem; font-weight: 650; color: #fff;
}
.chip-trig { background: #8e44ad; }
.chip-cerf { background: var(--critical); }
.trig-row td:first-child { font-weight: 650; }

.impact-bar {
  display: inline-block; min-width: 8.5em; text-align: right;
  padding-right: .3em; border-radius: 2px;
  background: linear-gradient(to right,
    color-mix(in srgb, #8e44ad 30%, transparent) var(--w), transparent var(--w));
}

.corr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; max-width: 900px; }
@media (max-width: 720px) { .corr-grid { grid-template-columns: 1fr; } }
.corr-grid svg { display: block; width: 100%; height: auto; }

.scroll-x { overflow-x: auto; }

/* design-tab map */
#dMap { height: 420px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); }
.d-pt { cursor: pointer; }
.d-pt:hover { opacity: .55; }
.d-row { cursor: pointer; }
.d-row:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.sel-row td:first-child { text-decoration: underline; text-underline-offset: 3px; }
.sw-r34 { background: color-mix(in srgb, #e0a800 30%, transparent); border: 1.5px solid #e0a800; }
.sw-r50 { background: color-mix(in srgb, #ee8434 35%, transparent); border: 1.5px solid #ee8434; }
.sw-r64 { background: color-mix(in srgb, #c02526 40%, transparent); border: 1.5px solid #c02526; }

.locked-trigger { color: var(--text-secondary); }
.locked-trigger strong { color: var(--text-primary); }

/* RP breakdown */
#rpTable td { vertical-align: top; text-align: left; font-size: .85rem; }
#rpTable th { text-align: left; }
#rpTable td:last-child, #rpTable th:last-child { text-align: right; }
.rp-storms { color: var(--text-muted); font-size: .78rem; }
.storm-list { text-align: left; font-size: .78rem; color: var(--text-secondary); max-width: 34ch; }
#dScatter svg { display: block; width: 100%; height: auto; }

.rp-chart-title { margin-top: 1.2rem; }
#rpChart svg { display: block; width: 100%; height: auto; }

#rpxScatter svg { max-width: 640px; }
