:root {
  --bg:        #FFFFFF;
  --bg-2:      #F4F5F2;
  --card:      #FFFFFF;
  --card-edge: #E2E4DF;
  --paper:     #16181A;   /* text on light, not a background */
  --dim:       #585D64;
  --dimmer:    rgba(88, 93, 100, 0.65);

  /* Region palette. Every colour on this page means a region.
     Each one clears 4.5:1 as text on both white and the band. */
  --r-af: #9A5B00;
  --r-as: #D42546;
  --r-eu: #1668C6;
  --r-na: #00786A;
  --r-sa: #1E7F3C;
  --r-oc: #C22F6B;

  /* Soft tints of the same hues, for tile and bar fills. */
  --t-af: rgba(154, 91, 0, 0.09);
  --t-as: rgba(212, 37, 70, 0.08);
  --t-na: rgba(0, 120, 106, 0.09);
  --t-sa: rgba(30, 127, 60, 0.09);

  --live:   #1E7F3C;
  --deaths: #5B6472;

  --step--1: clamp(0.78rem, 0.75rem + 0.16vw, 0.86rem);
  --step-0:  clamp(0.95rem, 0.91rem + 0.22vw, 1.05rem);
  --step-1:  clamp(1.15rem, 1.02rem + 0.55vw, 1.42rem);
  --step-2:  clamp(1.55rem, 1.25rem + 1.3vw, 2.3rem);
  --measure: 62ch;
  --radius: 14px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--paper);
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  font-size: var(--step-0);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--r-na); text-underline-offset: 0.18em; }
a:hover { color: var(--paper); }
:focus-visible { outline: 2px solid var(--r-eu); outline-offset: 3px; border-radius: 4px; }

