/* Shared component styles for the navy toy look (ADR 0006,
   docs/design/look-and-feel.md). This file uses only variables from theme.css:
   it never defines a colour, a font or a duration. Phone first: the base rules
   are the phone, and wider screens add rules in media queries. Animations use
   only transform and opacity, and stop under prefers-reduced-motion. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --page-pad: 8px;
  --gap-board: 3px;
  --board-pad: 10px; /* the board's inner padding, which the column glow follows */
  --frame: 4px; /* the board's frame thickness (--outline-thick) */
  --ghost-size: 34px;
  --board-width: 100%;
}

/* A little less page padding at 320px, so each of the seven columns is at least 44px wide (U15). */
@media (max-width: 359px) {
  :root {
    --page-pad: 6px;
  }
}

html {
  background: var(--ground-top);
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  font: 16px/1.4 var(--font-body);
  color: var(--text);
  background: linear-gradient(180deg, var(--ground-top), var(--ground-bottom)) fixed;
  padding: env(safe-area-inset-top) max(var(--page-pad), env(safe-area-inset-right)) env(safe-area-inset-bottom)
    max(var(--page-pad), env(safe-area-inset-left));
  overflow-x: hidden;
}

a {
  color: var(--link);
}

/* Text links are tap targets too: at least 44 px tall. */
a:not(.btn):not(.round-item) {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  min-width: 44px;
}

/* U9a, U51a: the general fallback focus ring, for anything not covered by its own rule below
   (a field, a button, a round icon button, a tab and the popup close button each carry their own,
   consistent focus state instead: one border that turns yellow, with a glow, never a second ring). */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.round-item:focus-visible {
  outline: none;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.arena {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 0 24px;
}

h2,
h3 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 18px 0 8px;
}

/* ---- The header bar (docs/design/qa-checklist.md Q12, U131): Home on the left of every screen but home ---- */

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: 0 auto 16px; /* Q4: 16px to the first card under it */
  min-height: 52px;
}

.topbar-home {
  min-height: 44px;
  padding: 0 14px;
  gap: 6px;
  font-size: 1rem;
}

.topbar-home .icon {
  width: 20px;
  height: 20px;
}

.topbar-title,
.topbar-right {
  margin: 0;
  font: 700 1rem/1.2 var(--font-display);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-title {
  text-align: center;
}

.topbar-right {
  text-align: right;
  min-width: 0;
}

/* Something on the right as wide as Home keeps the middle line centred on the page. */
.topbar-right:empty {
  visibility: hidden;
}

/* ---- Bubbles (U3): disc-shaped, faint, rising behind everything ---- */

.bubbles {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bubble {
  position: absolute;
  bottom: -90px;
  left: var(--x);
  width: var(--size);
  height: var(--size);
  border-radius: var(--radius-pill);
  border: var(--outline-bubble);
  animation: rise var(--time) linear var(--delay) infinite;
  will-change: transform;
}

.bubble[data-colour="red"] {
  background: var(--bubble-red);
}

.bubble[data-colour="yellow"] {
  background: var(--bubble-yellow);
}

.bubble[data-colour="blue"] {
  background: var(--bubble-blue);
}

/* Some bubbles carry a ring, some a cross, like the discs they imitate. */
.bubble[data-mark="ring"]::after {
  content: "";
  position: absolute;
  inset: 26%;
  border-radius: var(--radius-pill);
  border: var(--outline-bubble-marker);
}

.bubble[data-mark="cross"]::before,
.bubble[data-mark="cross"]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 24%;
  width: 52%;
  height: 3px;
  margin-top: -1.5px;
  background: var(--bubble-rim);
}

.bubble[data-mark="cross"]::before {
  transform: rotate(45deg);
}

.bubble[data-mark="cross"]::after {
  transform: rotate(-45deg);
}

@keyframes rise {
  0% {
    transform: translateY(0) translateX(0);
  }
  50% {
    transform: translateY(-60vh) translateX(14px);
  }
  100% {
    transform: translateY(calc(-100vh - 180px)) translateX(-10px);
  }
}

/* ---- Title (U5): cracked yellow letters, a red hard shadow, falling chips ---- */

.title {
  position: relative;
  display: block;
  width: fit-content;
  margin: 12px auto 6px;
  padding: 0 0.1em;
  text-align: center;
  font: 700 clamp(44px, 16vw, 76px) / 1 var(--font-display);
  letter-spacing: 0.04em;
  isolation: isolate;
}

.title-shadow,
.title-fill {
  display: block;
}

.title-shadow {
  position: absolute;
  inset: 0;
  z-index: -1;
  color: var(--ink);
  -webkit-text-stroke: 0.18em var(--ink);
  text-shadow: var(--shadow-title);
  transform: translate(0.04em, 0.05em);
}

.title-fill {
  color: var(--yellow);
  -webkit-text-stroke: 0.05em var(--ink);
  paint-order: stroke fill;
}

/* Cracks: jagged ink lines across the letters. */
.title-cracks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  stroke: var(--ink);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* Chips: small yellow bits that fall away from the cracks, in a loop. */
.chip {
  position: absolute;
  top: 40%;
  left: var(--x);
  width: 0.13em;
  height: 0.13em;
  background: var(--yellow);
  border: var(--outline-thin);
  border-radius: var(--radius-chip);
  animation: chip-fall var(--dur-chip) ease-in calc(var(--dur-chip-stagger) * var(--i, 0)) infinite;
  font-size: clamp(44px, 16vw, 76px);
}

.chip[data-i="1"] { --i: 1; }
.chip[data-i="2"] { --i: 2; }
.chip[data-i="3"] { --i: 3; }
.chip[data-i="4"] { --i: 4; }

@keyframes chip-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    transform: translateY(var(--chip-fall)) rotate(200deg);
    opacity: 0;
  }
}

.tagline {
  text-align: center;
  color: var(--text-muted);
  margin: 0 0 12px;
}

/* ---- Buttons (U8, U9): flat, outlined, hard shadow, sink when pressed ---- */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  min-width: 44px;
  padding: 0 20px;
  border: var(--outline);
  border-radius: var(--radius-button);
  font: 700 1.1rem/1 var(--font-display);
  letter-spacing: 0.02em;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform var(--dur-press) ease, box-shadow var(--dur-press) ease;
  -webkit-tap-highlight-color: transparent;
}

/* U9a: a button's border turns yellow on keyboard focus only (:focus-visible, never on tap or click), at the same width,
   with the same soft glow as a focused field. This replaces the generic outline for buttons, so the border and the hard
   shadow keep lining up on every side. Covers every outlined button shape: the main buttons, round icon buttons and the
   leaderboard tabs. */
.btn:focus-visible,
.round-item:focus-visible .round,
.tab:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: var(--shadow), var(--glow-focus);
}

/* .icon-only (the nickname pencil, the power-up info buttons) carries no hard shadow at rest, so its focus state adds
   only the border colour and the glow, never a shadow that was not there before (U9a). */
.icon-only:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: var(--glow-focus);
}

/* The popup close button is a plain icon (U85a): on keyboard focus only, a yellow ring shows around the icon. */
.dialog-close:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -8px;
  border-radius: var(--radius-pill);
}

/* A yellow button's own fill is the same colour as --focus, so a yellow border alone would vanish into it: its
   focus state keeps the yellow fill but adds a dark ink ring instead, so the state is still visible (U9a). */
.btn-yellow:focus-visible,
.tab[aria-selected="true"]:focus-visible {
  border-color: var(--ink);
  box-shadow: var(--shadow), var(--glow-focus-dark);
}

.btn-red {
  background: var(--red);
  color: var(--text);
}

.btn-blue {
  background: var(--blue);
  color: var(--text);
}

.btn-yellow {
  background: var(--yellow);
  color: var(--ink);
}

@media (hover: hover) {
  .btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-raised);
  }
}

.btn:active:not(:disabled) {
  transform: translateY(5px);
  box-shadow: var(--shadow-pressed);
}

/* Disabled looks "off" without being see-through, so a bubble never shows through it
   and its label keeps its contrast (disabled text on the disabled fill is 5.94:1). */
.btn:disabled {
  background: var(--disabled);
  color: var(--disabled-text);
  box-shadow: var(--shadow-small);
  cursor: not-allowed;
}

.btn .icon {
  width: 24px;
  height: 24px;
  flex: none;
}

.btn-block {
  display: flex;
  width: 100%;
}

.stack {
  display: grid;
  gap: 16px;
  margin: 12px auto 20px;
  max-width: var(--stack-width);
}

/* Small round icon buttons use the same outline, shadow and press behaviour. */
.round-row {
  display: grid;
  /* Five buttons fit one row from 380px wide. Narrower, they wrap three and two, never four and one (U34, U76). */
  grid-template-columns: repeat(6, minmax(0, 1fr));
  justify-items: center;
  gap: 12px 8px;
  max-width: var(--stack-width);
  margin: 8px auto 16px;
}

/* Six columns, each button across two: three on a row, and the last two sit centred under them (3 and 2). */
.round-row > * {
  grid-column: span 2;
}

.round-row > :nth-child(4) {
  grid-column: 2 / span 2;
}

.round-row > :nth-child(5) {
  grid-column: 4 / span 2;
}

@media (min-width: 380px) {
  .round-row {
    grid-template-columns: repeat(5, minmax(64px, 1fr));
  }

  .round-row > *,
  .round-row > :nth-child(4),
  .round-row > :nth-child(5) {
    grid-column: auto;
  }
}

.round-item {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-width: 64px;
  min-height: 44px;
  font: 700 0.8rem/1.1 var(--font-display);
  color: var(--text);
  text-decoration: none;
}

button.round-item {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.round {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: var(--outline);
  border-radius: var(--radius-pill);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform var(--dur-press) ease, box-shadow var(--dur-press) ease;
}

.round .icon {
  width: 28px;
  height: 28px;
}

.round-item:active .round {
  transform: translateY(5px);
  box-shadow: var(--shadow-pressed);
}

/* ---- Panels (U6) and players ---- */

.panel {
  background: var(--panel);
  border: var(--outline);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow);
  padding: 12px;
}

.players {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 4px;
  margin: 8px 0;
}

.player {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 8px;
  background: var(--panel);
  border: var(--outline);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow);
}

.avatar {
  width: 44px;
  height: 44px;
  border: var(--outline);
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: var(--panel);
  flex: none;
}

.avatar svg {
  display: block;
  width: 100%;
  height: 100%;
}

.avatar .ink {
  fill: var(--ink);
}

.player-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.player-name {
  display: block;
  font: 700 0.95rem/1.2 var(--font-display);
  overflow-wrap: anywhere; /* a long nickname wraps instead of being cut to "May..." */
}

/* "Guest" or "Logged in" under the nickname on the home card (not a nickname tag, R31). */
.player-status {
  color: var(--text-muted);
}

.player-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.mini-disc {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: var(--outline-thin);
  border-radius: var(--radius-pill);
  position: relative;
  flex: none;
}

.shield-state {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.shield-state svg {
  width: 16px;
  height: 16px;
  fill: var(--shield-on);
}

.shield-state[data-shield="used"] svg {
  fill: var(--shield-off);
}

/* A used shield is struck through, like a used Earthquake, so it differs by shape as well as colour (U105). */
.shield-state {
  position: relative;
}

.shield-state[data-shield="used"]::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  border-top: 3px solid var(--ink);
  transform: rotate(-35deg);
}

.shield-state[data-shield="glow"] svg {
  filter: drop-shadow(0 0 6px var(--shield-on));
}

.vs {
  position: relative;
  z-index: 1;
  padding: 6px 12px;
  font: 700 1rem/1 var(--font-display);
  color: var(--ink);
  background: var(--yellow);
  border: var(--outline);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-small);
  transform: rotate(-4deg);
}

/* ---- Board (U7): the blue toy board with a frame and feet ---- */

