:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page-plane:     #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1:       #2a78d6; /* blue — sequential hue */
  --series-1-wash:  rgba(42,120,214,0.10);
  --good:           #0ca30c;
  /* Computed/derived magnitude (spot score, forecast estimate) — matches chart.js heatColor() */
  --magnitude-low:  #cde2fb;
  --magnitude-high: #184f95;
  /* Genuine measured spectral energy density — matches chart.js spectralColor(), polarSpectrum only */
  --spectral-low:   #fdf3ea;
  --spectral-mid:   #eb6834;
  --spectral-high:  #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page-plane:     #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --series-1:       #3987e5;
    --series-1-wash:  rgba(57,135,229,0.14);
    --good:           #0ca30c;
    --magnitude-low:  #1c5cab;
    --magnitude-high: #9ec5f4;
    --spectral-low:   #4a3226;
    --spectral-mid:   #d95926;
    --spectral-high:  #ff6a52;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page-plane:     #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.10);
  --series-1:       #3987e5;
  --series-1-wash:  rgba(57,135,229,0.14);
  --good:           #0ca30c;
  --magnitude-low:  #1c5cab;
  --magnitude-high: #9ec5f4;
  --spectral-low:   #4a3226;
  --spectral-mid:   #d95926;
  --spectral-high:  #ff6a52;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 2rem;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.75rem;
  max-width: 720px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-mark { font-size: 1.8rem; line-height: 1; }
.app-header h1 { font-size: 1.15rem; margin: 0; letter-spacing: -0.01em; }
.tagline { margin: 0.1rem 0 0; font-size: 0.78rem; color: var(--text-secondary); }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  font-size: 1rem;
  cursor: pointer;
}
.icon-btn:hover { background: var(--gridline); }

main#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.hero-card {
  background: linear-gradient(135deg, var(--series-1) 0%, #184f95 100%);
  color: #fff;
  border-radius: 16px;
  padding: 1.1rem 1.25rem 1.25rem;
}
.hero-label { margin: 0 0 0.25rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.85; }
.hero-value { margin: 0; font-size: 1.25rem; font-weight: 600; }
.hero-sub { margin: 0.35rem 0 0; font-size: 0.85rem; opacity: 0.92; }

.stat-strip {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.1rem;
}
.stat-tile {
  flex: 0 0 auto;
  min-width: 190px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
}
.stat-tile .label { font-size: 0.72rem; color: var(--text-secondary); margin: 0 0 0.3rem; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-tile .value { font-size: 1.3rem; font-weight: 600; margin: 0; }
.stat-tile .sub { font-size: 0.78rem; color: var(--text-secondary); margin: 0.15rem 0 0; }
.stat-tile svg { display: block; margin-top: 0.4rem; }

.spot-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
}
@media (min-width: 620px) {
  .spot-grid { grid-template-columns: 1fr 1fr; }
}

.spot-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.spot-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.spot-name { font-weight: 600; font-size: 1rem; margin: 0; }
.spot-tag { font-size: 0.74rem; color: var(--text-secondary); margin: 0.1rem 0 0; }
.spot-stars { font-size: 0.95rem; color: var(--good); white-space: nowrap; }
.spot-stars .dim { color: var(--baseline); }

.spot-reading { font-size: 0.86rem; color: var(--text-secondary); margin: 0; }
.spot-reading strong { color: var(--text-primary); font-weight: 600; }

.heat-strip {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 2px 0;
}
.heat-cell {
  flex: 0 0 8px;
  height: 28px;
  border-radius: 2px;
  cursor: pointer;
  position: relative;
}
.heat-cell:hover, .heat-cell:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}
.heat-axis { display: flex; justify-content: space-between; font-size: 0.68rem; color: var(--text-muted); }

details.chart-toggle > summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--series-1);
  list-style: none;
}
details.chart-toggle > summary::-webkit-details-marker { display: none; }
details.chart-toggle > summary::before { content: "▸ "; }
details.chart-toggle[open] > summary::before { content: "▾ "; }

.chart-wrap { margin-top: 0.5rem; position: relative; }
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface-1);
  font-size: 0.72rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  white-space: nowrap;
  transform: translate(-50%, -110%);
  opacity: 0;
  transition: opacity 0.08s ease;
  z-index: 2;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tt-value { font-weight: 600; }

