:root {
  --bg: #eaf2fb;
  --ink: #1b1c20;
  --ink2: #3a3d45;
  --muted: #6b7280;
  --line: #e5e9f0;
  --card: #ffffff;
  --accent: #0f6cbd;
  --accent2: #2b88d8;
  --green: #1a9e5f;
  --yellow: #d9a406;
  --orange: #e8710a;
  --red: #d13438;
  --shadow: 0 2px 10px rgba(20, 40, 80, .06), 0 8px 24px rgba(20, 40, 80, .05);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 500px at 50% -160px, #bcd8f5 0%, rgba(188,216,245,0) 70%),
    linear-gradient(180deg, #dcebfb 0%, var(--bg) 240px, #f4f7fb 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

#app { max-width: 720px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(80px + var(--safe-bot)); }

/* App bar */
.appbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: rgba(240, 246, 253, .78);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255,255,255,.5);
}
.appbar-main { display: flex; align-items: center; justify-content: space-between; }
.title { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 24px; }
.title h1 { font-size: 17px; margin: 0; letter-spacing: .2px; color: var(--ink); font-weight: 700; }
.title p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }
.icon-btn {
  background: #fff; color: var(--accent); border: 1px solid var(--line);
  width: 38px; height: 38px; border-radius: 50%; font-size: 18px; cursor: pointer;
  display: grid; place-items: center; transition: transform .3s; box-shadow: var(--shadow);
}
.icon-btn:active { transform: rotate(180deg); }
.countdown { margin-top: 8px; font-size: 12.5px; color: var(--ink2); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.countdown b { color: var(--accent); }

main { padding: 14px 14px 0; }
.section-title { font-size: 13px; font-weight: 700; letter-spacing: .2px; color: var(--ink2); margin: 20px 6px 10px; display: flex; align-items: center; gap: 6px; }

/* ---------- HERO (MSN-style) ---------- */
.hero {
  border-radius: 22px; padding: 20px; color: #fff; position: relative; overflow: hidden;
  box-shadow: var(--shadow); min-height: 190px;
  background: linear-gradient(160deg, #3a8bd6, #6fb1e8);
}
.hero.sky-sun { background: linear-gradient(160deg, #2f8fd6 0%, #57b0e6 55%, #8fd0f0 100%); }
.hero.sky-cloud { background: linear-gradient(160deg, #6b8ba8 0%, #91a9c0 60%, #b6c6d6 100%); }
.hero.sky-rain { background: linear-gradient(160deg, #3f5c78 0%, #5d7c99 55%, #7f9ab0 100%); }
.hero.sky-storm { background: linear-gradient(160deg, #2f3b52 0%, #4a5a72 55%, #6a7890 100%); }
.hero.sky-snow { background: linear-gradient(160deg, #6f8fb0, #a9c2da); }
.hero::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(255,255,255,.25), rgba(255,255,255,0) 70%); border-radius: 50%;
}
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; position: relative; z-index: 1; }
.hero-loc { font-size: 15px; font-weight: 600; opacity: .96; }
.hero-date { font-size: 12.5px; opacity: .85; margin-top: 2px; }
.hero-src { font-size: 11px; opacity: .8; background: rgba(255,255,255,.18); padding: 3px 8px; border-radius: 999px; }
.hero-main { display: flex; align-items: center; gap: 10px; margin: 8px 0 2px; position: relative; z-index: 1; }
.hero-temp { font-size: 58px; font-weight: 300; line-height: 1; letter-spacing: -2px; }
.hero-emoji { font-size: 46px; }
.hero-cond { font-size: 15px; opacity: .96; position: relative; z-index: 1; }
.hero-sub { font-size: 13px; opacity: .9; margin-top: 6px; display: flex; gap: 14px; flex-wrap: wrap; position: relative; z-index: 1; }
.hero-risk {
  margin-top: 12px; display: inline-flex; align-items: center; gap: 7px; position: relative; z-index: 1;
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.28);
  padding: 7px 12px; border-radius: 12px; font-size: 12.5px;
}
.hero-risk .dot { width: 9px; height: 9px; border-radius: 50%; }

/* ---------- Current weather cards ---------- */
.nowrow { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 8px; -webkit-overflow-scrolling: touch; }
.nowcard {
  flex: 0 0 auto; width: 150px; border-radius: 16px; padding: 13px; color: #fff;
  box-shadow: var(--shadow); background: linear-gradient(160deg, #3a8bd6, #6fb1e8); cursor: pointer;
}
.nowcard.sky-sun { background: linear-gradient(160deg, #2f8fd6, #6cc0f0); }
.nowcard.sky-cloud { background: linear-gradient(160deg, #6b8ba8, #a2b6ca); }
.nowcard.sky-rain { background: linear-gradient(160deg, #3f5c78, #6f8ba3); }
.nowcard.sky-storm { background: linear-gradient(160deg, #2f3b52, #5a6a82); }
.nowcard.sky-snow { background: linear-gradient(160deg, #6f8fb0, #a9c2da); }
.nowcard .nc-top { display: flex; justify-content: space-between; align-items: flex-start; }
.nowcard .nc-name { font-size: 13.5px; font-weight: 700; }
.nowcard .nc-cn { font-size: 10px; opacity: .8; }
.nowcard .nc-emoji { font-size: 26px; line-height: 1; }
.nowcard .nc-temp { font-size: 34px; font-weight: 300; letter-spacing: -1px; margin: 4px 0 0; }
.nowcard .nc-cond { font-size: 12px; opacity: .95; }
.nowcard .nc-sub { font-size: 11px; opacity: .9; margin-top: 8px; line-height: 1.5; }
.nowcard .nc-upd { font-size: 9.5px; opacity: .75; margin-top: 6px; }

/* ---------- Tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 13px;
  box-shadow: var(--shadow);
}
.tile .tl { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; display: flex; align-items: center; gap: 4px; }
.tile .tv { font-size: 22px; font-weight: 700; margin-top: 6px; color: var(--ink); }
.tile .tvs { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.tile.warn .tv { color: var(--orange); }
.tile.danger .tv { color: var(--red); }
.tile.ok .tv { color: var(--green); }

/* ---------- Daily rows (MSN 10-day) ---------- */
.daily { background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.drow { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; border-top: 1px solid var(--line); }
.drow:first-child { border-top: none; }
.drow:active { background: #f5f8fc; }
.drow-day { width: 74px; flex-shrink: 0; }
.drow-day b { font-size: 14px; display: block; color: var(--ink); }
.drow-day span { font-size: 11px; color: var(--muted); }
.drow-emoji { font-size: 26px; width: 34px; text-align: center; flex-shrink: 0; }
.drow-mid { flex: 1; min-width: 0; }
.drow-cond { font-size: 12.5px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drow-rain { font-size: 11px; color: var(--accent); font-weight: 600; }
.drow-temps { display: flex; align-items: center; gap: 8px; width: 132px; flex-shrink: 0; }
.drow-lo { font-size: 13px; color: var(--muted); width: 26px; text-align: right; }
.drow-hi { font-size: 13px; color: var(--ink); font-weight: 600; width: 26px; }
.tempbar { flex: 1; height: 5px; border-radius: 999px; background: #e9edf3; position: relative; overflow: hidden; }
.tempbar i { position: absolute; top: 0; bottom: 0; border-radius: 999px; background: linear-gradient(90deg, #4aa3e0, #f2b705, #e8710a); }
.risk-pip { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ---------- Overview banner (used in alerts/radar) ---------- */
.banner { border-radius: 18px; padding: 16px; margin-bottom: 12px; border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow); }
.banner.risk-red { background: linear-gradient(135deg, #fff, #fdecec); border-color: #f3c6c7; }
.banner.risk-orange { background: linear-gradient(135deg, #fff, #fdf1e6); border-color: #f4d6b8; }
.banner.risk-yellow { background: linear-gradient(135deg, #fff, #fdf8e3); border-color: #efe3ab; }
.banner.risk-green { background: linear-gradient(135deg, #fff, #e9f7ef); border-color: #bfe6cf; }
.banner h2 { margin: 0 0 6px; font-size: 16px; color: var(--ink); }
.banner p { margin: 0; font-size: 13.5px; color: var(--ink2); line-height: 1.5; }
.banner .stat-row { display: flex; gap: 10px; margin-top: 12px; }
.banner .stat { flex: 1; background: #f5f8fc; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.banner .stat b { display: block; font-size: 20px; color: var(--ink); }
.banner .stat span { font-size: 11px; color: var(--muted); }

/* legacy day-card (fallback) */
.day-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.day-title { font-size: 15px; font-weight: 600; color: var(--ink); }
.day-date { font-size: 12px; color: var(--muted); }
.day-loc { font-size: 12.5px; color: var(--muted); }

.badge-risk { font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 999px; white-space: nowrap; }
.br-0, .br-1 { background: #e4f5ec; color: var(--green); }
.br-2 { background: #fdf6df; color: var(--yellow); }
.br-3 { background: #fdeede; color: var(--orange); }
.br-4 { background: #fbe3e4; color: var(--red); }

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: #f0f4f9; border: 1px solid var(--line); color: var(--ink2); }
.chip.warn { border-color: #f4d6b8; color: var(--orange); background: #fdf3e8; }
.chip.danger { border-color: #f3c6c7; color: var(--red); background: #fdecec; }
.tag { font-size: 10px; padding: 2px 7px; border-radius: 6px; background: #e7f0fb; color: var(--accent); }
.tag.climate { background: #eef0f4; color: var(--muted); }

/* Alerts */
.alert { border-radius: 14px; padding: 13px 14px; margin-bottom: 10px; border: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; background: var(--card); box-shadow: var(--shadow); }
.alert.red { border-color: #f3c6c7; background: linear-gradient(135deg,#fff,#fdecec); }
.alert.orange { border-color: #f4d6b8; background: linear-gradient(135deg,#fff,#fdf1e6); }
.alert.yellow { border-color: #efe3ab; background: linear-gradient(135deg,#fff,#fdf8e3); }
.alert .aicon { font-size: 22px; }
.alert .abody h4 { margin: 0 0 3px; font-size: 14px; color: var(--ink); }
.alert .abody p { margin: 0; font-size: 12.5px; color: var(--ink2); }
.alert .ameta { font-size: 11px; color: var(--muted); margin-top: 5px; }

/* Sources */
.src-city { margin-bottom: 18px; }
.src-city h3 { font-size: 15px; margin: 0 0 4px; color: var(--ink); }
.src-city .cn { color: var(--muted); font-weight: 400; font-size: 13px; }
.link { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; color: var(--ink); text-decoration: none; box-shadow: var(--shadow); }
.link:active { background: #f5f8fc; }
.link .ltag { font-size: 10px; color: var(--accent); background: #e7f0fb; padding: 2px 7px; border-radius: 6px; white-space: nowrap; }
.link .larrow { color: var(--muted); }
.link small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }

/* AI */
.ai-controls { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.ai-input { flex: 1; min-width: 160px; background: #fff; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); padding: 12px 14px; font-size: 14px; box-shadow: var(--shadow); }
.ai-input::placeholder { color: var(--muted); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border: none; border-radius: 12px; padding: 12px 16px; font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap; box-shadow: var(--shadow); }
.btn-primary:disabled { opacity: .6; }
.btn-secondary { background: #fff; color: var(--accent); border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; font-size: 13px; cursor: pointer; font-weight: 600; box-shadow: var(--shadow); }
.markdown { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; font-size: 14px; line-height: 1.6; color: var(--ink2); box-shadow: var(--shadow); }
.markdown h1 { font-size: 18px; margin: 4px 0 10px; color: var(--ink); }
.markdown h2 { font-size: 15.5px; margin: 18px 0 8px; color: var(--accent); }
.markdown h3 { font-size: 14px; margin: 14px 0 5px; color: var(--ink); }
.markdown ul { padding-left: 20px; margin: 6px 0; }
.markdown li { margin: 4px 0; }
.markdown p { margin: 8px 0; }
.markdown em { color: var(--muted); font-style: normal; font-size: 12.5px; }
.markdown strong { color: var(--ink); }
.markdown code { background: #eef2f7; padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.ai-note { font-size: 12.5px; color: var(--muted); margin-top: 10px; padding: 11px 12px; background: #eef3f9; border: 1px solid var(--line); border-radius: 12px; line-height: 1.5; }
.ai-note b { color: var(--ink2); }

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; max-width: 720px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255,255,255,.92); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-bot);
  box-shadow: 0 -2px 16px rgba(20,40,80,.06);
}
.tab { background: none; border: none; color: var(--muted); font-size: 10.5px; padding: 9px 4px 7px; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; position: relative; font-weight: 600; }
.tab span { font-size: 19px; }
.tab.active { color: var(--accent); }
.badge { position: absolute; top: 3px; right: 50%; transform: translateX(20px); background: var(--red); color: #fff; font-size: 10px; min-width: 16px; height: 16px; border-radius: 999px; display: grid; place-items: center; padding: 0 4px; }

/* Detail sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet.hidden, .hidden { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20,30,50,.4); }
.sheet-body { position: absolute; left: 0; right: 0; bottom: 0; max-width: 720px; margin: 0 auto; background: #f4f7fb; border-radius: 22px 22px 0 0; border: 1px solid var(--line); max-height: 90vh; overflow-y: auto; padding: 8px 16px calc(24px + var(--safe-bot)); animation: slideup .25s ease; }
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-grabber { width: 42px; height: 5px; background: #cdd6e2; border-radius: 999px; margin: 8px auto 12px; }

.model-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; }
.model-name { width: 108px; flex-shrink: 0; color: var(--ink2); font-size: 12px; }
.model-bar-wrap { flex: 1; background: #eaeef4; border-radius: 6px; height: 20px; position: relative; overflow: hidden; }
.model-bar { height: 100%; border-radius: 6px; background: linear-gradient(90deg, #4aa3e0, var(--accent)); }
.model-val { width: 62px; text-align: right; font-size: 12px; flex-shrink: 0; color: var(--ink2); }

.trend svg { width: 100%; height: 120px; display: block; }
.loading { text-align: center; padding: 40px 20px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid #dbe3ee; border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { background: #fdecec; border: 1px solid #f3c6c7; color: #a4262c; border-radius: 12px; padding: 14px; font-size: 13px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin: 4px 0 0; }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.kv .cell { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); }
.kv .cell b { font-size: 16px; display: block; color: var(--ink); }
.kv .cell span { font-size: 11px; color: var(--muted); }
.detail-h { font-size: 13px; color: var(--ink2); font-weight: 700; letter-spacing: .2px; margin: 18px 0 8px; }

/* Hourly strip */
.hourly-src { font-size: 11.5px; color: var(--muted); margin: 0 0 8px; }
.hourly-src b { color: var(--accent); }
.period-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 12px; }
.period { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 4px; text-align: center; box-shadow: var(--shadow); }
.period .pi { font-size: 18px; }
.period .pn { font-size: 9.5px; color: var(--muted); margin-top: 1px; }
.period .pr { font-size: 10px; margin-top: 2px; color: var(--ink2); }
.period .pr.rain { color: var(--accent); font-weight: 700; }

.hstrip { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px 10px; -webkit-overflow-scrolling: touch; }
.hcell { flex: 0 0 auto; width: 50px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px 3px 5px; text-align: center; box-shadow: var(--shadow); }
.hcell.now { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent); }
.hcell .hh { font-size: 10.5px; color: var(--muted); }
.hcell .he { font-size: 18px; line-height: 1.2; margin: 2px 0; }
.hcell .ht { font-size: 12.5px; font-weight: 700; color: var(--ink); }
.hbar-wrap { height: 34px; display: flex; align-items: flex-end; justify-content: center; margin: 4px 0 2px; }
.hbar { width: 10px; background: linear-gradient(180deg, #6bb2ea, var(--accent)); border-radius: 999px; min-height: 2px; }
.hmm { font-size: 9px; color: var(--accent); height: 11px; font-weight: 600; }
.hprob { font-size: 9px; color: var(--muted); }
.hconf { height: 4px; border-radius: 3px; margin-top: 4px; background: #eaeef4; overflow: hidden; }
.hconf i { display: block; height: 100%; }
.hlegend { font-size: 10.5px; color: var(--muted); margin-top: 4px; display: flex; gap: 12px; flex-wrap: wrap; }

details summary { outline: none; }
