/* Apple Weather–inspired PWA — mobile-first */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --glass: rgba(255, 255, 255, 0.12);
  --glass-border: rgba(255, 255, 255, 0.18);
  --text: #fff;
  --text-secondary: rgba(255, 255, 255, 0.72);
  --text-tertiary: rgba(255, 255, 255, 0.45);
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Helvetica Neue", Helvetica, Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: #0a1628;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

/* —— Condition gradients —— */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  transition: background 0.8s ease;
}
.bg--clear-day {
  background: linear-gradient(180deg, #1a6bb5 0%, #4a9fe0 40%, #87ceeb 100%);
}
.bg--clear-night {
  background: linear-gradient(180deg, #0a1628 0%, #1a2a4a 45%, #2a3a5c 100%);
}
.bg--partly {
  background: linear-gradient(180deg, #3a7ab5 0%, #6a9bc4 50%, #8bb5d4 100%);
}
.bg--cloudy {
  background: linear-gradient(180deg, #4a5568 0%, #6b7a8d 50%, #8899aa 100%);
}
.bg--rain {
  background: linear-gradient(180deg, #2c3e50 0%, #3d5a73 40%, #4a6fa5 100%);
}
.bg--storm {
  background: linear-gradient(180deg, #1a1a2e 0%, #2d2d44 40%, #3d3d5c 100%);
}
.bg--snow {
  background: linear-gradient(180deg, #5a7a9a 0%, #8aa8c4 50%, #b8d0e0 100%);
}
.bg--fog {
  background: linear-gradient(180deg, #6a7585 0%, #8a95a5 50%, #a8b0bc 100%);
}
.bg--hot {
  background: linear-gradient(180deg, #c45c26 0%, #e08a3c 40%, #f0b060 100%);
}

/* —— Top bar —— */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 8px;
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(0, 0, 0, 0.08);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--glass);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.icon-btn:active { opacity: 0.7; transform: scale(0.94); }
.icon-btn.spinning svg { animation: spin 0.8s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

.location-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  cursor: pointer;
  max-width: 60vw;
}
.location-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* —— Main —— */
.main {
  padding: 0 16px calc(28px + var(--safe-bottom));
  max-width: 480px;
  margin: 0 auto;
}

.hero {
  text-align: center;
  padding: 8px 0 20px;
}
.condition {
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.3px;
  opacity: 0.95;
}
.temp {
  font-size: 96px;
  font-weight: 200;
  letter-spacing: -4px;
  line-height: 1;
  margin: 4px 0;
}
.hi-lo {
  font-size: 18px;
  font-weight: 500;
  opacity: 0.9;
}
.consensus {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  min-height: 1.2em;
}

/* —— Cards —— */
.card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  margin-bottom: 12px;
  overflow: hidden;
}
.card-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  padding: 14px 16px 8px;
}

/* Hourly */
.hourly {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 8px 12px 16px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.hourly::-webkit-scrollbar { display: none; }
.hour {
  flex: 0 0 58px;
  text-align: center;
  scroll-snap-align: start;
  padding: 4px 0;
}
.hour-time {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.hour-icon {
  font-size: 24px;
  line-height: 1;
  margin-bottom: 8px;
  height: 28px;
}
.hour-temp {
  font-size: 17px;
  font-weight: 500;
}
.hour-precip {
  font-size: 11px;
  color: #7ec8ff;
  font-weight: 600;
  margin-top: 4px;
  min-height: 14px;
}

/* Daily */
.daily { padding: 0 16px 8px; }
.day-row {
  display: grid;
  grid-template-columns: 52px 36px 1fr 44px 44px;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 16px;
  font-weight: 500;
}
.day-row:first-child { border-top: none; }
.day-name { font-weight: 600; }
.day-icon { font-size: 22px; text-align: center; }
.day-bar-wrap {
  display: flex;
  align-items: center;
  gap: 0;
  height: 4px;
  position: relative;
}
.day-bar-track {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
}
.day-bar-fill {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, #5ac8fa, #ffd60a, #ff9f0a);
}
.day-lo { text-align: right; color: var(--text-secondary); }
.day-hi { text-align: right; }

/* Details grid */
.details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.tile {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: 14px 16px 16px;
  min-height: 110px;
}
.tile-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.tile-value {
  font-size: 28px;
  font-weight: 400;
  letter-spacing: -0.5px;
  line-height: 1.15;
}
.tile-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* Sources */
.sources {
  padding: 0 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.source-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}
.source-name { font-weight: 500; }
.source-temp { color: var(--text-secondary); }
.source-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  margin-left: 8px;
}
.source-badge.ok { background: rgba(48, 209, 88, 0.25); color: #30d158; }
.source-badge.err { background: rgba(255, 69, 58, 0.25); color: #ff6961; }
.source-badge.skip { background: rgba(255, 255, 255, 0.1); color: var(--text-tertiary); }

/* Alerts */
.alerts { padding: 0 16px 14px; }
.alert-item {
  background: rgba(255, 159, 10, 0.2);
  border: 1px solid rgba(255, 159, 10, 0.4);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
}
.alert-item:last-child { margin-bottom: 0; }
.alert-event {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}
.alert-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.updated {
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
  padding: 8px 0 16px;
}

.hidden { display: none !important; }

/* —— Search sheet —— */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 85dvh;
  background: #1c1c1e;
  border-radius: 16px 16px 0 0;
  padding: 8px 16px calc(20px + var(--safe-bottom));
  overflow-y: auto;
  animation: slideUp 0.28s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.sheet-handle {
  width: 36px; height: 5px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 3px;
  margin: 4px auto 12px;
}
.sheet-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
}
.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #2c2c2e;
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.search-icon { color: var(--text-tertiary); flex-shrink: 0; }
#search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  outline: none;
}
#search-input::placeholder { color: var(--text-tertiary); }
.text-btn {
  border: none;
  background: transparent;
  color: #0a84ff;
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  white-space: nowrap;
}
.search-results {
  list-style: none;
}
.search-results li,
.list-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 4px;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
}
.search-results li:active,
.list-btn:active { opacity: 0.7; }
.search-results .sub {
  display: block;
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* Loading / toast */
.loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(10, 22, 40, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 15px;
  color: var(--text-secondary);
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 200;
  background: rgba(40, 40, 42, 0.95);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

@media (min-width: 480px) {
  .temp { font-size: 110px; }
  .details { grid-template-columns: 1fr 1fr; }
}

/* —— Multi-city pager —— */
.top-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 55vw;
}
.location-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.page-dots {
  display: flex;
  gap: 6px;
  align-items: center;
  min-height: 8px;
}
.page-dots .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transition: background 0.2s, transform 0.2s;
}
.page-dots .dot.active {
  background: #fff;
  transform: scale(1.15);
}
.page-dots .dot.loc {
  width: 7px;
  height: 7px;
  background: transparent;
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  box-sizing: border-box;
}
.page-dots .dot.loc.active {
  background: #fff;
  border-color: #fff;
}

.pager {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  height: calc(100dvh - 64px - var(--safe-top));
  outline: none;
}
.pager::-webkit-scrollbar { display: none; }

.city-page {
  flex: 0 0 100%;
  width: 100%;
  max-width: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(28px + var(--safe-bottom));
  max-width: 480px;
  /* center content on wide screens while keeping full-width swipe */
  margin: 0 auto;
  box-sizing: border-box;
}

/* On narrow mobile, each page is full viewport width */
@supports (width: 100vw) {
  .city-page {
    flex: 0 0 100vw;
    width: 100vw;
    max-width: 100vw;
    padding-left: max(16px, calc((100vw - 480px) / 2 + 16px));
    padding-right: max(16px, calc((100vw - 480px) / 2 + 16px));
  }
}

.sheet-panel--full {
  max-height: 92dvh;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.city-list {
  list-style: none;
  margin: 8px 0 16px;
}
.city-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.city-item:active { cursor: grabbing; }
.city-item.dragging {
  opacity: 0.55;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
}
.city-item-main {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}
.city-item-name {
  font-size: 17px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.city-item-meta {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 2px;
}
.city-item-temp {
  font-size: 28px;
  font-weight: 300;
  letter-spacing: -1px;
  min-width: 52px;
  text-align: right;
}
.city-item-actions {
  display: flex;
  gap: 4px;
}
.btn-remove {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 69, 58, 0.2);
  color: #ff6961;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.btn-remove:active { opacity: 0.7; }
.drag-handle {
  color: var(--text-tertiary);
  padding: 4px;
  cursor: grab;
  font-size: 16px;
  letter-spacing: -2px;
}
.list-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: center;
  margin-bottom: 12px;
  line-height: 1.4;
}
.primary-btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 14px;
  background: #0a84ff;
  color: #fff;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  padding: 14px;
  cursor: pointer;
}
.primary-btn:active { opacity: 0.85; }
.list-btn--accent {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #0a84ff;
  font-weight: 500;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 4px;
}
.city-page .main-inner {
  max-width: 448px;
  margin: 0 auto;
}

/* —— Radar (precipitation map) —— */
:root {
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
.radar-card {
  display: block;
  margin-bottom: 12px;
  padding: 14px 16px 14px;
  min-height: 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.radar-card:active { transform: scale(0.99); }
.radar-card:focus-visible { outline: 2px solid #0a84ff; outline-offset: 2px; }
.radar-head { margin-bottom: 10px; }
.radar-time {
  margin-left: auto;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.radar-map-wrap {
  position: relative;
  height: 190px;
  border-radius: 12px;
  overflow: hidden;
  background: #0e1116;
  /* keep horizontal swipes for the city pager */
  touch-action: pan-x pan-y;
}
.radar-map {
  position: absolute;
  inset: 0;
  background: #0e1116;
}
/* Static preview: the map never receives pointer events, so swipes reach the pager */
.radar-map,
.radar-map * {
  pointer-events: none !important;
  touch-action: pan-x pan-y !important;
}
.radar-map .leaflet-control-attribution {
  font-size: 8px;
  line-height: 1.3;
  padding: 0 4px;
  background: rgba(0, 0, 0, 0.45) !important;
  color: rgba(255, 255, 255, 0.55);
}
.radar-map .leaflet-control-attribution a { color: rgba(255, 255, 255, 0.7); }
.radar-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  color: var(--text-secondary);
  z-index: 500;
  pointer-events: none;
}
.radar-play {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 600;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.radar-play:active { opacity: 0.7; }
.radar-expand {
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 600;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.radar-progress {
  height: 3px;
  margin-top: 10px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}
.radar-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: #5ac8fa;
  border-radius: 2px;
  transition: width 0.25s linear;
}

/* Fullscreen radar */
body.radar-open { overflow: hidden; }
.radar-full {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: #0e1116;
  animation: radarIn 0.22s ease;
}
@keyframes radarIn { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: none; } }
.radar-full-map {
  position: absolute;
  inset: 0;
  background: #0e1116;
}
.radar-full-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) calc(16px + var(--safe-right)) 16px calc(12px + var(--safe-left));
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0));
  pointer-events: none;
}
.radar-close {
  pointer-events: auto;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  background: rgba(30, 30, 32, 0.85);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.radar-close:active { opacity: 0.7; transform: scale(0.94); }
.radar-full-title { min-width: 0; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6); }
.radar-full-name {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.radar-full-sub { font-size: 12px; color: var(--text-secondary); margin-top: 1px; }
.radar-full .leaflet-top { top: calc(64px + var(--safe-top)); }
.radar-full .leaflet-right { right: var(--safe-right); }
.radar-full .leaflet-bar a {
  background: rgba(30, 30, 32, 0.9);
  color: #fff;
  border-bottom-color: rgba(255, 255, 255, 0.15);
  width: 36px; height: 36px; line-height: 36px;
}
.radar-full .leaflet-bar { border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 10px; overflow: hidden; }
.radar-full .leaflet-bottom { bottom: calc(84px + var(--safe-bottom)); }
.radar-full .leaflet-control-attribution {
  background: rgba(0, 0, 0, 0.5) !important;
  color: rgba(255, 255, 255, 0.6);
  font-size: 10px;
}
.radar-full .leaflet-control-attribution a { color: rgba(255, 255, 255, 0.8); }
.radar-full-bottom {
  position: absolute;
  left: calc(12px + var(--safe-left));
  right: calc(12px + var(--safe-right));
  bottom: calc(12px + var(--safe-bottom));
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(30, 30, 32, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.radar-full-play,
.radar-full-recenter {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.radar-full-play:active,
.radar-full-recenter:active { opacity: 0.7; }
.radar-full-timeline { flex: 1; min-width: 0; }
.radar-full-time {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}
#radar-full-range {
  width: 100%;
  accent-color: #5ac8fa;
  touch-action: pan-x;
}
.radar-full-status {
  position: absolute;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  font-size: 15px;
  pointer-events: none;
}
.leaflet-container { font-family: var(--font); }
