/* condies — minimal, mobile-first, system fonts, dark mode auto. */

:root {
  --bg:            #fafafa;
  --bg-elev:       #ffffff;
  --fg:            #1a1a1a;
  --fg-muted:      #6b6b6b;
  --border:        #e5e5e5;
  --accent:        #2563eb;
  --go:            #16a34a;
  --maybe:         #d97706;
  --no:            #dc2626;
  --offline:       #9ca3af;
  --chart-temp:      #ef4444;
  --chart-temp-soft: #f97316;  /* NWS temp: orange (vs Open-Meteo red) — distinct hue for colorblind */
  --chart-dew:       #2563eb;
  --chart-dew-soft:  #0d9488;  /* NWS dew: teal (vs Open-Meteo blue) — distinct hue for colorblind */
  --chart-rain:      #0ea5e9;
  --chart-cloud:     #64748b;
  --chart-day-tint:  rgba(0,0,0,0.025);
  --chart-past-bg:   rgba(0,0,0,0.025);
  --radius:        8px;
  --gap:           12px;
}

/* Dark vars applied either via system pref (when no explicit choice) OR via data-theme="dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:              #0f0f0f;
    --bg-elev:         #1a1a1a;
    --fg:              #f0f0f0;
    --fg-muted:        #a0a0a0;
    --border:          #2a2a2a;
    --accent:          #60a5fa;
    --go:              #22c55e;
    --maybe:           #f59e0b;
    --no:              #ef4444;
    --offline:         #6b7280;
    --chart-temp:      #f87171;
    --chart-temp-soft: #fb923c;  /* NWS temp: orange (distinct from Open-Meteo red) */
    --chart-dew:       #60a5fa;
    --chart-dew-soft:  #2dd4bf;  /* NWS dew: teal (distinct from Open-Meteo blue) */
    --chart-rain:      #38bdf8;
    --chart-cloud:     #cbd5e1;
    --chart-day-tint:  rgba(255,255,255,0.035);
    --chart-past-bg:   rgba(255,255,255,0.04);
  }
}

:root[data-theme="dark"] {
  --bg:              #0f0f0f;
  --bg-elev:         #1a1a1a;
  --fg:              #f0f0f0;
  --fg-muted:        #a0a0a0;
  --border:          #2a2a2a;
  --accent:          #60a5fa;
  --go:              #22c55e;
  --maybe:           #f59e0b;
  --no:              #ef4444;
  --offline:         #6b7280;
  --chart-temp:      #f87171;
  --chart-temp-soft: #fb923c;  /* NWS temp: orange (distinct from Open-Meteo red) */
  --chart-dew:       #60a5fa;
  --chart-dew-soft:  #2dd4bf;  /* NWS dew: teal (distinct from Open-Meteo blue) */
  --chart-rain:      #38bdf8;
  --chart-cloud:     #cbd5e1;
  --chart-day-tint:  rgba(255,255,255,0.035);
  --chart-past-bg:   rgba(255,255,255,0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding-bottom: 4rem;
}

a { color: var(--accent); }

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

/* ── topbar ───────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  flex: 1;
}

.topbar .back {
  text-decoration: none;
  font-size: 13px;
}

.topbar .controls {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
}

.topbar button {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  padding: 4px 10px;
  font: inherit;
  cursor: pointer;
}

.topbar button:hover:not(:disabled) {
  background: var(--bg);
}

.topbar button:disabled {
  opacity: 0.5;
  cursor: wait;
}

.stale-badge {
  display: inline-flex;
  padding: 2px 8px;
  background: var(--no);
  color: white;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.stale-badge[hidden] { display: none; }

/* ── main ─────────────────────────────────────────────── */
main {
  max-width: 1500px;
  margin: 0 auto;
  padding: 16px;
}

.best-bet {
  padding: 12px 16px;
  background: var(--bg-elev);
  border-radius: var(--radius);
  border-left: 4px solid var(--accent);
  margin: 0 0 16px;
}

.best-bet .rank-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
  margin-bottom: 6px;
}

/* Three (now / tomorrow / day after) heatmap sections.
   Stack vertically by default (mobile-friendly), flex horizontally on desktop. */
.best-bet .heatmap-section + .heatmap-section {
  margin-top: 18px;
}

