:root {
  --bg: #f2f3f5;
  --fg: #1b1d1f;
  --muted: #6b7075;
  --card: #ffffff;
  --border: #e3e4e6;
  --control-bg: #f1f2f4;
  --accent: #1f7a6d;
  --shadow: 0 6px 24px rgba(15, 20, 25, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1113;
    --fg: #eceef0;
    --muted: #979ca3;
    --card: #181b1e;
    --border: #2a2e33;
    --control-bg: #23272c;
    --accent: #3aa594;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; }
.muted { color: var(--muted); font-weight: 400; }

/* ---- split layout: dashboard | map ------------------------------------- */
body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); height: 100vh; overflow: hidden; }
#dash { overflow-y: auto; padding: 20px 22px 28px; border-right: 1px solid var(--border); }
#map-pane { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; z-index: 0; }

.dash-head { margin-bottom: 14px; }
.dash-head h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; margin: 0; }
#city-name { color: var(--muted); font-weight: 500; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
.card h2 { font-size: 13px; font-weight: 650; margin: 0 0 10px; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 12px 0; }
.controls { display: grid; gap: 12px; }
details.card { margin-top: 12px; padding: 12px 16px; }
summary { cursor: pointer; font-size: 13px; font-weight: 650; }

/* segmented controls */
.seg { display: flex; padding: 3px; gap: 3px; background: var(--control-bg); border-radius: 10px; }
.seg button {
  flex: 1; padding: 8px 6px; font-size: 13px; font-weight: 550; cursor: pointer; white-space: nowrap;
  color: var(--muted); background: transparent; border: 0; border-radius: 7px;
}
.seg button[aria-selected="true"], .seg button[aria-pressed="true"] {
  color: var(--fg); background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.seg.small button { padding: 5px 8px; font-size: 12px; }

.row2 { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.row2 label, .eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.row2 select {
  display: block; width: 100%; margin-top: 4px; padding: 8px; font-size: 14px; font-weight: 500;
  text-transform: none; letter-spacing: 0; color: var(--fg); background: var(--control-bg);
  border: 1px solid var(--border); border-radius: 8px;
}

/* headline */
.hero-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.hero-value { font-size: 32px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hero-sub { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.delta { font-size: 12px; font-weight: 650; padding: 2px 8px; border-radius: 999px; }
.delta.up { color: #b3261e; background: rgba(215, 48, 31, 0.12); }
.delta.down { color: #1b7a4a; background: rgba(27, 122, 74, 0.14); }
.delta.flat { color: var(--muted); background: var(--control-bg); }

/* legend */
.stack { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--control-bg); margin-top: 8px; }
.stack span { height: 100%; }
.keys { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px; margin-top: 8px; }
.key { font-size: 11px; color: var(--muted); line-height: 1.25; white-space: nowrap; }
.key b { display: block; font-size: 14px; color: var(--fg); font-variant-numeric: tabular-nums; }
.key i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }
.caption { font-size: 11px; color: var(--muted); margin: 8px 0 0; }
.ramp { height: 10px; border-radius: 999px; margin-top: 8px; background: linear-gradient(90deg, rgb(253,212,158), rgb(252,141,89), rgb(215,48,31), rgb(127,0,0)); }
.ramp-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }

/* riskiest zones list */
#top-list { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
#top-list li { counter-increment: rank; }
#top-list button {
  display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 8px; width: 100%;
  padding: 6px 4px; font-size: 13px; text-align: left; cursor: pointer;
  color: var(--fg); background: transparent; border: 0; border-radius: 6px;
}
#top-list button::before { content: counter(rank); color: var(--muted); font-size: 11px; font-weight: 650; }
#top-list button:hover, #top-list button[aria-current="true"] { background: var(--control-bg); }
#top-list .val { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

/* zone card */
#zone-card h2 { display: flex; justify-content: space-between; align-items: center; }
.badge { font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 999px; color: #fff; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.why { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.tag { font-size: 9px; font-weight: 700; letter-spacing: 0.04em; padding: 1px 4px; border-radius: 3px; margin-left: 5px; vertical-align: 1px; }
.tag-measured { background: #1b7837; color: #fff; }
.tag-derived  { background: #5e3c99; color: #fff; }
.tag-assumed  { background: #b35806; color: #fff; }

/* climate */
.bar-row { display: grid; grid-template-columns: 1fr 70px 64px; align-items: center; gap: 8px; font-size: 12px; margin: 8px 0; }
.bar { height: 8px; background: var(--accent); border-radius: 999px; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; }
.notice { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.error { color: #d7301f; }

/* floating map settings */
#map-controls {
  position: absolute; z-index: 10; top: 14px; right: 14px; width: 270px; padding: 8px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.opacity { display: flex; align-items: center; gap: 8px; margin: 8px 4px 2px; font-size: 11px; color: var(--muted); }
.opacity input { flex: 1; accent-color: var(--accent); }

/* narrower dashboards: single column of cards */
@media (max-width: 1150px) {
  .cards { grid-template-columns: minmax(0, 1fr); }
}

/* phones: map on top, dashboard scrolls below with sticky controls */
@media (max-width: 700px) {
  body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 55vh minmax(0, 1fr);
    grid-template-rows: 55dvh minmax(0, 1fr);  /* dvh tracks the mobile URL bar */
    height: 100vh; height: 100dvh;
  }
  #map-pane { grid-row: 1; }
  #dash {
    grid-row: 2; padding: 0 12px calc(24px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border);
  }
  .dash-head { display: none; }

  /* resource + layer + scenario stay reachable while scrolling */
  .controls {
    position: sticky; top: 0; z-index: 5; margin: 0 -12px; padding: 10px 12px;
    border-radius: 0; border-width: 0 0 1px; gap: 8px; background: var(--bg);
  }
  .seg.tabs button { padding: 10px 6px; font-size: 14px; }
  .row2 { gap: 8px; }
  .row2 select { font-size: 16px; padding: 9px 8px; }  /* 16px stops iOS zooming on focus */

  .cards { gap: 10px; margin-top: 10px; }
  .card { padding: 12px 14px; border-radius: 12px; }
  .hero-value { font-size: 26px; }
  .hero-sub { font-size: 11px; }
  .keys { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .key { font-size: 10px; }
  .key b { font-size: 13px; }

  /* a tapped zone jumps to the top of the cards, below the sticky controls */
  .cards.has-selection #zone-card { order: -1; }
  #zone-card { scroll-margin-top: 150px; }
  #top-list button { padding: 9px 4px; }

  #map-controls { top: 8px; right: 8px; width: 232px; padding: 4px; border-radius: 10px; }
  #map-controls .opacity { margin: 4px 6px 2px; font-size: 11px; }
  /* taller hit area so the thumb is easy to grab */
  #map-controls .opacity input { height: 28px; margin: 0; }
  .seg.small button { padding: 6px 9px; font-size: 12px; }
}