.board-wrap {
  position: relative;
  width: 100%;
  margin: 8px 0 26px;
  /* The countdown overshoots its size and confetti falls past the edge: clip
     sideways so neither can make the page scroll. */
  overflow-x: clip;
  padding-bottom: 20px;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--gap-board);
  padding: var(--board-pad);
  background: var(--blue);
  border: var(--outline-thick);
  border-radius: var(--radius-board);
  box-shadow: inset 0 8px 0 var(--board-shine), inset 0 -8px 0 var(--board-edge), var(--shadow);
  overflow: hidden; /* a falling disc starts out of sight above the frame */
}

/* Two feet under the bottom corners, like the toy stand. */
.board-wrap::before,
.board-wrap::after {
  content: "";
  position: absolute;
  bottom: 2px;
  width: 18%;
  height: 26px;
  background: var(--board-edge);
  border: var(--outline);
  border-radius: var(--radius-foot);
  z-index: 0;
}

.board {
  z-index: 1;
}

.board-wrap::before {
  left: 8%;
}

.board-wrap::after {
  right: 8%;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-pill);
  background: var(--hole);
  border: var(--outline-thin);
}

/* Rock (U71): a closed row. Solid and square-cornered, with crack lines and no hatch, so it
   is never mistaken for rubble, which is a round hatched piece in a hole. It belongs to nobody. */
.cell[data-closed="true"] {
  background:
    linear-gradient(135deg, transparent 0 46%, var(--ink) 46% 52%, transparent 52% 100%),
    linear-gradient(45deg, transparent 0 62%, var(--ink) 62% 67%, transparent 67% 100%),
    var(--rock);
  border: var(--outline);
  border-radius: var(--radius-rock);
  box-shadow: inset 0 -6px 0 var(--rock-dark);
}

/* A cell about to close flashes a crack pattern (U69). Under reduced motion the pattern shows and does not pulse. */
.cell[data-doomed="true"] {
  background:
    linear-gradient(135deg, transparent 0 46%, var(--timer-warn) 46% 54%, transparent 54% 100%),
    linear-gradient(45deg, transparent 0 62%, var(--timer-warn) 62% 68%, transparent 68% 100%),
    var(--hole);
  animation: doomed var(--dur-doomed) ease-in-out infinite;
}

.cell.cracking {
  animation: doomed calc(var(--dur-collapse) / 2) linear 2;
}

@keyframes doomed {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

/* A disc or a rubble block sits inside its hole. */
.piece {
  position: absolute;
  inset: -2px;
  border: var(--outline-thin);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-small);
}

/* A disc's colour and marker follow its seat's colour (R93, R94, U134): red with a ring, yellow with a cross, the same on every
   screen. A piece with no colour (the home demo, the tutorial) is red with a ring for "you" and yellow with a cross for the
   opponent, the practice look. */
.piece[data-colour="red"],
.piece[data-piece="you"]:not([data-colour]) {
  background: var(--red);
}

.piece[data-colour="yellow"],
.piece[data-piece="opponent"]:not([data-colour]) {
  background: var(--yellow);
}

.piece[data-piece="rubble"] {
  background: repeating-linear-gradient(45deg, var(--rubble) 0 5px, var(--rubble-hatch) 5px 10px);
}

.piece.recent[data-colour="red"],
.piece.recent[data-piece="you"]:not([data-colour]) {
  box-shadow: var(--shadow-small), 0 0 14px 3px var(--disc-glow-red);
}

.piece.recent[data-colour="yellow"],
.piece.recent[data-piece="opponent"]:not([data-colour]) {
  box-shadow: var(--shadow-small), 0 0 14px 3px var(--disc-glow-yellow);
}

.piece.win {
  box-shadow: var(--shadow-small), 0 0 18px 6px var(--win-glow);
  z-index: 1;
}

/* Markers: a ring on red discs, a cross on yellow ones, so colour is never the only difference. */
.piece[data-colour="red"]::after,
.piece[data-piece="you"]:not([data-colour])::after,
.mini-disc[data-colour="red"]::after,
.mini-disc[data-piece="you"]:not([data-colour])::after {
  content: "";
  position: absolute;
  inset: 26%;
  border-radius: var(--radius-pill);
  border: var(--outline-marker);
}

.mini-disc[data-colour="red"]::after,
.mini-disc[data-piece="you"]:not([data-colour])::after {
  inset: 2px;
  border: var(--outline-marker-small);
}

.piece[data-colour="yellow"]::before,
.piece[data-colour="yellow"]::after,
.piece[data-piece="opponent"]:not([data-colour])::before,
.piece[data-piece="opponent"]:not([data-colour])::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 24%;
  width: 52%;
  height: 3px;
  margin-top: -1.5px;
  background: var(--marker-yellow);
  border-radius: var(--radius-chip);
}

.piece[data-colour="yellow"]::before,
.piece[data-piece="opponent"]:not([data-colour])::before,
.mini-disc[data-colour="yellow"]::before,
.mini-disc[data-piece="opponent"]:not([data-colour])::before {
  transform: rotate(45deg);
}

.piece[data-colour="yellow"]::after,
.piece[data-piece="opponent"]:not([data-colour])::after,
.mini-disc[data-colour="yellow"]::after,
.mini-disc[data-piece="opponent"]:not([data-colour])::after {
  transform: rotate(-45deg);
}

.mini-disc[data-colour="red"],
.mini-disc[data-piece="you"]:not([data-colour]) {
  background: var(--red);
}

.mini-disc[data-colour="yellow"],
.mini-disc[data-piece="opponent"]:not([data-colour]) {
  background: var(--yellow);
}

.mini-disc[data-colour="yellow"]::before,
.mini-disc[data-colour="yellow"]::after,
.mini-disc[data-piece="opponent"]:not([data-colour])::before,
.mini-disc[data-piece="opponent"]:not([data-colour])::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  right: 2px;
  height: 2px;
  margin-top: -1px;
  background: var(--marker-yellow);
}

.mini-disc[data-piece="rubble"] {
  background: repeating-linear-gradient(45deg, var(--rubble) 0 3px, var(--rubble-hatch) 3px 6px);
}

/* ---- The reveal: discs drop at once, with no countdown (U19) ---- */

.result {
  min-height: 2.8em;
  margin: 4px 0;
  text-align: center;
  font: 700 1.05rem/1.3 var(--font-display);
}

.confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 4;
}

.confetti i {
  position: absolute;
  top: -12px;
  left: var(--x);
  width: 12px;
  height: 12px;
  border: var(--outline-thin);
  border-radius: var(--radius-pill);
  animation: confetti-fall var(--dur-confetti) ease-in var(--delay) both;
}

.confetti i:nth-child(4n + 1) {
  background: var(--confetti-1);
}

.confetti i:nth-child(4n + 2) {
  background: var(--confetti-2);
}

.confetti i:nth-child(4n + 3) {
  background: var(--confetti-3);
}

.confetti i:nth-child(4n) {
  background: var(--confetti-4);
}

.dropping {
  animation: drop-in var(--dur-drop) cubic-bezier(0.3, 0, 0.7, 1) both;
}

.thud {
  animation: thud var(--dur-drop) ease-in both;
}

.shake {
  animation: shake var(--dur-shake) linear both;
}

/* The earthquake (U65): the board shakes, the bottom row crumbles, the columns slide down one row. */
.quake-shake {
  animation: shake var(--dur-quake-shake) linear both;
}

.crumble {
  animation: crumble var(--dur-quake-crumble) ease-in both;
}

.sliding {
  animation: slide-in var(--dur-quake-slide) ease-in both;
}

.win {
  animation: win-pulse var(--dur-win-pulse) ease-in-out 3;
}

@keyframes pop {
  0% {
    transform: scale(0.4);
  }
  35% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

/* Falls from above the board (--fall rows up), lands and bounces. */
@keyframes drop-in {
  0% {
    transform: translateY(calc(var(--fall, 6) * -112%));
  }
  62% {
    transform: translateY(0);
  }
  76% {
    transform: translateY(-14%);
  }
  88% {
    transform: translateY(0);
  }
  94% {
    transform: translateY(-4%);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes thud {
  0% {
    transform: translateY(calc(var(--fall, 6) * -112%));
  }
  70% {
    transform: translateY(0) scale(1.12, 0.86);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-4px);
  }
  40% {
    transform: translateX(4px);
  }
  60% {
    transform: translateX(-3px);
  }
  80% {
    transform: translateX(3px);
  }
}

@keyframes crumble {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateY(40%) scale(0.5) rotate(25deg);
    opacity: 0;
  }
}

@keyframes slide-in {
  0% {
    transform: translateY(-112%);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes win-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.12);
  }
}

@keyframes confetti-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(520px) rotate(540deg);
    opacity: 0;
  }
}

/* Under reduced motion nothing moves (U30): bubbles and chips stay where they
   are, discs appear in place, and there is no drop, shake, pulse or confetti. */
@media (prefers-reduced-motion: reduce) {
  .cell[data-doomed="true"],
  .cell.cracking,
  .dropping,
  .thud,
  .shake,
  .quake-shake,
  .crumble,
  .sliding,
  .win,
  .btn,
  .round {
    animation: none;
    transition: none;
  }

  .bubble {
    animation: none;
    bottom: auto;
    top: var(--rest);
  }

  .spinner,
  .ghost,
  .get-ready,
  .popup-card {
    animation: none;
  }

  .chip {
    animation: none;
    /* The still picture rests where a falling chip ends (--chip-fall), inside the title's own box (U5a), never on the line below. */
    transform: translateY(var(--chip-fall)) rotate(60deg);
    opacity: 1;
  }

  .confetti {
    display: none;
  }
}

/* ---- Key of pieces and leaderboard rows ---- */

.key {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 8px 0;
  padding: 0;
  list-style: none;
}

.key li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
}

.rows {
  width: 100%;
  max-width: var(--list-width);
  display: grid;
  gap: 10px;
  margin: 8px auto;
  padding: 0;
  list-style: none;
}

.row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border: var(--outline);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow);
}

.row-rank {
  min-width: 1.6em;
  text-align: center;
  font: 700 1.1rem/1 var(--font-display);
}

.row-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.row-value {
  font: 700 1.1rem/1 var(--font-display);
}

