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

:root {
  --bg: #010d1a;
  --surface: rgba(0,100,200,0.1);
  --surface2: rgba(0,120,220,0.16);
  --border: rgba(0,160,255,0.18);
  --text: #dff0ff;
  --muted: #5a9ec0;
  --accent: #00b4ff;
  --radius: 16px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html {
  min-height: 100%;
  background:
    radial-gradient(ellipse at 15% 50%, rgba(0,80,200,0.6) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 20%, rgba(0,180,220,0.4) 0%, transparent 45%),
    radial-gradient(ellipse at 50% 100%, rgba(0,40,120,0.55) 0%, transparent 45%),
    radial-gradient(ellipse at 70% 60%, rgba(0,100,180,0.3) 0%, transparent 40%),
    var(--bg);
  background-attachment: fixed;
}

body {
  min-height: 100dvh;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden; /* swipe viewport handles scrolling */
}

/* ── Screens ────────────────────────────────────────────────────────── */
#app { width: 100%; height: 100dvh; }
.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; flex-direction: column; }

#loading, #error {
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--muted);
  font-size: 0.95rem;
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-icon { font-size: 2.5rem; }
.error-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 8px; }
#retry-btn, #add-location-btn {
  padding: 10px 28px;
  border: none;
  border-radius: 999px;
  font-size: 0.95rem;
  cursor: pointer;
}
#retry-btn { background: var(--accent); color: #001828; font-weight: 600; }
#add-location-btn {
  background: rgba(0,100,200,0.14);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  color: var(--text);
}

/* ── Top bar ────────────────────────────────────────────────────────── */
/* top-bar is now inside each panel header — no fixed overlay needed */
.city-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}

.city-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  transition: background 0.25s, transform 0.25s;
  cursor: pointer;
}
.city-dot.active {
  background: #fff;
  transform: scale(1.3);
}
.city-dot.gps { background: var(--accent); opacity: 0.7; }
.city-dot.gps.active { background: var(--accent); opacity: 1; }

#add-btn {
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 1.3rem;
  line-height: 1;
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s;
  flex-shrink: 0;
}
#add-btn:active { background: rgba(255,255,255,0.22); }

/* ── Swipe viewport ─────────────────────────────────────────────────── */
#main { overflow: hidden; position: relative; }

#swipe-viewport {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

#swipe-track {
  display: flex;
  height: 100%;
  will-change: transform;
  transform: translateX(0);
  /* transition only applied when snapping, not during drag */
}
#swipe-track.snap {
  transition: transform 0.28s cubic-bezier(0.25,0.46,0.45,0.94);
}