@media (min-width: 1000px) {
  .best-bet {
    display: flex;
    gap: 22px;
    align-items: flex-start;
  }
  .best-bet .heatmap-section {
    flex: 1 1 0;
    min-width: 0;
  }
  .best-bet .heatmap-section + .heatmap-section {
    margin-top: 0;
  }
  .best-bet .heatmap {
    width: 100%;
  }
  .best-bet .heatmap .heatmap-cell {
    min-width: 0;
    padding: 0 4px;
  }
  .best-bet .heatmap th {
    padding: 2px 4px;
    font-size: 10px;
  }
  .best-bet .heatmap .heatmap-name {
    white-space: nowrap;
    /* No max-width / ellipsis — let the column auto-size to fit the longest
       crag name ("Lincoln Woods"). The 4 score cells share whatever width
       remains, which is plenty even at 1000px viewport ÷ 3 sections. */
  }
}

/* ── Mobile pass: tighten everything so 320–600px phones fit ─────── */
@media (max-width: 600px) {
  main { padding: 10px 8px; }

  .topbar h1 { font-size: 16px; }
  .topbar .controls { font-size: 11px; gap: 8px; }

  .crag-section { padding: 10px 10px 12px; }
  .crag-section .crag-header h2 { font-size: 17px; }
  .crag-section .crag-header { flex-wrap: wrap; gap: 8px; }
  .crag-section .now-line { font-size: 12px; gap: 1px; }
  .crag-section .now-pill { padding: 1px 5px; }
  .crag-section .now-sep { margin: 0 2px; }

  /* Top heatmap — table-layout: fixed forces equal columns so scores
     can't get pushed off-screen. Cells go as small as needed. */
  .best-bet { padding: 10px 10px; }
  .best-bet .heatmap-section { width: 100%; }
  .best-bet .heatmap {
    border-spacing: 3px 3px;
    width: 100%;
    table-layout: fixed;
  }
  .best-bet .heatmap .heatmap-cell {
    min-width: 0;
    width: auto;
    padding: 0 2px;
    font-size: 11px;
    height: 24px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .best-bet .heatmap th {
    padding: 1px 2px;
    font-size: 9px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .best-bet .heatmap .heatmap-name {
    width: 70px;
    max-width: 70px;
  }
  .best-bet .heatmap .heatmap-name a {
    font-size: 11px;
    padding-right: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    max-width: 100%;
  }

  /* Per-crag mini heatmap is REDUNDANT with the top heatmap on mobile
     (same info, different orientation). Hide it on mobile to cut clutter
     and total scroll length. */
  .crag-section .mini-heatmap { display: none; }

  /* Best-window block: wrap so it doesn't overflow */
  .crag-section .best-window { font-size: 12px; }

  /* Score legend (collapses to 1-col grid via the existing @media rule) */
  .score-legend { padding: 14px 12px; }
  .score-legend-intro { font-size: 12px; }
  .score-legend-grid { font-size: 12px; }

  /* Footer */
  footer { padding: 24px 12px 0; }
  footer .footer-donate { font-size: 12px; }
}

.best-bet .rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.best-bet .rank-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.best-bet .rank-row::before {
  counter-increment: rank-counter;
  content: counter(rank-counter);
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  width: 18px;
  text-align: right;
  font-size: 12px;
}

.best-bet .rank-list { counter-reset: rank-counter; }

.best-bet .rank-row .rank-name {
  flex: 1;
  color: var(--fg);
  text-decoration: none;
}

.best-bet .rank-row .rank-name:hover { color: var(--accent); }

/* ── heatmap (top of homepage) ────────────────────────── */
.best-bet .heatmap {
  border-collapse: separate;
  border-spacing: 6px 4px;
  margin: 4px 0 2px;
  font-size: 13px;
}

.best-bet .heatmap th {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  text-align: center;
}

.best-bet .heatmap th:first-child { text-align: left; }

.best-bet .heatmap td.heatmap-name a {
  color: var(--fg);
  text-decoration: none;
  font-weight: 500;
  padding-right: 12px;
}
.best-bet .heatmap td.heatmap-name a:hover { color: var(--accent); }

.best-bet .heatmap .heatmap-cell {
  min-width: 84px;
  height: 28px;
  border-radius: 4px;
  cursor: help;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 13px;
  padding: 0 8px;
}

.heatmap-cell.heatmap-empty { background: var(--bg); color: var(--fg-muted); }

/* ── factor chips (per-crag header) ───────────────────── */
.crag-section .factor-chips {
  display: inline-flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* Mini per-crag 3-period heatmap. */
.crag-section .mini-heatmap {
  border-collapse: separate;
  border-spacing: 6px 3px;
  margin: 10px 0 14px;
  font-size: 13px;
}
.crag-section .mini-heatmap th {
  font-size: 10px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  text-align: center;
}
.crag-section .mini-heatmap th:first-child { text-align: left; }
.crag-section .mini-heatmap .mini-period {
  color: var(--fg);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-right: 10px;
  white-space: nowrap;
}
.crag-section .mini-heatmap .heatmap-cell {
  min-width: 64px;
  height: 24px;
  border-radius: 4px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 12px;
  padding: 0 6px;
}

.factor-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: lowercase;
  cursor: help;
  font-variant-numeric: tabular-nums;
}

.factor-chip.factor-empty { background: var(--bg); color: var(--fg-muted); }

/* ── best-window pill (tone-colored) ──────────────────── */
.crag-section .best-window-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: white;
}
.best-window-pill.best-good  { background: var(--go); }
.best-window-pill.best-mixed { background: var(--maybe); }
.best-window-pill.best-poor  { background: var(--no); }

/* ── crag sections (homepage, full per-crag block) ────── */
.crag-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.crag-section {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
}

.crag-section .crag-header {
  display: flex;
  align-items: center;
  gap: var(--gap);
  margin-bottom: 8px;
}

.crag-section .crag-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  flex: 1;
}

