:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --success: #006300;
  --card-surface: #ffffff;
  --card-shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 6px 16px rgba(11, 11, 11, 0.08);
  --card-shadow-hover: 0 2px 4px rgba(11, 11, 11, 0.08), 0 10px 22px rgba(11, 11, 11, 0.12);

  --series-1: #2a78d6; /* PSPI / blue */
  --series-2: #eb6834; /* SSI / orange */
  --series-3: #1baf7a; /* SQO / aqua */
  --series-4: #eda100; /* Great Lakes / yellow */
  --series-5: #e87ba4; /* Overrunning / magenta */
  --series-6: #008300; /* Coastal / green */
  --series-7: #4a3aa7; /* NAO / violet */
  --series-8: #e34948; /* Alerts / red */

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
}

/* OS-level preference -- only applies when the user hasn't made an explicit
   choice via the header toggle (persisted as :root[data-theme]). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --success: #0ca30c;
    --card-surface: #242423;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.45);
    --card-shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.5), 0 10px 26px rgba(0, 0, 0, 0.55);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

/* Explicit user choice via the header toggle -- always wins over OS
   preference, in either direction. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --success: #0ca30c;
  --card-surface: #242423;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.45);
  --card-shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.5), 0 10px 26px rgba(0, 0, 0, 0.55);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}
:root[data-theme="light"] {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --success: #006300;
  --card-surface: #ffffff;
  --card-shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 6px 16px rgba(11, 11, 11, 0.08);
  --card-shadow-hover: 0 2px 4px rgba(11, 11, 11, 0.08), 0 10px 22px rgba(11, 11, 11, 0.12);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

header.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.masthead-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.masthead-logo {
  height: 100px;
  width: auto;
}
header.masthead h1 {
  font-size: 20px;
  margin: 0;
}
header.masthead .subtitle {
  color: var(--text-secondary);
  font-size: 13px;
}
.masthead-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.theme-toggle-btn {
  appearance: none;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-surface);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.theme-toggle-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--card-shadow-hover);
}

.tab-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--gridline);
}
.tab-button {
  appearance: none;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
}
.tab-button:hover { color: var(--text-primary); }
.tab-button.active {
  color: var(--text-primary);
  border-bottom-color: var(--series-1);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.history-attribution {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 14px;
}
.history-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 12px 0 0;
}
.reset-zoom-button {
  appearance: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  padding: 6px 12px;
  margin-top: 10px;
  cursor: pointer;
}
.reset-zoom-button:hover { color: var(--text-primary); }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 20px;
}
.panel h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin: 0 0 14px;
}

.top-card {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
}
@media (max-width: 760px) {
  .top-card { grid-template-columns: 1fr; }
}

.hero-value {
  font-size: 48px;
  font-weight: 600;
  line-height: 1;
  margin: 4px 0;
}
.hero-label {
  color: var(--text-secondary);
  font-size: 13px;
}
.hero-range {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}
.trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  margin-top: 6px;
}
.trend.improving { color: var(--status-good); }
.trend.declining { color: var(--status-critical); }
.trend.initial, .trend.steady { color: var(--text-secondary); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--gridline);
  color: var(--text-primary);
  margin-top: 6px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.stat-tile .label {
  font-size: 12px;
  color: var(--text-secondary);
}
.stat-tile .value {
  font-size: 26px;
  font-weight: 600;
  margin-top: 2px;
}
.stat-tile .interp {
  font-size: 12px;
  color: var(--text-muted);
}

.pattern-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px;
}
.pattern-card {
  appearance: none;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--card-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px 16px;
  flex: 0 0 150px;
  font: inherit;
  text-align: left;
  color: inherit;
  cursor: pointer;
  box-shadow: var(--card-shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.pattern-card:hover {
  border-color: var(--baseline);
  transform: translateY(-2px);
  box-shadow: var(--card-shadow-hover);
}
.pattern-card-tab {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 50%);
  background: rgba(255, 255, 255, 0.92);
  color: rgba(11, 11, 11, 0.65);
  font-size: 11px;
  line-height: 1;
  letter-spacing: 1px;
  padding: 1px 8px 2px;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.pattern-card.expanded .pattern-card-tab { opacity: 0; }
.pattern-card .name,
.ambient-field-card .name {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}
.pattern-card .full-name {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}
.pattern-card .val,
.ambient-field-card .val {
  font-size: 20px;
  font-weight: 600;
  margin-top: 2px;
}
.pattern-card-detail {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  border-top: 1px solid transparent;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin-top 0.25s ease, padding-top 0.25s ease, border-color 0.25s ease;
}
.pattern-card.expanded .pattern-card-detail {
  max-height: 220px;
  opacity: 1;
  margin-top: 8px;
  padding-top: 8px;
  border-color: var(--gridline);
}
.pattern-card .status {
  font-size: 12px;
  margin-top: 2px;
}
.status-favorable { color: var(--status-good); }
.status-unfavorable { color: var(--status-critical); }
.status-neutral { color: var(--text-muted); }

.chart-wrap {
  position: relative;
  height: 280px;
}

.map-wrap {
  height: 560px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
/* Leaflet's default UI is styled for a light basemap; darken it to blend
   with this app's dark theme rather than sitting on top like a foreign widget. */