/* ── City panel (one per location) ─────────────────────────────────── */
.city-panel {
  flex: 0 0 100vw;
  width: 100vw;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  padding-bottom: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.city-panel::-webkit-scrollbar { display: none; }

.city-panel > * {
  width: 100%;
  max-width: 480px;
}

/* ── Header inside panel ────────────────────────────────────────────── */
.panel-header {
  padding: env(safe-area-inset-top, 16px) 20px 12px;
  padding-top: max(env(safe-area-inset-top, 16px), 16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.panel-loc {
  font-size: 1.2rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-updated { font-size: 0.72rem; color: var(--muted); }

.panel-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Current conditions ─────────────────────────────────────────────── */
.current { padding: 8px 24px 24px; }

.current-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.temp-block { display: flex; align-items: flex-start; line-height: 1; }
.temp-val { font-size: 5.5rem; font-weight: 300; letter-spacing: -2px; }
.unit { font-size: 2rem; font-weight: 300; margin-top: 12px; color: var(--muted); }

.condition-block {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.wx-icon { font-size: 3rem; line-height: 1; }
.cond-label { font-size: 0.95rem; color: var(--muted); }
.feels { font-size: 0.85rem; color: var(--muted); }

.current-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.detail {
  background: rgba(0,100,200,0.12);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(0,160,255,0.2);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.detail .label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.detail .val { font-size: 1.05rem; font-weight: 500; }

/* ── Section blocks ─────────────────────────────────────────────────── */
.section-block { margin: 8px 24px 0; }
.section-block h2 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 12px;
}


/* ── Daily accordion ────────────────────────────────────────────────── */
.daily-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }

.day-wrapper {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(0,160,255,0.18);
  background: rgba(0,100,200,0.12);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.07);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.day-wrapper.open {
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(0,160,255,0.12);
}

.day-row {
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 72px 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.day-row:active { opacity: 0.7; }
.day-name { font-size: 0.9rem; font-weight: 500; }
.day-icon { font-size: 1.3rem; justify-self: center; }
.day-rain { font-size: 0.78rem; color: var(--accent); text-align: right; min-width: 28px; }
.day-temps { display: flex; gap: 8px; font-size: 0.9rem; }
.day-hi { font-weight: 600; }
.day-lo { color: var(--muted); }
.day-chevron { color: var(--muted); font-size: 1.1rem; transition: transform 0.2s; line-height: 1; }
.day-wrapper.open .day-chevron { transform: rotate(90deg); }

.day-detail { max-height: 0; overflow: hidden; transition: max-height 0.35s ease; }
.day-wrapper.open .day-detail { max-height: 340px; }

.day-hourly {
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: none;
}
.day-hourly::-webkit-scrollbar { display: none; }

.day-hour-row {
  display: grid;
  grid-template-columns: 44px 28px 42px 1fr 54px 36px;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  font-size: 0.85rem;
  border-bottom: 1px solid rgba(0,160,255,0.08);
  flex-shrink: 0;
}
.day-hour-row:last-child { border-bottom: none; }
.day-hour-row.current-hour { background: rgba(0,140,255,0.1); }
.day-hour-row.current-hour .dh-time { color: var(--accent); font-weight: 600; }
.dh-time { color: var(--muted); font-size: 0.78rem; }
.dh-icon { font-size: 1.1rem; }
.dh-temp { font-weight: 600; }
.dh-feels { color: var(--muted); font-size: 0.78rem; }
.dh-wind { color: var(--muted); font-size: 0.78rem; text-align: right; }
.dh-rain { color: var(--muted); font-size: 0.78rem; text-align: right; }
.dh-rain.has-rain { color: var(--accent); }

/* ── Footer ─────────────────────────────────────────────────────────── */
.panel-footer {
  margin-top: 32px;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
}
.panel-footer a { color: var(--muted); }

/* ── Delete city button (long-press dot hint) ───────────────────────── */
.delete-city-btn {
  display: block;
  margin: 20px auto 0;
  background: rgba(255,60,60,0.12);
  border: 1px solid rgba(255,60,60,0.25);
  border-radius: 999px;
  color: rgba(255,120,120,0.8);
  font-size: 0.8rem;
  padding: 8px 20px;
  cursor: pointer;
}

/* ── Bottom sheet (add location) ────────────────────────────────────── */
.sheet-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 20;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.sheet-overlay.open { display: block; }

.add-sheet {
  position: fixed;
  bottom: 0; left: 50%; transform: translateX(-50%) translateY(100%);
  width: 100%; max-width: 480px;
  background: rgba(1,18,40,0.92);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-top: 1px solid rgba(0,160,255,0.2);
  border-radius: 20px 20px 0 0;
  z-index: 21;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  padding-bottom: env(safe-area-inset-bottom, 16px);
}
.add-sheet.open { transform: translateX(-50%) translateY(0); }

.sheet-handle {
  width: 36px; height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 12px auto 0;
}

.sheet-inner { padding: 16px 20px 20px; }

.sheet-search-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

#loc-search {
  flex: 1;
  background: rgba(0,100,200,0.15);
  border: 1px solid rgba(0,160,255,0.25);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  caret-color: var(--accent);
}
#loc-search::placeholder { color: var(--muted); }
#loc-search:focus { border-color: var(--accent); }

#loc-close-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 50%;
  color: var(--muted);
  font-size: 0.9rem;
  width: 32px; height: 32px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loc-results { display: flex; flex-direction: column; gap: 2px; max-height: 55vh; overflow-y: auto; }

.loc-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.9rem;
  gap: 10px;
  border: 1px solid transparent;
  transition: background 0.15s;
}
.loc-result-item:hover, .loc-result-item:active { background: rgba(0,100,200,0.18); }

.loc-result-name { font-weight: 500; font-size: 0.95rem; }
.loc-result-sub { font-size: 0.78rem; color: var(--muted); margin-top: 1px; }

.loc-result-add {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #001828;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.loc-searching {
  padding: 20px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
