/* populon.org — one neutral, quiet system: system sans, hairline borders, generous space, colour only for data. */

:root {
  color-scheme: light;
  --page: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f3f3f0;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e6e5df;
  --line-strong: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.08);
  --accent: #2a78d6;
  --accent-soft: #e8f1fc;
  --accent-ink: #ffffff;
  --warn: #8a4b06;
  --warn-bg: #fdf1dc;
  /* Categorical series, fixed order (validated palette). */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --fold-1: #a9a8a1; --fold-2: #8f8e87; --fold-3: #c3c2b7; --fold-4: #75746e;
  /* Flows: inflows and outflows are the first two series. */
  --flow-in: var(--s1);
  --flow-out: var(--s2);
  /* Map. */
  --map-water: #eef2f6;
  --map-empty: #dcdbd5;
  --map-none: #cbc9c1;
  --map-stroke: #ffffff;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --line: #2c2c2a;
  --line-strong: #383835;
  --ring: rgba(255, 255, 255, 0.08);
  --accent: #3987e5;
  --accent-soft: #15253a;
  --accent-ink: #ffffff;
  --warn: #f3c27a;
  --warn-bg: #33270f;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --fold-1: #6b6a65; --fold-2: #57564f; --fold-3: #807f78; --fold-4: #45443f;
  --map-water: #141a21;
  --map-empty: #2e2e2b;
  --map-none: #45443f;
  --map-stroke: #0d0d0d;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--sans); font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; color: var(--ink); }
h1 { margin: 0 0 0.5rem; font-size: clamp(1.7rem, 3.2vw, 2.4rem); letter-spacing: -0.02em; }
h2 { margin: 0 0 0.35rem; font-size: 1.45rem; }
h3 { margin: 0 0 0.6rem; font-size: 1.05rem; }
h4 { margin: 1rem 0 0.4rem; font-size: 0.92rem; color: var(--ink-2); font-weight: 600; }
p { margin: 0 0 0.75rem; }
a { color: var(--accent); text-underline-offset: 2px; }
code { font-size: 0.9em; background: var(--surface-2); padding: 0.05rem 0.3rem; border-radius: 4px; }
.skip { position: absolute; left: 0.5rem; top: -3rem; background: var(--accent); color: var(--accent-ink); padding: 0.4rem 0.7rem; border-radius: var(--radius-sm); }
.skip:focus { top: 0.5rem; z-index: 50; }

/* Layout width. */
.topbar-inner, .hero, main, .site-footer { width: min(1200px, calc(100% - 32px)); margin-inline: auto; }

/* Top bar. */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; gap: 1.25rem; min-height: 60px; flex-wrap: wrap; padding-block: 8px; }
.brand { display: inline-flex; align-items: center; gap: 0.55rem; font-weight: 700; font-size: 1.05rem; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.brand img { border-radius: 7px; display: block; }
.brand .tld { color: var(--muted); font-weight: 500; }
.views { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.views a { padding: 0.32rem 0.85rem; border-radius: 8px; text-decoration: none; color: var(--ink-2); font-size: 0.9rem; font-weight: 550; }
.views a:hover { color: var(--ink); }
.views a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px var(--ring); }
.tools { margin-left: auto; display: flex; gap: 0.5rem; align-items: center; flex: 1 1 260px; justify-content: flex-end; }
.tools input { max-width: 300px; }

/* Controls. */
input, button, select { font: inherit; color: inherit; }
input[type="search"], select {
  width: 100%; padding: 0.45rem 0.75rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; outline: none;
}
input[type="search"]:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
button {
  cursor: pointer; padding: 0.4rem 0.8rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; color: var(--ink);
  font-size: 0.9rem; font-weight: 550; transition: background 0.15s, border-color 0.15s;
}
button:hover { background: var(--surface-2); }
button:focus-visible, a:focus-visible, input:focus-visible, th[tabindex]:focus-visible, [role="button"]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
#theme { white-space: nowrap; }
.search-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Hero. */
.hero { padding: 2.25rem 0 1rem; }
.kicker { margin: 0 0 0.4rem; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.72rem; font-weight: 650; color: var(--muted); }
.lede { max-width: 46rem; margin: 0; color: var(--ink-2); font-size: 1.02rem; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 0.5rem 1.75rem; margin-top: 1.1rem; color: var(--ink-2); font-size: 0.9rem; }
.hero-stats strong { color: var(--ink); font-size: 1.15rem; font-weight: 650; margin-right: 0.25rem; }

/* Panels and cards. */
main { padding-bottom: 2rem; }
.panel { padding: 0.75rem 0 1.5rem; }
.section-head { margin-bottom: 1rem; }
.section-head p { color: var(--ink-2); max-width: 52rem; margin: 0; }
.card, .caveat, .sum-note, .source-card, .chart-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow);
}
.chart-card, .sum-note, .source-card { margin: 1rem 0; }
.caveat { background: var(--surface-2); border: 0; box-shadow: none; color: var(--ink-2); font-size: 0.92rem; margin: 1rem 0; }
.caveat strong { color: var(--ink); }
.meta { color: var(--ink-2); font-size: 0.9rem; }
.tip { font-size: 0.88rem; min-height: 1.3rem; color: var(--ink-2); }
details { margin-top: 0.75rem; }
details > summary { cursor: pointer; color: var(--ink-2); font-size: 0.9rem; font-weight: 550; }
details > summary:hover { color: var(--ink); }
details[open] > summary { margin-bottom: 0.5rem; }
details ul { padding-left: 1.1rem; }
details li { margin: 0.3rem 0; }

