/* ------------------------------------------------------------------ tokens */
:root {
  --bg-app: #eef2f6;
  --bg-panel: rgba(255, 255, 255, 0.80);      /* light glass */
  --bg-raised: rgba(255, 255, 255, 0.96);
  --stroke: rgba(30, 45, 65, 0.10);
  --text: #16212c;
  --text-dim: #5c6b7a;
  --accent: #0d8ddb;                          /* rain blue — shared with the data */
  --tile-mix: rgba(127, 127, 127, 0.07);
  --radius: 14px;
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.10);
}

:root[data-theme="dark"] {
  --bg-app: #0b111a;
  --bg-panel: rgba(15, 23, 33, 0.82);         /* cold night-blue glass */
  --bg-raised: rgba(26, 37, 51, 0.9);
  --stroke: rgba(140, 170, 200, 0.16);
  --text: #e9f0f7;
  --text-dim: #8ba0b5;
  --accent: #5ec8f2;
  --tile-mix: rgba(255, 255, 255, 0.05);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg-app);
}

#map { position: fixed; inset: 0; background: var(--bg-app); }

/* Darken the light parts of the basemap slightly in dark mode so radar
   colors pop; the light basemap is already muted enough on its own. */
:root[data-theme="dark"] .leaflet-tile-pane { filter: saturate(0.85) brightness(0.95); }
.leaflet-control-attribution { color: var(--text-dim); background: var(--bg-raised) !important; }
.leaflet-control-attribution a { color: var(--text-dim); }
.radar-frame { transition: opacity 120ms linear; image-rendering: auto; }

/* ------------------------------------------------------------------ HUD */
.hud {
  position: fixed;
  z-index: 900;
  background: var(--bg-panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.hud-top {
  top: 16px; left: 16px;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  max-width: min(620px, calc(100vw - 32px));
}

.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700; font-size: 17px; letter-spacing: 0.01em;
}
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) {
  .brand-dot { animation: none; }
  .radar-frame { transition: none; }
}

/* Search */
.search { position: relative; flex: 1; min-width: 140px; }
#search-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid var(--stroke);
  background: var(--tile-mix);
  color: var(--text);
  font: 500 14px var(--font-body);
  outline: none;
}
#search-input:focus-visible { border-color: var(--accent); }
#search-input::placeholder { color: var(--text-dim); }

.search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  margin: 0; padding: 6px; list-style: none;
  background: var(--bg-raised);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 280px; overflow-y: auto;
}
.search-results li {
  padding: 8px 10px; border-radius: 7px;
  font-size: 13px; color: var(--text);
  cursor: pointer;
}
.search-results li:hover,
.search-results li:focus-visible { background: rgba(13, 141, 219, 0.12); outline: none; }
.search-results .muted { color: var(--text-dim); cursor: default; }

/* Icon buttons (locate / theme) */
.icon-btn {
  flex: none;
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--stroke);
  background: var(--tile-mix);
  color: var(--text-dim);
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn.busy { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#theme-btn .icon-sun { display: none; }
:root[data-theme="dark"] #theme-btn .icon-sun { display: block; }
:root[data-theme="dark"] #theme-btn .icon-moon { display: none; }

/* Recent searches */
.hud-recent {
  top: 68px; left: 16px;
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 10px;
  max-width: min(620px, calc(100vw - 32px));
}
.hud-recent .chip {
  border: 1px solid var(--stroke);
  background: var(--tile-mix);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}
.hud-recent .chip:hover { color: var(--text); border-color: var(--accent); }

/* ------------------------------------------------------------- timeline */
.hud-timeline {
  left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  width: min(560px, calc(100vw - 32px));
}

.play-btn {
  flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--stroke);
  background: rgba(13, 141, 219, 0.12);
  color: var(--accent);
  display: grid; place-items: center;
  cursor: pointer;
}
.play-btn:hover { background: rgba(13, 141, 219, 0.22); }
.play-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.play-btn .icon-pause { display: none; }
.play-btn.playing .icon-pause { display: block; }
.play-btn.playing .icon-play { display: none; }

.timeline-body { flex: 1; position: relative; padding-top: 10px; }

