:root {
  --bg: #f7f5f0;
  --surface: #fffdf9;
  --ink: #1d2327;
  --ink-2: #4a5258;
  --muted: #7b8186;
  --rule: #e3ded3;
  --rule-strong: #cfc8ba;
  --accent: #1f4e6b;
  --nodata: #e9e5dc;
  --ocean: #f7f5f0;
  --border: #fffdf9;
  --shadow: 0 1px 2px rgba(29, 35, 39, .06), 0 8px 24px rgba(29, 35, 39, .08);
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --max: 1180px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; line-height: 1.15; margin: 0; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 24px; }
.muted { color: var(--muted); }

/* Masthead */
.masthead { padding: 48px 0 20px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; }
h1 { font-size: clamp(40px, 6vw, 68px); font-weight: 700; }
.dek { font-family: var(--serif); font-size: clamp(17px, 1.7vw, 20px); color: var(--ink-2); max-width: 760px; margin: 14px 0 0; line-height: 1.5; }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; padding-top: 16px; padding-bottom: 16px; border-top: 1px solid var(--rule); }
.layers { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar-label { font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  --c: var(--accent);
  display: inline-flex; align-items: center; gap: 8px;
  font: 500 14px/1 var(--sans); color: var(--ink-2);
  padding: 9px 14px; border-radius: 999px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--rule-strong);
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { border-color: var(--c); color: var(--ink); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--c); background: transparent; transition: background .15s; }
.chip[aria-pressed="true"] { background: var(--c); border-color: var(--c); color: #fff; }
.chip[aria-pressed="true"] .dot { background: #fff; border-color: #fff; }
.chip:focus-visible, .btn:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tools { display: flex; gap: 8px; align-items: center; }
.search input {
  font: 400 14px/1 var(--sans); color: var(--ink);
  width: 220px; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--rule-strong); background: var(--surface);
}
.btn {
  font: 500 14px/1 var(--sans); color: var(--ink-2); cursor: pointer;
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--rule-strong); background: var(--surface);
}
.btn:hover { color: var(--ink); border-color: var(--ink-2); }
.btn.icon { width: 34px; height: 34px; padding: 0; font-size: 18px; display: grid; place-items: center; }

