:root {
  --bg: #fbfbfa;
  --fg: #1c1c1e;
  --muted: #8a8a8e;
  --line: #ececec;
  --card: #ffffff;
  /* CPCB NAQI colours, toned for screen */
  --c0: #2e9e5b;
  --c1: #8cc04b;
  --c2: #e3b417;
  --c3: #f08a24;
  --c4: #e0403a;
  --c5: #9b1d2a;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f10;
    --fg: #ececed;
    --muted: #7c7c82;
    --line: #222226;
    --card: #161618;
    --c5: #c8344a;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 48px 20px 32px;
}

h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 24px;
}

a { color: inherit; text-decoration: none; }

/* ---------- GRAP ---------- */

.grap {
  display: grid;
  grid-template-columns: 1fr auto;
  row-gap: 4px;
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 32px;
  transition: border-color .15s;
}
.grap:hover { border-color: var(--muted); }

.grap-region, #grap-since { color: var(--muted); font-size: 13px; }
#grap-since { text-align: right; }
.grap strong {
  grid-column: 1 / -1;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.meter {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  list-style: none;
  margin-top: 12px;
}
.meter li { height: 4px; border-radius: 2px; background: var(--line); }
.grap[data-stage="1"] .meter li:nth-child(-n+1) { background: var(--c2); }
.grap[data-stage="2"] .meter li:nth-child(-n+2) { background: var(--c3); }
.grap[data-stage="3"] .meter li:nth-child(-n+3) { background: var(--c4); }
.grap[data-stage="4"] .meter li:nth-child(-n+4) { background: var(--c5); }

/* ---------- Cities ---------- */

.cities { list-style: none; }

.cities li {
  display: grid;
  grid-template-columns: 1fr 96px 3.5ch 6.5rem 20px;
  align-items: center;
  gap: 16px;
  height: 44px;
  border-bottom: 1px solid var(--line);
}
.cities li.sep { margin-top: 20px; }

.rm {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  font: inherit;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
}
li:hover .rm, .rm:focus-visible { opacity: 1; }
.rm:hover { color: var(--fg); }
@media (hover: none) { .rm { opacity: 1; } }

/* ---------- Search ---------- */

.search { position: relative; margin-bottom: 8px; }

.search input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  outline: none;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { border-color: var(--muted); }

#results {
  position: absolute;
  z-index: 1;
  top: 44px;
  left: 0;
  right: 0;
  list-style: none;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .12);
}
#results li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
}
#results li[aria-selected="true"], #results li:hover { background: var(--line); }
#results small { color: var(--muted); font-size: 13px; }
#results .none { color: var(--muted); cursor: default; }
#results .none:hover { background: none; }

.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cities svg { width: 96px; height: 24px; overflow: visible; }
.cities polyline {
  fill: none;
  stroke: var(--c);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.value { font-weight: 600; text-align: right; }

.cat {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.cat::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
  flex: none;
}

[data-cat="0"] { --c: var(--c0); }
[data-cat="1"] { --c: var(--c1); }
[data-cat="2"] { --c: var(--c2); }
[data-cat="3"] { --c: var(--c3); }
[data-cat="4"] { --c: var(--c4); }
[data-cat="5"] { --c: var(--c5); }

/* ---------- States ---------- */

[aria-busy="true"] { opacity: .4; }
.cities[aria-busy="true"] { min-height: 900px; }
.grap[aria-busy="true"] { min-height: 128px; }
[data-error] { color: var(--muted); padding: 20px 0; }

/* ---------- Footer ---------- */

footer {
  margin-top: 24px;
  color: var(--muted);
  font-size: 13px;
}
footer a:hover { color: var(--fg); }
footer time:not(:empty)::before { content: " · "; }

@media (max-width: 480px) {
  main { padding-top: 32px; }
  .cities li { grid-template-columns: 1fr 64px 3.5ch 6rem 20px; gap: 8px; }
  .cities svg { width: 64px; }
}
