/* ==========================================================================
   AirWatch MY — design system
   Kid-friendly skin: big rounded shapes, friendly type, emoji faces, and the
   same semantic air-quality colours underneath. Light + dark themes.
   ========================================================================== */

/* ------------------------------------------------------------------ tokens */
:root {
  color-scheme: light;

  --bg: #f5f7fc;
  --bg-inset: #e9eef8;
  --surface: #ffffff;
  --surface-hover: #f3f7ff;

  --border: #dde5f7;
  --border-strong: #bcc9e8;
  --border-w: 2px;

  --text: #131c31;
  --text-2: #4b5772;
  --text-3: #5f6a86;

  --accent: #2b6cff;
  --accent-hover: #1b57e0;
  --accent-soft: #e6eeff;
  --accent-text: #1a4fd0;

  --invert-bg: #1b4fd8;
  --invert-text: #ffffff;

  --sun: #f6a723;

  --aqi-good: #18a957;
  --aqi-good-soft: #e4f7ec;
  --aqi-moderate: #dfa700;
  --aqi-moderate-soft: #fdf3d6;
  --aqi-unhealthy: #ef7313;
  --aqi-unhealthy-soft: #fdeade;
  --aqi-very: #e0322f;
  --aqi-very-soft: #fde8e7;
  --aqi-hazardous: #8b1d2e;
  --aqi-hazardous-soft: #f7e4e8;
  --aqi-unknown: #9aa2ad;
  --aqi-unknown-soft: #edf0f6;

  /* Ink grades: the same bands, darkened so they stay readable as text on the
     light surfaces (>= 4.5:1). Fills keep the vivid grades above. */
  --aqi-good-ink: #0f7a3d;
  --aqi-moderate-ink: #7d5c00;
  --aqi-unhealthy-ink: #b34d00;
  --aqi-very-ink: #c02420;
  --aqi-hazardous-ink: #8b1d2e;
  --aqi-unknown-ink: #5f6a86;

  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius: 18px;
  --radius-lg: 26px;

  --shadow-1: 0 2px 0 rgba(19, 28, 49, .04), 0 3px 10px rgba(19, 28, 49, .05);
  --shadow-2: 0 6px 18px rgba(19, 28, 49, .09), 0 1px 3px rgba(19, 28, 49, .05);
  --shadow-3: 0 20px 46px rgba(19, 28, 49, .18);

  --font: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: "Fredoka", "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --wrap: 1180px;
  --appbar-h: 74px;
  --statebar-h: 68px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --t: 150ms var(--ease);

  --heatmap-empty: #e6ebf6;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0a0d14;
  --bg-inset: #171e2b;
  --surface: #121822;
  --surface-hover: #1b2331;

  --border: #26303f;
  --border-strong: #3b4859;

  --text: #f2f5fa;
  --text-2: #aab4c6;
  --text-3: #8b95a8;

  --accent: #4d84ff;
  --accent-hover: #6b9aff;
  --accent-soft: #17233d;
  --accent-text: #9dbcff;

  --invert-bg: #dbe6ff;
  --invert-text: #101a33;

  --sun: #ffc255;

  --aqi-good: #2dc06a;
  --aqi-good-soft: rgba(45, 192, 106, .18);
  --aqi-moderate: #e9bd21;
  --aqi-moderate-soft: rgba(233, 189, 33, .18);
  --aqi-unhealthy: #f5872f;
  --aqi-unhealthy-soft: rgba(245, 135, 47, .18);
  --aqi-very: #f0564f;
  --aqi-very-soft: rgba(240, 86, 79, .18);
  --aqi-hazardous: #d1445f;
  --aqi-hazardous-soft: rgba(209, 68, 95, .2);
  --aqi-unknown: #6b7480;
  --aqi-unknown-soft: rgba(255, 255, 255, .07);

  /* Ink grades: brightened so the bands stay readable as text on the dark
     surfaces (>= 4.5:1). Fills keep the vivid grades above. */
  --aqi-good-ink: #2dc06a;
  --aqi-moderate-ink: #e9bd21;
  --aqi-unhealthy-ink: #f5872f;
  --aqi-very-ink: #f45f59;
  --aqi-hazardous-ink: #e56a7e;
  --aqi-unknown-ink: #8b95a8;

  --shadow-1: 0 2px 0 rgba(0, 0, 0, .3), 0 3px 12px rgba(0, 0, 0, .34);
  --shadow-2: 0 8px 22px rgba(0, 0, 0, .46), 0 1px 3px rgba(0, 0, 0, .3);
  --shadow-3: 0 20px 46px rgba(0, 0, 0, .6);

  --heatmap-empty: #1e2634;
}

/* One attribute drives a whole element's air colours: ink for text, soft for
   badges. The vivid fills are still set inline by the charts. */