.note {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---- Forms and messages (U51) ---- */

label {
  display: block;
  margin: 6px 0 4px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  font: 1rem/1.2 var(--font-body);
  color: var(--text);
  background: var(--field);
  border: var(--outline);
  border-radius: var(--radius-button);
}

/* U51a: one border only. Focused, it turns yellow at the same width and radius, with no glow, no outline and no box-shadow
   (the glow blended into a muddy ring), so nothing moves. Unfocused fields have no shadow either. */
input {
  box-shadow: none;
}

input:focus {
  border-color: var(--focus);
  outline: none;
  box-shadow: none;
}

.form {
  display: grid;
  gap: 8px;
  margin: 8px auto 16px;
  max-width: var(--list-width);
}

.message {
  min-height: 1.4em;
  margin: 6px 0;
  font-weight: 700;
}

.message[data-kind="error"] {
  color: var(--error);
}

.message[data-kind="ok"] {
  color: var(--ok);
}

.narrow {
  max-width: var(--stack-width);
}

.link-button {
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  background: none;
  border: 0;
  font: 700 1rem/1 var(--font-display);
  color: var(--link);
  text-decoration: underline;
  cursor: pointer;
}

.icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  background: var(--panel);
  color: var(--text);
  border: var(--outline);
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.icon-only .icon {
  width: 22px;
  height: 22px;
}

.prose {
  overflow-wrap: anywhere;
}

.prose h1,
.prose h2,
.prose h3 {
  font-family: var(--font-display);
}

.prose img,
.prose table,
.prose pre {
  max-width: 100%;
}

.prose pre {
  overflow-x: auto;
}

/* ---- Waiting and loading (U53) ---- */

.waiting {
  display: flex;
  align-items: center;
  gap: 14px;
}

.spinner {
  width: 32px;
  height: 32px;
  flex: none;
  border: var(--outline-spinner);
  border-top: var(--outline-spinner-head);
  border-radius: var(--radius-pill);
  animation: spin var(--dur-spin) linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---- Home (U31 to U40) ---- */

.home-left,
.home-right {
  min-width: 0;
}

.card-message {
  grid-column: 1 / -1;
  margin: 0;
  min-height: 0;
  text-align: center;
}

.card-message:empty {
  display: none;
}

.player-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin: 0 auto;
  width: 100%;
  max-width: var(--stack-width);
  /* Q23, U37: taller than a menu button, with 16px above and below its content and a slightly larger avatar. */
  box-sizing: border-box;
  padding-block: 16px;
}

.player-card .avatar {
  width: 52px;
  height: 52px;
}

.nick-form,
.join-form {
  display: grid;
  gap: 8px;
  max-width: var(--stack-width);
  margin: 0 auto 12px;
}

.demo {
  margin: 8px 0;
}

/* U37: on a phone the order is title, tagline, player card, buttons, icon row, top
   players and then the demo board, so the menu is on the first screen. Both halves
   dissolve into one column and the demo board is moved to the end. */
.home {
  display: flex;
  flex-direction: column;
  justify-content: center; /* U164: the phone stack is centred on the screen; a taller stack starts at the top and scrolls */
  min-height: 100dvh;
  box-sizing: border-box;
}

.home-left {
  display: contents;
}

/* U37, Q17: the player card, the four buttons and the icon row are one stack with one gap. */
.home-right {
  display: grid;
  gap: 16px;
  width: 100%;
  max-width: var(--stack-width);
  margin: 0 auto;
}

.home-right .stack,
.home-right .menu {
  gap: 16px;
  margin: 0 auto;
  width: 100%;
}

.home-right .btn {
  min-height: 56px;
  box-sizing: border-box;
}

.home-right .round-row {
  margin: 0 auto;
}

/* U35, U36: the demo board and Top players are for the laptop only. */
.home .demo,
.home .top {
  display: none;
}

/* ---- The game screen (U10 to U18, U54 to U60) ---- */

/* The whole game is one centred group: round number, the two panels and the board. On a phone
   the panels sit above the board; on a laptop they sit to its left (U59). */
.game {
  max-width: 560px;
}

.stage {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 10px;
}

.shrink-warning {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0;
  padding: 2px 10px;
  font: 700 0.85rem/1.1 var(--font-display);
  color: var(--ink);
  background: var(--yellow);
  border: var(--outline);
  border-radius: var(--radius-pill);
  text-align: center;
}

.shrink-warning svg {
  flex: none;
  width: 16px;
  height: 16px;
  fill: var(--ink);
}

.shrink-warning[hidden] {
  display: none;
}

.round-line {
  margin: 0;
  font: 700 1.1rem/1 var(--font-display);
  text-align: center;
}

.game .players {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: start;
  gap: 6px;
  width: 100%;
  margin: 0;
}

.game .player {
  grid-template-columns: auto minmax(0, 1fr);
  align-content: start;
}

.game .vs {
  align-self: start;
  margin-top: 18px;
}

/* Your power-ups are one card of two full-width rows (U102): the row is the button, the info button sits at its right edge. */
.powerups {
  grid-column: 1 / -1;
  display: grid;
  gap: 0;
  padding: 0;
  overflow: hidden;
}

.powerup-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
}

.powerup-row + .powerup-row {
  border-top: var(--outline-thin);
}

/* The opponent's Earthquake: availability only (U64). A used one is struck through, so it differs by shape. */
.quake-state {
  position: relative;
  display: inline-flex;
  flex: none;
  width: 18px;
  height: 18px;
  margin-left: 4px;
}

.quake-state svg {
  width: 100%;
  height: 100%;
  fill: var(--shield-on);
}

.quake-state[data-quake="used"] svg {
  fill: var(--shield-off);
}

.quake-state[data-quake="used"]::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  border-top: 3px solid var(--ink);
  transform: rotate(-35deg);
}

/* The crack marker over the board once Earthquake is chosen (U62): it names no column. */
.quake-marker {
  position: absolute;
  left: 50%;
  top: 0;
  z-index: 3;
  width: 32px;
  height: 32px;
  transform: translate(-50%, -100%);
  pointer-events: none;
}

.quake-marker svg {
  width: 100%;
  height: 100%;
  fill: var(--yellow);
}

.quake-marker[hidden] {
  display: none;
}

.powerup-info {
  min-width: 52px;
  min-height: 48px;
  padding: 0;
  border: 0;
  border-left: var(--outline-thin);
  border-radius: 0;
  box-shadow: none;
}

.play-area {
  position: relative;
  width: 100%;
}

.game .board-wrap {
  margin: calc(var(--ghost-size) + 12px) 0 22px; /* room above the board for the ghost disc (U11) */
  padding-bottom: 20px;
}

/* The glow behind one column of holes. It is placed over exactly the holes of its column, from the
   top of the board face to the bottom hole, inside the board's padding, so it never covers the
   frame or the feet (U10). The grid has the board's own padding and gaps. */
/* The tap layer covers the whole board face in seven equal columns, so each is at least 44px wide. */
.columns-hit {
  position: absolute;
  top: var(--frame);
  left: 0;
  right: 0;
  bottom: calc(20px + var(--frame));
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  z-index: 3;
}

/* The glow follows the board's own grid (same padding and gaps), so it covers exactly one column of
   holes, inside the frame and clear of the feet (U10). */
.columns-glow {
  position: absolute;
  top: var(--frame);
  left: var(--frame);
  right: var(--frame);
  bottom: calc(20px + var(--frame));
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  column-gap: var(--gap-board);
  padding: 0 var(--board-pad);
  z-index: 2;
  pointer-events: none;
}

.column-glow {
  position: relative;
  border-radius: var(--radius-pill);
  background: none;
}

.column-hit {
  position: relative;
  min-width: 0;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.column-hit:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

.column-hit[aria-disabled="true"] {
  cursor: not-allowed;
}

.column-glow[data-on="true"] {
  background: var(--gloss-column);
}

/* The ghost disc sits centred above its column, outside the board (U11, U12). */
.ghost {
  position: absolute;
  top: -6px;
  left: 50%;
  width: var(--ghost-size);
  height: var(--ghost-size);
  transform: translate(-50%, -100%);
  border: var(--outline-thin);
  border-radius: var(--radius-pill);
  background: var(--red);
  opacity: 0.55;
  pointer-events: none;
  z-index: 4;
}

/* The ghost disc is drawn in your own colour (U11, U134). */
.ghost[data-colour="yellow"] {
  background: var(--yellow);
}

.ghost[data-chosen="true"] {
  opacity: 1;
  animation: ghost-lock var(--dur-lock) ease-out both; /* lifts a little, then locks (U12) */
}

@keyframes ghost-lock {
  0% {
    transform: translate(-50%, -100%);
  }
  45% {
    transform: translate(-50%, calc(-100% - 8px));
  }
  100% {
    transform: translate(-50%, -100%);
  }
}

.shield-badge {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 4px 12px;
  font: 700 1rem/1.1 var(--font-display);
  white-space: nowrap;
  color: var(--text);
  background: var(--panel);
  border: 0;
  border-radius: 0;
  cursor: pointer;
}

.shield-badge svg {
  width: 28px;
  height: 28px;
  flex: none;
  fill: var(--shield-on);
}

.shield-badge[aria-pressed="true"] {
  background: var(--yellow);
  color: var(--ink);
  box-shadow: var(--shadow-small), 0 0 14px 3px var(--win-glow);
}

.shield-badge[aria-pressed="true"] svg {
  fill: var(--ink);
}

.shield-badge[data-state="spent"] {
  background: var(--disabled);
  color: var(--disabled-text);
  cursor: default;
}

.shield-badge[data-state="spent"] svg {
  fill: var(--shield-off);
}

.shield-badge:disabled {
  cursor: default;
}

/* A power-up that cannot be used right now is greyed (U103), whatever the reason. */
.shield-badge:disabled:not([aria-pressed="true"]) {
  background: var(--disabled);
  color: var(--disabled-text);
}

.shield-badge:disabled:not([aria-pressed="true"]) svg {
  fill: var(--shield-off);
}

/* The round timer: a slim bar under the board that drains over the round (U25). */
.timer-track {
  width: 100%;
  height: 12px;
  overflow: hidden;
  background: var(--field);
  border: var(--outline-thin);
  border-radius: var(--radius-pill);
}

.timer-track[hidden] {
  display: none;
}

.timer-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--timer-ok);
  transform-origin: left center;
  transform: scaleX(var(--left, 1));
}

.timer-track[data-urgency="warn"] .timer-fill {
  background: var(--timer-warn);
}

.timer-track[data-urgency="urgent"] .timer-fill {
  background: var(--timer-urgent);
}

/* U151, Q19 (changed 31 October 2026): the result line is never visible, on the game screen or the watching screen. It
   stays an aria-live region (so it is still announced) without ever taking space in the layout, so removing it frees
   the 16px the power-up row now keeps above the bottom of the screen. */
.game .result {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  margin: 0;
}

.game .message {
  min-height: 1.4em;
  margin: 2px 0;
  text-align: center;
}

/* "Get ready" shows once, when a game first starts (U55). */
/* The start countdown (U133, R97): a card over the board for the 3 seconds before round 1, saying the player's colour with
   their disc shown large, so the colour is told by shape too. */
.get-ready {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(100%, 300px);
  height: fit-content;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 16px 20px 18px;
  text-align: center;
  pointer-events: none;
  z-index: 6;
  animation: pop var(--dur-pop) ease-out both;
}

.get-ready p {
  margin: 0;
}

.get-ready-lead {
  font: 700 1rem/1.2 var(--font-display);
  color: var(--text-muted);
}

.you-are {
  font: 700 1.8rem/1.1 var(--font-display);
  white-space: nowrap;
}

/* The real disc, large: the piece's own colour and marker rules draw it. */
.you-are-disc.piece {
  position: relative;
  inset: auto;
  display: block;
  width: 72px;
  height: 72px;
  box-shadow: var(--shadow);
}

.countdown-number {
  font: 700 2.4rem/1 var(--font-display);
  color: var(--yellow);
}

.get-ready[hidden] {
  display: none;
}

/* While a game waits for its second player, the board is dimmed and the card sits over it (U54). */
.game[data-waiting="true"] .board {
  opacity: 0.35;
}

/* Waiting: only the board and its card are on the screen, and they are centred on it (U108). The heading, the panels and
   the round line take no room, so nothing is left behind as a gap above the board. */
.game[data-waiting="true"] .players,
.game[data-waiting="true"] .status-row,
.game[data-waiting="true"] .opponent-heading {
  display: none;
}

.game[data-waiting="true"] .stage {
  align-content: center;
  min-height: calc(100vh - 32px);
}

.game[data-waiting="true"] .timer-track {
  display: none;
}

.share {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(100%, 480px);
  height: fit-content;
  display: grid;
  gap: 8px;
  text-align: center;
  z-index: 6;
}

.share[hidden] {
  display: none;
}

.share h2 {
  margin: 0;
  font-size: 1.2rem;
}

.share .code {
  margin: 0;
  font: 700 clamp(28px, 8vw, 40px) / 1 var(--font-display);
  letter-spacing: 0.2em;
  color: var(--yellow);
}

.share-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.share-actions .btn {
  min-width: 0;
  padding: 0 8px;
}

/* Spectating (docs/design/spectating.md U76 to U84). The watching screen reuses the game screen's layout and has
   nothing to act on. */
.watching-banner {
  margin: 0;
  padding: 2px 10px;
  font: 700 0.85rem/1.1 var(--font-display);
  color: var(--ink);
  background: var(--yellow);
  border: var(--outline);
  border-radius: var(--radius-pill);
  text-align: center;
}

/* The eye and a number: how many are watching (R75). A number only, at a small fixed size. */
.watcher-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  font: 700 0.85rem/1.1 var(--font-display);
  color: var(--text-muted);
}

.watcher-count svg {
  flex: none;
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.watcher-count[hidden] {
  display: none;
}

/* The watching screen has no timer bar and no keys hint, so nothing but the result line and the message sits
   between the board and the buttons, and an empty message takes no room (U79, first-screen rule). */
.watching .message:empty {
  display: none;
}

.watch-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  margin-top: 8px;
}

.watch-actions .btn {
  min-width: 0;
  padding: 0 6px;
  font-size: 1rem;
}

