:root {
  color-scheme: light dark;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #86857f;
  --good: #008300;
  --warn: #c07800;
  --bad: #e34948;
  --accent: #2a78d6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 1px 8px rgba(0, 0, 0, .04);
  --radius: 14px;
  /* Rain streak colour — dark, saturated blue so it reads on the light ground.
     Dark theme overrides it below with a lighter blue. */
  --rain-drop: rgba(42, 92, 165, .9);
}

/* Dark palette. Applied when the user explicitly picks dark (data-theme, set by
   app.js), and — before JS runs — when the system prefers dark and no choice is
   stamped yet, which keeps the first paint from flashing light. app.js always
   stamps data-theme on load, so the media block only covers that pre-JS moment. */
:root[data-theme="dark"] {
  --bg: #131312;
  --surface-1: #1f1f1d;
  --surface-2: #262624;
  --border: #34342f;
  --text-primary: #f4f4f0;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e84;
  --good: #33a852;
  --warn: #c98500;
  --bad: #e66767;
  --accent: #3987e5;
  --shadow: none;
  --rain-drop: rgba(150, 190, 240, .92);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #131312;
    --surface-1: #1f1f1d;
    --surface-2: #262624;
    --border: #34342f;
    --text-primary: #f4f4f0;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e84;
    --good: #33a852;
    --warn: #c98500;
    --bad: #e66767;
    --accent: #3987e5;
    --shadow: none;
    --rain-drop: rgba(150, 190, 240, .92);
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute is only `display: none` in the browser's own
   stylesheet, so ANY author rule that sets `display` on the element beats it on
   specificity and silently defeats el.hidden = true. That bit `.battery`
   (display:flex) and `.batt-cap` (display:inline-flex): JS hid them and they
   stayed on screen. Fix it once, globally, instead of adding another
   per-element `[hidden]` override every time it comes up. */
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--text-muted); }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.brand h1 { white-space: nowrap; }
.brand-logo { display: inline-flex; align-items: center; flex: 0 0 auto; line-height: 0; }
.brand-logo img { height: 34px; width: auto; }
.brand-logo .logo-dark { display: none; }
:root[data-theme="dark"] .brand-logo .logo-light { display: none; }
:root[data-theme="dark"] .brand-logo .logo-dark { display: inline; }
.brand-sep { color: var(--text-muted); font-weight: 400; margin-right: 8px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Station picker — a native <select> so it scales to any number of stations
   and gets the phone's own picker, dressed to match the segmented controls.
   Its own color-scheme follows the page theme, not the OS, so the open list
   matches when someone has picked light on a dark system (or the reverse). */
.station-pick { position: relative; display: inline-flex; align-items: center; min-width: 0; color: var(--text-primary); }
.station-pick[hidden] { display: none; }
.station-pick select {
  appearance: none; -webkit-appearance: none; color-scheme: light;
  border: 0; border-radius: 9px; background: var(--surface-2); color: var(--text-primary);
  font: inherit; font-size: 13px; font-weight: 550;
  padding: 6px 30px 6px 12px; max-width: 100%; cursor: pointer;
  text-overflow: ellipsis; white-space: nowrap;
}
:root[data-theme="dark"] .station-pick select { color-scheme: dark; }
.station-pick select:hover { background: var(--border); }
.station-pick select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.station-pick option { background: var(--surface-1); color: var(--text-primary); font-weight: 400; }
.station-chev { position: absolute; right: 11px; pointer-events: none; color: var(--text-secondary); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); flex: 0 0 auto; }
.dot.ok { background: var(--good); }
.dot.bad { background: var(--bad); }
.updated { font-size: 13px; color: var(--text-secondary); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.status-col { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.next-refresh { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
/* Sensor battery — a little cell glyph whose fill scales with the level, plus
   the percentage. Colour tracks the level (good / warn / bad), same vocabulary
   as the status dot. */
.battery { display: flex; align-items: center; gap: 6px; color: var(--good); }
.battery.warn { color: var(--warn); }
.battery.bad { color: var(--bad); }
.batt-shell {
  position: relative; display: inline-block;
  width: 24px; height: 12px; border-radius: 3px;
  border: 1.5px solid currentColor; padding: 1.5px;
}
/* the positive nub on the end of the cell */
.batt-shell::after {
  content: ''; position: absolute; left: 100%; top: 50%; transform: translateY(-50%);
  width: 2px; height: 5px; border-radius: 0 2px 2px 0; background: currentColor;
}
.batt-fill { display: block; height: 100%; border-radius: 1px; background: currentColor; }
.batt-pct {
  font-size: 12px; font-variant-numeric: tabular-nums;
  color: var(--text-secondary); line-height: 1;
}
/* Supercapacitor volts — the daytime supply. Muted and bolt-marked so it reads
   as a second, different number rather than more of the battery percentage. */
.batt-cap {
  display: inline-flex; align-items: center; gap: 2px;
  font-size: 12px; font-variant-numeric: tabular-nums;
  color: var(--text-muted); line-height: 1;
}
.batt-cap::before { content: '·'; margin-right: 3px; }

.theme-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-secondary); cursor: pointer; flex: 0 0 auto;
}
.theme-btn:hover { color: var(--text-primary); box-shadow: var(--shadow); }
/* Back to the station map (the home page). Sized to sit beside the theme button. */
.map-link {
  display: inline-flex; align-items: center; height: 32px; padding: 0 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary);
  font-size: 13px; font-weight: 500; text-decoration: none; flex: 0 0 auto;
}
.map-link:hover { color: var(--text-primary); box-shadow: var(--shadow); }

