:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #15181c;
  --muted: #5f6772;
  --border: #e0e4e9;
  /* flag navy, census-count's colour: --accent fills and underlines, --link the text links */
  --accent: #27418f;
  --accent-text: #ffffff;
  --link: #223a82;
  --track: #e8ebef;
  --radius: 12px;
  /* map: none, then two ramps of five, light to dark: people gained (teal) and people lost (orange).
     Gains and losses use steps 1, 3 and 5 of each; births and deaths all five of one. */
  --map-0: #e9ebee;
  --gain-1: #d3f1ec; --gain-2: #9bdcd1; --gain-3: #4cbdad; --gain-4: #0f9d8c; --gain-5: #0a665b;
  --loss-1: #fbe3d0; --loss-2: #f4c09a; --loss-3: #e8985c; --loss-4: #cf6a26; --loss-5: #8f420e;
  --map-sea: #eef3f8;
  /* the year-by-year bars: births, deaths, international migration, domestic migration */
  --s-births: #2a78d6; --s-deaths: #eb6834; --s-intl: #1baf7a; --s-dom: #eda100;
  --grid: #e6e9ed; --axis: #b9c0c9;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1215; --surface: #181c21; --text: #e7eaee; --muted: #9aa2ad; --border: #2a3038;
  --accent: #8ea6f2; --accent-text: #0a1230; --link: #9db3f5; --track: #262c33;
  --map-0: #2c3038;
  --gain-1: #123b37; --gain-2: #175c54; --gain-3: #1c8376; --gain-4: #35b3a4; --gain-5: #9fe6dc;
  --loss-1: #46240e; --loss-2: #713a15; --loss-3: #a65a24; --loss-4: #d98548; --loss-5: #f8c8a0;
  --map-sea: #14171c;
  --s-births: #3987e5; --s-deaths: #d95926; --s-intl: #199e70; --s-dom: #c98500;
  --grid: #262c33; --axis: #3a424c;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1215; --surface: #181c21; --text: #e7eaee; --muted: #9aa2ad; --border: #2a3038;
    --accent: #8ea6f2; --accent-text: #0a1230; --link: #9db3f5; --track: #262c33;
    --map-0: #2c3038;
    --gain-1: #123b37; --gain-2: #175c54; --gain-3: #1c8376; --gain-4: #35b3a4; --gain-5: #9fe6dc;
    --loss-1: #46240e; --loss-2: #713a15; --loss-3: #a65a24; --loss-4: #d98548; --loss-5: #f8c8a0;
    --map-sea: #14171c;
    --s-births: #3987e5; --s-deaths: #d95926; --s-intl: #199e70; --s-dom: #c98500;
    --grid: #262c33; --axis: #3a424c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--link); }
h1, h2, h3, p { margin: 0; }

main, .foot { max-width: 1200px; margin: 0 auto; padding: 0 16px; } /* 1200 as the sister projects, so the maps line up */
main { padding-top: 16px; min-height: 100vh; display: flex; flex-direction: column; gap: 16px; } /* always scrolls, as the sister pages do */
.muted { color: var(--muted); font-weight: 400; }

/* mathemantique bar above the top bar, as on the sister projects */
.site-bar { background: #007FFF; text-align: center; padding: .4rem 16px; padding-left: calc(16px + 100vw - 100%); } /* the scrollbar's width added on the left: the name sits at the window's centre */
.site-bar a { color: #fff; text-decoration: none; font-family: Georgia, 'Times New Roman', serif; font-size: 1.15rem; font-weight: bold; letter-spacing: .02em; }
.site-bar a:hover { text-decoration: underline; }

.topbar { display: flex; align-items: center; gap: .5rem 1rem; padding: .7rem 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: .01em; flex: 1; }
.brand .muted { font-weight: 400; margin-left: .4rem; }
.theme-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 2px; background: var(--bg); flex-shrink: 0; }
.theme-toggle button { font: inherit; font-size: .82rem; border: 0; background: transparent; color: var(--muted); padding: .25rem .65rem; border-radius: 999px; cursor: pointer; }
.theme-toggle button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }
@media (max-width: 560px) { .brand { flex-basis: 100%; } }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.panel h2 { font-size: 1.05rem; margin-bottom: .5rem; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 1.05rem; margin: 0 0 .6rem; }
.crumbs .sep { color: var(--muted); }
.crumbs .here { font-weight: 700; }
button.link { border: 0; background: none; padding: 0; font: inherit; color: var(--link); cursor: pointer; text-align: left; }
button.link:hover { text-decoration: underline; }
.year-text { font-size: .95rem; line-height: 1.55; max-width: 70rem; }

