:root {
  color-scheme: light dark;
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #1a2330;
  --muted: #667085;
  --accent: #2563eb;
  --high: #1a8f4c;
  --medium: #b8860b;
  --low: #c0392b;
  --border: #e3e8ef;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --card: #171e2c;
    --text: #eaf0fb;
    --muted: #93a0b4;
    --border: #2a3346;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  padding: env(safe-area-inset-top, 16px) 20px 8px;
  text-align: center;
}
.topbar h1 { font-size: 1.3rem; margin: 8px 0; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

.location-bar { position: relative; }

.location-chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  font-size: 0.9rem;
}
.chip.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip .remove { color: var(--muted); font-weight: 700; padding-left: 2px; }
.chip .remove:hover { color: var(--low); }

.search-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.search-form input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.95rem;
}
.search-form button {
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
}
.search-form button:disabled { opacity: 0.6; }

.search-status {
  margin: 8px 2px 0;
  color: var(--medium);
}

.search-results {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  position: absolute;
  z-index: 5;
  width: 100%;
}
.search-results li {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-results li:last-child { border-bottom: none; }
.search-results li:hover { background: var(--bg); }

.forecast-card, .alert-settings, .radar-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
}

.forecast-headline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.location-name-row { display: flex; align-items: center; gap: 8px; }
.location-name { font-weight: 700; font-size: 1.05rem; }

.refresh-button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  border-radius: 6px;
}
.refresh-button:hover { background: var(--border); }
.refresh-button:disabled { opacity: 0.5; cursor: default; background: none; }
.refresh-button.spinning { animation: refresh-spin 0.8s linear infinite; }
@keyframes refresh-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

#autoRefreshNote { margin-bottom: 10px; }

.confidence-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.confidence-caption {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.confidence-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
}
.confidence-badge.High { background: rgba(26,143,76,0.15); color: var(--high); }
.confidence-badge.Medium { background: rgba(184,134,11,0.15); color: var(--medium); }
.confidence-badge.Low { background: rgba(192,57,43,0.15); color: var(--low); }

.rain-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.rain-status.is-raining { background: rgba(37,99,235,0.15); color: var(--accent); }
.rain-status.not-raining { background: rgba(26,143,76,0.12); color: var(--high); }

.probability-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 8px 0 12px;
}
.probability-number { font-size: 3rem; font-weight: 800; line-height: 1; }
.probability-sub #intensityLabel { font-weight: 600; text-transform: capitalize; }

.next-rain-row {
  display: flex;
  gap: 32px;
  margin-bottom: 4px;
}
.next-rain-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.next-rain-value { font-size: 1.15rem; font-weight: 700; }
.next-rain-caption { font-size: 0.75rem; color: var(--muted); }

.next-rain-strength-value { display: flex; align-items: center; gap: 5px; }
.next-rain-strength-icon { font-size: 1.15rem; line-height: 1; }
#nextRainStrengthLabel { text-transform: capitalize; }

#nextRainNote { margin-bottom: 12px; }

.wind-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.wind-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 64px;
}
.wind-value {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.wind-value .unit {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
}
.wind-caption {
  font-size: 0.75rem;
  color: var(--muted);
}

.wind-trend-arrow {
  display: inline-block;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
}
/* Colour reflects the SIZE of the change through the day, not its direction —
   a small nudge either way reads green, a big swing reads red, so the colour
   and the arrow/label together answer "how much" and "which way". */
.wind-trend-arrow.tier-green { color: var(--high); }
.wind-trend-arrow.tier-amber { color: var(--medium); }
.wind-trend-arrow.tier-red { color: var(--low); }
.wind-trend-arrow.tier-unknown { color: var(--muted); }

#windTrendLabel.tier-green { color: var(--high); }
#windTrendLabel.tier-amber { color: var(--medium); }
#windTrendLabel.tier-red { color: var(--low); }
#windTrendLabel.tier-unknown { color: var(--muted); }

.wind-direction-value { align-items: center; }
.wind-direction-arrow {
  display: inline-block;
  font-size: 1.1rem;
  line-height: 1;
  transition: transform 0.2s;
}
#windDirectionLabel { font-size: 0.95rem; }

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  padding: 0;
  cursor: pointer;
}

.sources-detail { margin-top: 12px; }
.sources-detail table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.sources-detail th, .sources-detail td {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}
.sources-detail tr.unavailable td { color: var(--muted); font-style: italic; }

.alert-settings h2, .radar-section h2 {
  font-size: 1rem;
  margin: 0 0 12px;
}
.alert-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.alert-settings-header h2 { margin: 0; }

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex: 0 0 auto;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background-color: var(--border);
  border-radius: 999px;
  transition: background-color 0.15s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.15s;
}
.toggle-switch input:checked + .toggle-slider { background-color: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

#alertControlsBody.alerts-disabled { opacity: 0.45; pointer-events: none; }

.lead-time-presets { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.lead-time-presets button {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}
.lead-time-presets button.active { background: var(--accent); border-color: var(--accent); color: white; }

.custom-lead {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.custom-lead input {
  width: 70px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

#radarMap {
  height: 280px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.radar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.radar-controls input[type="range"] { flex: 1; }
.radar-controls button {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.build-info {
  text-align: center;
  padding: 4px 16px 24px;
  opacity: 0.6;
}