.leaflet-control-zoom a {
  background: var(--surface-1) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}

/* Custom per-layer toggle+opacity panel (dashboard.js addLayerControlPanel),
   replacing Leaflet's default checkbox-only L.control.layers. */
.layer-control-panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-primary);
  min-width: 210px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.layer-control-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
}
.layer-control-row:last-child { margin-bottom: 0; }
.layer-control-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.layer-control-slider {
  width: 100%;
  accent-color: var(--series-1);
}
.layer-control-slider:disabled { opacity: 0.4; }

/* OpenWeatherMap's wind/temperature tiles are very pale at the source --
   this makes the tinting actually distinguishable instead of a near-white
   wash. See dashboard.js where this class is assigned. */
.owm-boost-contrast {
  filter: saturate(2.5) contrast(1.4);
}

.ambient-station {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--gridline);
}
.ambient-station:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
.ambient-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin: 16px 0 8px;
}
.ambient-group-title:first-of-type {
  margin-top: 8px;
}
.ambient-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  justify-items: center;
  gap: 12px;
}
@media (max-width: 760px) {
  .ambient-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 480px) {
  .ambient-grid { grid-template-columns: minmax(0, 1fr); }
}

.ambient-field-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--card-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 30px 12px 10px;
  flex: 0 0 150px;
  width: 150px;
  max-width: 100%;
  box-shadow: var(--card-shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.ambient-field-card .name {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  text-align: center;
  font-weight: 700;
}
.ambient-field-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--card-shadow-hover);
}

.wind-compass-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.wind-compass-svg {
  width: 92px;
  height: 92px;
  margin: 4px 0 2px;
}
.wind-compass-ring {
  fill: none;
  stroke: var(--gridline);
  stroke-width: 2;
}
.wind-compass-tick {
  stroke: var(--text-muted);
  stroke-width: 1.5;
}
.wind-compass-tick-label {
  font-size: 9px;
  fill: var(--text-muted);
  text-anchor: middle;
}
.wind-compass-arrow {
  fill: var(--series-1);
}
.wind-compass-arrow-stem {
  stroke: var(--series-1);
  stroke-width: 2.5;
}
.wind-compass-badge {
  fill: var(--surface-1);
  stroke: var(--series-1);
  stroke-width: 1.5;
}
.wind-compass-abbr {
  font-size: 9px;
  font-weight: 700;
  fill: var(--text-primary);
  text-anchor: middle;
}
.wind-compass-deg {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.combo-card {
  flex-basis: 260px;
  width: 260px;
}
.combo-card-body {
  display: flex;
  align-items: center;
  gap: 14px;
}
.wind-compass-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
}
.pressure-prediction {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
  width: 72px;
}
.pressure-prediction-icon {
  font-size: 34px;
  line-height: 1;
}
.pressure-prediction-label {
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
  text-align: center;
}
.combo-rows {
  flex: 1 1 auto;
  min-width: 0;
}
.combo-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-top: 5px;
  font-size: 11px;
}
.combo-row-label {
  color: var(--text-secondary);
}
.combo-row-val {
  font-weight: 600;
  white-space: nowrap;
  flex: 0 0 auto;
}