.crag-section .crag-header h2 a {
  color: var(--fg);
  text-decoration: none;
}

.crag-section .crag-header h2 a:hover {
  color: var(--accent);
}

.crag-section .state {
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 400;
  margin-left: 4px;
}

.crag-section .now-line {
  font-size: 14px;
  margin: 4px 0 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
}

.crag-section .now-line .observed {
  font-size: 12px;
  margin-left: 4px;
}

.crag-section .now-prefix {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
  margin-right: 2px;
}

.crag-section .now-sep {
  color: var(--fg-muted);
  margin: 0 4px;
}

.crag-section .now-pill {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 1px 6px;
  border-radius: 4px;
}

.crag-section .now-pill.now-caution {
  background: rgba(217, 119, 6, 0.18);
  color: var(--maybe);
}
.crag-section .now-pill.now-warn {
  background: rgba(220, 38, 38, 0.18);
  color: var(--no);
}

@media (prefers-color-scheme: dark) {
  .crag-section .now-pill.now-caution { background: rgba(245, 158, 11, 0.22); }
  .crag-section .now-pill.now-warn    { background: rgba(239, 68, 68, 0.22); }
}
:root[data-theme="dark"] .crag-section .now-pill.now-caution { background: rgba(245, 158, 11, 0.22); }
:root[data-theme="dark"] .crag-section .now-pill.now-warn    { background: rgba(239, 68, 68, 0.22); }

.crag-section .best-window {
  font-size: 13px;
  margin: 4px 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.crag-section .best-window-label {
  color: var(--fg-muted);
}

.crag-section .best-window-pill {
  font-size: 11px;
  padding: 2px 8px;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  color: white;
}

.score-pill.GO     { background: var(--go); }
.score-pill.MAYBE  { background: var(--maybe); }
.score-pill.NO     { background: var(--no); }
.score-pill.ERR    { background: var(--offline); }

/* ── chart ────────────────────────────────────────────── */
.chart-wrap {
  margin: 12px 0 16px;
  position: relative;
}

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
  font-family: ui-monospace, monospace;
  /* Reserve horizontal drags for our touch-scrub handler while leaving
     vertical page-scroll to the browser. Also suppress text-selection / the
     iOS long-press callout so scrubbing feels clean. */
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.chart-svg .chart-axis {
  font-size: 14px;
  fill: var(--fg-muted);
}

.chart-svg .chart-legend {
  font-size: 14px;
  fill: var(--fg);
}

.chart-svg .chart-legend-secondary {
  font-size: 12px;
  fill: var(--fg-muted);
}

.chart-svg .chart-day-label {
  font-size: 14px;
  font-weight: 600;
  fill: var(--fg);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chart-svg .chart-crosshair {
  pointer-events: none;
}

.chart-tooltip {
  position: absolute;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  z-index: 10;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
  display: none;
  min-width: 170px;
  font-variant-numeric: tabular-nums;
}

.chart-tooltip .tt-time {
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 13px;
}

.chart-tooltip .tt-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.chart-tooltip .tt-label {
  color: var(--fg-muted);
}

.chart-tooltip .tt-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.chart-tooltip.pinned {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(37,99,235,0.25);
}

.chart-svg { cursor: crosshair; }
.chart-svg.pinned { cursor: pointer; }

/* ── inline cams (homepage) ───────────────────────────── */
/* One cam per row at every breakpoint — latest + daylight take the full
   crag-section width side-by-side, so each image is ~half of ~1450px ≈ 700px.
   Large enough to actually read road surface conditions. */
.cams-inline {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-top: 14px;
}

.cam-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cam-block-head {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 12px;
  line-height: 1.3;
}

.cam-block-label {
  font-weight: 600;
}

.cam-block-miles {
  color: var(--fg-muted);
  font-size: 11px;
}

.cam-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.cam-fig {
  margin: 0;
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.cam-fig a {
  display: block;
  aspect-ratio: 16 / 9;
}

.cam-fig img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cam-fig figcaption {
  font-size: 10px;
  color: var(--fg-muted);
  text-align: center;
  padding: 2px 0;
  border-top: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cam-fig.offline { opacity: 0.6; }

.cam-fig .cam-offline-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--fg-muted);
  background: var(--bg);
  bottom: 18px;        /* leave the figcaption visible */
}

/* ── per-crag detail ──────────────────────────────────── */
.score-banner {
  display: flex;
  align-items: center;
  gap: var(--gap);
  font-size: 24px;
  margin-bottom: 8px;
}

.score-banner .score-pill {
  font-size: 20px;
  padding: 5px 14px;
}

.now-panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}

.now-panel .now-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 640px) {
  .now-panel .now-grid { grid-template-columns: repeat(4, 1fr); }
}

