:root {
  --bg: #f6f4ef;
  --bg-elevated: #ffffff;
  --text: #1c1917;
  --text-secondary: #57534e;
  --text-tertiary: #78716c;
  --accent: #1d4ed8;
  --link: #1d4ed8;
  --border: #e4e1db;
  --border-subtle: #eceae4;
  --fill-muted: #eceae6;
  --pin: #2563eb;
  --chart: #2563eb;
  --chart-muted: #93c5fd;
  --shadow: 0 8px 24px rgba(28, 25, 23, 0.12);
  --radius: 16px;
  --radius-sm: 8px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141311;
    --bg-elevated: #1c1b19;
    --text: #f5f5f4;
    --text-secondary: #a8a29e;
    --text-tertiary: #8a847e;
    --accent: #93c5fd;
    --link: #93c5fd;
    --border: #3f3c38;
    --border-subtle: #2c2a27;
    --fill-muted: #2a2825;
    --pin: #60a5fa;
    --chart: #60a5fa;
    --chart-muted: #1e3a8a;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141311;
  --bg-elevated: #1c1b19;
  --text: #f5f5f4;
  --text-secondary: #a8a29e;
  --text-tertiary: #8a847e;
  --accent: #93c5fd;
  --link: #93c5fd;
  --border: #3f3c38;
  --border-subtle: #2c2a27;
  --fill-muted: #2a2825;
  --pin: #60a5fa;
  --chart: #60a5fa;
  --chart-muted: #1e3a8a;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--bg-elevated);
  color: var(--text);
  padding: 8px 12px;
  z-index: 10;
}
.skip-link:focus { left: 8px; top: 8px; }

.page {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 80px;
}

.site-header { text-align: center; }

.site-header h1 {
  margin: 0 auto 12px;
  font-size: clamp(1.75rem, 3vw, 2.35rem);
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
  max-width: 28ch;
}

.lede {
  margin: 0 auto 28px;
  max-width: 62ch;
  color: var(--text-secondary);
  font-size: 1.05rem;
}

.logo-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
  margin: 8px 0 20px;
}

.logo {
  width: 240px;
  height: auto;
  display: block;
}

.logo-dark { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-light { display: none; }
  :root:not([data-theme="light"]) .logo-dark { display: block; }
}

:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: block; }

.follow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 0 0 40px;
}

.follow-title {
  font-size: 1.15rem;
  line-height: 1.35;
  font-weight: 600;
}

.section { margin: 48px 0 0; }

.section h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.section-intro {
  margin: 0 0 20px;
  color: var(--text-secondary);
  max-width: 70ch;
}

.caption {
  margin: 0 0 16px;
  color: var(--text-tertiary);
  font-size: 0.9rem;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.section-head .caption { margin-bottom: 0; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.metric {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
}

.metric-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.metric-label {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.metric-detail {
  margin-top: 2px;
  color: var(--text-tertiary);
  font-size: 0.82rem;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
}

.segmented button {
  font: inherit;
  font-size: 0.9rem;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.segmented button.is-active {
  background: var(--text);
  color: var(--bg);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: flex-end;
  margin: 0 0 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: min(100%, 200px);
}

.field > span {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.field input,
.field select,
.btn {
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.field input,
.field select { min-width: 220px; }

.btn { cursor: pointer; background: var(--bg-elevated); }
.btn:hover { border-color: var(--text-secondary); }

#region-chart svg,
#year-chart svg { display: block; width: 100%; height: auto; }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(7.5rem, 13rem) 1fr 2.25rem;
  gap: 10px;
  align-items: center;
}
.bar-name { font-size: 0.88rem; line-height: 1.25; overflow-wrap: anywhere; }
.bar-track { height: 14px; background: var(--fill-muted); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--chart); border-radius: 3px; }
.bar-fill.is-emphasis { background: var(--accent); }
.bar-n { font-size: 0.82rem; color: var(--text-secondary); text-align: right; }

.col-axis,
.col-label { fill: var(--text-tertiary); font-size: 12px; }
.col-fill { fill: var(--chart-muted); }
.col-fill.is-emphasis { fill: var(--chart); }
.col-value { fill: var(--text-secondary); font-size: 11px; }

.map-card { padding: 16px; overflow: hidden; }

.map-wrap { position: relative; width: 100%; }

.map-wrap svg {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  cursor: grab;
  background: transparent;
}

.map-wrap svg:active { cursor: grabbing; }

.map-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.map-buttons,
.map-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.map-legend {
  color: var(--text-secondary);
  font-size: 0.82rem;
  gap: 10px;
}

.legend-swatch,
.ramp-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid var(--border);
  vertical-align: middle;
}

.ramp { display: inline-flex; gap: 2px; align-items: center; }
.ramp-swatch { width: 14px; }

.map-btn {
  font: inherit;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
}

.popup {
  position: absolute;
  width: 240px;
  max-height: 220px;
  overflow: auto;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 0.92rem;
  line-height: 1.4;
  box-shadow: var(--shadow);
  z-index: 2;
}

.popup-place {
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.popup-item { margin-top: 4px; }

.table-wrap {
  margin-top: 16px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}

th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.82rem;
  letter-spacing: 0.01em;
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
}

tr:last-child td { border-bottom: 0; }

th.num, td.num { text-align: right; white-space: nowrap; }

.back-to-top {
  position: fixed;
  right: 16px;
  bottom: 16px;
  font: inherit;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 5;
}

.noscript {
  margin: 24px auto;
  max-width: 40ch;
  text-align: center;
  color: var(--text-secondary);
}

@media (max-width: 800px) {
  .page { width: calc(100% - 24px); padding-top: 24px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .field input, .field select { min-width: 0; width: 100%; }
  .field { min-width: min(100%, 160px); flex: 1 1 160px; }
  th, td { padding: 8px 10px; }
}

@media (max-width: 480px) {
  .site-header h1 { max-width: none; }
  .logo { width: 200px; }
  .filters { flex-direction: column; align-items: stretch; }
  .field { min-width: 0; width: 100%; flex: 1 1 auto; }
  .bar-row { grid-template-columns: minmax(6.5rem, 9.5rem) 1fr 2rem; gap: 8px; }
}
