/* ==========================================================================
   HazeSG | Light, minimal, mobile first
   ========================================================================== */

:root {
  /* Colour */
  --bg: #ffffff;
  --bg-soft: #f3f4f6;
  --bg-selected: #eef4ff;
  --ink: #1b1f24;
  --ink-2: #4a525c;
  --ink-3: #6f7782;
  --line: #e3e6ea;
  --line-strong: #cfd4da;
  --accent: #1f5fd6;
  --alert-bg: #fdf2f2;
  --alert-line: #f5caca;
  --alert-ink: #a61b1b;

  --safe-good: #16a34a;
  --safe-moderate: #ca8a04;
  --safe-caution: #ea7a0c;
  --safe-poor: #dc2626;

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.25rem;

  /* Space (4px base) */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 24px;
  --s8: 32px;

  /* Shape */
  --r-sm: 8px;
  --r-md: 12px;
  --r-full: 999px;

  /* Layers */
  --z-map: 0;
  --z-sticky: 300;
  --z-scrim: 400;
  --z-sheet: 500;
  --z-toast: 600;

  --topbar-h: 56px;
  --pad-x: max(var(--s4), env(safe-area-inset-left));
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--topbar-h) + var(--s3));
}

html.is-locked,
html.is-locked body {
  overflow: hidden;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p, dl, dd, ul {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--pad-x) 0;
  padding-right: max(var(--s2), env(safe-area-inset-right));
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--ink);
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  width: 28px;
  height: 28px;
  flex: none;
}

.brand-name {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-tagline {
  display: none;
  padding-left: 10px;
  margin-left: 2px;
  border-left: 1px solid var(--line);
  color: var(--ink-3);
  font-size: var(--text-sm);
  white-space: nowrap;
}

@media (min-width: 480px) {
  .brand-tagline {
    display: inline;
  }
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink);
}

@media (hover: hover) {
  .icon-btn:hover {
    background: var(--bg-soft);
  }
}

.icon-btn .icon {
  width: 24px;
  height: 24px;
}

/* --------------------------------------------------------------------------
   Alert
   -------------------------------------------------------------------------- */
.alert {
  display: flex;
  align-items: baseline;
  gap: var(--s3);
  margin: var(--s3) var(--pad-x) 0;
  padding: 10px var(--s3);
  background: var(--alert-bg);
  border: 1px solid var(--alert-line);
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  line-height: 1.4;
}

.alert-level {
  flex: none;
  font-weight: 700;
  color: var(--alert-ink);
  white-space: nowrap;
}

.alert-level.risk-mid {
  color: #a16207;
}

.alert-level.risk-low {
  color: #15803d;
}

.alert-text {
  color: var(--ink);
}

/* --------------------------------------------------------------------------
   Layout (mobile first: one column, the page scrolls)
   -------------------------------------------------------------------------- */
.layout {
  max-width: 760px;
  margin: 0 auto;
}

.map-area {
  padding: var(--s3) var(--pad-x) 0;
}

.map-box {
  position: relative;
  z-index: var(--z-map);
  isolation: isolate;
  height: 56vh;
  height: 56svh;
  min-height: 320px;
  max-height: 540px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: #eceef0;
  scroll-margin-top: calc(var(--topbar-h) + var(--s3));
}

#sg-map {
  position: absolute;
  inset: 0;
  background: #eceef0;
}

#smoke-canvas {
  position: absolute;
  inset: 0;
  z-index: 450;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.map-chip {
  position: absolute;
  top: var(--s3);
  right: var(--s3);
  z-index: 800;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-full);
  background: #fff;
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.map-hint {
  position: absolute;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s6);
  background: rgba(27, 31, 36, 0.45);
  color: #fff;
  font-size: var(--text-base);
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.map-hint.is-visible {
  opacity: 1;
}

.panel {
  padding: 0 var(--pad-x);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 var(--s4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--ink);
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
}

