:root {
  --bg: #0b1118;
  --surface: #121a24;
  --surface-2: #1a2431;
  --border: #243142;
  --text: #e2e8f0;
  --muted: #8a9bb0;
  --accent: #2dd4bf;
  --calm: #34d399;
  --watch: #fbbf24;
  --high: #f87171;
  --river: #60a5fa;
  --topbar-h: 52px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(11, 17, 24, 0.92);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: 0.04em; text-transform: uppercase; }
.live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--high);
  box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.6);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  70% { box-shadow: 0 0 0 8px rgba(248, 113, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0); }
}
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

#map { position: fixed; inset: var(--topbar-h) 0 0 0; }

.link-btn {
  background: none; border: 0; padding: 0;
  color: var(--accent); font: inherit; font-size: 14px;
  cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}

.hint {
  position: fixed;
  left: 50%; bottom: 28px;
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
}

/* Panel: bottom sheet on phones, side panel on wider screens */
.panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 62vh;
  overflow-y: auto;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.45);
  z-index: 5;
}
@media (min-width: 760px) {
  .panel {
    left: auto; right: 16px; top: calc(var(--topbar-h) + 16px); bottom: auto;
    width: 360px;
    max-height: calc(100vh - var(--topbar-h) - 32px);
    border: 1px solid var(--border);
    border-radius: 14px;
  }
}

.close-btn {
  position: absolute; top: 10px; right: 10px;
  width: 36px; height: 36px;
  border: 0; border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  font-size: 22px; line-height: 1;
  cursor: pointer;
}

.eyebrow {
  margin: 0;
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent);
}
.panel h2 { margin: 2px 40px 10px 0; font-size: 20px; line-height: 1.25; }
.summary { margin: 0 0 14px; font-size: 15px; line-height: 1.45; }

.hero { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.temp { font-size: 56px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.unit { font-size: 24px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.feels { color: var(--muted); font-size: 14px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); }
/* calm → watch → high colour scale, shared by stats, river cards, bars and swatches */
.stat.lvl-calm, .river.lvl-calm { border-left: 4px solid var(--calm); }
.stat.lvl-watch, .river.lvl-watch { border-left: 4px solid var(--watch); }
.stat.lvl-high, .river.lvl-high { border-left: 4px solid var(--high); }
.bar.lvl-calm, .swatch.lvl-calm, .key.lvl-calm { background: var(--river); }
.bar.lvl-watch, .swatch.lvl-watch, .key.lvl-watch { background: var(--watch); }
.bar.lvl-high, .swatch.lvl-high, .key.lvl-high { background: var(--high); }
.swatch.lvl-calm { background: var(--calm); }

.meta { margin: 12px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); }
.muted { color: var(--muted); }
.panel h3 {
  margin: 22px 0 10px; font-size: 13px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.h3-sub { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 6px; }
.totals { margin-top: 10px; }

/* Flood watch box */
.flood {
  margin: 0 0 14px; padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border); border-left-width: 4px;
  border-radius: 10px;
}
.flood-calm { border-left-color: var(--calm); }
.flood-watch { border-left-color: var(--watch); }
.flood-high { border-left-color: var(--high); }
.flood-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.flood-title { font-weight: 600; font-size: 15px; }
.est {
  margin-left: 4px; padding: 1px 6px;
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); border: 1px solid var(--border); border-radius: 999px;
  vertical-align: 2px;
}
.badge {
  padding: 4px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: #0b1118;
}
.badge-calm { background: var(--calm); }
.badge-watch { background: var(--watch); }
.badge-high { background: var(--high); }
.reasons { margin: 10px 0 0; padding-left: 18px; font-size: 14px; line-height: 1.45; }
.reasons li + li { margin-top: 4px; }
.flood-note { margin: 10px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); }

/* Hourly rain bars */
.bars {
  display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px;
  align-items: end; height: 72px;
  padding: 0 0 2px; border-bottom: 1px solid var(--border);
}
.bar { border-radius: 2px 2px 0 0; min-height: 2px; }
.bar-axis { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 4px; font-size: 11px; color: var(--muted); }
.chart-key { margin-top: 6px; }
.key, .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 4px 0 8px; vertical-align: -1px; }

/* River cards */
.river {
  margin-bottom: 8px; padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px;
}
.river-top { font-size: 14px; }
.river-nums { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 4px 0 6px; font-size: 13px; }
.river-ahead { margin: 0 0 6px; font-size: 13px; color: var(--watch); }
.river .meta { margin-top: 4px; }
.spark { display: block; width: 100%; height: 56px; }
.spark path { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark-past { stroke: var(--river); }
.spark-future { stroke: var(--river); opacity: 0.45; stroke-dasharray: 4 3; }
.spark-usual { stroke: var(--muted); stroke-dasharray: 3 3; stroke-width: 1; vector-effect: non-scaling-stroke; opacity: 0.7; }
.spark-today { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }

/* Map key */
.legend {
  position: fixed; top: calc(var(--topbar-h) + 10px); left: 10px;
  padding: 8px 10px;
  background: rgba(18, 26, 36, 0.9);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 12px; z-index: 4;
}
.legend p { margin: 0; }
.legend-title { font-weight: 600; margin-bottom: 4px !important; }
.legend-row { color: var(--muted); line-height: 1.8; }
.legend-row .swatch:first-child { margin-left: 0; }
.ring {
  display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px;
  border: 3px solid var(--river); border-radius: 50%; background: var(--bg);
}
.updated { margin-top: 4px !important; color: var(--muted); font-size: 11px; }
.updated.stale { color: var(--watch); }
.loading, .error { padding: 16px 0; color: var(--muted); font-size: 15px; }

/* Data sources dialog */
.sources {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 20px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.sources::backdrop { background: rgba(0, 0, 0, 0.6); }
.sources h2 { margin: 0 0 12px; font-size: 18px; }
.sources ul { padding-left: 18px; margin: 0 0 12px; }
.sources li { margin-bottom: 10px; font-size: 14px; line-height: 1.5; }
.note { font-size: 13px; color: var(--muted); line-height: 1.5; }
.btn {
  margin-top: 4px; padding: 10px 18px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font: inherit; cursor: pointer;
}

/* Keep MapLibre's attribution readable on the dark theme */
.maplibregl-ctrl-attrib { background: rgba(18, 26, 36, 0.85) !important; color: var(--muted); }
.maplibregl-ctrl-attrib a { color: var(--muted); }
