:root {
  --bg: #f6efe4;
  --bg-2: #efe5d5;
  --surface: rgba(255, 252, 246, 0.82);
  --surface-solid: #fffcf6;
  --line: rgba(60, 45, 25, 0.12);
  --text: #2a2218;
  --muted: #74685a;
  --good: #23905a;
  --moderate: #2f78bd;
  --unhealthy: #d9822b;
  --very: #c8372d;
  --hazardous: #7d2a6b;
  --none: #9a8d7c;
  --accent: var(--none);
  --radius: 20px;
  --font: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --num: ui-rounded, "SF Pro Rounded", -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1712;
    --bg-2: #241e17;
    --surface: rgba(43, 36, 28, 0.78);
    --surface-solid: #2b241c;
    --line: rgba(255, 236, 210, 0.1);
    --text: #f5ece0;
    --muted: #b5a690;
    --good: #43b97b;
    --moderate: #5aa0e0;
    --unhealthy: #f0a04b;
    --very: #ef5d50;
    --hazardous: #c162ad;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1712; --bg-2: #241e17; --surface: rgba(43,36,28,.78); --surface-solid: #2b241c;
  --line: rgba(255,236,210,.1); --text: #f5ece0; --muted: #b5a690;
  --good: #43b97b; --moderate: #5aa0e0; --unhealthy: #f0a04b; --very: #ef5d50; --hazardous: #c162ad;
}

body[data-band="good"] { --accent: var(--good); }
body[data-band="moderate"] { --accent: var(--moderate); }
body[data-band="unhealthy"] { --accent: var(--unhealthy); }
body[data-band="very"] { --accent: var(--very); }
body[data-band="hazardous"] { --accent: var(--hazardous); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-x: hidden;
}
.haze-bg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(120% 60% at 20% -10%, color-mix(in srgb, var(--accent) 38%, transparent), transparent 70%),
    radial-gradient(90% 50% at 100% 10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
    linear-gradient(var(--bg), var(--bg-2));
  transition: background 0.6s ease;
}
a { color: inherit; text-underline-offset: 3px; }
button { font: inherit; color: inherit; cursor: pointer; }

.top, main, .foot { max-width: 720px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 16px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  background: radial-gradient(circle at 35% 35%, #ffd27a 0 28%, transparent 30%),
              linear-gradient(160deg, #e58a3a, #8f4a2a);
  box-shadow: inset 0 -6px 0 rgba(255,255,255,.18);
}
h1 { margin: 0; font-size: 1.05rem; letter-spacing: -0.01em; }
h1 span { color: var(--accent); }
.updated { margin: 0; font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; flex: none;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.icon-btn.small { width: 32px; height: 32px; font-size: 0.8rem; }
.icon-btn.spin svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Hero */
.hero { padding: 28px 0 8px; }
.eyebrow { margin: 0; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); font-weight: 600; }
.status { margin: 6px 0 4px; font-size: clamp(2.1rem, 9vw, 3.2rem); line-height: 1.02; letter-spacing: -0.03em; color: var(--accent); transition: color .4s; }
.status-sub { margin: 0 0 20px; color: var(--muted); font-size: 0.95rem; max-width: 46ch; }

.hero-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.metric {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 14px 14px; min-width: 0;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  --c: var(--none);
}
.metric::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--c); }
.metric header { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.metric-label { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.02em; }
.metric-value { font-family: var(--num); font-size: clamp(3.2rem, 17vw, 4.6rem); font-weight: 700; line-height: 1; margin: 10px 0 6px; letter-spacing: -0.04em; color: var(--c); font-variant-numeric: tabular-nums; }
.metric-range { margin: 0; font-size: 0.82rem; font-weight: 600; }
.metric-note { margin: 4px 0 0; font-size: 0.72rem; color: var(--muted); }

.chip {
  display: inline-block; font-size: 0.68rem; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--c, var(--accent)) 16%, transparent); color: var(--c, var(--accent));
  white-space: nowrap;
}
.stale { margin: 12px 0 0; font-size: 0.8rem; padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--unhealthy) 14%, transparent); }

/* Install */
.install {
  display: flex; align-items: center; gap: 12px; margin: 16px 0 0; padding: 12px 12px 12px 16px;
  border-radius: 16px; background: var(--surface); border: 1px dashed color-mix(in srgb, var(--accent) 60%, var(--line));
}
.install > div { flex: 1; min-width: 0; }
.install strong { font-size: 0.9rem; }
.install p { margin: 2px 0 0; font-size: 0.8rem; color: var(--muted); }
.btn {
  border: 0; border-radius: 999px; padding: 10px 18px; font-weight: 700; font-size: 0.9rem;
  background: var(--text); color: var(--bg);
}