@media (hover: hover) {
  .btn:hover {
    background: var(--bg-soft);
  }
}

.btn:active {
  background: #e9ebee;
}

.btn[disabled] {
  cursor: progress;
  color: var(--ink-3);
}

.btn-block {
  width: 100%;
}

.btn.is-busy .icon {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.link-btn {
  padding: var(--s1) 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Actions + legend (directly under the map)
   -------------------------------------------------------------------------- */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s2);
  margin-top: var(--s3);
}

.updated {
  margin-top: var(--s2);
  color: var(--ink-3);
  font-size: var(--text-xs);
}

.sources {
  margin-top: var(--s1);
  color: var(--ink-3);
  font-size: var(--text-xs);
  line-height: 1.5;
}

.sources.is-loading {
  color: var(--ink-3);
}

.sources.is-warning {
  padding: var(--s2) 10px;
  border-radius: var(--r-sm);
  background: var(--alert-bg);
  color: var(--alert-ink);
}

.footer-subtitle {
  margin-top: var(--s2);
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 700;
}

.legend {
  margin-top: var(--s3);
  padding: var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.legend-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s2);
  margin-bottom: var(--s2);
  font-size: var(--text-sm);
  font-weight: 600;
}

.legend-source {
  color: var(--ink-3);
  font-size: var(--text-xs);
  font-weight: 500;
}

.legend-bar {
  display: flex;
  height: 8px;
  overflow: hidden;
  border-radius: var(--r-full);
}

.legend-bar span {
  flex: 1;
}

.legend-labels {
  display: flex;
  margin-top: 6px;
}

.legend-labels span {
  flex: 1;
  min-width: 0;
  font-size: var(--text-xs);
  line-height: 1.3;
  color: var(--ink-2);
}

.legend-labels small {
  display: block;
  color: var(--ink-3);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Sections
   -------------------------------------------------------------------------- */
.block {
  margin-top: var(--s8);
}

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s3);
}

.block h2 {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.note {
  color: var(--ink-2);
  font-size: var(--text-sm);
  line-height: 1.55;
}

.note-tight {
  margin-top: var(--s2);
}

/* Segmented control */
.segmented {
  display: inline-flex;
  flex: none;
  padding: 3px;
  border-radius: 10px;
  background: var(--bg-soft);
}

.seg {
  min-height: 34px;
  padding: 0 var(--s3);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
}

.seg.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.segmented-full {
  display: flex;
  width: 100%;
}

.segmented-full .seg {
  flex: 1;
  padding: 0 var(--s2);
  font-size: 0.8125rem;
}

/* Collapsible sections */
.block-title {
  margin: 0 0 var(--s3);
}

.block-toggle {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
}

.block-name {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.block-summary {
  display: none;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--ink-3);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.block-chevron {
  margin-left: auto;
  flex: none;
  color: var(--ink-3);
  transform: rotate(-90deg);
  transition: transform 0.2s ease;
}

.block.is-collapsed .block-title {
  margin-bottom: 0;
}

.block.is-collapsed .block-summary {
  display: block;
}

.block.is-collapsed .block-chevron {
  transform: rotate(90deg);
}

.block.is-collapsed .block-body {
  display: none;
}

.block + .block {
  margin-top: var(--s4);
  padding-top: var(--s4);
  border-top: 1px solid var(--line);
}

/* Reading switch (1-hour vs 24-hour) */
.reading-switch {
  margin-bottom: var(--s3);
}

.reading-switch .seg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 52px;
  padding: 6px var(--s2);
  white-space: normal;
  line-height: 1.2;
}

.reading-switch .seg strong {
  font-size: var(--text-sm);
  font-weight: 700;
}

.reading-switch .seg small {
  color: var(--ink-3);
  font-size: 0.75rem;
  font-weight: 500;
}

.reading-switch .seg.is-active small {
  color: var(--ink-2);
}

/* Day meta line */
.day-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2) var(--s4);
  font-size: var(--text-sm);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--c, var(--ink-3));
}