/* A link game's spectator is told why they are watching, in place of the banner (U92, U173). As wide as the board, with
   comfortable padding, centred text that wraps to at most two lines on a phone and one on a laptop, so it looks
   deliberately designed rather than squeezed. */
.spectator-notice {
  background: var(--panel);
  color: var(--text);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 12px 16px;
  text-align: center;
  white-space: normal;
  overflow-wrap: break-word;
}

.spectator-notice[hidden] {
  display: none;
}

/* Nothing is live: a centred card in the toy style with the way on (U93). */
.no-live {
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(480px, 100%);
  margin: 32px auto 16px;
  padding: 24px 16px;
  text-align: center;
}

.no-live[hidden] {
  display: none;
}

.no-live h2 {
  margin: 0;
}

.no-live p {
  margin: 0;
}

.no-live-icon svg {
  width: 48px;
  height: 48px;
  fill: var(--yellow);
}

.no-live-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  margin-top: 8px;
}

.no-live-actions .btn {
  min-width: 0;
  padding: 0 8px;
  white-space: nowrap;
}

.share-text {
  margin: 0 0 12px;
  text-align: center;
}

/* The result card sits over the board, compact and centred, like the end popup (U82). */
.watch-result {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 6;
  width: min(300px, 90%);
  padding: 12px 14px;
  text-align: center;
  transform: translate(-50%, -50%);
}

.watch-result[hidden] {
  display: none;
}

.watch-result h2 {
  margin: 0 0 4px;
  font-size: 1.4rem;
  overflow-wrap: anywhere;
}

.watch-result p {
  margin: 0;
}

/* U178: the spectator's end card is spaced like the other popups. 24px padding on every side, 8px from the title to the
   count down line and 20px from that line to Back to home, which spans the content width at the popups' button height. The
   bottom padding (24px) is wider than the button's 5px hard shadow (--shadow), so the shadow is never cut off. */
.watch-result:not(.watch-learning) {
  display: flex;
  flex-direction: column;
  width: min(340px, calc(100% - 32px));
  padding: 24px;
  overflow: visible;
}

.watch-result:not(.watch-learning)[hidden] {
  display: none;
}

.watch-result:not(.watch-learning) h2 {
  margin: 0;
}

.watch-result:not(.watch-learning) h2 + p {
  margin-top: 8px;
}

.watch-result:not(.watch-learning) h2 + p:empty {
  display: none;
}

.watch-result > .btn {
  align-self: stretch;
  width: 100%;
  min-height: 52px;
  margin-top: 20px;
  white-space: nowrap;
}

/* The "Watch live" round button on the home screen carries a small live count under its label (U76). */
.watch-live {
  position: relative;
}

.live-count {
  position: absolute;
  top: -6px;
  left: 50%;
  z-index: 1;
  min-width: 20px;
  padding: 1px 6px;
  font: 700 0.7rem/1.2 var(--font-display);
  color: var(--ink);
  background: var(--yellow);
  border: var(--outline-thin);
  border-radius: var(--radius-pill);
  white-space: nowrap;
  transform: translateX(8px); /* over the circle's top right corner */
}

/* Nothing is live: the badge is not drawn, and its words stay for screen readers (U76). */
.live-count[data-live="0"] {
  position: absolute;
  width: 1px;
  height: 1px;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  border: 0;
  white-space: nowrap;
}

/* The end popup is centred over the board, compact, and its title fits (U27a). */
.popup {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: var(--backdrop);
  border-radius: var(--radius-board);
}

.popup[hidden] {
  display: none;
}

.popup-card {
  width: 100%;
  max-width: 300px;
  text-align: center;
  animation: pop var(--dur-popup) ease-out both;
}

.popup-card p {
  margin: 4px 0 10px;
}

.popup-title {
  margin: 4px 0 16px; /* U29: only the title is above the buttons, so its shadow needs room before them */
  font: 700 clamp(24px, 7.5vw, 40px) / 1.05 var(--font-display);
  color: var(--yellow);
  -webkit-text-stroke: 0.04em var(--ink);
  paint-order: stroke fill;
  text-shadow: var(--shadow-title-popup);
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.popup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.popup-actions .btn {
  min-width: 0;
  padding: 0 6px;
}

/* At 320 px wide the board, timer bar and both names must still fit one 568 px screen (docs/design.md):
   smaller ghost, tighter panels and spacing. */
@media (max-width: 359px) {
  :root {
    --ghost-size: 26px;
    --board-pad: 6px;
  }

  .game .stage {
    gap: 4px;
  }

  .round-line {
    font-size: 1rem;
  }

  /* At 320px the round number and the banner share one line, so the banner costs no height (U68, U75). */
  .status-row {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .shrink-warning {
    min-width: 0;
    padding: 1px 6px;
    font-size: 0.72rem;
    gap: 4px;
  }

  .shrink-warning svg {
    width: 12px;
    height: 12px;
  }

  /* Every item in the status row is one line at 320px (U68, U84). The players' screen keeps one row; the watching
     screen holds one more item and has no timer bar, so its row wraps, with the ceiling warning on a second line only
     in the round it shows (U78, first-screen rule). */
  .status-row > * {
    white-space: nowrap;
  }

  .watching .status-row {
    flex-wrap: wrap;
    gap: 1px 8px;
  }

  .watching .shrink-warning {
    flex-basis: auto;
  }

  .watching .watching-banner,
  .watching .watcher-count {
    font-size: 0.78rem;
  }

  /* "Watching <name> vs <name>" is as long as two nicknames and tags (U94): it takes its own line, cut with an ellipsis if
     the widest names still do not fit, and the names stay whole in the player panels below. */
  .watching .watching-banner:not(.spectator-notice) {
    order: 3;
    flex: 1 0 100%;
    padding-block: 0;
    width: 0; /* adds nothing to the row's own width, so a long name never widens the screen */
    min-width: 100%;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  /* U173: still comfortably padded and centred at 320px, sized to wrap to at most two lines rather than being squeezed.
     Overrides the status row's one-line-per-item rule above: this chip is the one item meant to wrap. */
  .watching .spectator-notice {
    font-size: 0.78rem;
    padding: 12px 16px;
    white-space: normal;
  }

  /* "Watch another game" is the longest label (U79). At 320px the arrow icon goes, so the words fit on two lines. */
  .watch-actions .btn svg {
    display: none;
  }

  .watch-actions .btn {
    font-size: 0.95rem;
    line-height: 1.1;
    text-align: center;
  }

  /* On the players' screen the count and the warning share the round line, so they must fit the 308px of the board. */
  .game:not(.watching) .shrink-warning {
    font-size: 0.68rem;
    padding: 1px 5px;
  }

  .game:not(.watching) .status-row {
    gap: 4px;
  }

  .watching .stage {
    gap: 2px;
  }

  /* The game screen keeps room above the board for the ghost disc (U11). The watching screen has no ghost disc
     (U79), so that room is given back. */
  .game.watching .board-wrap {
    margin-top: 4px;
  }

  .game .player {
    padding: 4px 4px 6px;
    gap: 2px;
  }

  .game .player .avatar {
    width: 32px;
    height: 32px;
  }

  .game .player-name {
    font-size: 0.85rem;
  }

  .game .player-meta {
    font-size: 0.78rem;
    gap: 0 4px;
  }

  .game .vs {
    margin-top: 10px;
    padding: 4px 8px;
  }

  .shield-badge {
    min-height: 40px;
    padding: 2px 10px;
    gap: 10px;
    font-size: 0.9rem;
  }

  .shield-badge svg {
    width: 20px;
    height: 20px;
  }

  /* The rows are 44px tall (U102) and the opponent's labels are small, so the board and timer keep the first screen. */
  .powerup-info {
    min-width: 44px;
    min-height: 44px;
  }

  .powerup-row {
    min-height: 44px;
  }

  .game .board-wrap {
    margin: calc(var(--ghost-size) + 6px) 0 4px;
    padding-bottom: 16px;
  }

  .columns-hit,
  .columns-glow {
    bottom: calc(16px + var(--frame));
  }

  .board-wrap::before,
  .board-wrap::after {
    height: 18px;
  }
}

/* Last, so it wins over the game rules above (U30). */
@media (prefers-reduced-motion: reduce) {
  .ghost,
  .get-ready,
  .popup-card {
    animation: none;
  }
}

@media (min-width: 900px) {
  :root {
    --board-width: min(560px, calc((100vh - 350px) * 7 / 6));
    --ghost-size: 56px;
  }

  /* U132: one centred column, as wide as the board, sized so the header, the versus bar, the board, the timer and the power-up
     row fit the laptop screen. */
  .game {
    max-width: var(--board-width);
  }
}
/* ---- Tutorial card (U27 to U29, U41 to U48, U52, U167, U172, ADR 0016) ----
   One card of one size per viewport, centred, identical on all 11 steps. Its height is the sum of its parts, each a block in normal
   flow (see .tutorial-card below). The top area's height is the measured height of the longest instruction at that viewport
   (docs/design/tutorial.md); the board's size is set once per viewport. */

.tutorial {
  /* The phone's sizes are in theme.css (--tut-top is 7 lines, the longest instruction, measured 202.8px at 390 x 844). */
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--backdrop);
  overflow: hidden;
}

@media (min-width: 600px) {
  .tutorial {
    --tut-pad-y: 24px;
    --tut-pad-x: 32px;
    --tut-top: 140px; /* 4 lines, the longest instruction on the laptop (measured 139.8px) */
    --tut-board-w: 310px;
  }
}

/* The card is a plain stack of blocks in normal flow (U172): padding, the instruction area, 16px, the ghost lane, 8px, the board, 12px,
   one reserved slot, 24px, Next, 12px, Skip tutorial, padding. Its height is the sum of those, so it is the same on every step and
   nothing can overlap or leave a gap bigger than the one written here. No absolute positioning, no negative margins. */
.tutorial-card {
  width: min(560px, 100vw - 32px);
  height: auto;
  margin: 0;
  padding: var(--tut-pad-y) var(--tut-pad-x);
  text-align: center;
}

/* Top: the counter, the title and the instructions, from the top of the area. Shorter instructions leave blank space below. */
.tutorial-top {
  height: var(--tut-top);
  min-width: 0;
}

.tutorial-progress {
  margin: 0;
  font: 700 0.85rem/1.2 var(--font-display);
  color: var(--text-muted);
}

.tutorial-card h2 {
  margin: 2px 0 0;
}

.tutorial-caption {
  margin: 4px 0 0;
  font-size: 1.05rem;
  line-height: 1.25;
}

/* The ghost disc's lane: one disc tall, 16px under the instructions. The disc sits in it, 8px above the board. */
.tutorial-lane {
  height: var(--ghost-size);
  margin-top: 16px;
}

.tutorial-board .ghost {
  top: -12px; /* its bottom edge is 8px above the board (the lane's own 8px), not 2px */
}

/* The board, 8px under the lane. Its width is set once per viewport, so its height is too. */
.tutorial-board {
  display: grid;
  margin-top: 8px;
}

.tutorial-board > .board-wrap,
.tutorial-board > .tutorial-friends {
  grid-area: 1 / 1;
}

.tutorial-board .board-wrap {
  width: min(var(--tut-board-w), 100%);
  margin: 0 auto;
  padding-bottom: 0;
}

.tutorial-board .board-wrap::before,
.tutorial-board .board-wrap::after {
  display: none;
}

.tutorial-board .columns-hit,
.tutorial-board .columns-glow {
  bottom: var(--frame);
}

/* The friends step's panel (U177): exactly the board's box. It shares the board's grid cell, so it is stretched to the board's width and
   height (the board keeps its place, hidden), and it is framed like the board: the same corner radius and dark outline, in a muted navy. */
.tutorial-board .tutorial-friends {
  width: min(var(--tut-board-w), 100%);
  height: 100%;
  min-height: 0;
  margin: 0 auto;
  box-sizing: border-box;
  background: var(--field);
  border: var(--outline-thick);
  border-radius: var(--radius-board);
  container-type: size; /* the picture below scales with the panel's own size */
}

/* The slot under the board: 12px below it, as tall as its tallest tenant (a 44px button), exactly as wide as the board. One tenant
   shows at a time, and none is wider than the slot (U172). */
.tutorial-slot {
  display: grid;
  place-items: center;
  width: min(var(--tut-board-w), 100%);
  height: 44px;
  margin: 12px auto 0;
}

.tutorial-slot > * {
  grid-area: 1 / 1;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: 0;
}

.tutorial-slot > [hidden] {
  display: none;
}

.tutorial-warning {
  font-size: 17px; /* U173: a little bigger than the game's banner, on one line */
  padding-top: 6px;
  padding-bottom: 6px;
  white-space: nowrap;
  width: 100%; /* U173: exactly the board's width, like the timer bar; the text stays centred (the banner is a centring flex row) */
  box-sizing: border-box;
}

.tutorial-shield {
  min-height: 44px;
  height: 44px;
  /* The practice badges are free-standing pills, as the game's were before the power-up card (U102): the game's rows are borderless
     because they sit inside a card, and these do not. */
  justify-content: center;
  background: var(--panel);
  border: var(--outline);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-small);
}

.tutorial-shield[aria-pressed="true"] {
  background: var(--yellow);
  color: var(--ink);
}

.tutorial-shield[data-state="spent"] {
  background: var(--disabled);
  color: var(--disabled-text);
}

/* Bottom: Next, 24px under the slot, centred, with Skip tutorial 12px under it, in the same place on every step. */
.tutorial-actions {
  display: grid;
  justify-items: center;
  gap: 12px;
  margin-top: 24px;
}

.tutorial-actions .btn {
  min-height: 44px;
  height: 44px;
}

/* ---- A phone: the tutorial is full screen (U176, ADR 0018) ----
   Below 600px wide the card is not a card: it fills the whole visible screen (100svh, the height that stays visible with Safari's
   toolbars showing) in the card's own colour, with no rounded edge, outline, shadow, outer margin or backdrop, and the page never
   scrolls. Its content keeps the safe areas clear. The layout inside is the same stack as the laptop's (U172); the script sets
   --tut-board-w, --tut-top and --tut-gap once when the tutorial opens (and again on a resize or a rotation, never on a step), so the
   board is the same size and in the same place on every step. The gaps close first on a short screen, then the board gets smaller,
   never below seven 44px columns, so the defaults here are the largest layout and the script only ever reduces them. */
@media (max-width: 599px) {
  .tutorial {
    --tut-gap: 1; /* 1 is the gaps of U172; 0 is no gaps at all. Set by the script (src/client/tutorial.ts), default here. */
    --tut-margin: 24px; /* the space above and below the content block, before the safe areas (U180). Set by the script. */
    --tut-pad-y: 0px;
    --tut-pad-x: 16px;
    display: block;
    height: 100svh;
    padding: 0;
    background: var(--panel);
    overflow: hidden;
  }

  /* The card is the whole visible screen, and its content block is centred in it (U180): the same space above and below, at least
     the margin plus the safe areas. justify-content centres the block; the block is as tall as its parts, so nothing inside it moves. */
  .tutorial-card {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100%;
    height: 100svh;
    margin: 0;
    padding: calc(var(--tut-margin) + env(safe-area-inset-top)) calc(var(--tut-pad-x) + env(safe-area-inset-right)) calc(var(--tut-margin) + env(safe-area-inset-bottom)) calc(var(--tut-pad-x) + env(safe-area-inset-left));
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
  }

  .tutorial-card > * {
    flex: none;
  }

  /* The two sets of text sizes (U179). The script picks one when the tutorial opens, from the visible height. */
  .tutorial[data-size="large"] .tutorial-progress {
    font-size: 17px;
  }

  .tutorial[data-size="large"] .tutorial-card h2 {
    font-size: 32px;
  }

  .tutorial[data-size="large"] .tutorial-caption {
    font-size: 19px;
  }

  .tutorial[data-size="short"] .tutorial-progress {
    font-size: 15px;
  }

  .tutorial[data-size="short"] .tutorial-card h2 {
    font-size: 26px;
  }

  .tutorial[data-size="short"] .tutorial-caption {
    font-size: 17px;
  }

  /* Next is exactly the board's width and at least 52px tall (the large set) or 48px (the short set), with 20px text. Skip tutorial is
     17px with a box at least 44px tall, centred below it. */
  .tutorial-actions .btn[data-testid="tutorial-next"] {
    width: min(var(--tut-board-w), 100%);
    font-size: 20px;
    height: var(--tut-next-h, 52px);
    min-height: var(--tut-next-h, 52px);
  }

  .tutorial[data-size="short"] {
    --tut-next-h: 48px;
  }

  .tutorial-actions .link-button {
    font-size: 17px;
    min-height: 44px;
  }

  .tutorial-lane {
    margin-top: calc(16px * var(--tut-gap));
  }

  .tutorial-board {
    margin-top: calc(8px * var(--tut-gap));
  }

  .tutorial-slot {
    margin-top: calc(12px * var(--tut-gap));
  }

  .tutorial-actions {
    margin-top: calc(24px * var(--tut-gap));
    gap: calc(12px * var(--tut-gap));
  }

  /* Still too short with every gap closed and the margin at its smallest (a 320 x 568 phone): the script sets data-tight, Next and Skip
     tutorial share one row and the instructions use the smaller text, the last resort U176 always had. The board keeps its seven 44px
     columns, and the sizes of U179 give way here. */
  .tutorial[data-tight="true"] {
    --tut-pad-x: 0px;
    --tut-margin: 4px;
    --tut-next-h: 44px;
  }

  .tutorial[data-tight="true"] .tutorial-top {
    padding: 0 8px;
  }

  .tutorial[data-tight="true"] .tutorial-progress {
    font-size: 13.6px;
  }

  .tutorial[data-tight="true"] .tutorial-card h2 {
    font-size: 24px;
  }

  .tutorial[data-tight="true"] .tutorial-caption {
    font-size: 0.8rem;
  }

  .tutorial[data-tight="true"] .tutorial-actions {
    grid-auto-flow: column;
    align-items: center;
    margin-top: calc(4px * var(--tut-gap));
    gap: 8px;
  }

  .tutorial[data-tight="true"] .tutorial-actions .btn[data-testid="tutorial-next"] {
    width: auto;
    font-size: 17.6px;
  }

  .tutorial[data-tight="true"] .tutorial-actions .link-button {
    font-size: 16px;
  }
}

/* ---- Wider screens ---- */

@media (min-width: 900px) {
  :root {
    --page-pad: 24px;
  }

  /* Home (U38): two halves share the width evenly, both vertically centred, nothing stretched. */
  .home {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 64px;
    align-items: center;
    min-height: calc(100vh - 48px);
    max-width: 1100px;
  }

  .home .demo {
    display: block;
  }

  .home .top {
    display: block;
  }

  .home-right .top h2 {
    margin: 8px 0 6px;
  }

  .home-right .rows {
    gap: 6px;
  }

  .home-left {
    display: block;
    min-width: 0;
  }

  /* The right half is the full half so the two halves stay balanced; its stack is centred in it at the stack width. */
  .home-right {
    max-width: none;
    justify-items: center;
  }

  .home-right > * {
    width: 100%;
    max-width: var(--stack-width);
  }

  .home-left {
    display: grid;
    justify-items: center;
  }

  .home-left .demo {
    width: min(100%, 440px);
  }

  .arena {
    max-width: 1100px;
  }
}

/* ---- Popups (docs/design/popups.md U85 to U90): one component, src/client/dialog.ts ---- */
.dialog {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--backdrop);
  overscroll-behavior: contain;
}