main { max-width: 1080px; margin: 0 auto; padding: 20px; }
.station-line { font-size: 14px; font-weight: 500; color: var(--text-secondary); margin: 0 0 14px; }
.station-line span { color: var(--text-primary); font-weight: 600; }

/* ---- current conditions ---- */
.now {
  display: grid; grid-template-columns: minmax(200px, 260px) minmax(150px, 180px) 1fr; gap: 16px;
  margin-bottom: 26px;
}
@media (max-width: 900px) { .now { grid-template-columns: 1fr 1fr; } .now .tiles { grid-column: 1 / -1; } }
.hero {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.hero-temp { font-size: 64px; font-weight: 300; line-height: 1; letter-spacing: -2px; }
.hero-temp .unit { font-size: 26px; color: var(--text-secondary); margin-left: 4px; }
.hero-sub { margin-top: 12px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 14px; }
.hero-sub .hl-hi { color: var(--bad); font-weight: 600; }
.hero-sub .hl-lo { color: var(--accent); font-weight: 600; }

/* wind compass */
.compass {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
}
.compass-svg { width: 100%; max-width: 150px; height: auto; }
.compass-svg .c-ring { fill: none; stroke: var(--border); stroke-width: 2; }
.compass-svg .c-tick { stroke: var(--text-muted); stroke-width: 1.5; }
.compass-svg .c-card { fill: var(--text-secondary); font-size: 11px; font-weight: 600; text-anchor: middle; dominant-baseline: middle; }
.compass-svg .c-n { fill: var(--bad); }
.compass-svg .c-needle { fill: var(--accent); transition: transform .5s cubic-bezier(.2,.7,.2,1); transform-origin: 60px 60px; }
.compass-svg #compassNeedle { transition: transform .5s cubic-bezier(.2,.7,.2,1); transform-origin: 60px 60px; }
.compass-svg .c-hub { fill: var(--text-secondary); }
.c-readout { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.c-readout #compassDir { font-size: 17px; font-weight: 600; }
.c-readout #compassSpd { font-size: 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px;
  align-items: center; text-align: center;
}
.tile .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
.tile .value { font-size: 24px; font-weight: 450; }
.tile .value .u { font-size: 14px; color: var(--text-secondary); font-weight: 400; margin-left: 2px; }
.tile .sub { font-size: 12px; color: var(--text-secondary); }
/* rain-outlook tile: verdict text with a palette-coloured status dot */
.tile-outlook .value { font-size: 18px; }
.rain-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }

/* Rain backdrop — a full-screen layer of thin falling streaks, faded in only
   while rain looks likely (body.is-raining). Sits above content but ignores the
   pointer, and stays behind the sticky header so the top bar reads cleanly. */
.rainfx {
  position: fixed; inset: 0; z-index: 1; pointer-events: none; overflow: hidden;
  opacity: 0; transition: opacity .6s ease;
}
body.is-raining .rainfx { opacity: 1; }
.rainfx .drop {
  position: absolute; top: 0; width: 1.6px; border-radius: 1px;
  background: linear-gradient(to bottom, transparent, var(--rain-drop));
  animation-name: rain-fall; animation-timing-function: linear; animation-iteration-count: infinite;
}
@keyframes rain-fall {
  0%   { transform: translateY(-12vh); }
  100% { transform: translateY(112vh); }
}
@media (prefers-reduced-motion: reduce) {
  .rainfx .drop { animation: none; }
  body.is-raining .rainfx { opacity: 0; } /* no static streaks for reduced-motion users */
}

/* wind compass arrow */
.arrow { display: inline-block; transition: transform .4s ease; }

/* ---- history ---- */
.history-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 14px;
}
.history-head h2 { font-size: 16px; margin: 0; font-weight: 600; }
/* period navigator: ‹ [Today|Week|Month|Year] › + a period label + overlay toggle */
.hist-controls { display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex-wrap: wrap; }
.periodnav { position: relative; display: flex; align-items: center; gap: 4px; }
.periods { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.periods button {
  border: 0; background: transparent; color: var(--text-secondary);
  font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 8px; cursor: pointer;
}
.periods button:hover { color: var(--text-primary); }
.periods button.active { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); font-weight: 550; }
.periodnav .icon-btn {
  border: 0; background: var(--surface-2); color: var(--text-secondary);
  font: inherit; font-size: 15px; line-height: 1; cursor: pointer;
  width: 28px; height: 28px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.periodnav .icon-btn:hover:not(:disabled) { color: var(--text-primary); box-shadow: var(--shadow); }
.periodnav .icon-btn:disabled { opacity: .35; cursor: default; }
.period-label {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  min-width: 92px; text-align: center; white-space: nowrap;
}
.overlay-toggle {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  font-size: 12.5px; color: var(--text-secondary); user-select: none;
}
.overlay-toggle:hover { color: var(--text-primary); }
/* sliding on/off switch driven by the (visually hidden) checkbox */
.switch-input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch {
  position: relative; flex: 0 0 auto; width: 36px; height: 20px;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  transition: background .15s ease, border-color .15s ease;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%; background: var(--text-muted);
  transition: transform .15s ease, background .15s ease;
}
.switch-input:checked + .switch { background: var(--accent); border-color: var(--accent); }
.switch-input:checked + .switch::after { transform: translateX(16px); background: #fff; }
.switch-input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
.periodnav .cal-btn { margin-left: 2px; }

/* calendar popover */
.cal-pop {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 20;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 4px 20px rgba(0, 0, 0, .18);
  padding: 10px; width: min(244px, calc(100vw - 32px));
}
.cal-pop[hidden] { display: none; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-head .icon-btn {
  border: 0; background: transparent; color: var(--text-secondary);
  font: inherit; font-size: 15px; cursor: pointer;
  width: 26px; height: 26px; border-radius: 7px;
}
.cal-head .icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text-primary); }
.cal-head .icon-btn:disabled { opacity: .35; cursor: default; }
.cal-title { font-size: 13px; font-weight: 600; }
.cal-dow, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { margin-bottom: 2px; }
.cal-dow span { font-size: 10px; color: var(--text-muted); text-align: center; text-transform: uppercase; letter-spacing: .3px; }
.cal-grid .cal-pad { height: 30px; }
.cal-grid button {
  height: 30px; border: 0; background: transparent; color: var(--text-primary);
  font: inherit; font-size: 12.5px; border-radius: 7px; cursor: pointer;
}
.cal-grid button:hover:not(:disabled) { background: var(--surface-2); }
.cal-grid button:disabled { color: var(--text-muted); opacity: .4; cursor: default; }
.cal-grid button.today { font-weight: 700; color: var(--accent); }
/* every day in the selected period (day/week/month/year) is highlighted */
.cal-grid button.sel { background: var(--accent); color: #fff; font-weight: 600; }
.cal-grid button.sel.today { color: #fff; }
.cal-today {
  width: 100%; margin-top: 8px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-secondary); font: inherit; font-size: 12.5px; padding: 6px; border-radius: 8px; cursor: pointer;
}
.cal-today:hover { color: var(--text-primary); }

/* wind rose */
.rose-card { margin-bottom: 16px; }
.rose-body { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; justify-content: center; }
.rose-plot { flex: 0 0 auto; }
.rose-svg { width: 260px; max-width: 100%; height: auto; }
.rose-svg .rose-ring { fill: none; stroke: var(--border); stroke-width: 1; }
.rose-svg .rose-pct { fill: var(--text-muted); font-size: 9px; }
.rose-svg .rose-card { fill: var(--text-secondary); font-size: 12px; font-weight: 600; }
.rose-svg .rose-petal { stroke: var(--surface-1); stroke-width: 1; }
.rose-empty { padding: 40px 10px; text-align: center; }
.rose-legend { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.rose-legend .rl-item { display: flex; align-items: center; gap: 7px; color: var(--text-secondary); }
.rose-legend .rl-sw { width: 14px; height: 14px; border-radius: 3px; flex: 0 0 auto; }

/* rainfall — last 24 h */
.rain24 { margin-bottom: 18px; }
.rain24-body { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.rain24-total { flex: 0 0 auto; font-size: 32px; font-weight: 620; line-height: 1.1; }
.rain24-total .unit { font-size: 16px; color: var(--text-secondary); margin-left: 4px; font-weight: 400; }
.rain24-sub { display: block; font-size: 12px; font-weight: 400; margin-top: 2px; }
.rain24-plot { flex: 1 1 320px; min-width: 0; }
/* Scales with the card, aspect preserved — see the viewBox note in app.js. */
.r24-svg { width: 100%; height: auto; display: block; }
/* Bar fill is set inline from the JS palette (rainfall = aqua, matching the
   Rainfall chart) so colour follows the metric across the whole dashboard. */
/* An invisible full-height target per hour, so hovering a dry hour still shows
   its 0.0 mm tooltip instead of hitting nothing. */
.r24-slot { fill: transparent; }
.rain24-plot g:hover .r24-slot { fill: color-mix(in srgb, var(--text-secondary) 8%, transparent); }
.r24-axis { stroke: var(--border); stroke-width: 1; }
.r24-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 3; opacity: .7; }
.r24-tick { fill: var(--text-muted); font-size: 10px; }

/* total rainfall for the selected period — reuses the 24-hour card's layout
   (.rain24-body / -total / -plot) so the two rainfall panels read as one pair;
   only the clickable-card affordance and the expanded view are new here. */
.rain-total-card { margin-bottom: 16px; cursor: pointer; position: relative; }
.rain-total-card:hover { border-color: var(--text-muted); }
.rain-total-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rain-total-card .expand-hint {
  position: absolute; top: 12px; right: 12px; font-size: 15px; line-height: 1;
  color: var(--text-muted); opacity: 0; transition: opacity .15s ease; pointer-events: none;
}
.rain-total-card:hover .expand-hint, .rain-total-card:focus-visible .expand-hint { opacity: .85; }
/* The previous period sits behind the live bar, faded — same convention as the
   dashed "prev" series on the charts. */
.rt-prev { opacity: .3; }

/* expanded breakdown */
.rain-detail { overflow-y: auto; min-height: 0; }
.rain-detail-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.rain-detail-total { font-size: 38px; font-weight: 620; line-height: 1.1; }
.rain-detail-total .unit { font-size: 17px; color: var(--text-secondary); margin-left: 4px; font-weight: 400; }
.rain-detail-meta { font-size: 13px; }
.rain-detail-plot { margin-bottom: 14px; }

.rain-table-wrap { overflow-x: auto; }
.rain-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rain-table th, .rain-table td { padding: 5px 10px; text-align: left; font-weight: 400; }
.rain-table thead th { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.rain-table tbody tr { border-top: 1px solid var(--border); }
.rain-table tbody th { color: var(--text-secondary); white-space: nowrap; }
.rain-table .rt-num { text-align: right; font-variant-numeric: tabular-nums; width: 1%; white-space: nowrap; }
.rain-table .rt-prev-cell { color: var(--text-muted); }
/* Dry buckets stay in the table — "no rain on the 14th" is part of the answer —
   but recede so the wet ones carry the shape of the period. */
.rain-table .rt-dry th, .rain-table .rt-dry .rt-num { color: var(--text-muted); }
.rain-table .rt-wettest th, .rain-table .rt-wettest .rt-num:first-of-type { font-weight: 620; color: var(--text-primary); }
.rain-table .rt-share { width: 55%; }
.rain-table .rt-share-h { width: 55%; }
.rain-table .rt-share span { display: block; height: 8px; border-radius: 2px; min-width: 0; }
.rain-table tfoot tr { border-top: 2px solid var(--border); }
.rain-table tfoot th, .rain-table tfoot td { font-weight: 620; padding-top: 8px; }

/* min() so a viewport narrower than 320px collapses to one column instead of
   forcing a 320px track and scrolling the page sideways. */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 16px; }
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 16px 10px; min-width: 0;
}
.card h3 { font-size: 14px; margin: 0 0 2px; font-weight: 600; }
.card .card-unit { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.card .uplot { width: 100% !important; }

/* clickable chart cards — hover/focus affordance + expand glyph */
.chart-card { cursor: pointer; position: relative; }
.chart-card:hover { border-color: var(--text-muted); }
.chart-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chart-card .expand-hint {
  position: absolute; top: 12px; right: 12px; font-size: 15px; line-height: 1;
  color: var(--text-muted); opacity: 0; transition: opacity .15s ease; pointer-events: none;
}
.chart-card:hover .expand-hint, .chart-card:focus-visible .expand-hint { opacity: .85; }

/* expanded-chart modal */
body.modal-open { overflow: hidden; }
.chart-modal {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(0, 0, 0, .5);
}
.chart-modal[hidden] { display: none; }
.chart-modal-panel {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 48px rgba(0, 0, 0, .35);
  width: min(1200px, 100%); max-height: 92vh; padding: 18px 20px 14px;
  display: flex; flex-direction: column;
}
.chart-modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.chart-modal-head h3 { font-size: 16px; margin: 0 0 2px; font-weight: 600; }
.modal-close {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary);
  font: inherit; font-size: 14px; line-height: 1; cursor: pointer;
  width: 30px; height: 30px; border-radius: 8px; flex: 0 0 auto;
}
.modal-close:hover { color: var(--text-primary); box-shadow: var(--shadow); }
.modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.modal-plot { width: 100%; }

.foot { max-width: 1080px; margin: 0 auto; padding: 4px 20px 30px; font-size: 12px; }
.about { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); color: var(--text-secondary); max-width: 72ch; line-height: 1.55; }
.about h2 { font-size: 13px; font-weight: 600; margin: 0 0 6px; color: var(--text-primary); }
.about p { margin: 0 0 8px; }
.about strong { font-weight: 600; color: var(--text-primary); }
.about a { color: inherit; }

/* uPlot tooltip */
.u-tip {
  position: absolute; z-index: 10; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 2px 12px rgba(0,0,0,.14);
  padding: 7px 10px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -120%);
  color: var(--text-primary);
}
.u-tip .t-time { color: var(--text-muted); margin-bottom: 3px; }
.u-tip .t-row { display: flex; align-items: center; gap: 6px; }
.u-tip .t-swatch { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 auto; }
.u-tip .t-val { font-weight: 600; margin-left: auto; }