[data-band="good"] { --band-ink: var(--aqi-good-ink); --band-soft: var(--aqi-good-soft); --band-fill: var(--aqi-good); }
[data-band="moderate"] { --band-ink: var(--aqi-moderate-ink); --band-soft: var(--aqi-moderate-soft); --band-fill: var(--aqi-moderate); }
[data-band="unhealthy"] { --band-ink: var(--aqi-unhealthy-ink); --band-soft: var(--aqi-unhealthy-soft); --band-fill: var(--aqi-unhealthy); }
[data-band="very-unhealthy"] { --band-ink: var(--aqi-very-ink); --band-soft: var(--aqi-very-soft); --band-fill: var(--aqi-very); }
[data-band="hazardous"] { --band-ink: var(--aqi-hazardous-ink); --band-soft: var(--aqi-hazardous-soft); --band-fill: var(--aqi-hazardous); }
[data-band="unknown"] { --band-ink: var(--aqi-unknown-ink); --band-soft: var(--aqi-unknown-soft); --band-fill: var(--aqi-unknown); }

/* ------------------------------------------------------------------- reset */
*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--appbar-h) + var(--statebar-h) + 18px);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: .9375rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 { margin: 0; line-height: 1.18; font-weight: 600; font-family: var(--font-display); letter-spacing: -.01em; }
h1 { font-size: clamp(1.7rem, 3.4vw, 2.35rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.0625rem; }
p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }
svg { flex: none; }

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

.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;
}

.wrap { width: min(100% - 2.5rem, var(--wrap)); margin-inline: auto; }

/* ------------------------------------------------------------------- icons */
.sprite { display: none; }
.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}

.skip-link {
  position: absolute; left: 12px; top: -70px; z-index: 200;
  background: var(--invert-bg); color: var(--invert-text);
  padding: 10px 16px; border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-weight: 700; text-decoration: none; transition: top var(--t);
}
.skip-link:focus { top: 0; }

/* ----------------------------------------------------------------- appbar */
.appbar {
  position: sticky; top: 0; z-index: 70;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: var(--border-w) solid var(--border);
}
.appbar-inner { height: var(--appbar-h); display: flex; align-items: center; gap: 1rem; }

.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark { display: block; width: 38px; height: 38px; flex: none; }
.brand-mark svg { display: block; width: 100%; height: 100%; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; letter-spacing: -.015em; color: var(--text); }
.brand-text small { font-size: .75rem; color: var(--text-3); font-weight: 600; }

.appnav { display: flex; gap: .2rem; margin-left: .5rem; }
.appnav a {
  display: inline-flex; align-items: center; gap: .35rem;
  color: var(--text-2); font-weight: 700; font-size: .875rem;
  padding: .5rem .7rem; border-radius: 999px;
  transition: color var(--t), background var(--t); text-decoration: none;
}
.appnav a:hover, .appnav a:focus-visible { color: var(--text); background: var(--surface); text-decoration: none; }

.appbar-actions { display: flex; align-items: center; gap: .5rem; margin-left: auto; }

.status {
  display: flex; align-items: center; gap: .45rem;
  font-size: .8125rem; font-weight: 700; color: var(--text-2);
  background: var(--surface); border: var(--border-w) solid var(--border);
  padding: .35rem .7rem; border-radius: 999px; white-space: nowrap;
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--aqi-unknown); transition: background var(--t); }
.status[data-state="live"] .dot { background: var(--aqi-good); animation: pulse 2.6s infinite; }
.status[data-state="loading"] .dot { background: var(--aqi-moderate); animation: pulse 1.2s infinite; }
.status[data-state="error"] .dot { background: var(--aqi-very); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--aqi-good) 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ----------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 42px;
  border: var(--border-w) solid transparent; border-radius: 999px;
  padding: .45rem .95rem; font-family: var(--font-display); font-size: .9375rem; font-weight: 500;
  cursor: pointer; white-space: nowrap; user-select: none; text-decoration: none;
  transition: background var(--t), border-color var(--t), color var(--t), box-shadow var(--t), transform var(--t);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-1); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-hover); border-color: var(--accent); color: var(--accent-text); }