.wind {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-2);
}

#wind-arrow {
  transition: transform 0.3s ease;
}

.metric-note {
  margin: var(--s2) 0 var(--s3);
  color: var(--ink-3);
  font-size: var(--text-xs);
}

/* Region list */
.region-list {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}

.region-list li + li {
  border-top: 1px solid var(--line);
}

.region-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: 60px;
  padding: 10px var(--s3);
  border: 0;
  background: #fff;
  text-align: left;
}

@media (hover: hover) {
  .region-row:hover {
    background: #fafbfc;
  }
}

.region-row.is-selected {
  background: var(--bg-selected);
}

.region-main {
  flex: 1;
  min-width: 0;
}

.region-name {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--text-base);
  font-weight: 600;
}

.region-tag {
  padding: 1px 6px;
  border-radius: var(--r-full);
  background: var(--alert-bg);
  color: var(--alert-ink);
  font-size: 0.6875rem;
  font-weight: 700;
}

.region-areas {
  overflow: hidden;
  color: var(--ink-3);
  font-size: 0.8125rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.region-value {
  flex: none;
  text-align: right;
}

.region-value strong {
  display: block;
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.region-value span {
  color: var(--ink-3);
  font-size: var(--text-xs);
}

/* 7-day strip */
.day-strip {
  display: flex;
  gap: var(--s2);
  margin: 0 calc(var(--pad-x) * -1);
  padding: 2px var(--pad-x) var(--s1);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding: 0 var(--pad-x);
  scrollbar-width: none;
}

.day-strip::-webkit-scrollbar {
  display: none;
}

.day-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: none;
  min-width: 76px;
  padding: 9px var(--s2);
  /* Always 2px, so switching days never changes the box size. A 1px to 2px swap
     forces a subpixel repaint, which iOS Safari can leave half-drawn. */
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  background: #fff;
  scroll-snap-align: start;
}

.day-btn.is-active {
  border-color: var(--accent);
  background: var(--bg-selected);
}

.day-btn.is-active .day-btn-name {
  color: var(--accent);
  font-weight: 700;
}

/* Keyboard focus must never look like selection. On a phone the browser can leave a
   focus ring on a tapped card, which made two days appear chosen at once. */
.day-btn:focus-visible {
  outline: 2px dashed var(--ink);
  outline-offset: 3px;
}

.day-btn:focus:not(:focus-visible) {
  outline: none;
}

.day-btn-name {
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

.day-btn .icon {
  width: 22px;
  height: 22px;
  color: var(--ink-2);
}

.day-btn-val {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.9375rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.day-btn-val .dot {
  width: 8px;
  height: 8px;
}

.day-detail {
  margin-top: var(--s3);
}

.day-facts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s4);
  margin-bottom: var(--s2);
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* Hour chart */
.hour-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 140px;
  padding-top: var(--s2);
}

.hour-col {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
}

.hour-track {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  min-height: 0;
}

.hour-val {
  margin-bottom: 4px;
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hour-bar {
  width: 100%;
  max-width: 30px;
  border-radius: 4px 4px 2px 2px;
  background: var(--c);
}

.hour-time {
  margin-top: 6px;
  color: var(--ink-3);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
}

.hour-key {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s4);
  margin: var(--s3) 0 var(--s2);
  color: var(--ink-2);
  font-size: var(--text-xs);
}

.hour-key span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.key-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--c);
}

/* Health advice */
.advice {
  margin-top: var(--s3);
  border-top: 1px solid var(--line);
}

.advice div {
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--line);
}

.advice dt {
  margin-bottom: 2px;
  font-size: var(--text-sm);
  font-weight: 700;
}

.advice dd {
  color: var(--ink-2);
  font-size: var(--text-sm);
  line-height: 1.55;
}

/* Fires */
.fire-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s2);
}