/* uPlot theme tweaks */
.u-legend { font-size: 12px; }
.u-title { display: none; }

@media (max-width: 620px) {
  main { padding: 16px 12px; }
  /* The top bar can't hold logo, title, switcher, battery and status on one
     line at phone width — they overlapped. Stack it: logo + title, then the
     station switcher full width, then battery / status / theme. */
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .brand { flex-wrap: wrap; width: 100%; row-gap: 8px; }
  .brand-logo img { height: 28px; }
  .brand h1 { font-size: 16px; }
  .station-pick { flex: 1 1 100%; }
  /* Full width, and 16px so iOS doesn't zoom the page when it's tapped. */
  .station-pick select { width: 100%; font-size: 16px; padding: 7px 32px 7px 12px; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .battery, .batt-pct, .batt-cap { white-space: nowrap; }
  .status-col { flex: 1 1 auto; min-width: 0; align-items: flex-start; }
  .updated, .next-refresh { white-space: nowrap; }
  .now { grid-template-columns: 1fr; }
  .hero { align-items: center; text-align: center; }

  /* The history controls no longer fit beside the heading: give them their own
     full-width row and let the segmented bar stretch to fill it. */
  .history-head { align-items: baseline; }
  .hist-controls { width: 100%; justify-content: space-between; gap: 8px; }
  .periodnav { flex: 1 1 260px; }
  .periods { flex: 1 1 auto; }
  .periods button { flex: 1 1 0; padding: 6px 8px; }
  .foot { padding-left: 12px; padding-right: 12px; }

  /* No room for a share bar next to the numbers — drop the column rather than
     squeezing the labels. */
  .rain-table .rt-share, .rain-table .rt-share-h { display: none; }
  .rain-detail-total { font-size: 30px; }
}

/* ---- Sidebar advert slots ----
   Up to two creatives (left, right), managed on the LAN-only /admin page and
   rendered by app.js into shadow roots, so their own CSS stays self-contained.
   app.js adds .has-left / .has-right for each live slot and .rails-on when the
   window is wide enough to put them beside the 1080px dashboard (1440px for one
   rail, 1780px for two); otherwise they sit in #adInline instead. */
.layout { display: block; }
.ad-inline {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start;
  gap: 16px; margin-bottom: 18px;
}
.ad-inline[hidden] { display: none; }
.ad-host { display: block; max-width: 100%; }

.layout.rails-on {
  display: grid; align-items: start;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1080px) minmax(0, 1fr);
}
.layout.rails-on.has-left  { grid-template-columns: minmax(340px, 1fr) minmax(0, 1080px) minmax(0, 1fr); }
.layout.rails-on.has-right { grid-template-columns: minmax(0, 1fr) minmax(0, 1080px) minmax(340px, 1fr); }
.layout.rails-on.has-left.has-right { grid-template-columns: minmax(340px, 1fr) minmax(0, 1080px) minmax(340px, 1fr); }
.layout.rails-on > main { margin: 0; width: 100%; box-sizing: border-box; min-width: 0; }
.layout.rails-on > .ad-rail-left  { grid-column: 1; grid-row: 1; }
.layout.rails-on > main           { grid-column: 2; grid-row: 1; }
.layout.rails-on > .ad-rail-right { grid-column: 3; grid-row: 1; }
.ad-rail {
  position: sticky; top: 61px;              /* the sticky topbar's height */
  z-index: 4;                               /* above the stale-data notice */
  box-sizing: border-box; padding: 20px;    /* matches main's, so tops line up */
  max-height: calc(100vh - 61px); overflow-y: auto; overscroll-behavior: contain;
  display: flex;
}
.ad-rail-left  { justify-content: flex-end; }   /* hug the dashboard */
.ad-rail-right { justify-content: flex-start; }
.ad-rail[hidden] { display: none; }