/* Map */
.map-shell { position: relative; width: 100%; height: min(82vh, 62vw); min-height: 360px; background: var(--ocean); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); overflow: hidden; touch-action: none; }
#map { width: 100%; height: 100%; display: block; cursor: grab; }
#map:active { cursor: grabbing; }
.sphere { fill: #eef0ee; stroke: var(--rule-strong); stroke-width: .6; }
.graticule { fill: none; stroke: #dfe2df; stroke-width: .5; }
.country { stroke: var(--border); stroke-width: .5; vector-effect: non-scaling-stroke; transition: fill .25s, opacity .25s; }
.country.nodata { fill: var(--nodata); }
.country.faded { opacity: .28; }
.country.hover { stroke: var(--ink); stroke-width: 1.4; }
.layer-outline { fill: none; stroke-width: 1.6; vector-effect: non-scaling-stroke; pointer-events: none; stroke-linejoin: round; }
.selected-outline { fill: none; stroke: var(--ink); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }

.legend { position: absolute; left: 20px; bottom: 20px; background: rgba(255, 253, 249, .92); backdrop-filter: blur(4px); border: 1px solid var(--rule); border-radius: 10px; padding: 12px 14px 10px; box-shadow: var(--shadow); }
.legend-title { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
#legend text { font: 500 11px var(--sans); fill: var(--ink-2); }
.legend-nodata { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.swatch-nodata { width: 14px; height: 10px; border-radius: 2px; background: var(--nodata); border: 1px solid var(--rule-strong); }

.zoom-ctrls { position: absolute; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 6px; }
.zoom-ctrls .btn { box-shadow: var(--shadow); }

.layer-card { position: absolute; top: 20px; right: 20px; width: 270px; background: rgba(255, 253, 249, .95); backdrop-filter: blur(4px); border: 1px solid var(--rule); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); }
.layer-card h3 { font-size: 18px; margin-bottom: 10px; }
.layer-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; border-top: 1px solid var(--rule); font-size: 13px; color: var(--ink-2); }
.layer-row:first-of-type { border-top: 0; padding-top: 0; }
.layer-row .lname { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); }
.layer-row .lname i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.layer-row .big { font-family: var(--serif); font-size: 22px; font-weight: 600; color: var(--ink); text-align: right; line-height: 1; }
.layer-row .sub { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }

/* Tooltip */
.tooltip { position: absolute; z-index: 10; pointer-events: none; min-width: 230px; max-width: 280px; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); font-size: 13px; color: var(--ink-2); }
.tooltip .tname { font-family: var(--serif); font-size: 19px; font-weight: 600; color: var(--ink); line-height: 1.2; }
.tooltip .trank { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tooltip .tiq { display: flex; align-items: baseline; gap: 8px; margin: 10px 0 4px; }
.tooltip .tiq b { font-family: var(--serif); font-size: 34px; font-weight: 700; color: var(--ink); line-height: 1; }
.tooltip .tiq span { font-size: 13px; color: var(--muted); }
.tooltip .tbar { position: relative; height: 6px; background: var(--rule); border-radius: 3px; margin: 8px 0 12px; }
.tooltip .tbar .ci { position: absolute; top: 0; height: 100%; background: var(--rule-strong); border-radius: 3px; }
.tooltip .tbar .pt { position: absolute; top: -3px; width: 3px; height: 12px; background: var(--ink); border-radius: 1px; transform: translateX(-1px); }
.tooltip .tsec { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 4px 0 6px; }
.tooltip .relbar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--rule); }
.tooltip .relbar span { height: 100%; }
.tooltip .rellist { display: grid; grid-template-columns: auto 1fr auto; gap: 3px 8px; margin-top: 8px; align-items: center; }
.tooltip .rellist i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.tooltip .rellist em { font-style: normal; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.tooltip .tnote { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin-top: 40px; border-top: 1px solid var(--ink); }
.stat { padding: 18px 20px 4px 0; }
.stat + .stat { padding-left: 20px; border-left: 1px solid var(--rule); }
.stat .label { font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.stat .value { font-family: var(--serif); font-size: 36px; font-weight: 600; line-height: 1.1; margin-top: 6px; }
.stat .detail { font-size: 14px; color: var(--ink-2); }

/* Prose */
.prose { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 64px; margin-top: 56px; }
.prose h2 { font-size: 26px; margin: 36px 0 12px; }
.prose .col > h2:first-child, .sources > h2:first-child { margin-top: 0; }
.prose p { margin: 0 0 16px; color: var(--ink-2); max-width: 68ch; }
.prose strong { color: var(--ink); font-weight: 600; }
.sources { border-top: 1px solid var(--ink); padding-top: 20px; align-self: start; }
.sources h2 { font-size: 22px; }
.sources ol { margin: 14px 0 0; padding-left: 20px; font-size: 14px; }
.sources li { margin-bottom: 14px; padding-left: 4px; }
.sources li::marker { color: var(--muted); font-variant-numeric: tabular-nums; }
.sources .note { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Ranking */
.ranking { margin-top: 56px; }
.ranking-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; border-top: 1px solid var(--ink); padding-top: 20px; }
.ranking-head h2 { font-size: 26px; }
.ranking-head p { margin: 0; font-size: 14px; }
.table-scroll { overflow-x: auto; margin-top: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--rule-strong); }
td { padding: 8px 12px; border-bottom: 1px solid var(--rule); color: var(--ink-2); }
td.cname { color: var(--ink); font-weight: 500; }
.num { text-align: right; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--surface); }
td .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 8px; vertical-align: -1px; }
#toggle-table { margin-top: 16px; }

.footer { margin-top: 64px; padding-top: 20px; padding-bottom: 48px; border-top: 1px solid var(--rule); font-size: 13px; color: var(--muted); }

@media (max-width: 900px) {
  .prose { grid-template-columns: 1fr; gap: 24px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(3) { border-left: 0; padding-left: 0; }
  .layer-card { width: 220px; padding: 12px 14px; }
}
@media (max-width: 600px) {
  .wrap { padding: 0 16px; }
  .masthead { padding-top: 32px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .tools { width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .map-shell { height: 115vw; min-height: 0; }
  .legend { left: 10px; bottom: 10px; padding: 8px 10px 6px; transform: scale(.85); transform-origin: left bottom; }
  .legend-nodata { display: none; }
  .zoom-ctrls { right: 10px; bottom: 10px; }
  .layer-card { top: 10px; right: 10px; left: 10px; width: auto; padding: 10px 12px; }
  .layer-card h3 { display: none; }
  .layer-row { padding: 5px 0; }
  .layer-row .sub { display: none; }
  .layer-row .big { font-size: 18px; }
  .tooltip { min-width: 0; max-width: 220px; padding: 10px 12px; }
  .tooltip .tiq b { font-size: 26px; }
  .stat .value { font-size: 28px; }
  td, th { padding: 7px 8px; }
  td:nth-child(5), th:nth-child(5) { display: none; }
}

/* Fallback (pre-2024) estimates */
.fallback-overlay { pointer-events: none; transition: opacity .25s; }
.marker.fallback { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 2 1.5; }
.legend-older { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.swatch-older { width: 14px; height: 10px; border-radius: 2px; border: 1px solid var(--rule-strong); background: repeating-linear-gradient(45deg, #d8d49e 0 2px, #fffdf9 2px 3.5px); }
.tooltip .tslave { margin-bottom: 10px; color: var(--ink-2); }
.tooltip .tslave b { font-family: var(--serif); font-size: 17px; color: var(--ink); }