.rain-card {
  flex-basis: 320px;
  width: 320px;
}
.rain-tubes {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.rain-tube {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
}
.rain-tube-value {
  font-size: 10px;
  font-weight: 600;
  margin-bottom: 3px;
  white-space: nowrap;
}
.rain-tube-body {
  position: relative;
  width: 16px;
  height: 70px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-1);
  overflow: hidden;
}
.rain-tube-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, var(--series-1), var(--series-3));
  transition: height 0.3s ease;
}
.rain-tube-label {
  font-size: 9px;
  color: var(--text-secondary);
  margin-top: 4px;
  text-align: center;
}

.snow-tube-fill {
  background: linear-gradient(180deg, #ffffff, #7fb3e0);
}

.goggle-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
}
.goggles-svg {
  width: 100px;
  height: 46px;
}
.goggles-frame {
  fill: #4b4f56;
  stroke: var(--border);
  stroke-width: 1;
}
.goggles-lens {
  stroke: rgba(0, 0, 0, 0.3);
  stroke-width: 1;
}
.goggles-mirror-shine {
  stroke: rgba(255, 255, 255, 0.55);
  stroke-width: 5;
  stroke-linecap: round;
}
.goggles-strap-band {
  fill: #34373c;
}
.goggles-strap-stripe {
  fill: #d8dade;
  opacity: 0.9;
}
.goggles-vent {
  stroke: rgba(255, 255, 255, 0.3);
  stroke-width: 2;
  stroke-linecap: round;
}
.goggle-label {
  font-size: 11px;
  font-weight: 600;
  margin-top: 4px;
  text-align: center;
}

.scene-wrap {
  display: flex;
  flex: 0 0 auto;
}
.mountain-scene-svg {
  width: 130px;
  height: 74px;
  border-radius: 6px;
  overflow: hidden;
}
.scene-sky {
  fill: #5b86b5;
}
.scene-mountain {
  fill: #5a5f6c;
}
.scene-mountain-snow {
  fill: #f2f4f6;
}
.scene-valley {
  fill: #3f6b46;
}
.scene-cloud {
  fill: #eef1f3;
  opacity: 0.92;
}

.aqi-card {
  flex-basis: 300px;
  width: 300px;
}
.aqi-gauge-wrap {
  margin-top: 10px;
}
.aqi-bar {
  position: relative;
  height: 10px;
  border-radius: 5px;
}
.aqi-bar-marker {
  position: absolute;
  top: -3px;
  left: 0;
  width: 4px;
  height: 16px;
  background: var(--text-primary);
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}
.aqi-label {
  font-size: 12px;
  font-weight: 600;
  margin-top: 8px;
  text-align: center;
}

.legend-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-row .key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend-row .swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.freshness {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 24px;
  border-top: 1px solid var(--gridline);
  padding-top: 12px;
}

.site-footer {
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--gridline);
}
.site-footer p {
  margin: 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-muted);
}
.freshness table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.freshness td, .freshness th {
  text-align: left;
  padding: 4px 8px 4px 0;
  border-bottom: 1px solid var(--gridline);
}
.freshness .ok { color: var(--status-good); }
.freshness .error { color: var(--status-critical); }

a.explain-link {
  color: var(--series-1);
  font-size: 12px;
  text-decoration: none;
}
a.explain-link:hover { text-decoration: underline; }

.driver-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 13px;
}
.driver-list li {
  padding: 4px 0;
  border-bottom: 1px solid var(--gridline);
}
.driver-list li:last-child { border-bottom: none; }
.driver-delta {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  margin-right: 8px;
}
.driver-delta.pos { color: var(--status-good); }
.driver-delta.neg { color: var(--status-critical); }