.dialog-card {
  position: relative;
  width: min(480px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 24px 16px 16px;
  animation: dialog-in var(--dur-popup) ease-out both;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .dialog-card {
    animation: none;
  }
}

.dialog-title {
  margin: 0 48px 16px 0;
  font-size: 1.4rem;
  line-height: 1.15;
  text-align: left;
}

.dialog-close {
  position: absolute;
  top: -1px; /* the 20px icon sits 12px inside this 44px tappable area, so 16px from the card's outer edge past its 5px border (U85a) */
  right: -1px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  cursor: pointer;
}

.dialog-close svg {
  width: 20px;
  height: 20px;
}

.dialog-form {
  display: grid;
  gap: 16px;
}

.dialog-field label {
  margin: 0 0 6px;
}

.dialog-text {
  margin: 0;
}

.dialog-error {
  margin: 6px 0 0;
  color: var(--error);
  font-weight: 700;
}

.dialog-error[hidden] {
  display: none;
}

.dialog-actions {
  display: grid;
  gap: 16px;
}

.dialog-actions[data-count="2"] {
  grid-template-columns: 1fr 1fr;
}

.dialog-actions .btn {
  min-width: 0;
  padding: 0 8px;
  white-space: nowrap;
}

.menu {
  gap: 16px;
}

/* ---- Quick match (docs/design/quick-match.md U96 to U101) ---- */
.quick {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 16px;
}

.quick .subtitle {
  width: min(480px, 100%);
  margin: 24px 0 0; /* clear of the title's falling chips (U5a) */
  text-align: center;
}

.quick-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(480px, 100%);
  margin: 0;
  padding: 24px 16px;
  text-align: center;
}

.quick-status {
  margin: 0;
  font-size: 1.3rem;
  line-height: 1.15;
}

.quick-hint,
.quick-live {
  margin: 0;
  color: var(--text-muted);
}

.quick-live {
  min-height: 1.4em;
  font-weight: 700;
}

.quick-offer {
  display: grid;
  gap: 16px;
  width: 100%;
  margin-top: 8px;
  padding-top: 16px;
  border-top: var(--outline-thin);
}

.quick-offer[hidden] {
  display: none;
}

.quick-offer p {
  margin: 0;
}

/* The pair of discs swings together and parts again, with only transform. The ring disc and the cross disc differ by shape. */
.quick-discs {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 112px;
  height: 56px;
}

.quick-disc {
  display: block;
  width: 48px;
  height: 48px;
  border: var(--outline);
  border-radius: var(--radius-pill);
  animation: quick-meet var(--dur-meet) ease-in-out infinite;
}

.quick-disc-you {
  background: var(--red);
  box-shadow: inset 0 0 0 6px var(--red), inset 0 0 0 9px var(--marker-red);
}

.quick-disc-opponent {
  position: relative;
  background: var(--yellow);
  animation-direction: reverse;
}

.quick-disc-opponent::before,
.quick-disc-opponent::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 4px;
  background: var(--marker-yellow);
  border-radius: var(--radius-chip);
  transform: translate(-50%, -50%) rotate(45deg);
}

.quick-disc-opponent::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

