:root {
  --bg: #0F1A1C;
  --bar: #12201F;
  --surface: #172629;
  --line: #22383C;
  --line-2: #2A4246;
  --text: #E8EEEC;
  --text-2: #C9D6D4;
  --muted: #9DB0AE;
  --water: #5FB8B0;
  --water-ink: #8FD9D1;
  --sand: #E0A458;
  --sand-hi: #F2C58A;
  --minor: #F08A4B;
  --major: #E5484D;
  --scrim: rgba(10, 18, 19, 0.82);
  --gutter: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  overflow-x: hidden;
}
a { color: var(--sand); }
a:hover { color: var(--sand-hi); }
h1, h2, h3, .brand-name, .big, .mid, .ov-level { font-family: "Space Grotesk", Inter, sans-serif; }
h1 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
h3 { margin: 0; font-size: 17px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.accent { color: var(--sand); font-weight: 600; }
.strong { font-weight: 600; margin-top: 2px; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--sand); outline-offset: 2px; }

.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding-left: max(var(--gutter), env(safe-area-inset-left)); padding-right: max(var(--gutter), env(safe-area-inset-right)); }
.wrap-wide, body[data-page="live"] .topbar .wrap, body[data-page="live"] .footer .wrap { max-width: 1680px; }
@media (min-width: 720px) { :root { --gutter: 24px; } }

/* ------------------------------------------------------------------ header */
.topbar { background: var(--bar); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding-top: 10px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-width: 0; }
.brand:hover { color: var(--text); }
.brand svg { flex: none; }
.brand > span { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; font-size: 19px; letter-spacing: -0.01em; line-height: 1.2; white-space: nowrap; }
.brand-sub { line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav { display: flex; gap: 2px; font-size: 14px; font-weight: 500; margin-left: auto; }
.nav a { color: var(--muted); text-decoration: none; padding: 10px 14px; border-radius: 8px; text-align: center; white-space: nowrap; }
.nav a:hover { color: var(--text); background: var(--surface); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface); box-shadow: inset 0 -2px 0 var(--sand); }