/* Badges. */
.badges { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.75rem 0; }
.badge { display: inline-block; font-size: 0.76rem; font-weight: 600; border-radius: 99px; padding: 0.15rem 0.6rem; background: var(--surface-2); color: var(--ink-2); margin: 0; }
.badge.outdated, .badge.warn { background: var(--warn-bg); color: var(--warn); }
p.badge { display: block; border-radius: var(--radius-sm); padding: 0.5rem 0.75rem; font-weight: 500; font-size: 0.85rem; }

/* Map view. */
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .map-layout { grid-template-columns: 1fr; } }
.map-frame { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.map-canvas { background: var(--map-water); }
#map svg, .flow-map svg { display: block; width: 100%; height: auto; }
#map path, .flow-map path.land { stroke: var(--map-stroke); stroke-width: 0.5; transition: fill 0.15s; }
#map path.hit { cursor: pointer; }
#map path.hit:hover, #map path.hit:focus { stroke: var(--ink); stroke-width: 1; outline: none; }
#map path.marker { stroke: var(--ink); stroke-width: 1; }
.map-frame figcaption { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.1rem; padding: 0.75rem 1rem; font-size: 0.82rem; color: var(--ink-2); border-top: 1px solid var(--line); }
.ramp { display: inline-flex; align-items: center; gap: 0.4rem; }
.ramp i { width: 96px; height: 8px; border-radius: 99px; background: linear-gradient(90deg, #cde2fb, #2a78d6, #0d366b); }
html[data-theme="dark"] .ramp i { background: linear-gradient(90deg, #104281, #3987e5, #b7d3f6); }
.swatch { width: 10px; height: 10px; display: inline-block; vertical-align: -1px; margin-right: 0.35rem; border-radius: 3px; flex: none; }
.swatch.none { background: repeating-linear-gradient(45deg, var(--map-none), var(--map-none) 2px, var(--surface) 2px, var(--surface) 4px); }
.swatch.missing { background: var(--map-empty); }
.map-status { color: var(--ink-2); font-size: 0.88rem; margin: 0.6rem 0.25rem 0; min-height: 2.6em; }
.side-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.side-card h3 { margin: 0; padding: 0.9rem 1rem 0.6rem; font-size: 0.92rem; }
.country-list, .search-hits { list-style: none; margin: 0; padding: 0 0 0.35rem; max-height: 34rem; overflow: auto; }
.search-hits { border-top: 1px solid var(--line); }
.search-hits li > strong { display: block; padding: 0.6rem 1rem 0.3rem; font-size: 0.82rem; color: var(--ink-2); }
.country-list button, .search-hits button {
  display: block; width: 100%; text-align: left; border: 0; border-radius: 0; background: transparent; padding: 0.5rem 1rem; font-weight: 550; font-size: 0.92rem;
}
.country-list button:hover, .search-hits button:hover { background: var(--surface-2); }
.country-list button small, .search-hits button small { display: block; color: var(--muted); font-weight: 400; font-size: 0.8rem; }
.confidence-key { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; margin-top: 0.85rem; font-size: 0.8rem; color: var(--ink-2); }
.confidence-key ol { display: contents; list-style: none; }
.confidence-key li { background: var(--surface-2); border-radius: 99px; padding: 0.1rem 0.55rem; }

/* Country view. */
.back { margin: 0.25rem 0 0.75rem; }
.country-hero { padding: 0.5rem 0 0.25rem; }
.country-hero h2 { font-size: clamp(1.8rem, 3.4vw, 2.5rem); letter-spacing: -0.02em; margin-bottom: 0.3rem; }
.country-hero .meta { max-width: 50rem; font-size: 0.95rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.75rem; margin: 1rem 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.85rem 1rem; box-shadow: var(--shadow); }
.stat span { display: block; font-size: 0.78rem; color: var(--ink-2); font-weight: 550; }
.stat strong { display: block; font-size: 1.35rem; font-weight: 650; letter-spacing: -0.01em; margin-top: 0.15rem; }
.stat small { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 0.1rem; }
.wave-switch { display: inline-flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 10px; margin: 0.25rem 0 0.5rem; }
.wave-switch button { border: 0; background: transparent; padding: 0.3rem 0.8rem; border-radius: 8px; }
.wave-switch button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 2px var(--ring); }

/* Charts. */
.charts { display: grid; gap: 1rem; margin: 1rem 0; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart text { fill: var(--ink-2); }
.chart-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 1rem; margin: 1rem 0; align-items: start; }
.chart-pair > .chart-card { margin: 0; }
@media (max-width: 900px) { .chart-pair { grid-template-columns: 1fr; } }
.composition { display: grid; grid-template-columns: minmax(9rem, 14rem) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 560px) { .composition { grid-template-columns: 1fr; } }
.composition svg.chart { max-width: 14rem; }
.slice { cursor: pointer; transition: opacity 0.15s; stroke: var(--surface); stroke-width: 2; }
.slice:hover { opacity: 0.85; }
.slice.dim { opacity: 0.3; }
.slice.selected { stroke: var(--ink); stroke-width: 1.5; }
.legend-list { list-style: none; margin: 0; padding: 0; max-height: 20rem; overflow: auto; }
.legend-list li { display: flex; align-items: baseline; gap: 0.1rem; font-size: 0.86rem; padding: 0.12rem 0; color: var(--ink-2); }
.legend-list button { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3rem; width: 100%; text-align: left; border: 0; border-radius: var(--radius-sm); background: transparent; font-weight: 500; font-size: 0.88rem; padding: 0.3rem 0.45rem; }
.legend-list button:hover { background: var(--surface-2); }
.legend-list button[aria-pressed="true"] { background: var(--accent-soft); }
.legend-list small { color: var(--muted); }
svg.pyramid { max-height: 30rem; }

/* Projection cards. */
.projection h3 { font-size: 1.1rem; }
.proj-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.75rem 1.25rem; margin: 0.75rem 0 0.5rem; padding: 0.85rem 1rem; background: var(--surface-2); border-radius: var(--radius-sm); }
.proj-control { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 0.5rem; font-size: 0.85rem; align-items: center; margin: 0; }
.proj-control > span { grid-column: 1 / -1; color: var(--ink-2); font-weight: 550; }
.proj-control select { grid-column: 1 / -1; padding: 0.3rem 0.5rem; }
.proj-control input[type="range"] { width: 100%; accent-color: var(--accent); }
.proj-control output { font-variant-numeric: tabular-nums; min-width: 3.5rem; text-align: right; color: var(--ink); font-weight: 600; }
.proj-rule { grid-column: 1 / -1; margin: 0; }

/* Tables. */
.table-wrap, .table-scroll { overflow-x: auto; max-width: 100%; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
caption { text-align: left; padding: 0.9rem 1rem; color: var(--ink-2); font-size: 0.85rem; }
th, td { padding: 0.55rem 0.75rem; border-top: 1px solid var(--line); vertical-align: top; text-align: left; }
thead th { border-top: 0; background: var(--surface-2); font-weight: 600; font-size: 0.8rem; color: var(--ink-2); }
th { cursor: pointer; white-space: nowrap; }
td.num, th.num, .group-table td.num, .group-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
th[aria-sort="ascending"]::after { content: " ↑"; }
th[aria-sort="descending"]::after { content: " ↓"; }
tbody tr:hover { background: var(--surface-2); }
.group-table tbody tr { cursor: pointer; }
tr.highlight { background: var(--accent-soft); }
mark { background: #fdeab5; color: inherit; border-radius: 3px; }
html[data-theme="dark"] mark { background: #5c4a22; }

/* Migration flows. */
.flows-card { padding: 0; overflow: hidden; }
.flows-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 0.75rem; padding: 1.1rem 1.25rem 0.75rem; }
.flows-head h3 { margin: 0 0 0.2rem; }
.flows-head p { margin: 0; }
.segmented { display: inline-flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.segmented button { border: 0; background: transparent; padding: 0.3rem 0.8rem; border-radius: 8px; font-size: 0.85rem; display: inline-flex; align-items: center; gap: 0.4rem; }
.segmented button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 2px var(--ring); }
.segmented .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.flows-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; border-top: 1px solid var(--line); }
@media (max-width: 900px) { .flows-body { grid-template-columns: 1fr; } }
.flow-map { background: var(--map-water); position: relative; }
.flow-map path.land { fill: var(--map-empty); }
.flow-map path.land.focus { fill: var(--ink); }
.flow-map path.land.partner { fill: var(--line-strong); }
.flow-arc { fill: none; stroke-linecap: round; opacity: 0.85; transition: opacity 0.15s; cursor: default; }
.flow-arc.in { stroke: var(--flow-in); }
.flow-arc.out { stroke: var(--flow-out); }
.flow-map svg.dimmed .flow-arc { opacity: 0.18; }
.flow-map svg.dimmed .flow-arc.on { opacity: 1; }
.flow-hit { fill: none; stroke: transparent; stroke-width: 12; cursor: pointer; }
.flow-node { stroke: var(--surface); stroke-width: 1.5; }
.flow-label { font-size: 10px; font-weight: 600; fill: var(--ink); paint-order: stroke; stroke: var(--map-water); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.flow-tooltip {
  position: absolute; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem; font-size: 0.8rem; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12); max-width: 240px; z-index: 5;
}
.flow-tooltip strong { display: block; font-size: 0.95rem; }
.flow-list { padding: 0.75rem 0; border-left: 1px solid var(--line); max-height: 520px; overflow: auto; }
@media (max-width: 900px) { .flow-list { border-left: 0; border-top: 1px solid var(--line); } }
.flow-list h4 { margin: 0.25rem 1rem 0.35rem; display: flex; align-items: center; gap: 0.4rem; color: var(--ink); }
.flow-list ol { list-style: none; margin: 0 0 0.75rem; padding: 0; }
.flow-list li { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; padding: 0.3rem 1rem; font-size: 0.86rem; cursor: default; }
.flow-list li:hover, .flow-list li.on { background: var(--surface-2); }
.flow-list li .bar { grid-column: 1 / -1; height: 3px; border-radius: 99px; background: currentColor; opacity: 0.85; }
.flow-list li.in { color: var(--flow-in); }
.flow-list li.out { color: var(--flow-out); }
.flow-list li span, .flow-list li b { color: var(--ink); font-weight: 500; }
.flow-list li b { font-variant-numeric: tabular-nums; font-weight: 600; }
.flows-foot { padding: 0.75rem 1.25rem 1rem; border-top: 1px solid var(--line); }
.flows-foot p { margin: 0; }

/* About and footer. */
.prose { max-width: 46rem; }
.prose h3 { margin-top: 1.75rem; }
.prose li { margin: 0.4rem 0; }
.site-footer { padding: 1.5rem 0 2.5rem; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--line); }

@media (max-width: 640px) {
  .topbar-inner { gap: 0.6rem; }
  .tools { flex-basis: 100%; }
  .tools input { max-width: none; }
  .card:not(.flows-card), .chart-card { padding: 0.9rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* Grid and flex children may shrink below their content (the map SVG is 960 wide by default). */
.map-layout > *, .chart-pair > *, .flows-body > *, .composition > * { min-width: 0; }
.tools input { flex: 1 1 auto; min-width: 0; }
