:root {
  --bg: #0b1622;
  --ink: #f2f7fb;
  --muted: rgba(226, 238, 248, 0.62);
  --faint: rgba(226, 238, 248, 0.4);
  --glass-bg: rgba(18, 32, 47, 0.55);
  --glass-brd: rgba(255, 255, 255, 0.12);
  --accent: #36c6e0;
  --accent-2: #2f7bff;
  --pin: #2bb6cf;
  --good: #34d27b;
  --mod: #f1c40f;
  --unhealthy: #e67e22;
  --bad: #e74c3c;
  --hazard: #9b59b6;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --sheet-h: 152px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: #05080d;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); overflow: hidden;
}
body {
  background:
    radial-gradient(1200px 800px at 50% -10%, #14304a 0%, #070d15 55%, #05080d 100%);
}
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }

#app {
  position: relative;
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  backdrop-filter: blur(22px) saturate(140%);
  border: 1px solid var(--glass-brd);
}

/* ---------- Map ---------- */
#map { position: absolute; inset: 0; z-index: 0; background: #0b1622; }
.leaflet-container { background: #0b1622; font-family: inherit; }
.leaflet-control-attribution {
  background: rgba(0,0,0,.35) !important; color: rgba(255,255,255,.5) !important;
  font-size: 9px !important; backdrop-filter: blur(4px);
}
.leaflet-control-attribution a { color: rgba(255,255,255,.7) !important; }
.leaflet-tile { filter: saturate(1.05) brightness(1.02); }

/* Temperature / value pins */
.wx-pin {
  position: relative; display: flex; align-items: center; justify-content: center;
  min-width: 40px; height: 30px; padding: 0 9px;
  background: linear-gradient(180deg, #34c3da, #1f97b5);
  color: #fff; font-weight: 700; font-size: 13px; letter-spacing: -.2px;
  border-radius: 16px; box-shadow: 0 4px 12px rgba(0,0,0,.4);
  border: 1.5px solid rgba(255,255,255,.5);
  transform: translateY(-6px);
}
.wx-pin::after {
  content: ""; position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%) rotate(45deg);
  width: 11px; height: 11px; background: #1f97b5; border-right: 1.5px solid rgba(255,255,255,.5);
  border-bottom: 1.5px solid rgba(255,255,255,.5); border-bottom-right-radius: 3px;
}
.wx-pin.rain { background: linear-gradient(180deg, #4f9bff, #2f6fe0); }
.wx-pin.rain::after { background: #2f6fe0; }
.wx-pin.wind { background: linear-gradient(180deg, #7bd0a8, #3fa776); }
.wx-pin.wind::after { background: #3fa776; }
.wx-pin.humidity { background: linear-gradient(180deg, #8ea6ff, #5a6fe0); }
.wx-pin.humidity::after { background: #5a6fe0; }
.wx-pin .u { font-size: 9px; opacity: .85; margin-left: 1px; font-weight: 600; }

/* Selected-location blue dot */
.me-dot { width: 20px; height: 20px; }
.me-dot i {
  display: block; width: 16px; height: 16px; margin: 2px; border-radius: 50%;
  background: #2f7bff; border: 2.5px solid #fff; box-shadow: 0 0 0 2px rgba(47,123,255,.4), 0 2px 8px rgba(0,0,0,.5);
}
.me-dot i::before {
  content: ""; position: absolute; left: -10px; top: -10px; width: 40px; height: 40px;
  border-radius: 50%; background: radial-gradient(circle, rgba(47,123,255,.45), rgba(47,123,255,0) 70%);
}

/* ---------- Top card ---------- */
.top-card {
  position: absolute; top: 14px; left: 14px; z-index: 1000;
  display: flex; align-items: center; gap: 12px; max-width: 270px;
  padding: 12px 16px; border-radius: 22px; text-align: left; color: var(--ink);
  box-shadow: var(--shadow);
}
.tc-icon { flex: 0 0 auto; width: 38px; height: 38px; display: grid; place-items: center; }
.tc-icon svg { width: 38px; height: 38px; }
.tc-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.tc-loc { display: inline-flex; align-items: center; gap: 6px; font-size: 17px; font-weight: 700; }
.tc-chev { width: 12px; height: 8px; opacity: .8; }
.tc-forecast { font-size: 14px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tc-period { font-size: 12px; color: var(--muted); }

/* ---------- Right layer controls ---------- */
.layer-controls {
  position: absolute; top: 14px; right: 14px; z-index: 1000;
  display: flex; flex-direction: column; padding: 6px; gap: 4px;
  border-radius: 26px; box-shadow: var(--shadow);
}
.layer-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  color: var(--ink); transition: background .18s, color .18s, transform .1s;
}
.layer-btn svg { width: 23px; height: 23px; }
.layer-btn:active { transform: scale(.92); }
.layer-btn.is-active { background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 4px 14px rgba(47,123,255,.5); }

/* ---------- Bottom-right map buttons ---------- */
.map-buttons {
  position: absolute; right: 14px; z-index: 1000; bottom: calc(var(--sheet-h) + 92px);
  display: flex; flex-direction: column; gap: 12px;
}
.map-btn {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  color: var(--ink); box-shadow: var(--shadow); transition: transform .1s;
}
.map-btn svg { width: 24px; height: 24px; }
.map-btn:active { transform: scale(.92); }
.map-btn.accent { color: var(--accent); }

/* ---------- Timeline ---------- */
.timeline {
  position: absolute; left: 14px; right: 14px; z-index: 1000;
  bottom: calc(var(--sheet-h) + 16px);
  display: flex; align-items: center; gap: 12px; padding: 10px 14px 10px 10px;
  border-radius: 22px; box-shadow: var(--shadow);
}
.play-btn {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 50%;
  background: rgba(255,255,255,.1); display: grid; place-items: center; color: #fff;
  transition: transform .1s, background .15s;
}
.play-btn:active { transform: scale(.92); }
.play-btn svg { width: 22px; height: 22px; grid-area: 1 / 1; }
.tl-track { position: relative; flex: 1; height: 56px; min-width: 0; }
.tl-2h {
  position: absolute; left: 4px; top: 50%; transform: translateY(-50%); z-index: 3;
  font-size: 12px; font-weight: 700; color: var(--ink);
  background: rgba(255,255,255,.14); padding: 4px 10px; border-radius: 20px;
}
#trendCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.tl-handle {
  position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,.9);
  left: 78%; cursor: grab; z-index: 4;
}
.tl-handle::before {
  content: ""; position: absolute; bottom: -3px; left: 50%; transform: translateX(-50%);
  width: 12px; height: 12px; border-radius: 50%; background: #fff; box-shadow: 0 0 8px rgba(255,255,255,.6);
}
.tl-readout {
  position: absolute; top: -30px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  background: rgba(20,34,50,.92); border: 1px solid var(--glass-brd);
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 20px;
}

/* ---------- Bottom sheet ---------- */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1100;
  min-height: var(--sheet-h); padding: 8px 16px calc(14px + env(safe-area-inset-bottom));
  border-radius: 26px 26px 0 0; border-bottom: none;
  box-shadow: 0 -10px 40px rgba(0,0,0,.5);
}
.grabber { width: 38px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.3); margin: 4px auto 10px; }

.main-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mc-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mc-icon { flex: 0 0 auto; width: 52px; height: 52px; }
.mc-icon svg { width: 52px; height: 52px; }
.mc-temp-wrap { display: flex; flex-direction: column; min-width: 0; }
.mc-temp { font-size: 40px; font-weight: 300; line-height: 1; letter-spacing: -1px; }
.mc-temp::after { content: "°"; }
.mc-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mc-right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.psi { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.psi-label { font-weight: 600; }
.psi-val { font-weight: 700; color: var(--ink); }
.psi-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--good); box-shadow: 0 0 8px currentColor; }
.refresh-btn {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255,255,255,.08); color: var(--ink);
}
.refresh-btn svg { width: 22px; height: 22px; }
.refresh-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.searchbar {
  margin-top: 8px; width: 100%; display: flex; align-items: center; gap: 9px;
  padding: 11px 14px; border-radius: 16px; color: var(--muted);
  background: rgba(255,255,255,.07); border: 1px solid var(--glass-brd); text-align: left;
}
.searchbar svg { width: 18px; height: 18px; flex: 0 0 auto; }
.searchbar b { color: var(--ink); font-weight: 600; }

/* ---------- Area picker ---------- */
.picker {
  position: absolute; inset: 0; z-index: 2000; display: flex; align-items: flex-end;
  background: rgba(0,0,0,.45); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.picker[hidden] { display: none; }
.picker-panel {
  width: 100%; max-height: 76%; display: flex; flex-direction: column;
  border-radius: 24px 24px 0 0; padding: 14px 14px calc(18px + env(safe-area-inset-bottom));
  animation: rise .25s ease;
}
@keyframes rise { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.picker-head { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
#pickerSearch {
  flex: 1; padding: 12px 14px; border-radius: 14px; font-size: 15px;
  background: rgba(255,255,255,.08); border: 1px solid var(--glass-brd); color: var(--ink); outline: none;
}
#pickerSearch::placeholder { color: var(--faint); }
#pickerClose { width: 40px; height: 40px; border-radius: 12px; background: rgba(255,255,255,.08); font-size: 16px; color: var(--muted); }
.picker-list { overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; }
.picker-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 12px; border-radius: 12px; text-align: left; color: var(--ink); font-size: 15px;
}
.picker-item:active { background: rgba(255,255,255,.06); }
.picker-item .pi-fore { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.picker-item .pi-fore svg { width: 18px; height: 18px; }
.picker-item.is-sel { background: rgba(47,123,255,.18); }

/* ---------- Toast ---------- */
.toast {
  position: absolute; left: 50%; bottom: calc(var(--sheet-h) + 70px); transform: translateX(-50%);
  z-index: 2100; max-width: 86%; padding: 11px 16px; border-radius: 14px;
  background: rgba(20,34,50,.95); border: 1px solid var(--glass-brd); color: var(--ink);
  font-size: 13px; box-shadow: var(--shadow); animation: rise .2s ease;
}
.toast[hidden] { display: none; }

/* weather glyph colors */
.g-sun { color: #ffd34d; }
.g-cloud { color: #c8d6e5; }
.g-rain { color: #6fa8ff; }
.g-storm { color: #8ea6ff; }
.g-haze { color: #d9c79a; }

/* ---------- Forecast strip ---------- */
.fc-strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 2px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none; margin-top: 6px;
}
.fc-strip::-webkit-scrollbar { display: none; }
.fc-card {
  flex: 0 0 54px; height: 64px; border-radius: 14px;
  background: rgba(255,255,255,.07); border: 1px solid var(--glass-brd);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 7px 4px; gap: 0;
}
.fc-card.is-now { background: rgba(47,123,255,.18); border-color: rgba(47,123,255,.4); }
.fc-day { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; line-height: 1; }
.fc-ico { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; }
.fc-ico svg { width: 22px; height: 22px; }
.fc-temp { font-size: 10px; color: var(--ink); white-space: nowrap; line-height: 1; }

/* ---------- Wind arrow pin ---------- */
.wind-arrow-pin {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(180deg, #7bd0a8, #3fa776);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; color: #fff; font-weight: 700; font-size: 11px;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  border: 1.5px solid rgba(255,255,255,.5);
}
.wind-arrow-pin svg { width: 16px; height: 16px; }

/* ---------- Empty layer message ---------- */
.layer-msg {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 900; padding: 10px 18px; border-radius: 20px;
  background: rgba(12,22,34,.82); border: 1px solid var(--glass-brd);
  color: var(--muted); font-size: 13px; font-weight: 600;
  pointer-events: none; text-align: center;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.layer-msg[hidden] { display: none; }

/* ---------- Wide-screen responsive ---------- */
@media (min-width: 640px) {
  .top-card { max-width: 320px; }
  .timeline {
    left: 50%; right: auto;
    transform: translateX(-50%);
    width: min(560px, calc(100vw - 120px));
  }
  .sheet {
    padding-left: max(20px, calc(50vw - 260px));
    padding-right: max(20px, calc(50vw - 260px));
  }
  .map-buttons { right: max(14px, calc(50vw - 294px)); }
}
