/* Shared chrome for every variant, so the eight renderings can be compared
   without the UI itself being a variable. */

/* Light is the default; dark is opt-in via data-theme="dark" on <html>.
   Only the colour tokens change between themes — every rule below reads them. */
:root {
  --bg: #eaeef4;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-solid: #ffffff;
  --edge: rgba(15, 23, 42, 0.13);
  --edge-strong: rgba(15, 23, 42, 0.26);
  --ink: #0f172a;
  --ink-dim: #475569;
  --ink-faint: #71809a;
  --accent: #0678b8;
  --on-accent: #ffffff;
  --accent-warm: #b45309;
  --observed: #0e9f6e;
  --forecast: #d97706;
  --observed-wash: rgba(14, 159, 110, 0.14);
  --forecast-wash: rgba(217, 119, 6, 0.14);
  --control: rgba(15, 23, 42, 0.05);
  --control-hover: rgba(15, 23, 42, 0.09);
  --danger: #dc2626;
  --shadow: 0 8px 26px rgba(15, 23, 42, 0.14);
  --cursor: #0f172a;
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #0b1017;
  --panel: rgba(17, 24, 34, 0.86);
  --panel-solid: #121926;
  --edge: rgba(255, 255, 255, 0.11);
  --edge-strong: rgba(255, 255, 255, 0.2);
  --ink: #e9eef6;
  --ink-dim: #93a2b8;
  --ink-faint: #64748b;
  --accent: #4fc3f7;
  --on-accent: #04121c;
  --accent-warm: #ffb648;
  --observed: #6ee7b7;
  --forecast: #fbbf24;
  --observed-wash: rgba(110, 231, 183, 0.16);
  --forecast-wash: rgba(251, 191, 36, 0.16);
  --control: rgba(255, 255, 255, 0.06);
  --control-hover: rgba(255, 255, 255, 0.1);
  --danger: #f87171;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  --cursor: #ffffff;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------- layout -------------------------------- */
.app { display: grid; grid-template-rows: auto 1fr; height: 100%; }

.hdr {
  display: flex; align-items: center; gap: 14px;
  padding: 9px 16px;
  background: var(--panel-solid);
  border-bottom: 1px solid var(--edge);
  z-index: 20;
}
.hdr .back {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border: 1px solid var(--edge); border-radius: 99px;
  color: var(--ink-dim); font-size: 12.5px; white-space: nowrap;
}
.hdr .back:hover { color: var(--ink); border-color: var(--edge-strong); text-decoration: none; }
.hdr h1 { font-size: 15px; margin: 0; font-weight: 620; letter-spacing: -0.01em; }
.hdr .sub { font-size: 12.5px; color: var(--ink-faint); margin-left: -6px; }
.hdr .spacer { flex: 1; }
.hdr .status { font-family: var(--mono); font-size: 11.5px; color: var(--ink-faint); white-space: nowrap; }
.hdr .status b { color: var(--observed); font-weight: 600; }
.hdr .status.stale b { color: var(--danger); }
.hdr .theme {
  width: 30px; height: 30px; padding: 0; border-radius: 50%;
  font-size: 14px; line-height: 1; display: grid; place-content: center; flex: none;
}

.stage { position: relative; overflow: hidden; }
.map { position: absolute; inset: 0; }

/* ------------------------------- panels -------------------------------- */
.panel {
  position: absolute; z-index: 10;
  background: var(--panel);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 13px;
}
.panel h2 {
  margin: 0 0 9px; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--ink-faint); font-weight: 650;
}
.panel + .panel { margin-top: 10px; }
.tl { top: 14px; left: 14px; width: 236px; }
.tr { top: 14px; right: 14px; width: 236px; }
.stack { position: absolute; top: 14px; left: 14px; width: 236px; z-index: 10; max-height: calc(100% - 130px); overflow-y: auto; }
.stack.right { left: auto; right: 14px; }
.stack .panel { position: static; }
.stack::-webkit-scrollbar { width: 6px; }
.stack::-webkit-scrollbar-thumb { background: var(--edge-strong); border-radius: 3px; }

/* ------------------------------ controls -------------------------------- */
.row { display: flex; align-items: center; gap: 8px; }
.row + .row { margin-top: 8px; }
.row label { font-size: 12px; color: var(--ink-dim); flex: 1; }

