/* ---- tokens ------------------------------------------------------------ */
:root {
  --bg: #0d0f12;
  --surface: #15181c;
  --surface-2: #1b1f25;
  --track: #23272d;
  --line: #272c33;
  --line-soft: #1f2429;
  --ink: #e8eaed;
  --muted: #99a1ab;
  --accent: #f0b429;

  /* Chrome stays grey on purpose so the nine source colours carry the meaning. */
  --coal: #9aa1ab;
  --gas: #a78bfa;
  --oil: #fb923c;
  --nuclear: #f87171;
  --hydro: #60a5fa;
  --wind: #34d399;
  --solar: #fbbf24;
  --biofuel: #a3e635;
  --otherRenewables: #2dd4bf;

  --good: #34d399;
  --mid: #fbbf24;
  --bad: #f87171;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ---- a11y primitives --------------------------------------------------- */
.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-link {
  position: absolute; left: 8px; top: -48px; z-index: 20;
  padding: 9px 14px; border-radius: 3px;
  background: var(--accent); color: #14171a; font-weight: 650; text-decoration: none;
}
.skip-link:focus { top: 8px; }

:where(a, button, input, select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ---- chrome ------------------------------------------------------------ */
.topbar { border-bottom: 1px solid var(--line); background: var(--bg); }
.topbar-inner {
  width: 100%; max-width: 940px; margin: 0 auto;
  padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 52px;
  min-width: 0;
}

.wordmark { font-weight: 650; letter-spacing: -.01em; font-size: 1.0625rem; }

.topbar-right { display: flex; align-items: center; gap: 16px; min-width: 0; }
.tagline { color: var(--muted); font-size: .8125rem; text-align: right; }

.topbar-link {
  flex: none;
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 3px;
  color: var(--muted); text-decoration: none;
  font-size: .8125rem; font-weight: 550; white-space: nowrap;
}
.topbar-link:hover { color: var(--ink); background: var(--surface-2); border-color: #343a42; }

.shell {
  width: 100%; max-width: 940px; margin: 0 auto;
  padding: 22px 16px 40px;
  min-width: 0;
}

.lede { margin: 0 0 20px; color: var(--muted); max-width: 62ch; }

/* ---- panels ------------------------------------------------------------ */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 12px;
  min-width: 0;
}

.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.panel-head h2 { margin: 0; }

h2 { margin: 0 0 12px; font-size: .9375rem; font-weight: 650; letter-spacing: -.005em; }
h3 { margin: 0 0 4px; font-size: .8125rem; font-weight: 650; color: var(--muted); }
.panel-subtitle { margin: 4px 0 0; color: var(--muted); font-size: .8125rem; max-width: 68ch; }

.meta { color: var(--muted); font-size: .8125rem; }
.meta b, .meta strong { color: var(--ink); font-weight: 600; }

a { color: var(--ink); text-decoration-color: var(--line); text-underline-offset: 2px; }
a:hover { text-decoration-color: var(--accent); }

/* ---- the stacked fingerprint ------------------------------------------- */
.stack {
  display: flex; width: 100%; height: 44px;
  border: 1px solid var(--line); border-radius: 3px;
  background: var(--track); overflow: hidden;
}
.stack-seg {
  position: relative; min-width: 2px; height: 100%;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
/* Inline label only where the slice is genuinely wide enough to hold it. */
.stack-seg > span {
  font-size: .6875rem; font-weight: 650; color: #0d0f12;
  white-space: nowrap; padding: 0 4px;
}

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .75rem; color: var(--muted);
}
.legend-swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.legend-item b { color: var(--ink); font-family: var(--mono); font-weight: 550; font-variant-numeric: tabular-nums; }

.summary-row {
  display: flex; flex-wrap: wrap; gap: 6px 24px;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line-soft);
  font-size: .8125rem; color: var(--muted);
}
.summary-row b { color: var(--ink); font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 550; }

details.fine-print { margin-top: 12px; }
details.fine-print summary {
  cursor: pointer; font-size: .8125rem; color: var(--muted); width: fit-content;
}
details.fine-print summary:hover { color: var(--ink); }
details.fine-print[open] summary { margin-bottom: 10px; }

.bar-list { display: grid; gap: 5px; }
.bar {
  display: grid; grid-template-columns: 106px 1fr 48px; gap: 10px; align-items: center;
  font-size: .8125rem; color: var(--muted);
}
.bar-track { height: 8px; border-radius: 2px; background: var(--track); overflow: hidden; }
.bar-fill { display: block; height: 100%; }
.bar b {
  text-align: right; color: var(--ink);
  font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 550;
}

/* ---- play -------------------------------------------------------------- */
.guess-row { display: flex; gap: 8px; }

input, button, select {
  font: inherit; border-radius: 3px; border: 1px solid var(--line); padding: 10px 12px;
}
input, select { background: var(--surface-2); color: var(--ink); }
input { flex: 1; min-width: 0; }
input::placeholder { color: #6b737d; }
input:hover:not(:disabled), select:hover { border-color: #343a42; }
input:disabled { opacity: .5; }

button {
  cursor: pointer; font-weight: 600;
  background: var(--ink); color: #14171a; border-color: var(--ink);
}
button:hover:not(:disabled) { background: #fff; border-color: #fff; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
button.secondary:hover:not(:disabled) { background: var(--surface-2); border-color: #343a42; }

select { padding-right: 8px; }

.message { margin: 10px 0 0; min-height: 1.5em; color: var(--muted); font-size: .875rem; }
.message b { color: var(--ink); }
.message.win b { color: var(--good); }
.message.lose b { color: var(--bad); }

.play-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line-soft);
}
.play-actions { display: flex; gap: 8px; }
#tier-note { margin: 8px 0 0; }

/* ---- board ------------------------------------------------------------- */
.table-scroll { overflow-x: auto; max-width: 100%; }

.board { width: 100%; border-collapse: collapse; font-size: .875rem; }
.board th {
  text-align: left; font-weight: 600; font-size: .75rem; color: var(--muted);
  padding: 0 10px 8px 0; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.board th.num, .board td.num { text-align: right; }
.board th:last-child, .board td:last-child { padding-right: 0; }
.board td { padding: 9px 10px 9px 0; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.board tr:last-child td { border-bottom: 0; }
.board .col-n { width: 1%; color: var(--muted); font-family: var(--mono); }
.board .country { font-weight: 600; }
.board .region { color: var(--muted); font-weight: 400; }
.board td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.board-empty td { color: var(--muted); border-bottom: 0; padding-top: 12px; }

.bearing { white-space: nowrap; color: var(--muted); }
.bearing .arrow { color: var(--ink); font-size: 1rem; margin-right: 3px; }

/* Mix distance reads as a value plus a bar, so "34.2" has a visual anchor. */
.sim { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.sim-meter { width: 54px; height: 5px; border-radius: 2px; background: var(--track); overflow: hidden; flex: none; }
.sim-fill { display: block; height: 100%; }
.sim-val { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sim.good .sim-fill { background: var(--good); }
.sim.mid  .sim-fill { background: var(--mid); }
.sim.bad  .sim-fill { background: var(--bad); }
.sim.good .sim-val { color: var(--good); }
.sim.mid  .sim-val { color: var(--mid); }
.sim.bad  .sim-val { color: var(--bad); }

abbr[title] {
  cursor: help; text-decoration: none; border: 1px solid var(--line);
  border-radius: 50%; display: inline-flex; width: 14px; height: 14px;
  align-items: center; justify-content: center; font-size: .625rem; vertical-align: middle;
}

/* ---- answer ------------------------------------------------------------ */
.answer { border-color: #2f4a3c; background: #141a17; }
.answer h2 { font-size: 1.0625rem; }
.answer p { margin: 0 0 14px; color: var(--muted); max-width: 68ch; }
.trivia {
  margin: 0 0 14px; padding: 12px 14px;
  border-left: 2px solid var(--wind); border-radius: 0 3px 3px 0;
  background: rgba(255, 255, 255, .03);
}
.trivia h3 { margin: 0 0 5px; color: var(--muted); }
.trivia p { margin: 0; color: var(--ink); font-size: .875rem; max-width: 62ch; }

.answer-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.share-targets {
  display: flex; align-items: center; gap: 4px 12px; flex-wrap: wrap;
  margin: 12px 0 0; color: var(--muted); font-size: .8125rem;
}
.share-targets a, .linklike {
  color: var(--ink); text-decoration: underline;
  text-decoration-color: var(--line); text-underline-offset: 3px;
}
.share-targets a:hover, .linklike:hover { text-decoration-color: var(--accent); }
/* A button that reads as a link: same weight and colour, no chrome. */
.linklike {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-size: .8125rem;
}
.linklike:disabled { opacity: .5; cursor: default; }

/* ---- browse spoiler ---------------------------------------------------- */
.spoiler-tag {
  display: inline-flex; margin-left: 6px; padding: 2px 6px;
  border: 1px solid #4b3420; border-radius: 999px;
  color: #fbbf24; background: rgba(251, 191, 36, .08);
  font-size: .625rem; text-transform: uppercase; letter-spacing: .06em;
}

.browse .panel-head { align-items: center; }
.browse-body { border-top: 1px solid var(--line-soft); padding-top: 14px; }
.browse-controls {
  display: grid; grid-template-columns: minmax(220px, 1fr) minmax(180px, auto) auto;
  gap: 8px; align-items: center;
}
.browse-controls input[type="search"] { width: 100%; }
.checkline {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: .8125rem; white-space: nowrap;
}
.checkline input { flex: none; accent-color: var(--accent); }
#browse-count { margin: 10px 0; }
.browse-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.browse-card {
  padding: 12px; border: 1px solid var(--line-soft); border-radius: 4px;
  background: rgba(255, 255, 255, .025);
}
.browse-card.curated { border-color: #3e4f38; background: linear-gradient(180deg, rgba(52, 211, 153, .055), rgba(255,255,255,.02)); }
.browse-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.browse-card h3 { margin: 0; color: var(--ink); font-size: .9375rem; }
.browse-badges { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  display: inline-flex; padding: 2px 6px; border-radius: 999px;
  background: rgba(52, 211, 153, .12); color: var(--good);
  font-size: .6875rem; font-weight: 650; white-space: nowrap;
}
.badge.muted { color: var(--muted); background: var(--surface-2); }
.browse-chips { display: flex; flex-wrap: wrap; gap: 5px 8px; margin-top: 10px; }
.source-chip {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--muted); font-size: .75rem;
}
.source-chip b { color: var(--ink); font-family: var(--mono); font-weight: 550; }
.browse-stats, .browse-reason, .empty-note { margin: 9px 0 0; color: var(--muted); font-size: .8125rem; }
.browse-stats b { color: var(--ink); font-family: var(--mono); font-weight: 550; }
.browse-reason { color: #c6cbd2; }

/* ---- hints ------------------------------------------------------------- */
.hint-block { padding-top: 12px; margin-top: 12px; border-top: 1px solid var(--line-soft); }
.hint-block:first-of-type { padding-top: 0; margin-top: 0; border-top: 0; }
.hint-block p { margin: 0; color: var(--muted); font-size: .875rem; }
.hint-block p b { color: var(--ink); }

.delta-list { display: grid; gap: 3px; margin-top: 8px; }
.delta {
  display: flex; justify-content: space-between; gap: 16px; max-width: 320px;
  font-size: .8125rem; padding: 2px 0;
}
.delta-val { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.delta-val.up { color: var(--good); }
.delta-val.down { color: var(--bad); }

/* ---- about dialog ------------------------------------------------------ */
.modal {
  width: min(560px, calc(100% - 32px));
  padding: 0; border: 1px solid var(--line); border-radius: 4px;
  background: var(--surface); color: var(--ink);
}
.modal::backdrop { background: rgba(6, 8, 10, .72); }
.modal-body { padding: 20px; }
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  margin-bottom: 4px;
}
.modal-head h2 { margin: 0; font-size: 1.125rem; }
.modal-x {
  flex: none; background: none; border: 0; padding: 0 4px; cursor: pointer;
  color: var(--muted); font-size: 1.4rem; line-height: 1;
}
.modal-x:hover { color: var(--ink); }

.about-section { margin-top: 16px; }
.about-section:empty { display: none; }
.about-section h3 { margin-bottom: 5px; }
.about-section p { margin: 0; color: var(--muted); font-size: .875rem; line-height: 1.55; }
.about-section p b { color: var(--ink); }
.about-foot { margin: 20px 0 0; padding-top: 14px; border-top: 1px solid var(--line-soft); font-size: .875rem; }

/* ---- foot -------------------------------------------------------------- */
.site-foot {
  display: flex; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap;
  align-items: flex-end;
  margin-top: 20px; color: var(--muted); font-size: .8125rem;
}
.site-foot-note { max-width: 64ch; line-height: 1.5; }
/* The strikethrough is the joke — dim it so it reads as deliberate, not as a
   rendering accident. */
.site-foot-note s { color: #6b737d; text-decoration-thickness: 1px; }

/* ---- responsive -------------------------------------------------------- */
@media (max-width: 640px) {
  .topbar-inner { padding-left: 12px; padding-right: 12px; }
  .shell { padding: 16px 12px 40px; }
  .tagline { display: none; }
  .lede { margin-bottom: 16px; font-size: .875rem; }
  .stack { height: 38px; }
  .board { font-size: .8125rem; }
  .board th, .board td { padding-right: 8px; }
  /* The arrow alone carries the bearing; the word would force a sideways scroll. */
  .board th { white-space: normal; }
  .bearing-label { display: none; }
  .sim-meter { width: 34px; }
  .sim { gap: 6px; }
  .play-foot { align-items: stretch; flex-direction: column; }
  .play-actions { width: 100%; }
  .play-actions select { flex: 1; min-width: 0; }
  .browse-controls { grid-template-columns: 1fr; }
  .browse-results { grid-template-columns: 1fr; }
  .browse-card-head { flex-direction: column; }
  .browse-badges { justify-content: flex-start; }
  .bar { grid-template-columns: 88px 1fr 44px; }
}

/* ---- motion ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