.btn-ghost { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-ghost:hover { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-sm { min-height: 36px; padding: .3rem .75rem; font-size: .875rem; }
.btn.is-busy { opacity: .6; pointer-events: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 42px; height: 42px;
  border-radius: 999px; border: var(--border-w) solid var(--border);
  background: var(--surface); color: var(--text-2); cursor: pointer;
  font-size: 1.1rem; line-height: 1;
  transition: background var(--t), color var(--t), border-color var(--t), transform var(--t);
}
.icon-btn:hover { background: var(--surface-hover); border-color: var(--border-strong); transform: translateY(-1px); }

#theme-btn .icon-sun { display: none; }
#theme-btn .icon-moon { display: block; }
[data-theme="dark"] #theme-btn .icon-sun { display: block; }
[data-theme="dark"] #theme-btn .icon-moon { display: none; }

/* -------------------------------------------------------------- state bar */
.statebar {
  position: sticky; top: var(--appbar-h); z-index: 65;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: var(--border-w) solid var(--border);
}
.statebar-inner { height: var(--statebar-h); display: flex; align-items: center; gap: .75rem; }
.statebar-label {
  font-family: var(--font-display); font-size: .875rem; font-weight: 500;
  color: var(--text-2); flex: none;
}
.state-chips { display: flex; gap: .45rem; overflow-x: auto; flex: 1; min-width: 0; padding: .3rem 0; scrollbar-width: none; }
.state-chips::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex; align-items: center; gap: .5rem; flex: none; white-space: nowrap;
  background: var(--surface); border: var(--border-w) solid var(--border);
  border-radius: 999px; padding: .28rem .55rem .28rem .3rem;
  min-height: 44px;
  cursor: pointer; font-size: .9375rem; font-weight: 700; color: var(--text);
  transition: background var(--t), color var(--t), border-color var(--t), transform var(--t), box-shadow var(--t);
}
.chip:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow-1); }
.chip.is-active { background: var(--invert-bg); border-color: var(--invert-bg); color: var(--invert-text); }
.chip-flag {
  width: 30px; height: 15px; flex: none; border-radius: 3px; object-fit: cover;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--text) 16%, transparent);
}
.chip.is-active .chip-flag { box-shadow: 0 0 0 1px color-mix(in srgb, #ffffff 45%, transparent); }
.chip-name { line-height: 1.2; }
.chip-count {
  font-size: .75rem; font-weight: 800; border-radius: 999px; padding: .15rem .5rem;
  background: var(--band-soft, var(--bg-inset)); color: var(--band-ink, var(--text-2));
  font-variant-numeric: tabular-nums;
}
.chip.is-active .chip-count {
  /* On the active chip the pill is outlined, not tinted: a tinted pill over the inverted
     background drops the count below the 4.5:1 contrast floor. */
  background: transparent; color: inherit;
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, currentColor 38%, transparent);
}
.chip-pin-mark { width: 15px; height: 15px; color: var(--accent-text); }
.chip.is-active .chip-pin-mark { color: inherit; }

/* ------------------------------------------------------------- face badge */
.face {
  --face-size: 38px;
  display: inline-grid; place-items: center; flex: none;
  width: var(--face-size); height: var(--face-size);
  border-radius: 999px; font-size: calc(var(--face-size) * .58); line-height: 1;
  background: var(--band-soft, var(--bg-inset));
  border: var(--border-w) solid color-mix(in srgb, var(--band-ink, var(--border-strong)) 30%, transparent);
}
.face-lg { --face-size: 58px; }

/* --------------------------------------- change since the previous reading */
.delta {
  display: inline-block; vertical-align: middle; margin-left: .4rem;
  font-family: var(--font-display); font-size: .8125rem; font-weight: 500;
  line-height: 1.15; padding: .1rem .4rem; border-radius: 999px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.delta-up { background: var(--aqi-unhealthy-soft); color: var(--text); }
.delta-down { background: var(--aqi-good-soft); color: var(--text); }
.delta-flat { background: var(--bg-inset); color: var(--text-2); }
/* The heat map's place column is narrow, so the chip shrinks there. */
.hm-current .delta { font-size: .6875rem; padding: .05rem .3rem; margin-left: .3rem; }

/* ----------------------------------------------------------------- layout */
.section { padding: 1.5rem 0 0; }
.card {
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 1.3rem 1.4rem 1.5rem;
}
.card-head { margin-bottom: 1.1rem; }
.card-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.card-note { color: var(--text-2); font-size: .9375rem; margin-top: .25rem; }

.toolbar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.toolbar-secondary { margin-bottom: 1rem; }
.toolbar-count { font-size: .875rem; font-weight: 700; color: var(--text-3); margin-left: auto; font-variant-numeric: tabular-nums; }

.field { display: flex; flex-direction: column; }
.field-search { flex: 1 1 220px; max-width: 320px; }
.field select, .field input {
  background: var(--surface); border: var(--border-w) solid var(--border-strong);
  border-radius: 999px; padding: .5rem 1rem;
  font-size: .9375rem; font-weight: 600; color: var(--text);
  min-height: 44px; min-width: 156px; width: 100%;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
.field-search input { padding-left: 2.4rem; }
.field-search { position: relative; }
.field-search .search-icon {
  position: absolute; left: .9rem; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; color: var(--text-3); pointer-events: none;
}
.field select:hover, .field input:hover { border-color: var(--text-3); }
.field select:focus, .field input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft);
}
.field input::placeholder { color: var(--text-3); }

/* --------------------------------------------------------------- overview */
.overview { padding: 1.6rem 0 .25rem; }

.scope-head { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.scope-title { letter-spacing: -.02em; }
.scope-meta { color: var(--text-2); font-size: .9375rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: .3rem; }
.scope-flag {
  width: 34px; height: 17px; border-radius: 4px; object-fit: cover;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--text) 16%, transparent);
}
.pin-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent-text); }
.freshline { color: var(--text-3); font-size: .8125rem; font-weight: 700; margin-top: .3rem; }