/* map with its filters on the left: the same layout as the sister projects */
.map-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.map-filters { display: flex; flex-direction: column; gap: .7rem; min-width: 0; font-size: .9rem; }
.map-filters label, .map-filters .label { display: flex; flex-direction: column; gap: .2rem; color: var(--muted); }
.map-filters select { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .3rem .4rem; }
.map-main { min-width: 0; }
@media (max-width: 820px) { .map-layout { grid-template-columns: minmax(0, 1fr); } }
.summary { color: var(--muted); }
.note { color: var(--muted); font-size: .82rem; margin-top: .4rem; }

/* who: age, sex, race, Hispanic origin */
.who { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem .6rem; padding: .6rem; border: 1px solid var(--border); border-radius: 8px; }
.who-head { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; color: var(--text); font-weight: 600; }
.who-head button.link { font-weight: 400; font-size: .85rem; }
.who label { min-width: 0; }
.who .note { grid-column: 1 / -1; margin-top: 0; }

.periods { display: flex; flex-wrap: wrap; gap: 6px; }
.periods button { font: inherit; font-size: .85rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 4px 12px; cursor: pointer; }
.periods button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.download { font-size: .85rem; align-self: flex-start; }

.totals { width: 100%; border-collapse: collapse; font-size: .85rem; }
.totals td { padding: 3px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.totals td.n { text-align: right; font-variant-numeric: tabular-nums; padding-left: 8px; white-space: nowrap; }
.totals tr.on td { font-weight: 700; }
.totals tr.sub td:first-child { padding-left: 12px; }
.totals tr.end td { border-bottom: 0; }
.totals button.link { font-size: .85rem; }

.worldmap { position: relative; }
.worldmap svg { display: block; width: 100%; height: auto; max-height: 72vh; background: var(--map-sea); border-radius: 8px; touch-action: auto; cursor: grab; }
.worldmap svg.zoomed { touch-action: none; }
.worldmap svg.dragging { cursor: grabbing; }
.worldmap .unit { stroke: var(--surface); stroke-width: .6; vector-effect: non-scaling-stroke; cursor: pointer; fill-rule: evenodd; }
.worldmap .unit.dot { stroke-width: 1; }
.worldmap .unit:hover, .worldmap .unit:focus { stroke: var(--text); stroke-width: 1.5; outline: none; }
.worldmap .unit.dim { opacity: .35; }
.worldmap .unit.selected { stroke: var(--text); stroke-width: 2; }
.worldmap .inset { fill: none; stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.map-zoom { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 4px; }
.map-zoom button { font: inherit; min-width: 30px; height: 30px; padding: 0 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); cursor: pointer; font-size: 1rem; line-height: 1; }
.map-zoom button.reset { font-size: .7rem; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-c0 { fill: var(--map-0); background: var(--map-0); }
/* one ramp of five (births; deaths with .loss on the map's box) */
.map-c1 { fill: var(--gain-1); background: var(--gain-1); }
.map-c2 { fill: var(--gain-2); background: var(--gain-2); }
.map-c3 { fill: var(--gain-3); background: var(--gain-3); }
.map-c4 { fill: var(--gain-4); background: var(--gain-4); }
.map-c5 { fill: var(--gain-5); background: var(--gain-5); }
.worldmap.loss .map-c1 { fill: var(--loss-1); background: var(--loss-1); }
.worldmap.loss .map-c2 { fill: var(--loss-2); background: var(--loss-2); }
.worldmap.loss .map-c3 { fill: var(--loss-3); background: var(--loss-3); }
.worldmap.loss .map-c4 { fill: var(--loss-4); background: var(--loss-4); }
.worldmap.loss .map-c5 { fill: var(--loss-5); background: var(--loss-5); }
/* gains and losses: three bands each side of zero */
.map-g1 { fill: var(--gain-1); background: var(--gain-1); }
.map-g2 { fill: var(--gain-3); background: var(--gain-3); }
.map-g3 { fill: var(--gain-5); background: var(--gain-5); }
.map-l1 { fill: var(--loss-1); background: var(--loss-1); }
.map-l2 { fill: var(--loss-3); background: var(--loss-3); }
.map-l3 { fill: var(--loss-5); background: var(--loss-5); }
.map-legend { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .3rem .9rem; margin-top: .5rem; font-size: .8rem; color: var(--muted); }
.map-legend .sw { display: inline-block; width: 16px; height: 10px; border-radius: 2px; margin-right: .3rem; vertical-align: -1px; }
.chart-tip { position: absolute; transform: translateX(-50%); pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .4rem .6rem; font-size: .82rem; box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; color: var(--text); z-index: 5; }
.chart-tip .tip-head { font-weight: 600; margin-bottom: .15rem; }
.chart-tip .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; }

/* year-by-year bars */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 280px; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .zero { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart text.year { font-size: 12px; }
.chart text.net { fill: var(--text); font-weight: 600; }
.chart .net-line { stroke: var(--text); stroke-width: 2; stroke-linecap: round; }
.chart .hit { fill: transparent; }
.chart .group:hover .hit { fill: var(--track); opacity: .5; }
.s-births { fill: var(--s-births); background: var(--s-births); }
.s-deaths { fill: var(--s-deaths); background: var(--s-deaths); }
.s-intl { fill: var(--s-intl); background: var(--s-intl); }
.s-dom { fill: var(--s-dom); background: var(--s-dom); }
.s-net { background: var(--text); }
/* a group's one bar a year: grew or shrank, as on the map */
.s-gain { fill: var(--gain-4); background: var(--gain-4); }
.s-loss { fill: var(--loss-4); background: var(--loss-4); }
.chart-key { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .8rem; color: var(--muted); margin-top: .3rem; }
.chart-key .sw { display: inline-block; width: 12px; height: 10px; border-radius: 2px; margin-right: .3rem; vertical-align: -1px; }
.chart-key .sw.s-net { height: 2px; width: 14px; vertical-align: 3px; }

/* every place, ranked: a bar each side of zero */
.rank { list-style: none; margin: .4rem 0 0; padding: 0; columns: 2 420px; column-gap: 32px; font-size: .85rem; }
.rank li { break-inside: avoid; display: grid; grid-template-columns: 1.7rem minmax(0, 9.5rem) minmax(40px, 1fr) 5.6rem; gap: 8px; align-items: center; padding: 2px 0; }
/* on a phone the name comes first: it takes the room, the bar is short */
@media (max-width: 520px) { .rank li { grid-template-columns: 1.6rem minmax(0, 1fr) 2.6rem auto; gap: 6px; } }
.rank .i { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.rank button.link { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.rank li.on button.link { font-weight: 700; }
.rank .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rank .track { position: relative; height: 10px; }
.rank .track::before { content: ""; position: absolute; top: -3px; bottom: -3px; left: var(--zero, 0%); width: 1px; background: var(--axis); }
.rank .fill { position: absolute; top: 0; bottom: 0; min-width: 1px; }
.rank .fill.pos { border-radius: 0 3px 3px 0; }
.rank .fill.neg { border-radius: 3px 0 0 3px; }
.rank .fill.gain { background: var(--gain-4); }
.rank .fill.loss { background: var(--loss-4); }
.rank li.none .n { color: var(--muted); }

.foot { color: var(--muted); font-size: 0.8rem; padding-top: 16px; padding-bottom: 32px; display: flex; flex-direction: column; gap: 6px; }