table.hourly-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; margin-top: 0.4rem; }
table.hourly-table th, table.hourly-table td {
  text-align: left;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}
table.hourly-table th { color: var(--text-secondary); font-weight: 500; }
.table-scroll { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; margin-top: 0.4rem; }

.polar-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.polar-card h2 { font-size: 0.95rem; margin: 0; }

.polar-tabs { display: flex; gap: 0.4rem; }
.tab-btn {
  flex: 1;
  padding: 0.5rem 0.4rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
}
.tab-btn.active { background: var(--series-1); color: #fff; border-color: var(--series-1); font-weight: 600; }
.tab-panel[hidden] { display: none; }
.tab-panel { display: flex; flex-direction: column; gap: 0.5rem; }
.polar-card .sub { font-size: 0.78rem; color: var(--text-secondary); margin: 0; }
.polar-chart-shell { max-width: 300px; margin: 0 auto; width: 100%; }
.polar-current { transition: cx 0.35s ease, cy 0.35s ease, fill 0.35s ease; cursor: pointer; }
.trail-dot { transition: cx 0.35s ease, cy 0.35s ease; }

.polar-readout {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  min-height: 1.2em;
}
.polar-readout strong { color: var(--text-primary); }

.polar-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.polar-controls input[type="range"] {
  flex: 1;
  accent-color: var(--series-1);
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--baseline); /* overridden inline per-render with the actual/forecast split */
}
.polar-controls input[type="range"]::-webkit-slider-runnable-track { background: transparent; height: 4px; }
.polar-controls input[type="range"]::-moz-range-track { background: transparent; height: 4px; }
.polar-controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--series-1);
  border: 2px solid var(--surface-1);
  margin-top: -5px;
  cursor: pointer;
}
.polar-controls input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--series-1);
  border: 2px solid var(--surface-1);
  cursor: pointer;
}

.polar-legend {
  display: flex;
  gap: 1rem;
  justify-content: center;
  font-size: 0.76rem;
  color: var(--text-secondary);
}
.polar-legend .swatch {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.polar-legend .dot {
  width: 9px; height: 9px; border-radius: 50%;
  display: inline-block;
}
.polar-legend .dot.live { background: var(--good); }
.polar-legend .dot.forecast { background: var(--series-1); border: 1px dashed var(--surface-1); box-sizing: border-box; }
.polar-note { text-align: center; font-size: 0.74rem; color: var(--text-muted); }

.arrival-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  margin-top: 0.2rem;
}
.arrival-title {
  margin: 0 0 0.3rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}
.arrival-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8rem;
  padding: 0.3rem 0;
  border-top: 1px solid var(--gridline);
}
.arrival-row:first-child { border-top: none; }
.arrival-spot { color: var(--text-primary); font-weight: 500; flex: 0 0 auto; }
.arrival-detail { color: var(--text-secondary); text-align: right; }
.arrival-detail strong { color: var(--text-primary); }
.arrival-detail.arrival-none { color: var(--text-muted); font-style: italic; }

.energy-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.energy-legend .bar {
  width: 90px;
  height: 8px;
  border-radius: 4px;
  /* Default: computed/derived magnitude (forecast estimate) */
  background: linear-gradient(to right, var(--magnitude-low), var(--magnitude-high));
}
.energy-legend.spectral .bar {
  /* Genuine measured spectral energy density — visually distinct on purpose */
  background: linear-gradient(to right, var(--spectral-low), var(--spectral-mid), var(--spectral-high));
}
.play-btn {
  border: 1px solid var(--border);
  background: var(--series-1);
  color: #fff;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  font-size: 1rem;
  cursor: pointer;
  flex: 0 0 auto;
}

.about {
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
}
.about summary { cursor: pointer; font-weight: 500; color: var(--text-primary); }
.about p { line-height: 1.5; }

.error-banner {
  background: #fdece9;
  color: #7a1f1f;
  border: 1px solid #f2b8ac;
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
}
:root[data-theme="dark"] .error-banner {
  background: #3a1c1c; color: #f2b8ac; border-color: #5c2a2a;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .error-banner {
    background: #3a1c1c; color: #f2b8ac; border-color: #5c2a2a;
  }
}

.app-footer {
  max-width: 720px;
  margin: 1rem auto 0;
  padding: 0 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}
.app-footer a { color: inherit; }