.skip { position: absolute; left: -9999px; top: 0; background: var(--paper);
        color: #FFFFFF; padding: 0.6rem 1rem; z-index: 100; }
.skip:focus { left: 0; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  border: 0; clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

.wrap { width: min(100% - 2rem, 70rem); margin-inline: auto; }

/* ---------- masthead and logo ---------- */

.masthead { padding: 1.1rem 0; }
.masthead .wrap { display: flex; align-items: center; gap: 0.7rem; }
.brand { display: inline-flex; align-items: center; gap: 0.6rem; text-decoration: none; }
.brand svg { display: block; flex: 0 0 auto; }
.brand .name {
  font-weight: 700; font-size: 1.02rem; letter-spacing: -0.015em;
  color: var(--paper); line-height: 1.1;
}
.brand .name span { display: block; font-weight: 400; font-size: 0.72rem;
                    color: var(--dim); letter-spacing: 0.02em; }


/* ---------- hero counter ---------- */

.hero { text-align: center; padding: clamp(1.8rem, 5vw, 3.4rem) 0 clamp(1.4rem, 3vw, 2.2rem); }

.eyebrow {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-size: var(--step--1); color: var(--dim); margin: 0 0 1rem;
  letter-spacing: 0.04em;
}
.pulse {
  width: 0.5rem; height: 0.5rem; border-radius: 50%;
  background: var(--live); flex: 0 0 auto;
  box-shadow: 0 0 0 0 rgba(30, 127, 60, 0.6);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(30, 127, 60, 0.45); }
  70%  { box-shadow: 0 0 0 0.7rem rgba(30, 127, 60, 0); }
  100% { box-shadow: 0 0 0 0 rgba(30, 127, 60, 0); }
}

.counter {
  display: flex; justify-content: center; flex-wrap: nowrap;
  font-size: clamp(2.35rem, 10.5vw, 7rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1;
  margin: 0;
  color: var(--paper);
}
.d   { display: inline-block; text-align: center; width: 0.615em; }
.sep { display: inline-block; width: 0.24em; }

.subline { margin: 1.1rem 0 0; color: var(--dim); font-size: var(--step-1); }
.subline b { color: var(--paper); font-weight: 600; }

/* ---------- stat tiles ---------- */

.tiles {
  display: grid; gap: 0.8rem;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  margin: clamp(1.6rem, 4vw, 2.6rem) 0 0;
}
.tile {
  border: 1px solid var(--card-edge);
  border-radius: var(--radius); padding: 1.05rem 1.1rem;
  border-top: 3px solid var(--tc, var(--dim));
}
.tile .n {
  font-size: clamp(1.35rem, 4.2vw, 1.95rem); font-weight: 700;
  line-height: 1.05; margin: 0; color: var(--tc, var(--paper));
  font-variant-numeric: tabular-nums;
}
.tile .k { margin: 0.3rem 0 0; font-size: var(--step--1); color: var(--dim); }
.tile { background: var(--tbg, var(--card)); }
.tile.births { --tc: var(--r-sa); --tbg: var(--t-sa); }
.tile.deaths { --tc: var(--deaths); --tbg: rgba(91, 100, 114, 0.07); }
.tile.net    { --tc: var(--r-af); --tbg: var(--t-af); }
.tile.you    { --tc: var(--r-as); --tbg: var(--t-as); }

/* ---------- milestone ---------- */

.milestone {
  margin: clamp(1.6rem, 4vw, 2.4rem) 0 0;
  background: linear-gradient(180deg, rgba(0,120,106,0.10), rgba(0,120,106,0.02));
  border: 1px solid var(--card-edge); border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
}
.milestone h2 { margin: 0 0 0.15rem; font-size: var(--step-1); font-weight: 600; }
.milestone p  { margin: 0; color: var(--dim); font-size: var(--step--1); }
.track {
  margin: 0.9rem 0 0.5rem; height: 0.55rem; border-radius: 99px;
  background: rgba(22, 24, 26, 0.09); overflow: hidden;
}
.track i { display: block; height: 100%; background: var(--r-na); border-radius: 99px; }

/* ---------- sections ---------- */

section.band { padding: clamp(2.2rem, 5vw, 3.4rem) 0; }
section.alt  { background: var(--bg-2); }

h2.section { font-size: var(--step-2); font-weight: 700; letter-spacing: -0.02em;
             line-height: 1.12; margin: 0 0 0.5rem; }
p.lede { margin: 0 0 1.5rem; color: var(--dim); max-width: var(--measure); }

/* ---------- region chips ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0 0 1.1rem; padding: 0; list-style: none; }
.chip {
  background: var(--bg); border: 1px solid var(--card-edge);
  color: var(--paper); border-radius: 99px; padding: 0.4rem 0.9rem;
  font: inherit; font-size: var(--step--1); cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.45rem;
}
.chip:hover { border-color: var(--cc, var(--paper)); }
.chip[aria-pressed="true"] { background: var(--cc, var(--paper)); color: #FFFFFF; border-color: transparent; font-weight: 600; }
.chip .dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--cc, var(--dim)); }
.chip[aria-pressed="true"] .dot { background: #FFFFFF; }

/* ---------- country list ---------- */

.controls { display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: center; margin-bottom: 1rem; }
.controls input {
  background: var(--bg); border: 1px solid var(--card-edge); color: var(--paper);
  padding: 0.6rem 0.9rem; font: inherit; font-size: var(--step--1);
  border-radius: 99px; min-width: 13rem; flex: 1 1 13rem;
}
.controls input::placeholder { color: var(--dimmer); }
.controls .count { font-size: var(--step--1); color: var(--dim); }

.tablescroll { overflow-x: auto; }
table.countries { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: var(--step--1); }
table.countries th, table.countries td { padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--card-edge); }
table.countries th:first-child, table.countries td:first-child { padding-left: 0; width: 2.6rem; }
table.countries th { text-align: right; font-weight: 500; color: var(--dim); white-space: nowrap; }
table.countries th:nth-child(2) { text-align: left; }
table.countries td { text-align: right; white-space: nowrap; }
table.countries td:nth-child(2) { text-align: left; white-space: normal; }
table.countries tbody tr:hover { background: rgba(22, 24, 26, 0.035); }
table.countries th button {
  background: none; border: 0; color: inherit; font: inherit; font-weight: 500;
  cursor: pointer; padding: 0.15rem 0; display: inline-flex; gap: 0.3rem; align-items: center;
}
th button[aria-sort="descending"]::after { content: '\25BC'; font-size: 0.58em; }
th button[aria-sort="ascending"]::after  { content: '\25B2'; font-size: 0.58em; }

.cname { display: inline-flex; align-items: center; gap: 0.55rem; }
.cdot  { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--rc, var(--dim)); flex: 0 0 auto; }

