/* 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-dew:     #3b82f6;
  --chart-past-bg: rgba(0,0,0,0.025);
  --radius:        8px;
  --gap:           12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --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-dew:     #60a5fa;
    --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;
}

/* ── main ─────────────────────────────────────────────── */
main {
  max-width: 1100px;
  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;
}

.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); }

/* ── 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;
}

.crag-section .now-line strong { font-weight: 600; }

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

.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;
}

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
  font-family: ui-monospace, monospace;
}

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

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

/* ── inline cams (homepage) ───────────────────────────── */
.cams-inline {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-top: 14px;
}

@media (min-width: 720px) {
  .cams-inline { grid-template-columns: repeat(2, 1fr); }
}

.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;
}

/* ── cams ─────────────────────────────────────────────── */
.cams {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
  margin: 16px 0;
}

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

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

.cam {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cam .head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
}

.cam .label {
  font-size: 12px;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.cam .modes {
  display: flex;
  gap: 4px;
  font-size: 11px;
}

.cam .modes button {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg-muted);
  padding: 2px 6px;
  font: inherit;
  cursor: pointer;
}

.cam .modes button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.cam .img-wrap {
  position: relative;
  background: var(--bg);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 4px;
}

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

.cam .offline {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--fg-muted);
  font-size: 11px;
}

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

.forecast table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.forecast th, .forecast td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.forecast th {
  font-weight: 600;
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.forecast tr:last-child td { border-bottom: none; }

.forecast tr.divider td {
  background: var(--bg);
  font-weight: 600;
  font-size: 11px;
  color: var(--fg-muted);
}

/* ── history ──────────────────────────────────────────── */
.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;
}

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