/* Stale-data notice: a wide band on a 30° incline across the middle of the
   screen. Fixed so it stays in view while scrolling, under the adverts (z 4),
   the sticky top bar (z 5) and modals (z 60), and click-through so the page
   still works. */
.stale-stamp {
  position: fixed; inset: 0; z-index: 3; pointer-events: none; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden;
  transition: opacity .6s ease, visibility 0s linear .6s;
}
.stale-stamp.show {
  opacity: 1; visibility: visible;
  transition: opacity .6s ease, visibility 0s;
}
@media (prefers-reduced-motion: reduce) {
  .stale-stamp, .stale-stamp.show { transition: none; }
}
.stale-band {
  width: 300vmax; flex: 0 0 auto; transform: rotate(-30deg);
  padding: 14px 0; text-align: center;
  background: rgba(227, 73, 72, .82); color: #fff;
  border-top: 4px solid rgba(255, 255, 255, .7); border-bottom: 4px solid rgba(255, 255, 255, .7);
  box-shadow: 0 4px 24px rgba(0, 0, 0, .25);
  font-size: clamp(14px, 3vw, 38px); font-weight: 800; line-height: 1.25;
  letter-spacing: .01em; text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
/* Keep the words inside the part of the band that's on screen: a 30° line
   through the centre leaves the viewport after 100vw/cos30 or 100vh/sin30,
   whichever is shorter. The text is two or three lines (<br>s in the markup;
   the middle outage line only after an hour); the font shrinks on narrow
   screens so each line fits, and the outage line may wrap on a phone. */
.stale-band p { margin: 0 auto; max-width: calc(min(115vw, 200vh) - 72px); }
#staleWhen { white-space: nowrap; }

/* Station search in the top bar, on the map and the dashboard (station-search.js).
   The list drops down over the page (the top bar is z-index 5). On phones it
   takes a row of its own. */
.site-search { position: relative; flex: 1 1 260px; max-width: 360px; }
.site-search input {
  width: 100%; height: 34px; padding: 0 12px 0 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
  font: inherit; font-size: 14px;
}
.site-search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface-1); }
.site-search-ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.site-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18); max-height: 320px; overflow-y: auto;
}
.site-results li {
  display: flex; align-items: baseline; gap: 8px; padding: 8px 10px; border-radius: 6px;
  cursor: pointer; font-size: 14px;
}
.site-results li[aria-selected="true"] { background: var(--surface-2); color: var(--accent); }
.site-results .sr-name { font-weight: 600; }
.site-results .sr-aka, .site-results .sr-tag { font-size: 12px; color: var(--text-secondary); }
.site-results .sr-temp { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-secondary); white-space: nowrap; }
.site-results .sr-none { cursor: default; color: var(--text-secondary); }
@media (max-width: 620px) {
  .site-search { flex-basis: 100%; max-width: none; }
  /* 16px so iOS doesn't zoom the page when it's tapped. */
  .site-search input { font-size: 16px; }
}
/* The dashboard's top bar already holds the station dropdown, battery and
   status, so below 1180px the search moves to a full-width row of its own
   rather than squeezing them (it cut the station name off). */
@media (max-width: 1180px) {
  .topbar-dash { flex-wrap: wrap; row-gap: 10px; }
  .topbar-dash .site-search { order: 3; flex-basis: 100%; max-width: none; }
}