.barcell { width: 34%; min-width: 7rem; }
.bar { height: 0.5rem; border-radius: 99px; background: rgba(22, 24, 26, 0.08); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--rc, var(--dim)); border-radius: 99px; }

.up   { color: var(--r-sa); }
.down { color: var(--r-as); }
.nodata { color: var(--dimmer); }

.moreline { text-align: center; margin: 1.3rem 0 0; }
.more {
  background: var(--bg); border: 1px solid var(--card-edge); color: var(--paper);
  border-radius: 99px; padding: 0.6rem 1.4rem; font: inherit; font-size: var(--step--1);
  cursor: pointer; font-weight: 500;
}
.more:hover { border-color: var(--paper); }

.tablenote { font-size: var(--step--1); color: var(--dim); margin: 1rem 0 0; max-width: var(--measure); }
.status { color: var(--dim); font-size: var(--step--1); }
.status.err { color: var(--r-as); }

/* ---------- prose ---------- */

.prose p { max-width: none; margin: 0 0 1rem; color: var(--dim); }
.prose p strong { color: var(--paper); font-weight: 600; }
.prose h2 { margin-top: 2.2rem; }
.prose h2:first-child { margin-top: 0; }

/* ---------- footer ---------- */

footer { background: var(--bg-2); padding: clamp(2rem, 5vw, 3rem) 0 2rem; }
footer .sources { font-size: var(--step--1); color: var(--dim); max-width: none; }
footer .sources p { margin: 0 0 0.7rem; max-width: none; }

.footbar {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 0.7rem 1.6rem;
  margin-top: 1.9rem; padding-top: 1.3rem;
  border-top: 1px solid var(--card-edge);
}
.legal-links { display: flex; flex-wrap: wrap; gap: 0.4rem 1.3rem; margin: 0;
               padding: 0; list-style: none; font-size: var(--step--1); }
.legal-links button { background: none; border: 0; padding: 0; cursor: pointer; color: var(--dim);
                      font: inherit; text-decoration: underline; text-underline-offset: 0.18em; }
.legal-links button:hover { color: var(--paper); }

.colophon { font-size: var(--step--1); color: var(--dim); text-align: left; line-height: 1.7; margin: 0; }
.colophon a { color: var(--dim); }
.colophon a:hover { color: var(--paper); }

/* ---------- modals ---------- */

dialog.legal { width: min(100% - 2rem, 46rem); max-height: 82vh; background: #FFFFFF;
               color: var(--paper); border: 0; padding: 0; border-radius: var(--radius);
               box-shadow: 0 24px 60px rgba(22,24,26,0.22); }
dialog.legal::backdrop { background: rgba(22, 24, 26, 0.55); }
dialog.legal .dlg-head { position: sticky; top: 0; background: #FFFFFF; display: flex;
  justify-content: space-between; align-items: center; gap: 1rem;
  padding: 1.2rem 1.4rem 0.8rem; border-bottom: 1px solid var(--card-edge); }
dialog.legal h2 { margin: 0; font-size: var(--step-1); font-weight: 700; }
dialog.legal .dlg-body { padding: 1.1rem 1.4rem 1.8rem; overflow-y: auto; }
dialog.legal p { margin: 0 0 0.9rem; max-width: 62ch; font-size: var(--step--1); line-height: 1.7; color: var(--dim); }
dialog.legal .close { background: var(--paper); color: #FFFFFF; border: 0; border-radius: 99px;
                      padding: 0.45rem 1rem; cursor: pointer; font: inherit; font-size: var(--step--1); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
                           transition-duration: 0.001ms !important; }
}

