/* ---------- Base ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #fff;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(180deg, #1c2b45 0%, #0d1b2e 100%);
  background-attachment: fixed;
  overscroll-behavior-y: none;
}
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input { font: inherit; }

/* Condition themes: [data-wx] on body */
body[data-wx="clear-day"]     { background: linear-gradient(180deg, #2f74c0 0%, #5a9fd8 55%, #8ec3e6 100%); }
body[data-wx="clear-night"]   { background: linear-gradient(180deg, #0b1026 0%, #1b2a4a 70%, #2c3e5f 100%); }
body[data-wx="partly-day"]    { background: linear-gradient(180deg, #3a7ab8 0%, #6ba3cf 60%, #9dc4de 100%); }
body[data-wx="partly-night"]  { background: linear-gradient(180deg, #101a33 0%, #24344f 70%, #35455e 100%); }
body[data-wx="cloudy-day"]    { background: linear-gradient(180deg, #54728c 0%, #7a94a8 60%, #9fb2c0 100%); }
body[data-wx="cloudy-night"]  { background: linear-gradient(180deg, #171f2b 0%, #2b3542 70%, #3a4552 100%); }
body[data-wx="rain-day"]      { background: linear-gradient(180deg, #3c5670 0%, #56718b 60%, #7189a0 100%); }
body[data-wx="rain-night"]    { background: linear-gradient(180deg, #10182300 0%, #1c2836 70%, #2a3847 100%), #101823; }
body[data-wx="snow-day"]      { background: linear-gradient(180deg, #6e8aa5 0%, #93aabf 60%, #b8c8d6 100%); }
body[data-wx="snow-night"]    { background: linear-gradient(180deg, #1a2330 0%, #303c4c 70%, #445263 100%); }
body[data-wx="fog"]           { background: linear-gradient(180deg, #5d6b78 0%, #7d8a95 60%, #9aa5ae 100%); }
body[data-wx="storm"]         { background: linear-gradient(180deg, #191927 0%, #2c2b40 60%, #403e55 100%); }

#app {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 14px calc(28px + env(safe-area-inset-bottom));
}

/* ---------- Pull to refresh ---------- */
.ptr {
  position: fixed;
  top: calc(env(safe-area-inset-top) - 46px);
  left: 50%;
  z-index: 900;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.94);
  color: #16273c;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  transform: translateX(-50%);
  will-change: transform;
}
.ptr.settling { transition: transform .2s; }
.ptr.refreshing svg { animation: spin .7s linear infinite; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-bottom: 4px;
  position: sticky;
  top: 0;
  z-index: 500;
}
.city-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  padding: 4px 0;
}
.city-tabs::-webkit-scrollbar { display: none; }
.city-tab {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .15s;
}
.city-tab[aria-current="true"] { background: rgba(255,255,255,0.92); color: #16273c; }
.city-tab svg { flex: 0 0 auto; }
.icon-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: rgba(255,255,255,0.28); }

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 26px 0 30px; }
.hero-place {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: .2px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.hero-save {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.hero-save[hidden] { display: none; }
.hero-temp { font-size: 88px; font-weight: 200; line-height: 1.05; margin: 2px 0; letter-spacing: -2px; }
.hero-cond { font-size: 17px; font-weight: 500; opacity: .95; }
.hero-range { font-size: 15px; opacity: .85; margin-top: 3px; }
.hero-updated { font-size: 12px; opacity: .55; margin-top: 8px; }

.hero-nowcast {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  margin-top: 10px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(60, 110, 180, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.hero-nowcast[hidden] { display: none; }

/* ---------- Alerts ---------- */
.alert {
  border-radius: 14px;
  margin-bottom: 12px;
  overflow: hidden;
  background: rgba(120, 60, 30, 0.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.15);
}
.alert.sev-extreme, .alert.sev-severe { background: rgba(150, 35, 35, 0.60); }
.alert.sev-minor { background: rgba(130, 100, 20, 0.55); }
.alert summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 600;
}
.alert summary::-webkit-details-marker { display: none; }
.alert .alert-when { font-weight: 400; opacity: .8; font-size: 12px; margin-left: auto; white-space: nowrap; }
.alert .alert-body {
  padding: 0 14px 12px;
  font-size: 13px;
  line-height: 1.5;
  opacity: .92;
  white-space: pre-line;
  max-height: 300px;
  overflow-y: auto;
}
.alert .alert-src { font-size: 11px; opacity: .6; padding: 0 14px 10px; }

/* ---------- Cards ---------- */
.card {
  background: rgba(20, 30, 46, 0.32);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  opacity: .65;
  margin-bottom: 10px;
}

/* ---------- Hourly strip ---------- */
.hourly-strip {
  display: flex;
  overflow-x: auto;
  gap: 2px;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.hourly-strip::-webkit-scrollbar { display: none; }
.hour-cell {
  flex: 0 0 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 0 4px;
  border-radius: 12px;
}
.hour-cell.now { background: rgba(255,255,255,0.10); }
.hour-time { font-size: 12px; font-weight: 500; opacity: .8; }
.hour-icon { width: 28px; height: 28px; }
.hour-icon svg { width: 100%; height: 100%; display: block; }
.hour-pop { font-size: 11px; font-weight: 600; color: #9ec5f4; min-height: 14px; }
.hour-temp { font-size: 15px; font-weight: 600; }
.hour-cell.sun-event .hour-time { opacity: .9; }
.hour-cell.sun-event .hour-temp { font-size: 12px; font-weight: 500; opacity: .85; }
.hour-sep {
  flex: 0 0 auto;
  align-self: stretch;
  display: flex;
  align-items: center;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  opacity: .45;
  writing-mode: vertical-rl;
  text-transform: uppercase;
}

/* ---------- Daily list ---------- */
.daily-row {
  display: grid;
  grid-template-columns: 52px 30px 34px 1fr 34px;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.daily-row:first-child { border-top: none; }
.day-name { font-size: 15px; font-weight: 500; }
.day-icon { width: 26px; height: 26px; }
.day-icon svg { width: 100%; height: 100%; display: block; }
.day-icon .day-pop { display: block; font-size: 10px; font-weight: 600; color: #9ec5f4; text-align: center; }
.day-lo, .day-hi { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.day-lo { opacity: .65; }
.range-track {
  position: relative;
  height: 4px;
  border-radius: 4px;
  background: rgba(255,255,255,0.16);
}
.range-fill {
  position: absolute;
  top: 0; bottom: 0;
  border-radius: 4px;
  min-width: 4px;
}
.range-now {
  position: absolute;
  top: 50%;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(13,27,46,0.55);
  transform: translate(-50%, -50%);
}

/* ---------- Radar ---------- */
.card-radar { padding: 14px 16px 12px; }
.radar-title-row { display: flex; justify-content: space-between; align-items: baseline; }
.radar-time { font-size: 12px; font-weight: 600; letter-spacing: 0; text-transform: none; opacity: .8; }
.radar-wrap { position: relative; border-radius: 12px; overflow: hidden; }
#radarMap { height: 340px; background: #263238; z-index: 0; }
.radar-controls {
  position: absolute;
  left: 10px; right: 10px; bottom: 10px;
  z-index: 400;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(15, 23, 36, 0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 12px;
  padding: 6px 12px 6px 6px;
}
.radar-play { width: 34px; height: 34px; background: rgba(255,255,255,0.16); }
#radarScrub {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 4px;
  background: rgba(255,255,255,0.25);
  outline: none;
}
#radarScrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}
#radarScrub::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  border: none;
  cursor: pointer;
}
.leaflet-container { font: inherit; }
.leaflet-control-attribution {
  background: rgba(15,23,36,0.6) !important;
  color: rgba(255,255,255,0.6) !important;
  font-size: 9px !important;
}
.leaflet-control-attribution a { color: rgba(255,255,255,0.8) !important; }
.leaflet-bar a {
  background: rgba(15,23,36,0.78) !important;
  color: #fff !important;
  border-color: rgba(255,255,255,0.15) !important;
}

/* ---------- Details grid ---------- */
.details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.detail-card {
  background: rgba(20, 30, 46, 0.32);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px;
  padding: 12px 14px;
  min-height: 92px;
}
.detail-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  opacity: .6;
  display: flex;
  align-items: center;
  gap: 5px;
}
.detail-value { font-size: 26px; font-weight: 500; margin-top: 8px; }
.detail-sub { font-size: 12px; opacity: .7; margin-top: 3px; }
.meter {
  position: relative;
  height: 4px;
  border-radius: 4px;
  background: rgba(255,255,255,0.16);
  margin-top: 10px;
}
.meter-fill { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 4px; background: #86b6ef; }

/* ---------- Empty state / loading / error ---------- */
.empty-state { text-align: center; padding: 18vh 20px 0; }
.empty-art { font-size: 64px; }
.empty-state h1 { font-size: 26px; margin: 14px 0 6px; }
.empty-state p { opacity: .75; margin-bottom: 26px; }
.empty-actions { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 22px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
  font-weight: 600;
  font-size: 15px;
}
.btn-primary { background: rgba(255,255,255,0.92); color: #16273c; }
.loading { display: flex; justify-content: center; padding: 60px 0; }
.loading[hidden], .overlay[hidden], .empty-state[hidden] { display: none; }
.spinner {
  width: 30px; height: 30px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-banner {
  background: rgba(208, 59, 59, 0.85);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  margin: 10px 0;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.error-banner[hidden] { display: none; }
.error-banner .retry {
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(255,255,255,0.9);
  color: #7a1d1d;
  font-weight: 700;
  font-size: 13px;
}

.update-toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 2000;
  background: rgba(255,255,255,0.95);
  color: #16273c;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
  white-space: nowrap;
}
.update-toast[hidden] { display: none; }

.credits {
  text-align: center;
  font-size: 11px;
  opacity: .5;
  padding: 8px 0 4px;
}

/* ---------- Manage overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(8, 14, 24, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.overlay-panel {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - env(safe-area-inset-top));
  overflow-y: auto;
  margin-top: env(safe-area-inset-top);
  background: linear-gradient(180deg, #1a2739 0%, #131e2e 100%);
  border-radius: 0 0 22px 22px;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 600px) {
  .overlay { align-items: center; padding: 20px; }
  .overlay-panel { border-radius: 22px; margin-top: 0; max-height: 82dvh; }
}
.overlay-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.overlay-head h2 { font-size: 20px; }
.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.10);
  border-radius: 12px;
  padding: 0 12px;
}
.search-ico { opacity: .6; flex: 0 0 auto; }
#citySearch {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: #fff;
  padding: 12px 0;
  font-size: 16px;
}
#citySearch::placeholder { color: rgba(255,255,255,0.45); }
.search-results { margin-top: 6px; }
.search-result {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 15px;
}
.search-result:hover, .search-result:focus { background: rgba(255,255,255,0.10); }
.search-result .sub { display: block; font-size: 12px; opacity: .6; margin-top: 1px; }
.search-note { padding: 12px; font-size: 13px; opacity: .6; }
.saved-head-row { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 6px; }
.overlay-subtitle {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  opacity: .6;
}
.unit-toggle {
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
}
.saved-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px 10px 6px;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  margin-bottom: 6px;
  position: relative;
}
.saved-row:not(.dragging) { transition: transform .15s; }
.saved-row.dragging {
  opacity: .92;
  background: rgba(255,255,255,0.16);
  z-index: 10;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}
.saved-row .grip {
  width: 34px; height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: .5;
  cursor: grab;
  touch-action: none;
  flex: 0 0 auto;
}
.saved-row .name { flex: 1; font-size: 15px; font-weight: 500; }
.saved-row .name .sub { display: block; font-size: 12px; opacity: .55; font-weight: 400; }
.saved-row .del {
  width: 36px; height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: .65;
}
.saved-row .del:hover { opacity: 1; background: rgba(208,59,59,0.25); }
.geo-row { width: 100%; justify-content: center; margin-top: 12px; font-size: 14px; }
