/* Flags render from one small font on every device, so Windows (which has no
   flag emoji) looks the same as phones. Graphics: Twemoji, CC BY 4.0. */
@font-face {
  font-family: "Twemoji Country Flags";
  src: url("/fonts/TwemojiCountryFlags.woff2?v=e1e22e0882") format("woff2");
  font-display: swap;
  unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0062-E0063, U+E0065, U+E0067, U+E006C, U+E006E, U+E0073-E0074, U+E0077, U+E007F;
}

:root {
  --bg: #090d1a;
  --bg-2: #0f1630;
  --card: #131b36;
  --card-hi: #1a2445;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f2f5ff;
  --muted: #9ca7cf;
  --dim: #6d789f;
  --gold: #ffc83d;
  --gold-deep: #f59f0a;
  --cyan: #4cc9f0;
  --good: #5fdc94;
  --bad: #ff6b6b;
  --silver: #cfd8ee;
  --bronze: #e6a06a;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tabs-h: 62px;
  --font: "Twemoji Country Flags", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60% 42% at 50% 0%, rgba(76, 201, 240, 0.16), transparent 70%),
    radial-gradient(50% 36% at 50% 46%, rgba(255, 200, 61, 0.07), transparent 70%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 55%);
}
h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.flag { font-family: "Twemoji Country Flags", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; font-style: normal; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ------------------------------------------------------------- top bar */
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; padding-bottom: calc(var(--tabs-h) + var(--safe-b)); }
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 6px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 30px; height: 30px; flex: none; }
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 42px; height: 42px; display: grid; place-items: center; flex: none;
  border: 1px solid var(--line); border-radius: 50%; background: rgba(255, 255, 255, 0.04);
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.icon-btn:disabled { opacity: 0.35; }
.icon-btn svg, .chip svg, .tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
#btn-sound .spk { fill: currentColor; stroke: none; }
#btn-sound .mute { display: none; }
#btn-sound[aria-pressed="false"] .wave { display: none; }
#btn-sound[aria-pressed="false"] .mute { display: inline; }
#btn-sound[aria-pressed="false"] { color: var(--dim); }

/* ---------------------------------------------------------------- play */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.play { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly; gap: 10px; padding: 4px 16px 14px; text-align: center; }
.country-pick { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 9px; max-width: min(88vw, 360px);
  padding: 8px 12px 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06);
  font-weight: 700; font-size: 17px;
}
.chip:hover { background: rgba(255, 255, 255, 0.11); }
.chip .flag { font-size: 22px; line-height: 1; }
.chip #chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip svg { width: 18px; height: 18px; color: var(--muted); flex: none; }