@keyframes quick-meet {
  0%,
  100% {
    transform: translateX(-14px);
  }
  50% {
    transform: translateX(14px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .quick-disc {
    animation: none;
  }
}

/* At 320px the computer offer must leave Cancel on the first screen (U101): tighter card, smaller discs. */
@media (max-width: 359px) {
  .quick-card {
    gap: 6px;
    padding: 10px 12px;
  }

  .quick-discs {
    height: 40px;
  }

  .quick-disc {
    width: 36px;
    height: 36px;
  }

  .quick-offer {
    gap: 8px;
    margin-top: 4px;
    padding-top: 8px;
  }
}

@media (max-width: 359px) {
  .game .players {
    row-gap: 3px;
  }

  .game .player-name {
    font-size: 0.78rem;
    line-height: 1.1;
  }

  .game .player-meta {
    line-height: 1.1;
  }

  .game .stage {
    gap: 2px;
  }

  .powerups {
    border: var(--outline-thin);
  }

  .game .board-wrap {
    margin: calc(var(--ghost-size) - 2px) 0 0;
  }

  .timer-track {
    height: 6px;
  }
}

/* Who you are playing, and leaving (docs/design/game-screen.md U106 to U108). */
.opponent-heading {
  width: 100%;
  margin: 0;
  overflow: hidden;
  font-size: 1rem;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leave-game {
  width: 100%;
  margin-top: 16px;
}

.leave-game[hidden] {
  display: none;
}

.share .btn-block {
  margin-top: 8px; /* with the card's 8px gap, 16px under Copy link and Share (Q4) */
}

/* The end popup's two buttons are one line each, down to 320px (U29). */
.popup-actions .btn {
  white-space: nowrap;
}

@media (max-width: 359px) {
  .popup-actions .btn svg {
    display: none;
  }

  .popup-actions .btn {
    padding: 0 4px;
    font-size: 1rem;
  }
}

.game[data-waiting="true"] .leave-game {
  display: none;
}

@media (max-width: 359px) {
  .opponent-heading {
    font-size: 0.8rem;
    line-height: 1;
  }
}

/* The rematch line inside the end popup (docs/design/rematch.md U110, U111, U113). It is text, so it may wrap at 320px. */
.rematch-status {
  margin: 0 0 8px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.rematch-status[hidden],
.popup-actions .btn[hidden] {
  display: none;
}

.popup-actions:has(.btn[hidden]) {
  grid-template-columns: 1fr;
}

/* ---- The account page (docs/design/account.md U114 to U122) ---- */
.account {
  display: grid;
  justify-items: center;
  align-content: start;
}

.account-columns {
  display: grid;
  justify-items: center;
  gap: 16px;
  width: 100%;
}

.account-left {
  display: grid;
  justify-items: center;
  gap: 16px;
  width: 100%;
}

.account .subtitle {
  width: min(480px, 100%);
  margin: 24px 0 0; /* clear of the title's falling chips (U5a) */
  text-align: center;
}

.account-card {
  display: grid;
  gap: 16px;
  width: min(480px, 100%);
  margin: 0;
}

.account-who {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "avatar names" "edit edit";
  align-items: center;
  gap: 12px;
}

.account-who > .avatar {
  grid-area: avatar;
}

.account-names {
  grid-area: names;
}

.account-edit {
  grid-area: edit;
}

@media (min-width: 480px) {
  .account-who {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "avatar names edit";
  }
}

.account-names {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.account-nickname {
  font: 700 1.15rem/1.2 var(--font-display);
  overflow-wrap: anywhere;
}

.account-edit {
  width: 100%;
}

@media (min-width: 480px) {
  .account-edit {
    width: auto;
  }
}

.account-status {
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.account-hint {
  margin: 0;
  color: var(--text-muted);
}

.account-hint[hidden],
.account-actions .btn[hidden],
.account-edit[hidden] {
  display: none;
}

.account-actions {
  display: grid;
  gap: 16px;
}

.account-actions:not(:has(.btn:not([hidden]))) {
  display: none;
}

.account-edit {
  min-width: 0;
  padding: 0 14px;
  white-space: nowrap;
}

.account-actions .btn {
  white-space: nowrap;
}

.account .card-message {
  margin: 0;
}

.forgot-link {
  justify-self: start;
  padding: 0;
  color: var(--link);
  text-decoration: underline;
}

/* Your record: two small stats cards and the list of the last 20 games, in the same column as the card (U118). */
.record {
  display: grid;
  gap: 16px;
  width: min(480px, 100%);
  margin-top: 16px; /* with the page's 16px gap, 32px between the card and the record (Q4) */
}

.record h2 {
  margin: 0;
}

.record-stats {
  display: grid;
  gap: 16px;
}

.record-card {
  margin: 0;
}

.record-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.record-card dl {
  display: grid;
  gap: 4px;
  margin: 0;
}

.record-card dl > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.record-card dt {
  color: var(--text-muted);
}

.record-card dd {
  margin: 0;
  font-weight: 700;
}

.record-none {
  margin: 0;
  color: var(--text-muted);
}

.history-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.history-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "who name" "who result" "who detail";
  align-items: center;
  gap: 2px 12px;
}

@media (min-width: 400px) {
  .history-row {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "who name result" "who detail detail";
  }
}

.history-row > .avatar {
  grid-area: who;
}

.history-row .row-name {
  grid-area: name;
}

.history-result {
  grid-area: result;
  font-weight: 700;
}

.history-detail {
  grid-area: detail;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.history-row[data-abandoned="true"] {
  opacity: 0.7;
}

.history-empty {
  text-align: center;
}

@media (min-width: 560px) {
  .record-stats {
    grid-template-columns: 1fr 1fr;
  }
}

.dialog-hint {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.record-error {
  margin: 0;
  color: var(--error);
  font-weight: 700;
}

/* U118, Q30 (changed 31 October 2026): one "No games yet" message under both stat cards, never inside a card. */
.record-empty {
  margin: 0;
  color: var(--text-muted);
  text-align: center;
}

.record-empty[hidden] {
  display: none;
}

/* ---- Q30, Q33, U114a, U114b: the account page on a laptop is two columns filling the area under the header bar ----
   The page is one screen tall: the header bar, then 32px, then the columns, then 32px to the bottom of the screen. The right column
   fills the area (heading, stat cards, then the history as one card that takes the height left and scrolls inside itself); the left
   column is vertically centred in the same area, and its right edge shares the header bar's Home button's right edge (Q5, Q12, see
   the ".account > .topbar" rule below), not centred horizontally. */
@media (min-width: 900px) {
  .account {
    box-sizing: border-box;
    height: 100dvh;
    padding: 8px 0 32px;
    grid-template-rows: auto minmax(0, 1fr);
    align-content: stretch;
  }

  .account > .topbar {
    margin-bottom: 32px;
  }

  .account-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
    gap: 64px;
    max-width: 1100px;
    min-height: 0;
  }

  .account-left {
    align-self: center;
    justify-self: end;
    width: 100%;
    max-width: 480px;
  }

  .record {
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    align-content: start;
    justify-self: start;
    align-self: stretch;
    width: 100%;
    max-width: var(--list-width);
    min-height: 0;
    margin-top: 0;
  }

  .record-empty {
    grid-row: 3;
    margin: 0;
  }

  /* One card: a border on every side and the card's shadow, its rows divided by thin lines. It takes all the height left and
     scrolls inside itself, so its bottom edge is always on screen. */
  .history-list {
    grid-row: 4; /* always the last row, which takes the height left, even while the empty message is hidden */
    min-height: 0;
    max-width: none;
    margin: 0; /* the card's edge is 32px above the bottom of the screen; its hard shadow (U9b) falls inside that 32px */
    padding: 4px 12px;
    overflow-y: auto;
    background: var(--panel);
    border: var(--outline);
    border-radius: var(--radius-panel);
    box-shadow: var(--shadow);
    align-content: start;
    gap: 0;
  }

  .history-list:empty {
    display: none;
  }

  .history-list .history-row {
    padding: 10px 0;
    background: none;
    border: 0;
    border-bottom: var(--outline-thin);
    border-radius: 0;
    box-shadow: none;
  }

  .history-list .history-row:last-child {
    border-bottom: 0;
  }
}

/* ---- The leaderboard (docs/design/leaderboard.md U123 to U130) ---- */
.leaderboard {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 16px;
  max-width: var(--list-width);
}

.leaderboard .subtitle {
  width: min(var(--list-width), 100%);
  margin: 24px 0 0; /* clear of the title's falling chips (U5a) */
  text-align: center;
}

.board-column {
  display: grid;
  gap: 16px;
  width: min(var(--list-width), 100%);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tab {
  min-height: 48px;
  padding: 0 8px;
  font: 700 1rem/1 var(--font-display);
  white-space: nowrap;
  color: var(--text);
  background: var(--panel);
  border: var(--outline);
  border-radius: var(--radius-button);
  box-shadow: var(--shadow-small);
  cursor: pointer;
}

.tab[aria-selected="true"] {
  color: var(--ink);
  background: var(--yellow);
  box-shadow: var(--shadow);
}

.board-panel {
  display: grid;
  gap: 16px;
}

.board-loading {
  margin: 0;
  color: var(--text-muted);
  text-align: center;
}

.board-loading[hidden],
.podium[hidden],
.board-rows[hidden],
.board-empty[hidden],
.board-error[hidden] {
  display: none;
}

/* The podium: second on the left, first in the middle and tallest, third on the right. */
.podium {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: end;
  gap: 8px;
  margin-top: 8px;
}

/* First place is always in the middle column, second on the left and third on the right, whoever is missing (U125). */
.podium-place[data-place="2"] {
  grid-column: 1;
}

.podium-place[data-place="1"] {
  grid-column: 2;
}

.podium-place[data-place="3"] {
  grid-column: 3;
}

.podium-place {
  grid-row: 1;
  display: grid;
  align-content: end;
  gap: 8px;
  min-width: 0;
  text-align: center;
}

.podium-who {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-width: 0;
}

.podium-name {
  max-width: 100%;
  font: 700 0.85rem/1.15 var(--font-display);
  overflow-wrap: anywhere;
}

.podium-step {
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 4px;
  padding: 8px 4px;
  color: var(--ink);
  background: var(--blue);
  border: var(--outline);
  border-radius: var(--radius-button) var(--radius-button) 0 0;
  box-shadow: var(--shadow);
}

.podium-place[data-place="1"] .podium-step {
  min-height: 132px;
  background: var(--yellow);
}

.podium-place[data-place="2"] .podium-step {
  min-height: 100px;
  color: var(--text);
}

.podium-place[data-place="3"] .podium-step {
  min-height: 76px;
  color: var(--text);
  background: var(--red);
}

.podium-rank {
  font: 700 1.6rem/1 var(--font-display);
}

.podium-score {
  font: 700 0.8rem/1.1 var(--font-display);
}

.podium-place[data-you="true"] .podium-step {
  outline: 4px solid var(--text);
  outline-offset: 2px;
}

.you-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 8px;
  color: var(--ink);
  font: 700 0.75rem/1.4 var(--font-display);
  background: var(--yellow);
  border: var(--outline-thin);
  border-radius: var(--radius-pill);
}

.podium-who .you-tag {
  margin: 0;
}

/* Compact rows from fourth place, 12px apart. */
.board-rows {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

.board-row {
  grid-template-columns: auto auto minmax(0, 1fr) auto;
}

.board-row .row-name {
  overflow-wrap: anywhere;
}

.board-row[data-you="true"] {
  outline: 4px solid var(--yellow);
  outline-offset: 2px;
}

.board-row .row-value {
  white-space: nowrap;
}

.board-empty {
  display: grid;
  gap: 16px;
  width: min(480px, 100%); /* an explanation and two buttons is a form-size card (Q3), centred in the column */
  margin: 0 auto;
  text-align: center;
}

.board-empty-text,
.board-error p {
  margin: 0;
}

.board-empty-actions {
  display: grid;
  gap: 16px;
}

.board-error {
  display: grid;
  gap: 16px;
  width: min(480px, 100%);
  margin: 0 auto;
  color: var(--error);
  text-align: center;
  font-weight: 700;
}

.your-best {
  min-height: 1.4em;
  margin: 0;
  color: var(--text-muted);
  font-weight: 700;
  text-align: center;
}

.leaderboard > .stack {
  width: min(var(--list-width), 100%);
  margin: 16px 0 0;
}

/* A round button's label is one line (Q2). From 360 to 479px five buttons share a row, so the words are a little smaller there. */
.round-item > span:last-child {
  white-space: nowrap;
}

@media (min-width: 360px) and (max-width: 479px) {
  .round-item {
    font-size: 0.72rem;
  }
}

/* The "No live games" card is not part of the game's two column layout: on a laptop it is centred on the page, not squeezed into
   the column of the player panels (U93). */
@media (min-width: 900px) {
  .watching .no-live {
    grid-column: 1 / -1;
    grid-row: auto;
    justify-self: center;
    margin-top: 48px;
  }

  .watching:has(.no-live:not([hidden])) .stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: none;
    justify-items: center;
  }
}

/* Two buttons side by side in a narrow card: the icon goes at 320px so each label fits inside its button (Q2). */
@media (max-width: 359px) {
  .no-live-actions .btn svg {
    display: none;
  }
}

.no-live-header {
  display: grid;
  justify-items: center;
  gap: 24px;
  width: 100%;
}

.no-live-header[hidden] {
  display: none;
}

.no-live-header .subtitle {
  margin: 0;
  text-align: center;
}

.watching:has(.no-live:not([hidden])) .no-live {
  margin-top: 16px;
}

@media (min-width: 900px) {
  .watching .no-live-header {
    grid-column: 1 / -1;
    justify-self: center;
  }
}

/* Leave game is a quiet button, not the biggest thing under the board (U107). */
.leave-game {
  width: min(320px, 100%);
  justify-self: center;
  margin-inline: auto;
  display: flex;
}


/* At 320px the word "Watching" gives way so both names show whole on one line (U94); it is still read out. */
@media (max-width: 359px) {
  .watching-lead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* The watching screen's status row is as wide as the board, so the banner under the round line has the board's width to use
   and not only the width of the round number and the count beside it (U94). */
.watching .status-row {
  width: 100%;
}


/* ---- The game screen as one centred column (docs/design/game-screen.md U132, U135, Q13) ---- */
/* The header bar holds the opponent and the round (U132); the round line is not centred in the page any more. */
.game .topbar .round-line,
.game .topbar .opponent-heading {
  font: inherit;
  white-space: nowrap;
}

/* The heading is cut with an ellipsis inside the bar, so it never reaches past the screen (U132). */
.game .topbar .opponent-heading {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game .topbar {
  margin-bottom: 8px;
}

.game .status-row:not(:has(> :not([hidden]))) {
  display: none;
}

/* The versus bar: your card, a small VS badge, the opponent's card, as wide as the board. */
.game .players.versus {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  gap: 8px;
  width: 100%;
  margin: 0;
}

/* U154 (changed 31 October 2026): both cards share one layout, avatar on the left, name then status on two lines, with
   at least 12px of padding. */
.game .versus .player {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  padding: 12px;
}

.game .versus .vs {
  align-self: center;
  margin: 0;
}

/* U154: line 1 of a game card is the name and the status icon straight after it: three dots while choosing, a green tick
   once chosen. The name gives way (cut with an ellipsis) so the icon is always whole. */
.game .versus .player-text {
  gap: 1px; /* line 1 (name and icon) and line 2 (power-ups) sit 1px apart, so the cards stay within the laptop's 768px */
}

.player-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.player-line .player-name {
  min-width: 0;
  flex: 0 1 auto;
}

.ready-icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px; /* no taller than the name's line, so the icon adds no height to the card */
}

.ready-icon svg {
  width: 100%;
  height: 100%;
}

.ready-dots {
  fill: var(--text-muted);
}

.ready-tick {
  stroke: var(--ok);
  display: none;
}

.ready-icon[data-state="ready"] .ready-dots {
  display: none;
}

.ready-icon[data-state="ready"] .ready-tick {
  display: block;
}

.opponent-powerups {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.opp-power {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.opp-power .shield-state,
.opp-power .quake-state {
  margin: 0;
  width: 16px;
  height: 16px;
}

/* The board sits directly under the versus bar, with room above it for the ghost disc (U11). The watching screen has no ghost
   disc (U79), so it gives that room back. */
.game:not(.watching) .board-wrap {
  margin: calc(var(--ghost-size) + 2px) 0 4px;
}

.game.watching .board-wrap {
  margin: 8px 0 4px;
}

/* Your power-ups: one row of two compact buttons, each with its info button, centred under the timer (U132). */
.game .powerups {
  display: flex;
  justify-content: center;
  gap: 12px;
  width: 100%; /* U174: the two buttons together are exactly the board's width, edge to edge */
  margin: 12px auto 0;
  padding: 0;
  overflow: visible;
  background: none;
  border: 0;
  box-shadow: none;
}

.game .powerup-row {
  display: flex;
  flex: 1 1 0; /* U174: the two rows share the board's width equally, so the left edge of the first and the right edge of the second are the board's */
  min-width: 0;
  align-items: stretch;
  border: var(--outline);
  border-radius: var(--radius-button);
  box-shadow: var(--shadow); /* U9b: the one button shadow, with no overflow: hidden on the row, so nothing clips it */
  background: var(--panel);
}

.game .powerup-row + .powerup-row {
  border-top: var(--outline);
}

.game .powerups .shield-badge {
  border-radius: calc(var(--radius-button) - 3px) 0 0 calc(var(--radius-button) - 3px); /* the row's inner corners (U9b) */
  flex: 1 1 0;
  min-width: 0;
  width: auto;
  min-height: 48px;
  gap: 8px;
  padding: 4px 12px;
}

.game .powerups .shield-badge svg {
  width: 24px;
  height: 24px;
}

.game .powerups .powerup-info {
  border-radius: 0 calc(var(--radius-button) - 3px) calc(var(--radius-button) - 3px) 0;
  min-width: 44px;
  min-height: 48px;
}

/* Waiting for the second player (U135): only the header bar and the dimmed board with the card over it, the board centred on
   the screen below the bar. */
.game[data-waiting="true"] .powerups,
.game[data-waiting="true"] .players.versus,
.game[data-waiting="true"] .status-row,
.game[data-waiting="true"] .timer-track {
  display: none;
}

.game[data-waiting="true"] .stage {
  align-content: center;
  min-height: calc(100vh - 100px);
}

@media (max-width: 359px) {
  .game .versus .player {
    padding: 12px 6px;
    gap: 6px;
  }

  .game .powerups {
    gap: 8px;
  }

  .game .powerups .shield-badge {
    padding: 4px 8px;
    gap: 6px;
    font-size: 0.9rem;
  }

  .game .topbar {
    gap: 6px;
  }

  .game .topbar-title,
  .game .topbar-right {
    font-size: 0.85rem;
  }
}

/* U132: at 320px the power-up buttons show the short word; the state is still in the button's accessible name (U103). */
.label-short {
  display: none;
}

@media (max-width: 599px) {
  .game .powerups .label-long {
    display: none;
  }

  .game .powerups .label-short {
    display: inline;
  }
}

/* One column, never wider than the screen on a phone, and as wide as the board on a laptop (U132). */
.arena.game {
  width: 100%;
  max-width: 560px;
}

.game .stage,
.game .play-area {
  min-width: 0;
  width: 100%;
}

@media (min-width: 900px) {
  .arena.game {
    max-width: var(--board-width);
  }
}

/* The watching screen at 320 x 568 (U78, U80, U132): the banner and the count share one row under the header bar, and an empty
   result line takes no room, so the board and Watch another game fit the first screen with the widest names. */
@media (max-width: 359px) {
  .game.watching .status-row:not(:has(.shrink-warning:not([hidden]))) {
    flex-wrap: nowrap;
  }

  .game.watching .status-row > .watching-banner {
    min-width: 0;
    flex: 1 1 auto;
  }

  .game.watching .topbar {
    margin-bottom: 4px;
  }
}

/* At 320px the header bar is as short as its 44px Home button allows (Q12, U132). */
@media (max-width: 359px) {
  .topbar {
    min-height: 44px;
  }

  .topbar-home {
    min-height: 44px;
    padding: 0 10px;
    box-shadow: var(--shadow-small);
  }
}

/* U78: at 320px a watching panel's name is at most two lines, cut with an ellipsis. */
@media (max-width: 359px) {
  .game.watching .player-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
  }
}

/* Phone-width fixes found by the phone-tester on 29 October 2026.
   1. A link spectator's notice keeps a whole line of its own, and the watcher count goes under it, so the row never widens the
      page (E4, Q13, U92: the notice is one line and never cut off). */
.game.watching .status-row:has(.spectator-notice:not([hidden])) {
  flex-wrap: wrap !important;
  min-width: 0;
  max-width: 100%;
}

.game.watching .status-row:has(.spectator-notice:not([hidden])) > .spectator-notice {
  flex: 1 0 100%;
  text-align: center;
}

/* 2. "Watch another game" is one line at every width (Q2): its button takes the width it needs. */
.watch-actions .btn {
  white-space: nowrap;
}

@media (max-width: 599px) {
  .watch-actions {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .watch-actions .btn {
    min-width: min(100%, 260px);
  }
}

/* 3. At 320px a game panel's name is at most two lines, so the widest names leave the power-ups on the first screen. */
@media (max-width: 359px) {
  .game:not(.watching) .player-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
  }
}

/* Q5, Q12: the header bar shares its page's content column, so Home lines up with the card or list under it on a laptop. */
.quick > .topbar {
  max-width: min(480px, 100%);
}

.leaderboard > .topbar {
  max-width: min(var(--list-width), 100%);
}

/* Q30, U114a (changed 31 October 2026, refined 9 November 2026): on a laptop the account page is two columns, and its
   left column is end-aligned within its own track, at most 480px wide (the account card sits toward the middle gap,
   not the page edge, U114a). Home sits in a same-width, same-position box in the header bar, so its left edge always
   matches the card's left edge (Q5, Q12): Home moves to meet the card, never the other way round. */
@media (min-width: 900px) {
  .account > .topbar {
    max-width: 1100px;
    gap: 64px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .account > .topbar .topbar-home {
    grid-column: 1;
    justify-self: start;
    /* The same box .account-left sits in (width: 100%, max-width: 480px, justify-self: end): Home sits at its left edge. */
    margin-left: max(0px, calc(100% - 480px));
  }

  .account > .topbar .topbar-title,
  .account > .topbar .topbar-right {
    grid-column: 2;
    display: none; /* the account page passes neither (screens.ts), so these stay empty; Home is the only thing in the bar */
  }
}


/* The power-up rows share the board's width equally (U174, which replaces the "natural width" of U132 and U149): the first row's left
   edge and the second row's right edge are the board's. The labels shrink first, so the info buttons are never clipped. */
.game .powerups {
  min-width: 0;
}

.game .powerup-row {
  flex: 1 1 0;
  min-width: 0;
}


/* ---- Popups, the result and names (Q18 to Q20, U150 to U152) ---- */

/* Q18: 16px between the end popup's edge and its content; the two buttons are stacked full width 12px apart at every size, because
   the 300px card cannot hold two with 12px of clearance round each label and its icon. */
.popup-card {
  padding: 16px;
}

.popup-actions {
  grid-template-columns: 1fr;
  gap: 12px;
}

.popup-actions .btn {
  padding: 0 12px;
}

@media (max-width: 359px) {
  .popup-actions .btn svg {
    display: inline-block;
  }

  .popup-actions .btn {
    padding: 0 12px;
    font-size: 1.1rem;
  }
}

.player-text {
  grid-template-columns: minmax(0, 1fr);
}

/* Q20, U152: a nickname is cut with an ellipsis after two lines; "(you)", when both players share a nickname (R103), stays whole. */
.player-name .pn-you {
  white-space: nowrap;
  color: var(--text-muted);
}

.player-name .pn-nick {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}


/* ---- The keyboard (Q21, U91): the popup follows the visible area, its fields scroll and its buttons stay at the bottom ---- */
.dialog {
  top: var(--vv-top, 0);
  bottom: auto;
  height: var(--vv-height, 100%);
}

.dialog-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 24px 16px 16px;
}

.dialog-form {
  min-height: 0;
  overflow-y: auto;
  align-content: start;
}

/* The buttons stay at the bottom of the form's scrolling area, so a short visible area scrolls the fields, not the buttons. */
.dialog-actions {
  position: sticky;
  bottom: 0;
  background: var(--panel);
  padding-bottom: 8px; /* U9b: the buttons' hard shadow falls inside the scrolling form, never clipped by it */
}


/* ---- Colour avatars, no VS badge and a tidy header on phones (Q22, U153 to U155) ---- */

/* U153: in a game an avatar wears its player's disc colour, with the disc's marker as a badge in its corner. The avatar is not
   clipped any more, so the badge can sit on its corner; the face is clipped by its own svg. */
.avatar[data-colour] {
  position: relative;
  overflow: visible;
}

.avatar[data-colour="red"] {
  background: var(--red);
}

.avatar[data-colour="yellow"] {
  background: var(--yellow);
}

.avatar[data-colour] svg {
  border-radius: var(--radius-pill);
}

.avatar-badge {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 16px;
  height: 16px;
  border: var(--outline-thin);
  border-radius: var(--radius-pill);
  background: var(--panel);
}

.avatar-badge[data-marker="ring"] {
  background: var(--red);
}

.avatar-badge[data-marker="cross"] {
  background: var(--yellow);
}

.avatar-badge[data-marker="ring"]::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: var(--radius-pill);
  border: var(--outline-marker-small);
}

.avatar-badge[data-marker="cross"]::before,
.avatar-badge[data-marker="cross"]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  right: 2px;
  height: 2px;
  margin-top: -1px;
  background: var(--ink);
}

.avatar-badge[data-marker="cross"]::before {
  transform: rotate(45deg);
}

.avatar-badge[data-marker="cross"]::after {
  transform: rotate(-45deg);
}

/* The status line's place is reserved even when empty (before a choice, nobody has chosen yet), so the card does not
   grow when "Chosen" or "Ready" first appears and the other card, matched to it by the grid's stretch, does not move
   (Q25: nothing moves when a disc appears). */
.game .player-meta {
  flex-wrap: nowrap;
  min-height: 1.4em; /* one line at the line-height it would have anyway, so "Chosen" or "Ready" appearing first adds no height */
}

@media (max-width: 599px) {
  /* U154: no VS badge on a phone; the two cards sit side by side with an even gap. */
  .game .players.versus {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
  }

  .game .versus .vs {
    display: none;
  }

  /* The power-ups' names are accessible labels, not visible words: small icons, crossed out once used. */
  .game .opp-power-word {
    display: none;
  }

  .game .opponent-powerups {
    flex-wrap: nowrap;
    gap: 12px;
  }

  /* U155: Home is its house icon only, at least 44px. */
  .topbar-home .topbar-home-word {
    display: none;
  }

  .topbar-home {
    min-width: 44px;
    padding: 0 10px;
  }

  /* U155: Round N is at least 16px from the screen's right edge. */
  .game .topbar {
    padding-right: 10px; /* with the page's own 6 to 8px, 16px or more to the edge */
  }
}


/* Q23, U35a: at least 8px between each round icon's circle and its label (the circle's shadow is 4px, so the gap is larger),
   and room for the labels not to touch at 320px. */
.round-item {
  gap: 12px;
}

@media (max-width: 379px) {
  .round-item {
    min-width: 0;
    font-size: 0.72rem;
  }
}

/* U38: with Top players gone, the right half is vertically centred beside the left half on a laptop. */
@media (min-width: 900px) {
  .home {
    align-items: center;
  }

  .home-right {
    align-self: center;
  }
}


/* ---- The waiting screen (Q9, Q12, Q24, U156): Cancel game is the way out, so there is no Home button ---- */
.game[data-waiting="true"] .topbar-home {
  visibility: hidden; /* kept in the bar so the middle line and the round stay where they are; it cannot be seen or tapped */
  pointer-events: none;
}


/* ---- The waiting card sits within the board (Q24, U156) ---- */
/* The card is about as tall as the board, so a board peeking out above and below it looks like a mistake. While waiting the board
   is dimmed right back (a faint shape, not a second card) and the card is centred on the page and on the board, whose centre it is. */
.game[data-waiting="true"] .board {
  opacity: 0.12;
}

.game[data-waiting="true"] .board-wrap::before,
.game[data-waiting="true"] .board-wrap::after {
  display: none; /* the stand's feet stick out under the board; they have no place behind a card */
}

.game[data-waiting="true"] .board-wrap {
  padding-bottom: 0;
}


/* ---- The friends step's picture (U146, U177, U178): a share card, two arrows, two players and a group of watchers, scaled to fill the
   panel. Everything is sized in the panel's own units (cqw, cqh), so it fills the same share of the panel at the phone's and the laptop's
   board size. Nothing in it is clickable. The picture spans at least 80% of the panel's width and height (Q49). ---- */
.tutorial-friends {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly; /* the rows spread over the whole panel's height */
  padding: 0; /* no padding, so a cqw is 1% of the whole inside width and the rows set their own widths */
  overflow: hidden;
}

.tutorial-friends[hidden] {
  display: none;
}

/* 1. The share card: a code and a Copy link button, shapes only. */
.friend-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2cqw;
  width: 90cqw;
  padding: 3cqh 4cqw;
  box-sizing: border-box;
  background: var(--panel);
  border: var(--outline);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-small);
}

.friend-code {
  font: 700 10.5cqw/1 var(--font-display);
  letter-spacing: 0.1em;
  color: var(--yellow);
}

.friend-copy {
  padding: 2cqh 3.4cqw;
  font: 700 6cqw/1 var(--font-display);
  white-space: nowrap;
  color: var(--ink);
  background: var(--yellow);
  border: var(--outline);
  border-radius: var(--radius-button);
}

/* 2. Two arrows, one over the players and one over the watchers. */
.friend-arrows {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  width: 90cqw;
  justify-items: center;
}

.friend-arrow {
  width: 12cqw;
  height: 12cqw;
  fill: none;
  stroke: var(--text);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 3 and 4. The players on the left and the watchers on the right, with a label under each. */
.friend-below {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  align-items: end;
  gap: 3cqw;
  width: 90cqw;
}

.friend-players,
.friend-watchers {
  display: grid;
  justify-items: center;
  gap: 2cqh;
}

.friend-pair {
  display: flex;
  align-items: center;
  gap: 1cqw;
}

.friend {
  display: grid;
  justify-items: center;
}

.friend .avatar {
  width: 21cqw;
  height: 21cqw;
}

.friend-link {
  width: 5cqw;
  height: 0;
  border-top: var(--outline);
}

.friend-group {
  display: grid;
  grid-template-columns: repeat(2, auto);
  align-items: center;
  justify-content: center;
  justify-items: center;
  gap: 1.6cqw 2cqw;
  width: 100%;
  padding: 2.4cqh 2cqw;
  box-sizing: border-box;
  border: var(--outline);
  border-style: dashed;
  border-radius: var(--radius-panel);
}

.friend-eye {
  width: 11cqw;
  height: 11cqw;
  fill: var(--text);
}

.friend-small {
  width: 11cqw;
  height: 11cqw;
}

.friend-label {
  font: 700 max(14px, 5.6cqw)/1.1 var(--font-display);
  color: var(--text);
  text-align: center;
}

/* ---- The game screen's fixed vertical order (U157, Q25) ----
   header bar, 16px, versus bar, 16px, the ghost lane (one disc tall), 8px, the board, 12px, the timer bar, 16px, the power-up row.
   The lane is the board's top margin, so the disc floats in it and nothing else ever does. */
.game .message:empty {
  display: none;
}

.arena.game {
  padding: 8px 0;
}

.game .topbar {
  margin-bottom: 16px;
}

.game .players.versus {
  margin: 0;
}

.game:not(.watching) .board-wrap {
  margin: calc(var(--ghost-size) + 8px) 0 12px; /* the lane (one disc tall), then 8px to the board; the 16px above it is the versus bar's */
  padding-bottom: 0;
}

.game:not(.watching) .players.versus {
  margin-bottom: 16px;
}

.game:not(.watching) .stage {
  gap: 0; /* the gaps are the fixed ones of U157, never an extra grid gap */
}

.game .timer-track {
  margin: 0 0 16px;
}

/* U151: the result line and the message line are visually hidden or empty, so they no longer hold the space below the
   power-up row; this keeps the 16px clearance to the bottom of the screen explicit instead. */
.game .powerups {
  margin: 0 auto 16px;
}

/* On a laptop the board is at least 60% of the screen's height (Q26, U158): its width is 7/6 of its height, and the whole
   column shares that width. The ghost lane is 40px so the whole screen still fits 768px with no scrolling (Q15). */
@media (min-width: 900px) {
  :root {
    /* U154's 12px card padding (added 31 October 2026) made the versus bar taller than before, which this lane size
       and board formula did not leave room for alongside U151's 16px below the power-up row; the lane shrinks a
       little to give that room back, never below a disc that still reads clearly (Q15, Q25). */
    --ghost-size: 28px;
    --board-width: min(620px, calc(100vh * 0.6 * 7 / 6 - 4px));
  }

  .arena.game {
    padding: 4px 0 0;
  }

  .arena.game .topbar {
    min-height: 44px;
  }

  .arena.game .topbar .topbar-home {
    min-height: 44px;
  }

  .game .versus .player {
    padding: 12px;
    align-content: center;
  }

  .game .player-meta {
    line-height: 1.1;
    min-height: 1.1em; /* matches this line-height, so the reserved line is exactly one line tall here too */
  }

  .game .versus .avatar {
    width: 40px;
    height: 40px;
  }

  /* The power-up buttons are 48px tall and equal (U158). */
  .game .powerups .shield-badge,
  .game .powerups .powerup-info {
    min-height: 44px;
    height: 44px;
  }

  .game .powerup-row {
    min-height: 0;
  }

  /* The opponent's power-ups sit beside their status on one line, so the two cards are the same height (U158, U154). */
  .game .opponent-powerups {
    flex-wrap: nowrap;
  }

  .game .powerups {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
  }

  .game .powerup-row {
    width: 100%;
  }

  .game .powerups .shield-badge {
    flex: 1 1 auto;
    width: 100%;
  }
}

@media (max-width: 899px) and (max-height: 700px) {
  .arena.game {
    padding: 4px 0 0;
  }
}

/* The game's board has no stand padding under it any more (U157), so the tap and glow layers end at the frame, not 20px above it. */
.game:not(.watching) .columns-hit,
.game:not(.watching) .columns-glow {
  bottom: var(--frame);
}

.game:not(.watching) .board-wrap::before {
  display: none; /* the stand's feet hung into the 12px gap under the board */
}

.game:not(.watching) .board-wrap::after {
  display: none;
}


/* ---- One backdrop behind every popup and overlay, and a card edge that stands out (Q27, U52a, U52b) ---- */
/* The dialogs, the tutorial and the end popup already cover what is behind them with --backdrop (above). The cards that sit on the
   board itself (the waiting card, the countdown, the watching screen's result) get the same backdrop as a layer over the whole
   board behind them, so the board is pushed back, not just shaded by the card's own shadow. */
.share,
.get-ready,
.watch-result {
  box-shadow: var(--shadow-popup);
}

.board-wrap:has(> .share:not([hidden]))::after,
.board-wrap:has(> .get-ready:not([hidden]))::after,
.board-wrap:has(> .watch-result:not([hidden]))::after {
  /* The shared backdrop over the whole screen, painted by the board's wrapper just under the card (which has z-index 6), so the
     card keeps its own colour and the board and page are pushed back. It replaces the board's feet, which sit in this slot. */
  display: block !important; /* wins over the rules that remove the stand's feet from this slot */
  content: "";
  position: fixed;
  inset: 0;
  width: auto;
  height: auto;
  z-index: 5;
  background: var(--backdrop);
  border: 0;
  border-radius: 0;
  pointer-events: none;
}

.dialog-card,
.popup-card,
.share,
.get-ready,
.watch-result,
.no-live {
  border: var(--outline-popup);
  box-shadow: var(--shadow-popup);
}

/* The tutorial's card has the popup edge on a laptop only: on a phone it is full screen with no edge (U176). */
@media (min-width: 600px) {
  .tutorial-card {
    border: var(--outline-popup);
    box-shadow: var(--shadow-popup);
  }
}


/* ---- The Rubble title above the waiting card (U163, Q37) ----
   It hangs off the card's top edge (the card is positioned), 16px above it, so the card itself stays centred and inside the board. */
.waiting-logo {
  position: absolute;
  bottom: calc(100% + 16px + 5px); /* the card's 5px popup border (--outline-popup) is outside the box this is measured from */
  left: -5px;
  right: -5px;
  pointer-events: none;
}

.waiting-logo .title {
  margin: 0 auto;
  font-size: clamp(40px, min(16vw, 12dvh), 64px);
}

/* Nothing on the game screen until the server has said what the game is (U168, R101). The page is the same for every game and starts
   with its waiting card in the markup, so without this a computer game showed the share link until the first message arrived. It is
   hidden with visibility, not display, so nothing moves when it shows. */
.game[data-known="false"] {
  visibility: hidden;
}

