/* MultiQuest styles */
:root {
  --t-math: #f0a020;
  --t-history: #d64541;
  --t-science: #2bb673;
  --t-portuguese: #2f80ed;
  --t-english: #9b51e0;
  --t-french: #e84393;
  --t-tech: #00a3a3;
  --t-music: #a0632d;
  --good: #1fa463;
  --bad: #e0413a;
  --warn: #e69b00;
  --magic: #8e44ad;
  --radius: 16px;
  --font: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
}

/* ------------------------------------------------------------- themes */
body[data-theme="default"] {
  --bg: #eef3fb;
  --bg-image:
    radial-gradient(circle at 25% 25%, transparent 9px, rgba(31,78,156,.12) 10px, transparent 12px),
    linear-gradient(45deg, rgba(31,78,156,.06) 25%, transparent 25%, transparent 75%, rgba(31,78,156,.06) 75%);
  --bg-size: 48px 48px, 48px 48px;
  --ink: #13233f;
  --panel: rgba(255,255,255,.92);
  --panel-ink: #13233f;
  --panel-border: #c8d6ee;
  --accent: #1f4e9c;
  --accent-ink: #fff;
  --board-bg: linear-gradient(135deg, #1f4e9c, #2a64c4);
  --cell: #ffffff;
  --cell-ink: #13233f;
}
body[data-theme="warrior"] {
  --bg: #2a2420;
  --bg-image:
    linear-gradient(rgba(0,0,0,.25) 2px, transparent 2px),
    linear-gradient(90deg, rgba(0,0,0,.25) 2px, transparent 2px);
  --bg-size: 64px 32px, 64px 64px;
  --ink: #f4e9da;
  --panel: rgba(59,50,44,.94);
  --panel-ink: #f4e9da;
  --panel-border: #6b5a4c;
  --accent: #b8322a;
  --accent-ink: #fff;
  --board-bg: linear-gradient(180deg, #5b4e44, #3d342d);
  --cell: #e8dccb;
  --cell-ink: #2a2420;
  --font-display: Georgia, serif;
}
body[data-theme="lynx"] {
  --bg: #f1d9ad;
  --bg-image:
    radial-gradient(ellipse at 20% 80%, rgba(120,80,20,.10) 0 9px, transparent 10px),
    radial-gradient(ellipse at 70% 30%, rgba(120,80,20,.08) 0 6px, transparent 7px);
  --bg-size: 90px 70px, 110px 85px;
  --ink: #3b2a1a;
  --panel: rgba(255,250,240,.94);
  --panel-ink: #3b2a1a;
  --panel-border: #e2c08a;
  --accent: #b5651d;
  --accent-ink: #fff;
  --board-bg: linear-gradient(135deg, #8a5a2b, #a87232);
  --cell: #fff6e6;
  --cell-ink: #3b2a1a;
}
body[data-theme="tree"] {
  --bg: #d9efd3;
  --bg-image:
    radial-gradient(circle at 30% 30%, rgba(46,125,50,.16) 0 18px, transparent 19px),
    radial-gradient(circle at 75% 65%, rgba(46,125,50,.12) 0 26px, transparent 27px);
  --bg-size: 120px 120px, 160px 160px;
  --ink: #1b3a1d;
  --panel: rgba(247,252,244,.94);
  --panel-ink: #1b3a1d;
  --panel-border: #a5d6a7;
  --accent: #2e7d32;
  --accent-ink: #fff;
  --board-bg: linear-gradient(135deg, #6d4c41, #4e342e);
  --cell: #f1f8e9;
  --cell-ink: #1b3a1d;
}
body[data-theme="rock"] {
  --bg: #b9c3cc;
  --bg-image:
    linear-gradient(135deg, rgba(255,255,255,.18) 0 20%, transparent 20% 50%, rgba(0,0,0,.06) 50% 70%, transparent 70%);
  --bg-size: 140px 140px;
  --ink: #1f2a30;
  --panel: rgba(240,243,245,.94);
  --panel-ink: #1f2a30;
  --panel-border: #9aa7b2;
  --accent: #4f6470;
  --accent-ink: #fff;
  --board-bg: linear-gradient(135deg, #546e7a, #37474f);
  --cell: #eceff1;
  --cell-ink: #1f2a30;
}
body[data-theme="camoes"] {
  --bg: #0d2a4d;
  --bg-image:
    radial-gradient(ellipse at 50% 0, rgba(255,255,255,.08) 0 16px, transparent 17px),
    radial-gradient(ellipse at 0 100%, rgba(255,255,255,.06) 0 16px, transparent 17px);
  --bg-size: 60px 22px, 60px 22px;
  --ink: #f4ecd8;
  --panel: rgba(244,236,216,.96);
  --panel-ink: #2b1d0e;
  --panel-border: #c9a86a;
  --accent: #b8860b;
  --accent-ink: #fff;
  --board-bg: linear-gradient(135deg, #13315c, #1d4e89);
  --cell: #f4ecd8;
  --cell-ink: #2b1d0e;
  --font-display: Georgia, "Times New Roman", serif;
}
body[data-theme="shakespeare"] {
  --bg: #2a0920;
  --bg-image: repeating-linear-gradient(90deg, rgba(0,0,0,.28) 0 14px, rgba(255,255,255,.03) 14px 40px);
  --bg-size: auto;
  --ink: #f8e9c8;
  --panel: rgba(58,14,42,.95);
  --panel-ink: #f8e9c8;
  --panel-border: #8a5a2b;
  --accent: #c99a2e;
  --accent-ink: #2a0920;
  --board-bg: linear-gradient(180deg, #6a1a4c, #3d0c2e);
  --cell: #fbf1dc;
  --cell-ink: #2a0920;
  --font-display: Georgia, "Times New Roman", serif;
}
body[data-theme="ball"] {
  --bg: #2e8b3e;
  --bg-image: repeating-linear-gradient(90deg, rgba(255,255,255,.07) 0 70px, transparent 70px 140px);
  --bg-size: auto;
  --ink: #ffffff;
  --panel: rgba(255,255,255,.95);
  --panel-ink: #0f2a14;
  --panel-border: #b6e0bd;
  --accent: #111111;
  --accent-ink: #fff;
  --board-bg: linear-gradient(135deg, #1f6b2c, #27843a);
  --cell: #ffffff;
  --cell-ink: #0f2a14;
}

/* -------------------------------------------------------------- base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background-color: var(--bg);
  background-image: var(--bg-image);
  background-size: var(--bg-size);
  transition: background-color .6s ease, color .6s ease;
  overflow-x: hidden;
}
button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
.hidden { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; }

#decor { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
#decor span {
  position: absolute; opacity: .16; animation: floaty 14s ease-in-out infinite;
  filter: saturate(.8);
}
@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-24px) rotate(10deg); }
}

.topbar {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 34px; display: inline-block; animation: logo-spin 6s ease-in-out infinite; }
@keyframes logo-spin { 0%, 80%, 100% { transform: rotate(0); } 88% { transform: rotate(200deg); } 94% { transform: rotate(350deg); } }
.brand h1 { font-size: 26px; letter-spacing: .5px; }
.tagline { margin: 0; font-size: 13px; opacity: .8; }
/* Online: round trip to the host (or, for the host, the slowest player). */
.net-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; background: var(--panel); color: var(--panel-ink); font-size: 12px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.net-badge .dot { width: 9px; height: 9px; border-radius: 50%; background: #9e9e9e; flex: none; }
.net-badge.good .dot { background: var(--good); }
.net-badge.ok .dot { background: var(--warn); }
.net-badge.bad .dot { background: var(--bad); animation: net-blink 1s steps(2) infinite; }
@keyframes net-blink { 50% { opacity: .3; } }
/* Online: the option just picked, while the host confirms it. */
.q-opt.picked { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent) inset; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.lang { display: inline-flex; border-radius: 999px; overflow: hidden; border: 2px solid var(--accent); }
.lang-btn { border: 0; padding: 6px 12px; background: var(--panel); color: var(--panel-ink); font-weight: 700; }
.lang-btn.active { background: var(--accent); color: var(--accent-ink); }

.ghost {
  border: 2px solid var(--accent); background: var(--panel); color: var(--panel-ink);
  padding: 7px 14px; border-radius: 999px; font-weight: 600;
}
.top-actions .ico { display: none; }
/* Narrow phones in a game: About and New game shrink to icons. */
@media (max-width: 420px) {
  body.in-game .top-actions .ico { display: inline; font-size: 15px; }
  body.in-game .top-actions .lbl { display: none; }
  body.in-game #aboutBtn, body.in-game #newGameBtn { padding-left: 9px; padding-right: 9px; }
}
.sound-btn { position: relative; padding: 4px 0; width: 38px; height: 34px; font-size: 17px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.sound-btn.off { opacity: .8; }
/* A red slash over the note when the music is off. */
#musicBtn.off::after {
  content: ''; position: absolute; left: 7px; right: 7px; top: 50%; height: 3px; border-radius: 2px;
  background: #e53935; transform: rotate(-40deg);
}
.primary {
  border: 0; background: var(--accent); color: var(--accent-ink);
  padding: 10px 18px; border-radius: 999px; font-weight: 700;
  box-shadow: 0 4px 0 rgba(0,0,0,.25); transition: transform .1s, box-shadow .1s, filter .2s;
}
.primary:hover:not(:disabled) { filter: brightness(1.1); }
.primary:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.primary:disabled { opacity: .45; box-shadow: none; }
.primary.big { font-size: 18px; padding: 12px 24px; }
.primary.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 4px 0 rgba(0,0,0,.25), 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); } 50% { box-shadow: 0 4px 0 rgba(0,0,0,.25), 0 0 0 10px transparent; } }
button:focus-visible, input:focus-visible { outline: 3px solid #ffbf00; outline-offset: 2px; }

main { position: relative; z-index: 1; padding: 0 16px 24px; }
.card {
  background: var(--panel); color: var(--panel-ink);
  border: 2px solid var(--panel-border); border-radius: var(--radius);
  padding: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  transition: background-color .6s, color .6s, border-color .6s;
}
.card h3 { font-size: 16px; margin-bottom: 8px; }
.label { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; opacity: .75; margin: 10px 0 6px; }
.hint { font-size: 12px; opacity: .65; }

/* ------------------------------------------------------------- setup */
/* One player card at a time (two or three on wider screens), scrolled sideways. */
.setup-card { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.setup-card h2 { font-size: 24px; }
.setup-card .field .label { margin-top: 6px; }
.count-picker { display: flex; gap: 8px; }
/* 2 to 10 players: on narrow phones the buttons shrink to keep one row. */
.count-btn {
  flex: 0 1 auto; min-width: 0; padding: 0;
  width: 48px; height: 48px; border-radius: 14px; border: 2px solid var(--panel-border);
  background: rgba(127,127,127,.06); color: inherit; font-size: 20px; font-weight: 800;
  transition: transform .15s, background .2s, box-shadow .2s;
}
.count-btn:hover { transform: translateY(-2px); }
.count-btn.active {
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 70%, #fff), var(--accent));
  color: var(--accent-ink); border-color: transparent;
  box-shadow: 0 6px 18px -4px var(--accent), inset 0 1px 0 rgba(255,255,255,.4);
  transform: translateY(-2px) scale(1.05);
}
.carousel { position: relative; margin: 0 -14px; }
.player-rows {
  display: flex; gap: 12px; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
  padding: 10px 14px 16px; scroll-padding: 0 14px; scrollbar-width: none;
}
.player-rows::-webkit-scrollbar { display: none; }
.player-row {
  --per: 1;
  flex: 0 0 calc((100% - 12px * (var(--per) - 1)) / var(--per)); min-width: 0;
  scroll-snap-align: start; position: relative;
  border: 2px solid color-mix(in srgb, var(--pc) 55%, transparent); border-radius: 20px; padding: 14px;
  background:
    radial-gradient(120% 70% at 0% 0%, color-mix(in srgb, var(--pc) 28%, transparent), transparent 60%),
    linear-gradient(170deg, color-mix(in srgb, var(--pc) 12%, transparent), color-mix(in srgb, var(--pc) 3%, transparent));
  box-shadow: 0 14px 30px -14px color-mix(in srgb, var(--pc) 75%, transparent), inset 0 1px 0 rgba(255,255,255,.35);
  transition: transform .35s cubic-bezier(.3,1.3,.5,1), opacity .35s, box-shadow .3s;
}
.player-row:not(.in-view) { transform: scale(.94); opacity: .55; }
@media (min-width: 668px) { .player-row { --per: 2; } }
@media (min-width: 1008px) { .player-row { --per: 3; } }
.row-head { display: flex; align-items: center; gap: 12px; }
.row-head .avatar.preview {
  width: 72px; height: 72px; flex: none; animation: var(--idle-anim) 2s ease-in-out infinite;
  filter: drop-shadow(0 8px 10px color-mix(in srgb, var(--pc) 55%, transparent));
}
.name-field { flex: 1; min-width: 0; }
.name-field .label { margin-top: 0; }
.name-field input {
  width: 100%; padding: 9px 12px; border-radius: 12px; border: 2px solid var(--panel-border);
  font: inherit; font-size: 16px; background: #fff; color: #222;
  transition: border-color .2s, box-shadow .2s;
}
.name-field input:focus { border-color: var(--pc); box-shadow: 0 0 0 4px color-mix(in srgb, var(--pc) 25%, transparent); }
.age-field { flex: none; }
.age-field .label { margin-top: 0; }
.age-field select {
  width: 72px; padding: 9px 6px; border-radius: 12px; border: 2px solid var(--panel-border);
  font: inherit; font-size: 16px; font-weight: 700; background: #fff; color: #222; cursor: pointer;
  transition: border-color .2s, box-shadow .2s;
}
.age-field select:focus { outline: none; border-color: var(--pc); box-shadow: 0 0 0 4px color-mix(in srgb, var(--pc) 25%, transparent); }
.row-head { flex-wrap: wrap; }
.row-sub { flex-basis: 100%; margin: -6px 0 0 84px; font-size: 12px; font-weight: 700; color: color-mix(in srgb, var(--pc) 70%, var(--panel-ink)); }
.avatar-picker { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.avatar-opt {
  display: flex; align-items: center; justify-content: center; aspect-ratio: 1;
  border: 2px solid transparent; border-radius: 12px; padding: 3px;
  background: rgba(127,127,127,.1); color: inherit; min-width: 0;
  transition: transform .15s, background .2s, border-color .2s;
}
.avatar-opt span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.avatar-opt:hover { transform: translateY(-2px); }
.avatar-opt .avatar { width: 100%; height: 100%; max-width: 44px; max-height: 44px; }
.avatar-opt:hover .avatar, .avatar-opt.active .avatar { animation: var(--step-anim) .9s ease-in-out infinite; }
.avatar-opt.active {
  border-color: var(--pc); background: color-mix(in srgb, var(--pc) 22%, transparent);
  box-shadow: 0 4px 14px -4px var(--pc);
}
.color-picker { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.swatch {
  width: 100%; max-width: 34px; aspect-ratio: 1; justify-self: center; border-radius: 50%; border: 3px solid #fff; padding: 0;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.55), transparent 45%), var(--sw);
  box-shadow: 0 0 0 1px rgba(0,0,0,.2), 0 3px 6px rgba(0,0,0,.2);
  transition: transform .15s;
}
.swatch:hover:not(:disabled) { transform: scale(1.12); }
.swatch.active { box-shadow: 0 0 0 3px var(--panel-ink), 0 0 14px var(--sw); transform: scale(1.15); }
.swatch:disabled { opacity: .25; background-image: linear-gradient(45deg, transparent 45%, #fff 45% 55%, transparent 55%); }

.carousel-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.carousel-nav.all-visible .nav-btn { visibility: hidden; }
.nav-btn {
  flex: none; min-width: 48px; height: 44px; padding: 0 14px; border-radius: 999px;
  border: 2px solid var(--panel-border); background: rgba(127,127,127,.08); color: inherit;
  font-size: 22px; font-weight: 800; line-height: 1; transition: transform .15s, opacity .2s, background .2s;
}
.nav-btn.next { font-size: 16px; background: color-mix(in srgb, var(--accent) 14%, transparent); border-color: var(--accent); }
.nav-btn.next span { margin-right: 2px; }
.nav-btn:hover:not(:disabled) { transform: translateY(-2px); }
.nav-btn:disabled { opacity: .3; }
/* One row however many players: with 10 on a small phone the dots shrink. */
.dots { display: flex; gap: 6px; justify-content: center; flex-wrap: nowrap; min-width: 0; }
.dot {
  flex: 0 1 auto; min-width: 0; aspect-ratio: 1;
  width: 34px; height: auto; padding: 3px; border-radius: 50%; border: 2px solid transparent;
  background: color-mix(in srgb, var(--pc) 18%, transparent); opacity: .55;
  transition: transform .2s, opacity .2s, border-color .2s;
}
.dot .avatar { width: 100%; height: 100%; }
.dot.active { opacity: 1; border-color: var(--pc); transform: scale(1.12); box-shadow: 0 0 12px -2px var(--pc); }
#startBtn { display: block; margin: 0; }
.start-row { display: flex; align-items: center; justify-content: center; gap: 10px; }

/* --------------------------------------------------------------- game */
/* In game the page is exactly one screen tall: board in the middle, bar at the bottom, nothing scrolls. */
body.in-game { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
body.in-game .topbar { padding-top: 6px; padding-bottom: 6px; flex: none; }
body.in-game .tagline { display: none; }
body.in-game .logo { font-size: 26px; }
body.in-game .brand h1 { font-size: 20px; }
body.in-game main { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 12px; padding-bottom: env(safe-area-inset-bottom); }
#game { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.board-area { flex: 1; min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.board-wrap { position: relative; }
.board {
  display: grid; grid-template-columns: repeat(var(--cols, 13), var(--cs, 56px)); grid-auto-rows: var(--cs, 56px);
  gap: var(--gap, 5px); padding: var(--pad, 10px); border-radius: 18px; background: var(--board-bg);
  box-shadow: 0 14px 40px rgba(0,0,0,.3), inset 0 0 0 3px rgba(255,255,255,.15);
}
.cell {
  position: relative; border-radius: calc(var(--cs, 56px) * .16); container-type: size;
  background: var(--cell); color: var(--cell-ink);
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  border-bottom: max(3px, calc(var(--cs, 56px) * .08)) solid var(--topic, #999);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--topic, #999) 35%, transparent);
  transition: background-color .6s, transform .2s;
  overflow: hidden;
}
/* A square with a pawn on it takes the pawn's colour (see markOccupied in js/game.js). */
.cell.occupied { isolation: isolate; }
.cell .occ { position: absolute; inset: 0; z-index: -1; border-radius: inherit; opacity: .6; pointer-events: none; box-shadow: inset 0 0 0 max(3px, calc(var(--cs, 56px) * .09)) var(--ring); }
.cell.occupied::before { z-index: -1; }
.cell .num { position: absolute; top: 2px; left: 4px; font-size: max(8px, calc(var(--cs, 56px) * .2)); font-weight: 800; opacity: .85; line-height: 1.1; }
.cell .icon { font-size: calc(var(--cs, 56px) * .36); line-height: 1; margin-top: calc(var(--cs, 56px) * .12); }
.cell .tag { font-size: max(7px, calc(var(--cs, 56px) * .13)); font-weight: 700; text-align: center; line-height: 1.05; padding: 0 2px; margin-top: 2px; }
@container (max-width: 58px) { .cell .tag { display: none; } }
.cell.topic-math { --topic: var(--t-math); }
.cell.topic-history { --topic: var(--t-history); }
.cell.topic-science { --topic: var(--t-science); }
.cell.topic-portuguese { --topic: var(--t-portuguese); }
.cell.topic-english { --topic: var(--t-english); }
.cell.topic-french { --topic: var(--t-french); }
.cell.topic-tech { --topic: var(--t-tech); }
.cell.topic-music { --topic: var(--t-music); }
.cell.start { --topic: var(--accent); background: repeating-linear-gradient(45deg, #fff 0 6px, #222 6px 12px); color: #222; }
.cell.start .num, .cell.start .tag { background: #fff; border-radius: 4px; padding: 0 3px; }
.cell.special {
  --topic: #ffcc00;
  background: radial-gradient(circle at 50% 40%, #fff7c2, #ffd54f);
  color: #3a2a00;
}
.cell.special-teleport { --topic: var(--magic); background: radial-gradient(circle at 50% 40%, #f0d7ff, #b57edc); color: #2c0b3f; }
.cell.special-teleport .icon { animation: spin 3s linear infinite; }
.cell.special-skip { --topic: #9e9e9e; background: radial-gradient(circle at 50% 40%, #ffffff, #cfd8dc); }
.cell.special-again { --topic: #00b894; background: radial-gradient(circle at 50% 40%, #e0fff6, #7fe0c4); color: #003d2e; }
.cell.portal { box-shadow: inset 0 0 0 3px var(--magic); }
.cell.refuge::after {
  content: "🛟"; position: absolute; inset: auto 2px 2px auto; font-size: max(9px, calc(var(--cs, 56px) * .24)); line-height: 1;
}
.cell.finish { background: radial-gradient(circle at 50% 40%, #fff8d6, #ffcf40); box-shadow: inset 0 0 0 3px #e0a800, 0 0 18px #ffd54f; }
.cell.trail { animation: trail .5s ease-out; }
.cell.flash { animation: flash .8s ease-out; }
.cell.boom { animation: boom .8s ease-out; }
@keyframes trail { from { box-shadow: inset 0 0 0 4px var(--accent); } }
@keyframes flash { 0% { transform: scale(1); } 30% { transform: scale(1.15); filter: brightness(1.3); } 100% { transform: scale(1); } }
@keyframes boom { 0% { transform: scale(1); } 20% { transform: scale(1.25) rotate(-4deg); } 40% { transform: scale(.95) rotate(3deg); } 100% { transform: scale(1); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- tokens */
.tokens { position: absolute; inset: 0; pointer-events: none; }
.token {
  position: absolute; left: 0; top: 0; width: 40px; height: 40px; z-index: 2;
  transition: transform var(--step-ms, .5s) var(--ease, ease), width .3s, height .3s;
  will-change: transform;
}
.token.no-anim { transition: none !important; }
.token.active { z-index: 6; }
.token.walking { z-index: 8; }
.token .base {
  position: absolute; left: 10%; right: 10%; bottom: -2%; height: 22%; border-radius: 50%;
  background: var(--pc); opacity: .9;
  box-shadow: 0 0 0 2px #fff, 0 3px 6px rgba(0,0,0,.4);
}
.token.active .base { animation: base-glow 1.2s ease-in-out infinite; }
@keyframes base-glow { 0%, 100% { box-shadow: 0 0 0 2px #fff, 0 0 0 0 var(--pc); } 50% { box-shadow: 0 0 0 2px #fff, 0 0 0 8px transparent; } }
.token .avatar { position: absolute; inset: 0 0 8% 0; filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); }
.token.active:not(.walking) .avatar { animation: var(--idle-anim) var(--idle-ms, 1.8s) ease-in-out infinite; }
.token.retreat { transition-duration: .75s; transition-timing-function: cubic-bezier(.5,-.35,.5,1.3); }
.token.retreat .avatar { animation: dizzy .75s ease-in-out; }
.token.knocked { transition-duration: .95s; transition-timing-function: cubic-bezier(.2,.9,.3,1); z-index: 9; }
.token.knocked .avatar { animation: knocked .95s ease-out; }
.token.quaked { transition-duration: 1.5s; transition-timing-function: cubic-bezier(.3,1.25,.4,1); z-index: 9; }
.token.quaked .avatar { animation: knocked 1.5s ease-in-out; }
.move-tag {
  position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%); z-index: 12; pointer-events: none;
  font-weight: 900; font-size: 18px; padding: 1px 8px; border-radius: 999px; color: #fff; white-space: nowrap;
  box-shadow: 0 3px 8px rgba(0,0,0,.35); animation: tag-float 2.2s ease-out forwards;
}
.move-tag.up { background: #2e7d32; }
.move-tag.down { background: #c62828; }
@keyframes tag-float { 0% { opacity: 0; transform: translate(-50%, 8px) scale(.6); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.15); } 75% { opacity: 1; transform: translate(-50%, -14px) scale(1); } 100% { opacity: 0; transform: translate(-50%, -26px); } }
.token.vanish .avatar { animation: vanish .5s ease-in forwards; }
.token.appear .avatar { animation: appear .55s cubic-bezier(.3,1.6,.5,1); }
.token.champion .avatar { animation: champion 1s ease-in-out infinite !important; }
@keyframes dizzy { 0% { transform: rotate(0); } 25% { transform: rotate(-25deg); } 50% { transform: rotate(20deg) scale(.9); } 75% { transform: rotate(-10deg); } 100% { transform: rotate(0); } }
@keyframes knocked { 0% { transform: scale(1) rotate(0); } 50% { transform: scale(1.4) rotate(400deg) translateY(-30%); } 100% { transform: scale(1) rotate(720deg); } }
@keyframes vanish { to { transform: scale(0) rotate(540deg); opacity: 0; } }
@keyframes appear { from { transform: scale(0) rotate(-360deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes champion { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-30%) scale(1.2); } }

/* ------------------------------------------------- avatar drawings */
.avatar { display: block; --pc: #888; }
.avatar svg { width: 100%; height: 100%; display: block; overflow: visible; }
.avatar .pc { fill: var(--pc); }
.avatar .pcs { stroke: var(--pc); }
.avatar svg g { transform-box: fill-box; }

/* Each avatar has its own step motion (when walking) and idle motion (when it is their turn). */
.avatar[data-avatar="warrior"] { --step-anim: warrior-step; --idle-anim: warrior-idle; transform-origin: 50% 100%; }
.avatar[data-avatar="lynx"] { --step-anim: lynx-step; --idle-anim: lynx-idle; transform-origin: 50% 100%; }
.avatar[data-avatar="tree"] { --step-anim: tree-step; --idle-anim: tree-idle; transform-origin: 50% 100%; --idle-ms: 3s; }
.avatar[data-avatar="rock"] { --step-anim: rock-step; --idle-anim: rock-idle; transform-origin: 50% 55%; --idle-ms: 2.6s; }
.avatar[data-avatar="camoes"] { --step-anim: camoes-step; --idle-anim: camoes-idle; transform-origin: 50% 90%; --idle-ms: 2.6s; }
.avatar[data-avatar="shakespeare"] { --step-anim: shakespeare-step; --idle-anim: shakespeare-idle; transform-origin: 50% 100%; }
.avatar[data-avatar="ball"] { --step-anim: ball-step; --idle-anim: ball-idle; transform-origin: 50% 100%; --idle-ms: .9s; }
.avatar.step { animation: var(--step-anim) var(--step-ms, .45s) linear both; }
.avatar.idle { animation: var(--idle-anim) var(--idle-ms, 1.8s) ease-in-out infinite; }

/* Warrior: marches, stomping, sword raised */
@keyframes warrior-step {
  0% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-14%) rotate(-7deg); }
  50% { transform: translateY(0) rotate(0) scaleY(.94); }
  75% { transform: translateY(-14%) rotate(7deg); }
  100% { transform: translateY(0) rotate(0); }
}
.token .avatar.step[data-avatar="warrior"] .part-sword,
.avatar-opt:hover [data-avatar="warrior"] .part-sword,
.avatar-opt.active [data-avatar="warrior"] .part-sword { animation: sword-swing var(--step-ms, .9s) ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes sword-swing { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-35deg); } }
@keyframes warrior-idle { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5%) scale(1.03); } }

/* Lynx: crouches and pounces in a big arc */
@keyframes lynx-step {
  0% { transform: translateY(0) scale(1, 1); }
  18% { transform: translateY(4%) scale(1.18, .82); }
  55% { transform: translateY(-60%) scale(.9, 1.12) rotate(-10deg); }
  82% { transform: translateY(0) scale(1.15, .85) rotate(4deg); }
  100% { transform: translateY(0) scale(1, 1); }
}
@keyframes lynx-idle { 0%, 100% { transform: scale(1, 1); } 40% { transform: scale(1.06, .94); } 60% { transform: scale(1.06, .94) rotate(-3deg); } }

/* Tree: sways and shuffles its roots */
@keyframes tree-step {
  0% { transform: rotate(0); }
  30% { transform: rotate(-15deg) translateY(-4%); }
  65% { transform: rotate(12deg) translateY(-2%); }
  100% { transform: rotate(0); }
}
@keyframes tree-idle { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
.token .avatar.step[data-avatar="tree"] .part-canopy { animation: rustle var(--step-ms) ease-in-out; transform-origin: 50% 100%; }
@keyframes rustle { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08, .95); } }

/* Rock: rolls over, thuds */
@keyframes rock-step {
  0% { transform: rotate(0) translateY(0); }
  80% { transform: rotate(330deg) translateY(-6%); }
  90% { transform: rotate(360deg) translateY(2%) scale(1.06, .92); }
  100% { transform: rotate(360deg) translateY(0); }
}
@keyframes rock-idle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }

/* Camões: sails, rocking like a caravel on the waves */
@keyframes camoes-step {
  0% { transform: rotate(-9deg) translateY(0); }
  50% { transform: rotate(9deg) translateY(-18%); }
  100% { transform: rotate(-9deg) translateY(0); }
}
@keyframes camoes-idle { 0%, 100% { transform: rotate(-5deg) translateY(0); } 50% { transform: rotate(5deg) translateY(-4%); } }
.token .avatar.step[data-avatar="camoes"] .part-quill,
.avatar.idle[data-avatar="camoes"] .part-quill { animation: quill 1s ease-in-out infinite; transform-origin: 0% 100%; }
@keyframes quill { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-18deg); } }

/* Shakespeare: theatrical twirl and bow */
@keyframes shakespeare-step {
  0% { transform: rotateY(0) translateY(0); }
  50% { transform: rotateY(180deg) translateY(-22%); }
  100% { transform: rotateY(360deg) translateY(0); }
}
@keyframes shakespeare-idle { 0%, 60%, 100% { transform: rotate(0); } 75% { transform: rotate(14deg) translateY(4%); } }

/* Football: bounces high with spin and squash */
@keyframes ball-step {
  0% { transform: translateY(0) rotate(0) scale(1.15, .85); }
  12% { transform: translateY(-10%) rotate(40deg) scale(.95, 1.05); }
  50% { transform: translateY(-75%) rotate(180deg) scale(1); }
  88% { transform: translateY(0) rotate(330deg) scale(1); }
  94% { transform: translateY(0) rotate(350deg) scale(1.18, .82); }
  100% { transform: translateY(0) rotate(360deg) scale(1); }
}
@keyframes ball-idle { 0%, 100% { transform: translateY(0) scale(1.08, .92); } 50% { transform: translateY(-22%) scale(1); } }

/* -------------------------------------------------------------- panel */
/* Bottom bar: current player + die */
.bottombar {
  flex: none; display: flex; align-items: center; gap: 12px;
  margin: 0 auto 10px; width: min(100%, 900px); padding: 8px 10px 8px 12px;
  background: var(--panel); color: var(--panel-ink); border: 3px solid var(--pc, var(--accent));
  border-radius: 18px; box-shadow: 0 8px 24px rgba(0,0,0,.2);
  transition: background-color .6s, color .6s, border-color .4s;
}
.turn-avatar .avatar { width: 52px; height: 52px; }
.turn-info { flex: 1; min-width: 0; }
.turn-line { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.turn-name { font-family: var(--font-display); font-size: 20px; font-weight: 700; border-bottom: 4px solid var(--pc); line-height: 1.2; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn-pos { font-size: 14px; opacity: .8; white-space: nowrap; }
.roll-btn {
  flex: none; display: inline-flex; align-items: center; gap: 10px;
  border: 0; border-radius: 16px; padding: 6px 16px 6px 6px;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 17px;
  box-shadow: 0 4px 0 rgba(0,0,0,.25); transition: transform .1s, box-shadow .1s, filter .2s, opacity .2s;
}
.roll-btn:hover:not(:disabled) { filter: brightness(1.1); }
.roll-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.roll-btn:disabled { opacity: .55; box-shadow: none; }
.roll-btn.pulse { animation: pulse 1.6s ease-in-out infinite; }
.icon-btn {
  flex: none; width: 44px; height: 44px; border-radius: 12px; font-size: 20px; line-height: 1;
  border: 2px solid var(--panel-border); background: transparent; color: inherit;
}
.icon-btn:hover { border-color: var(--accent); }
.die {
  width: 52px; height: 52px; flex: none; border-radius: 12px; background: #fff;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: 7px; gap: 1px;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.25); border: 2px solid #ddd;
}
.pip { border-radius: 50%; margin: 2px; }
.pip.on { background: #222; }
.die.rolling { animation: die-roll .25s linear infinite; }
.die.landed { animation: die-land .35s cubic-bezier(.3,1.6,.5,1); }
@keyframes die-roll { 0% { transform: rotate(0) translateY(0); } 50% { transform: rotate(180deg) translateY(-8px); } 100% { transform: rotate(360deg) translateY(0); } }
@keyframes die-land { from { transform: scale(1.35); } to { transform: scale(1); } }
.message { margin-top: 3px; font-weight: 600; font-size: 14px; line-height: 1.25; min-height: 1.25em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.message.good { color: var(--good); }
.message.bad { color: var(--bad); }
.message.warn { color: var(--warn); }
.message.magic { color: var(--magic); }

.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.player-list li {
  display: grid; grid-template-columns: 32px 1fr auto auto auto; grid-template-rows: auto 5px; align-items: center; column-gap: 8px;
  padding: 5px 8px; border-radius: 10px; border-left: 5px solid var(--pc);
  background: rgba(127,127,127,.08);
}
.player-list li.active { background: color-mix(in srgb, var(--pc) 22%, transparent); font-weight: 700; }
.player-list .avatar.mini { width: 32px; height: 32px; grid-row: span 2; }
.pl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-pos { font-weight: 800; font-variant-numeric: tabular-nums; }
.badge { font-size: 10px; background: var(--warn); color: #fff; border-radius: 999px; padding: 1px 6px; }
.bar { grid-column: 2 / -1; height: 5px; background: rgba(127,127,127,.2); border-radius: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--pc); transition: width .4s; }

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.chip { width: 26px; height: 26px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; background: #fff; border-bottom: 4px solid var(--topic, #ffcc00); flex: none; }
.chip.topic-math { --topic: var(--t-math); }
.chip.topic-history { --topic: var(--t-history); }
.chip.topic-science { --topic: var(--t-science); }
.chip.topic-portuguese { --topic: var(--t-portuguese); }
.chip.topic-english { --topic: var(--t-english); }
.chip.topic-french { --topic: var(--t-french); }
.chip.topic-tech { --topic: var(--t-tech); }
.chip.topic-music { --topic: var(--t-music); }
.chip.special { background: #ffe680; }

.log-card .log { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow: auto; font-size: 13px; }
.log li { padding: 4px 0; border-bottom: 1px dashed rgba(127,127,127,.3); }
.log li.good { color: var(--good); }
.log li.bad { color: var(--bad); }
.log li.warn { color: var(--warn); }
.log li.magic { color: var(--magic); }

/* ------------------------------------------------------------ overlays */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(10,12,20,.55); backdrop-filter: blur(3px);
  animation: fade-in .2s ease-out;
}
@keyframes fade-in { from { opacity: 0; } }
.modal {
  position: relative; width: 100%; max-width: 580px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 24px); overflow: auto;
  background: var(--panel); color: var(--panel-ink); border-radius: 20px; padding: 20px;
  border: 3px solid var(--accent); box-shadow: 0 20px 60px rgba(0,0,0,.45);
  animation: pop-in .3s cubic-bezier(.3,1.5,.5,1);
}
@keyframes pop-in { from { transform: scale(.85); opacity: 0; } }
.modal.shake { animation: shake .45s ease-in-out; }
.modal.cheer { animation: cheer .5s ease-out; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
@keyframes cheer { 40% { transform: scale(1.04); } }
.q-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.topic-badge { padding: 5px 12px; border-radius: 999px; color: #fff; font-weight: 700; font-size: 14px; background: var(--topic); }
.topic-badge.topic-math { --topic: var(--t-math); }
.topic-badge.topic-history { --topic: var(--t-history); }
.topic-badge.topic-science { --topic: var(--t-science); }
.topic-badge.topic-portuguese { --topic: var(--t-portuguese); }
.topic-badge.topic-english { --topic: var(--t-english); }
.topic-badge.topic-french { --topic: var(--t-french); }
.topic-badge.topic-tech { --topic: var(--t-tech); }
.topic-badge.topic-music { --topic: var(--t-music); }
.q-house { font-weight: 700; opacity: .75; }
.q-player { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-weight: 700; }
.q-player .avatar { width: 36px; height: 36px; }
.q-text { font-size: 21px; font-weight: 700; margin: 14px 0; line-height: 1.3; font-family: var(--font-display); }
.q-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
/* Savant maths: an answer box and an on-screen number pad instead of options
   (no phone keyboard popping up and pushing the question around). */
.q-options.typed { display: block; }
.q-typed { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.q-entry {
  width: min(100%, 320px); min-height: 56px; display: flex; align-items: center; justify-content: center;
  border-radius: 14px; border: 2px solid var(--accent); background: rgba(127,127,127,.08);
  font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 1px; outline: none;
}
.q-entry.empty { font-size: 16px; font-weight: 600; opacity: .6; letter-spacing: 0; }
.q-entry.correct { background: var(--good); border-color: var(--good); color: #fff; opacity: 1; }
.q-entry.wrong { background: var(--bad); border-color: var(--bad); color: #fff; text-decoration: line-through; opacity: 1; }
.q-entry.small { min-height: 40px; font-size: 22px; width: min(100%, 220px); }
.q-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(100%, 320px); }
.pad-key {
  min-height: 50px; border-radius: 12px; border: 2px solid var(--panel-border);
  background: rgba(127,127,127,.1); color: inherit; font-size: 24px; font-weight: 800;
  touch-action: manipulation; transition: transform .08s, background .15s;
}
.pad-key:active:not(:disabled) { transform: scale(.94); }
.pad-key.back { font-size: 22px; }
.pad-key.ok { background: var(--good); border-color: var(--good); color: #fff; font-size: 16px; }
.pad-key:disabled { opacity: .35; }
@media (max-height: 700px) { .pad-key { min-height: 40px; font-size: 20px; } .q-entry { min-height: 44px; font-size: 24px; } }
.q-opt {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 12px; border-radius: 14px; border: 2px solid var(--panel-border);
  background: rgba(127,127,127,.08); color: inherit; font-size: 16px; font-weight: 600; min-height: 56px;
  transition: transform .1s, background .2s, border-color .2s;
}
.q-opt:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--accent); }
.q-opt .key { flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.q-opt.correct { background: var(--good); border-color: var(--good); color: #fff; animation: flash .6s; }
.q-opt.wrong { background: var(--bad); border-color: var(--bad); color: #fff; }
.q-opt.dim { opacity: .45; }
.q-opt:disabled { cursor: default; }
.q-feedback { min-height: 1.4em; margin-top: 12px; font-weight: 700; }
.q-feedback.good { color: var(--good); }
.q-feedback.bad { color: var(--bad); }
#qContinue { position: relative; overflow: hidden; }
#qContinue.counting::after {
  content: ""; position: absolute; left: 0; bottom: 0; height: 4px; width: 100%;
  background: rgba(255,255,255,.75); transform-origin: left;
  animation: countdown var(--auto-ms, 3s) linear forwards;
}
@keyframes countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.q-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 10px; }

.win-modal { text-align: center; overflow: hidden; }
.win-modal h2 { font-size: 28px; margin: 8px 0; }
.win-modal p { font-size: 18px; }
.win-avatar .avatar { width: 120px; height: 120px; margin: 0 auto; }
.win-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti i { position: absolute; top: -10px; width: 9px; height: 14px; border-radius: 2px; animation: confetti linear infinite; }
@keyframes confetti { to { transform: translateY(110vh) rotate(720deg); } }

.rules-modal { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 14px; }
.rules-modal h2 { flex: none; font-size: 22px; }
.rules-body {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  font-size: 15px; line-height: 1.45; margin: 8px -6px 12px; padding: 0 6px;
  border-top: 1px solid var(--panel-border); border-bottom: 1px solid var(--panel-border);
}
.rules-body ul { padding-left: 18px; margin: 8px 0; }
.rules-body li { margin-bottom: 4px; }
.rules-body h3 { margin-top: 10px; font-size: 17px; }
.rules-body p { margin: 8px 0; }
.rules-modal > .primary { flex: none; align-self: flex-start; }
.tabs { flex: none; display: flex; gap: 6px; border-bottom: 2px solid var(--panel-border); }
.tab {
  border: 0; background: transparent; color: inherit; font: inherit; font-size: 17px; font-weight: 700;
  padding: 8px 14px; border-radius: 12px 12px 0 0; opacity: .65; margin-bottom: -2px; border-bottom: 3px solid transparent;
}
.tab.active { opacity: 1; border-bottom-color: var(--accent); }
.about-body h2 { font-size: 22px; margin: 10px 0 4px; }
.about-by { font-size: 16px; }
.about-links { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.about-links a { text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.about-links .ghost { padding: 10px 16px; border-radius: 999px; color: inherit; }
.about-site { font-size: 13px; opacity: .75; }
.about-site a { color: inherit; }
.count-list { list-style: none; padding: 0 !important; margin: 6px 0; }
.count-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--panel-border); }
.count-name { flex: 1; min-width: 0; }
.count-name small { display: block; font-size: 12px; opacity: .7; }
.count-num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.count-total { font-size: 16px; }
.count-note { font-size: 12px; opacity: .65; }

.toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 520px); }
/* Host only: a player is taking too long. Above the question and duel boxes. */
.slow-bar {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 62; width: max-content; max-width: min(94vw, 560px);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px;
  padding: 8px 10px 8px 16px; border-radius: 18px; background: linear-gradient(180deg, #ffe082, #ffb300); color: #3a2a00; font-weight: 800;
  box-shadow: 0 8px 24px rgba(0,0,0,.35); animation: toast-in .35s cubic-bezier(.3,1.5,.5,1);
}
.slow-bar .slow-actions { display: flex; gap: 8px; }
.slow-bar .ghost { padding: 4px 12px; border-color: #3a2a00; background: rgba(255,255,255,.55); color: #3a2a00; }
.slow-bar .ghost.sure { background: var(--bad); border-color: var(--bad); color: #fff; }
.player-list li.out { opacity: .45; }
.player-list li.out .pl-name { text-decoration: line-through; }
.toast {
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 700; text-align: center;
  box-shadow: 0 8px 20px rgba(0,0,0,.3); animation: toast-in .35s cubic-bezier(.3,1.5,.5,1);
}
.toast.good { background: var(--good); }
.toast.bad { background: var(--bad); }
.toast.warn { background: var(--warn); }
.toast.magic { background: var(--magic); }
.toast.out { opacity: 0; transform: translateY(-10px); transition: .4s; }
@keyframes toast-in { from { transform: translateY(-20px) scale(.9); opacity: 0; } }

/* --------------------------------------------------------- difficulty */
.diff-picker { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.diff-btn {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 4px;
  border-radius: 10px; border: 2px solid var(--panel-border); background: transparent; color: inherit;
  font-size: 13px; font-weight: 700;
}
.diff-btn .stars { font-size: 11px; letter-spacing: 1px; color: var(--lvl); white-space: nowrap; }
.diff-btn.lvl-5 .stars { letter-spacing: 0; font-size: 10px; }
.diff-btn.active { background: var(--lvl); border-color: var(--lvl); color: #fff; }
.diff-btn.active .stars { color: #fff; }
.lvl-1 { --lvl: #2e9d57; }
.lvl-2 { --lvl: #2f80ed; }
.lvl-3 { --lvl: #e67e22; }
.lvl-4 { --lvl: #8e2de2; }
.lvl-5 { --lvl: #c2185b; }
.diff-badge { font-size: 11px; font-weight: 800; color: #fff; background: var(--lvl, #888); border-radius: 999px; padding: 2px 8px; white-space: nowrap; font-family: var(--font); }
.diff-badge:empty { display: none; }
.age-badge { font-size: 11px; font-weight: 800; color: var(--panel-ink); background: color-mix(in srgb, var(--panel-ink) 12%, transparent); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.q-meta { display: inline-flex; align-items: center; gap: 8px; }

/* ------------------------------------------------------------- drawer */
.drawer-overlay { justify-content: flex-end; align-items: stretch; padding: 0; }
.drawer {
  width: min(380px, 100%); height: 100%; overflow: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--bg); background-image: var(--bg-image); background-size: var(--bg-size);
  box-shadow: -10px 0 40px rgba(0,0,0,.35); animation: slide-in .25s ease-out;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; color: var(--ink); }
.drawer-head .icon-btn { background: var(--panel); color: var(--panel-ink); }
@keyframes slide-in { from { transform: translateX(100%); } }
.drawer .log-card .log { max-height: none; }

/* ---------------------------------------------------------- responsive */
@media (max-width: 600px) {
  main { padding: 0 8px 16px; }
  body.in-game main { padding: 0 6px; }
  body.in-game .topbar { flex-wrap: nowrap; padding: 6px; gap: 6px; }
  body.in-game .brand h1 { display: none; }
  body.in-game .top-actions { gap: 5px; }
  body.in-game .top-actions .ghost, body.in-game .lang-btn { padding: 5px 9px; font-size: 14px; }
  body.in-game .top-actions .sound-btn { padding: 0; width: 32px; height: 31px; font-size: 15px; }
  .bottombar { gap: 8px; padding: 6px; margin-bottom: 6px; border-radius: 14px; }
  .turn-avatar .avatar { width: 40px; height: 40px; }
  .turn-name { font-size: 16px; }
  .turn-pos { font-size: 12px; }
  .message { font-size: 12px; }
  .roll-label { display: none; }
  .roll-btn { padding: 5px; border-radius: 14px; }
  .icon-btn { width: 40px; height: 40px; }
  .topbar { padding: 10px 8px; }
  .brand h1 { font-size: 20px; }
  .tagline { display: none; }
  .board { border-radius: 12px; }
  .q-options { grid-template-columns: 1fr; }
  .q-text { font-size: 18px; }
  .overlay { padding: 10px; }
  .modal { padding: 14px; border-radius: 16px; }
  .rules-modal h2 { font-size: 19px; }
  .rules-body { font-size: 13.5px; line-height: 1.4; }
  .rules-body h3 { font-size: 15px; }
  .die { width: 46px; height: 46px; padding: 6px; }
  .diff-btn { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* ============================================================ eye candy */
/* Glow, glass and sparkle on top of the themes. Everything here is decoration:
   it uses each theme's own colours, and the reduced-motion rule above stills it. */

/* A slow aurora of the theme colours behind everything. */
body::before {
  content: ""; position: fixed; inset: -25%; z-index: 0; pointer-events: none;
  background:
    radial-gradient(38% 32% at 22% 24%, color-mix(in srgb, var(--accent) 55%, transparent), transparent 70%),
    radial-gradient(32% 30% at 80% 18%, color-mix(in srgb, var(--t-english) 40%, transparent), transparent 70%),
    radial-gradient(40% 36% at 72% 82%, color-mix(in srgb, var(--t-science) 34%, transparent), transparent 70%),
    radial-gradient(30% 30% at 14% 80%, color-mix(in srgb, var(--t-math) 38%, transparent), transparent 70%);
  filter: blur(40px); opacity: .5; animation: aurora 26s ease-in-out infinite alternate;
}
@keyframes aurora {
  0% { transform: translate3d(0, 0, 0) rotate(0) scale(1); }
  50% { transform: translate3d(5%, -4%, 0) rotate(6deg) scale(1.08); }
  100% { transform: translate3d(-4%, 3%, 0) rotate(-5deg) scale(1.04); }
}
/* Twinkling specks. */
body::after {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 68% 9%, #fff, transparent),
    radial-gradient(2px 2px at 85% 46%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 33% 72%, #fff, transparent),
    radial-gradient(2px 2px at 52% 38%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 92% 88%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 6% 55%, #fff, transparent);
  background-size: 420px 420px; opacity: .55; animation: twinkle 5s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .15; } to { opacity: .6; } }

/* Gradient, shimmering title. */
.brand h1 {
  background: linear-gradient(90deg, var(--ink) 0%, var(--accent) 25%, var(--t-math) 45%, var(--t-english) 65%, var(--ink) 100%);
  background-size: 250% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 9s linear infinite;
}
@keyframes shimmer { from { background-position: 0% 0; } to { background-position: 250% 0; } }
.logo { filter: drop-shadow(0 4px 8px rgba(0,0,0,.25)); }

/* Frosted glass panels. */
.card, .bottombar, .modal {
  background-color: color-mix(in srgb, var(--panel) 80%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.5); backdrop-filter: blur(16px) saturate(1.5);
}
.card { box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 24px 60px -20px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.08); border-radius: 22px; }

/* Glossy buttons with a light sweep. */
.primary, .roll-btn {
  background-image: linear-gradient(180deg, rgba(255,255,255,.28), rgba(255,255,255,0) 55%, rgba(0,0,0,.12));
  position: relative; overflow: hidden; isolation: isolate;
}
.primary:not(#qContinue)::after, .roll-btn::after {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.5) 50%, transparent 70%);
  transform: translateX(-130%);
}
.primary:not(#qContinue):hover::after, .primary.big:not(#qContinue)::after, .roll-btn.pulse::after { animation: sheen 2.6s ease-in-out infinite; }
@keyframes sheen { 0% { transform: translateX(-130%); } 45%, 100% { transform: translateX(130%); } }
.primary.big { box-shadow: 0 5px 0 rgba(0,0,0,.25), 0 12px 30px -8px var(--accent); }

/* The board: a lit frame and glossy tiles. */
.board {
  box-shadow:
    inset 0 0 0 3px rgba(255,255,255,.18), inset 0 2px 0 rgba(255,255,255,.3),
    0 0 0 5px color-mix(in srgb, var(--accent) 30%, transparent),
    0 0 70px -10px color-mix(in srgb, var(--accent) 80%, transparent),
    0 30px 60px -20px rgba(0,0,0,.55);
}
.cell { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--topic, #999) 35%, transparent), 0 3px 6px -2px rgba(0,0,0,.3); }
.cell::before {
  content: ""; position: absolute; inset: 0 0 52% 0; pointer-events: none; border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,255,255,.6), rgba(255,255,255,0));
}
.cell.special::before, .cell.finish::before {
  inset: 0; background: linear-gradient(115deg, transparent 35%, rgba(255,255,255,.75) 50%, transparent 65%);
  background-size: 300% 100%; animation: tile-shine 3.2s ease-in-out infinite;
}
@keyframes tile-shine { 0% { background-position: 120% 0; } 60%, 100% { background-position: -40% 0; } }
.cell.finish { animation: finish-glow 2s ease-in-out infinite; }
@keyframes finish-glow {
  0%, 100% { box-shadow: inset 0 0 0 3px #e0a800, 0 0 14px #ffd54f; }
  50% { box-shadow: inset 0 0 0 3px #e0a800, 0 0 30px 4px #ffd54f; }
}
.cell.flash { animation: flash .8s ease-out, ripple .8s ease-out; }
@keyframes ripple {
  from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--topic, #fff) 90%, transparent), 0 0 20px var(--topic, #fff); }
  to { box-shadow: 0 0 0 14px transparent, 0 0 0 transparent; }
}

/* A glowing halo under whoever is playing. */
.token.active::before {
  content: ""; position: absolute; left: -15%; right: -15%; bottom: -12%; height: 40%; border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--pc) 85%, #fff), transparent);
  filter: blur(2px); animation: halo 1.4s ease-in-out infinite;
}
@keyframes halo { 0%, 100% { opacity: .55; transform: scale(.9); } 50% { opacity: 1; transform: scale(1.15); } }

/* Bottom bar glows in the player's colour. */
.bottombar {
  border-color: color-mix(in srgb, var(--pc, var(--accent)) 80%, #fff);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.3), 0 0 0 4px color-mix(in srgb, var(--pc, var(--accent)) 22%, transparent),
    0 0 36px -6px var(--pc, var(--accent)), 0 16px 40px -14px rgba(0,0,0,.45);
}
.turn-avatar .avatar { filter: drop-shadow(0 4px 8px color-mix(in srgb, var(--pc, #000) 60%, transparent)); }

/* A real-looking die that tumbles in 3D. */
.roll-btn { perspective: 320px; }
.die {
  background: radial-gradient(circle at 30% 25%, #ffffff, #eef1f6 60%, #d9dee8);
  border: 0; box-shadow: inset 0 -5px 0 rgba(0,0,0,.1), inset 0 2px 0 #fff, 0 6px 12px -2px rgba(0,0,0,.4);
  transform-style: preserve-3d;
}
.pip.on { background: radial-gradient(circle at 35% 30%, #555, #111 70%); box-shadow: inset 0 1px 1px rgba(0,0,0,.6); }
.die.rolling { animation: die-tumble .32s linear infinite; }
@keyframes die-tumble {
  0% { transform: translateY(0) rotateX(0) rotateY(0) rotateZ(0); }
  50% { transform: translateY(-12px) rotateX(180deg) rotateY(90deg) rotateZ(45deg); }
  100% { transform: translateY(0) rotateX(360deg) rotateY(180deg) rotateZ(90deg); }
}

/* Question card tinted by its topic, answers popping in one by one. */
.question-modal[data-topic="math"] { --topic: var(--t-math); }
.question-modal[data-topic="history"] { --topic: var(--t-history); }
.question-modal[data-topic="science"] { --topic: var(--t-science); }
.question-modal[data-topic="portuguese"] { --topic: var(--t-portuguese); }
.question-modal[data-topic="english"] { --topic: var(--t-english); }
.question-modal[data-topic="french"] { --topic: var(--t-french); }
.question-modal[data-topic="tech"] { --topic: var(--t-tech); }
.question-modal[data-topic="music"] { --topic: var(--t-music); }
.question-modal {
  border-color: var(--topic, var(--accent));
  background-image: radial-gradient(120% 55% at 50% -12%, color-mix(in srgb, var(--topic, var(--accent)) 32%, transparent), transparent 62%);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--topic, var(--accent)) 22%, transparent), 0 0 80px -10px var(--topic, var(--accent)), 0 30px 70px rgba(0,0,0,.5);
}
.topic-badge { box-shadow: 0 4px 14px -3px var(--topic); }
.q-opt { background-image: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,0)); }
.q-opt:not(:disabled) { animation: opt-in .45s cubic-bezier(.3,1.5,.5,1) both; }
.q-opt:nth-child(2) { animation-delay: .06s; }
.q-opt:nth-child(3) { animation-delay: .12s; }
.q-opt:nth-child(4) { animation-delay: .18s; }
@keyframes opt-in { from { transform: translateY(14px) scale(.92); opacity: 0; } }
.q-opt:hover:not(:disabled) { box-shadow: 0 8px 20px -8px var(--topic, var(--accent)); }
.q-opt.correct { box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 35%, transparent), 0 0 30px -4px var(--good); }

/* Winner: sun rays behind the champion. */
.win-modal { border-color: #ffc107; box-shadow: 0 0 0 6px rgba(255,193,7,.25), 0 0 90px -10px #ffc107, 0 30px 70px rgba(0,0,0,.5); }
.win-avatar { position: relative; }
.win-avatar::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: 280px; height: 280px; margin: -140px 0 0 -140px;
  background: repeating-conic-gradient(rgba(255,200,40,.45) 0 9deg, transparent 9deg 18deg);
  -webkit-mask: radial-gradient(circle, #000 25%, transparent 68%); mask: radial-gradient(circle, #000 25%, transparent 68%);
  animation: spin 14s linear infinite;
}
.win-avatar .avatar { position: relative; filter: drop-shadow(0 10px 18px rgba(0,0,0,.35)); }
.win-modal h2 {
  background: linear-gradient(90deg, #ff9800, #ffd54f, #ff5e7e, #ff9800); background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 4s linear infinite;
}

/* Sparkle bursts (see burst() in game.js). */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 70; }
#fx i {
  position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%;
  background: var(--c); box-shadow: 0 0 10px var(--c);
  animation: burst ease-out forwards;
}
#fx i.star {
  width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 0; box-shadow: none;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  filter: drop-shadow(0 0 4px var(--c));
}
@keyframes burst {
  0% { transform: translate(0, 0) scale(.4) rotate(0); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0) rotate(240deg); opacity: 0; }
}

/* Toasts get the same glass and glow. */
.toast { -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); box-shadow: 0 10px 30px -6px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.3); }

@media (max-width: 600px) {
  .row-head .avatar.preview { width: 60px; height: 60px; }
  .row-sub { margin-left: 72px; }
  .player-row { padding: 12px; }
  .setup-card h2 { font-size: 21px; }
  .count-btn { width: 44px; height: 44px; }
}
/* Short phones: tighten the setup so it still fits without scrolling. */
@media (max-height: 720px) {
  .setup-card { gap: 6px; padding-top: 10px; padding-bottom: 10px; }
  .setup-card .label { margin: 6px 0 4px; }
  .player-rows { padding-top: 6px; padding-bottom: 10px; }
  .row-head .avatar.preview { width: 52px; height: 52px; }
  .row-sub { margin-left: 64px; }
  .count-btn { width: 42px; height: 42px; }
  .diff-btn { padding: 4px; }
}

/* ============================================================== powers */
.energy { display: inline-flex; gap: 1px; align-self: center; }
.energy .en-num { font-size: 13px; font-weight: 900; opacity: .45; white-space: nowrap; }
.energy .en-num.on { opacity: 1; text-shadow: 0 0 6px #ffc400; }
.energy .en-bar { display: inline-block; align-self: center; width: 40px; height: 6px; margin-left: 4px; border-radius: 3px; background: color-mix(in srgb, currentColor 18%, transparent); overflow: hidden; }
.energy .en-bar span { display: block; height: 100%; background: linear-gradient(90deg, #ffd54f, #ff9800); border-radius: 3px; transition: width .4s; }
/* Portal squares show how many more times they can be used. */
.cell .uses { position: absolute; right: 2px; bottom: 2px; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; font-size: 10px; line-height: 15px; font-weight: 900; text-align: center; color: #fff; background: #8e44ad; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
/* Mama */
.mama-scene { position: absolute; z-index: 20; pointer-events: none; transform: translate(-50%, -80%); text-align: center; }
.mama-scene .mama { display: block; font-size: 78px; line-height: 1; filter: drop-shadow(0 8px 14px rgba(0,0,0,.45)); animation: mama-in 1s cubic-bezier(.3,1.5,.5,1) both; }
.mama-scene .hearts { display: block; font-size: 22px; animation: hearts-up 2s ease-out infinite; }
.mama-scene.leaving .mama { animation: mama-out .5s ease-in forwards; }
.token.hugged .avatar { animation: hug-squeeze .6s ease-in-out 3; }
@keyframes mama-in { from { transform: translateY(-160px) scale(.3) rotate(-20deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes mama-out { to { transform: translateY(-120px) scale(.4); opacity: 0; } }
@keyframes hearts-up { 0% { transform: translateY(10px) scale(.7); opacity: 0; } 30% { opacity: 1; } 100% { transform: translateY(-30px) scale(1.1); opacity: 0; } }
@keyframes hug-squeeze { 0%, 100% { transform: scale(1); } 50% { transform: scale(.82, 1.12); } }
.energy i { font-style: normal; font-size: 13px; line-height: 1; opacity: .22; filter: grayscale(1); transition: opacity .3s, filter .3s, transform .3s; }
.energy i.on { opacity: 1; filter: drop-shadow(0 0 4px #ffc400); transform: scale(1.1); }

.power-btn {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 14px; border-radius: 14px; border: 0;
  background: linear-gradient(180deg, #8c6bff, #5e35b1); color: #fff; font-weight: 800; font-size: 15px;
  box-shadow: 0 4px 0 #3b1f8a, 0 8px 18px -6px rgba(124,77,255,.9); transition: transform .1s, box-shadow .1s, opacity .2s, filter .2s;
}
.power-btn { position: relative; }
.power-btn span[aria-hidden] { font-size: 18px; filter: drop-shadow(0 0 4px #ffc400); }
.power-count {
  position: absolute; top: -7px; right: -7px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  background: #ffc400; color: #3a2a00; font-size: 12px; line-height: 20px; text-align: center; box-shadow: 0 0 0 2px #fff, 0 2px 6px rgba(0,0,0,.3);
}
.power-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #3b1f8a; }
.power-btn:disabled { opacity: .45; filter: grayscale(.6); box-shadow: none; }
.power-btn.ready { animation: power-ready 1.8s ease-in-out infinite; }
@keyframes power-ready { 50% { box-shadow: 0 4px 0 #3b1f8a, 0 0 0 6px rgba(255,196,0,.3), 0 0 26px rgba(255,196,0,.9); } }

.power-modal { max-width: 720px; border-color: #ffb300; box-shadow: 0 0 0 6px rgba(255,179,0,.2), 0 0 80px -10px #ffb300, 0 30px 70px rgba(0,0,0,.5); }
.power-modal h2 { font-size: 22px; }
.power-modal > .hint { display: block; margin: 4px 0 0; font-size: 13px; }
.power-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin: 14px 0 4px; }
.power-card {
  display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "icon name cost" "desc desc desc" "why why why";
  align-items: center; gap: 4px 8px; text-align: left; padding: 12px; border-radius: 16px; color: inherit;
  border: 2px solid var(--panel-border);
  background: linear-gradient(160deg, rgba(255,213,79,.18), rgba(255,213,79,.02)), rgba(127,127,127,.06);
  transition: transform .15s, box-shadow .2s, border-color .2s;
  animation: opt-in .4s cubic-bezier(.3,1.5,.5,1) both;
}
.power-card:nth-child(2) { animation-delay: .04s; } .power-card:nth-child(3) { animation-delay: .08s; }
.power-card:nth-child(4) { animation-delay: .12s; } .power-card:nth-child(5) { animation-delay: .16s; } .power-card:nth-child(6) { animation-delay: .2s; }
.power-card:hover:not(:disabled) { transform: translateY(-3px); border-color: #ffb300; box-shadow: 0 12px 24px -10px #ffb300; }
.power-card:disabled { opacity: .5; }
.pc-icon { grid-area: icon; font-size: 28px; line-height: 1; filter: drop-shadow(0 3px 4px rgba(0,0,0,.25)); }
.pc-name { grid-area: name; font-weight: 800; font-size: 16px; }
.pc-cost { grid-area: cost; font-size: 13px; letter-spacing: -1px; filter: drop-shadow(0 0 3px #ffc400); }
.pc-desc { grid-area: desc; font-size: 12.5px; line-height: 1.3; opacity: .85; }
.pc-why { grid-area: why; font-size: 12px; font-weight: 800; color: var(--bad); }
.power-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.target-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 12px; }
.target-btn {
  display: grid; grid-template-columns: 46px 1fr; grid-template-rows: auto auto; align-items: center; column-gap: 10px; text-align: left;
  padding: 8px 12px 8px 8px; border-radius: 16px; border: 2px solid var(--pc); color: inherit;
  background: linear-gradient(160deg, color-mix(in srgb, var(--pc) 25%, transparent), color-mix(in srgb, var(--pc) 5%, transparent));
  transition: transform .15s, box-shadow .2s;
}
.target-btn:hover { transform: translateY(-3px); box-shadow: 0 10px 22px -8px var(--pc); }
.target-btn .avatar { width: 46px; height: 46px; grid-row: span 2; }
.tb-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-meta { font-size: 12px; opacity: .8; }
.topic-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.topic-pick { padding: 14px 10px; border: 0; border-radius: 14px; color: #fff; font-weight: 800; font-size: 15px; background: var(--topic); box-shadow: 0 4px 0 rgba(0,0,0,.2), 0 10px 20px -10px var(--topic); transition: transform .15s; }
.topic-pick:hover { transform: translateY(-2px); }
.topic-pick.topic-math { --topic: var(--t-math); } .topic-pick.topic-history { --topic: var(--t-history); }
.topic-pick.topic-science { --topic: var(--t-science); } .topic-pick.topic-portuguese { --topic: var(--t-portuguese); }
.topic-pick.topic-english { --topic: var(--t-english); }
.topic-pick.topic-french { --topic: var(--t-french); }
.topic-pick.topic-tech { --topic: var(--t-tech); }
.topic-pick.topic-music { --topic: var(--t-music); }

/* Traps */
.trap-banner {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 12px; align-self: center;
  padding: 6px 8px 6px 16px; border-radius: 999px; background: linear-gradient(180deg, #ffe082, #ffb300); color: #3a2a00; font-weight: 800;
  box-shadow: 0 0 30px rgba(255,179,0,.7); animation: pop-in .3s cubic-bezier(.3,1.5,.5,1);
}
.trap-banner .ghost { padding: 4px 12px; border-color: #3a2a00; background: rgba(255,255,255,.5); color: #3a2a00; }
.cell.trappable { cursor: pointer; outline: 3px dashed #ffb300; outline-offset: -3px; animation: trappable .9s ease-in-out infinite alternate; }
.cell.trappable:hover { transform: scale(1.1); z-index: 1; }
@keyframes trappable { to { filter: brightness(1.12); outline-color: #ff6f00; } }
.trap-mark { position: absolute; right: 2px; bottom: 3px; font-size: max(10px, calc(var(--cs, 56px) * .3)); line-height: 1; filter: drop-shadow(0 0 3px var(--pc)) drop-shadow(0 0 2px var(--pc)); animation: trap-wiggle 2.4s ease-in-out infinite; }
@keyframes trap-wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-14deg); } 92% { transform: rotate(12deg); } }

/* Status on tokens */
.token.shielded::after {
  content: ""; position: absolute; inset: -16% -16% -6%; border-radius: 50%; pointer-events: none;
  border: 2px solid rgba(128,216,255,.95); background: radial-gradient(circle, transparent 55%, rgba(128,216,255,.4));
  box-shadow: 0 0 12px rgba(128,216,255,.9); animation: shield-pulse 2s ease-in-out infinite;
}
@keyframes shield-pulse { 50% { transform: scale(1.06); box-shadow: 0 0 20px rgba(128,216,255,1); } }
.token.frozen .avatar { filter: saturate(.3) brightness(1.15) hue-rotate(180deg) drop-shadow(0 0 5px #81d4fa) !important; }
.token.cursed .base { box-shadow: 0 0 0 2px #fff, 0 0 12px 4px #ff7043; }
.pl-status { font-size: 12px; white-space: nowrap; }
.pl-energy { color: #e09b00; font-weight: 800; margin-left: 2px; }

/* Question timer */
.q-timer { position: relative; height: 10px; margin: 12px 46px 4px 0; border-radius: 99px; background: rgba(127,127,127,.22); }
.q-timer-bar {
  position: absolute; inset: 0; border-radius: inherit; transform-origin: left;
  background: linear-gradient(90deg, var(--good), #9be15d, #ffd54f); box-shadow: 0 0 10px rgba(155,225,93,.7);
}
.q-timer.running .q-timer-bar { animation: q-timer var(--t-ms, 30s) linear var(--t-delay, 0ms) forwards; }
.q-timer.stopped .q-timer-bar { animation-play-state: paused; }
.q-timer.urgent .q-timer-bar { background: linear-gradient(90deg, var(--bad), #ff8a65); box-shadow: 0 0 12px var(--bad); }
.q-timer-num { position: absolute; right: -46px; top: 50%; transform: translateY(-50%); width: 38px; text-align: right; font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.q-timer.urgent .q-timer-num { color: var(--bad); animation: tick .5s ease-in-out infinite alternate; }
@keyframes q-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes tick { to { transform: translateY(-50%) scale(1.25); } }

/* Duel */
.duel-modal { border-color: #ff5722; box-shadow: 0 0 0 6px rgba(255,87,34,.22), 0 0 90px -10px #ff5722, 0 30px 70px rgba(0,0,0,.5);
  background-image: radial-gradient(120% 55% at 50% -12%, rgba(255,87,34,.3), transparent 62%); }
.duel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.duel-title { font-family: var(--font-display); font-size: 26px; font-weight: 800; background: linear-gradient(90deg, #ff3d00, #ffab00); -webkit-background-clip: text; background-clip: text; color: transparent; }
.duel-vs { display: inline-flex; align-items: center; gap: 6px; }
.duel-vs .avatar { width: 36px; height: 36px; }
.duel-vs b { color: #ff3d00; font-weight: 900; font-size: 14px; }
.duel-pass { text-align: center; padding: 8px 0 4px; }
.duel-pass .avatar { width: 112px; height: 112px; margin: 6px auto; filter: drop-shadow(0 10px 18px color-mix(in srgb, var(--pc) 70%, transparent)); }
.duel-sub { margin: 4px 0; opacity: .8; }
.duel-hide { font-size: 18px; font-weight: 800; margin: 8px 0 16px; }
.duel-answer { font-weight: 800; color: var(--good); margin: -4px 0 10px; }
.duel-results { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.duel-results li {
  display: grid; grid-template-columns: 40px 1fr auto; grid-template-rows: auto auto; align-items: center; column-gap: 10px;
  padding: 8px 12px 8px 8px; border-radius: 14px; border: 2px solid var(--panel-border); background: rgba(127,127,127,.08);
}
.duel-results li .avatar { width: 40px; height: 40px; grid-row: span 2; }
.duel-results .dr-name { font-weight: 800; }
.duel-results .dr-ans { grid-column: 2; font-size: 14px; }
.duel-results .dr-time { grid-row: 1 / span 2; grid-column: 3; font-weight: 800; font-variant-numeric: tabular-nums; }
.duel-results li.good .dr-ans { color: var(--good); }
.duel-results li.bad .dr-ans { color: var(--bad); }
.duel-results li.winner { border-color: #ffc107; background: linear-gradient(160deg, rgba(255,193,7,.3), rgba(255,193,7,.05)); box-shadow: 0 0 24px -6px #ffc107; }
.duel-verdict { text-align: center; font-weight: 800; font-size: 18px; margin: 14px 0 0; }

/* Steal */
/* Surprise power: a box that shakes, then opens. */
.surprise-modal { text-align: center; max-width: 440px; border-color: #ffb300; box-shadow: 0 0 0 6px rgba(255,179,0,.25), 0 0 80px -10px #ffb300, 0 30px 70px rgba(0,0,0,.5); }
.surprise-modal.good { border-color: #43a047; box-shadow: 0 0 0 6px rgba(67,160,71,.3), 0 0 90px -10px #43a047, 0 30px 70px rgba(0,0,0,.5); }
.surprise-modal.bad { border-color: #e53935; box-shadow: 0 0 0 6px rgba(229,57,53,.3), 0 0 90px -10px #e53935, 0 30px 70px rgba(0,0,0,.5); }
.surprise-modal.chaos { border-color: #8e24aa; box-shadow: 0 0 0 6px rgba(142,36,170,.3), 0 0 90px -10px #8e24aa, 0 30px 70px rgba(0,0,0,.5); }
.surprise-modal h2 { font-size: 24px; margin: 6px 0; }
.surprise-modal p { font-size: 17px; line-height: 1.4; margin: 6px 0 14px; }
.sur-box { font-size: 96px; line-height: 1.1; display: inline-block; animation: sur-shake .5s ease-in-out infinite; }
@keyframes sur-shake { 0%, 100% { transform: rotate(0) scale(1); } 20% { transform: rotate(-14deg) scale(1.05); } 40% { transform: rotate(12deg) scale(.95); } 60% { transform: rotate(-8deg) translateY(-8px); } 80% { transform: rotate(6deg); } }
.sur-icon { font-size: 92px; line-height: 1.1; display: inline-block; animation: sur-pop .6s cubic-bezier(.3,1.7,.5,1); }
@keyframes sur-pop { from { transform: scale(0) rotate(-200deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
.sur-kind { display: inline-block; font-weight: 900; font-size: 13px; letter-spacing: .5px; text-transform: uppercase; color: #fff; padding: 3px 12px; border-radius: 999px; background: #8e24aa; }
.sur-kind.good { background: #2e7d32; }
.sur-kind.bad { background: #c62828; }
/* "Better in full screen" */
.fs-modal { text-align: center; max-width: 420px; }
.fs-modal h2 { font-size: 22px; margin: 6px 0; }
.fs-modal p { font-size: 16px; line-height: 1.4; }
.fs-icon { font-size: 54px; line-height: 1; }

/* Leaderboard */
.scores-link { display: inline-flex; align-items: center; gap: 6px; flex: none; }
@media (max-width: 520px), (max-height: 700px) { .scores-link .scores-label { display: none; } .scores-link { padding: 8px 12px; font-size: 18px; } }
.scores-modal { max-width: 640px; width: 100%; }
.scores-modal h2 { font-size: 24px; margin-bottom: 4px; }
.scores-empty { text-align: center; font-size: 16px; opacity: .8; margin: 18px 0; }
.scores-wrap { max-height: min(55vh, 460px); overflow: auto; border-radius: 12px; }
table.scores { width: 100%; border-collapse: collapse; font-size: 14px; }
table.scores th { position: sticky; top: 0; background: var(--panel); text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; opacity: .85; padding: 6px; }
table.scores td { padding: 6px; border-top: 1px solid color-mix(in srgb, var(--panel-ink) 12%, transparent); vertical-align: middle; }
table.scores td.rank { font-weight: 800; text-align: center; width: 2em; }
table.scores td.who { display: flex; align-items: center; gap: 6px; font-weight: 700; }
table.scores td.who small { font-weight: 600; opacity: .7; }
table.scores td.who .avatar { width: 28px; height: 28px; flex: none; }
table.scores td.pts { font-weight: 900; font-size: 16px; }
table.scores td.date { font-size: 12px; opacity: .75; white-space: nowrap; }
table.scores tr.mine td { background: color-mix(in srgb, var(--pc) 22%, transparent); }
@media (max-width: 520px) {
  table.scores .date, table.scores th:last-child, table.scores td.who small { display: none; }
  table.scores { font-size: 13px; }
  table.scores th { font-size: 10px; letter-spacing: 0; padding: 4px 3px; }
  table.scores td { padding: 5px 3px; }
  table.scores td.who .avatar { width: 22px; height: 22px; }
  table.scores td.pts { font-size: 14px; }
  table.scores .diff-badge { padding: 2px 5px; font-size: 10px; }
  table.scores th .long { display: none; }
}
table.scores th .short { display: none; }
@media (max-width: 520px) { table.scores th .short { display: inline; } }
.win-score { display: flex; flex-direction: column; gap: 4px; align-items: center; margin: 4px 0; }
.win-score:empty { display: none; }
.win-points { font-size: 26px; font-weight: 900; }
.win-detail { font-size: 14px; opacity: .85; }
.win-rank { font-size: 15px; font-weight: 800; }
.steal-modal { text-align: center; max-width: 460px; border-color: #7e57c2; box-shadow: 0 0 0 6px rgba(126,87,194,.25), 0 0 80px -10px #7e57c2, 0 30px 70px rgba(0,0,0,.5); }
.steal-avatar .avatar { width: 92px; height: 92px; margin: 0 auto 6px; }
.steal-modal h2 { font-size: 24px; }
.steal-modal p { font-size: 16px; line-height: 1.4; }

@media (max-width: 600px) {
  .power-label { display: none; }
  .power-btn { padding: 0 10px; height: 40px; }
  .power-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .power-card { padding: 10px; grid-template-areas: "icon cost" "name name" "desc desc" "why why"; grid-template-columns: 1fr auto; }
  .pc-desc { font-size: 11.5px; }
  .target-list { grid-template-columns: 1fr; }
  .energy i { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  /* The timer bar is information, not decoration: keep it counting down. */
  .q-timer.running .q-timer-bar { animation-duration: var(--t-ms, 30s) !important; }
}

/* ============================================================ 3D die */
.die {
  --ds: 52px; position: relative; display: block; width: var(--ds); height: var(--ds); padding: 0;
  background: none; border: 0; border-radius: 0; box-shadow: none; perspective: 240px;
}
.cube { position: absolute; inset: 0; transform-style: preserve-3d; }
.face {
  position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  padding: 12%; border-radius: 20%; backface-visibility: hidden;
  background: radial-gradient(circle at 30% 25%, #ffffff, #f2f4f9 55%, #d6dce8);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08), inset 0 -3px 6px rgba(0,0,0,.12);
}
.face .pip { margin: 16%; border-radius: 50%; }
.face .pip.on { background: radial-gradient(circle at 35% 30%, #555, #111 70%); box-shadow: inset 0 1px 1px rgba(0,0,0,.6); }
.face.f1 .pip.on { background: radial-gradient(circle at 35% 30%, #ff6b6b, #c62828 70%); }
.f1 { transform: translateZ(calc(var(--ds) / 2)); }
.f6 { transform: rotateY(180deg) translateZ(calc(var(--ds) / 2)); }
.f2 { transform: rotateY(90deg) translateZ(calc(var(--ds) / 2)); }
.f5 { transform: rotateY(-90deg) translateZ(calc(var(--ds) / 2)); }
.f3 { transform: rotateX(90deg) translateZ(calc(var(--ds) / 2)); }
.f4 { transform: rotateX(-90deg) translateZ(calc(var(--ds) / 2)); }
.die-shadow {
  position: absolute; left: 12%; right: 12%; bottom: -9%; height: 14%; border-radius: 50%;
  background: rgba(0,0,0,.35); filter: blur(3px); z-index: -1;
}
.die.rolling { animation: die-hop 1.1s cubic-bezier(.3,.6,.4,1); }
.die.landed { animation: die-squash .3s ease-out; }
@keyframes die-hop {
  0% { transform: translateY(0) scale(1); }
  20% { transform: translateY(-6px) scale(1.06); }
  45% { transform: translateY(0) scale(1); }
  60% { transform: translateY(-3px) scale(1.03); }
  75%, 100% { transform: translateY(0) scale(1); }
}
@keyframes die-squash { 40% { transform: scale(1.08, .92); } 100% { transform: scale(1); } }
@media (max-width: 600px) { .die { --ds: 46px; padding: 0; } }

/* Streak badge on the question */
.streak-badge { font-size: 11px; font-weight: 800; color: #fff; border-radius: 999px; padding: 2px 8px; white-space: nowrap;
  background: linear-gradient(90deg, #ff3d00, #ff9100); box-shadow: 0 0 12px -2px #ff6d00; }
.streak-badge:empty { display: none; }
/* The roll button must not clip the die while it tumbles: the sheen moves by
   background position instead of overflowing, and only the label dims. */
.roll-btn { overflow: visible; }
.roll-btn::after {
  transform: none; border-radius: inherit;
  background: linear-gradient(110deg, transparent 40%, rgba(255,255,255,.5) 50%, transparent 60%) no-repeat;
  background-size: 300% 100%; background-position: 150% 0;
}
.roll-btn.pulse::after { animation: sheen-bg 2.6s ease-in-out infinite; }
@keyframes sheen-bg { 0% { background-position: 150% 0; } 45%, 100% { background-position: -50% 0; } }
.roll-btn:disabled { opacity: 1; background-color: color-mix(in srgb, var(--accent) 55%, #777); }
.roll-btn:disabled .roll-label { opacity: .6; }

/* ===================================================== a real board */
/* The board is a thick printed board with a wooden frame, lying on the table
   and tilted away from the player. The pawns stand up on it. */
.board-wrap {
  transform: perspective(var(--persp, 1500px)) rotateX(var(--tilt, 0deg));
  transform-origin: 50% 55%;
  transform-style: preserve-3d;
}
.board {
  position: relative;
  border: var(--frame, 10px) solid transparent;
  border-radius: calc(var(--frame, 10px) + 10px);
  background:
    var(--board-bg) padding-box,
    linear-gradient(90deg, rgba(0,0,0,.18), transparent 12%, transparent 88%, rgba(0,0,0,.18)) border-box,
    repeating-linear-gradient(92deg, #7a4a22 0 2px, #8d5a2b 2px 5px, #9b6633 5px 9px, #87552a 9px 12px, #a06b37 12px 17px) border-box;
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,.12), inset 0 6px 18px rgba(0,0,0,.35),
    0 2px 0 #6b4220, 0 6px 0 #5a3519, 0 10px 0 #4a2b14,
    0 24px 30px rgba(0,0,0,.45), 0 50px 70px -20px rgba(0,0,0,.5);
}
/* Printed paper texture on the board's surface. */
.board::after {
  content: ""; position: absolute; inset: 0; border-radius: 10px; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(rgba(255,255,255,.06) 1px, transparent 1px),
    radial-gradient(rgba(0,0,0,.06) 1px, transparent 1px);
  background-size: 7px 7px, 11px 11px;
  background-position: 0 0, 3px 5px;
}
.road { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 0; }
.road polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.road-bed { stroke: rgba(0,0,0,.28); stroke-width: calc(var(--cs, 56px) * .42); }
.road-line { stroke: rgba(255,240,200,.75); stroke-width: max(2px, calc(var(--cs, 56px) * .06)); stroke-dasharray: 6 7; }
.cell { z-index: 1; }
/* Tiles: printed card with a thickness and a shadow on the board. */
.cell {
  background-image:
    linear-gradient(180deg, rgba(255,255,255,.35), rgba(255,255,255,0) 45%),
    radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px);
  background-size: auto, 5px 5px;
  box-shadow:
    inset 0 0 0 2px color-mix(in srgb, var(--topic, #999) 35%, transparent),
    0 2px 0 color-mix(in srgb, var(--topic, #999) 55%, #000),
    0 4px 0 rgba(0,0,0,.25),
    0 6px 8px rgba(0,0,0,.25);
}
.cell::before { display: none; }
.cell .num { text-shadow: 0 1px 0 rgba(255,255,255,.6); }
.cell .icon { filter: drop-shadow(0 2px 1px rgba(0,0,0,.25)); }
/* Pawns stand upright on the tilted board; their base disc lies flat on it. */
.tokens, .token { transform-style: preserve-3d; }
.token .avatar { rotate: x calc(-1 * var(--tilt, 0deg)); transform-origin: 50% 92%; }
.token .base {
  background: radial-gradient(ellipse at 50% 40%, color-mix(in srgb, var(--pc) 85%, #fff), var(--pc) 60%, color-mix(in srgb, var(--pc) 60%, #000));
  box-shadow: 0 0 0 2px #fff, 0 2px 0 color-mix(in srgb, var(--pc) 50%, #000), 0 4px 8px rgba(0,0,0,.5);
}
/* A soft pool of light on the table under the board. */
.board-area { background: radial-gradient(60% 55% at 50% 50%, rgba(255,255,255,.12), transparent 70%); }

/* Earthquake: the whole board shakes and the squares wobble. */
.board-area.quaking { animation: quake 1.6s cubic-bezier(.36,.07,.19,.97) 2; }
.board-area.quaking .cell { animation: wobble .25s ease-in-out 12 alternate; }
.board-area.quaking .cell:nth-child(3n) { animation-delay: .05s; }
.board-area.quaking .cell:nth-child(3n+1) { animation-delay: .1s; animation-direction: alternate-reverse; }
@keyframes quake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  10%, 50%, 90% { transform: translate(-9px, 3px) rotate(-1deg); }
  30%, 70% { transform: translate(9px, -4px) rotate(1deg); }
  20%, 60% { transform: translate(6px, 5px) rotate(.5deg); }
  40%, 80% { transform: translate(-6px, -3px) rotate(-.5deg); }
}
@keyframes wobble { from { transform: translateY(0) rotate(0); } to { transform: translateY(-3px) rotate(2deg); } }

/* ======================================================== screen sizes */
/* Big screens (TVs, 1440p/4K monitors): the board already grows to fill the
   space; scale the rest of the interface with it so text and buttons don't
   end up tiny. `zoom` also scales viewport units, so heights based on the
   viewport are divided by the same factor. */
:root { --ui: 1; }
@media (min-width: 1700px) and (min-height: 950px) { :root { --ui: 1.25; } }
@media (min-width: 2300px) and (min-height: 1300px) { :root { --ui: 1.6; } }
@media (min-width: 3200px) and (min-height: 1800px) { :root { --ui: 2.2; } }
.topbar, .setup-card, .bottombar, .trap-banner, .overlay, .toasts, .slow-bar { zoom: var(--ui); }
.modal { max-height: calc((100dvh - 24px) / var(--ui)); }
.toasts { width: min(92vw / var(--ui), 520px); }

/* Small phones: keep the whole setup on one screen. */
@media (max-width: 400px) {
  .dots { gap: 4px; }
  .dot { width: 28px; padding: 2px; }
  .nav-btn { min-width: 40px; height: 40px; padding: 0 10px; }
  .nav-btn.next { font-size: 14px; }
  .count-picker { gap: 6px; }
}
@media (max-height: 700px) and (orientation: portrait) {
  .topbar { padding-top: 6px; padding-bottom: 6px; }
  .logo { font-size: 26px; }
  .setup-card { padding: 10px 12px; }
  .setup-card h2 { font-size: 19px; }
  .setup-card .label { margin: 4px 0 3px; }
  .player-rows { padding-top: 4px; padding-bottom: 8px; }
  .player-row { padding: 10px; }
  .row-head .avatar.preview { width: 46px; height: 46px; }
  .row-sub { margin-left: 58px; }
  .count-btn { width: 40px; height: 40px; font-size: 18px; border-radius: 12px; }
  .avatar-picker { gap: 3px; }
  .primary.big { font-size: 16px; padding: 10px 22px; }
}
@media (max-height: 600px) and (orientation: portrait) {
  .row-sub { display: none; }
  .setup-card h2 { display: none; }
  .setup-card .field .label { margin-top: 0; }
  .avatar-opt { padding: 1px; border-radius: 9px; }
  .swatch { border-width: 2px; }
}

/* Phones held sideways (and other short, wide windows): the bars at the top
   and bottom would leave the board a thin strip, so the player panel moves to
   the side and the board gets the full height. */
@media (orientation: landscape) and (max-height: 520px) {
  .topbar { padding: 4px 10px; gap: 8px; }
  .logo { font-size: 22px; }
  .brand h1 { font-size: 18px; }
  .tagline { display: none; }
  .top-actions .ghost, .lang-btn { padding: 4px 10px; font-size: 13px; }
  body.in-game .topbar { padding: 3px 10px; flex-wrap: nowrap; }
  body.in-game .logo { font-size: 20px; }
  body.in-game .brand h1 { font-size: 16px; }
  body.in-game main { padding: 0 8px 0 max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }

  #game { position: relative; flex-direction: row; gap: 8px; }
  .trap-banner { position: absolute; top: 4px; left: 50%; transform: translateX(-50%); z-index: 5; font-size: 13px; }
  .bottombar {
    width: clamp(150px, 24vw, 210px); margin: 0 0 max(8px, env(safe-area-inset-bottom)); align-self: center;
    max-height: 100%; overflow: hidden;
    flex-wrap: wrap; align-content: center; gap: 6px; padding: 8px; border-radius: 14px;
  }
  .turn-avatar .avatar { width: 36px; height: 36px; }
  .turn-info { flex: 1 1 calc(100% - 46px); }
  .turn-name { font-size: 15px; }
  .turn-pos { font-size: 12px; }
  .turn-line { gap: 2px 6px; }
  .message { flex-basis: 100%; font-size: 12px; -webkit-line-clamp: 3; }
  .roll-btn { flex: 1 1 100%; justify-content: center; padding: 4px 10px 4px 4px; font-size: 14px; border-radius: 12px; }
  .roll-label { display: inline; }
  .die { --ds: 38px; width: 38px; height: 38px; padding: 5px; }
  .power-btn { flex: 1; justify-content: center; font-size: 13px; }
  .icon-btn { width: 38px; height: 38px; }

  /* Questions: two columns of answers and tighter spacing so they fit without scrolling. */
  .overlay { padding: 8px; }
  .modal { padding: 12px 16px; max-width: 680px; }
  .q-options { grid-template-columns: 1fr 1fr; gap: 8px; }
  .q-opt { min-height: 44px; padding: 6px 10px; font-size: 14px; }
  .q-text { font-size: 17px; margin: 6px 0 8px; }
  .q-player { margin: 4px 0 0; }
  .q-foot .hint { display: none; }
  .power-modal { max-width: 760px; }
}

/* Setup on phones held sideways: one player at a time, laid out in two
   columns (name + avatar | difficulty + colour) so it fits the short screen. */
@media (orientation: landscape) and (max-height: 520px) {
  main { padding-bottom: 8px; }
  .setup-card { padding: 8px 14px; gap: 4px; }
  .setup-card h2, .row-sub { display: none; }
  .setup-card .field { display: flex; align-items: center; gap: 10px; }
  .setup-card .field .label { margin: 0; }
  .count-btn { width: 36px; height: 36px; font-size: 17px; border-radius: 10px; }
  .player-rows { padding-top: 4px; padding-bottom: 6px; }
  .player-row {
    --per: 1; padding: 8px 12px;
    display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; align-content: start;
    grid-template-areas: "head dl" "head diff" "al cl" "av col";
  }
  .player-row > :nth-child(1) { grid-area: head; align-self: center; }
  .player-row > :nth-child(2) { grid-area: al; }
  .player-row > :nth-child(3) { grid-area: av; }
  .player-row > :nth-child(4) { grid-area: dl; margin-top: 0; }
  .player-row > :nth-child(5) { grid-area: diff; }
  .player-row > :nth-child(6) { grid-area: cl; }
  .player-row > :nth-child(7) { grid-area: col; align-self: center; }
  .player-row .label { margin: 4px 0 3px; }
  .row-head .avatar.preview { width: 44px; height: 44px; }
  .name-field input { padding: 6px 10px; }
  .age-field select { padding: 6px 4px; width: 62px; }
  .avatar-opt { padding: 1px; border-radius: 9px; }
  .avatar-opt .avatar { max-width: 32px; max-height: 32px; }
  .swatch { border-width: 2px; }
  .diff-btn { padding: 3px; }
  .nav-btn { height: 36px; min-width: 40px; }
  .dot { width: 30px; padding: 2px; }
  .primary.big { font-size: 15px; padding: 8px 22px; }
}
/* Very narrow phones: the logo makes room for the sound buttons during a game. */
@media (max-width: 360px) {
  body.in-game .brand { display: none; }
  body.in-game .topbar { justify-content: flex-end; padding-left: 4px; padding-right: 4px; }
  body.in-game .top-actions { gap: 3px; }
  body.in-game .top-actions .sound-btn { width: 28px; }
  .top-actions { gap: 4px; }
  .top-actions .sound-btn { width: 30px; }
  .top-actions .ghost:not(.sound-btn), .lang-btn { padding-left: 8px; padding-right: 8px; }
  body.in-game .top-actions { gap: 4px; }
  body.in-game .top-actions .ghost { white-space: nowrap; padding: 4px 7px; font-size: 13px; }
  body.in-game .lang-btn { padding: 4px 7px; font-size: 13px; }
  body.in-game .top-actions .sound-btn { width: 30px; padding: 0; }
}
/* Very narrow phones: the Next button shows just the arrow so the player dots stay on one line. */
@media (max-width: 359px) {
  .nav-btn.next span { display: none; }
  .dot { width: 26px; }
}

/* ------------------------------------------------------------- online */
.start-row { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.start-row #startBtn { margin: 0; }
.online-btn { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
@media (max-width: 420px) { .online-btn [data-i18n] { display: none; } .online-btn { font-size: 20px; padding: 8px 12px; } }
.online-btn.off { opacity: .55; }
.online-card { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.online-card > div { display: flex; flex-direction: column; gap: 12px; }
.online-card > div.hidden { display: none; }
.online-card h2 { font-size: 24px; }
.online-card .ghost { align-self: flex-start; }
.join-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.join-row .name-field { --pc: var(--accent); }
.join-row input { text-transform: uppercase; letter-spacing: 4px; font-weight: 800; font-size: 20px; }
.online-status { min-height: 1.3em; font-weight: 600; }
.online-status.bad { color: var(--bad); }
.room-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.room-head .label { margin: 0 0 2px; }
.room-code { font-size: 34px; letter-spacing: 8px; font-family: var(--font-display); color: var(--accent); }
.my-card .player-row { flex: none; }
.roster { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.roster li {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 12px;
  background: color-mix(in srgb, var(--pc) 14%, transparent); border-left: 4px solid var(--pc);
}
.roster li.me { font-weight: 700; }
.roster li.offline { opacity: .5; }
.roster .avatar.mini { width: 32px; height: 32px; flex: none; }
.roster .ro-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster .ro-name em { font-weight: 400; opacity: .7; }
.roster .ro-link { font-size: 12px; opacity: .7; }
.turn-waiting { font-size: 13px; font-weight: 600; opacity: .75; }
.bottombar.remote .roll-btn, .bottombar.remote .power-btn { opacity: .45; }
.q-watch { margin: 8px 0 0; font-weight: 600; opacity: .75; min-height: 0; }
.q-watch:empty { display: none; }
#questionOverlay.watching .hint { visibility: hidden; }
body.replaying .tokens, body.replaying .die { transition: none !important; }

.online-status.warn { color: var(--warn); }

/* ------------------------------------------------------- world ranking */
.win-world { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 4px 0 10px; min-height: 0; }
.win-world:empty { display: none; }
.win-world .hint { max-width: 32em; text-align: center; }
.world-msg { font-weight: 700; }
.world-msg.good { color: var(--good); }
.world-msg.bad, .scores-empty.bad { color: var(--bad); }
.scores-tabs { display: flex; gap: 6px; margin: 6px 0 4px; }
.scores-tab { border: 2px solid var(--accent); background: var(--panel); color: var(--panel-ink); padding: 5px 12px; border-radius: 999px; font-weight: 700; }
.scores-tab.active { background: var(--accent); color: var(--accent-ink); }

/* ------------------------------------------------------------ pause */
.pause-overlay { backdrop-filter: blur(6px) grayscale(.4); -webkit-backdrop-filter: blur(6px) grayscale(.4); }
/* In a game, the top bar (with Quit) stays reachable above question, duel and
   other game screens; the quit and pause screens cover everything. */
body.in-game .topbar { z-index: 55; }
#quitOverlay, #pauseOverlay { z-index: 65; }