/* The air buddy: one line that answers "can I go out and play?" */
.buddy {
  display: flex; align-items: center; gap: 1.1rem;
  margin-top: 1.1rem; padding: 1rem 1.3rem;
  border-radius: var(--radius-lg);
  border: var(--border-w) solid color-mix(in srgb, var(--band-ink, var(--border-strong)) 32%, transparent);
  background: var(--band-soft, var(--surface));
  box-shadow: var(--shadow-1);
  transition: background var(--t), border-color var(--t);
}
.buddy-face {
  display: grid; place-items: center; flex: none;
  width: 62px; height: 62px; border-radius: 999px;
  font-size: 34px; line-height: 1;
  background: var(--surface); box-shadow: var(--shadow-1);
}
.buddy-say { min-width: 0; }
.buddy-text {
  font-family: var(--font-display); font-size: clamp(1.05rem, 2.4vw, 1.3rem);
  font-weight: 500; color: var(--text); letter-spacing: -.01em;
}
.buddy-hint { font-size: .8125rem; font-weight: 600; color: var(--text-2); margin-top: .2rem; }

/* --------------------------------------------- stations in the chosen state */
.stations-panel {
  margin-top: 1.25rem;
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 1.2rem 1.3rem 1.4rem;
}
.stations-panel-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: .85rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.stations-panel-note { color: var(--text-2); font-size: .9375rem; margin-top: .25rem; }

.station-list { display: flex; flex-direction: column; gap: .5rem; margin: 0; padding: 0; list-style: none; }
.station-item {
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius); background: var(--surface);
  overflow: hidden;
  transition: border-color var(--t), background var(--t);
}
.station-item:hover { border-color: var(--border-strong); }
.station-item.is-open { border-color: var(--accent); background: var(--surface-hover); }
.station-heading { margin: 0; font: inherit; letter-spacing: normal; }

