:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  /* HAND risk ramp: dark red -> red -> orange -> light green -> green.
     Validated with the dataviz skill's categorical adjacent-pair check
     (CVD separation and normal-vision floor both pass; the surface-contrast
     WARN on individual steps is mitigated by always-visible text labels -
     axis ticks, direct value labels, legend and tooltips - never color alone). */
  --band-1: #7a1c1c; /* 0-5m    - dark red  (highest risk) */
  --band-2: #d03b3b; /* 5-10m   - red */
  --band-3: #e08214; /* 10-15m  - orange */
  --band-4: #aac95a; /* 15-20m  - light green */
  --band-5: #0ca30c; /* >20m    - green (lowest risk) */
  --band-nodata: #898781;

  /* Sequential red ramp for the district choropleth (share of buildings
     within 0-5m). One hue, light -> dark, darkest step matches --band-1 so
     "more red" keeps meaning "closer to the highest-risk band" everywhere
     in the dashboard. */
  --seq-0: #fbeaea;
  --seq-1: #f2bfbf;
  --seq-2: #e69494;
  --seq-3: #d46a6a;
  --seq-4: #b03f3f;
  --seq-5: #7a1c1c;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);

    --band-1: #8f2b2b;
    --band-2: #e2534f;
    --band-3: #f0973a;
    --band-4: #b9d67c;
    --band-5: #0ca30c;
    --band-nodata: #898781;

    --seq-0: #362323;
    --seq-1: #573030;
    --seq-2: #7d3d3d;
    --seq-3: #a84545;
    --seq-4: #cc4f4a;
    --seq-5: #e2534f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);

  --band-1: #8f2b2b;
  --band-2: #e2534f;
  --band-3: #f0973a;
  --band-4: #b9d67c;
  --band-5: #0ca30c;
  --band-nodata: #898781;

  --seq-0: #362323;
  --seq-1: #573030;
  --seq-2: #7d3d3d;
  --seq-3: #a84545;
  --seq-4: #cc4f4a;
  --seq-5: #e2534f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

/* ---------- header ---------- */
.topbar {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 14px 0 4px;
  flex-wrap: wrap;
}
.topbar h1 {
  font-family: 'Lexend', sans-serif;
  font-size: 28px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin: 0;
}
.topbar .subtitle {
  color: var(--text-secondary);
  font-size: 13px;
}
.topbar .spacer { flex: 1; }
.icon-btn {
  appearance: none;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}
.icon-btn:hover { color: var(--text-primary); border-color: var(--text-muted); }

/* ---------- tabs ---------- */
.tab-row {
  display: flex;
  gap: 4px;
  margin: 14px 0 0;
  padding: 5px;
  width: fit-content;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.tab-btn {
  font: inherit;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  background: none;
  border: none;
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab-btn:hover { color: var(--text-primary); background: var(--gridline); }
.tab-btn[aria-selected="true"] {
  color: #fff;
  font-weight: 650;
  background: var(--band-1);
}

.about-panel { max-width: 720px; }
.about-panel h2 { margin-top: 22px; }
.about-panel h2:first-child { margin-top: 0; }
.about-panel p, .about-panel li { color: var(--text-secondary); line-height: 1.6; }

/* ---------- filter row ---------- */
.filter-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--gridline);
  flex-wrap: wrap;
}
.filter-row label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-row select {
  font: inherit;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 220px;
}

/* ---------- stat tiles ---------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 18px 0;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.stat-tile .label {
  font-size: 12px;
  color: var(--text-muted);
}
.stat-tile .value {
  font-family: 'Lexend', sans-serif;
  font-size: 26px;
  font-weight: 700;
  margin-top: 2px;
}
.stat-tile .value.risk { color: var(--band-1); }

/* ---------- panels / grid ---------- */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px 18px;
}
.panel.wide { grid-column: 1 / -1; }
.panel h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
}
.panel .panel-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 12px;
}

.tab-link {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.tab-link:hover {
  color: var(--seq-4);
}

#map {
  height: 320px;
  border-radius: 8px;
  background: var(--gridline);
}

#nepal-choropleth-map, #health-map, #school-map {
  height: 440px;
  border-radius: 8px;
  background: var(--gridline);
}

.gradient-legend {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-secondary);
}
.gradient-legend .bar {
  height: 10px;
  border-radius: 5px;
}
.gradient-legend .ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
}

/* ---------- charts (hand-rolled SVG) ---------- */
.chart-svg { width: 100%; height: auto; display: block; }
.chart-svg text {
  fill: var(--text-secondary);
  font-size: 11px;
  font-family: inherit;
}
.chart-svg text.value-label {
  fill: var(--text-primary);
  font-weight: 600;
}
.chart-svg .axis-line { stroke: var(--baseline); stroke-width: 1; }
.chart-svg .gridline { stroke: var(--gridline); stroke-width: 1; }
.chart-svg .bar { cursor: pointer; }
.chart-svg .bar:hover, .chart-svg .bar.hover { filter: brightness(1.08); }

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-secondary);
}
.legend .legend-item { display: flex; align-items: center; gap: 5px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.legend .ramp-caption { color: var(--text-muted); }
.legend .legend-toggle { cursor: pointer; user-select: none; }
.legend .legend-toggle input { margin: 0; cursor: pointer; }

.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--page);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 12px;
  line-height: 1.4;
  z-index: 1000;
  max-width: 220px;
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.1s;
}
.tooltip.visible { opacity: 1; }
.tooltip .t-value { font-weight: 650; }

footer {
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--gridline);
  color: var(--text-muted);
  font-size: 11.5px;
}
footer a { color: var(--text-secondary); }

@media (max-width: 760px) {
  .content-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}
