:root {
  color-scheme: light;
  --surface-0: #f6f5f2;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border:    #dedbd4;
  --border-strong: #c4c0b6;
  --text-primary: #16150f;
  --text-secondary: #52514e;
  --text-muted: #7d7b73;
  --accent: #256abf;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --s100:#cde2fb; --s200:#9ec5f4; --s300:#6da7ec; --s400:#3987e5;
  --s500:#256abf; --s600:#184f95; --s700:#0d366b;
  --nodata: #e3e1dc;
  --shadow: 0 1px 2px rgba(20,18,10,.06), 0 8px 24px rgba(20,18,10,.06);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #131312;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --border:    #33332f;
    --border-strong: #4a4a45;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8d8c83;
    --accent: #6da7ec;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --s100:#0d366b; --s200:#184f95; --s300:#256abf; --s400:#2a78d6;
    --s500:#5598e7; --s600:#86b6ef; --s700:#cde2fb;
    --nodata: #2b2b29;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #131312; --surface-1: #1a1a19; --surface-2: #232322;
  --border: #33332f; --border-strong: #4a4a45;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #8d8c83;
  --accent: #6da7ec; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --s100:#0d366b; --s200:#184f95; --s300:#256abf; --s400:#2a78d6;
  --s500:#5598e7; --s600:#86b6ef; --s700:#cde2fb;
  --nodata: #2b2b29;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--surface-0);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 620; letter-spacing: -0.011em; }

/* ---- header ---- */
.site-head {
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 56px;
  background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: baseline; gap: 9px; font-weight: 680; letter-spacing: -0.02em; font-size: 17px; color: var(--text-primary); }
.brand:hover { text-decoration: none; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--series-1); display: inline-block; }
.brand small { font-weight: 450; color: var(--text-muted); font-size: 12.5px; letter-spacing: 0; }
.site-nav { display: flex; gap: 18px; margin-left: auto; align-items: center; font-size: 14px; }
.site-nav a { color: var(--text-secondary); }
.site-nav a.on { color: var(--text-primary); font-weight: 560; }
.theme-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary);
  border-radius: 7px; height: 30px; padding: 0 10px; cursor: pointer; font: inherit; font-size: 13px;
}
.theme-btn:hover { border-color: var(--border-strong); }

/* ---- search ---- */
.search { position: relative; }
.search input {
  width: 260px; height: 32px; padding: 0 10px; font: inherit; font-size: 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text-primary);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.results {
  position: absolute; top: 38px; left: 0; width: 340px; max-height: 60vh; overflow: auto;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); z-index: 60; padding: 5px;
}
.results button {
  display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left;
  border: 0; background: none; color: var(--text-primary); font: inherit; padding: 7px 9px;
  border-radius: 7px; cursor: pointer;
}
.results button:hover, .results button.sel { background: var(--surface-2); }
.results .kind { color: var(--text-muted); font-size: 12.5px; white-space: nowrap; }

/* ---- layout ---- */
.wrap { max-width: 1420px; margin: 0 auto; padding: 20px; }
.panel {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.muted { color: var(--text-muted); }
.small { font-size: 13px; }

/* ---- controls ---- */
.controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; padding: 14px 16px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field[hidden] { display: none; }
.field > label { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; }
select, .seg {
  height: 34px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text-primary); font: inherit; font-size: 14px;
}
select { padding: 0 8px; max-width: 320px; }
.seg { display: inline-flex; padding: 3px; gap: 3px; }
.seg button {
  border: 0; background: none; color: var(--text-secondary); font: inherit; font-size: 13.5px;
  padding: 0 12px; border-radius: 6px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); font-weight: 560; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
input[type=range] { width: 260px; accent-color: var(--accent); }
.yearline { display: flex; align-items: center; gap: 10px; }
.yearval { font-variant-numeric: tabular-nums; font-weight: 620; min-width: 42px; }

/* ---- map ---- */
.map-grid { display: grid; grid-template-columns: 1fr 330px; gap: 14px; align-items: start; }
@media (max-width: 1020px) { .map-grid { grid-template-columns: 1fr; } }
.map-box { position: relative; padding: 8px; }
.map-box svg { display: block; width: 100%; height: auto; }
path.unit { stroke: var(--surface-1); stroke-width: .4; cursor: pointer; }
path.unit:hover { stroke: var(--text-primary); stroke-width: 1.4; }
path.unit.sel { stroke: var(--text-primary); stroke-width: 1.8; }
.tip {
  position: fixed; pointer-events: none; z-index: 90; max-width: 260px;
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: 9px;
  box-shadow: var(--shadow); padding: 9px 11px; font-size: 13px; opacity: 0; transition: opacity .09s;
}
.tip b { display: block; font-size: 14px; margin-bottom: 3px; }
.tip .row { display: flex; justify-content: space-between; gap: 14px; color: var(--text-secondary); }
.tip .row span:last-child { font-variant-numeric: tabular-nums; color: var(--text-primary); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 10px 14px 4px; }
.ramp { display: flex; }
.ramp i { width: 42px; height: 11px; display: block; }
.ramp i:first-child { border-radius: 3px 0 0 3px; }
.ramp i:last-child { border-radius: 0 3px 3px 0; }
.ramp-labels { display: flex; font-variant-numeric: tabular-nums; font-size: 11.5px; color: var(--text-muted); }
.ramp-labels span { width: 42px; text-align: right; transform: translateX(50%); }