.now-panel .stat {
  font-size: 12px;
  color: var(--fg-muted);
}

.now-panel .stat strong {
  display: block;
  font-size: 22px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 2px;
}

/* ── history ──────────────────────────────────────────── */
.history h2 {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
  margin: 24px 0 8px;
}

.history .stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

@media (min-width: 640px) {
  .history .stats { grid-template-columns: repeat(4, 1fr); }
}

.history .stat {
  font-size: 12px;
  color: var(--fg-muted);
}

.history .stat strong {
  display: block;
  font-size: 18px;
  font-weight: 600;
  color: var(--fg);
}

/* ── notes ────────────────────────────────────────────── */
.notes {
  margin: 16px 0;
  font-size: 13px;
  font-style: italic;
  color: var(--fg-muted);
  padding-left: 12px;
  border-left: 3px solid var(--border);
}

/* ── breakdown ────────────────────────────────────────── */
details#breakdown {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  margin: 16px 0;
  font-size: 13px;
}

details#breakdown summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--fg-muted);
}

#breakdown-body {
  margin-top: 8px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

/* ── score legend ─────────────────────────────────────── */
.score-legend {
  margin: 32px 0 16px;
  padding: 18px 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.score-legend-title {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
  margin: 0 0 12px;
}

.score-legend-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.score-legend-intro {
  font-size: 13px;
  color: var(--fg-muted);
  margin: 0 0 12px;
}

.legend-gradient {
  height: 14px;
  border-radius: 4px;
  margin-bottom: 18px;
  background: linear-gradient(
    to right,
    rgb(215,25,28)   0%,
    rgb(253,174,97)  25%,
    rgb(255,255,191) 50%,
    rgb(171,217,233) 75%,
    rgb(44,123,182)  100%
  );
  position: relative;
}
.legend-gradient::before {
  content: "bad → best";
  position: absolute;
  top: 18px;
  left: 0;
  right: 0;
  font-size: 11px;
  color: var(--fg-muted);
  display: flex;
  justify-content: space-between;
}
.legend-gradient::after { content: ""; }

.score-legend-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.5;
}

.score-legend-grid dt {
  font-weight: 600;
  color: var(--fg);
}

.score-legend-grid dd {
  margin: 0;
  color: var(--fg-muted);
}

@media (max-width: 600px) {
  .score-legend-grid {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }
  .score-legend-grid dd { margin-bottom: 8px; }
}

.score-legend-note {
  font-size: 12px;
  margin: 8px 0 0;
}

/* ── footer ───────────────────────────────────────────── */
footer {
  text-align: center;
  font-size: 12px;
  padding: 32px 16px 0;
}

footer .footer-donate {
  font-size: 13px;
  margin: 0 0 6px;
  color: var(--fg);
}

footer .footer-donate a {
  font-weight: 600;
}