select, button, input[type="text"] {
  font-family: inherit; font-size: 12.5px; color: var(--ink);
  background: var(--control);
  border: 1px solid var(--edge); border-radius: var(--radius-sm);
  padding: 6px 8px; cursor: pointer;
}
select { width: 100%; }
select:hover, button:hover { border-color: var(--edge-strong); background: var(--control-hover); }
button:active { transform: translateY(1px); }
button.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; width: 15px; height: 15px; }

.seg { display: flex; gap: 0; border: 1px solid var(--edge); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { border: 0; border-radius: 0; flex: 1; padding: 6px 4px; font-size: 11.5px; background: transparent; }
.seg button + button { border-left: 1px solid var(--edge); }
/* .seg button sets a transparent background, which would otherwise beat the
   generic .on rule on specificity and leave active buttons unreadable. */
.seg button.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.hint { font-size: 11px; color: var(--ink-faint); line-height: 1.45; margin-top: 8px; }
.kbd {
  font-family: var(--mono); font-size: 10.5px; padding: 1px 5px;
  border: 1px solid var(--edge-strong); border-radius: 4px; color: var(--ink-dim);
}

/* ------------------------------- legend --------------------------------- */
.legend .bar { display: flex; height: 12px; border-radius: 3px; overflow: hidden; margin-bottom: 5px; }
.legend .bar i { flex: 1; }
.legend .ticks { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 9.5px; color: var(--ink-faint); }
.legend .unit { font-size: 10.5px; color: var(--ink-faint); margin-top: 5px; }

/* ------------------------------ timeline -------------------------------- */
.dock {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 16px;
  width: min(760px, calc(100% - 28px)); z-index: 12;
  background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--edge); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 11px 14px 12px;
}
.dock .head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 9px; }
.dock .clock { font-family: var(--mono); font-size: 19px; font-weight: 650; letter-spacing: -0.02em; }
.dock .tag {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 650;
  padding: 2px 7px; border-radius: 99px;
}
.dock .tag.observed { background: var(--observed-wash); color: var(--observed); }
.dock .tag.forecast { background: var(--forecast-wash); color: var(--forecast); }
.dock .lead { font-family: var(--mono); font-size: 12px; color: var(--ink-faint); }
.dock .grow { flex: 1; }
.dock .peak { font-family: var(--mono); font-size: 12px; color: var(--ink-dim); }

/* Sparkline of national rain intensity, doubling as the scrub track. */
.track { position: relative; height: 46px; cursor: pointer; user-select: none; touch-action: none; }
.track svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.track .now-line { stroke: var(--ink-faint); stroke-width: 1; stroke-dasharray: 2 3; }
.track .cursor { stroke: var(--cursor); stroke-width: 2; }
.track .hnd { fill: var(--cursor); }
.ctl { display: flex; align-items: center; gap: 7px; margin-top: 9px; }
.ctl button { padding: 5px 9px; min-width: 34px; }
.ctl .play { min-width: 42px; font-size: 14px; }
.ctl .times { display: flex; justify-content: space-between; flex: 1; font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint); }

/* ------------------------------ readouts -------------------------------- */
.readout { font-family: var(--mono); font-size: 12px; line-height: 1.6; }
.readout .big { font-size: 22px; font-weight: 650; letter-spacing: -0.02em; }
.readout .lbl { color: var(--ink-faint); }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; padding: 2.5px 0; }
.kv span:first-child { color: var(--ink-dim); }
.kv span:last-child { font-family: var(--mono); }

/* ------------------------------- overlay -------------------------------- */
.boot {
  position: absolute; inset: 0; z-index: 50;
  display: grid; place-content: center; gap: 12px; justify-items: center;
  background: var(--bg); color: var(--ink-dim); font-size: 13px;
}
.boot.hidden { display: none; }
.spin {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--edge-strong); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.err { color: var(--danger); max-width: 460px; text-align: center; line-height: 1.5; }

.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-popup-content {
  background: var(--panel-solid); color: var(--ink);
  border: 1px solid var(--edge); border-radius: var(--radius-sm);
  font-size: 12px; padding: 9px 11px; box-shadow: var(--shadow);
}
.maplibregl-popup-tip { border-top-color: var(--panel-solid) !important; border-bottom-color: var(--panel-solid) !important; }

@media (max-width: 720px) {
  .stack, .tl, .tr { width: 190px; }
  .hdr .sub { display: none; }
}