/* ---------- country pages ---------- */

.crumbs { font-size: var(--step--1); color: var(--dim); margin: 0 0 1.4rem; }
.crumbs a { color: var(--dim); }
.crumbs a:hover { color: var(--paper); }
.crumbs span { margin: 0 0.4rem; color: var(--dimmer); }

.country-hero { text-align: center; padding: clamp(1.4rem, 4vw, 2.6rem) 0 clamp(1.2rem, 3vw, 2rem); }
.country-hero .region-tag {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-size: var(--step--1); color: var(--dim); margin: 0 0 0.9rem;
}
.country-hero .region-tag .dot { width: 0.55rem; height: 0.55rem; border-radius: 50%;
                                 background: var(--rc, var(--dim)); }
h1.country-name {
  font-size: var(--step-1); font-weight: 500; letter-spacing: 0;
  margin: 0 0 0.7rem; line-height: 1.2; color: var(--dim);
}

.country-hero .counter {
  font-size: clamp(2.2rem, 11vw, 6.8rem);
  letter-spacing: -0.04em;
}
.country-hero .subline { margin-top: 0.9rem; }

.facts { display: grid; gap: 0.8rem; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
         margin: clamp(1.4rem, 4vw, 2.2rem) 0 0; }
.fact { background: var(--card); border: 1px solid var(--card-edge); border-radius: var(--radius);
        padding: 0.95rem 1rem; text-align: left; }
.fact .n { margin: 0; font-size: clamp(1.15rem, 3.4vw, 1.5rem); font-weight: 700; line-height: 1.1;
           font-variant-numeric: tabular-nums; }
.fact .k { margin: 0.25rem 0 0; font-size: var(--step--1); color: var(--dim); }

.pager { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.8rem;
         margin-top: 1.6rem; padding-top: 1.3rem; border-top: 1px solid var(--card-edge);
         font-size: var(--step--1); }
.pager a { display: inline-flex; flex-direction: column; gap: 0.1rem; text-decoration: none; }
.pager .lbl { color: var(--dim); font-size: 0.82em; }
.pager .val { color: var(--r-eu); font-weight: 600; }
.pager .next { text-align: right; margin-left: auto; }

.neighbours { display: flex; flex-wrap: wrap; gap: 0.45rem; padding: 0; list-style: none; margin: 0; }
.neighbours a {
  display: inline-flex; align-items: center; gap: 0.45rem; text-decoration: none;
  background: var(--bg); border: 1px solid var(--card-edge); border-radius: 99px;
  padding: 0.4rem 0.9rem; font-size: var(--step--1); color: var(--paper);
}
.neighbours a:hover { border-color: var(--rc, var(--paper)); }
.neighbours .dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--rc, var(--dim)); }

table.countries td a { color: var(--paper); text-decoration: none; }
table.countries td a:hover { color: var(--r-eu); text-decoration: underline; }

.legal-page h1 { font-size: var(--step-2); font-weight: 700; margin: 0 0 1.2rem; letter-spacing: -0.02em; }
.legal-page p { max-width: 68ch; color: var(--dim); margin: 0 0 1rem; }


/* ---------- advertise overlay ---------- */

dialog.adv .dlg-body { padding-top: 1.3rem; }