.now-pill { order: 3; display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: #183B3A; color: var(--water-ink); text-decoration: none; font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.now-pill:hover { color: var(--water-ink); }
.now-pill .dot, .badge .dot { width: 8px; height: 8px; border-radius: 999px; background: var(--water); flex: none; }
body[data-page="live"] .now-pill { display: none; }

@media (max-width: 759px) {
  .topbar-inner { padding-top: 8px; padding-bottom: 0; gap: 6px 12px; }
  .brand-name { font-size: 17px; }
  .now-pill { order: 0; margin-left: auto; }
  body[data-page="live"] .brand { margin-right: auto; }
  body:not([data-page="live"]) .brand-sub { display: none; }
  .now-pill { padding: 5px 10px; font-size: 13px; }
  .now-cls { display: none; }
  .nav { order: 4; flex-basis: 100%; margin: 0 calc(-1 * var(--gutter)); padding: 0 calc(var(--gutter) - 6px); display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; }
  .nav a { padding: 12px 4px; border-radius: 0; }
  .nav a[aria-current="page"] { background: transparent; box-shadow: inset 0 -3px 0 var(--sand); }
}
@media (max-width: 380px) { .brand-sub { display: none; } }

.main { flex: 1; display: flex; flex-direction: column; gap: 32px; padding-top: 24px; padding-bottom: 48px; }
@media (max-width: 599px) { .main { padding-top: 16px; gap: 24px; } }

/* ------------------------------------------------------------------- cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.pad { padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

.stat { padding: 16px 18px; border-radius: 14px; }
.numbers { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); gap: 12px; }
.numbers .mid { font-variant-numeric: tabular-nums; }
.big { font-weight: 600; font-size: 44px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.mid { font-weight: 600; font-size: 28px; line-height: 1.2; margin-top: 6px; }

.badge { display: inline-flex; align-items: center; gap: 8px; border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 14px; background: #183B3A; color: var(--water-ink); white-space: nowrap; }
[data-cls="above"] { background: #3D2D17; color: var(--sand-hi); }
[data-cls="above"] .dot { background: var(--sand); }
[data-cls="minor"], [data-cls="moderate"] { background: #42261A; color: #FFC2A0; }
[data-cls="minor"] .dot, [data-cls="moderate"] .dot { background: var(--minor); }
[data-cls="major"] { background: #4A1D20; color: #FFB4B6; }
[data-cls="major"] .dot { background: var(--major); }
[data-cls="unknown"] { background: var(--line); color: var(--text-2); }
[data-cls="unknown"] .dot { background: var(--muted); }

.section-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.section-head p { margin-top: 2px; font-size: 14px; }

/* --------------------------------------------------------------- live page */
.live-page { gap: 16px; }
.live-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
@media (min-width: 1000px) { .live-grid { grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; } }
@media (min-width: 1400px) { .live-grid { grid-template-columns: minmax(0, 1fr) 380px; } }
.live-cam { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.cam-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }

.flood-banner { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px; background: #42261A; color: #FFC2A0; text-decoration: none; font-weight: 600; }
.flood-banner:hover { color: #FFE0CC; }
.flood-banner .dot { width: 9px; height: 9px; border-radius: 999px; background: var(--minor); animation: pulse 2s infinite; flex: none; }
.flood-banner .arrow { margin-left: auto; }
.flood-banner[hidden] { display: none; }

.river { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.river-now { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 10px; }
.river-level { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.trend { font-size: 14px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.trend[data-dir="up"] { color: var(--sand-hi); }
.trend[data-dir="down"] { color: var(--water-ink); }
.status-note { color: var(--text-2); }
.status-note:empty { display: none; }
.river-chart { border-top: 1px solid var(--line); padding-top: 14px; }
.river .levels { border-top: 1px solid var(--line); padding-top: 14px; margin: 0; }

.seg { display: inline-flex; gap: 2px; background: var(--bar); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { min-height: 32px; min-width: 44px; padding: 0 10px; border: none; border-radius: 7px; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--line-2); color: var(--text); }

/* tablet: put the river panel's parts side by side under the camera */
@media (min-width: 640px) and (max-width: 999px) {
  .river { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); column-gap: 24px; }
  .river > :not(.river-chart) { grid-column: 1; }
  .river-chart { grid-column: 2; grid-row: 1 / span 4; border-top: 0; padding-top: 0; }
}

@media (max-width: 599px) { .big { font-size: 40px; } }

/* ------------------------------------------------------------------- media */
.media { position: relative; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); background: #0A1213; aspect-ratio: 16 / 9; }
.media img, .media video { display: block; width: 100%; height: 100%; object-fit: cover; background: #0A1213; }
.media video { object-fit: contain; }
.media video[hidden], .media.no-video .overlay { display: none; }
.media-live:fullscreen { border: 0; border-radius: 0; aspect-ratio: auto; width: 100%; height: 100%; }
.media-live:fullscreen img { object-fit: contain; }
.media-live:-webkit-full-screen { border: 0; border-radius: 0; width: 100%; height: 100%; }
.media-live:-webkit-full-screen img { object-fit: contain; }

.live-pill { position: absolute; top: 12px; left: 12px; display: inline-flex; align-items: center; gap: 6px; background: var(--scrim); border-radius: 999px; padding: 5px 10px; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; font-variant-numeric: tabular-nums; }
.live-pill .dot { width: 7px; height: 7px; border-radius: 999px; background: var(--sand); animation: pulse 2s infinite; }
.live-time { font-weight: 500; letter-spacing: 0; color: var(--text-2); }
.live-time:not(:empty)::before { content: "· "; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .live-pill .dot, .flood-banner .dot { animation: none; } }

.cam-actions { display: flex; gap: 8px; }
/* phone: camera goes edge to edge (after .media so it wins) */
@media (max-width: 599px) {
  .media.media-live { margin: 0 calc(-1 * var(--gutter)); border-radius: 0; border-left: 0; border-right: 0; }
  .cam-actions { width: 100%; }
  .cam-actions .toggle { flex: 1; justify-content: center; }
}

.overlay { position: absolute; background: var(--scrim); border-radius: 12px; pointer-events: none; }
.overlay-live { right: 14px; bottom: 14px; display: flex; align-items: stretch; gap: 14px; padding: 12px 16px; border: 1px solid rgba(143, 217, 209, 0.25); }
.overlay-video { right: 12px; top: 12px; padding: 8px 12px; display: flex; align-items: baseline; gap: 8px; }
.ov-level { font-weight: 700; font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.overlay-video .ov-level { font-size: 20px; }
.ov-sub { font-size: 12px; color: var(--text-2); }
.gauge { width: 8px; border-radius: 4px; background: var(--line-2); position: relative; overflow: hidden; }
.gauge-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: var(--water); transition: height 0.6s; }
.gauge-mark { position: absolute; left: -2px; right: -2px; height: 2px; background: var(--sand); }
body.overlay-off .overlay { display: none; }
@media (max-width: 599px) {
  .overlay-live { right: 8px; bottom: 8px; padding: 6px 10px; gap: 8px; border-radius: 10px; }
  .overlay-live .label { display: none; }
  .ov-level { font-size: 20px; }
  .ov-sub { font-size: 11px; }
  .overlay-video { right: 8px; top: 8px; padding: 5px 9px; }
  .overlay-video .ov-level { font-size: 16px; }
  .live-pill { top: 8px; left: 8px; }
}

.toggle { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 14px; background: var(--surface); color: var(--text); border: 1px solid var(--line-2); border-radius: 10px; font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; }
.switch { position: relative; width: 36px; height: 20px; border-radius: 999px; background: var(--line-2); flex: none; transition: background 0.2s; }
.switch span { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 999px; background: var(--bg); transition: left 0.2s; }
.toggle[aria-pressed="true"] .switch { background: var(--water); }
.toggle[aria-pressed="true"] .switch span { left: 18px; }

.chart { margin-top: 12px; min-height: 120px; }
.chart svg { display: block; width: 100%; height: auto; }
.levels { display: grid; grid-template-columns: 1fr auto; row-gap: 8px; margin: 10px 0 0; font-size: 14px; }
.levels dt { color: var(--text-2); }
.levels dt.accent { color: var(--sand); }
.levels dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------- timelapse page */
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tabs button { min-height: 40px; padding: 0 16px; border-radius: 8px; border: none; background: transparent; color: var(--text-2); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { background: var(--sand); color: var(--bg); }
@media (max-width: 599px) {
  .tabs { width: 100%; }
  .tabs button { flex: 1; padding: 0 6px; }
}

.player-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
@media (min-width: 900px) { .player-grid { grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; } }
.info { display: flex; flex-direction: column; gap: 12px; }
.info h3 { font-size: 20px; }
.info p { color: var(--text-2); font-size: 14px; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; font-size: 13px; }
.facts > div { background: var(--bar); border-radius: 10px; padding: 10px 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; border-radius: 10px; border: 1px solid var(--line-2); text-decoration: none; color: var(--text); font-weight: 500; font-size: 14px; }
.btn:hover { color: var(--text); background: var(--bar); }
.btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; color: var(--muted); }

/* -------------------------------------------------------------- floods page */
.events { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 16px; }
.event { display: flex; flex-direction: column; text-align: left; padding: 0; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; cursor: pointer; }
.event:hover { border-color: var(--line-2); }
.event:disabled { cursor: default; }
.event:focus-visible { outline: 2px solid var(--sand); outline-offset: 2px; }
.event-thumb { position: relative; aspect-ratio: 16 / 9; background: #0A1213; }
.event-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.event-badge { position: absolute; left: 10px; top: 10px; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; background: var(--sand); color: var(--bg); }
.event-badge[data-cls="minor"], .event-badge[data-cls="moderate"] { background: var(--minor); color: var(--bg); }
.event-badge[data-cls="major"] { background: var(--major); color: #fff; }
.event-badge[data-live] { background: var(--text); color: var(--bg); }
.event-len { position: absolute; right: 10px; bottom: 10px; background: var(--scrim); border-radius: 6px; padding: 2px 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
.event-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.event-title { font-family: "Space Grotesk", Inter, sans-serif; font-weight: 600; font-size: 17px; }
.event-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; margin-top: 4px; }

.dialog { width: min(1100px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 16px; background: var(--surface); color: var(--text); border: 1px solid var(--line-2); border-radius: 16px; }
.dialog::backdrop { background: rgba(5, 10, 11, 0.75); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.dialog p { margin-top: 10px; }
@media (max-width: 599px) {
  .dialog { width: calc(100vw - 16px); max-width: none; padding: 12px; border-radius: 12px; }
  .dialog .media { border-radius: 10px; }
}
.icon-btn { width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; border: 1px solid var(--line-2); background: transparent; color: var(--text); cursor: pointer; }

/* ------------------------------------------------------------------ footer */
.footer { background: var(--bar); border-top: 1px solid var(--line); }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; padding-top: 24px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.version { flex-basis: 100%; font-variant-numeric: tabular-nums; opacity: 0.8; }
.version .warn { color: var(--sand); }
