:root {
  color-scheme: dark;
  --bg: #11151c;
  --panel: #1a2029;
  --panel-2: #222b37;
  --line: #2c3645;
  --text: #e6e9ee;
  --muted: #8a93a0;
  --good: #6fcf8e;
  --bad: #e07a7a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-x: contain; /* curb horizontal overscroll → back/forward nav */
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .75rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 1.15rem; margin: 0; white-space: nowrap; }
.tabs { display: flex; gap: .25rem; }
.tab {
  background: none; border: 1px solid transparent; color: var(--muted);
  padding: .4rem .9rem; border-radius: .5rem; cursor: pointer; font-size: .95rem;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--panel-2); border-color: var(--line); }
.tab-help {
  margin-left: .15rem; width: 1.9rem; height: 1.9rem; padding: 0;
  border-radius: 50%; font-weight: 700; line-height: 1; display: grid; place-items: center;
}
.stats { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.stats #vote-count { color: var(--text); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }
.hint { color: var(--muted); text-align: center; margin: .25rem 0 1rem; }
.hint-touch { display: none; }   /* shown only on touch/mobile widths */
.skip-btn {
  display: none; margin: .9rem auto 0; padding: .55rem 1.2rem;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  border-radius: .5rem; cursor: pointer; font-size: .95rem;
}
.skip-btn:active { color: var(--text); border-color: var(--muted); }
kbd {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: .3rem; padding: 0 .35rem; font-size: .85em;
}

/* ---- matchup ---- */
.matchup {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; align-items: start;
}
.vs { align-self: center; color: var(--muted); font-weight: 700; letter-spacing: .1em; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent, #5a6b86);
  border-radius: .6rem;
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: transform .08s, box-shadow .12s, border-color .12s;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 0 1px var(--accent), 0 8px 24px rgba(0,0,0,.35);
}
.card.picked { transform: scale(.99); box-shadow: 0 0 0 2px var(--good); }

.card-head { display: flex; align-items: baseline; gap: .5rem; margin-bottom: .75rem; }
.card-head h2 { font-size: 1.15rem; margin: 0; }
.country { color: var(--muted); font-size: .85rem; }

.block h3, .ideas { margin: .6rem 0 .3rem; }
.block h3 {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: .2rem;
}
.ambition h3 { color: var(--accent); }

ul.mods { list-style: none; margin: .2rem 0; padding: 0; }
ul.mods li { display: flex; gap: .4rem; align-items: center; }
.mval { color: var(--good); font-variant-numeric: tabular-nums; font-weight: 600; flex: none; }
.mlabel { color: var(--text); }

ol.ideas { list-style: none; margin: 0; padding: 0; counter-reset: idea; }
.idea { padding: .45rem 0; border-bottom: 1px dashed var(--line); }
.idea:last-child { border-bottom: none; }
.idea-name { font-weight: 600; display: block; margin-bottom: .15rem; }
.idea-name::before {
  counter-increment: idea; content: counter(idea) ". ";
  color: var(--muted); font-weight: 400;
}

/* ---- component matchup ---- */
.slot-header { text-align: center; margin-bottom: 1rem; }
.slot-header h2 { font-size: 1.7rem; margin: 0 0 .25rem; }
.slot-header .hint { margin: 0; }

.card.comp { padding: 0; overflow: hidden; }
.card-country {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem 1rem; line-height: 1.2;
}
.flag {
  width: 2.4rem; height: 2.4rem; object-fit: contain; flex: none;
  border-radius: .2rem; box-shadow: 0 0 0 1px rgba(0, 0, 0, .3);
}
.cc-name { font-size: 1.25rem; font-weight: 700; }
.comp-body { padding: 1rem 1.1rem; min-height: 5rem; }
.comp-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .4rem; min-height: 2.6rem; }
.big-icon { width: 2.6rem; height: 2.6rem; object-fit: contain; flex: none; }
.comp-name { font-weight: 700; font-size: 1.05rem; }
.flavor {
  font-size: .8rem; color: var(--muted); font-style: italic;
  margin: .1rem 0 .6rem; display: -webkit-box;
  -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.comp-body ul.mods li { font-size: 1.02rem; padding: .1rem 0; }

.board-pick { color: var(--muted); font-size: .95rem; }
.board-pick select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: .5rem;
  padding: .35rem .6rem; font-size: .95rem; margin-left: .4rem;
}

.controls { text-align: center; margin-top: 1.25rem; }
.ghost {
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  padding: .5rem 1rem; border-radius: .5rem; cursor: pointer;
}
.ghost:hover { color: var(--text); border-color: var(--muted); }
.ghost.danger:hover { color: var(--bad); border-color: var(--bad); }