.adv-stats {
  display: grid; gap: 0.5rem; list-style: none; margin: 0 0 0.7rem; padding: 0;
  grid-template-columns: repeat(auto-fit, minmax(8.2rem, 1fr));
}
.adv-stats li {
  border: 1px solid var(--card-edge); border-radius: 12px;
  padding: 0.85rem 0.9rem; border-top: 3px solid var(--sc, var(--r-eu));
  background: var(--bg-2);
}
.adv-stats li:nth-child(1) { --sc: var(--r-eu); }
.adv-stats li:nth-child(2) { --sc: var(--r-na); }
.adv-stats li:nth-child(3) { --sc: var(--r-sa); }
.adv-stats li:nth-child(4) { --sc: var(--r-af); }
.adv-stats li:nth-child(5) { --sc: var(--r-oc); }
.adv-stats .v {
  display: block; font-size: 1.5rem; font-weight: 700; line-height: 1.05;
  color: var(--sc, var(--paper)); font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.adv-stats .k {
  display: block; font-size: 0.76rem; line-height: 1.35; color: var(--dim);
  margin-top: 0.25rem;
}
.adv-note { font-size: 0.78rem; color: var(--dim); margin: 0 0 1.6rem; }

.adv-h {
  font-size: 0.82rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--r-eu);
  margin: 1.7rem 0 0.5rem; padding-top: 1rem;
  border-top: 1px solid var(--card-edge);
}

.adv-cta {
  margin: 1.9rem 0 0; padding: 1.2rem 1.2rem 1.3rem;
  background: var(--bg-2); border: 1px solid var(--card-edge); border-radius: 12px;
}
.adv-cta-lead { margin: 0 0 0.9rem; max-width: 52ch; }
.adv-cta-btn {
  display: inline-block; background: var(--r-eu); color: #FFFFFF;
  text-decoration: none; border-radius: 99px; padding: 0.6rem 1.3rem;
  font-size: var(--step--1); font-weight: 600;
}
.adv-cta-btn:hover { background: var(--paper); color: #FFFFFF; }

.dot-sep { color: var(--dimmer); margin: 0 0.3rem; }
.adv-inline {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-size: inherit; color: var(--r-na);
  text-decoration: underline; text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}
.adv-inline:hover { color: var(--paper); }

/* ---------- ad slots ---------- */

/* Symmetric, so the slot sits centred in its own band rather than pinned to
   the top of it. */
.adrail { padding: 0.85rem 0; text-align: center; }

/* The blocks either side carry large default padding that would otherwise
   land almost entirely below the slot. Trimming both to the same small value
   leaves an equal 1rem of space above and below. */
.masthead:has(+ .adrail),
.hero:has(+ .adrail),
.country-hero:has(+ .adrail),
section.band:has(+ .adrail) { padding-bottom: 0.15rem; }

.adrail + section,
.adrail + main > section:first-child { padding-top: 0.15rem; }
/* The height is reserved once, here on the wrapper, so nothing inside can
   add a second reservation on top of it. Whatever ends up inside, a real ad
   or the placeholder, fills this space rather than extending it. */
.adwrap {
  width: 100%; max-width: 970px; margin-inline: auto;
  min-height: 90px;
  display: flex; flex-direction: column; justify-content: center;
}

/* Small centred caption above live creative, so an advertisement is always
   distinguishable from the content around it. */
.adlabel {
  display: block; text-align: center;
  font-size: 0.62rem; letter-spacing: 0.16em; text-transform: uppercase;
  font-weight: 600; color: var(--dimmer); margin-bottom: 0.45rem;
}
.adlabel[hidden] { display: none; }

/* Deliberately no min-height here. The wrapper above already reserves the
   space; repeating it on the ad container is what stacked an empty 90px slot
   on top of the 90px placeholder. */
.adwrap > div[id^="ad-"] {
  display: flex; align-items: center; justify-content: center;
}
.adwrap.is-empty > div[id^="ad-"] { display: none; }
@media (max-width: 740px) {
  .adwrap { min-height: 100px; }
  .adhouse { min-height: 100px; }
}

/* Placeholder shown only when the slot is confirmed empty. One line, dashed
   outline, nothing else. Never sits over live creative. */
.adhouse {
  display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: 90px;
  background: var(--bg-2);
  border: 1px dashed var(--card-edge);
  border-radius: 6px;
  font: inherit; font-size: 0.7rem; font-weight: 600;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--dim); cursor: pointer;
}
.adhouse:hover { color: var(--r-eu); border-color: var(--r-eu); }
.adhouse[hidden] { display: none; }