/* world-population-playback.alxevt.com
   One dark instrument surface, one accent spent on time, mint/coral spent on
   demographic direction. All visual decisions live here; JS writes state via
   classes, attributes and custom properties only (CSP: no inline styles). */

:root {
  --bg: #0b0e11;
  --surface: #11161b;
  --surface-2: #161c22;
  --line: rgba(240, 246, 250, 0.09);
  --ink: #f2f5f7;
  --ink-2: #9aa5ae;
  --ink-3: #7d8892; /* muted voice, still ≥4.5:1 on every surface it sits on */
  --accent: #1e9ad4;        /* marks, fills — validated ≥3:1 on --bg */
  --accent-text: #5ec1ee;   /* small text/chips on --bg */
  --accent-ink: #06202e;    /* ink on accent fills */
  --pos: #65d6bd;           /* births, growth  (house token) */
  --neg: #ff7e6b;           /* deaths, decline (house token) */
  --focus: #8ed0f2;
  --radius: 16px;
  --radius-s: 10px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur: 180ms;
  --pad-x: clamp(1.1rem, 4.5vw, 3.5rem);
  --gap: clamp(2rem, 5.5vw, 4rem);
  --max: 62rem;
  --ff: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ff-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --ff-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --ff-hero: var(--ff);       /* face for the big counter — swapped per skin */
  --hero-weight: 750;
  --hero-tracking: -0.055em;
  --ground: radial-gradient(120% 90% at 50% -10%, #10161d 0%, var(--bg) 55%), var(--bg);
  color-scheme: dark;
}

/* ---------- skins (cycled by the Skin button) ---------- */
/* SOLARI — a mechanical departure board: warm near-black, amber on the flaps,
   monospace figures. Nods to timer.alxevt.com. */
:root[data-skin="solari"] {
  --bg: #0d0e10;
  --surface: #16181c;
  --surface-2: #1d2025;
  --line: rgba(245, 232, 205, 0.10);
  --ink: #f3ecdd;
  --ink-2: #bcae94;
  --ink-3: #948868;
  --accent: #f3a51f;
  --accent-text: #ffc65e;
  --accent-ink: #241800;
  --pos: #86d68f;
  --neg: #ff9152;
  --focus: #ffc65e;
  --ff-hero: var(--ff-mono);
  --hero-weight: 600;
  --hero-tracking: 0.01em;
  --ground: radial-gradient(120% 90% at 50% -10%, #16171a 0%, var(--bg) 60%), var(--bg);
  color-scheme: dark;
}

/* INK — electronic ink on warm paper: light, high-contrast, quiet indigo accent. */
:root[data-skin="ink"] {
  --bg: #efece3;
  --surface: #f6f3ea;
  --surface-2: #e8e3d6;
  --line: rgba(28, 24, 16, 0.16);
  --ink: #1b1a15;
  --ink-2: #514d43;
  --ink-3: #5f5b4f;
  --accent: #2f3f86;
  --accent-text: #2b3a7d;
  --accent-ink: #ffffff;
  --pos: #1f7a4d;
  --neg: #b23a2e;
  --focus: #2f3f86;
  --ff-hero: var(--ff-serif);
  --hero-weight: 620;
  --hero-tracking: -0.02em;
  --ground: var(--bg);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  min-height: 100%;
  font-family: var(--ff);
  font-size: clamp(1rem, 0.5vw + 0.92rem, 1.125rem);
  line-height: 1.5;
  color: var(--ink);
  background: var(--ground);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

a { color: var(--ink-2); text-underline-offset: 0.2em; }
a:hover { color: var(--ink); }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 30;
  padding: 0.6rem 1rem;
  background: var(--surface-2);
  border-radius: var(--radius-s);
  transition: top var(--dur) var(--ease);
}
.skip:focus-visible { top: 1rem; }

/* ---- the label voice: mono, small, spaced ---- */
.micro {
  font-family: var(--ff-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---- header ---- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  flex-wrap: wrap;
  padding: clamp(0.9rem, 2.5vw, 1.4rem) var(--pad-x);
}

.wordmark {
  font-family: var(--ff-mono);
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.top-controls { display: flex; align-items: center; gap: 0.5rem; }

.skin-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 34px;
  padding: 0.3rem 0.7rem 0.3rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-2);
  font-family: var(--ff-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.skin-btn:hover { color: var(--ink); border-color: rgba(240, 246, 250, 0.25); background: var(--surface); }
.skin-btn:active { transform: scale(0.97); }
.skin-ic { width: 16px; height: 16px; color: var(--accent-text); flex: none; }
.skin-word { color: var(--ink-3); }
.skin-sep { color: var(--ink-3); opacity: 0.5; }
.skin-btn #skin-name { color: var(--ink); }

.lang { display: flex; gap: 2px; border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.lang-btn {
  position: relative;
  font-family: var(--ff-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
/* extend hit areas of visually-small controls to ≥44px without growing them */
.lang-btn::after,
.ghost-s::after,
.seg [role="radio"]::after {
  content: "";
  position: absolute;
  inset: -6px;
}
.ghost-s { position: relative; }
.seg [role="radio"] { position: relative; }
.lang-btn[aria-pressed="true"] { color: var(--ink); background: var(--surface-2); }
.lang-btn:hover { color: var(--ink); }

/* ---- stage ---- */
.stage {
  flex: 1;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: clamp(0.5rem, 3vh, 2.5rem) var(--pad-x) var(--gap);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.noscript {
  padding: 1rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink-2);
}

/* ---- counter ---- */
.counter { text-align: center; }

.place {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 1.1rem;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: clamp(1.05rem, 2.2vw, 1.25rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.place:hover { border-color: rgba(240, 246, 250, 0.25); background: var(--surface); }
.place .chev { width: 12px; height: 8px; color: var(--ink-3); }

.simdate {
  margin-top: clamp(1.1rem, 3vh, 2rem);
  font-family: var(--ff-mono);
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
  min-height: 1.4em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.chip {
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  line-height: 1;
}
.chip-live { color: var(--accent-text); border: 1px solid currentColor; }
.chip-live::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 0.4rem;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite var(--ease);
  vertical-align: 0.05em;
}
.chip-end { color: var(--neg); border: 1px solid currentColor; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.hero {
  margin-top: clamp(0.4rem, 1.5vh, 1rem);
  font-family: var(--ff-hero);
  font-size: clamp(2.6rem, 10.5vw, 7rem);
  font-weight: var(--hero-weight);
  letter-spacing: var(--hero-tracking);
  line-height: 0.95;
  font-variant-numeric: tabular-nums; /* animated counter: width-stable digits */
  font-feature-settings: "tnum";
  color: var(--ink);
}

.attribution { margin-top: 0.9rem; }

/* ---- flow tiles ---- */
.flows {
  margin: clamp(1.6rem, 4vh, 2.6rem) auto 0;
  max-width: 40rem;
}
.flows-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 0.2rem 0.55rem;
}
.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.tile { background: var(--surface); padding: 0.9rem 0.6rem 1rem; }
.tile-label {
  font-size: 0.8rem;
  color: var(--ink-2);
}
.tile-value {
  margin-top: 0.25rem;
  font-size: clamp(1.05rem, 3vw, 1.5rem);
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.tile-value.pos { color: var(--pos); }
.tile-value.neg { color: var(--neg); }
.tile-value.zero { color: var(--ink-2); }

/* ---- transport ---- */
.transport {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(0.8rem, 2.5vw, 1.2rem);
}

/* one compact control row above the timeline: play, speed, refresh, reset */
.console {
  display: flex;
  align-items: center;
  gap: clamp(0.4rem, 1.6vw, 0.7rem);
  flex-wrap: wrap;
  margin-bottom: clamp(0.7rem, 2vw, 1rem);
}

.scrub {
  position: relative;
  padding: 0.7rem 0 0.2rem;
  cursor: pointer;
  border-radius: var(--radius-s);
  touch-action: none; /* the whole gesture belongs to the pointer handlers */
}
.scrub-track {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.scrub-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--p, 0) * 100%);
  border-radius: 999px;
  background: var(--accent);
}
.scrub-thumb {
  position: absolute;
  top: 50%;
  left: calc(var(--p, 0) * 100%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--bg);
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
  transition: transform var(--dur) var(--ease);
}
.scrub:hover .scrub-thumb,
.scrub:focus-visible .scrub-thumb { transform: translate(-50%, -50%) scale(1.18); }
/* generous hit target above the visual track */
.scrub::before { content: ""; position: absolute; inset: -8px 0; }

.scrub-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 0.55rem;
  font-family: var(--ff-mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.play {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 5px 16px rgba(30, 154, 212, 0.3);
  transition: transform var(--dur) var(--ease), background-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.play:hover { transform: scale(1.06); box-shadow: 0 7px 22px rgba(30, 154, 212, 0.42); }
.play:active { transform: scale(0.95); }
.play .ic { width: 22px; height: 22px; fill: currentColor; }
.play .ic-play { margin-left: 2px; } /* optical centering of the triangle */
.play .ic-pause { display: none; }
body.playing .play .ic-play { display: none; }
body.playing .play .ic-pause { display: block; }

/* pill buttons used across the console and the leaderboard: refresh, reset, N, metric */
.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 40px;
  padding: 0.34rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: var(--ff-mono);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease), background-color var(--dur) var(--ease), transform 90ms var(--ease);
}
.chip-btn:hover { color: var(--ink); border-color: rgba(240, 246, 250, 0.25); }
.chip-btn:active { transform: scale(0.96); }
.chip-ic { width: 16px; height: 16px; color: var(--accent-text); flex: none; }
/* refresh + reset sit at the trailing edge of the control row */
.console #refresh-btn { margin-left: auto; }

/* speed stepper: ◀◀ value ▶▶ */
.speed-stepper {
  display: flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  background: var(--surface-2);
}
.step {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--ink-2);
  display: grid;
  place-items: center;
  transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease), transform 90ms var(--ease);
  touch-action: none;
}
.step:hover:not(:disabled) { color: var(--ink); background: rgba(240, 246, 250, 0.06); }
.step:active:not(:disabled) { transform: scale(0.9); color: var(--accent-text); }
.step:disabled { opacity: 0.32; cursor: default; }
.step .ic { width: 20px; height: 20px; }
.speed-value {
  min-width: 4.6rem;
  text-align: center;
  font-family: var(--ff-mono);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

/* ---- change leaderboard ---- */
.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.board-controls { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.seg {
  display: flex;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
  background: var(--surface-2);
}
.seg [role="radio"] {
  font-family: var(--ff-mono);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--ink-2);
  padding: 0.34rem 0.62rem;
  min-height: 32px;
  border-radius: 999px;
  white-space: nowrap;
  transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.seg [role="radio"]:hover { color: var(--ink); }
.seg [role="radio"][aria-checked="true"] {
  color: var(--accent-ink);
  background: var(--accent);
  font-weight: 700;
}

.board-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(0.8rem, 2.5vw, 1.4rem);
  margin-top: 1rem;
  align-items: start;
}
.board-col {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 0.6rem 0.6rem;
}
.board-col-title {
  font-family: var(--ff-mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
  padding: 0 0.5rem 0.6rem;
}
.dir.up { color: var(--pos); }
.dir.down { color: var(--neg); }

.board-list { list-style: none; }
.board-list li { position: relative; }
.board-row {
  position: relative;
  display: grid;
  grid-template-columns: 1.8em 1.4em minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  min-height: 44px;
  padding: 0.34rem 0.55rem;
  border-radius: var(--radius-s);
  text-align: left;
  overflow: hidden;
  transition: background-color var(--dur) var(--ease);
}
.b-id { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.b-sub {
  font-family: var(--ff-mono);
  font-size: 0.62rem;
  letter-spacing: 0.03em;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.board-row::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--w, 0) * 100%);
  background: var(--bar, rgba(101, 214, 189, 0.1));
  transition: width 240ms var(--ease);
  pointer-events: none;
}
.board-row:hover { background: var(--surface-2); }
.board-row[aria-current="true"] { outline: 1px solid var(--line); background: var(--surface-2); }
.board-row > * { position: relative; }
.b-rank {
  font-family: var(--ff-mono);
  font-size: 0.66rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.b-flag { font-size: 1rem; line-height: 1; }
.b-name {
  font-size: 0.86rem;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.board-row:hover .b-name { color: var(--ink); }
.b-val {
  font-family: var(--ff-mono);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.b-val.pos { color: var(--pos); }
.b-val.neg { color: var(--neg); }
.board-empty { padding: 0.6rem; color: var(--ink-3); font-size: 0.82rem; }

/* FLIP reorder animation: JS sets --dy then removes .flip on next frame */
.board-row.flip { transition: none; transform: translateY(var(--dy, 0px)); }
.board-row.unflip { transition: transform 340ms var(--ease); transform: translateY(0); }

@media (max-width: 620px) {
  .board-cols { grid-template-columns: 1fr; }
}

/* ---- footer ---- */
.foot {
  max-width: var(--max);
  width: 100%;
  margin: 0 auto;
  padding: var(--gap) var(--pad-x) clamp(1.4rem, 4vw, 2.2rem);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  text-align: center;
}
.foot .micro { letter-spacing: 0.08em; text-transform: none; }
.foot-meta { overflow-wrap: anywhere; }

/* ---- place picker ---- */
.picker { position: fixed; inset: 0; z-index: 20; }
.picker[hidden] { display: none; }
.picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 8, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.picker-panel {
  position: absolute;
  left: 50%;
  top: clamp(3rem, 12vh, 8rem);
  transform: translateX(-50%);
  width: min(92vw, 26rem);
  max-height: min(70vh, 30rem);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
#picker-search {
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 0.95rem 1.1rem;
}
#picker-search:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
  border-radius: 0;
}
#picker-search::placeholder { color: var(--ink-3); }
#picker-list {
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.4rem;
}
#picker-list [role="option"] {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-s);
  cursor: pointer;
  color: var(--ink-2);
}
#picker-list [role="option"] .opt-pop {
  font-family: var(--ff-mono);
  font-size: 0.7rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
#picker-list [role="option"]:hover,
#picker-list [role="option"].active { background: var(--surface-2); color: var(--ink); }
#picker-list [role="option"][aria-selected="true"] { color: var(--accent-text); }
.picker-empty { padding: 0.9rem; color: var(--ink-3); text-align: center; }

/* ---- small screens ---- */
@media (max-width: 620px) {
  .console { gap: 0.45rem; }
  .console #refresh-btn { margin-left: 0; } /* pack controls left when they wrap */
}

/* ---- motion discipline ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

@media print {
  :root {
    --bg: #fff;
    --surface: #fff;
    --surface-2: #fff;
    --line: #ccc;
    --ink: #000;
    --ink-2: #333;
    --ink-3: #555;
  }
  .transport, .picker, .lang, .skip { display: none; }
  body { background: #fff; color: #000; }
}