.fire-stat {
  padding: var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.fire-stat strong {
  display: block;
  font-size: 1.625rem;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.fire-stat span {
  color: var(--ink-3);
  font-size: 0.8125rem;
}

.risk {
  margin-top: var(--s4);
}

.risk-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s2);
  font-size: var(--text-sm);
  font-weight: 600;
}

.risk-head strong {
  flex: none;
  font-variant-numeric: tabular-nums;
}

.risk-track {
  height: 8px;
  overflow: hidden;
  border-radius: var(--r-full);
  background: var(--bg-soft);
}

.risk-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--c, var(--safe-caution));
  transition: width 0.4s ease;
}

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s3) var(--s4);
  margin-top: var(--s4);
}

.facts dt {
  color: var(--ink-3);
  font-size: var(--text-xs);
}

.facts dd {
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.4;
}

.fire-actions {
  display: grid;
  gap: var(--s2);
  margin-top: var(--s4);
}

.cams {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s1) var(--s3);
  margin-top: var(--s3);
  color: var(--ink-3);
  font-size: var(--text-xs);
}

.cams span {
  color: var(--ink-2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Switch rows */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  min-height: 56px;
  padding: 10px var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
}

.switch-row strong {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
}

.switch-row small {
  display: block;
  color: var(--ink-3);
  font-size: var(--text-xs);
}

.switch {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
}

.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-ui {
  position: absolute;
  inset: 0;
  border-radius: var(--r-full);
  background: var(--line-strong);
  transition: background 0.2s ease;
  pointer-events: none;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.switch input:checked + .switch-ui {
  background: var(--accent);
}

.switch input:checked + .switch-ui::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch-ui {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Footer, disclaimer and branding */
.footer-title {
  color: var(--ink);
  font-size: var(--text-base);
  font-weight: 700;
}

.source-list {
  display: grid;
  gap: 6px;
  padding-left: var(--s4);
  list-style: disc;
}

.source-list li::marker {
  color: var(--line-strong);
}

.powered {
  margin-top: var(--s2);
  color: var(--ink-2);
  font-size: var(--text-sm);
}

.powered strong {
  color: var(--ink);
}

.sheet-section .powered {
  margin-top: var(--s3);
}

/* Footer (extra bottom space so the Netlify badge never covers content) */
.site-footer {
  scroll-margin-top: calc(var(--topbar-h) + var(--s3));
  display: grid;
  gap: var(--s2);
  margin-top: var(--s8);
  padding: var(--s4) 0 calc(96px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--ink-3);
  font-size: var(--text-xs);
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   Menu sheet
   -------------------------------------------------------------------------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-scrim);
  background: rgba(27, 31, 36, 0.35);
}

.scrim[hidden] {
  display: none;
}

.sheet {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-sheet);
  display: flex;
  flex-direction: column;
  width: min(360px, 88vw);
  background: #fff;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.24s ease, visibility 0s linear 0.24s;
}

.sheet.is-open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 0.24s ease, visibility 0s;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  flex: none;
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--s2) 0 var(--s4);
  border-bottom: 1px solid var(--line);
}

.sheet-head h2 {
  font-size: var(--text-lg);
  font-weight: 700;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--s2) var(--s4) calc(var(--s8) + env(safe-area-inset-bottom));
}

.sheet-section {
  padding: var(--s4) 0;
}

.sheet-section + .sheet-section {
  border-top: 1px solid var(--line);
}

.sheet-section h3 {
  margin-bottom: var(--s3);
  color: var(--ink-3);
  font-size: 0.8125rem;
  font-weight: 600;
}

.sheet-section .switch-row + .switch-row {
  margin-top: var(--s2);
}

.choice-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s2);
}

.choice {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice:has(input:checked) {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  background: var(--bg-selected);
}

.choice.is-checked {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  background: var(--bg-selected);
}

.choice:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.row-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  width: 100%;
  min-height: 56px;
  padding: var(--s2) 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--ink);
  text-align: left;
}

