:root {
  color-scheme: dark;
  --bg: #0e0e10;
  --surface: #1b1b1f;
  --surface-2: #26262c;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f4f4f6;
  --muted: #9b9ba6;
  --accent: #2f7cf6;
  --accent-2: #ff8a1f;
  --seat-green: #34c759;
  --seat-red: #ff5a64;
  --seat-purple: #b07cff;
  --seat-teal: #2ec8c8;
  --danger: #e5484d;
  --light-core: #fff7cf;
  --light-edge: #e0a400;
  --light-glow: rgba(255, 205, 28, 0.55);
  --pad-wait: #a3192c;
  --pad-go: #12a14a;
  --pad-foul: #8a4b00;
  --num-bg: #2c2c34;
  --asphalt: #2b2b31;
  --asphalt-2: #1d1d22;
  --card-face: #f4f2ea;
  --card-back: #2f5fd0;
  --match: #31c95a;
  --banner-bg: #4a3a12;
  --banner-fg: #ffe08a;

  /* Tile colours, tuned to read like the physical plastic tiles. */
  --white: #f1f1ea;
  --yellow: #ffcd1c;
  --orange: #ff7317;
  --red: #d9233a;
  --green: #12a14a;
  --blue: #1c5fdc;
  --purple: #8a3fd6;

  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Rounded', 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

[hidden] { display: none !important; }

#app { position: absolute; inset: 0; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active { display: flex; }

[data-color='white'] { --c: var(--white); }
[data-color='yellow'] { --c: var(--yellow); }
[data-color='orange'] { --c: var(--orange); }
[data-color='red'] { --c: var(--red); }
[data-color='green'] { --c: var(--green); }
[data-color='blue'] { --c: var(--blue); }
[data-color='purple'] { --c: var(--purple); }

/* ---------- buttons ---------- */
button { font: inherit; color: inherit; }

.btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-2);
  font-size: 17px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 80ms ease, background 120ms ease;
}
.btn small { font-size: 13px; font-weight: 450; color: var(--muted); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: transparent; }
.btn.primary small { color: rgba(255, 255, 255, 0.8); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: transparent; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:active { transform: none; }

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: transparent;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- home ---------- */
.home {
  margin: auto;
  width: min(420px, 100% - 32px);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  /* Scroll when the menu is taller than a small phone screen. */
  max-height: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.home h1 { margin: 18px 0 4px; font-size: 40px; font-weight: 800; letter-spacing: -0.02em; }
.tagline { margin: 0 0 28px; color: var(--muted); }
.menu { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.menu-row { width: 100%; display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.menu-row .btn { width: auto; flex: 1 1 0; }
.menu-row [data-action='join'] { flex-basis: 100%; }
.menu-row .btn:not([data-action='join']) { min-width: 0; padding: 14px 6px; font-size: 16px; }
.menu-row .btn > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-head { margin-bottom: 8px; }
.home-head h1 { margin-top: 8px; }
.home-head .tagline { margin-bottom: 20px; }

/* Game cards on the home screen. */
.game-list { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.game-card {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: transform 80ms ease;
}
.game-card:active { transform: scale(0.98); }
.game-icon { flex: 0 0 auto; width: 64px; height: 64px; }
.game-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.game-name { font-size: 19px; font-weight: 750; }
.game-blurb { font-size: 14px; color: var(--muted); }
.chev { font-size: 28px; color: var(--muted); }

/* Home: Tile Race, then a card for the other games. */
.more-games { margin-top: 16px; gap: 12px; padding: 10px 14px; border-radius: 16px; text-align: left; }
.more-games .game-name { font-size: 16px; }
.more-games .game-blurb { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more-games .chev { font-size: 22px; }
.more-icons { flex: 0 0 auto; width: 42px; height: 42px; display: grid; grid-template-columns: 20px 20px; grid-template-rows: 20px 20px; gap: 2px; }
/* Each icon is drawn at its usual 64 px and scaled down, so it keeps its look. */
.more-icons > div { position: relative; overflow: hidden; }
.more-icons > div > * { position: absolute; top: 0; left: 0; width: 64px; height: 64px; transform: scale(0.3125); transform-origin: top left; }

/* Icons are small live versions of each game's board. */
.game-icon > *, .game-hero > * { width: 100%; height: 100%; }
.game-icon .pattern, .game-hero .pattern {
  padding: 10%;
  border-radius: 22%;
  background: linear-gradient(160deg, #2a2a30, #1a1a1e);
  box-shadow: inset 0 0 0 1px var(--line);
}
.game-hero { flex: 0 0 auto; width: 120px; height: 120px; margin-top: 8px; }
.reaction-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 22%;
  background: linear-gradient(160deg, #1fbf5b, #0d8a3c);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}
.reaction-icon span {
  width: 42%;
  height: 42%;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.25);
}
.install-hint { margin-top: 24px; font-size: 13px; color: var(--muted); }

/* ---------- top bar ---------- */
.topbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 4px 8px;
}
.topbar h2 { margin: 0; font-size: 17px; font-weight: 650; }
.topbar > :last-child { justify-self: end; }
.tally { font-weight: 700; font-variant-numeric: tabular-nums; }
.tally.small { font-size: 14px; color: var(--muted); padding-right: 8px; }

.stage { flex: 1; display: flex; min-height: 0; min-width: 0; position: relative; }

/* ---------- player area ---------- */
.player {
  container-type: size;
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
}

.player-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px;
  --pat: min(26cqw, 22cqh, 150px);
  --board: min(100cqw - 24px, 100cqh - var(--pat) - 40px, 640px);
}

.panel {
  width: var(--board);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.stats { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
/* Each seat has its own colour so players can tell each other apart. */
[data-accent='blue'] { --seat: var(--accent); }
[data-accent='orange'] { --seat: var(--accent-2); }
[data-accent='green'] { --seat: var(--seat-green); }
[data-accent='red'] { --seat: var(--seat-red); }
[data-accent='purple'] { --seat: var(--seat-purple); }
[data-accent='teal'] { --seat: var(--seat-teal); }
.name { font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--seat, var(--accent)); }
.timer {
  font-size: clamp(22px, 7cqmin, 44px);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.sub { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.goal:empty { display: none; }

.board-wrap { width: var(--board); height: var(--board); flex: 0 0 auto; }
.board { width: 100%; height: 100%; }

/* Games without a goal box (Lights Out, Reaction Duel) give that space to the board. */
.no-goal .player-inner { --pat: 64px; }
.no-goal .panel { justify-content: center; }
.no-goal .stats { align-items: center; }

/* Wide areas (iPad landscape, two players on an iPad): scrambler beside the tray. */
@container (min-aspect-ratio: 5/4) {
  .player-inner {
    flex-direction: row;
    gap: 24px;
    --pat: min(30cqh, 22cqw, 170px);
    --board: min(100cqh - 24px, 100cqw - var(--pat) - 72px, 700px);
  }
  .panel { width: auto; flex-direction: column; justify-content: center; gap: 20px; }
  .stats { align-items: center; }
  .no-goal .player-inner { --pat: 120px; }
}

/* ---------- Lights Out ---------- */
.lights {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 2.4%;
  padding: 3.4%;
  border-radius: 5%;
  background: linear-gradient(160deg, #222226, #141417);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55), inset 0 0 0 1px var(--line);
  touch-action: none;
}
.light {
  border-radius: 22%;
  background: #1c1c21;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.7), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  transition: background 110ms ease, box-shadow 160ms ease;
  cursor: pointer;
}
.light.on {
  background: radial-gradient(circle at 50% 38%, var(--light-core), var(--yellow) 58%, var(--light-edge));
  box-shadow: 0 0 22px var(--light-glow), inset 0 -3px 0 rgba(0, 0, 0, 0.16);
}
.lights.mini { gap: 4%; padding: 5%; box-shadow: inset 0 0 0 1px var(--line); }
.lights.mini .light { box-shadow: none; transition-duration: 60ms; }
.lights.mini .light.on { box-shadow: 0 0 6px var(--light-glow); }
.game-icon .lights, .game-hero .lights { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); border-radius: 22%; padding: 12%; gap: 8%; }

/* ---------- Number Rush ---------- */
.rush {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 2.4%;
  padding: 3.4%;
  border-radius: 5%;
  background: linear-gradient(160deg, #222226, #141417);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55), inset 0 0 0 1px var(--line);
  touch-action: none;
}
.num {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border-radius: 22%;
  background: var(--num-bg);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  font-size: clamp(16px, 6.5cqmin, 48px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: opacity 140ms ease, transform 140ms ease;
}
.num.done { opacity: 0.16; transform: scale(0.88); }
.num.wrong { animation: miss 280ms ease; }
@keyframes miss {
  0%, 100% { transform: none; background: var(--danger); }
  25% { transform: translateX(-6%); }
  75% { transform: translateX(6%); }
}
/* Numbers stay hidden until the countdown ends. */
.rush.covered .num span { visibility: hidden; }
.rush.mini { gap: 4%; padding: 5%; box-shadow: inset 0 0 0 1px var(--line); }
.rush.mini .num { font-size: 0; box-shadow: none; }
/* In an opponent's preview, found numbers fill with that player's colour. */
.rush.mini .num.done { opacity: 1; transform: none; background: var(--seat, var(--accent)); }
.game-icon .rush .num.done, .game-hero .rush .num.done { opacity: 0.3; background: var(--num-bg); }
.game-icon .rush, .game-hero .rush { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); border-radius: 22%; padding: 12%; gap: 8%; }
.game-icon .rush .num { font-size: 13px; }
.game-hero .rush .num { font-size: 24px; }

/* ---------- Traffic Jam ---------- */
.lot {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 3.4%;
  border-radius: 5%;
  background: linear-gradient(160deg, var(--asphalt), var(--asphalt-2));
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55), inset 0 0 0 1px var(--line);
  touch-action: none;
}
.lot-grid {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
}
.lot .spot { margin: 7%; border: 1px dashed rgba(255, 255, 255, 0.08); border-radius: 14%; }
/* The gap in the wall the red car drives out of (row 3 of 6). */
.lot-exit {
  position: absolute;
  right: 0;
  top: calc(3.4% + 93.2% * 2 / 6);
  width: 3.4%;
  height: calc(93.2% / 6);
  background: var(--bg);
}
.car {
  position: absolute;
  padding: 0.9%;
  z-index: 1;
  transition: transform 140ms cubic-bezier(0.25, 0.8, 0.35, 1);
  will-change: transform;
  cursor: grab;
}
.car i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: clamp(4px, 2.4cqmin, 14px);
  background-color: var(--car, #9aa0a6);
  background-image: linear-gradient(160deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, 0.15));
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.3), 0 3px 6px rgba(0, 0, 0, 0.5);
}
/* Windscreens: a darker band near the front of each vehicle. */
.car.horiz i { background-image: linear-gradient(90deg, transparent 62%, rgba(0, 0, 0, 0.28) 62% 74%, transparent 74%), linear-gradient(160deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, 0.15)); }
.car.vert i { background-image: linear-gradient(180deg, transparent 26%, rgba(0, 0, 0, 0.28) 26% 38%, transparent 38%), linear-gradient(160deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, 0.15)); }
.car.truck i { border-radius: clamp(3px, 1.4cqmin, 8px); }
.car.hero { z-index: 2; --car: var(--red); }
.car.dragging { transition: none; z-index: 3; cursor: grabbing; }
.car.dragging i { box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.3), 0 8px 18px rgba(0, 0, 0, 0.6); }
.car.leaving { transition: transform 420ms ease-in; }
.lot.covered .car { opacity: 0; }
.lot.mini { padding: 4%; box-shadow: inset 0 0 0 1px var(--line); }
.lot.mini .spot { border: none; }
.lot.mini .car { transition-duration: 90ms; }
.lot.mini .car i { border-radius: 2px; box-shadow: none; }
.lot.mini .lot-exit { width: 4%; }
.icon-lot { border-radius: 22%; }
.icon-lot .lot-exit { top: calc(3.4% + 93.2% / 3); height: calc(93.2% / 3); }

/* ---------- Spot the Match ---------- */
.spot-table { position: relative; width: 100%; height: 100%; touch-action: none; }
.spot-card {
  container-type: inline-size;
  position: absolute;
  width: 56%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--card-face);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55), inset 0 0 0 3px rgba(0, 0, 0, 0.06);
}
.spot-card:first-child { left: 0; top: 0; }
.spot-card:nth-child(2) { right: 0; bottom: 0; }
.sym {
  position: absolute;
  font-size: calc(var(--size) * 15cqw);
  line-height: 1;
  transform: translate(-50%, -50%) rotate(var(--tilt));
  transition: transform 160ms ease, filter 160ms ease;
  cursor: pointer;
}
.sym.hit { transform: translate(-50%, -50%) rotate(0deg) scale(1.3); filter: drop-shadow(0 0 6px var(--match)); }
.spot-count {
  position: absolute;
  right: 4%;
  top: 6%;
  font-size: clamp(16px, 6cqmin, 30px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.spot-table.covered .spot-card {
  background: repeating-linear-gradient(45deg, var(--card-back) 0 10px, color-mix(in srgb, var(--card-back), black 18%) 10px 20px);
}
.spot-table.covered .sym, .spot-table.covered .spot-count { visibility: hidden; }
.spot-table.frozen .spot-card { animation: miss-card 300ms ease; filter: saturate(0.3) brightness(0.8); }
@keyframes miss-card {
  25% { translate: -2% 0; }
  75% { translate: 2% 0; }
}
.spot-mini {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10%;
  border-radius: 50%;
  background: var(--card-face);
  color: #1b1b1f;
}
.spot-mini b { font-size: 15px; font-variant-numeric: tabular-nums; }
.spot-mini .bar { width: 70%; height: 6px; border-radius: 3px; background: rgba(0, 0, 0, 0.12); overflow: hidden; }
.spot-mini .bar i { display: block; height: 100%; background: var(--seat, var(--match)); transition: width 200ms ease; }
.spot-icon {
  display: grid;
  grid-template-columns: 1fr 1fr;
  place-items: center;
  padding: 12%;
  border-radius: 22%;
  background: linear-gradient(160deg, #2a2a30, #1a1a1e);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 22px;
}
.game-hero .spot-icon { font-size: 40px; }
.spot-icon span:first-child, .spot-icon span:nth-child(3) { filter: drop-shadow(0 0 4px var(--match)); }

/* ---------- Reaction Duel ---------- */
.reaction-pad {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  border-radius: 6%;
  background: var(--surface-2);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55), inset 0 0 0 1px var(--line);
  text-align: center;
  touch-action: none;
  cursor: pointer;
}
.pad-label { font-size: clamp(28px, 12cqmin, 84px); font-weight: 850; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.pad-sub { font-size: clamp(14px, 4cqmin, 20px); color: rgba(255, 255, 255, 0.78); }
.reaction-pad[data-phase='wait'] { background: var(--pad-wait); }
.reaction-pad[data-phase='go'] { background: var(--pad-go); }
.reaction-pad[data-phase='foul'] { background: var(--pad-foul); }
.reaction-pad.mini { padding: 4px; gap: 0; border-radius: 12%; box-shadow: inset 0 0 0 1px var(--line); }
.reaction-pad.mini .pad-label { font-size: 15px; font-weight: 750; }
.reaction-pad.mini .pad-sub { display: none; }

/* ---------- scrambler ---------- */
.scrambler {
  width: var(--pat);
  height: var(--pat);
  flex: 0 0 auto;
  padding: 8%;
  border-radius: 18%;
  background: linear-gradient(160deg, #2a2a30, #1a1a1e);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), inset 0 0 0 1px var(--line);
}

.pattern {
  display: grid;
  grid-template-columns: repeat(var(--p, 3), 1fr);
  grid-template-rows: repeat(var(--p, 3), 1fr);
  gap: calc(18% / var(--p, 3));
  width: 100%;
  height: 100%;
}
.die {
  border-radius: 18%;
  background: var(--c, #3a3a42);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  background-image: linear-gradient(160deg, rgba(255, 255, 255, 0.22), transparent 50%);
}
.hidden-pattern .die { background-color: #34343b; }
.pattern.reveal .die { animation: flip 420ms cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
.pattern.reveal .die:nth-child(3n + 2) { animation-delay: 40ms; }
.pattern.reveal .die:nth-child(3n) { animation-delay: 80ms; }

@keyframes flip {
  from { transform: scale(0.4) rotateX(90deg); }
  to { transform: none; }
}

/* ---------- tray ---------- */
.tray {
  width: 100%;
  height: 100%;
  padding: 3.4%;
  border-radius: 5%;
  background: linear-gradient(160deg, #222226, #141417);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55), inset 0 0 0 1px var(--line);
  touch-action: none;
}
.grid { position: relative; width: 100%; height: 100%; }

.well, .tile {
  position: absolute;
  left: 0;
  top: 0;
  /* --n: tiles per side (5, or 6 on the big board) */
  width: calc(100% / var(--n, 5));
  height: calc(100% / var(--n, 5));
  padding: calc(4.5% / var(--n, 5));
}
.well::before {
  content: '';
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 16%;
  background: #09090a;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.8);
}

.tile {
  transition: transform 115ms cubic-bezier(0.25, 0.8, 0.35, 1);
  will-change: transform;
  cursor: pointer;
}
.tile i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 16%;
  background-color: var(--c);
  background-image: linear-gradient(160deg, rgba(255, 255, 255, 0.26), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, 0.12));
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22), inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 2px 4px rgba(0, 0, 0, 0.55);
}
.tile.match i {
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22), inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 0 0 2px rgba(255, 255, 255, 0.85);
}
.no-anim .tile { transition: none; }
.locked .tile { cursor: default; }

/* Outline of the centre 3x3 that has to match. It sits in the gaps between tiles. */
.target-frame {
  position: absolute;
  left: calc(100% / var(--n, 5));
  top: calc(100% / var(--n, 5));
  width: calc(100% * (var(--n, 5) - 2) / var(--n, 5));
  height: calc(100% * (var(--n, 5) - 2) / var(--n, 5));
  margin: -1px;
  border: 2px solid rgba(255, 255, 255, 0.32);
  border-radius: 4%;
  pointer-events: none;
  z-index: 2;
}
.mini .target-frame { border-width: 1px; }
.mini.tray { padding: 4%; box-shadow: inset 0 0 0 1px var(--line); }
.mini .tile { transition-duration: 90ms; }
.mini .tile i { box-shadow: none; }

.player.solved .tray,
.player.solved .lights,
.player.solved .rush { animation: glow 900ms ease-out; }
@keyframes glow {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.9); }
  100% { box-shadow: 0 0 0 28px rgba(255, 255, 255, 0); }
}

/* ---------- overlay (countdown / results) ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 10, 12, 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.overlay.counting { background: rgba(10, 10, 12, 0.3); -webkit-backdrop-filter: none; backdrop-filter: none; }
.overlay-card {
  width: min(340px, 100%);
  padding: 22px 22px 18px;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), inset 0 0 0 1px var(--line);
  text-align: center;
}
.counting .overlay-card { background: none; box-shadow: none; }
.overlay-card h3 { margin: 0 0 8px; font-size: 26px; font-weight: 800; }
.overlay-card p { margin: 4px 0; font-variant-numeric: tabular-nums; }
.result.win h3 { color: var(--yellow); }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.actions-minor { display: flex; justify-content: center; margin-top: 18px; }
.text-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.text-btn:active { background: var(--surface-2); }
.count {
  font-size: min(32cqmin, 180px);
  font-weight: 850;
  text-shadow: 0 6px 30px rgba(0, 0, 0, 0.7);
  animation: pop 650ms ease-out both;
}
@keyframes pop {
  from { transform: scale(1.6); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  to { transform: scale(0.9); opacity: 0.85; }
}

/* ---------- online ---------- */
.net-banner {
  flex: 0 0 auto;
  margin: 0 16px 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--banner-bg);
  color: var(--banner-fg);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}
/* ---------- players who dropped out ---------- */
.roster li.away, .opponent.away { opacity: 0.5; }
.chat-log li.system { align-self: center; background: none; padding: 2px 8px; font-size: 13px; color: var(--muted); }

/* ---------- removing a player ---------- */
.remove-btn { padding: 4px 8px; font-size: 13px; color: var(--danger); }
.remove-btn[data-armed] { font-weight: 700; }

/* ---------- profile ---------- */
.profile-card { display: flex; flex-direction: column; gap: 12px; }
.profile-card > p { margin: 0; }
.profile-card h3 { margin: 12px 2px 0; font-size: 15px; color: var(--muted); font-weight: 650; }
.small-note { font-size: 13px; }
.profile-error { margin: 0; color: var(--danger); font-weight: 600; }
.rename-form { display: flex; gap: 8px; align-items: flex-end; }
.rename-form .field { flex: 1; width: auto; min-width: 0; }
.rename-form .btn { width: auto; padding: 12px 18px; }
.stats-gate { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 24px 8px; text-align: center; }
.stats-gate .btn { width: auto; }

/* ---------- open rooms ---------- */
.open-rooms { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-top: 8px; text-align: left; }
.open-rooms h3 { margin: 0 2px; font-size: 15px; color: var(--muted); font-weight: 650; }
.open-rooms .muted { margin: 0 2px; font-size: 14px; }
.open-rooms .stat-card { display: flex; align-items: center; gap: 12px; }
.open-rooms .room-info { flex: 1; min-width: 0; }
.open-rooms .room-info b { display: block; }
.open-rooms .room-info span { font-size: 14px; color: var(--muted); }
.open-rooms .btn { width: auto; flex: 0 0 auto; padding: 8px 14px; font-size: 15px; border-radius: 12px; }
.room-public { width: 100%; text-align: left; }
.room-public small { color: var(--muted); font-weight: 450; }
.ask-banner {
  flex: 0 0 auto;
  margin: 0 16px 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  font-weight: 650;
}
.ask-actions { display: flex; gap: 8px; }
.ask-actions .btn { width: auto; padding: 8px 16px; font-size: 15px; border-radius: 12px; }

/* ---------- stats ---------- */
.stats-page { flex: 1; min-height: 0; overflow-y: auto; width: min(560px, 100%); margin: 0 auto; padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.stats-body { display: flex; flex-direction: column; gap: 10px; }
.stats-body h3 { margin: 10px 2px 0; font-size: 15px; color: var(--muted); font-weight: 650; }
.stats-note { margin: 24px 8px; text-align: center; color: var(--muted); }
.stat-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.stat-card { padding: 12px 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.stat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.stat-head .muted { font-size: 13px; }
.stat-rows { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; }
.stat-rows li { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; font-variant-numeric: tabular-nums; }
.stat-rows li > :last-child { color: var(--muted); white-space: nowrap; }
.stat-rows li.won { font-weight: 700; }
.stat-rows li.won > :last-child { color: var(--text); }
.rank { display: inline-block; min-width: 1.6em; color: var(--muted); }

/* ---------- room chat ---------- */
.topbar-end { justify-self: end; display: flex; align-items: center; gap: 2px; }
.chat-btn { position: relative; display: grid; place-items: center; }
.chat-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.chat-badge {
  position: absolute;
  top: 4px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
}
.chat-sheet {
  position: fixed;
  inset: 0;
  z-index: 18;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + var(--kb, 0px) + env(safe-area-inset-bottom));
  background: rgb(0 0 0 / 0.35);
}
.chat-card {
  width: min(480px, 100%);
  max-height: min(70dvh, 560px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 14px 12px;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.35);
}
.chat-head { display: flex; align-items: center; justify-content: space-between; }
.chat-head h2 { margin: 0 0 0 4px; font-size: 18px; }
.chat-empty { margin: 4px; }
.chat-log { flex: 1; min-height: 0; overflow-y: auto; margin: 0; padding: 0 2px; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.chat-log:empty { display: none; }
.chat-log li {
  align-self: flex-start;
  max-width: 85%;
  padding: 7px 11px;
  border-radius: 14px;
  background: var(--surface-2);
  overflow-wrap: anywhere;
  font-size: 15px;
}
.chat-log li b { display: block; font-size: 12px; color: var(--seat, var(--muted)); }
.chat-log li.mine { align-self: flex-end; }
.chat-quick { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chip {
  flex: 0 0 auto;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
  cursor: pointer;
}
.chip:active { background: var(--surface-2); }
.chat-form { display: flex; gap: 8px; }
.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 16px; /* 16px or more: iOS doesn't zoom in on focus */
}
.chat-form .btn { width: auto; padding: 10px 16px; font-size: 15px; border-radius: 12px; }
.chat-toast {
  position: fixed;
  z-index: 16;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
  cursor: pointer;
}

/* "A new version is ready" */
.update-banner {
  position: fixed;
  z-index: 15;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
}
.update-banner[hidden] { display: none; }
.update-banner .small-btn { width: auto; justify-content: center; min-height: 36px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.lobby { flex: 1; display: flex; padding: 16px; overflow-y: auto; }
/* Centred while it fits; when taller than the screen it scrolls from its top
   (centring with align-items would cut off both ends). */
.lobby-card {
  margin: auto;
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.lobby-card p { margin: 0; }
.muted { color: var(--muted); }
.version { margin: 0; text-align: center; font-size: 12px; }
.update-check { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 6px; }
.update-status { margin: 0; text-align: center; font-size: 13px; font-weight: 600; }
#check-updates.ready { color: var(--accent); font-size: 15px; }
.room-code { font-size: 64px; font-weight: 850; letter-spacing: 0.18em; padding-left: 0.18em; font-variant-numeric: tabular-nums; }
.join-form { width: 100%; display: flex; gap: 10px; }
.join-form input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 22px;
  font-weight: 750;
  letter-spacing: 0.25em;
  text-align: center;
  text-transform: uppercase;
  -webkit-user-select: text;
  user-select: text;
}
.join-form .btn { width: auto; }

/* The host picks the room's game. */
.game-picker { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 4px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); }
.pick {
  flex: 1;
  min-width: 0;
  padding: 10px 6px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}
.pick[aria-pressed='true'] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.pick:disabled { cursor: default; }
.pick:disabled:not([aria-pressed='true']) { opacity: 0.5; }

.field { width: 100%; display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: 14px; color: var(--muted); }
.field input {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  -webkit-user-select: text;
  user-select: text;
}

.roster { width: 100%; margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.roster li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  text-align: left;
}
.roster li::before { content: ''; flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%; background: var(--seat); }
.roster-name { flex: 1; min-width: 0; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-tag { font-size: 13px; color: var(--muted); }
.roster li.open { background: transparent; border-style: dashed; color: var(--muted); }
.roster li.open::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.spinner-row { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.online-game { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* Opponents: a row of cards above your tray (portrait) or a column beside it (landscape). */
.opponents { flex: 0 0 auto; display: flex; justify-content: center; gap: 10px; padding: 4px 16px 8px; }
.opponent { flex: 0 1 120px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.opp-board { position: relative; width: min(84px, 100%); height: auto; aspect-ratio: 1; flex: 0 0 auto; }
.opp-board > * { position: absolute; inset: 0; width: 100%; height: 100%; }
.opp-info { min-width: 0; max-width: 100%; }
.opp-name {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--seat, var(--accent-2));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.opp-progress { font-size: 13px; font-variant-numeric: tabular-nums; }
.opp-status { font-size: 12px; color: var(--muted); }

/* A single opponent gets a roomier side-by-side card. */
[data-opponents='1'] .opponents { justify-content: flex-start; }
[data-opponents='1'] .opponent { flex: 0 1 auto; flex-direction: row; gap: 14px; text-align: left; }
[data-opponents='1'] .opp-name { font-size: 13px; }
[data-opponents='1'] .opp-progress { font-size: 16px; }
[data-opponents='1'] .opp-status { font-size: 14px; }

@media (min-width: 700px) and (min-height: 700px) {
  .opponent { flex-basis: 150px; }
  .opp-board { width: min(120px, 100%); }
}

@media (orientation: landscape) {
  .online-game { flex-direction: row; }
  .opponents { flex-direction: column; justify-content: center; width: 250px; padding: 12px 8px 12px 16px; }
  .opponent,
  [data-opponents='1'] .opponent { flex: 0 0 auto; flex-direction: row; gap: 10px; text-align: left; }
  .opp-board { width: min(96px, calc((100vh - 140px) / 3)); }
  [data-opponents='1'] .opponent { flex-direction: column; text-align: center; }
  [data-opponents='1'] .opp-board { width: min(150px, 40vh); }
}

/* Four or five opponents: smaller cards in one row on a phone, and a
   two-column grid beside the tray in landscape. */
:is([data-opponents='4'], [data-opponents='5']) .opponents { gap: 6px; padding-inline: 10px; }
:is([data-opponents='4'], [data-opponents='5']) .opponent { flex-basis: 76px; gap: 4px; }
:is([data-opponents='4'], [data-opponents='5']) .opp-board { width: min(64px, 100%); }
:is([data-opponents='4'], [data-opponents='5']) .opp-name { font-size: 10.5px; letter-spacing: 0.02em; }
:is([data-opponents='4'], [data-opponents='5']) .opp-progress { font-size: 11px; line-height: 1.25; }
:is([data-opponents='4'], [data-opponents='5']) .opp-status { font-size: 10.5px; }
@media (min-width: 700px) and (min-height: 700px) {
  :is([data-opponents='4'], [data-opponents='5']) .opponent { flex-basis: 140px; }
  :is([data-opponents='4'], [data-opponents='5']) .opp-board { width: min(104px, 100%); }
  :is([data-opponents='4'], [data-opponents='5']) .opp-progress { font-size: 13px; }
}
@media (orientation: portrait) and (max-width: 699px) {
  /* The status line would make the strip too tall on a phone. */
  :is([data-opponents='4'], [data-opponents='5']) .opp-status { display: none; }
}
@media (orientation: landscape) {
  :is([data-opponents='4'], [data-opponents='5']) .opponents {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-content: center;
    width: 360px;
    gap: 10px 8px;
  }
  :is([data-opponents='4'], [data-opponents='5']) .opponent { flex-direction: row; gap: 8px; text-align: left; }
  :is([data-opponents='4'], [data-opponents='5']) .opp-board { width: min(80px, calc((100vh - 120px) / 3 - 10px)); }
}
@media (orientation: landscape) and (min-width: 1000px) {
  :is([data-opponents='4'], [data-opponents='5']) .opponents { width: 460px; }
}

/* ---------- modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.6);
}
.modal-card {
  width: min(440px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 22px;
  border-radius: 22px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card h2 { margin: 0; }
.confirm-card { width: min(360px, 100%); text-align: center; }
.confirm-card .actions { margin-top: 4px; }
.modal-card ol { margin: 0; padding-left: 20px; line-height: 1.5; }
.modal-card li + li { margin-top: 6px; }
.modal-card p { margin: 0; line-height: 1.45; }

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.setting small { color: var(--muted); }
.setting input {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  background: #3a3a42;
  position: relative;
  transition: background 150ms;
}
.setting input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  transition: transform 150ms;
}
.setting input:checked { background: #31c95a; }
.setting input:checked::after { transform: translateX(20px); }

/* Offscreen native switch used to trigger iOS haptics. */
.haptic-switch { position: fixed; left: -200px; top: 0; opacity: 0; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  .tile { transition-duration: 60ms; }
  .pattern.reveal .die, .count, .player.solved .tray, .player.solved .lights, .player.solved .rush, .num.wrong, .spot-table.frozen .spot-card { animation: none; }
  .car, .sym { transition-duration: 60ms; }
}

/* Tile Golf's icon: the pattern with a flag in the corner. */
.game-icon, .game-hero, .more-icons > div { position: relative; }
.game-icon > .icon-badge, .game-hero > .icon-badge, .more-icons > div > .icon-badge {
  position: absolute;
  right: -4%;
  bottom: -4%;
  left: auto;
  top: auto;
  width: auto;
  height: auto;
  transform: none;
  font-size: 2.2em;
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}

/* ---------- tile styles (Settings → Tile style) ---------- */
/* A symbol on each tile and scrambler die, as well as its colour: easier to
   tell apart (and for colour-blind players), and fun. */
.skin-setting { flex-direction: column; align-items: stretch; }
.skin-setting .game-picker { margin-top: 2px; }
:root:not([data-skin='colors']) .tile i,
:root:not([data-skin='colors']) .die { display: grid; place-items: center; container-type: size; }
.tile i::after, .die::after {
  content: var(--sym, none);
  font-size: 62cqmin;
  line-height: 1;
  font-weight: 800;
  color: rgba(0, 0, 0, 0.5);
}
:root[data-skin='colors'] .tile i::after, :root[data-skin='colors'] .die::after { content: none; }
.hidden-pattern .die::after { content: none; }
/* Pale backgrounds for the picture styles, so each picture stands out. */
:root:is([data-skin='fruit'], [data-skin='animals']) .tile i,
:root:is([data-skin='fruit'], [data-skin='animals']) .die:not(.hidden-pattern .die) {
  background-color: color-mix(in srgb, var(--c) 45%, #fff);
}
:root:is([data-skin='fruit'], [data-skin='animals']) .tile i::after,
:root:is([data-skin='fruit'], [data-skin='animals']) .die::after { font-size: 70cqmin; font-weight: 400; color: initial; }

[data-skin='shapes'] [data-color='white'] { --sym: '\271A'; }
[data-skin='shapes'] [data-color='yellow'] { --sym: '\2605'; }
[data-skin='shapes'] [data-color='orange'] { --sym: '\25B2'; }
[data-skin='shapes'] [data-color='red'] { --sym: '\2665\FE0E'; }
[data-skin='shapes'] [data-color='green'] { --sym: '\2663\FE0E'; }
[data-skin='shapes'] [data-color='blue'] { --sym: '\25CF'; }
[data-skin='shapes'] [data-color='purple'] { --sym: '\25A0'; }
[data-skin='shapes'] [data-color='blue'], [data-skin='shapes'] [data-color='purple'], [data-skin='shapes'] [data-color='red'], [data-skin='shapes'] [data-color='green'] { --ink: rgba(255, 255, 255, 0.8); }

[data-skin='fruit'] [data-color='white'] { --sym: '🥥'; }
[data-skin='fruit'] [data-color='yellow'] { --sym: '🍋'; }
[data-skin='fruit'] [data-color='orange'] { --sym: '🍊'; }
[data-skin='fruit'] [data-color='red'] { --sym: '🍓'; }
[data-skin='fruit'] [data-color='green'] { --sym: '🥝'; }
[data-skin='fruit'] [data-color='blue'] { --sym: '🫐'; }
[data-skin='fruit'] [data-color='purple'] { --sym: '🍇'; }

[data-skin='animals'] [data-color='white'] { --sym: '🐑'; }
[data-skin='animals'] [data-color='yellow'] { --sym: '🐥'; }
[data-skin='animals'] [data-color='orange'] { --sym: '🦊'; }
[data-skin='animals'] [data-color='red'] { --sym: '🦀'; }
[data-skin='animals'] [data-color='green'] { --sym: '🐸'; }
[data-skin='animals'] [data-color='blue'] { --sym: '🐳'; }
[data-skin='animals'] [data-color='purple'] { --sym: '🐙'; }

[data-skin='numbers'] [data-color='white'] { --sym: '1'; }
[data-skin='numbers'] [data-color='yellow'] { --sym: '2'; }
[data-skin='numbers'] [data-color='orange'] { --sym: '3'; }
[data-skin='numbers'] [data-color='red'] { --sym: '4'; }
[data-skin='numbers'] [data-color='green'] { --sym: '5'; }
[data-skin='numbers'] [data-color='blue'] { --sym: '6'; }
[data-skin='numbers'] [data-color='purple'] { --sym: '7'; }
[data-skin='numbers'] :is([data-color='blue'], [data-color='purple'], [data-color='red'], [data-color='green']) { --ink: rgba(255, 255, 255, 0.85); }
.tile i::after, .die::after { color: var(--ink, rgba(0, 0, 0, 0.5)); }

/* ---------- tournament ---------- */
.tourney-row { width: 100%; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.tourney-row small { color: var(--muted); }
.game-picker.compact { grid-template-columns: repeat(5, 1fr); }
.overlay-card p.standing { margin: 2px 0; text-align: left; font-variant-numeric: tabular-nums; }
.overlay-card p.standing.me { font-weight: 700; }

/* The waiting room fits more on a phone: a smaller code, tighter rows, and
   Start stays on screen at the bottom while the rest scrolls. */
[data-step='room'] { gap: 10px; }
[data-step='room'] .room-code { font-size: 48px; line-height: 1; }
[data-step='room'] .roster li { padding-block: 8px; }
[data-step='room'] .pick { padding-block: 7px; }
#start-btn {
  position: sticky;
  bottom: 0;
  z-index: 1;
  /* A solid edge of the page's colour around it (the room's padding below it too), fading out above. */
  box-shadow: 0 0 0 16px var(--bg), 0 -24px 16px 8px var(--bg);
}

/* The room's More games button spans the picker's last row. */
.more-games-pick { grid-column: 1 / -1; }

/* Race a bot: the levels. */
.bot-card .btn small { font-weight: 450; }

/* ---------- achievements ---------- */
.achievements h3 small { font-size: 13px; font-weight: 500; margin-left: 6px; }
.badge-grid { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.badge {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
}
.badge-icon { grid-row: 1 / 3; font-size: 26px; line-height: 1; }
.badge b { font-size: 14px; }
.badge small { font-size: 12px; color: var(--muted); line-height: 1.25; }
.badge:not(.got) { opacity: 0.45; }
.badge:not(.got) .badge-icon { filter: grayscale(1); }
.badge.got { background: var(--surface-2); }
.achievement-toast {
  position: fixed;
  z-index: 17;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 14px;
  background: linear-gradient(135deg, #3a2f0b, #2a2a30);
  border: 1px solid rgba(255, 205, 28, 0.55);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.35);
  pointer-events: none;
  animation: pop-in 220ms cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
@keyframes pop-in { from { transform: translateX(-50%) scale(0.8); opacity: 0; } }
