/*
 * Look: Flow Free's black-and-white minimalism, sharpened. Pure black, white
 * type, hairline rules, square corners. Colour comes only from the game's
 * own pipe palette: the board, the logo, and the board-size menu.
 */
:root {
  --bg: #000;
  --raise: #0d0d0d;
  --line: #262626;
  --line-strong: #4d4d4d;
  --text: #fff;
  --muted: #8f8f8f;
  --dim: #555;

  /* Pipe palette (matches client/render.ts). */
  --red: #ff3b3b;
  --green: #1fbf3a;
  --blue: #3b6bff;
  --yellow: #f2e01d;
  --orange: #ff9416;
  --cyan: #28e6f0;
  --magenta: #ff3df2;
  --purple: #b06bff;

  --good: var(--green);
  --bad: var(--red);
  --warn: var(--yellow);

  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* No double-tap zoom on buttons; no edge-swipe back/forward navigation mid-drag. */
html { touch-action: manipulation; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
::selection { background: #fff; color: #000; }

/* During a race the page is a fixed-height column: no scrolling, no pull-to-refresh. */
body.in-match { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
body.in-match main {
  flex: 1; min-height: 0; width: 100%; max-width: 900px; display: flex; flex-direction: column;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
body.in-match #screen-match { flex: 1; min-height: 0; gap: 12px; -webkit-user-select: none; user-select: none; }
@media (max-height: 760px) {
  body.in-match .topbar { display: none; }
  body.in-match main { padding-top: max(10px, env(safe-area-inset-top)); }
}
[hidden] { display: none !important; }

/* ---------- Controls ---------- */
button, input { font: inherit; color: inherit; }
button {
  border: 1px solid transparent;
  border-radius: 0;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: .01em;
  transition: transform .06s, background-color .15s, border-color .15s, color .15s, opacity .15s;
}
button:active:not(:disabled) { transform: scale(.98); }
button:disabled { opacity: .35; cursor: default; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.primary { background: #fff; color: #000; }
.secondary { background: transparent; border-color: var(--line-strong); color: var(--text); }
.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.big { width: 100%; padding: 15px; font-size: 16px; margin-top: 14px; }

input {
  font-size: 16px; /* Below 16px, iOS zooms the page on focus. */
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  padding: 10px 12px;
  width: 100%;
  transition: border-color .15s;
}
input:focus { border-color: #fff; outline: none; }
input::placeholder { color: var(--dim); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  max-width: 620px;
  margin: 0 auto;
}
.logo { font: 800 24px/1 var(--font-display); letter-spacing: -.045em; text-transform: lowercase; }
.logo .f { color: var(--red); }
.logo .l { color: var(--yellow); }
.logo .o { color: var(--blue); }
.logo .w { color: var(--green); }
.logo .race { color: #fff; margin-left: .06em; }
.topbar .me { margin-left: auto; color: var(--muted); font-size: 12px; text-align: right; line-height: 1.3; }
.topbar .me b { color: var(--text); font-size: 13px; }
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.conn i { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.conn[data-status="online"] i { background: var(--good); }
.conn[data-status="online"] span { display: none; }
.conn[data-status="offline"] i, .conn[data-status="replaced"] i { background: var(--bad); }

.icon-btn { background: transparent; border: 1px solid var(--line); color: var(--muted); padding: 0; width: 32px; height: 32px; display: grid; place-items: center; }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn[aria-pressed="true"] { color: var(--bad); }

main { max-width: 620px; margin: 0 auto; padding: 0 16px 32px; }
.screen { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Panels & type ---------- */
.panel {
  background: transparent;
  border: 1px solid var(--line);
  padding: 18px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
h2 { margin: 0; font: 700 19px/1.2 var(--font-display); letter-spacing: -.02em; }
.label { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin: 14px 0 8px; }
.field .label { margin-top: 0; }
.hint { color: var(--muted); font-size: 13px; }
.center { text-align: center; }

/* ---------- Board-size and time pickers ---------- */
/* Each size has its own pipe colour, like the pack list in the original. */
.option-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.option-grid .option:nth-child(1) { --c: var(--red); }
.option-grid .option:nth-child(2) { --c: var(--green); }
.option-grid .option:nth-child(3) { --c: var(--blue); }
.option-grid .option:nth-child(4) { --c: var(--yellow); }
.option-grid .option:nth-child(5) { --c: var(--orange); }
.option-grid .option:nth-child(6) { --c: var(--magenta); }
.option-grid .option:nth-child(7) { --c: var(--purple); }
.option-grid .option:nth-child(8) { --c: var(--cyan); }
.option {
  background: transparent;
  border: 1px solid var(--line);
  padding: 12px 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.option .opt-main { font: 700 18px/1.2 var(--font-display); letter-spacing: -.02em; color: var(--c, #fff); }
.option .opt-sub { font-size: 11px; font-weight: 500; color: var(--muted); }
.option .opt-sub.live { color: var(--good); }
.opt-icon { width: 24px; height: 24px; color: var(--dim); margin-bottom: 4px; transition: color .15s; }
.option[aria-pressed="true"] { border-color: var(--c, #fff); background: color-mix(in srgb, var(--c, #fff) 10%, transparent); }
.option[aria-pressed="true"] .opt-icon { color: var(--c, #fff); }

.segmented { display: flex; border: 1px solid var(--line); margin-top: 8px; }
.segmented button { flex: 1; background: transparent; padding: 9px; color: var(--muted); border: 0; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: #fff; color: #000; }

/* ---------- Queue ---------- */
.queue-status { display: flex; align-items: center; gap: 14px; margin-top: 14px; padding: 14px; border: 1px solid #fff; }
.queue-text { display: flex; flex-direction: column; flex: 1; }
.queue-text span { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line-strong); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.friends-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.friends-row > button { flex: 1 1 140px; }
.join-form { display: flex; gap: 8px; flex: 1 1 200px; }
.join-form input { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; text-align: center; min-width: 0; }

.rules summary { cursor: pointer; font-weight: 600; list-style-position: inside; }
.rules ul { margin: 12px 0 0; padding-left: 18px; color: var(--muted); }
.rules li { margin: 5px 0; }
.rules b { color: var(--text); font-weight: 600; }

/* ---------- Lobby ---------- */
.code-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.code { font: 700 38px/1 var(--font-display); letter-spacing: .28em; font-variant-numeric: tabular-nums; }
.members { list-style: none; margin: 0; padding: 0; }
.members li { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-top: 1px solid var(--line); }
.members li:last-child { border-bottom: 1px solid var(--line); }
.members .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.members .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.members .tag { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); border: 1px solid var(--line-strong); padding: 2px 6px; }
.members .state { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); }
.members .state.ready { color: var(--good); }
.lobby-actions { display: flex; gap: 8px; align-items: stretch; }
.lobby-actions .big { margin-top: 0; flex: 1; }
.lobby-actions .ghost { flex: none; }
#ready-btn.is-ready { background: var(--good); color: #000; }

/* ---------- Race ---------- */
.hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; }
.hud-block .label { margin: 0 0 2px; }
.hud-block strong { font: 700 28px/1 var(--font-display); font-variant-numeric: tabular-nums; display: inline-block; }
.hud-block.right { text-align: right; }
.hud-timer { font: 700 46px/1 var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.hud-timer.low { color: var(--bad); }

.opponents { display: flex; flex-direction: column; gap: 6px; }
.opp { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; align-items: center; border: 1px solid var(--line); padding: 9px 12px; transition: border-color .2s; }
.opp-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.opp-name small { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 12px; }
.opp-score { font: 700 20px/1 var(--font-display); font-variant-numeric: tabular-nums; }
.opp-bar { grid-column: 1 / -1; height: 2px; background: var(--line); overflow: hidden; }
.opp-bar i { display: block; height: 100%; background: #fff; transition: width .25s ease-out; }
.opp.offline { opacity: .4; }
.opp.ahead .opp-score { color: var(--bad); }
.opp.pb .opp-name { color: var(--muted); }
.opp.pb.beaten { border-color: var(--good); }
.opp.pb.beaten .opp-score { color: var(--good); }

/* The board takes whatever space is left and stays square, so the whole race fits on screen. */
.board-wrap { flex: 1 1 auto; min-height: 200px; container-type: size; display: flex; align-items: center; justify-content: center; }
.board-box { position: relative; width: min(100cqw, 100cqh); aspect-ratio: 1; }
#board {
  width: 100%; height: 100%; display: block; cursor: default;
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(0, 0, 0, .85); text-align: center; pointer-events: none; }
.overlay.solid { background: #000; }
/* "GO!" floats over the live board without hiding or blocking it. */
.overlay.go { background: transparent; }
.overlay.go .overlay-big { text-shadow: 0 0 40px #000, 0 0 12px #000; animation: go-out .7s ease-out forwards; }
.overlay-big.tick { animation: tick-pop .35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes tick-pop { from { transform: scale(1.5); opacity: .2; } to { transform: scale(1); opacity: 1; } }
@keyframes go-out { 0% { transform: scale(.6); opacity: 0; } 25% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1.5); opacity: 0; } }
.overlay-vs { font: 600 18px/1.3 var(--font-display); margin-bottom: 14px; }
.overlay-vs .vs { color: var(--muted); font-weight: 400; margin: 0 10px; text-transform: uppercase; font-size: 12px; letter-spacing: .14em; }
.overlay-big { font: 700 104px/1 var(--font-display); letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.overlay-small { color: var(--muted); margin-top: 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .14em; }

.board-info { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; font-variant-numeric: tabular-nums; }
#board-worth { color: #fff; }
.match-actions { display: flex; gap: 8px; }
.match-actions button { flex: 1; min-height: 48px; }
/* In a row layout the undo/clear pair just joins the row; the sidebar layout stacks it. */
.action-row { display: contents; }

.score-pop { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(1.4); color: var(--good); } 100% { transform: scale(1); } }

/* ---------- Results ---------- */
.result-head { text-align: center; padding: 26px 0 8px; }
.result-title { font: 800 46px/1.05 var(--font-display); letter-spacing: -.04em; }
.result-title.win { color: var(--good); }
.result-title.loss { color: var(--bad); }
.result-sub { color: var(--muted); margin-top: 8px; }
.result-sub .delta-up { color: var(--good); font-weight: 700; }
.result-sub .delta-down { color: var(--bad); font-weight: 700; }

/* Standings and leaderboard share one ruled-table look. */
.standings, .leaderboard { list-style: none; margin: 0; padding: 0; }
.standings li, .leaderboard li { display: grid; gap: 12px; align-items: center; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.standings li:last-child, .leaderboard li:last-child { border-bottom: 1px solid var(--line); }
.standings li.me, .leaderboard li.me { box-shadow: inset 3px 0 0 #fff; }
.standings li { grid-template-columns: 34px minmax(0, 1fr) auto; padding: 12px 12px; }
.standings .place { font: 700 20px/1 var(--font-display); color: var(--dim); }
.standings li:first-child .place { color: #fff; }
.standings .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.standings .who small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.standings .pts { font: 700 24px/1 var(--font-display); }
.result-actions { display: flex; flex-direction: column; gap: 8px; }
.result-actions .big { margin-top: 0; }

.leaderboard { margin-top: 6px; }
.leaderboard li { grid-template-columns: 28px minmax(0, 1fr) auto; padding: 9px 10px; }
.leaderboard .rank { color: var(--dim); font-weight: 700; }
.leaderboard li:nth-child(1) .rank { color: var(--yellow); }
.leaderboard li:nth-child(2) .rank, .leaderboard li:nth-child(3) .rank { color: #fff; }
.leaderboard .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard .who small { color: var(--dim); margin-left: 8px; font-size: 12px; }
.leaderboard .rating { font-weight: 700; }
.leaderboard li.empty { display: block; border: 0; color: var(--muted); padding: 6px 0; }

/* ---------- Toast & banner ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #fff; color: #000; font-weight: 600;
  padding: 11px 18px; max-width: calc(100% - 32px); z-index: 30;
}
.banner {
  position: fixed; inset: 0; display: flex; flex-direction: column; gap: 16px; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .94); text-align: center; padding: 24px; z-index: 10;
}

/* ---------- Home pieces ---------- */
.play-buttons { display: grid; gap: 8px; margin-top: 16px; }
.play-buttons .big { margin-top: 0; }
.practice-btn { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.practice-btn small { font-size: 12px; font-weight: 500; color: var(--muted); }
.practice-btn small:empty { display: none; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 14px; border: 1px solid var(--line); }
.stats > div { padding: 10px 12px; min-width: 0; }
.stats > div + div { border-left: 1px solid var(--line); }
.stats .label { margin: 0 0 4px; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats strong { font: 700 22px/1 var(--font-display); font-variant-numeric: tabular-nums; }

/* Shortcut chips only make sense with a keyboard and a precise pointer. */
kbd { display: none; font: 600 10px/1 ui-monospace, "Cascadia Mono", Consolas, monospace; padding: 3px 5px; margin-left: 8px; border: 1px solid currentColor; opacity: .45; vertical-align: 2px; }
.shortcuts { display: none; margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.shortcuts kbd { margin: 0 1px; }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }

/* ---------- Motion ---------- */
.screen:not([hidden]) { animation: screen-in .22s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.hud-timer.low { animation: timer-pulse 1s ease-in-out infinite; }
@keyframes timer-pulse { 50% { opacity: .55; } }

.opp.scored { animation: opp-scored .6s ease-out; }
@keyframes opp-scored { 0% { border-color: var(--bad); background: rgba(255, 59, 59, .12); } 100% { background: transparent; } }
.opp.scored .opp-score { animation: pop .4s ease-out; }

.result-title { animation: title-in .45s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes title-in { from { transform: translateY(10px) scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
.standings li { animation: row-in .3s ease-out backwards; animation-delay: calc(var(--i, 0) * 60ms + 120ms); }
@keyframes row-in { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }

/* ---------- Modes & twists ---------- */
.mode-hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; min-height: 1.45em; }
.twists { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.twist { background: transparent; border: 1px solid var(--line); color: var(--muted); padding: 9px 4px; font-size: 14px; }
.twist[aria-pressed="true"] { background: #fff; border-color: #fff; color: #000; }
@media (max-width: 420px) { .twists { grid-template-columns: repeat(2, 1fr); } }

/* Tug of war: you pull right, they pull left. The knot is a square, like everything else. */
.rope { border: 1px solid var(--line); padding: 10px 12px 12px; }
.rope-names { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.rope-names span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rope-names .you { color: #fff; }
.rope-track { position: relative; height: 16px; margin: 8px 0 6px; }
.rope-track::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 2px; transform: translateY(-50%); background: var(--line-strong); }
.rope-track .mid { position: absolute; left: 50%; top: 2px; bottom: 2px; width: 1px; background: var(--muted); }
.rope-track .goal { position: absolute; top: 0; bottom: 0; width: 3px; }
.rope-track .goal.them { left: 0; background: var(--bad); }
.rope-track .goal.you { right: 0; background: var(--good); }
.rope-knot { position: absolute; top: 50%; width: 14px; height: 14px; background: #fff; transform: translate(-50%, -50%); transition: left .4s cubic-bezier(.2, 1.4, .4, 1), background-color .2s; }
.rope.winning .rope-knot { background: var(--good); }
.rope.losing .rope-knot { background: var(--bad); }
.rope-text { font-size: 12px; color: var(--muted); text-align: center; }

.opp.out { opacity: .35; }
.opp.out .opp-name { text-decoration: line-through; }
.opp.done .opp-name small { color: var(--good); }

/* ---------- Mouse & keyboard ---------- */
@media (hover: hover) and (pointer: fine) {
  kbd { display: inline-block; }
  .shortcuts { display: block; }
  .primary:hover:not(:disabled) { background: #d6d6d6; }
  .secondary:hover:not(:disabled) { border-color: #fff; }
  .ghost:hover:not(:disabled) { color: #fff; border-color: var(--line-strong); }
  #ready-btn.is-ready:hover:not(:disabled) { background: #3ad655; }
  .option:hover:not(:disabled):not([aria-pressed="true"]) { border-color: var(--line-strong); background: var(--raise); }
  .option:hover:not(:disabled) .opt-icon { color: var(--c, #fff); }
  .segmented button:hover:not(:disabled):not([aria-pressed="true"]) { color: #fff; background: var(--raise); }
  .twist:hover:not(:disabled):not([aria-pressed="true"]) { color: #fff; border-color: var(--line-strong); }
  .icon-btn:hover { color: #fff; border-color: var(--line-strong); }
  .leaderboard li:not(.empty):hover, .members li:hover { background: var(--raise); }
  .rules summary:hover { color: var(--muted); }
}

/* ---------- Desktop layout ---------- */
@media (min-width: 1000px) {
  .topbar, main { max-width: 1140px; }
  .topbar { padding: 22px 24px 18px; }
  .logo { font-size: 30px; }
  main { padding: 0 24px 40px; }

  /* Home becomes a dashboard: playing on the left, you and your friends on the right. */
  #screen-home {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "play  profile"
      "play  friends"
      "play  ranks"
      "rules ranks";
    gap: 16px 20px;
    align-items: start;
  }
  #screen-home .profile { grid-area: profile; }
  #screen-home .play { grid-area: play; padding: 28px 30px 30px; }
  #screen-home .friends { grid-area: friends; }
  #screen-home .ranks { grid-area: ranks; }
  #screen-home .rules { grid-area: rules; }
  /* The topbar's name/rating repeats the profile card here. */
  body[data-screen="home"] .topbar .me { visibility: hidden; }

  .play h2 { font-size: 30px; letter-spacing: -.035em; }
  .play .option-grid { gap: 10px; }
  .play .option { padding: 18px 8px 14px; }
  .play .option .opt-main { font-size: 21px; }
  .play .opt-icon { width: 30px; height: 30px; }
  .play .segmented button { padding: 11px; }
  .play-buttons { grid-template-columns: 3fr 2fr; margin-top: 20px; }
  .play-buttons .big { padding: 17px; }
  .friends .friends-row { flex-direction: column; }
  .friends .friends-row > button, .friends .join-form { flex: none; }

  /* Lobby: who's in on the left, what you're racing on the right. */
  #screen-lobby {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "code    settings"
      "players settings"
      "players actions"
      "hint    hint";
    gap: 16px 20px;
    align-items: start;
    max-width: 980px;
    width: 100%;
    margin: 0 auto;
  }
  #screen-lobby .lobby-code { grid-area: code; }
  #screen-lobby .lobby-players { grid-area: players; }
  #screen-lobby .lobby-settings { grid-area: settings; }
  #screen-lobby .lobby-actions { grid-area: actions; }
  #screen-lobby .lobby-hint { grid-area: hint; margin: 0; }

  #screen-result { max-width: 720px; width: 100%; margin: 0 auto; }
  .result-title { font-size: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 420px) {
  .hud-timer { font-size: 38px; }
  .hud-block strong { font-size: 24px; }
  .code { font-size: 30px; }
  .opp { padding: 7px 10px; }
  .overlay-big { font-size: 84px; }
}

/* Landscape tablets and laptops (e.g. Surface): board at full height, everything else in a sidebar. */
@media (orientation: landscape) and (min-width: 820px) {
  /* Wide enough for a full-height square board plus the 300px sidebar, and no wider,
     so the two sit together in the middle of the screen. */
  body.in-match main { max-width: calc(100dvh + 280px); }
  body.in-match #screen-match {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "board hud"
      "board opps"
      "board info"
      "board actions";
    gap: 14px 28px;
  }
  body.in-match .board-wrap { grid-area: board; min-height: 0; }
  body.in-match .hud { grid-area: hud; padding-top: 6px; }
  body.in-match .opponents { grid-area: opps; overflow-y: auto; align-content: start; }
  body.in-match .board-info { grid-area: info; }
  body.in-match .match-actions { grid-area: actions; flex-direction: column; }
  body.in-match .action-row { display: flex; gap: 8px; }
  body.in-match .match-actions button { min-height: 54px; font-size: 15px; }
  body.in-match .match-actions #skip-btn { order: -1; }
}
