:root {
  --g1: #2b6fd6; --g2: #0a2a5e; --accent: #7cc4ff; --accent2: #b388ff;
  --text: #eef3fb; --muted: #9fb0c8; --card: rgba(255,255,255,.07); --card-brd: rgba(255,255,255,.12);
  --chip: rgba(255,255,255,.06); --shadow: 0 10px 40px rgba(0,0,0,.35);
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  font-synthesis: none;
}
body[data-theme="clear-day"]   { --g1:#2b6fd6; --g2:#0a2a5e; --accent:#ffd479; --accent2:#7cc4ff; }
body[data-theme="clear-night"] { --g1:#16213e; --g2:#05060f; --accent:#9db8ff; --accent2:#b388ff; }
body[data-theme="cloud-day"]   { --g1:#4a6585; --g2:#1a2738; --accent:#cfe0f5; --accent2:#9fb6d6; }
body[data-theme="cloud-night"] { --g1:#222d40; --g2:#0a0f1a; --accent:#b8c6dc; --accent2:#8a9bbb; }
body[data-theme="rain"]        { --g1:#33506e; --g2:#0c1622; --accent:#8fd0ff; --accent2:#6fb0e8; }
body[data-theme="snow"]        { --g1:#5a7088; --g2:#1b2530; --accent:#eaf4ff; --accent2:#cfe0f5; }
body[data-theme="fog"]         { --g1:#465463; --g2:#191f27; --accent:#c8d2dd; --accent2:#aab6c4; }
body[data-theme="storm"]       { --g1:#2a2a44; --g2:#070710; --accent:#c4a6ff; --accent2:#7cc4ff; }

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  color: var(--text); background: var(--g2);
  min-height: 100vh; min-height: 100dvh; -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
.bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; background: linear-gradient(165deg, var(--g1), var(--g2) 72%); transition: background .9s ease; }
.bg span { position: absolute; border-radius: 50%; filter: blur(64px); opacity: .2; background: radial-gradient(circle at 30% 30%, var(--accent), transparent 70%); animation: float 20s ease-in-out infinite; }
.bg span:nth-child(1){ width:60vw; height:60vw; top:-12vw; left:-10vw; }
.bg span:nth-child(2){ width:46vw; height:46vw; bottom:-12vw; right:-12vw; background: radial-gradient(circle at 30% 30%, var(--accent2), transparent 70%); animation-delay:-7s; }
.bg span:nth-child(3){ width:30vw; height:30vw; top:42%; left:60%; opacity:.18; animation-delay:-13s; }
@keyframes float { 0%,100%{ transform: translateY(0) translateX(0); } 50%{ transform: translateY(-4vh) translateX(2vw); } }

.app { position: relative; z-index: 1; max-width: 600px; margin: 0 auto; padding: 0 16px calc(40px + var(--safe-b)); }

/* topbar */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px; padding: calc(12px + var(--safe-t)) 16px 12px; max-width: 600px; margin: 0 auto;
  background: linear-gradient(180deg, rgba(10,16,28,.55), transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.icon-btn { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border: 0; border-radius: 12px; background: var(--card); color: var(--text); cursor: pointer; border: 1px solid var(--card-brd); }
.icon-btn:active { transform: scale(.94); }
.icon-btn .ico { width: 20px; height: 20px; }
.loc-btn { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; background: none; border: 0; color: var(--text); cursor: pointer; padding: 4px 6px; }
.loc-pin .ico { width: 16px; height: 16px; color: var(--accent); flex: none; }
.loc-text { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.loc-text .place { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.loc-text .when { font-size: 11.5px; color: var(--muted); }
.loc-caret { color: var(--muted); font-size: 12px; }
.top-actions { display: flex; gap: 8px; margin-left: auto; }

/* saved chips */
.saved { position: relative; z-index: 1; display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 8px; max-width: 600px; margin: 0 auto; scrollbar-width: none; }
.saved::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; border-radius: 999px; background: var(--card); border: 1px solid var(--card-brd); overflow: hidden; }
.chip.on { border-color: var(--accent); background: rgba(124,196,255,.12); }
.chip-name { background: none; border: 0; color: var(--text); font-size: 13px; font-weight: 600; padding: 8px 5px 8px 14px; cursor: pointer; white-space: nowrap; max-width: 52vw; overflow: hidden; text-overflow: ellipsis; }
.chip-del { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 8px 11px 8px 4px; display: grid; place-items: center; }
.chip-del .ico { width: 13px; height: 13px; }
.chip-del:active { color: #ff7a7a; }
.chip-add { flex: none; display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1px dashed var(--card-brd); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.chip-add .ico { width: 14px; height: 14px; color: var(--accent); }
.chip-add:active { transform: scale(.96); }

.status { text-align: center; padding: 60px 16px; color: var(--muted); }
.status.error { color: #ffb4b4; }

/* hero */
.hero { text-align: center; padding: 8px 0 18px; animation: rise .5s ease both; }
.hero-top { display: flex; align-items: center; justify-content: center; gap: 4px; }
.hero-icon { width: 120px; height: 120px; flex: none; }
.hero-icon svg { width: 100%; height: 100%; overflow: visible; }
.hero-temp { font-size: 92px; font-weight: 200; letter-spacing: -4px; line-height: 1; }
.hero-temp .deg { font-weight: 300; }
.hero-cond { font-size: 19px; font-weight: 600; color: var(--accent); margin-top: 2px; }
.hero-sub { color: var(--muted); font-size: 14px; margin-top: 6px; }
.hero-engine { display: inline-flex; align-items: center; gap: 6px; margin-top: 12px; font-size: 11.5px; color: var(--muted); background: var(--chip); border: 1px solid var(--card-brd); padding: 4px 10px; border-radius: 999px; }
.hero-engine .dot { width: 7px; height: 7px; border-radius: 50%; background: #58e08a; box-shadow: 0 0 8px #58e08a; }
.hero-engine.tier1 .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.hero-engine.aifs .dot { background: #b388ff; box-shadow: 0 0 8px #b388ff; }
.hero-engine.ens .dot { background: #ffc266; box-shadow: 0 0 8px #ffc266; }

/* cards */
.card { background: var(--card); border: 1px solid var(--card-brd); border-radius: 22px; padding: 18px; margin-bottom: 14px; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: var(--shadow); animation: rise .5s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-title { font-size: 12.5px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); font-weight: 600; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.two-col .card { margin-bottom: 0; }

/* nowcast */
.nowcast { display: flex; align-items: center; gap: 10px; background: linear-gradient(90deg, rgba(143,208,255,.14), rgba(124,196,255,.05)); border: 1px solid rgba(143,208,255,.25); border-radius: 16px; padding: 12px 16px; margin-bottom: 14px; font-size: 14px; }
.nowcast .nc-ico { font-size: 18px; }
.nowcast strong { font-weight: 700; }

/* segmented */
.seg { display: inline-flex; background: var(--chip); border: 1px solid var(--card-brd); border-radius: 10px; overflow: hidden; }
.seg button { background: none; border: 0; color: var(--muted); font-size: 12px; padding: 6px 12px; cursor: pointer; font-weight: 600; }
.seg button.on { background: rgba(255,255,255,.12); color: var(--text); }

/* hourly graph */
.graph-scroll { overflow-x: auto; scrollbar-width: none; margin: 0 -6px; }
.graph-scroll::-webkit-scrollbar { display: none; }
#graph svg { display: block; }

/* detail grid */
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.metric { background: var(--chip); border: 1px solid var(--card-brd); border-radius: 14px; padding: 12px 14px; }
.metric .k { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; }
.metric .k .ico { width: 14px; height: 14px; }
.metric .v { font-size: 20px; font-weight: 600; margin-top: 5px; }
.metric .v small { font-size: 12px; color: var(--muted); font-weight: 400; }
.metric .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.wind-rose { float: right; width: 34px; height: 34px; margin-top: -2px; }

/* sun card */
.sun-arc { position: relative; }
.sun-arc svg { width: 100%; height: auto; overflow: visible; }
.sun-times { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12px; color: var(--muted); }
.sun-times b { color: var(--text); font-weight: 600; display: block; font-size: 14px; }
.moon-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.moon-row .mi { font-size: 28px; }
.moon-row .ml { font-size: 13px; } .moon-row .ml small { color: var(--muted); display: block; }

/* air quality */
.aq-top { display: flex; align-items: center; gap: 12px; }
.aq-dial { width: 64px; height: 64px; flex: none; }
.aq-num { font-size: 22px; font-weight: 700; }
.aq-cat { font-size: 13px; font-weight: 600; }
.aq-pollutants { display: grid; grid-template-columns: repeat(2,1fr); gap: 6px 12px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.aq-pollutants b { color: var(--text); font-weight: 600; }

/* daily */
.daily { display: flex; flex-direction: column; }
.day { display: grid; grid-template-columns: 70px 30px 50px 1fr; align-items: center; gap: 10px; padding: 11px 2px; border-bottom: 1px solid rgba(255,255,255,.07); cursor: pointer; }
.day:last-child { border-bottom: 0; }
.day .dname { font-weight: 600; font-size: 14px; }
.day .di { width: 28px; height: 28px; } .day .di svg { width: 100%; height: 100%; }
.day .dp { font-size: 12px; color: var(--accent); }
.day .drange { display: flex; align-items: center; gap: 9px; }
.day .lo { color: var(--muted); font-size: 14px; width: 32px; text-align: right; }
.day .hi { font-size: 14px; font-weight: 600; width: 32px; }
.bar { flex: 1; height: 6px; border-radius: 6px; background: rgba(255,255,255,.12); position: relative; overflow: hidden; }
.bar > span { position: absolute; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--accent2), var(--accent)); }
.day-detail { grid-column: 1/-1; overflow: hidden; max-height: 0; transition: max-height .3s ease; }
.day.open .day-detail { max-height: 120px; }
.day-detail-inner { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; padding: 12px 2px 4px; font-size: 12px; color: var(--muted); }
.day-detail-inner b { color: var(--text); display: block; font-size: 13px; }

/* radar cta */
.radar-cta { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; color: var(--text); cursor: pointer; }
.radar-cta-ico { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: rgba(124,196,255,.15); color: var(--accent); }
.radar-cta-ico .ico { width: 22px; height: 22px; }
.radar-cta strong { display: block; font-size: 15px; } .radar-cta small { color: var(--muted); font-size: 12.5px; }
.radar-cta .chev { margin-left: auto; color: var(--muted); font-size: 22px; }

/* hierarchy */
.hier-card details summary { cursor: pointer; color: var(--muted); font-size: 12.5px; list-style: none; }
.hier-card details summary::-webkit-details-marker { display: none; }
.hier { list-style: none; display: flex; flex-direction: column; gap: 8px; margin: 14px 0 6px; }
.hx { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; background: var(--chip); border: 1px solid var(--card-brd); border-radius: 12px; }
.hx.is-active { border-color: var(--accent); background: rgba(124,196,255,.10); }
.hx.is-dim { opacity: .5; }
.hx .rank { font-size: 16px; color: var(--accent); font-weight: 700; }
.hx-label { font-weight: 600; font-size: 13.5px; } .hx-vendor { font-size: 11px; color: var(--muted); }
.hx-status { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.st-active { color: #6ef0a0; background: rgba(88,224,138,.14); } .st-standby { color: var(--muted); background: rgba(255,255,255,.06); }
.st-offline { color: #ffb38a; background: rgba(255,150,90,.12); } .st-locked { color: #cdd7e6; background: rgba(255,255,255,.07); } .st-error { color: #ff9a9a; background: rgba(255,90,90,.13); }
.attrib { color: var(--muted); font-size: 11.5px; line-height: 1.5; margin-top: 10px; }
.foot { text-align: center; color: var(--muted); font-size: 11px; line-height: 1.6; padding: 8px 0 0; }
.muted { color: var(--muted); } .small { font-size: 11.5px; }

/* overlays / sheets */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(6,10,18,.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; max-width: 600px; max-height: 88vh; overflow-y: auto; background: #0f1626; border: 1px solid var(--card-brd); border-radius: 22px 22px 0 0; padding: 16px 16px calc(20px + var(--safe-b)); animation: slideup .28s cubic-bezier(.2,.8,.2,1); }
@keyframes slideup { from { transform: translateY(100%); } }
@keyframes slidedown { from { transform: translateY(-100%); } }
/* search sheet: anchor to TOP with sticky input so it never jumps under the keyboard */
#search-overlay { align-items: flex-start; }
#search-overlay .sheet { border-radius: 0 0 22px 22px; max-height: 100dvh; padding-top: 0; animation: slidedown .28s cubic-bezier(.2,.8,.2,1); }
/* sticky header absorbs the notch/Dynamic Island inset; its bg fills the status-bar band so content never shows under it */
#search-overlay .sheet-head { position: sticky; top: 0; z-index: 3; background: #0f1626; padding-top: calc(var(--safe-t) + 16px); padding-bottom: 12px; margin-bottom: 8px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet-head h2 { font-size: 18px; }
.text-btn { margin-left: auto; background: none; border: 0; color: var(--accent); font-size: 15px; font-weight: 600; cursor: pointer; }
.search-field { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--chip); border: 1px solid var(--card-brd); border-radius: 12px; padding: 0 12px; }
.search-field .ico { width: 18px; height: 18px; color: var(--muted); }
#q { flex: 1; background: none; border: 0; outline: none; color: var(--text); font-size: 16px; padding: 12px 0; }
.row-btn { width: 100%; display: flex; align-items: center; gap: 10px; background: var(--chip); border: 1px solid var(--card-brd); border-radius: 12px; padding: 12px 14px; color: var(--text); font-size: 14px; cursor: pointer; margin-bottom: 10px; }
.row-btn .ico { width: 18px; height: 18px; color: var(--accent); }
.suggestions { list-style: none; }
.suggestions li { padding: 13px 8px; border-bottom: 1px solid rgba(255,255,255,.06); cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.suggestions li .sub { color: var(--muted); font-size: 12px; }
.saved-list .sv { display: flex; align-items: center; gap: 10px; padding: 12px 8px; border-bottom: 1px solid rgba(255,255,255,.06); transition: transform .18s ease; }
.saved-list .sv.dragging { transition: none; background: rgba(255,255,255,.06); border-radius: 10px; border-bottom-color: transparent; box-shadow: 0 10px 26px rgba(0,0,0,.45); position: relative; z-index: 5; }
.saved-list .sv .grip { color: var(--muted); cursor: grab; touch-action: none; display: grid; place-items: center; padding: 4px 2px; }
.saved-list .sv .grip svg { width: 18px; height: 18px; }
.saved-list .sv .grip:active { cursor: grabbing; }
.saved-list .sv .nm { flex: 1; background: none; border: 0; color: var(--text); font: inherit; text-align: left; cursor: pointer; padding: 6px 0; }
.saved-list .sv .rm, .saved-list .sv .edit { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; display: grid; place-items: center; }
.saved-list .sv .rm svg, .saved-list .sv .edit svg { width: 16px; height: 16px; }
.saved-list .sv .edit:active { color: var(--accent); }
.saved-list .sv .nm-edit { flex: 1; min-width: 0; background: rgba(255,255,255,.08); border: 1px solid var(--accent); border-radius: 8px; color: var(--text); font: inherit; padding: 7px 10px; outline: none; }

/* settings */
.settings { display: flex; flex-direction: column; gap: 16px; }
.setting { } .setting > label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 7px; text-transform: uppercase; letter-spacing: .5px; }
.choices { display: flex; gap: 8px; flex-wrap: wrap; }
.choices button { background: var(--chip); border: 1px solid var(--card-brd); color: var(--text); border-radius: 10px; padding: 9px 14px; font-size: 14px; cursor: pointer; }
.choices button.on { border-color: var(--accent); background: rgba(124,196,255,.14); color: var(--text); }
.install-hint { background: var(--chip); border: 1px solid var(--card-brd); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.install-hint button { display: block; margin-top: 8px; background: var(--accent); color: #06121f; border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 700; cursor: pointer; }

/* radar overlay */
.radar-overlay { align-items: stretch; background: #05080f; flex-direction: column; }
.radar-head { display: flex; align-items: center; gap: 12px; padding: calc(12px + var(--safe-t)) 16px 12px; z-index: 2; }
.radar-title { font-weight: 700; } .radar-time { margin-left: auto; color: var(--muted); font-size: 13px; }
#map { flex: 1; width: 100%; background: #0b1220; }
.radar-controls { display: flex; align-items: center; gap: 12px; padding: 14px 16px calc(18px + var(--safe-b)); background: rgba(10,16,28,.85); }
.radar-controls input[type=range] { flex: 1; accent-color: var(--accent); }
.radar-frame { color: var(--muted); font-size: 12px; min-width: 44px; text-align: right; }
.leaflet-container { background: #0b1220 !important; font: inherit !important; }
.leaflet-control-attribution { background: rgba(0,0,0,.4) !important; color: #8aa !important; font-size: 9px !important; }
.leaflet-control-attribution a { color: #9bf !important; }

@media (min-width: 620px) { .app, .topbar, .saved { max-width: 600px; } }
@media (prefers-reduced-motion: reduce) { .bg span { animation: none; } .card, .hero, .sheet, .overlay { animation: none; } * { transition: none !important; } }
