:root {
  --bg: #ffffff;
  --fg: #1d2329;
  --muted: #66717c;
  --line: #d9dee3;
  --panel: rgba(255, 255, 255, 0.96);
  --accent: #1f6fd6;
  --accent-fg: #ffffff;
  --btn: #eef1f4;
  --btn-hover: #e1e6eb;
  --buf-empty: #e3e7eb;
  --buf-loading: #f2c14e;
  --buf-ready: #4f9be8;
  --buf-error: #e0301e;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15191d;
    --fg: #e6e9ec;
    --muted: #9aa5b0;
    --line: #2f363d;
    --panel: rgba(28, 33, 38, 0.96);
    --btn: #262c32;
    --btn-hover: #323941;
    --buf-empty: #2f363d;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
}

button, select, input { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- top bar */

#topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}

#topbar h1 { font-size: 16px; margin: 0 8px 0 0; }

.ctl, .chk { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.ctl select { padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--btn); }
.opacity input { width: 90px; }

/* ---------------------------------------------------------------- map */

#mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #dfe6ea; }
.radar-img { image-rendering: auto; }

#message {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 1000; padding: 8px 14px; border-radius: 8px;
  background: #b3261e; color: #fff; box-shadow: var(--shadow);
}

.legend {
  background: var(--panel); color: var(--fg);
  padding: 6px 8px; border-radius: 8px; box-shadow: var(--shadow);
  font-size: 11px; min-width: 200px;
}
.legend[hidden] { display: none; }
.lg-title { font-weight: 600; margin: 2px 0; }
.lg-title:not(:first-child) { margin-top: 6px; }
.lg-rain { display: flex; height: 10px; }
.lg-rain span { flex: 1; }
.lg-grad { height: 10px; }
.lg-labels { display: flex; color: var(--muted); }
.lg-labels span { flex: 1; }
.lg-labels.ends { justify-content: space-between; }
.lg-labels.ends span { flex: 0; }

/* station markers */
.st-icon { background: none; border: 0; }
.st {
  position: absolute; transform: translate(-50%, -50%);
  display: inline-flex; align-items: center; gap: 2px;
  padding: 1px 5px; border-radius: 9px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
.st .arr { font-style: normal; display: inline-block; line-height: 1; }
.st-icon.sel .st { outline: 2px solid var(--accent); outline-offset: 1px; z-index: 1; }
.obs-compact .st { width: 11px; height: 11px; padding: 0; border-radius: 50%; }
.obs-compact .st span, .obs-compact .st .arr { display: none; }

/* ---------------------------------------------------------------- station panel */

#panel {
  position: absolute; top: 10px; right: 10px; bottom: 10px; z-index: 1100; /* above Leaflet controls */
  width: 330px; overflow-y: auto;
  background: var(--panel); border-radius: 10px; box-shadow: var(--shadow);
  padding: 12px 14px;
}
#panel[hidden] { display: none; }
#panel h2 { font-size: 17px; margin: 0 28px 2px 0; }
#panel table { width: 100%; border-collapse: collapse; margin-top: 6px; }
#panel th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 6px 4px 0; }
#panel td { padding: 4px 0; border-top: 1px solid var(--line); }
#panel th { border-top: 1px solid var(--line); }
#panel td.v { font-weight: 600; white-space: nowrap; padding-right: 8px; }
#panel td.spark { width: 92px; }
#panel .spark svg path { fill: none; stroke: var(--accent); stroke-width: 1.4; }
#panel .spark svg circle { fill: var(--accent); }
#panel .when { margin: 8px 0 0; }
.badge { font-size: 11px; background: #f2c14e; color: #111; border-radius: 4px; padding: 0 5px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 11px; margin-top: 8px; }
#panel-close { position: absolute; top: 8px; right: 8px; }

/* ---------------------------------------------------------------- timeline */

#timeline {
  border-top: 1px solid var(--line);
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 6px;
}
#timeline .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btns { display: flex; gap: 3px; }
.track { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: 2px; }
#tl-slider { width: 100%; margin: 0; accent-color: var(--accent); }
#tl-buffer { width: 100%; height: 6px; border-radius: 3px; cursor: pointer; }
.label { min-width: 230px; white-space: nowrap; }
.label span { color: var(--muted); }

button.icon, button.txt, .seg button {
  border: 1px solid var(--line); background: var(--btn); border-radius: 6px; cursor: pointer;
}
button.icon { width: 32px; height: 30px; padding: 0; display: inline-grid; place-items: center; }
button.icon svg { width: 16px; height: 16px; fill: currentColor; }
button:hover { background: var(--btn-hover); }
button.play { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.play .i-pause, button.play.playing .i-play { display: none; }
button.play.playing .i-pause { display: block; }
button.txt { padding: 4px 10px; height: 30px; }
button.txt.busy { background: #fff3cf; color: #111; }
button.live.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.seg { display: inline-flex; align-items: center; }
.seg > span { color: var(--muted); margin-right: 6px; }
.seg button { padding: 4px 9px; height: 30px; border-radius: 0; margin-left: -1px; }
.seg button:first-of-type { border-radius: 6px 0 0 6px; }
.seg button:last-of-type { border-radius: 0 6px 6px 0; }
.seg button.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); position: relative; }
.seg button[hidden] { display: none; }

/* ---------------------------------------------------------------- phones */

@media (max-width: 640px) {
  #topbar { gap: 4px 10px; padding: 6px 10px; }
  #topbar h1 { display: none; }
  .opacity input { width: 70px; }
  #timeline { padding-left: 8px; padding-right: 8px; }
  .label { min-width: 0; width: 100%; order: -1; font-size: 13px; }
  .track { min-width: 0; }
  #timeline .row.opts { gap: 6px; }
  .seg > span { display: none; }
  #panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 55%;
    border-radius: 12px 12px 0 0;
  }
  .legend { min-width: 160px; }
}