.ticks {
  position: absolute; top: 0; left: 7px; right: 7px; height: 6px;
  display: flex; justify-content: space-between;
}
.ticks i {
  width: 3px; height: 6px; border-radius: 2px;
  background: rgba(92, 107, 122, 0.35);
}
.ticks i.loaded { background: var(--accent); }
.ticks i.forecast { background: rgba(230, 140, 20, 0.35); }
.ticks i.forecast.loaded { background: #e68c14; }
.ticks i.active { background: var(--text); box-shadow: 0 0 6px var(--accent); }
.ticks i.forecast.active { box-shadow: 0 0 6px #e68c14; }

#scrubber {
  width: 100%; margin: 0; appearance: none; background: transparent; cursor: pointer;
}
#scrubber::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: rgba(92, 107, 122, 0.3);
}
#scrubber::-webkit-slider-thumb {
  appearance: none; margin-top: -6px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-app);
}
#scrubber::-moz-range-track {
  height: 4px; border-radius: 2px; background: rgba(92, 107, 122, 0.3);
}
#scrubber::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-app);
}
#scrubber:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.time-readout {
  flex: none; text-align: right; min-width: 64px;
  font-family: var(--font-display);
}
.frame-badge {
  display: block;
  font: 700 9px/1 var(--font-body);
  letter-spacing: 0.09em;
  color: #b6650a;
  background: rgba(230, 140, 20, 0.14);
  border: 1px solid rgba(230, 140, 20, 0.4);
  border-radius: 5px;
  padding: 3px 5px;
  margin-bottom: 4px;
  white-space: nowrap;
}
:root[data-theme="dark"] .frame-badge { color: #ffb454; }
#frame-time { display: block; font-size: 20px; font-weight: 700; line-height: 1.05; }
.frame-date { font-size: 11px; color: var(--text-dim); }

/* ------------------------------------------------------------- status/legend */
.hud-status {
  left: 16px; bottom: 20px;
  padding: 8px 12px;
  font-size: 12px; color: var(--text-dim);
  max-width: 300px;
}
.hud-status.error { color: #d43d4f; }
:root[data-theme="dark"] .hud-status.error { color: #ff8f9c; }

.hud-legend {
  right: 16px; bottom: 20px;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  font-size: 11px; color: var(--text-dim);
}
.legend-bar {
  width: 110px; height: 8px; border-radius: 4px;
  background: linear-gradient(90deg,
    #3d7dd6, #40aae8, #48d6c2, #78e078, #ffde59, #ffa036, #ff5e3a, #ff2d55, #ee40ce);
}

/* ------------------------------------------------------------- forecast panel */
.panel {
  position: fixed; z-index: 950;
  top: 16px; right: 16px;
  width: min(320px, calc(100vw - 32px));
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  padding: 18px;
  background: var(--bg-panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.panel-close {
  position: absolute; top: 10px; right: 10px;
  width: 28px; height: 28px; border-radius: 8px;
  border: none; background: transparent;
  color: var(--text-dim); font-size: 18px; cursor: pointer;
}
.panel-close:hover { color: var(--text); background: var(--tile-mix); }

.panel h2 {
  margin: 0 24px 12px 0;
  font-family: var(--font-display);
  font-size: 17px; font-weight: 700; line-height: 1.25;
}
.panel h3 {
  margin: 18px 0 8px;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-dim);
}

.now { display: flex; align-items: center; gap: 12px; }
.now-symbol { font-size: 34px; line-height: 1; }
.now-main { display: flex; flex-direction: column; gap: 1px; }
.now-temp {
  font-family: var(--font-display);
  font-size: 40px; font-weight: 700; letter-spacing: -0.02em; line-height: 1;
}
.now-feels { font-size: 12px; color: var(--text-dim); }
.now-meta { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--text-dim); margin-left: auto; text-align: right; }

.now-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-top: 14px;
}
.stat {
  background: var(--tile-mix);
  border-radius: 8px;
  padding: 6px 9px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim);
}
.stat-value { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.sun-row {
  display: flex; justify-content: space-between;
  margin-top: 8px; padding: 8px 10px;
  background: var(--tile-mix);
  border-radius: 8px;
  font-size: 12px; color: var(--text-dim);
}
.sun-row span { display: flex; align-items: center; gap: 5px; }

.hours { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.hours li {
  display: grid;
  grid-template-columns: 44px 26px 44px 1fr;
  align-items: center; gap: 8px;
  padding: 5px 6px; border-radius: 8px;
  font-size: 13px;
}
.hours li:nth-child(odd) { background: var(--tile-mix); }
.hours .h-time { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.hours .h-temp { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.hours .h-precip {
  height: 8px; border-radius: 4px;
  background: rgba(92, 107, 122, 0.16);
  overflow: hidden;
}
.hours .h-precip > span {
  display: block; height: 100%;
  background: var(--accent);
  border-radius: 4px;
}
.panel-note { margin: 14px 0 0; font-size: 11px; color: var(--text-dim); }

.days { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.days li {
  display: grid;
  grid-template-columns: 64px 26px 62px 1fr;
  align-items: center; gap: 8px;
  padding: 6px; border-radius: 8px;
  font-size: 13px;
}
.days li:nth-child(odd) { background: var(--tile-mix); }
.days .d-name { color: var(--text-dim); }
.days .d-temp { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.days .d-temp em { font-style: normal; font-weight: 400; color: var(--text-dim); }
.days .d-rain { display: flex; align-items: baseline; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.days .d-mm {
  font-family: var(--font-display); font-weight: 700; font-size: 12px;
  color: var(--accent); white-space: nowrap;
}
.days .d-when { font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.days .d-dry { color: var(--text-dim); opacity: 0.7; }

/* small screens: stack the top bar, shrink readout */
@media (max-width: 560px) {
  .hud-top { right: 16px; flex-wrap: wrap; }
  .hud-recent { top: unset; bottom: 78px; left: 16px; right: 16px; max-width: none; }
  .panel { top: 74px; }
}