/* ---- tier list ---- */
.board-head { display: flex; align-items: center; gap: 1rem; }
.board-head .hint { text-align: left; margin: 0; flex: 1; }
.tiers { margin-top: 1rem; display: flex; flex-direction: column; gap: .4rem; }
.tier { display: flex; gap: .6rem; align-items: stretch; }
.tier-label {
  flex: none; width: 2.5rem; display: grid; place-items: center;
  font-weight: 800; font-size: 1.2rem; border-radius: .4rem; color: #11151c;
}
.tier-s .tier-label { background: #ff7f7f; }
.tier-a .tier-label { background: #ffbf7f; }
.tier-b .tier-label { background: #ffdf7f; }
.tier-c .tier-label { background: #ffff7f; }
.tier-d .tier-label { background: #bfff7f; }
.tier-f .tier-label { background: #7fffff; }
.tier-row {
  flex: 1; display: flex; flex-wrap: wrap; gap: .35rem;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: .4rem; padding: .4rem; min-height: 2.5rem;
}
.chip {
  display: inline-flex; align-items: center;
  border-left: 4px solid var(--accent); background: var(--panel-2);
  padding: .2rem .5rem; border-radius: .3rem; font-size: .85rem; cursor: default;
}
/* Individual board: a deduped bonus, click to see its country roster. */
.chip-bonus {
  border-left-color: var(--good); cursor: pointer; gap: .35rem;
}
.chip-bonus:hover { background: var(--line); }
.chip-ic {
  width: 1.05rem; height: 1.05rem; object-fit: contain; flex: none;
  border-radius: .12rem;
}
.empty { color: var(--muted); text-align: center; padding: 2rem; }

/* ---- about / how it works ---- */
.about { max-width: 680px; margin: 0 auto; }
.about h2 { font-size: 1.6rem; margin: .25rem 0 1rem; }
.about h3 {
  font-size: 1.05rem; margin: 1.6rem 0 .5rem; color: var(--text);
  border-bottom: 1px solid var(--line); padding-bottom: .3rem;
}
.about p { margin: .5rem 0; color: var(--text); }
.about ul { margin: .5rem 0; padding-left: 1.2rem; }
.about li { margin: .35rem 0; }
.about strong { color: #fff; }
.about em { color: var(--muted); font-style: italic; }

.loading { text-align: center; color: var(--muted); padding: 3rem; }

/* ---- tier-list hover popup ---- */
.set-popup {
  position: absolute; z-index: 50; width: 330px; max-height: calc(100vh - 16px); overflow-y: auto;
  pointer-events: none; /* purely visual: never steal hover from the chip (avoids open/close flicker) */
  background: var(--panel); border: 1px solid var(--line);
  border-radius: .5rem; box-shadow: 0 12px 32px rgba(0,0,0,.5);
  font-size: .82rem;
}
.pop-country {
  display: flex; align-items: center; gap: .5rem;
  font-weight: 700; font-size: 1rem; padding: .45rem .7rem;
  position: sticky; top: 0; z-index: 1;
}
.pop-flag {
  width: 1.6rem; height: 1.6rem; object-fit: contain; flex: none;
  border-radius: .15rem; box-shadow: 0 0 0 1px rgba(0,0,0,.35);
}
.pop-cname { flex: 1; }
.pop-rank {
  font-size: .75rem; font-weight: 600; opacity: .85;
  font-variant-numeric: tabular-nums; padding: .15rem .55rem .35rem;
  display: inline-block; color: var(--muted);
}
.pop-body { padding: .25rem .7rem .6rem; }
.pgrp { padding: .35rem 0; border-bottom: 1px dashed var(--line); }
.pgrp:last-child { border-bottom: none; }
.pgrp-h {
  display: flex; justify-content: space-between; align-items: baseline; gap: .5rem;
  font-size: .68rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-bottom: .15rem;
}
.pgrp-h > span:first-child { font-weight: 700; color: var(--text); }
.pgrp-rank { flex: none; font-variant-numeric: tabular-nums; text-transform: none; letter-spacing: 0; }
.pgrp-unrated { opacity: .5; font-style: italic; }
.pl { display: flex; gap: .4rem; align-items: baseline; }
.pl .mval { font-size: .82rem; }

/* ---- bonus roster modal (Individual board) ---- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.55); align-items: center; justify-content: center;
  padding: 1rem;
}
/* display only when shown — a bare `display: flex` would override the [hidden]
   attribute and leave the empty backdrop covering (and click-blocking) the page. */
.modal-backdrop:not([hidden]) { display: flex; }
.modal {
  width: 460px; max-width: 100%; max-height: 80vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: .6rem; box-shadow: 0 16px 40px rgba(0,0,0,.55); overflow: hidden;
}
.m-head {
  position: relative; padding: .7rem 2.2rem .6rem .9rem;
  border-bottom: 1px solid var(--line); background: var(--panel-2);
}
.m-title { font-weight: 700; font-size: 1.02rem; color: var(--text); }
.m-sub {
  margin-top: .2rem; font-size: .78rem; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.m-close {
  position: absolute; top: .45rem; right: .55rem;
  background: none; border: none; color: var(--muted);
  font-size: 1.4rem; line-height: 1; cursor: pointer; padding: .1rem .3rem;
}
.m-close:hover { color: var(--text); }
.m-list {
  list-style: none; margin: 0; padding: .4rem; overflow-y: auto;
  display: flex; flex-direction: column; gap: .3rem;
}
.m-row {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
}
.m-c {
  display: inline-flex; align-items: center; gap: .4rem;
  font-weight: 600; padding: .25rem .5rem; border-radius: .3rem;
  flex: 0 1 auto; min-width: 0; max-width: 70%;   /* hug the name, don't spill right */
}
.m-c > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-flag {
  width: 1.3rem; height: 1.3rem; object-fit: contain; flex: none;
  border-radius: .12rem; box-shadow: 0 0 0 1px rgba(0,0,0,.35);
}
.m-where {
  flex: none; font-size: .76rem; color: var(--muted); text-align: right;
  max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- responsive ---- */
@media (max-width: 720px) {
  main { padding: .85rem; }
  .topbar { gap: .5rem .75rem; flex-wrap: wrap; padding: .6rem .85rem; }
  .topbar h1 { font-size: 1rem; }

  .slot-header h2 { font-size: 1.3rem; }
  .hint-key { display: none; }
  .hint-touch { display: inline; }

  /* stacked cards, compacted so both fit a phone without scrolling */
  .matchup { grid-template-columns: 1fr; gap: .55rem; }
  .vs {
    justify-self: stretch; text-align: center; align-self: auto;
    font-size: .78rem; padding: .05rem 0;
  }
  .card.comp { touch-action: pan-y; }   /* we own horizontal swipes; browser keeps vertical scroll */
  .card-country { padding: .45rem .7rem; gap: .45rem; }
  .flag { width: 1.8rem; height: 1.8rem; }
  .cc-name { font-size: 1.05rem; }
  .comp-body { padding: .6rem .8rem; min-height: 0; }
  .comp-head { min-height: 0; gap: .45rem; margin-bottom: .3rem; }
  .big-icon { width: 2rem; height: 2rem; }
  .comp-name { font-size: .95rem; }
  .flavor { -webkit-line-clamp: 2; font-size: .72rem; margin-bottom: .4rem; }
  .comp-body ul.mods li { font-size: .9rem; padding: .05rem 0; }

  .skip-btn { display: block; }
}

/* Stale-version refresh banner. Normal flow at the very top so it pushes content
   down (no fixed/sticky conflict with the topbar). Hidden until markStale(). */
.update-banner {
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: .5rem 1rem;
  background: #2c5d87;
  color: #fff;
  font-weight: 600;
  font-size: .9rem;
  text-align: center;
}
.update-banner:not([hidden]) { display: flex; }
.update-banner button {
  background: #fff;
  color: #14202c;
  border: 0;
  border-radius: 6px;
  padding: .25rem .75rem;
  font-weight: 700;
  cursor: pointer;
}
.update-banner button:hover { background: #e6e9ee; }

/* Post-vote verdict toast: how your pick compared to the crowd's expectation. */
.verdict {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%) translateY(8px);
  z-index: 50;
  flex-direction: column;
  align-items: center;
  gap: .12rem;
  max-width: min(92vw, 30rem);
  padding: .55rem .9rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
/* Gate display behind :not([hidden]) so the hidden attribute still hard-hides. */
.verdict:not([hidden]) { display: flex; }
.verdict.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.v-tag { font-weight: 700; font-size: .95rem; }
.v-agree { color: var(--good); }
.v-upset { color: #e7b54e; }
.v-early { color: var(--muted); }
.v-line { color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.v-up { color: var(--good); }
.v-down { color: var(--bad); }

/* Cards fill the screen on mobile, so a bottom toast overlaps their text —
   anchor it just under the sticky header instead. (Must follow the base rule:
   equal specificity, so later source order wins for the bottom→auto flip.) */
@media (max-width: 720px) {
  .verdict { top: 5.75rem; bottom: auto; width: calc(100vw - 1rem); max-width: none; }
}

/* Deploy stamp on the "?" page — set at build time, hidden when absent (local). */
.deploy-stamp {
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
}