.row-btn:hover {
  text-decoration: none;
}

.row-btn:last-child {
  border-bottom: 0;
}

.row-btn strong {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
}

.row-btn small {
  display: block;
  color: var(--ink-3);
  font-size: var(--text-xs);
}

.row-btn .icon {
  color: var(--ink-3);
}

/* --------------------------------------------------------------------------
   API modal
   -------------------------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
  background: rgba(27, 31, 36, 0.35);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  display: flex;
  flex-direction: column;
  width: min(640px, 100%);
  max-height: min(88vh, 760px);
  overflow: hidden;
  border-radius: var(--r-md);
  background: #fff;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
}

.modal-card .sheet-head {
  min-height: var(--topbar-h);
  padding-top: 0;
}

.modal-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s3);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--s4);
}

.endpoint-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s2);
}

@media (min-width: 560px) {
  .endpoint-list {
    grid-template-columns: 1fr 1fr;
  }
}

.endpoint {
  min-width: 0;
  padding: 10px var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #fff;
  text-align: left;
}

.endpoint.is-active {
  border-color: var(--accent);
  background: var(--bg-selected);
}

.endpoint strong {
  display: block;
  font-size: var(--text-sm);
}

.endpoint span {
  display: block;
  overflow: hidden;
  color: var(--ink-3);
  font-size: 0.6875rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.request-bar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  border-radius: var(--r-sm);
  background: var(--bg-soft);
  font-size: var(--text-xs);
}

.request-bar code {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.method {
  font-weight: 700;
  color: var(--safe-good);
}

.req-status {
  flex: none;
  color: var(--ink-3);
  font-weight: 600;
}

.response {
  height: 240px;
  margin: 0;
  padding: var(--s3);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #fafbfc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.6875rem;
  line-height: 1.5;
  white-space: pre;
}

.token-box summary {
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.token-row {
  display: flex;
  gap: var(--s2);
  margin-top: var(--s2);
}

.token-row input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  font-size: var(--text-base);
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */
.toast {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + var(--s3));
  left: 50%;
  z-index: var(--z-toast);
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px var(--s4);
  border-radius: var(--r-sm);
  background: var(--ink);
  color: #fff;
  font-size: var(--text-sm);
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, -8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --------------------------------------------------------------------------
   Leaflet overrides (light)
   -------------------------------------------------------------------------- */
.leaflet-container {
  font-family: var(--font);
  background: #eceef0;
}

.leaflet-bar {
  border: 1px solid var(--line-strong) !important;
  border-radius: var(--r-sm) !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08) !important;
  overflow: hidden;
}

.leaflet-bar a,
.leaflet-touch .leaflet-bar a {
  width: 36px;
  height: 36px;
  line-height: 34px;
  color: var(--ink);
  font-size: 20px;
  font-weight: 400;
}

.leaflet-top.leaflet-left {
  top: 4px;
  left: 4px;
}

.leaflet-control-attribution {
  font-size: 10px;
  background: rgba(255, 255, 255, 0.8) !important;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--r-md);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.leaflet-popup-content {
  margin: var(--s3) var(--s4);
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--ink);
}

.pop h4 {
  margin: 0 0 2px;
  font-size: var(--text-base);
}

.pop p {
  margin: 0;
  color: var(--ink-2);
}

.pop .pop-row {
  display: flex;
  justify-content: space-between;
  gap: var(--s4);
  margin-top: 6px;
}

.pop .pop-row strong {
  font-variant-numeric: tabular-nums;
}

.pop .pop-sub {
  margin-top: 6px;
  color: var(--ink-3);
  font-size: var(--text-xs);
}

/* Region labels on the map */
.rl-icon {
  background: none;
  border: 0;
}

.rl {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 8px 4px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  color: var(--ink);
  line-height: 1.2;
  white-space: nowrap;
  transform: translate(-50%, -50%);
}