/* ---- rank list ---- */
.rank { padding: 6px; max-height: 640px; overflow: auto; }
.rank a { display: grid; grid-template-columns: 22px 1fr auto; gap: 9px; align-items: center;
  padding: 6px 9px; border-radius: 7px; color: var(--text-primary); }
.rank a:hover { background: var(--surface-2); text-decoration: none; }
.rank .n { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.rank .v { font-variant-numeric: tabular-nums; font-weight: 560; }
.rank .bar { grid-column: 2 / -1; height: 3px; border-radius: 2px; background: var(--s200); opacity: .85; margin-top: 1px; }
.sect-head { display: flex; justify-content: space-between; align-items: baseline; padding: 13px 16px 8px; }
.sect-head h2 { font-size: 15px; }

/* ---- place page ---- */
.place-head { display: flex; flex-wrap: wrap; gap: 16px 28px; align-items: flex-end; padding: 18px 20px; margin-bottom: 14px; }
.place-head h1 { font-size: 27px; }
.crumbs { font-size: 13px; color: var(--text-muted); margin-bottom: 5px; }
.crumbs a { color: var(--text-secondary); }
.facts { display: flex; gap: 26px; margin-left: auto; flex-wrap: wrap; }
.fact { min-width: 92px; }
.fact .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; }
.fact .v { font-size: 21px; font-weight: 640; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.fact .v small { font-size: 12px; font-weight: 450; color: var(--text-muted); letter-spacing: 0; }
.cols { display: grid; grid-template-columns: 1.35fr 1fr; gap: 14px; align-items: start; }
.cols > * { min-width: 0; }
.map-grid > * { min-width: 0; }
@media (max-width: 980px) { .cols { grid-template-columns: 1fr; } }
.chart-box { padding: 4px 16px 14px; }
.chart-box svg { display: block; width: 100%; height: auto; overflow: visible; }
.legend-inline { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-secondary); padding: 0 16px 8px; }
.legend-inline i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: 0; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { text-align: left; }
thead th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; position: sticky; top: 0; background: var(--surface-1); }
td { font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
.table-scroll { max-height: 520px; overflow: auto; padding: 0 6px 6px; }
.note {
  border-left: 3px solid var(--series-2); background: var(--surface-2);
  padding: 10px 14px; border-radius: 0 8px 8px 0; font-size: 13.5px; color: var(--text-secondary);
  margin: 0 16px 14px;
}
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); font-size: 12.5px; color: var(--text-secondary); margin: 0 5px 5px 0; }
.prose { padding: 4px 22px 26px; max-width: 78ch; }
.prose h2 { font-size: 18px; margin: 26px 0 8px; }
.prose h3 { font-size: 15px; margin: 20px 0 6px; }
.prose p, .prose li { color: var(--text-secondary); }
.prose code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.foot { color: var(--text-muted); font-size: 12.5px; padding: 26px 4px 40px; text-align: center; }
.skel { color: var(--text-muted); padding: 40px 16px; text-align: center; }

/* ---- small screens ---- */
@media (max-width: 720px) {
  .site-head { height: auto; flex-wrap: wrap; gap: 10px; padding: 10px 12px; position: static; }
  .brand small { display: none; }
  .search { order: 3; flex: 1 0 100%; }
  .search input { width: 100%; }
  .results { width: 100%; }
  .site-nav { margin-left: auto; gap: 14px; font-size: 13.5px; }
  .wrap { padding: 12px; }
  .place-head { padding: 14px; }
  .place-head h1 { font-size: 22px; }
  .facts { margin-left: 0; gap: 14px 20px; }
  .fact .v { font-size: 18px; }
  .controls { padding: 12px; gap: 12px; }
  select { max-width: 100%; }
  input[type=range] { width: 180px; }
  .chart-box { padding: 4px 10px 12px; }
  .note { margin: 0 12px 12px; }
  .sect-head { padding: 12px 12px 6px; }
  .table-scroll { padding: 0; }
  th, td { padding: 6px; }
}