.stage { position: relative; display: grid; place-items: center; width: 100%; padding: 8px 0; }
.tap {
  --size: min(62vw, 36vh, 280px);
  position: relative;
  width: var(--size); height: var(--size);
  border: 0; border-radius: 50%; padding: 0;
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.16), transparent 42%),
    radial-gradient(circle at 50% 55%, #26315f, #141c3c 72%);
  box-shadow:
    0 0 0 5px rgba(9, 13, 26, 0.9),
    0 0 0 8px var(--gold),
    0 0 0 9px rgba(0, 0, 0, 0.35),
    0 22px 60px rgba(0, 0, 0, 0.6),
    0 0 70px rgba(255, 200, 61, 0.16),
    inset 0 -14px 30px rgba(0, 0, 0, 0.5),
    inset 0 10px 22px rgba(255, 255, 255, 0.07);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform 0.07s ease-out, filter 0.2s;
  will-change: transform;
}
.tap:disabled { filter: saturate(0.35) brightness(0.75); }
.tap.down { transform: scale(0.955); }
.tap-flag { font-size: calc(var(--size) * 0.46); line-height: 1; pointer-events: none; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45)); }
.fx { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.plus {
  position: absolute; left: 0; top: 0; margin: -14px 0 0 -14px;
  font-weight: 800; font-size: 22px; color: var(--gold);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  opacity: 0; will-change: transform, opacity;
}
.ring {
  position: absolute; left: 50%; top: 50%; width: var(--size, 240px); height: var(--size, 240px);
  margin: calc(var(--size, 240px) / -2) 0 0 calc(var(--size, 240px) / -2);
  border-radius: 50%; border: 2px solid var(--gold); opacity: 0; will-change: transform, opacity;
}

.meter { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.meter-bar { width: 132px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.meter-bar i { display: block; height: 100%; width: 100%; transform-origin: left; transform: scaleX(var(--p, 0)); background: linear-gradient(90deg, var(--cyan), var(--gold) 70%, var(--bad)); transition: transform 0.12s linear; }
.meter-num { min-width: 64px; text-align: left; font-variant-numeric: tabular-nums; }
.meter-num b { color: var(--text); font-size: 15px; }
.meter.max .meter-num b { color: var(--gold); }

.mine { display: flex; flex-direction: column; align-items: center; }
.big-num { font-size: clamp(40px, 12vw, 60px); line-height: 1.05; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.card { width: 100%; max-width: 420px; background: linear-gradient(180deg, var(--card-hi), var(--card)); border: 1px solid var(--line); border-radius: var(--radius); }
.nation { padding: 12px 14px; text-align: left; }
.nation-main { display: flex; align-items: center; gap: 12px; }
.nation-flag { font-size: 34px; line-height: 1; flex: none; }
.nation-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.nation-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nation-rank { font-size: 13px; color: var(--gold); font-weight: 700; }
.nation-total { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.chase { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); min-height: 1.45em; }
.chase b { color: var(--text); }
.hint { font-size: 13px; color: var(--dim); }

/* ---------------------------------------------------------------- tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding-bottom: var(--safe-b);
  background: rgba(9, 13, 26, 0.9);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  height: var(--tabs-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 700;
}
.tab .fill { fill: currentColor; stroke: none; }
.tab[aria-current="page"] { color: var(--gold); }

/* -------------------------------------------------------------- panels */
.panel { padding: 6px 14px 20px; width: 100%; max-width: 640px; margin: 0 auto; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 4px 2px 10px; }
.panel-head h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.refresh { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); }
.seg button { border: 0; background: none; border-radius: 10px; padding: 9px 4px; font-weight: 700; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg button:hover { color: var(--text); }
.seg button[aria-selected="true"] { background: var(--text); color: #0b1022; }
.period-info { display: flex; justify-content: space-between; gap: 12px; padding: 10px 4px 2px; font-size: 13px; color: var(--muted); }
.period-info #lb-label { font-weight: 700; color: var(--text); }
.period-info #lb-reset { text-align: right; font-variant-numeric: tabular-nums; }
.summary { padding: 2px 4px 10px; font-size: 13px; color: var(--muted); min-height: 1.45em; }

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  position: relative; display: grid; grid-template-columns: 2.1em 1.7em minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 10px 12px 10px 6px; border-radius: 12px; overflow: hidden;
}
.row + .row { margin-top: 2px; }
.row .bar { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; transform-origin: left; transform: scaleX(var(--w, 0)); background: linear-gradient(90deg, rgba(76, 201, 240, 0.2), rgba(76, 201, 240, 0.05)); pointer-events: none; transition: transform 0.5s ease; }
.row > :not(.bar) { position: relative; }
.row .rk { text-align: right; font-weight: 800; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .fl { font-size: 24px; line-height: 1; }
.row .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .ct { font-weight: 800; font-variant-numeric: tabular-nums; }
.row[data-rank="1"] .rk { color: var(--gold); }
.row[data-rank="2"] .rk { color: var(--silver); }
.row[data-rank="3"] .rk { color: var(--bronze); }
.row.me { background: rgba(255, 200, 61, 0.1); box-shadow: inset 0 0 0 1.5px rgba(255, 200, 61, 0.6); }
.row.me .bar { background: linear-gradient(90deg, rgba(255, 200, 61, 0.26), rgba(255, 200, 61, 0.05)); }
.row .mv { font-size: 11px; font-weight: 800; margin-left: 6px; }
.row .mv.up { color: var(--good); }
.row .mv.down { color: var(--bad); }
.empty { padding: 34px 12px; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------- archive */
.arch-nav { display: flex; align-items: center; gap: 8px; padding: 12px 0 4px; }
.arch-nav select {
  flex: 1; min-width: 0; height: 42px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 700;
}
.podium { display: grid; grid-template-columns: repeat(3, 1fr); align-items: end; gap: 8px; padding: 6px 0 14px; }
.podium:empty { display: none; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; padding: 10px 6px; border-radius: 14px; border: 1px solid var(--line); background: linear-gradient(180deg, var(--card-hi), var(--card)); }
.pod .flag { font-size: 34px; line-height: 1.1; }
.pod .pod-rank { font-size: 12px; font-weight: 800; letter-spacing: 0.08em; }
.pod .pod-name { max-width: 100%; font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod .pod-num { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pod.p1 { order: 2; padding-top: 22px; padding-bottom: 16px; border-color: rgba(255, 200, 61, 0.55); }
.pod.p1 .flag { font-size: 46px; }
.pod.p1 .pod-rank { color: var(--gold); }
.pod.p2 { order: 1; }
.pod.p2 .pod-rank { color: var(--silver); }
.pod.p3 { order: 3; }
.pod.p3 .pod-rank { color: var(--bronze); }

/* ------------------------------------------------------------- dialogs */
.dlg {
  width: min(430px, calc(100vw - 28px)); max-height: min(88vh, 720px); max-height: min(88dvh, 720px);
  padding: 0; border: 1px solid var(--line); border-radius: 22px;
  background: var(--card); color: var(--text);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}
.dlg::backdrop { background: rgba(4, 6, 14, 0.74); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.dlg[open] { display: flex; flex-direction: column; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 14px 10px 20px; }
.dlg-head h2 { font-size: 20px; font-weight: 800; }
.dlg-body { padding: 4px 22px 22px; overflow-y: auto; min-height: 0; }
.dlg-body.center { padding-top: 26px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.dlg-body.center h2 { font-size: 22px; font-weight: 800; }
.dlg-flag { font-size: 84px; line-height: 1; }
.dlg-country { font-size: 20px; font-weight: 800; color: var(--gold); }
.dlg-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; margin-top: 14px; }
.btn { min-height: 48px; padding: 10px 18px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); font-weight: 700; }
.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn.primary { border: 0; background: linear-gradient(180deg, var(--gold), var(--gold-deep)); color: #201400; }
.btn.primary:hover { filter: brightness(1.07); }
.prose p { margin-bottom: 12px; color: #d6dcf3; }
.prose h3 { margin: 16px 0 6px; font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); }
.credits { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.credits a, .prose a { color: var(--cyan); }

.picker { height: min(88vh, 720px); height: min(88dvh, 720px); }
.search {
  margin: 0 16px 8px; height: 46px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); color: var(--text); font: inherit;
}
.search::placeholder { color: var(--dim); }
.picker-list { list-style: none; margin: 0; padding: 0 8px 10px; overflow-x: hidden; overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }
.pick {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 0; border-radius: 12px; background: none; text-align: left; font-weight: 600;
}
.pick:hover, .pick:focus-visible { background: rgba(255, 255, 255, 0.08); }
.pick .flag { font-size: 26px; line-height: 1; flex: none; }
.pick .pick-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick .tag { font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); }
.pick.current { background: rgba(255, 200, 61, 0.12); }

.ban-mark { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 107, 107, 0.14); color: var(--bad); }
.ban-mark svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.ban-wait { font-weight: 800; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------- human check */
.check {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 14px;
  background: rgba(4, 6, 14, 0.86); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.check-box { width: min(440px, 100%); display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.check-box h2 { font-size: 22px; font-weight: 800; }
.check-area {
  position: relative; width: 100%; height: min(52vh, 400px); margin-top: 6px; border-radius: 22px;
  border: 1px dashed rgba(255, 255, 255, 0.22); background: rgba(255, 255, 255, 0.04); overflow: hidden;
}
.check-area.wrong { animation: shake 0.3s; border-color: var(--bad); }
.check-target {
  position: absolute; left: calc(var(--x, 0.5) * 100%); top: calc(var(--y, 0.5) * 100%);
  width: 68px; height: 68px; margin: -34px 0 0 -34px; padding: 0; border-radius: 50%;
  border: 3px solid #fff; background: radial-gradient(circle at 35% 30%, #ffe9a8, var(--gold) 55%, var(--gold-deep));
  box-shadow: 0 0 0 0 rgba(255, 200, 61, 0.6); animation: beacon 1.1s infinite;
  touch-action: none;
}
.check-steps { display: flex; gap: 8px; padding: 6px 0 2px; }
.check-steps i { width: 26px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.16); }
.check-steps i.done { background: var(--good); }
@keyframes beacon { 0% { box-shadow: 0 0 0 0 rgba(255, 200, 61, 0.6); } 100% { box-shadow: 0 0 0 26px rgba(255, 200, 61, 0); } }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* --------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 14px); transform: translateX(-50%); z-index: 70;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 999px;
  background: #fff; color: #0b1022; font-weight: 700; font-size: 14px; text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.toast.bad { background: var(--bad); color: #2a0606; }
.noscript { padding: 40px; text-align: center; }

/* ------------------------------------------- phones: one view at a time */
@media (max-width: 959.98px) {
  body[data-view="play"] .panel { display: none; }
  body:not([data-view="play"]) .play { display: none; }
  body[data-view="live"] #view-archive { display: none; }
  body[data-view="archive"] #view-live { display: none; }
}
@media (max-width: 959.98px) and (max-height: 640px) {
  .hint { display: none; }
  .play { gap: 6px; }
  .tap { --size: min(56vw, 32vh, 240px); }
}

/* --------------------------------------- wide screens: play + board */
@media (min-width: 960px) {
  .app { padding-bottom: 0; }
  .top { max-width: 1120px; width: 100%; margin: 0 auto; padding: 18px 28px 8px; }
  .brand-name { font-size: 22px; }
  .main { flex-direction: row; justify-content: center; align-items: flex-start; gap: 36px; max-width: 1120px; width: 100%; margin: 0 auto; padding: 8px 28px 48px; }
  .play { flex: 0 0 420px; position: sticky; top: 16px; justify-content: flex-start; gap: 16px; padding: 12px 0; }
  .tap { --size: min(280px, 34vh); }
  .side { flex: 1 1 0; min-width: 0; max-width: 600px; background: rgba(19, 27, 54, 0.72); border: 1px solid var(--line); border-radius: 24px; padding: 10px; }
  .tabs { position: static; grid-template-columns: repeat(2, 1fr); gap: 4px; padding: 4px; margin-bottom: 4px; border: 0; border-radius: 16px; background: rgba(255, 255, 255, 0.05); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .tab { flex-direction: row; gap: 8px; height: 44px; border-radius: 12px; font-size: 14px; }
  .tab[data-view="play"] { display: none; }
  .tab[aria-current="page"] { background: rgba(255, 200, 61, 0.14); }
  .panel { padding: 10px 10px 14px; max-width: none; }
  body[data-side="live"] #view-archive { display: none; }
  body[data-side="archive"] #view-live { display: none; }
  .toast { bottom: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .tap, .row .bar, .meter-bar i { transition: none; }
  .check-target, .check-area.wrong { animation: none; }
}