.rl-name {
  color: var(--ink-3);
  font-size: 10.5px;
  font-weight: 500;
}

.rl-val {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.rl-val .dot {
  width: 8px;
  height: 8px;
}

.rl.is-selected {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink), 0 1px 3px rgba(0, 0, 0, 0.12);
}

.is-far .rl-icon {
  display: none;
}

/* You are here */
.me-icon {
  background: none;
  border: 0;
}

.me-dot {
  width: 16px;
  height: 16px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(31, 95, 214, 0.2), 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* --------------------------------------------------------------------------
   Tablet
   -------------------------------------------------------------------------- */
@media (min-width: 640px) and (max-width: 1023px) {
  .alert {
    width: min(728px, calc(100% - 32px));
    margin-left: auto;
    margin-right: auto;
  }
}

@media (min-width: 640px) {
  .map-box {
    height: 60vh;
    height: 60svh;
    max-height: 600px;
  }

  .day-strip {
    margin: 0;
    padding-left: 0;
    padding-right: 0;
  }
}

/* --------------------------------------------------------------------------
   Desktop: map on the left, details scroll on the right
   -------------------------------------------------------------------------- */
@media (min-width: 1024px) {
  .app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .topbar {
    flex: none;
    position: relative;
  }

  .alert {
    flex: none;
    margin: var(--s3) var(--s4) 0;
  }

  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: none;
    margin: 0;
  }

  .map-area {
    min-height: 0;
    padding: var(--s3) 0 var(--s4) var(--s4);
  }

  .map-box {
    height: 100%;
    min-height: 0;
    max-height: none;
  }

  .panel {
    min-height: 0;
    overflow-y: auto;
    padding: 0 var(--s4);
    scrollbar-gutter: stable;
  }

  .actions {
    margin-top: var(--s3);
  }

  .site-footer {
    padding-bottom: 88px;
  }
}

@media (min-width: 1440px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 440px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* --------------------------------------------------------------------------
   Haze cover and fire smoke layers
   -------------------------------------------------------------------------- */
/* Over Singapore alone the regional grid is one or two cells wide, so it only tints.
   Zoomed out, where the shape of the haze is the point, it shows at full strength. */
#sg-map .leaflet-hazePane-pane,
#sg-map .leaflet-plumePane-pane {
  opacity: 0.3;
  transition: opacity 0.3s ease;
}

#sg-map.is-far .leaflet-hazePane-pane,
#sg-map.is-far .leaflet-plumePane-pane {
  opacity: 1;
}

.smoke-img {
  image-rendering: auto;
}

.cover-key {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2) var(--s4);
  margin-top: var(--s4);
  color: var(--ink-2);
  font-size: var(--text-xs);
}

.cover-key span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cover-key i {
  flex: none;
  display: inline-block;
  width: 18px;
  height: 10px;
  border-radius: 3px;
}

.cover-key .ck-haze {
  background: linear-gradient(90deg, rgba(182, 152, 110, 0.35), rgba(146, 82, 38, 0.75), rgba(88, 22, 40, 0.85));
}

.cover-key .ck-edge {
  height: 0;
  border-top: 2px dashed #c2410c;
  border-radius: 0;
}

.cover-key .ck-high {
  height: 0;
  border-top: 2px solid #991b1b;
  border-radius: 0;
}

.cover-key .ck-plume {
  background: linear-gradient(90deg, rgba(118, 76, 196, 0.2), rgba(88, 36, 150, 0.65));
}

.cover-key .ck-p90 {
  height: 0;
  border-top: 2px dotted #6d28d9;
  border-radius: 0;
}

.method {
  margin-top: var(--s4);
  padding: var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--ink-2);
  font-size: var(--text-sm);
  line-height: 1.55;
}

.method summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 600;
}

.method p {
  margin-top: var(--s2);
}
