:root {
  --primary: #2196F3;
  --bg: #F7FAFF;
  --card: #FFFFFFCC;
  --text: #0F172A;
  --muted: #5b6470;
  --border: rgba(15,23,42,0.08);
  --shadow: 0 18px 40px -18px rgba(15,23,42,0.25), 0 2px 8px rgba(15,23,42,0.05);
  --glass: rgba(255,255,255,0.55);
  --glass-strong: rgba(255,255,255,0.72);
  --focus: #1976D2;
  --severe: #dc2626;
  --warning: #f59e0b;
  --info: #0ea5e9;
  --radius: 18px;
  --grad: linear-gradient(135deg,#74b9ff,#a3d8ff 60%,#ffffff);
}
[data-theme="dark"] {
  --primary: #7CC4FF;
  --bg: #07101E;
  --card: #0F1B2D;
  --text: #F1F5F9;
  --muted: #94a3b8;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 20px 50px -20px rgba(0,0,0,0.7);
  --glass: rgba(15,27,45,0.55);
  --glass-strong: rgba(15,27,45,0.8);
  --focus: #90CAF9;
  --grad: linear-gradient(135deg,#0f2027,#203a43,#2c5364);
}

[data-weather="clear-day"]   { --grad: linear-gradient(135deg,#56CCF2,#2F80ED); }
[data-weather="clear-night"] { --grad: linear-gradient(135deg,#0f2027,#203a43,#2c5364); }
[data-weather="cloudy"]      { --grad: linear-gradient(135deg,#bdc3c7,#2c3e50); }
[data-weather="rainy"]       { --grad: linear-gradient(135deg,#3a7bd5,#3a6073); }
[data-weather="snowy"]       { --grad: linear-gradient(135deg,#e6dada,#274046); }
[data-weather="storm"]       { --grad: linear-gradient(135deg,#141E30,#243B55); }
[data-weather="fog"]         { --grad: linear-gradient(135deg,#757F9A,#D7DDE8); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  transition: background .5s ease, color .3s ease;
  position: relative;
  overflow-x: hidden;
}
h1, h2 { font-family: 'Space Grotesk', 'Inter', sans-serif; }
.bg-layer {
  position: fixed; inset: 0; z-index: -2;
  background: var(--grad);
  opacity: .35;
  transition: background 1s ease;
}
[data-theme="dark"] .bg-layer { opacity: .55; }

/* Aurora blobs */
.aurora { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.aurora span {
  position: absolute; display: block; width: 520px; height: 520px; border-radius: 50%;
  filter: blur(80px); opacity: .35; mix-blend-mode: screen;
  animation: floaty 18s ease-in-out infinite;
}
.aurora span:nth-child(1) { background: #60a5fa; top: -120px; left: -120px; }
.aurora span:nth-child(2) { background: #f472b6; bottom: -160px; right: -120px; animation-delay: -6s; }
.aurora span:nth-child(3) { background: #34d399; top: 30%; right: 20%; width: 320px; height: 320px; animation-delay: -12s; }
[data-theme="dark"] .aurora span { opacity: .25; }
@keyframes floaty {
  0%, 100% { transform: translate(0,0) scale(1); }
  50%      { transform: translate(40px,-30px) scale(1.08); }
}

a { color: var(--primary); }
.muted { color: var(--muted); font-size: .875rem; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.skip-link {
  position: absolute; top: -40px; left: 12px; z-index: 100;
  background: var(--primary); color: #fff; padding: 10px 14px;
  border-radius: 8px; font-weight: 600; text-decoration: none;
  transition: top .2s ease;
}
.skip-link:focus { top: 12px; outline: 3px solid var(--focus); outline-offset: 2px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 18px 24px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  background: linear-gradient(180deg, var(--glass-strong), transparent);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text); font-size: 1.05rem; }
.brand svg { color: var(--primary); }
.brand strong { color: var(--primary); font-weight: 800; }

.search-wrap { display: flex; align-items: center; gap: 10px; flex: 1 1 420px; justify-content: flex-end; flex-wrap: wrap; }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--glass-strong);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px; min-width: 220px; flex: 1 1 260px;
  box-shadow: var(--shadow);
  transition: transform .2s ease;
}
.search:focus-within { transform: scale(1.01); outline: 2px solid var(--focus); outline-offset: 2px; }
.search svg { color: var(--muted); flex-shrink: 0; }
.search input { flex: 1; min-width: 0; border: none; outline: none; background: transparent; color: var(--text); font-size: 15px; font-family: inherit; }

.btn, .icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--glass-strong);
  color: var(--text); font: 500 14px/1 'Inter', sans-serif;
  padding: 10px 14px; border-radius: var(--radius); cursor: pointer;
  transition: transform .2s ease, background .2s ease, box-shadow .2s ease;
  box-shadow: var(--shadow);
  min-height: 44px;
}
.btn:hover, .icon-btn:hover { transform: translateY(-1px); }
.btn.primary { background: linear-gradient(135deg, var(--primary), #1565C0); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.icon-btn { padding: 10px; min-width: 44px; min-height: 44px; justify-content: center; }
.icon-btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--muted); }
.refresh-svg { transition: transform .8s ease; }
.is-refreshing .refresh-svg { transform: rotate(360deg); }

.unit-toggle { display: inline-flex; background: var(--glass-strong); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px; box-shadow: var(--shadow); }
.unit-btn { border: none; background: transparent; color: var(--text); font: 600 13px/1 'Inter', sans-serif; padding: 8px 12px; border-radius: 12px; cursor: pointer; min-width: 44px; transition: background .2s ease, color .2s ease; }
.unit-btn:hover { background: var(--card); }
.unit-btn.is-active { background: var(--primary); color: #fff; }

/* Recent */
.recent-row { display: flex; gap: 8px; padding: 0 24px 8px; flex-wrap: wrap; }
.recent-chip {
  background: var(--glass); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px; font-size: 13px;
  cursor: pointer; color: var(--text);
  transition: transform .2s ease, background .2s ease;
  backdrop-filter: blur(10px);
}
.recent-chip:hover { transform: scale(1.05); background: var(--primary); color: #fff; }

/* Toast & change banner */
.toast {
  position: fixed; top: 80px; left: 50%; transform: translateX(-50%);
  background: #ef4444; color: #fff; padding: 12px 18px;
  border-radius: var(--radius); box-shadow: var(--shadow);
  z-index: 50; font-weight: 500;
  animation: slideDown .35s ease;
}
.change-banner {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: linear-gradient(135deg, var(--primary), #0d47a1);
  color: #fff; padding: 12px 18px; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 50; font-weight: 600;
  display: inline-flex; align-items: center; gap: 10px;
  animation: slideUp .35s ease;
}
.change-banner button { background: rgba(255,255,255,.2); border: none; color: #fff; padding: 4px 10px; border-radius: 999px; cursor: pointer; font-weight: 600; }
@keyframes slideDown { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes slideUp { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Alert banner */
.alert-banner { display: flex; flex-direction: column; gap: 10px; }
.alert {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: flex-start;
  padding: 14px 18px; border-radius: var(--radius);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  animation: fadeUp .4s ease both;
  box-shadow: var(--shadow);
}
.alert-severe   { background: linear-gradient(135deg, rgba(220,38,38,.94), rgba(185,28,28,.94)); color: #fff; border-color: rgba(255,255,255,.15); }
.alert-warning  { background: linear-gradient(135deg, rgba(245,158,11,.94), rgba(217,119,6,.94)); color: #fff; border-color: rgba(255,255,255,.15); }
.alert-info     { background: linear-gradient(135deg, rgba(14,165,233,.94), rgba(2,132,199,.94)); color: #fff; border-color: rgba(255,255,255,.15); }
.alert-icon { font-size: 1.4rem; line-height: 1; }
.alert-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.alert-body strong { font-size: .98rem; font-weight: 700; letter-spacing: -.01em; }
.alert-body .alert-meta { font-size: .72rem; opacity: .9; text-transform: uppercase; letter-spacing: .08em; }
.alert-body p { margin: 4px 0 0; font-size: .88rem; opacity: .95; }
.alert-body p[hidden] { display: none; }
.alert-actions { display: flex; gap: 6px; }
.alert-actions button {
  background: rgba(255,255,255,.18); border: none; color: #fff;
  padding: 6px 10px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: .78rem;
}
.alert-actions button:hover { background: rgba(255,255,255,.3); }
.alert-severe { animation: pulse 2.4s ease-in-out infinite, fadeUp .4s ease both; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 10px 25px rgba(220,38,38,.3); }
  50%      { box-shadow: 0 10px 35px rgba(220,38,38,.6); }
}

/* Dashboard */
.dashboard { display: grid; gap: 20px; padding: 8px 24px 32px; grid-template-columns: 1fr; }
.dashboard:focus { outline: none; }
@media (min-width: 768px) {
  .dashboard { grid-template-columns: 1fr 1fr; }
  .hero, .alert-banner, .precip { grid-column: 1 / -1; }
}
@media (min-width: 1200px) {
  .dashboard { grid-template-columns: 2fr 1fr; }
  .hero, .alert-banner { grid-column: 1 / -1; }
  .precip { grid-column: 1 / -1; }
  .hourly { grid-column: 1 / 2; }
  .daily { grid-column: 2 / 3; }
}

/* Cards */
.card {
  background: var(--glass-strong);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  animation: fadeUp .5s ease both;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px);} to { opacity: 1; transform: translateY(0);} }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 8px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 1.05rem; font-weight: 600; letter-spacing: -.01em; }

/* Hero */
.hero { min-height: 260px; position: relative; overflow: hidden; }
.hero::before {
  content: ""; position: absolute; inset: -1px; border-radius: var(--radius); pointer-events: none;
  background: radial-gradient(800px 200px at 80% -10%, color-mix(in oklab, var(--primary) 30%, transparent), transparent 60%);
}
.hero-content { display: grid; gap: 24px; grid-template-columns: 1fr; animation: fadeUp .5s ease both; position: relative; }
@media (min-width: 900px) { .hero-content { grid-template-columns: 1fr 1.1fr; align-items: center; } }
.location h1 { margin: 0; font-size: clamp(1.6rem, 3vw, 2.4rem); font-weight: 700; letter-spacing: -.02em; }
.now { display: flex; align-items: center; gap: 18px; margin-top: 18px; }
.now-icon { width: 96px; height: 96px; flex-shrink: 0; color: var(--primary); animation: floatIcon 6s ease-in-out infinite; }
.now-icon svg { width: 100%; height: 100%; filter: drop-shadow(0 6px 14px rgba(0,0,0,.15)); }
@keyframes floatIcon { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.temp { font-size: clamp(3rem, 7vw, 5.2rem); font-weight: 800; line-height: 1; letter-spacing: -.04em; background: linear-gradient(180deg, currentColor, color-mix(in oklab, currentColor 65%, transparent)); -webkit-background-clip: text; background-clip: text; }
.temp sup { font-size: .35em; font-weight: 600; color: var(--muted); margin-left: 4px; vertical-align: super; -webkit-text-fill-color: var(--muted); }
.desc { font-size: 1.1rem; font-weight: 500; text-transform: capitalize; margin-top: 4px; }
.feels { margin-top: 2px; }

.hero-right { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 540px) { .hero-right { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 900px) { .hero-right { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .hero-right { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 4px; transition: transform .2s ease; }
.stat:hover { transform: scale(1.03); }
.stat-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.stat-val { font-size: 1rem; font-weight: 600; }

/* Precipitation chart */
.precip-chart {
  display: flex; align-items: flex-end; gap: 4px;
  height: 170px; padding: 8px 4px 0;
  border-bottom: 1px solid var(--border);
  position: relative; outline: none;
}
.precip-chart:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; border-radius: 10px; }
.bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; cursor: pointer; border: 0; background: transparent; padding: 0; color: inherit; font: inherit; }
.bar-wrap:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 8px; }
.bar { width: 100%; max-width: 22px; background: linear-gradient(180deg, var(--primary), #1565C0); border-radius: 6px 6px 0 0; position: relative; transition: transform .2s ease, filter .2s ease, background .2s ease; min-height: 3px; }
.bar-wrap:hover .bar, .bar-wrap:focus-visible .bar { transform: scaleY(1.05); filter: brightness(1.15); }
.bar-wrap.is-active .bar { background: linear-gradient(180deg, #ffd54f, #fb8c00); }
.bar-val { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: .65rem; font-weight: 600; color: var(--text); opacity: 0; transition: opacity .2s ease; white-space: nowrap; }
.bar-wrap:hover .bar-val, .bar-wrap:focus-visible .bar-val, .bar-wrap.is-active .bar-val { opacity: 1; }
.bar-label { font-size: .65rem; color: var(--muted); height: 12px; white-space: nowrap; }
.precip-tip { margin-top: 8px; font-size: .82rem; color: var(--muted); min-height: 1.2em; }
.precip-tip strong { color: var(--text); }

/* Hourly */
.hourly-scroll { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x mandatory; }
.hourly-scroll::-webkit-scrollbar { height: 6px; }
.hourly-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
.hour-card { flex: 0 0 100px; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px 10px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; scroll-snap-align: start; transition: transform .2s ease, background .2s ease; cursor: default; }
.hour-card:hover { transform: translateY(-3px); }
.hour-card .h-time { font-size: .8rem; color: var(--muted); font-weight: 500; }
.hour-card svg { width: 36px; height: 36px; color: var(--primary); }
.hour-card .h-temp { font-weight: 700; font-size: 1.05rem; }
.hour-card .h-rain { font-size: .7rem; color: var(--primary); }
.hour-card .h-wind { font-size: .7rem; color: var(--muted); }

/* Daily */
.daily-list { display: flex; flex-direction: column; gap: 8px; }
.day-row { display: grid; grid-template-columns: 1.2fr 40px 1fr 1fr; gap: 10px; align-items: center; padding: 10px 12px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; transition: transform .2s ease; }
.day-row:hover { transform: scale(1.01); }
.day-row .d-name { font-weight: 600; font-size: .92rem; }
.day-row svg { width: 30px; height: 30px; color: var(--primary); }
.day-row .d-rain { font-size: .78rem; color: var(--primary); }
.day-row .d-temps { font-size: .9rem; text-align: right; font-weight: 600; }
.day-row .d-temps .d-min { color: var(--muted); font-weight: 500; margin-left: 6px; }

/* Skeleton */
.skeleton { background: linear-gradient(90deg, var(--card) 25%, var(--border) 50%, var(--card) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 12px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.hero-skeleton { height: 220px; }
.h-skel { flex: 0 0 100px; height: 130px; }
.d-skel { height: 52px; }
.r-skel { height: 220px; }

.foot { text-align: center; padding: 18px; font-size: .8rem; }

/* Modal / Map */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2,6,23,0.55); backdrop-filter: blur(6px); animation: fadeIn .25s ease; }
.modal-panel {
  position: relative; width: min(1100px, 100%); max-height: 92dvh; overflow: hidden;
  background: var(--glass-strong); backdrop-filter: blur(20px);
  border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  animation: zoomIn .3s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes zoomIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.map-layout { display: grid; grid-template-columns: 1fr; gap: 0; overflow: hidden; min-height: 0; }
@media (min-width: 880px) { .map-layout { grid-template-columns: 1.2fr 1fr; min-height: 560px; } }
.leaflet-host { width: 100%; min-height: 320px; height: 320px; }
@media (min-width: 880px) { .leaflet-host { height: auto; } }
.region-grid {
  padding: 16px; display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  overflow-y: auto; max-height: 60dvh;
}
@media (min-width: 880px) { .region-grid { max-height: none; } }
.region-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  overflow: hidden; display: flex; flex-direction: column;
  transition: transform .25s ease, box-shadow .25s ease;
  box-shadow: 0 4px 14px rgba(0,0,0,.05);
}
.region-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.region-card.is-current { outline: 2px solid var(--primary); }
.region-photo { position: relative; aspect-ratio: 16/10; background: linear-gradient(135deg, #cbd5e1, #94a3b8); overflow: hidden; }
.region-photo img { width: 100%; height: 100%; object-fit: cover; transition: transform .6s ease; }
.region-card:hover .region-photo img { transform: scale(1.06); }
.region-photo .flag { position: absolute; top: 8px; left: 8px; width: 36px; height: 24px; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.3); object-fit: cover; }
.region-photo .badge {
  position: absolute; bottom: 8px; right: 8px; background: rgba(15,23,42,.78); color: #fff;
  padding: 4px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px;
}
.region-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.region-body .name { font-weight: 700; font-size: 1rem; }
.region-body .cond { color: var(--muted); font-size: .8rem; text-transform: capitalize; }
.region-body .temp-row { display: flex; align-items: baseline; justify-content: space-between; margin-top: 4px; }
.region-body .temp-row .big { font-size: 1.4rem; font-weight: 800; letter-spacing: -.02em; }
.region-body .temp-row .rain { font-size: .78rem; color: var(--primary); font-weight: 600; }

/* Leaflet popup tweaks */
.leaflet-popup-content { font-family: inherit; }
.leaflet-popup-content strong { display: block; margin-bottom: 2px; }

/* Mobile */
@media (max-width: 520px) {
  .topbar { padding: 14px; gap: 8px; }
  .search-wrap { justify-content: flex-start; }
  .btn span { display: none; }
  .dashboard { padding: 8px 14px 24px; }
  .card { padding: 16px; }
  .day-row { grid-template-columns: 1fr 30px 1fr; }
  .day-row .d-rain { display: none; }
  .precip-chart { height: 130px; }
  .modal { padding: 0; }
  .modal-panel { border-radius: 0; max-height: 100dvh; height: 100dvh; }
}

/* prefers-reduced-motion: keep layout, drop motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .aurora { display: none; }
  .now-icon { animation: none; }
  .skeleton { animation: none; background: var(--card); }
  .hero-content, .card, .alert, .change-banner, .toast, .modal-panel, .modal-backdrop { animation: none !important; }
  .bar-wrap:hover .bar, .stat:hover, .hour-card:hover, .day-row:hover, .btn:hover, .icon-btn:hover, .recent-chip:hover, .region-card:hover { transform: none !important; filter: none !important; }
}