.station-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center; gap: .85rem; width: 100%;
  padding: .7rem .9rem; border: 0; border-radius: 0;
  background: none; font: inherit; color: inherit; text-align: left; cursor: pointer;
  min-height: 68px;
  transition: background var(--t);
}
.station-row:hover { background: var(--bg-inset); }
.station-name { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.station-name strong {
  font-family: var(--font-display); font-size: 1.125rem; font-weight: 500;
  letter-spacing: -.015em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.station-name small { color: var(--text-3); font-size: .8125rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.station-api {
  font-family: var(--font-display); font-size: 1.75rem; font-weight: 600;
  color: var(--band-ink, var(--text)); line-height: 1; font-variant-numeric: tabular-nums;
}
.station-api sup { font-size: .5em; color: var(--text-3); margin-left: 1px; }
.station-chevron {
  width: 18px; height: 18px; color: var(--text-3); transition: transform var(--t);
}
.station-row[aria-expanded="true"] .station-chevron { transform: rotate(180deg); }
.station-row[aria-expanded="true"] { background: var(--bg-inset); }

.station-panel { padding: .1rem .9rem 1.2rem; }
.station-empty { color: var(--text-3); font-size: .9375rem; font-weight: 600; padding: .3rem 0 1rem; }
.station-chart { margin: .35rem 0 .7rem; }

/* The chart is themed through CSS so it repaints with the rest of the page. */
.stc { display: block; width: 100%; height: auto; overflow: visible; }
.stc-grid { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 4 5; stroke-opacity: .7; }
.stc-grid-label { fill: var(--text-3); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stc-area { stroke: none; fill-opacity: .16; }
.stc-line { fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.stc-dot { stroke: var(--surface); stroke-width: 1.6; }

.station-trend {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .9375rem; font-weight: 700; color: var(--text);
  background: var(--bg-inset); border-radius: 999px; padding: .35rem .8rem;
  margin-bottom: .7rem;
}
.trend-icon { width: 17px; height: 17px; }
.trend-up { color: var(--aqi-unhealthy-ink); }
.trend-down { color: var(--aqi-good-ink); }
.trend-flat { color: var(--text-3); }
.station-cells { display: flex; gap: 3px; height: 16px; }
.stc-cell { flex: 1 1 0; min-width: 0; border-radius: 4px; background: var(--heatmap-empty); }
.station-times {
  display: flex; justify-content: space-between; gap: .5rem; margin-top: .35rem;
  color: var(--text-3); font-size: .75rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.station-stats {
  display: flex; flex-wrap: wrap; gap: .4rem .5rem; margin-top: .9rem;
  font-variant-numeric: tabular-nums;
}
.station-stats span {
  display: inline-flex; align-items: baseline; gap: .35rem;
  background: var(--bg-inset); border-radius: 999px; padding: .3rem .75rem;
  color: var(--text-2); font-size: .875rem; font-weight: 700;
}
.station-stats b { color: var(--text); font-weight: 800; font-size: 1rem; }

/* ------------------------------------------------- national overview (landing)
   The "All Malaysia" scope reads like a data desk: the country's extremes in
   two ranked lists, then every state ranked. Nothing is averaged across the
   whole country — one national number would mix a city street with a
   rainforest. State scope keeps the friendlier buddy + place list instead. */
.national { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; margin-top: 1.15rem; }

/* Ranked places: the extremes of the country, one tap from their own trend. */
.nrank { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.nlist h2 { font-size: 1.15rem; }
.nlist .card-head { margin-bottom: .55rem; }
.nplaces { list-style: none; margin: 0; padding: 0; }
.nplaces li + li { border-top: 1px solid var(--border); }
.nplace {
  display: grid; grid-template-columns: 1.5rem minmax(0, 1fr) auto auto;
  align-items: center; gap: .65rem; width: 100%; min-height: 54px;
  padding: .5rem .35rem; border: 0; border-radius: var(--radius-xs);
  background: none; font: inherit; color: inherit; text-align: left; cursor: pointer;
  transition: background var(--t);
}
.nplace:hover { background: var(--bg-inset); }
.nplace-rank { font-size: .875rem; font-weight: 800; color: var(--text-3); font-variant-numeric: tabular-nums; }
.nplace-name { min-width: 0; }
.nplace-name strong {
  display: block; font-size: .9375rem; font-weight: 800;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nplace-name small {
  display: block; font-size: .75rem; font-weight: 700; color: var(--text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nplace-api {
  display: inline-flex; align-items: center;
  font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums;
  color: var(--band-ink, var(--text));
}
.nplace-go { width: 16px; height: 16px; color: var(--text-3); transform: rotate(-90deg); }

/* Ranked states: a dense table, the way a data desk would print it. */
.nstates .card-head { margin-bottom: .7rem; }
.ntable-scroll { overflow-x: auto; }
.ntable { width: 100%; border-collapse: collapse; font-size: .9375rem; font-variant-numeric: tabular-nums; }
.ntable th, .ntable td { padding: .5rem .55rem; text-align: left; vertical-align: middle; }
.ntable thead th {
  font-size: .6875rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-3); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.ntable tbody tr + tr { border-top: 1px solid var(--border); }
.ntable tbody tr:hover { background: var(--bg-inset); }
/* The whole row is the tap target for a state; the flag and name stay a real
   button, so keyboard and screen-reader users keep one too. */
.ntable tbody tr[data-state] { cursor: pointer; }
.ntable tbody tr[data-state]:focus-within { background: var(--bg-inset); }
.nt-rank { width: 2.2rem; color: var(--text-3); font-weight: 800; }
.nt-num { text-align: right; white-space: nowrap; }
.nt-places { color: var(--text-2); font-weight: 700; }
.nt-air { width: 1%; white-space: nowrap; }
.nt-state-btn {
  display: inline-flex; align-items: center; gap: .55rem; max-width: 100%;
  margin: -.15rem -.25rem; padding: .15rem .25rem;
  border: 0; border-radius: var(--radius-xs); background: none;
  font: inherit; font-weight: 800; color: var(--text); text-align: left; cursor: pointer;
  transition: color var(--t), background var(--t);
}
.nt-state-btn:hover { color: var(--accent-text); background: var(--accent-soft); }
.nt-flag {
  flex: none; width: 26px; height: 13px; border-radius: 3px; object-fit: cover;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--text) 16%, transparent);
}
/* Each state's most polluted place: the name, then its reading and bar — on one
   line when the cell has room, wrapping under the name when it does not. The
   min-width keeps the reading beside the name instead of squeezing it. */
.nt-place {
  font-size: .875rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .15rem .75rem;
}
.nt-place-name { font-weight: 800; min-width: 7.5ch; }
.nt-worst-value { display: inline-flex; align-items: center; gap: .55rem; }
.nt-worst-value b { font-size: 1.05rem; font-weight: 800; color: var(--band-ink, var(--text)); }
.nt-bar { flex: none; width: 56px; height: 6px; border-radius: 999px; background: var(--bg-inset); overflow: hidden; }
.nt-bar i { display: block; height: 100%; border-radius: 999px; background: var(--band-fill, var(--aqi-unknown)); }
.nt-pill { font-size: .75rem; padding: .2rem .6rem; }

/* Placeholder rows, shown until the first snapshot lands. They reuse the real
   row classes so the landing keeps its height — nothing jumps when the data
   arrives and JS swaps the three containers' contents. */
.sk-line {
  display: inline-block; vertical-align: middle;
  background: var(--bg-inset); border-radius: 999px;
}
.nplace.sk-row { cursor: default; pointer-events: none; }
.nplace.sk-row:hover { background: none; }
.nplace-name strong.sk-line { width: 7.5rem; max-width: 80%; }
.nplace-name small.sk-line { width: 4.5rem; max-width: 50%; }
.nplace-api .sk-line { width: 2.6rem; height: 1.1rem; }
.nt-rank .sk-line { width: 1rem; }
.sk-state { width: 6rem; max-width: 100%; }
.nt-places .sk-line { width: 1.2rem; }
.sk-num { width: 2rem; }
.sk-place { display: block; width: 6rem; max-width: 70%; }
.sk-pill { width: 3.4rem; }

/* The same two cards when the stations have nothing to say. */
.nplace-empty, .nt-empty { color: var(--text-3); font-weight: 700; }
.nplace-empty { padding: .9rem .35rem; }
.ntable td.nt-empty { padding: .9rem .55rem; }

/* ----------------------------------------------------------- distribution */
.dist-bar {
  display: flex; height: 16px; border-radius: 999px; overflow: hidden;
  background: var(--bg-inset); gap: 3px;
}
.dist-seg {
  height: 100%; border-radius: 6px; min-width: 0; overflow: hidden;
  font-size: 0; color: transparent;
  transition: flex-grow .5s var(--ease);
}
.dist-empty { flex: 1; background: var(--bg-inset); }
.dist-legend { list-style: none; margin: 1rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .45rem; }
.dist-legend li {
  display: flex; align-items: center; gap: .45rem; font-size: .9375rem; font-weight: 700;
  color: var(--text-2); background: var(--bg-inset);
  border-radius: 999px; padding: .3rem .85rem .3rem .4rem;
}
.dist-legend .face { --face-size: 30px; }
.dist-legend .count { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- segmented */
.segmented {
  display: inline-flex; background: var(--bg-inset); border: var(--border-w) solid var(--border);
  border-radius: 999px; padding: 3px; gap: 3px;
}
.segmented button {
  display: inline-flex; align-items: center; gap: .35rem;
  border: 0; background: transparent; cursor: pointer; border-radius: 999px;
  padding: .45rem .85rem; font-family: var(--font-display); font-size: .9375rem; font-weight: 500;
  color: var(--text-2); min-height: 38px;
  transition: background var(--t), color var(--t), box-shadow var(--t);
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

.panel { animation: fade .18s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.panel-hint { color: var(--text-2); font-size: .875rem; font-weight: 700; margin-bottom: .7rem; }

/* ----------------------------------------------------------------- heatmap */
.hm-scroll { overflow: auto; max-height: 620px; border: var(--border-w) solid var(--border); border-radius: var(--radius); padding: 0 0 .4rem; }
.heatmap { border-collapse: separate; border-spacing: 3px; font-size: .8125rem; width: max-content; }
.heatmap thead th {
  position: sticky; top: 0; z-index: 3; background: var(--surface);
  font-family: var(--font-display); font-size: .6875rem; font-weight: 500; color: var(--text-3);
  padding: 0; height: 28px; text-align: center;
  border-bottom: var(--border-w) solid var(--border);
}
.heatmap thead th.hm-hour { width: 22px; min-width: 22px; }
.heatmap thead th.hm-now { color: var(--text); }

.heatmap th.hm-station {
  position: sticky; left: 0; z-index: 4; background: var(--surface);
  text-align: left; padding: .25rem .6rem; width: 244px; min-width: 244px;
  vertical-align: middle;
}
.heatmap thead th.hm-station {
  z-index: 5; font-size: .6875rem; color: var(--text-3); font-weight: 500;
  vertical-align: bottom; padding-bottom: .45rem;
}
.hm-station-inner { display: flex; align-items: center; gap: .5rem; min-width: 0; line-height: 1.2; }
.hm-station-inner .face { --face-size: 28px; }
.hm-text { display: flex; align-items: baseline; gap: .4rem; min-width: 0; flex: 1; }
.hm-name { font-weight: 700; font-size: .875rem; color: var(--text); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hm-meta { font-size: .6875rem; color: var(--text-3); font-weight: 700; white-space: nowrap; flex: none; font-variant-numeric: tabular-nums; }
.hm-current {
  font-family: var(--font-display); font-weight: 600; font-size: 1.0625rem; line-height: 1.2;
  color: var(--band-ink, var(--text)); font-variant-numeric: tabular-nums; flex: none; margin-left: auto;
}

.hm-row th.hm-station { transition: background var(--t); }
.hm-row:hover th.hm-station { background: var(--bg-inset); }
.hm-cell { width: 24px; min-width: 24px; height: 24px; padding: 0; border-radius: 5px; transition: transform var(--t); }
.hm-cell[data-empty] { background: var(--heatmap-empty); }
.hm-row:hover .hm-cell { transform: scale(1.1); }

.hm-legend { display: flex; flex-wrap: wrap; gap: .4rem .45rem; margin-top: 1rem; }
.hm-legend .row {
  display: flex; align-items: center; gap: .4rem; font-size: .875rem; font-weight: 700;
  color: var(--text-2); background: var(--bg-inset); border-radius: 999px; padding: .25rem .75rem .25rem .45rem;
}
.hm-legend .row em { font-style: normal; color: var(--text-3); font-variant-numeric: tabular-nums; }
.hm-legend .swatch { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.hm-placeholder { padding: 2.5rem 1rem; text-align: center; color: var(--text-3); font-weight: 700; font-size: .9375rem; }

/* ---------------------------------------------------------- station cards */
.station-cards { display: grid; gap: .85rem; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.station-card {
  display: flex; flex-direction: column; gap: .55rem; text-align: left; font: inherit; color: inherit;
  background: var(--surface); border: var(--border-w) solid var(--border);
  border-radius: var(--radius); padding: .9rem 1rem;
  transition: border-color var(--t), box-shadow var(--t), transform var(--t);
}
.station-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-2); transform: translateY(-2px); }
.card-top { display: flex; align-items: center; gap: .6rem; }
.card-name { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.card-name strong {
  font-family: var(--font-display); font-size: 1rem; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-name small { font-size: .75rem; color: var(--text-3); font-weight: 700; }
.card-api {
  font-family: var(--font-display); font-size: 1.75rem; font-weight: 600; line-height: 1;
  letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--band-ink, var(--text));
}
.card-api sup { font-size: .42em; color: var(--text-3); }
.card-spark { display: block; height: 38px; }
.spark { width: 100%; height: 38px; display: block; }
.card-stats { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; font-size: .8125rem; color: var(--text-3); font-weight: 700; }
.card-stats strong { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }
.card-pill { margin-left: auto; }

/* ------------------------------------------------------------------ table */
.table-scroll { overflow-x: auto; border: var(--border-w) solid var(--border); border-radius: var(--radius); }
.stations-table { width: 100%; border-collapse: collapse; font-size: .9375rem; min-width: 780px; }
.stations-table thead th {
  text-align: left; font-family: var(--font-display); font-size: .8125rem; font-weight: 500;
  color: var(--text-2); padding: .7rem .9rem;
  background: var(--bg-inset); border-bottom: var(--border-w) solid var(--border);
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
.stations-table tbody tr { border-bottom: 1px solid var(--border); transition: background var(--t); }
.stations-table tbody tr:last-child { border-bottom: 0; }
.stations-table tbody tr:hover { background: var(--surface-hover); }
.stations-table td { padding: .6rem .9rem; vertical-align: middle; }
.stations-table thead th:first-child, .stations-table tbody td:first-child { min-width: 210px; }
.cell-station { display: flex; flex-direction: column; }
.cell-station strong { font-weight: 800; }
.cell-id { color: var(--text-3); font-size: .75rem; font-weight: 700; letter-spacing: .02em; }
.api-cell {
  font-family: var(--font-display); font-weight: 600; font-variant-numeric: tabular-nums;
  font-size: 1.25rem; color: var(--band-ink, var(--text));
}
.api-cell sup { font-size: .5em; color: var(--text-3); margin-left: 1px; }
.cell-spark { width: 160px; padding: .35rem .9rem; }
.cell-spark .spark { height: 28px; }
.cell-range { font-variant-numeric: tabular-nums; color: var(--text-2); font-weight: 700; white-space: nowrap; }
.muted { color: var(--text-3); font-size: .8125rem; font-weight: 700; }

.pill {
  display: inline-flex; align-items: center; gap: .35rem;
  border-radius: 999px; padding: .25rem .7rem;
  font-size: .8125rem; font-weight: 800; white-space: nowrap;
  background: var(--band-soft, var(--bg-inset)); color: var(--band-ink, var(--text-2));
}

.empty-state { text-align: center; color: var(--text-3); padding: 2rem 0 1rem; font-weight: 700; }

/* ------------------------------------------------------------------ help */
.air-grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr)); margin: 1.25rem 0; }
.air-item {
  border: var(--border-w) solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.05rem; background: var(--bg-inset);
  box-shadow: inset 6px 0 0 var(--band-fill, var(--aqi-unknown));
}
.air-item strong { display: block; font-family: var(--font-display); font-size: 1.125rem; font-weight: 500; margin-top: .5rem; }
.air-item .range { display: block; font-size: .8125rem; color: var(--text-3); font-weight: 700; font-variant-numeric: tabular-nums; margin-top: .1rem; }
.air-item .do { display: block; font-size: .9375rem; color: var(--text-2); margin-top: .45rem; }

.about-sub { margin: 1.6rem 0 .6rem; }
.about-text { color: var(--text-2); max-width: 74ch; margin-bottom: .7rem; }
.about-text strong { color: var(--text); font-weight: 800; }
.about-text a, .disclaimer a, .site-footer a { text-decoration: underline; text-underline-offset: 2px; }
.disclaimer {
  font-size: .875rem; color: var(--text-2); margin-top: 1rem;
  border-top: var(--border-w) solid var(--border); padding-top: 1rem;
}

/* ----------------------------------------------------------------- footer */
.site-footer { margin-top: 2.5rem; padding: 1.6rem 0 2.75rem; border-top: var(--border-w) solid var(--border); }
.footer-inner { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.site-footer p { font-size: .875rem; color: var(--text-2); font-weight: 700; }

/* -------------------------------------------------------------- loading */
.loading-block { display: flex; align-items: center; gap: .6rem; color: var(--text-2); font-weight: 700; font-size: .9375rem; padding: 1.25rem 0 .25rem; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  border: 3px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------- responsive */
@media (max-width: 980px) {
  .appnav { display: none; }
  .status { display: none; }
}
@media (max-width: 700px) {
  :root { --appbar-h: 64px; --statebar-h: 62px; }
  .brand-mark { width: 36px; height: 36px; font-size: 20px; border-radius: 12px; }
  .wrap { width: min(100% - 1.5rem, var(--wrap)); }
  .overview { padding: 1.25rem 0 .25rem; }
  .statebar-label { display: none; }
  .card { padding: 1.1rem 1rem 1.25rem; border-radius: var(--radius); }
  .stations-panel { padding: 1rem .9rem 1.1rem; }
  .buddy { gap: .8rem; padding: .9rem 1rem; }
  .buddy-face { width: 50px; height: 50px; font-size: 27px; }
  .station-row { grid-template-columns: auto minmax(0, 1fr) auto; gap: .6rem; padding: .65rem .7rem; }
  .station-chevron { display: none; }
  .station-api { font-size: 1.5rem; }
  .station-name strong { font-size: 1.0625rem; }
  .toolbar { width: 100%; }
  .field-search { max-width: none; }
  .station-cards { grid-template-columns: 1fr; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; text-align: center; justify-content: center; }
  .heatmap th.hm-station { width: 196px; min-width: 196px; }
  .col-state { display: none; }
  /* The landing keeps its ranked lists and state table full width. */
  .ntable { font-size: .875rem; }
  .ntable th, .ntable td { padding: .5rem .4rem; }
  .nt-places { display: none; }
  .nt-bar { width: 40px; }
}

/* Small phones: the state table drops to four tight columns so the page never
   needs a sideways scroll. */
@media (max-width: 560px) {
  .ntable { font-size: .8125rem; }
  .ntable th, .ntable td { padding: .45rem .3rem; }
  .nt-rank { width: 1.3rem; }
  .nt-state-btn { gap: .4rem; }
  .nt-flag { width: 22px; height: 11px; }
  .nt-worst-value { gap: .4rem; }
  .nt-bar { width: 28px; }
  .nt-pill { font-size: .6875rem; padding: .18rem .45rem; }
  /* Long headers and the longest band name wrap instead of forcing the table
     into a sideways scroll on a phone. */
  .ntable thead th { white-space: normal; }
  .nt-air, .nt-pill { white-space: normal; }
}

/* Tiny phones (320): the flag gives up its 26px so the state, its most polluted
   place and the band's name all still fit without a sideways scroll. */
@media (max-width: 360px) {
  .ntable th, .ntable td { padding: .45rem .2rem; }
  .nt-rank { width: 1rem; }
  .nt-flag { display: none; }
  .nt-bar { width: 24px; }
  .nt-worst-value { gap: .35rem; }
  .nt-pill { font-size: .625rem; padding: .16rem .4rem; }
}

/* Very small phones: keep the bar on one line by making Refresh icon-only. */
@media (max-width: 430px) {
  #refresh-btn .btn-label { display: none; }
  #refresh-btn { width: 42px; padding: 0; }
  .brand-text strong { font-size: 1.05rem; }
  /* The change chip tucks under the number so the middle column keeps its width
     and "Best · Worst" stays on two lines instead of three. */
  .station-api { display: inline-flex; flex-direction: column; align-items: flex-end; gap: .15rem; }
  .station-api .delta { margin-left: 0; font-size: .6875rem; padding: .04rem .3rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  html { scroll-behavior: auto; }
}

@media print {
  .appbar, .statebar, .toolbar, .site-footer { display: none !important; }
}