/* Cards */
.card {
  margin: 16px 0 0; padding: 18px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.card h3 { margin: 0; font-size: 1.05rem; letter-spacing: -0.01em; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.hint { margin: 8px 0 12px; font-size: 0.75rem; color: var(--muted); text-align: center; }

.seg { display: inline-flex; background: color-mix(in srgb, var(--text) 7%, transparent); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.seg button[aria-selected="true"] { background: var(--surface-solid); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* Compass map */
.compass {
  display: grid; gap: 8px;
  grid-template-columns: 1fr 1.15fr 1fr;
  grid-template-areas: ". n ." "w c e" ". s .";
}
.tile {
  --c: var(--none);
  border: 0; border-radius: 16px; padding: 12px 6px; min-height: 84px;
  background: color-mix(in srgb, var(--c) 18%, var(--surface-solid));
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--c) 45%, transparent);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: transform .15s, box-shadow .15s;
}
.tile:active { transform: scale(0.97); }
.tile.sel { box-shadow: inset 0 0 0 3px var(--c); }
.tile .r { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; color: var(--muted); }
.tile .v { font-family: var(--num); font-size: 1.9rem; font-weight: 700; line-height: 1.05; color: var(--c); font-variant-numeric: tabular-nums; }
.tile .d { font-size: 0.68rem; font-weight: 600; }

.table-wrap { overflow-x: auto; }
.regions { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.regions th { text-align: right; font-size: 0.7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.regions th:first-child, .regions td:first-child { text-align: left; }
.regions td { text-align: right; padding: 10px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; font-weight: 600; }
.regions tr:last-child td { border-bottom: 0; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: middle; }
.regions td .u { font-size: 0.7rem; color: var(--muted); font-weight: 500; }

/* Trend */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 12px; font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.chips button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .l24 { fill: none; stroke: var(--text); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .l1 { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 4 4; stroke-linejoin: round; stroke-linecap: round; }
.chart .band { opacity: 0.1; }
.chart .last { fill: var(--text); }
.legend { display: flex; gap: 16px; font-size: 0.75rem; color: var(--muted); margin-top: 8px; }
.sw { display: inline-block; width: 18px; height: 0; border-top: 2.5px solid var(--text); vertical-align: middle; margin-right: 6px; }
.sw-1 { border-top: 2px dashed var(--accent); }

/* Advice */
.advice-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 10px; }
.advice-list li { display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: start; }
.advice-list .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 15%, transparent); font-size: 1rem; }
.advice-list b { display: block; font-size: 0.85rem; }
.advice-list span { font-size: 0.85rem; color: var(--muted); }
#advice-chip { --c: var(--accent); }

/* Scale */
.scale { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 6px; }
.scale li { display: flex; gap: 10px; align-items: center; font-size: 0.88rem; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--c) 12%, transparent); border-left: 4px solid var(--c); }
.scale li b { min-width: 64px; font-variant-numeric: tabular-nums; }
.scale li[data-b="good"] { --c: var(--good); }
.scale li[data-b="moderate"] { --c: var(--moderate); }
.scale li[data-b="unhealthy"] { --c: var(--unhealthy); }
.scale li[data-b="very"] { --c: var(--very); }
.scale li[data-b="hazardous"] { --c: var(--hazardous); }
details { font-size: 0.85rem; color: var(--muted); }
summary { cursor: pointer; font-weight: 600; color: var(--text); padding: 6px 0; }

.foot { padding-top: 20px; padding-bottom: 32px; font-size: 0.75rem; color: var(--muted); text-align: center; }
.foot p { margin: 4px 0; }

/* iOS sheet */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet[hidden] { display: none; }
.sheet-card { background: var(--surface-solid); width: 100%; max-width: 480px; border-radius: 22px 22px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom)); }
.sheet-card h3 { margin: 0 0 10px; }
.sheet-card ol { padding-left: 20px; margin: 0 0 18px; }
.sheet-card li { margin: 8px 0; }
.sheet-card svg { vertical-align: -3px; }
.sheet-card .btn { width: 100%; }

[hidden] { display: none !important; }

@media (min-width: 560px) {
  .hero { padding-top: 40px; }
  .metric { padding: 18px; }
  .tile { min-height: 96px; }
}
@media (max-width: 350px) {
  .hero-cards { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
