:root {
  /* Studio (variation A) palette — editorial dark with wheat reserve bars. */
  --bg: #25211d;
  --page-bg: #15120f;
  --panel: #25211d;
  --pocket-bg: #c9b896;
  --board-light: #e8dec8;
  --board-dark: #a78760;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-mid: rgba(255, 255, 255, 0.08);
  --text: #ece7df;
  --text-bright: #ffffff;
  --muted: #8a8278;
  --active: #e8b04b;
  --warn: #e8b04b;
  --ok: #6cbf52;
  --danger: #e36a4a;
  --name-bar-h: 56px;
  --pieces-bar-h: 68px;
  --pocket-icon: 64px;
  --eval-white: #efe8d9;
  --eval-black: #1c1814;
  /* Match `.eval-bar-vertical` + `.board-row` gap — used to pin name/pieces
   * strips to the same width as the chessboard column (excluding eval bar). */
  --eval-bar-w: clamp(15px, 1.3vw, 20px);
  --board-row-gap: clamp(4px, 0.5vw, 8px);
  --board-max: 550px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Geist", "Helvetica Neue", system-ui, sans-serif;
  color: var(--text);
  background: var(--page-bg);
}

.page-overlay {
  min-height: 100vh;
  padding: 0;
  font-family: "Geist", "Helvetica Neue", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  background: var(--bg);
  color: var(--text);
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding: 0 clamp(20px, 3vw, 80px);
  height: 88px;
  border-bottom: 1px solid var(--border-subtle);
}

.header-brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rules-pill {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.site-title {
  margin: 0;
  font-size: clamp(20px, 1.6vw, 32px);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text);
  line-height: 1.05;
}

.header-status {
  text-align: right;
  min-width: 12rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.header-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-btn {
  margin: 0;
  padding: 6px;
  border-radius: 3px;
  border: 1px solid var(--border-mid);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  line-height: 0;
}
.header-btn--text {
  padding: 8px 14px;
  line-height: 1.2;
  font-family: "Geist", "Helvetica Neue", system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.header-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-bright);
  border-color: rgba(255, 255, 255, 0.18);
}
.header-btn.is-on {
  background: rgba(232, 176, 75, 0.12);
  color: var(--active);
  border-color: rgba(232, 176, 75, 0.35);
}
.header-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.header-select {
  margin: 0;
  padding: 8px 10px;
  border-radius: 3px;
  border: 1px solid var(--border-mid);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-family: "Geist", "Helvetica Neue", system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.header-select:hover,
.header-select:focus {
  color: var(--text-bright);
  border-color: rgba(255, 255, 255, 0.18);
  outline: none;
}

.move-status {
  margin: 0;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--warn);
  min-height: 0.95em;
  font-weight: 600;
  line-height: 1.35;
}

.conn-status {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--muted);
}
.conn-status.ok {
  color: var(--ok);
}
.conn-status.bad {
  color: var(--danger);
}

.overlay-grid {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(20px, 4vw, 80px);
  padding: clamp(20px, 3vw, 56px) clamp(20px, 3vw, 80px);
  flex-wrap: wrap;
}

/* When the view is flipped to Team 2's perspective each stack reverses
 * its top↔bottom bars (board orientation itself is set on cm-chessboard). */
.board-stack.is-flipped {
  flex-direction: column-reverse;
}

.board-stack {
  container-type: inline-size;
  --board-col-w: 100cqw;
  --board-square: calc(var(--board-col-w) / 8);
  --reserve-icon: min(var(--pocket-icon), var(--board-square));
  --reserve-bar-h: max(34px, calc(var(--reserve-icon) + 4px));
  position: relative;
  display: flex;
  flex-direction: column;
  width: clamp(320px, 42vw, var(--board-max));
  flex-shrink: 0;
}

body.engine-ui-on .board-stack {
  --board-col-w: calc(100cqw - var(--eval-bar-w) - var(--board-row-gap));
}

/* With engine UI on, name/pieces strips match the chessboard column width
 * (board-wrap only). Board B keeps eval on the left — inset strips so they
 * line up with the board. With engine off, eval + lines are hidden and strips
 * span full stack width so the board grows by `--eval-bar-w` + gap. */
body.engine-ui-on .name-bar,
body.engine-ui-on .pieces-bar {
  width: calc(100% - var(--eval-bar-w) - var(--board-row-gap));
  max-width: calc(100% - var(--eval-bar-w) - var(--board-row-gap));
  align-self: flex-start;
}
body.engine-ui-on .board-stack[data-board="B"] .name-bar,
body.engine-ui-on .board-stack[data-board="B"] .pieces-bar,
body.engine-ui-on .board-stack[data-board="B"] .engine-lines {
  margin-left: calc(var(--eval-bar-w) + var(--board-row-gap));
}
body.engine-ui-on .engine-lines,
body.engine-ui-on .move-list {
  width: calc(100% - var(--eval-bar-w) - var(--board-row-gap));
  max-width: calc(100% - var(--eval-bar-w) - var(--board-row-gap));
  align-self: flex-start;
}
body.engine-ui-on .board-stack[data-board="B"] .move-list {
  margin-left: calc(var(--eval-bar-w) + var(--board-row-gap));
}

body:not(.engine-ui-on) .eval-bar-vertical {
  display: none !important;
}
body:not(.engine-ui-on) .engine-lines {
  display: none !important;
}

.hidden {
  display: none !important;
}

.board-wrap {
  position: relative;
  width: 100%;
}

.chessboard-container {
  width: 100%;
  aspect-ratio: 1;
}

/* cm-chessboard theme override — Studio wheat board. */
.cm-chessboard.default .board .square.white {
  fill: var(--board-light);
}
.cm-chessboard.default .board .square.black {
  fill: var(--board-dark);
}
.cm-chessboard.default.border-type-thin .board .border,
.cm-chessboard.default.border-type-none .board .border {
  fill: var(--board-dark);
  stroke: var(--board-dark);
}
.cm-chessboard.default .coordinates .coordinate.black {
  fill: var(--board-light);
}
.cm-chessboard.default .coordinates .coordinate.white {
  fill: var(--board-dark);
}

/* Last-move highlight — square fill change (Lichess-style), no marker frame. */
.cm-chessboard .board .square.last-move-from.white,
.cm-chessboard .board .square.last-move-to.white {
  fill: #e7d16a;
}
.cm-chessboard .board .square.last-move-from.black,
.cm-chessboard .board .square.last-move-to.black {
  fill: #b09038;
}

/* Name bar — colored by side (white/black). */
.name-bar {
  height: var(--name-bar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 0 0 18px;
  width: 100%;
  box-sizing: border-box;
}
.name-bar[data-side="white"] {
  background: var(--board-light);
  color: #0e0c0a;
}
.name-bar[data-side="black"] {
  background: #0e0c0a;
  color: var(--text-bright);
}
.name-bar .player-name {
  flex: 1;
  font-size: clamp(16px, 2vw, 23px);
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.05;
}
/* Right-hand 90px slot for clock time / match-result. Always rendered
 * so the player-name column never shifts. The slot is full-width for
 * clock readouts; result text gets a 10px inner padding so the colored
 * pill doesn't run flush to the edges. */
.name-bar-meta {
  flex: 0 0 90px;
  width: 90px;
  box-sizing: border-box;
  height: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: clamp(15px, 1.2vw, 22px);
  letter-spacing: 0.04em;
  text-align: center;
  padding: 0;
}
.name-bar-meta.is-empty {
  background: transparent;
}
.name-bar-meta.is-clock-run {
  background: rgba(232, 176, 75, 0.22);
  color: var(--text-bright);
  box-shadow: 0 0 0 1px rgba(232, 176, 75, 0.35) inset;
}

.replay-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 16px;
  margin: 0 clamp(12px, 2vw, 24px) 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}

.replay-nav-short {
  display: none;
}

@media (max-width: 640px) {
  .replay-bar {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    gap: 0 6px;
    padding: 8px 10px;
  }

  .replay-bar .replay-bar-vrule {
    display: none;
  }

  .replay-bar .replay-nav-btn.btn-secondary {
    flex: 0 0 auto;
    min-width: 2.75rem;
    padding: 8px 12px;
    font-size: 15px;
    line-height: 1;
  }

  .replay-bar .replay-nav-long {
    display: none;
  }

  .replay-bar .replay-nav-short {
    display: inline;
  }

  .replay-truncate-btn {
    flex: 0 0 auto;
    margin-left: 0;
    white-space: nowrap;
  }
}
.replay-bar-sep {
  opacity: 0.35;
  padding: 0 0.25rem;
  user-select: none;
}

.replay-bar-vrule {
  width: 1px;
  align-self: stretch;
  min-height: 1.25rem;
  margin: 0 4px;
  background: var(--border-subtle);
  flex-shrink: 0;
}

.replay-bar-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-right: 4px;
}

.analysis-engine-bar {
  justify-content: flex-end;
}

.replay-truncate-btn {
  margin-left: auto;
}

.replay-truncate-btn[hidden] {
  display: none;
}

.replay-scrub {
  flex: 1 1 160px;
  min-width: 120px;
  accent-color: var(--active);
}
.replay-counter {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--text-bright);
  min-width: 4.5em;
}
body.replay-mode .pocket-pieces {
  pointer-events: none;
}
.name-bar[data-side="white"] .name-bar-meta.is-clock-run {
  color: #0e0c0a;
}
.name-bar[data-side="black"] .name-bar-meta.is-clock-run {
  color: #f3ece0;
}
.name-bar-meta.is-winner,
.name-bar-meta.is-loser,
.name-bar-meta.is-draw {
  padding: 0 10px;
}
.name-bar-meta.is-winner {
  background: rgba(76, 175, 80, 0.85);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18) inset;
}
.name-bar-meta.is-loser {
  background: rgba(220, 70, 70, 0.6);
  color: #fff;
}
.name-bar-meta.is-draw {
  background: rgba(232, 176, 75, 0.72);
  color: #17100a;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16) inset;
}

/* Active dot — only visible on the side to move. */
.active-dot {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.name-bar.is-active .active-dot::before {
  content: "";
  display: block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--active);
  box-shadow: 0 0 0 4px rgba(232, 176, 75, 0.22);
}
.name-bar[data-side="white"].is-active .active-dot::before {
  background: #f3ece0;
}
.name-bar[data-side="black"].is-active .active-dot::before {
  background: #0e0c0a;
}

/* Match / overlay boards — compact name rows on phones */
@media (max-width: 720px) {
  .page-overlay {
    --name-bar-h: auto;
  }

  .page-overlay .name-bar {
    min-height: 36px;
    height: auto;
    gap: 6px;
    padding: 3px 0 3px 8px;
    align-items: center;
  }

  .page-overlay .name-bar .player-name {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    white-space: normal;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }

  .page-overlay .active-dot {
    width: 8px;
    height: 8px;
    margin-right: 2px;
  }

  .page-overlay .name-bar.is-active .active-dot::before {
    width: 5px;
    height: 5px;
    border-width: 1px;
    box-shadow: none;
  }

  .page-overlay .name-bar-meta {
    flex: 0 0 40px;
    width: 40px;
    min-height: 0;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.02em;
  }

  .page-overlay .name-bar-meta.is-winner,
  .page-overlay .name-bar-meta.is-loser,
  .page-overlay .name-bar-meta.is-draw {
    padding: 0 3px;
    font-size: 8px;
    line-height: 1.1;
  }
}

/* Pieces (reserve) bar — wheat strip flush with the board. */
.pieces-bar {
  background: var(--pocket-bg);
  height: var(--reserve-bar-h);
  display: flex;
  align-items: center;
  padding: 0 calc(var(--reserve-icon) * 0.28);
  width: 100%;
  box-sizing: border-box;
}
.pieces-bar.is-active {
  box-shadow: inset 0 0 0 2px var(--active);
}

.pocket-pieces {
  display: flex;
  align-items: center;
  gap: max(1px, calc(var(--reserve-icon) * 0.06));
  flex-wrap: wrap;
  width: 100%;
  font-size: 0;
  line-height: 1;
}

.pocket-piece-icon {
  width: var(--reserve-icon);
  height: var(--reserve-icon);
  display: block;
  pointer-events: none;
}

.pocket-piece-icon .piece {
  pointer-events: none;
}

.pocket-pieces .pc {
  cursor: grab;
  touch-action: none;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 0 calc(var(--reserve-icon) * 0.03);
  border-radius: 2px;
  transition: background 0.15s ease;
}
.pocket-pieces .pc:hover {
  background: rgba(0, 0, 0, 0.06);
}
.pocket-pieces .pc:active {
  cursor: grabbing;
}

.pieces-bar.is-inactive .pc {
  pointer-events: none;
  cursor: not-allowed;
}

.pocket-pieces sub {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: calc(var(--reserve-icon) * 0.3);
  font-weight: 700;
  color: #1a1714;
  vertical-align: baseline;
  line-height: 1;
  margin-left: calc(var(--reserve-icon) * -0.18);
  letter-spacing: -0.02em;
}

/* Drag ghost (pocket → board). */
.pocket-drag-ghost {
  position: fixed;
  z-index: 10000;
  left: 0;
  top: 0;
  transform: translate(-50%, -55%);
  pointer-events: none;
  line-height: 0;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.55));
}

.pocket-drag-ghost svg {
  width: clamp(56px, 12vw, 96px);
  height: clamp(56px, 12vw, 96px);
  display: block;
}

body.pocket-dragging {
  cursor: grabbing;
}

/* Promoted-pawn letter overlay (drawn on top of pawn art). */
.promoted-pawn-letter {
  position: absolute;
  z-index: 4;
  font-family: "Geist", "Helvetica Neue", system-ui, sans-serif;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: #fff;
  pointer-events: none;
  text-shadow:
    0 0 3px #000,
    0 0 6px #000,
    1px 1px 0 #000;
}

/* Board row: chessboard + vertical eval bar (A: bar right; B: `.board-row--bar-left` → bar left). */
.board-row {
  display: flex;
  align-items: stretch;
  gap: clamp(4px, 0.5vw, 8px);
  width: 100%;
}
.board-row--bar-left {
  flex-direction: row;
}
.board-row--bar-left > .eval-bar-vertical {
  flex-shrink: 0;
}
.board-row > .board-wrap {
  flex: 1 1 auto;
  min-width: 0;
}

.eval-bar-vertical {
  position: relative;
  flex: 0 0 var(--eval-bar-w);
  background: var(--eval-black);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--border-mid);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: clamp(9px, 0.85vw, 11px);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.eval-fill-vertical {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: var(--eval-white);
  transition: height 220ms ease;
}
.eval-bar-vertical.is-flipped .eval-fill-vertical {
  bottom: auto;
  top: 0;
}

/* While the engine is recomputing for the new position, hold the previous
 * fill height + score, but pulse the fill so it's visually obvious the
 * value is stale. No collapse-to-50% mid-think. */
@keyframes eval-bar-thinking-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}
.eval-bar-vertical.is-thinking .eval-fill-vertical {
  animation: eval-bar-thinking-pulse 1.1s ease-in-out infinite;
}

/* Eval label slots — only one is populated at a time, depending on
 * which side is currently winning and the board orientation.
 */
.eval-bar-vertical .eval-score {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
  line-height: 1;
  padding: 2px 0;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.45);
}
.eval-bar-vertical .eval-score-top {
  top: 0;
}
.eval-bar-vertical .eval-score-bottom {
  bottom: 0;
}
.eval-bar-vertical .eval-score.is-white {
  color: #1c1814;
  text-shadow: 0 0 4px rgba(255, 255, 255, 0.5);
}
.eval-bar-vertical .eval-score.is-black {
  color: var(--text-bright);
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.65);
}

.eval-bar-vertical .eval-score.is-muted {
  color: var(--muted);
  font-size: 0.88em;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Top-3 engine lines pinned to the bottom of each board stack.
 * The stack uses `column-reverse` when flipped to Team 2's perspective; an
 * explicit `order` keeps the lines below everything (board, pockets, name
 * bars) in BOTH orientations. Each row: rank, eval pill, SAN PV, depth.
 *
 * The list reserves space for exactly three rows so the layout doesn't shift
 * while the engine is loading or has only partial output.
 */
.engine-lines {
  --engine-line-h: 30px;
  --engine-line-gap: 4px;
  list-style: none;
  margin: clamp(8px, 1vh, 14px) 0 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--engine-line-gap);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: clamp(12px, 1.1vw, 14px);
  color: var(--text-bright);
  min-height: calc(3 * var(--engine-line-h) + 2 * var(--engine-line-gap));
  order: 999;
}
.board-stack.is-flipped .engine-lines {
  order: -999;
}

.engine-line {
  display: grid;
  /* Fixed-width eval column ensures the pill background fully wraps "+10.00"
   * and "M9" alike. Rank is also fixed so PV always starts at the same x. */
  grid-template-columns: 1.6em 6ch 1fr auto;
  align-items: center;
  column-gap: clamp(10px, 1vw, 14px);
  padding: 0 10px;
  height: var(--engine-line-h);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  border-left: 3px solid transparent;
  line-height: 1.2;
}
.engine-line.is-empty {
  /* Legacy single-cell placeholder (no longer rendered, kept for safety). */
  color: var(--muted);
  font-style: italic;
  background: transparent;
  border-left-color: transparent;
  grid-template-columns: 1fr;
  padding-left: 6px;
}
/* Skeleton row: same grid + outer geometry, just empty inner cells.
 * Used while the engine is loading the WASM, or recomputing after a
 * position/pocket change, so the rows never collapse or jitter. */
.engine-line.is-pending {
  background: rgba(255, 255, 255, 0.025);
  border-left-color: transparent;
}
.engine-line.is-pending .line-eval {
  background: rgba(255, 255, 255, 0.06);
  box-shadow: none;
}
.engine-line:first-child:not(.is-empty):not(.is-pending) {
  background: rgba(232, 176, 75, 0.12);
  border-left-color: var(--active);
}

.engine-line .line-rank {
  color: var(--muted);
  font-weight: 600;
  text-align: right;
}
.engine-line .line-eval {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border-radius: 3px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.engine-line .line-eval.is-white {
  color: #1c1814;
  background: var(--eval-white);
}
.engine-line .line-eval.is-black {
  color: var(--text-bright);
  background: rgba(0, 0, 0, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.engine-line .line-pv {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-bright);
  font-weight: 500;
}
.engine-line .line-depth {
  color: var(--muted);
  font-size: 0.9em;
  font-weight: 500;
}

/* Move-list panel — `# White Black` scoresheet sits below the engine
 * lines on each board stack. Same alignment rules apply (board column
 * width, board-B inset). Body has a fixed height (10 rows) so the panel
 * never grows or shifts other elements when new plies arrive; the body
 * auto-scrolls to the most recent move. */
.move-list {
  --ml-row-h: 22px;
  --ml-rows: 10;
  --ml-row-gap: 0px;
  margin: clamp(8px, 1vh, 14px) 0 0 0;
  padding: 10px 12px 12px;
  border: 1px solid var(--border-mid);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: clamp(12px, 1.05vw, 14px);
  color: var(--text-bright);
  box-sizing: border-box;
  order: 1000;
}
.board-stack.is-flipped .move-list {
  order: -1000;
}
.move-list-head,
.move-list-row {
  display: grid;
  grid-template-columns: 3.2em 1fr 1fr;
  align-items: start;
  column-gap: 10px;
  padding: 2px 6px;
  min-height: var(--ml-row-h);
}

.move-list-head .ml-dgt-w,
.move-list-head .ml-dgt-b,
.move-list-row .ml-dgt-w,
.move-list-row .ml-dgt-b {
  display: none;
}
.move-list-head {
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 4px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.82em;
}
.move-list-body {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: calc(var(--ml-rows) * var(--ml-row-h) * 2.25);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  scrollbar-gutter: stable;
}
.move-list-row {
  font-variant-numeric: tabular-nums;
  border-radius: 3px;
  flex: 0 0 auto;
}
.move-list-row:nth-child(odd) {
  background: rgba(255, 255, 255, 0.025);
}
.move-list-row .ml-num {
  color: var(--muted);
  font-weight: 600;
  text-align: right;
  padding-right: 4px;
}
.move-list-row .ml-w,
.move-list-row .ml-b,
.move-list-row .ml-dgt-w,
.move-list-row .ml-dgt-b {
  white-space: normal;
  word-break: break-word;
  line-height: 1.25;
  max-height: calc(1.25em * 4);
  overflow: hidden;
}

.move-list-row .ml-dgt-w,
.move-list-row .ml-dgt-b {
  color: #ffd98a;
}

.move-list-row .is-dgt-log-move {
  cursor: pointer;
  border-radius: 3px;
  padding: 0 3px;
  margin: 0 -3px;
}

.move-list-row .is-dgt-log-move:hover,
.move-list-row .is-dgt-log-move:focus-visible {
  background: rgba(126, 184, 255, 0.16);
  box-shadow: 0 0 0 1px rgba(126, 184, 255, 0.55) inset;
  color: #cfe5ff;
  outline: none;
}

.move-list-row .is-dgt-different {
  background: rgba(232, 176, 75, 0.16);
  box-shadow: 0 0 0 1px rgba(232, 176, 75, 0.34) inset;
  border-radius: 3px;
  padding: 0 3px;
  margin: 0 -3px;
}

.move-list-row .is-admin-editable {
  border-radius: 3px;
  cursor: pointer;
  padding: 0 3px;
  margin: 0 -3px;
}

.move-list-row .is-admin-editable:hover,
.move-list-row .is-admin-editable:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  outline: none;
}

.move-list-row .is-dgt-suspect,
.move-list-row .is-dgt-uncertain,
.move-list-row .is-dgt-stopped {
  border-radius: 3px;
  cursor: pointer;
  padding: 0 3px;
  margin: 0 -3px;
}

.move-list-row .is-dgt-suspect {
  background: rgba(232, 176, 75, 0.22);
  color: #ffd98a;
  box-shadow: 0 0 0 1px rgba(232, 176, 75, 0.36) inset;
}

.move-list-row .is-dgt-uncertain {
  background: rgba(227, 106, 74, 0.2);
  color: #ffb29d;
  box-shadow: 0 0 0 1px rgba(227, 106, 74, 0.36) inset;
}

.move-list-row .is-dgt-stopped {
  background: rgba(220, 70, 70, 0.34);
  color: #ffd1c8;
  box-shadow: 0 0 0 1px rgba(220, 70, 70, 0.58) inset;
}

/* Navigation cursor: the ply currently shown on the board while reviewing history */
.move-list-row .is-nav-current {
  background: rgba(100, 180, 255, 0.22);
  box-shadow: 0 0 0 1px rgba(100, 180, 255, 0.5) inset;
  border-radius: 3px;
  font-weight: 600;
}
/* When a flagged (red) cell is also the nav cursor, blue wins */
.move-list-row .is-dgt-stopped.is-nav-current,
.move-list-row .is-dgt-suspect.is-nav-current,
.move-list-row .is-dgt-uncertain.is-nav-current {
  background: rgba(100, 180, 255, 0.32);
  box-shadow: 0 0 0 2px rgba(100, 180, 255, 0.65) inset;
  color: inherit;
}

.move-repair-panel {
  border-top: 1px solid rgba(232, 176, 75, 0.25);
  background: rgba(0, 0, 0, 0.28);
  font-size: 0.8em;
  line-height: 1.4;
}

/* Header: title + close */
.mrp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 7px 3px;
}
.mrp-title { font-weight: 600; color: var(--active); }
.mrp-close {
  flex-shrink: 0;
  padding: 0 2px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1em;
  line-height: 1;
  opacity: 0.6;
}
.mrp-close:hover { opacity: 1; }

/* One-line explanation below the title */
.mrp-subline {
  padding: 1px 7px 5px;
  color: var(--muted);
  font-size: 0.95em;
}
.mrp-subline strong { color: var(--text); }

/* Diff rows: this move / next move / unexpected gaps */
.mrp-diffs {
  border-top: 1px solid rgba(255,255,255,0.06);
  padding: 3px 0 2px;
}
.mrp-diff-row {
  display: flex;
  gap: 6px;
  padding: 1px 7px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.95em;
}
.mrp-diff-lbl {
  flex: 0 0 4.2em;
  color: var(--muted);
  white-space: nowrap;
}
.mrp-diff-val { color: var(--text); }
.mrp-diff-warn { background: rgba(200, 50, 50, 0.12); }
.mrp-diff-warn .mrp-diff-val { color: #ff9090; }

/* Actions */
.mrp-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 5px 7px 7px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.mrp-note { color: var(--muted); font-size: 0.9em; }

.move-repair-readout,
.move-repair-draw-on-board,
.move-repair-confirm-synced,
.move-repair-candidate {
  padding: 2px 7px;
  font-size: 0.9em;
}
.move-repair-readout {
  border-color: rgba(232, 176, 75, 0.4);
  background: rgba(232, 176, 75, 0.08);
  color: var(--active);
}
.move-repair-draw-on-board {
  border-color: rgba(100, 160, 255, 0.4);
  background: rgba(100, 160, 255, 0.08);
  color: #9dc8ff;
}
.move-repair-candidate {
  border-color: rgba(58, 208, 123, 0.4);
  background: rgba(58, 208, 123, 0.10);
  color: #9ff0bc;
}
.move-repair-confirm-synced {
  border-color: rgba(58, 208, 123, 0.4);
  background: rgba(58, 208, 123, 0.10);
  color: #9ff0bc;
}
.move-repair-candidate:disabled { cursor: not-allowed; opacity: 0.4; }

.pocket-unknown {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-overlay:not(.page-viewer-match) .overlay-grid {
  /* Tighter gap between the two boards so more screen goes to the side panels */
  gap: clamp(28px, 4vw, 70px);
  padding-left: clamp(220px, 16vw, 300px);
  padding-right: clamp(220px, 16vw, 300px);
}

/* Boards 10% smaller in admin overlay — frees ~100px more per side for panels */
.page-overlay:not(.page-viewer-match) .board-stack {
  width: clamp(280px, 38vw, 495px);
}

/* ── Operator overlay move list panels ─────────────────────────────────────
   The overlay grid has side padding of ~clamp(220px,16vw,300px) on each side.
   Board A's move list is anchored to the LEFT of Board A (right: 100%+12px)
   and Board B's is anchored to the RIGHT of Board B (left: 100%+12px).
   Each panel gets exactly the available side padding as its width so all
   columns it shows are fully visible.

   Board A panel (left side): shows the raw DGT log readout (#, DGT W, DGT B).
   Board B panel (right side): shows the reconstructed game moves (#, W, B).
   Use the move-repair panel (shown automatically on mismatch) or the
   "Reconstruct" button to compare and correct between boards.
   ────────────────────────────────────────────────────────────────────────── */
.page-overlay:not(.page-viewer-match) .move-list {
  position: absolute;
  top: 0;
  margin: 0 !important;
  align-self: auto;
  font-size: clamp(13px, 1.05vw, 16px);
  line-height: 1.35;
  z-index: 2;
}

/* Board A: panel to the LEFT. */
.page-overlay:not(.page-viewer-match) .board-stack[data-board="A"] .move-list {
  right: calc(100% + 12px);
  width: clamp(220px, calc(24vw - 16px), 400px) !important;
  max-width: clamp(220px, calc(24vw - 16px), 400px) !important;
}
.page-overlay:not(.page-viewer-match) .board-stack[data-board="A"] .move-list-head,
.page-overlay:not(.page-viewer-match) .board-stack[data-board="A"] .move-list-row {
  grid-template-columns: 2em 1fr 1fr;
  column-gap: 4px;
}

/* Board B: panel to the RIGHT. */
.page-overlay:not(.page-viewer-match) .board-stack[data-board="B"] .move-list {
  left: calc(100% + 12px);
  width: clamp(220px, calc(24vw - 16px), 400px) !important;
  max-width: clamp(220px, calc(24vw - 16px), 400px) !important;
}
.page-overlay:not(.page-viewer-match) .board-stack[data-board="B"] .move-list-head,
.page-overlay:not(.page-viewer-match) .board-stack[data-board="B"] .move-list-row {
  grid-template-columns: 2em 1fr 1fr;
  column-gap: 4px;
}

/* Common row sizing for both panels */
.page-overlay:not(.page-viewer-match) .move-list-head,
.page-overlay:not(.page-viewer-match) .move-list-row {
  min-height: 26px;
  padding-top: 3px;
  padding-bottom: 3px;
}

.page-overlay:not(.page-viewer-match) .move-list-body {
  max-height: min(36vh, 360px);
}

@media (max-width: 1180px) {
  .page-overlay:not(.page-viewer-match) .overlay-grid {
    gap: clamp(20px, 4vw, 80px);
    padding-left: clamp(20px, 3vw, 80px);
    padding-right: clamp(20px, 3vw, 80px);
  }

  /* On small screens both move lists fall below their boards at full width. */
  .page-overlay:not(.page-viewer-match) .move-list {
    position: static;
    width: 100% !important;
    max-width: 100% !important;
    margin-top: clamp(8px, 1vh, 14px) !important;
  }
  .page-overlay:not(.page-viewer-match) .board-stack[data-board="A"] .move-list-head,
  .page-overlay:not(.page-viewer-match) .board-stack[data-board="A"] .move-list-row,
  .page-overlay:not(.page-viewer-match) .board-stack[data-board="B"] .move-list-head,
  .page-overlay:not(.page-viewer-match) .board-stack[data-board="B"] .move-list-row {
    grid-template-columns: 2.4em 1fr 1fr;
    column-gap: 6px;
  }
}

/* Public viewer: hide DGT log columns — they're admin-only debug data */
body.page-viewer-match .ml-dgt-w,
body.page-viewer-match .ml-dgt-b {
  display: none;
}
body.page-viewer-match .move-list-head {
  display: none;
}

body.page-viewer-match .move-list-row {
  grid-template-columns: 3.2em 1fr 1fr;
}

body.page-viewer-match .move-list {
  padding-top: 8px;
}

.wadim-echo {
  margin-top: 6px;
  padding: 6px 8px 0;
  border-top: 1px dashed var(--border-subtle);
  font-size: 0.78em;
  line-height: 1.35;
  color: var(--muted);
}

.wadim-echo-line + .wadim-echo-line {
  margin-top: 4px;
}

/* Match-result banner — sits between header and main, always reserves
 * its full height so when a result fires the boards do NOT shift down.
 * `.hidden` toggles visibility (not display), keeping the layout slot. */
.match-result-banner {
  margin: 8px clamp(12px, 2vw, 24px) 4px;
  padding: 10px 16px;
  border-radius: 8px;
  text-align: center;
  font-weight: 700;
  font-size: clamp(14px, 1.2vw, 17px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid transparent;
  background: transparent;
  color: var(--active);
  box-shadow: none;
  /* Reserve a stable height so toggling the result banner never reflows
   * the boards. Matches one line of body text + vertical padding. */
  min-height: calc(1em + 20px);
  line-height: 1;
}
.match-result-banner.hidden {
  visibility: hidden;
}
.match-result-banner:not(.hidden) {
  background: linear-gradient(180deg, rgba(232, 176, 75, 0.18), rgba(232, 176, 75, 0.07));
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
}
.match-result-banner.team-1:not(.hidden) {
  background: linear-gradient(180deg, rgba(96, 165, 250, 0.22), rgba(96, 165, 250, 0.08));
  color: #cfe3ff;
  border-color: rgba(96, 165, 250, 0.35);
}
.match-result-banner.team-2:not(.hidden) {
  background: linear-gradient(180deg, rgba(248, 113, 113, 0.22), rgba(248, 113, 113, 0.08));
  color: #ffd7d7;
  border-color: rgba(248, 113, 113, 0.35);
}

/* When the match is over both boards visually de-emphasize: pieces dim
 * slightly so the result banner is clearly the focus. */
body.match-over .board-stack {
  opacity: 0.85;
}

/* Frozen overlay — semi-transparent scrim with copy. */
.freeze-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: rgba(10, 9, 8, 0.55);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--text-bright);
  text-transform: uppercase;
  text-align: center;
  padding: 0.75rem;
  line-height: 1.35;
}

@keyframes pocket-flash-gain {
  from {
    background: rgba(58, 208, 123, 0.55);
    box-shadow: inset 0 0 0 2px rgba(58, 208, 123, 0.85);
  }
  to {
    background: transparent;
    box-shadow: inset 0 0 0 2px transparent;
  }
}
@keyframes pocket-flash-spend {
  from {
    background: rgba(232, 176, 75, 0.4);
  }
  to {
    background: transparent;
  }
}

.pocket-pieces .pc.flash-gain {
  transition: none;
}

.flash-gain {
  animation:
    pocket-piece-gain 1.5s ease-out,
    pocket-flash-gain 1.5s ease-out;
}
.flash-spend {
  animation: pocket-flash-spend 0.45s ease-out;
}

@keyframes pocket-piece-gain {
  0% {
    filter: drop-shadow(0 0 0 rgba(58, 208, 123, 0));
    transform: scale(1);
  }
  18% {
    filter:
      drop-shadow(0 0 10px rgba(58, 208, 123, 1))
      drop-shadow(0 0 22px rgba(58, 208, 123, 0.75))
      drop-shadow(0 0 36px rgba(46, 180, 100, 0.45));
    transform: scale(1.1);
  }
  100% {
    filter: drop-shadow(0 0 0 rgba(58, 208, 123, 0));
    transform: scale(1);
  }
}

/* Admin help text. */
.help-section .help-list {
  margin: 0.35rem 0 0;
  padding-left: 1.25rem;
  line-height: 1.5;
  font-size: 0.9rem;
}

.help-section .help-list code {
  font-size: 0.85em;
  padding: 0.08rem 0.28rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
}

.small-print {
  font-size: 0.82rem;
  margin: 0.35rem 0 0.65rem;
}

.autoplay-area {
  display: block;
  margin-top: 0.5rem;
}

.autoplay-area textarea {
  width: 100%;
  margin-top: 0.25rem;
}

/* Admin */
.page-admin {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
  font-family: system-ui, sans-serif;
  background: var(--bg);
}

.page-admin.page-match-logs {
  width: min(100%, 1800px);
  max-width: none;
}

.admin-header h1 {
  margin: 0;
}

.admin-section {
  margin-bottom: 1.75rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-mid);
}

.admin-section h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.muted {
  color: var(--muted);
}

.admin-section label {
  display: block;
  margin: 0.5rem 0;
}

.admin-section input[type="text"],
.admin-section textarea {
  width: 100%;
  max-width: 100%;
}

.mono {
  font-family: ui-monospace, monospace;
}

.log-pane {
  background: rgba(0, 0, 0, 0.32);
  padding: 1rem;
  border-radius: 3px;
  border: 1px solid var(--border-mid);
  overflow: auto;
  max-height: 320px;
  font-size: 0.8rem;
}

button {
  margin: 0.25rem 0.35rem 0.25rem 0;
  padding: 0.35rem 0.65rem;
  border-radius: 3px;
  border: 1px solid var(--border-mid);
  background: var(--panel);
  color: var(--text-bright);
  cursor: pointer;
}

button:hover {
  background: rgba(255, 255, 255, 0.04);
}

.pocket-admin-row {
  margin: 0.35rem 0;
}

.pocket-admin-row button {
  font-size: 0.75rem;
}

/* ===========================================================================
 * Games-list landing page (replaces the old admin panel).
 * ========================================================================= */

.page-admin-list {
  min-height: 100vh;
  margin: 0;
  padding: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: "Geist", "Helvetica Neue", system-ui, sans-serif;
}

.page-admin-list a:not([class]) {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.25);
  text-underline-offset: 2px;
}

.page-admin-list a:not([class]):hover {
  color: var(--text-bright);
}

.page-admin-list .btn-primary {
  background: #9a7d55;
  color: #fff;
  border-color: #9a7d55;
}

.page-admin-list .btn-primary:hover {
  background: #b09266;
  border-color: #b09266;
}

.admin-list-header {
  padding: 24px clamp(20px, 4vw, 40px) 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg);
}

.admin-list-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.admin-list-brand .site-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.admin-subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.admin-header-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-nav-link {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border-mid);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.03);
}

.admin-nav-link:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-bright);
}

.admin-list-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(20px, 2.5vw, 32px) clamp(20px, 4vw, 40px);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.admin-list-section {
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 18px clamp(16px, 2vw, 22px);
}

.admin-section-primary {
  border-color: rgba(255, 255, 255, 0.1);
}

.admin-settings-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
}

.admin-settings-heading {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.admin-settings-section {
  background: rgba(255, 255, 255, 0.015);
}

.admin-settings-section .admin-list-section-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.admin-help-details {
  margin: 0 0 14px;
}

.admin-help-details summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  user-select: none;
  list-style: none;
}

.admin-help-details summary::-webkit-details-marker {
  display: none;
}

.admin-help-details summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.15s ease;
}

.admin-help-details[open] summary::before {
  transform: rotate(90deg);
}

.admin-help-details summary:hover {
  color: var(--text);
}

.admin-help-details .admin-list-help {
  margin-top: 8px;
}

.admin-list-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.admin-list-section-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.admin-list-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.admin-list-help {
  margin: 0;
  flex: 1 1 100%;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.admin-list-help strong {
  color: var(--text);
}

.admin-list-empty {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

/* New-game form */

.new-game-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.form-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
}

.form-col-title {
  margin: 0 0 4px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.form-col-title.team-1,
.form-col-title.team-2,
.form-col-title.eboard-col {
  color: var(--muted);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
}

.form-field input {
  background: var(--page-bg);
  border: 1px solid var(--border-mid);
  color: var(--text-bright);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
}

.form-field input:focus {
  outline: none;
  border-color: #6c7e9a;
}

.form-field select,
.form-select {
  background: var(--page-bg);
  border: 1px solid var(--border-mid);
  color: var(--text-bright);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
}

.form-field select:focus,
.form-select:focus {
  outline: none;
  border-color: #6c7e9a;
}

.form-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.form-status {
  font-size: 13px;
  color: var(--muted);
}

.btn-primary,
.btn-secondary,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}

.btn-primary {
  background: #4a6fa5;
  color: #ffffff;
  border-color: #4a6fa5;
}

.btn-primary:hover {
  background: #5a82be;
  border-color: #5a82be;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-color: var(--border-mid);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn-danger {
  background: rgba(227, 106, 74, 0.12);
  color: var(--danger);
  border-color: rgba(227, 106, 74, 0.4);
}

.btn-danger:hover {
  background: rgba(227, 106, 74, 0.2);
}

/* Games list — stacked game blocks */

.admin-table-wrap {
  overflow-x: auto;
  margin-top: 4px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table td {
  padding: 0;
  vertical-align: top;
}

.admin-games-row + .admin-games-row .game-block-cell {
  padding-top: 10px;
}

.game-block-cell {
  padding-bottom: 10px !important;
}

.game-block {
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
}

.admin-games-row:hover .game-block {
  background: rgba(255, 255, 255, 0.035);
}

.game-block-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.game-block-title .match-link {
  display: inline;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-bright);
  text-decoration: none;
}

.game-block-title .match-link:hover {
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.35);
}

.game-block-title .game-id-sub {
  display: inline;
  margin-left: 10px;
}

.game-id-sub {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.game-block-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.game-block-names-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px 24px;
  padding: 14px 0;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.game-block-names-grid .game-seat {
  display: grid;
  grid-template-columns: minmax(120px, 140px) minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  font-size: 15px;
  line-height: 1.4;
}

.game-block-names {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px 32px;
  padding: 14px 0;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.game-team-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
}

.game-seats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-seat {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  font-size: 15px;
  line-height: 1.4;
}

.seat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.seat-value {
  color: var(--text-bright);
  word-break: break-word;
}

.game-block-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 24px;
  padding-top: 12px;
  font-size: 14px;
  color: var(--text);
}

.meta-key {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-right: 6px;
}

.game-block-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.game-edit-row td {
  padding: 0 0 10px !important;
}

.game-edit-row .game-edit-form {
  margin: 0;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
}

.error-cell {
  color: #e07070;
  padding: 16px !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.games-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px clamp(14px, 1.6vw, 18px);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
}

.game-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.game-card-link {
  text-decoration: none;
  color: var(--text-bright);
}

.game-card-link:hover {
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.35);
}

.game-card-id {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.game-card-status {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rec-badge {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
}

.rec-badge.rec-on {
  background: rgba(58, 208, 123, 0.15);
  color: #3ad07b;
}

.rec-badge.rec-partial {
  background: rgba(232, 176, 75, 0.15);
  color: var(--warn);
}

.rec-badge.rec-pending {
  background: rgba(108, 126, 154, 0.15);
  color: #a4b1c5;
}

.rec-badge.rec-off {
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

.result-tag {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
}

.result-tag.team-1 {
  color: #f7d977;
  background: rgba(247, 217, 119, 0.12);
}

.result-tag.team-2 {
  color: #b6cffb;
  background: rgba(182, 207, 251, 0.12);
}

.game-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.game-card-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  font-size: 13px;
}

.game-card-col-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  margin-bottom: 2px;
}

.game-card-col-title.team-1 {
  color: #f7d977;
}
.game-card-col-title.team-2 {
  color: #b6cffb;
}
.game-card-col-title.eboard-col {
  color: #c2c2c8;
}

.game-card-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.seat-tag {
  display: inline-block;
  min-width: 24px;
  text-align: center;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

.game-edit-form {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
}

.game-edit-form.hidden {
  display: none;
}

.game-edit-title {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted, #9a9aa8);
}

.game-edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 0.5rem 0.75rem;
}

.game-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.error-row {
  list-style: none;
  padding: 12px;
  background: rgba(227, 106, 74, 0.08);
  color: var(--danger);
  border-radius: 4px;
  font-size: 13px;
}

/* ===========================================================================
 * Per-game DGT recording strip in the overlay.
 * ========================================================================= */

.header-brand-link {
  text-decoration: none;
  color: inherit;
  display: inline-block;
}

.header-brand-link:hover .site-title {
  color: var(--active);
}

.dgt-status-strip {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px clamp(20px, 3vw, 80px);
  background: rgba(0, 0, 0, 0.18);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12px;
  letter-spacing: 0.3px;
}

.dgt-status-strip[hidden] {
  display: none;
}

.dgt-status-label {
  text-transform: uppercase;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.dgt-mode-btn {
  margin: 0;
  padding: 4px 9px;
  border-radius: 3px;
  border: 1px solid var(--border-mid);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.dgt-mode-btn:hover,
.dgt-mode-btn.is-on {
  color: var(--active);
  border-color: rgba(232, 176, 75, 0.45);
  background: rgba(232, 176, 75, 0.12);
}

.dgt-status-board {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  color: var(--text);
}

.dgt-status-title {
  color: var(--text);
}

.dgt-status-detail {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.dgt-status-seg {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dgt-status-sep {
  color: var(--muted);
}

.dgt-status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  order: 2;
}

.dgt-status-seg-label {
  order: 1;
}

.dgt-status-dot.is-ok {
  background: #3ad07b;
  box-shadow: 0 0 0 2px rgba(58, 208, 123, 0.18);
}

.dgt-status-dot.is-bad {
  background: var(--danger);
  box-shadow: 0 0 0 2px rgba(227, 106, 74, 0.18);
}

.dgt-status-dot.is-idle {
  background: #6b6b75;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.04);
}

.dgt-status-board.has-warning .dgt-status-seg-label {
  color: var(--warn);
}

#record-btn[hidden],
#catchup-btn[hidden] {
  display: none !important;
}

#record-btn.is-on {
  background: rgba(227, 106, 74, 0.16);
  color: var(--danger);
  border-color: rgba(227, 106, 74, 0.5);
}

#readout-mode-btn[hidden] {
  display: none !important;
}

#readout-mode-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

#readout-mode-btn.is-on {
  color: var(--warn);
  border-color: rgba(232, 176, 75, 0.55);
  background: rgba(232, 176, 75, 0.12);
}

.hidden {
  display: none !important;
}

/* ===========================================================================
 * Public viewer pages (standings, results, /match-N broadcast)
 * Fjalla One: load via <link> in HTML (overlay + /bughouse/*), not @import here.
 * ========================================================================= */

.page-viewer,
.page-overlay.page-viewer-match {
  min-height: 100vh;
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: "Geist", "Helvetica Neue", system-ui, sans-serif;
}

[x-cloak] {
  display: none !important;
}

.viewer-nav {
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg);
  flex-shrink: 0;
}

.viewer-nav-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px clamp(16px, 3vw, 40px) 14px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
}

.viewer-nav-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 16px;
  width: 100%;
}

.viewer-nav-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  flex: 1 1 auto;
  min-width: 0;
}

.viewer-nav-dropdown {
  width: 100%;
}

.viewer-nav-dropdown > summary {
  list-style: none;
}

.viewer-nav-dropdown > summary::-webkit-details-marker {
  display: none;
}

.viewer-nav-menu-toggle {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  margin-top: 2px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  font-family: inherit;
  width: fit-content;
}

.viewer-nav-menu-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
}

.viewer-nav-menu-toggle:focus-visible {
  outline: 2px solid rgba(26, 157, 221, 0.65);
  outline-offset: 2px;
}

.viewer-nav-menu-panel {
  display: block;
}

.viewer-nav-subtitle {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin: 0;
  font-family: "Fjalla One", sans-serif;
  font-weight: 400;
  font-size: clamp(16px, 2vw, 20px);
  line-height: 1.2;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: right;
  flex-shrink: 0;
}

.viewer-event-location-city,
.viewer-event-location-comma {
  color: #fff;
}

.viewer-event-location-country {
  color: var(--muted);
}

.viewer-nav-flag {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.viewer-nav-flag img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.viewer-nav-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}

.viewer-nav-brand:hover .viewer-nav-title {
  color: var(--accent, #7eb8ff);
}

.viewer-nav-logo {
  flex-shrink: 0;
  width: 88px;
  height: auto;
  object-fit: contain;
}

.viewer-nav-title {
  font-family: "Fjalla One", sans-serif;
  font-size: clamp(22px, 3.2vw, 32px);
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: -0.03em;
  text-transform: uppercase;
  color: var(--text);
}

.viewer-nav-menu {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: clamp(16px, 3vw, 32px);
}

.viewer-nav-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.viewer-nav-group--solo .viewer-nav-group-links {
  padding-top: 0;
}

.viewer-nav-group-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.42);
  padding-left: 2px;
  line-height: 1;
}

.viewer-nav-group-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
}

.viewer-nav-link {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
  transition:
    color 0.15s ease,
    background 0.15s ease,
    border-color 0.15s ease;
}

.viewer-nav-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-subtle);
}

.viewer-nav-link.is-active {
  color: var(--text);
  border-color: rgba(26, 157, 221, 0.55);
  background: rgba(26, 157, 221, 0.18);
}

/* Unlabeled groups (Home, Replay): align pills with labeled rows */
.viewer-nav-group--no-label .viewer-nav-group-links {
  padding-top: 15px;
}

/* Labeled sections (Tournament, Live): quiet caps + hairline accent */
.viewer-nav-group--section {
  align-items: flex-start;
  gap: 7px;
}

.viewer-nav-group--section .viewer-nav-group-label {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  width: auto;
  max-width: 100%;
  gap: 7px;
  padding: 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.38);
  line-height: 1;
}

.viewer-nav-group--section .viewer-nav-group-label::before {
  content: "";
  flex-shrink: 0;
  width: 14px;
  height: 1px;
  background: rgba(26, 157, 221, 0.55);
}

.viewer-nav-group--live .viewer-nav-group-label::before {
  background: rgba(232, 93, 93, 0.85);
}

.viewer-nav-group--after-divider {
  padding-left: clamp(14px, 2.5vw, 24px);
  margin-left: 2px;
  border-left: 1px solid rgba(255, 255, 255, 0.14);
}

@media (min-width: 721px) {
  .viewer-nav-dropdown > summary {
    display: none;
  }

  /* Always show link row below logo/title — do not rely on <details open> before JS runs */
  .viewer-nav-dropdown .viewer-nav-menu-panel {
    display: block !important;
  }

  .viewer-nav-dropdown {
    width: 100%;
  }

  .viewer-nav-group--no-label .viewer-nav-group-links {
    padding-top: 15px;
  }
}

@media (max-width: 720px) {
  .viewer-nav-inner {
    padding: 12px 14px 10px;
    gap: 8px;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    align-items: start;
    column-gap: 10px;
  }

  /* Menu toggle top-right; dropdown panel full width below */
  .viewer-nav-dropdown {
    display: contents;
  }

  .viewer-nav-head {
    grid-column: 1;
    grid-row: 1;
    align-items: center;
    min-width: 0;
  }

  .viewer-nav-subtitle {
    display: none;
  }

  .viewer-nav-dropdown > summary.viewer-nav-menu-toggle {
    display: inline-flex;
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    align-self: start;
    margin-top: 0;
  }

  .viewer-nav-logo {
    width: 52px;
  }

  .viewer-nav-title {
    font-size: 15px;
    letter-spacing: -0.02em;
  }

  .viewer-nav-brand {
    gap: 8px;
  }

  .viewer-nav-menu-panel {
    grid-column: 1 / -1;
    grid-row: 2;
    padding: 12px 14px 14px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid var(--border-subtle);
    transition: opacity 0.15s ease;
  }

  .viewer-nav-menu {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .viewer-nav-group--no-label .viewer-nav-group-links {
    padding-top: 0;
  }

  .viewer-nav-group--after-divider {
    padding-left: 0;
    margin-left: 0;
    border-left: none;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .viewer-nav-link {
    display: block;
    width: 100%;
    box-sizing: border-box;
    text-align: left;
    padding: 12px 16px;
    font-size: 15px;
  }
}

.viewer-main {
  max-width: 900px;
  margin: 0 auto;
  padding: clamp(20px, 3vw, 40px) clamp(16px, 3vw, 40px);
}

.viewer-home-main {
  max-width: 1200px;
}

.viewer-home-hero {
  margin-bottom: 20px;
}

.viewer-home-subtitle {
  margin: 0;
  font-family: "Fjalla One", sans-serif;
  font-weight: 400;
  font-size: clamp(16px, 2.2vw, 20px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.viewer-home-section-title {
  margin: 0 0 12px;
  font-family: "Fjalla One", sans-serif;
  font-size: 18px;
  font-weight: 400;
  letter-spacing: -0.03em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.75);
}

.viewer-home-live {
  margin-bottom: 24px;
}

.viewer-home-live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.viewer-home-live-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.04);
  text-decoration: none;
  color: var(--text);
  transition:
    border-color 0.15s ease,
    background 0.15s ease,
    transform 0.15s ease;
}

.viewer-home-live-card:hover {
  border-color: rgba(26, 157, 221, 0.55);
  background: rgba(26, 157, 221, 0.12);
  transform: translateY(-1px);
}

.viewer-home-live-card--stream {
  border-color: rgba(26, 157, 221, 0.35);
  background: rgba(26, 157, 221, 0.1);
}

.viewer-home-live-card__label {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.viewer-home-live-card__hint {
  font-size: 12px;
  color: var(--muted);
}

.viewer-home-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.viewer-rank-list__place {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--muted);
  min-width: 1.5rem;
}

.viewer-rank-list__team {
  min-width: 0;
}

.viewer-rank-list__pts {
  font-variant-numeric: tabular-nums;
}

.viewer-rank-list li {
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: baseline;
}

.viewer-home-pairings {
  list-style: none;
  margin: 0;
  padding: 0;
}

.viewer-home-pairing {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px 14px;
  align-items: baseline;
  padding: 12px 0;
  border-top: 1px solid var(--border-subtle);
}

.viewer-home-pairing:first-child {
  border-top: 0;
  padding-top: 0;
}

.viewer-home-pairing__match {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent, #7eb8ff);
  text-decoration: none;
  white-space: nowrap;
}

.viewer-home-pairing__match:hover {
  text-decoration: underline;
}

.viewer-home-pairing__teams {
  font-size: 14px;
  line-height: 1.35;
  min-width: 0;
}

.viewer-home-pairing__vs {
  color: var(--muted);
  font-weight: 500;
}

.viewer-home-pairing__result {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}

.viewer-home-pairing__result.is-pending {
  color: var(--muted);
  font-weight: 500;
}

.viewer-panel {
  border: 1px solid var(--border-subtle);
  background: var(--bg);
  border-radius: 8px;
  padding: 14px;
}

.viewer-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.viewer-panel-head h2 {
  margin: 0;
  font-size: 16px;
}

.viewer-rank-list,
.viewer-game-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.viewer-rank-list li,
.viewer-game-list li {
  display: grid;
  gap: 6px;
  padding: 9px 0;
  border-top: 1px solid var(--border-subtle);
}

.viewer-rank-list li {
  grid-template-columns: 1fr auto;
}

.viewer-rank-list li:first-child,
.viewer-game-list li:first-child {
  border-top: 0;
}

.viewer-game-list li {
  grid-template-columns: auto auto 1fr auto;
  align-items: baseline;
}

.viewer-list-wide {
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg);
  padding: 4px 14px;
}

.viewer-game-list span,
.viewer-game-list em,
.viewer-muted {
  color: var(--muted);
  font-style: normal;
}

/* Replay games (/bughouse/finished) */
.page-viewer-finished .viewer-main {
  max-width: 920px;
}

.page-viewer-finished .viewer-replay-head {
  margin-bottom: 20px;
}

.page-viewer-finished .viewer-page-title {
  margin: 0 0 8px;
  font-family: "Fjalla One", sans-serif;
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 400;
  letter-spacing: -0.03em;
  text-transform: uppercase;
  line-height: 1.05;
}

.viewer-replay-panel {
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: linear-gradient(
    165deg,
    rgba(255, 255, 255, 0.04) 0%,
    rgba(255, 255, 255, 0.015) 100%
  );
  padding: 0;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}

.viewer-replay-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.viewer-replay-card {
  margin: 0;
  border-top: 1px solid var(--border-subtle);
}

.viewer-replay-card:first-child {
  border-top: 0;
}

.viewer-replay-card:nth-child(odd) .viewer-replay-card__link {
  background: rgba(255, 255, 255, 0.03);
}

.viewer-replay-card:nth-child(even) .viewer-replay-card__link {
  background: transparent;
}

.viewer-replay-card__link {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 20px;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s ease;
}

.viewer-replay-card__link:hover {
  background: rgba(26, 157, 221, 0.1);
}

.viewer-replay-card__link:focus-visible {
  outline: 2px solid rgba(26, 157, 221, 0.65);
  outline-offset: -2px;
}

.viewer-replay-card__top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
}

.viewer-replay-card__round-match {
  flex: 1 1 auto;
  min-width: 0;
  font-family: "Fjalla One", sans-serif;
  font-size: clamp(18px, 2.8vw, 24px);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.1;
  color: var(--text-bright, #f2f5f8);
}

.viewer-replay-card__ended {
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
  color: var(--muted);
}

.viewer-replay-card__ended-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
}

.viewer-replay-card__when {
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.72);
  white-space: nowrap;
}

.viewer-replay-card__cta {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: rgba(26, 157, 221, 0.22);
  border: 1px solid rgba(26, 157, 221, 0.5);
  white-space: nowrap;
  transition:
    background 0.15s ease,
    border-color 0.15s ease;
}

.viewer-replay-card__link:hover .viewer-replay-card__cta {
  background: rgba(26, 157, 221, 0.34);
  border-color: rgba(26, 157, 221, 0.7);
}

.viewer-replay-card__cta::after {
  content: " →";
  margin-left: 0.15em;
}

.viewer-replay-card__lineup {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 10px;
  font-size: 16px;
  line-height: 1.4;
  min-width: 0;
}

.viewer-replay-card__team {
  font-weight: 600;
}

.viewer-replay-card__vs {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.38);
}

.viewer-replay-card__score {
  margin-left: 0.35em;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.02em;
  color: var(--text-bright, #f2f5f8);
  white-space: nowrap;
}

@media (max-width: 640px) {
  .viewer-replay-card__top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .viewer-replay-card__cta {
    margin-left: 0;
    width: 100%;
  }
}

@media (max-width: 760px) {
  .viewer-home-grid {
    grid-template-columns: 1fr;
  }
  .viewer-panel + .viewer-panel {
    margin-top: 16px;
  }
  .viewer-home-pairing {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .viewer-game-list li {
    grid-template-columns: 1fr;
  }
}

.match-log-main {
  display: grid;
  grid-template-columns: minmax(460px, 0.65fr) minmax(920px, 1.35fr);
  gap: 18px;
  padding: 20px 0;
  min-width: 0;
}

.match-log-viewer,
.match-log-list-panel {
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg);
  padding: 14px;
  min-width: 0;
}

.match-log-boards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.match-log-boards h2,
.match-log-list-head h2 {
  margin: 0 0 10px;
  font-size: 14px;
}

.match-log-boards code {
  display: block;
  margin-top: 8px;
  min-height: 48px;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
}

.log-board {
  display: block;
  aspect-ratio: 1;
  border: 1px solid var(--border-mid);
  background: var(--panel);
  width: 100%;
  min-width: 0;
}

.log-board > svg {
  display: block;
}

.match-log-controls,
.match-log-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.match-log-list-head {
  margin-top: 0;
  margin-bottom: 10px;
}

.match-log-table-head {
  display: grid;
  grid-template-columns: 92px 68px 64px 150px minmax(0, 1fr);
  gap: 10px;
  padding: 0 10px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.match-log-list {
  display: grid;
  gap: 6px;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}

.match-log-row {
  display: grid;
  grid-template-columns: 92px 68px 64px 150px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 8px;
  text-align: left;
}

.match-log-row:hover,
.match-log-row.is-active {
  border-color: rgba(232, 176, 75, 0.5);
  background: rgba(232, 176, 75, 0.1);
}

.match-log-row.is-active {
  position: relative;
  border-color: #7eb8ff !important;
  background: rgba(126, 184, 255, 0.16) !important;
  box-shadow:
    0 0 0 2px rgba(126, 184, 255, 0.7),
    inset 4px 0 0 #7eb8ff;
}

.match-log-row span,
.match-log-row strong,
.match-log-row em {
  white-space: nowrap;
  min-width: 0;
}

.match-log-row em {
  justify-self: start;
  border-radius: 4px;
  padding: 3px 6px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-style: normal;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.match-log-row--clock em {
  background: rgba(232, 176, 75, 0.18);
  color: #ffd98a;
}

.match-log-diff {
  min-width: 0;
  white-space: normal !important;
  overflow-wrap: anywhere;
  color: var(--muted);
  line-height: 1.25;
}

.match-log-move {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 800;
  line-height: 1.25;
}

.match-log-row[data-move-status="partial"] .match-log-move {
  color: #ffd98a;
}

.match-log-row[data-move-status="stuck"] {
  border-color: rgba(229, 72, 77, 0.65);
  background: rgba(229, 72, 77, 0.11);
}

.match-log-row[data-move-status="stuck"] .match-log-move {
  color: #ff9b9f;
}

@media (max-width: 980px) {
  .match-log-main,
  .match-log-boards {
    grid-template-columns: 1fr;
  }
  .match-log-table-head {
    display: none;
  }
  .match-log-row {
    grid-template-columns: 1fr;
  }
}

.viewer-page-title {
  margin: 0 0 16px;
  font-size: 24px;
  font-weight: 600;
}

.viewer-results-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 20px;
  margin-bottom: 8px;
}

.viewer-results-head .viewer-page-title {
  margin-bottom: 0;
}

.viewer-round-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}

.viewer-round-label {
  font-size: 13px;
  color: var(--muted);
}

.viewer-status {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.viewer-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg);
}

.viewer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.viewer-table th,
.viewer-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.viewer-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}

.viewer-table tbody tr:last-child td {
  border-bottom: none;
}

.viewer-table td.num,
.viewer-table th.num {
  text-align: right;
  white-space: nowrap;
}

.viewer-table a {
  color: var(--accent, #7eb8ff);
  text-decoration: none;
  font-weight: 600;
}

.viewer-table a:hover {
  text-decoration: underline;
}

.result-cell {
  font-variant-numeric: tabular-nums;
}

.page-overlay.page-viewer-match {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

@media (min-height: 1101px) {
  .page-overlay.page-viewer-match {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }
}

@media (max-height: 1100px) {
  .page-overlay.page-viewer-match {
    height: auto;
    max-height: none;
    overflow: auto;
  }

  .page-overlay.page-viewer-match .viewer-match-layout--active {
    overflow: visible;
    flex: none;
  }

  .page-overlay.page-viewer-match .viewer-match-primary,
  .page-overlay.page-viewer-match .overlay-grid,
  .page-overlay.page-viewer-match .board-stack,
  .page-overlay.page-viewer-match .move-list,
  .page-overlay.page-viewer-match .viewer-video-panel {
    max-height: none;
    overflow: visible;
  }
}

.page-overlay.page-viewer-match .overlay-header {
  display: none !important;
}

.match-switcher {
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg);
}

.match-switcher.hidden {
  display: none;
}

.match-switcher-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px clamp(16px, 3vw, 40px);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.match-switcher-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
}

a.match-switcher-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

.match-switcher-btn.is-active {
  color: var(--text);
  background: rgba(26, 157, 221, 0.22);
  border-color: rgba(26, 157, 221, 0.55);
  cursor: default;
  pointer-events: none;
}

.match-switcher-btn.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.viewer-match-layout {
  display: block;
  max-width: 100%;
  min-height: 0;
}

.viewer-match-layout[hidden],
body.page-viewer-live #viewer-match-layout {
  display: none !important;
}

.page-overlay.page-viewer-match .viewer-match-layout--active {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.viewer-match-layout--active {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 38vw);
  gap: clamp(12px, 2vw, 24px);
  align-items: start;
  max-width: 1920px;
  margin: 0 auto;
  padding: clamp(8px, 1.2vw, 16px) clamp(12px, 2vw, 28px);
  box-sizing: border-box;
  width: 100%;
}

/* Boards + move lists + events bar (not the video column) */
.viewer-match-primary {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  min-width: 0;
  min-height: 0;
}

.page-overlay.page-viewer-match .viewer-match-primary .replay-bar {
  width: 100%;
  margin: 0 0 8px;
  flex-shrink: 0;
  justify-content: center;
  align-items: stretch;
  gap: 0 6px;
  padding: 8px 14px;
  box-sizing: border-box;
  border-radius: 0;
  border-left: none;
  border-right: none;
}

.page-overlay.page-viewer-match .replay-bar .replay-bar-vrule {
  margin: 4px 6px;
}

.page-overlay.page-viewer-match .replay-bar-vrule--before-engine {
  display: none;
}

@media (min-width: 901px) {
  .page-overlay.page-viewer-match .replay-bar-vrule--before-engine {
    display: block;
  }
}

.page-overlay.page-viewer-match .replay-bar .replay-bar-engine-btn {
  display: none;
}

@media (min-width: 901px) {
  .page-overlay.page-viewer-match .replay-bar .replay-bar-engine-btn {
    display: inline-flex;
  }
}

/* Public match on phones/tablets: no engine control or eval chrome */
@media (max-width: 900px) {
  .page-overlay.page-viewer-match #engine-btn,
  .page-overlay.page-viewer-match .replay-bar-engine-btn {
    display: none !important;
  }

  .page-overlay.page-viewer-match .eval-bar-vertical,
  .page-overlay.page-viewer-match .engine-lines {
    display: none !important;
  }

  body.engine-ui-on.page-viewer-match .board-stack {
    --board-col-w: 100cqw;
  }

  body.engine-ui-on.page-viewer-match .name-bar,
  body.engine-ui-on.page-viewer-match .pieces-bar,
  body.engine-ui-on.page-viewer-match .engine-lines,
  body.engine-ui-on.page-viewer-match .move-list {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
  }
}

.page-overlay:not(.page-viewer-match) .viewer-match-primary .replay-bar {
  margin: 0 clamp(12px, 2vw, 24px) 8px;
}

.viewer-video-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 12px;
}

.viewer-video-panel[hidden] {
  display: none !important;
}

.viewer-video-slot__title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.viewer-video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.viewer-video-iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.viewer-video-persist {
  position: fixed;
  inset: 0;
  width: 0;
  height: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 60;
}

.viewer-persist-slot {
  position: absolute;
  width: 0;
  height: 0;
  overflow: visible;
}

.viewer-video-frame[data-video-anchor] {
  position: relative;
}

.viewer-video-frame[data-video-anchor] .viewer-video-iframe {
  display: none;
}

.viewer-video-empty {
  margin: 0;
  padding: 1rem;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .viewer-match-layout--active {
    grid-template-columns: 1fr;
  }

  .viewer-video-panel {
    position: static;
  }
}

.page-overlay.page-viewer-match .overlay-grid {
  align-items: flex-start;
  justify-content: center;
  gap: clamp(10px, 1.4vw, 22px);
  padding: 0;
  flex-wrap: nowrap;
  width: 100%;
  min-width: 0;
  max-height: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

.page-overlay.page-viewer-match .board-stack {
  width: min(
    clamp(200px, 26vw, 460px),
    calc((100dvh - 7.5rem) * 0.88)
  );
  flex: 0 1 auto;
  min-width: 0;
  max-width: var(--board-max);
  max-height: calc(100dvh - 7.5rem);
  overflow: hidden;
}

.page-overlay.page-viewer-match .move-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(22vh, 200px);
  overflow: hidden;      /* clip, not scroll — body handles scrolling */
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.028);
  border-color: rgba(255, 255, 255, 0.08);
}

.page-overlay.page-viewer-match .move-list-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;  /* override the calc() cap from base rule */
}

.page-overlay.page-viewer-match .viewer-video-panel {
  max-height: calc(100dvh - 7.5rem);
  overflow-y: auto;
  position: static;
  top: auto;
}

.page-overlay.page-viewer-match #rules-pill,
.page-overlay.page-viewer-match #game-id-pill,
.page-overlay.page-viewer-match #record-btn,
.page-overlay.page-viewer-match #autoplay-btn,
.page-overlay.page-viewer-match #end-game-btn,
.page-overlay.page-viewer-match #result-select,
.page-overlay.page-viewer-match #dgt-status-strip {
  display: none !important;
}

/* Public viewer annotations (cm-chessboard Arrows extension) */
.page-overlay .cm-chessboard .arrow-success .arrow-line,
.page-overlay .cm-chessboard .arrow-success.arrow-annotate-preview .arrow-line {
  stroke-width: 5px;
  stroke-linecap: round;
  opacity: 0.88;
}

.page-overlay .cm-chessboard .arrow-success.arrow-annotate-preview .arrow-line {
  opacity: 0.5;
}

.page-overlay .cm-chessboard .arrow-success .arrow-head,
.page-overlay .cm-chessboard .arrow-success.arrow-annotate-preview .arrow-head {
  opacity: 0.95;
  transform: scale(1.4);
  transform-box: fill-box;
  transform-origin: center;
}

.page-overlay .cm-chessboard .markers .marker.marker-circle-success {
  stroke-width: 3px;
  opacity: 0.55;
}

.page-overlay .board-wrap {
  touch-action: none;
  cursor: default;
}

/* Public match pages on phones — edge-to-edge boards, gap only between stacks */
@media (max-width: 720px) {
  .page-overlay.page-viewer-match .viewer-match-layout--active {
    padding-left: 0;
    padding-right: 0;
    gap: 8px;
  }

  .page-overlay.page-viewer-match .viewer-match-primary {
    width: 100%;
  }

  .page-overlay.page-viewer-match .overlay-grid {
    padding-left: 0;
    padding-right: 0;
    gap: 6px;
    justify-content: center;
    width: 100%;
  }

  .page-overlay.page-viewer-match .board-stack {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    max-width: calc(50% - 3px);
  }
}

/*
 * Match pages — phone/tablet landscape (short viewport).
 * Portrait phones use max-width: 720px rules; landscape is often >720px wide
 * but only ~390–430px tall, so the generic max-height: 1100px scroll layout
 * breaks. Lock to one screen and size boards from available height.
 */
@media (orientation: landscape) and (max-height: 700px) and (max-width: 1024px) {
  html[data-bughouse-match] body.page-overlay.page-viewer-match {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .page-overlay.page-viewer-match {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .page-overlay.page-viewer-match .viewer-match-layout--active {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    grid-template-columns: 1fr;
    padding: 0;
    gap: 0;
    max-width: none;
  }

  /* Stream column steals height in landscape — boards take priority */
  .page-overlay.page-viewer-match .viewer-video-panel {
    display: none !important;
  }

  .page-overlay.page-viewer-match .viewer-match-primary {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    gap: 0;
    width: 100%;
  }

  .page-overlay.page-viewer-match .viewer-match-primary .replay-bar {
    margin: 0;
    padding: 5px 8px;
    gap: 6px 8px;
    flex-shrink: 0;
  }

  .page-overlay.page-viewer-match .replay-bar .btn-secondary,
  .page-overlay.page-viewer-match .replay-bar .replay-bar-engine-btn {
    padding: 5px 10px;
    font-size: 11px;
    min-height: 0;
  }

  .page-overlay.page-viewer-match .replay-bar .replay-bar-vrule {
    margin: 3px 4px;
  }

  .page-overlay.page-viewer-match .match-result-banner:not(.hidden) {
    flex-shrink: 0;
    padding: 6px 10px;
    font-size: 13px;
  }

  .page-overlay.page-viewer-match .overlay-grid {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow: hidden;
    align-items: stretch;
    justify-content: center;
    gap: 4px;
    padding: 0 4px;
    width: 100%;
  }

  .page-overlay.page-viewer-match .board-stack {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    max-width: calc(50% - 2px);
    max-height: none;
    overflow: hidden;
    --pocket-icon: min(28px, 7.5vw);
    --reserve-bar-h: max(28px, calc(var(--pocket-icon) + 2px));
  }

  .page-overlay.page-viewer-match .board-row {
    flex: 1 1 auto;
    min-height: 0;
    align-items: center;
    justify-content: center;
  }

  .page-overlay.page-viewer-match .board-wrap {
    width: min(100%, calc(100dvh - 8.5rem), calc((100dvw - 16px) / 2 - 4px));
    max-width: 100%;
    margin: 0 auto;
  }

  .page-overlay.page-viewer-match .chessboard-container {
    width: 100%;
    aspect-ratio: 1;
  }

  .page-overlay.page-viewer-match .name-bar {
    min-height: 26px;
    height: auto;
    gap: 4px;
    padding: 2px 0 2px 6px;
    flex-shrink: 0;
  }

  .page-overlay.page-viewer-match .name-bar .player-name {
    font-size: 10px;
    line-height: 1.15;
    -webkit-line-clamp: 1;
  }

  .page-overlay.page-viewer-match .name-bar-meta {
    flex: 0 0 34px;
    width: 34px;
    font-size: 8px;
  }

  .page-overlay.page-viewer-match .active-dot {
    width: 7px;
    height: 7px;
  }

  .page-overlay.page-viewer-match .pieces-bar {
    flex-shrink: 0;
    padding: 0 calc(var(--pocket-icon) * 0.2);
  }

  .page-overlay.page-viewer-match .move-list {
    flex: 0 0 auto;
    margin-top: 2px;
    padding: 4px 6px 6px;
    max-height: 52px;
    --ml-rows: 2;
    --ml-row-h: 18px;
    font-size: 10px;
    flex-shrink: 0;
  }

  .page-overlay.page-viewer-match .move-list-head {
    display: none;
  }

  body.engine-ui-on.page-viewer-match .engine-lines {
    flex: 0 0 auto;
    min-height: 0;
    max-height: 54px;
    --engine-line-h: 16px;
    font-size: 9px;
    margin-top: 2px;
  }

  .viewer-nav-inner {
    padding: 6px 10px 4px;
    gap: 6px;
  }

  .viewer-nav-subtitle {
    display: none;
  }

  .viewer-nav-logo {
    width: 44px;
  }

  .viewer-nav-title {
    font-size: 14px;
  }
}

/* Live Stream — camera picker + grid (live page only) */
.viewer-stream-bar {
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg);
}

.viewer-stream-bar.hidden {
  display: none !important;
}

.viewer-stream-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  max-width: 1920px;
  margin: 0 auto;
  padding: 10px clamp(16px, 3vw, 40px);
  box-sizing: border-box;
}

.viewer-stream-picker-btn {
  appearance: none;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.viewer-stream-picker-btn:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

.viewer-stream-picker-btn.is-active {
  color: var(--text);
  background: rgba(26, 157, 221, 0.22);
  border-color: rgba(26, 157, 221, 0.55);
}

.viewer-stream-picker-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.viewer-stream-grid {
  display: grid;
  gap: clamp(12px, 2vw, 20px);
  max-width: 1920px;
  margin: 0 auto;
  padding: clamp(12px, 2vw, 24px) clamp(12px, 2vw, 32px);
  box-sizing: border-box;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.page-viewer-live .viewer-stream-grid {
  padding: clamp(8px, 1.2vw, 16px) 0 0;
}

.viewer-stream-grid--count-1 {
  grid-template-columns: minmax(0, 1fr);
  max-width: 960px;
}

.viewer-stream-grid--count-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.viewer-stream-cell__label {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.viewer-stream-empty {
  margin: 0;
  padding: 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.page-live-stream .viewer-live-matches {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 40px) 2rem;
}

.page-live-stream .viewer-live-matches__title {
  margin: 0 0 12px;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--muted);
}

.page-live-stream,
body.page-viewer-live.page-overlay {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

@media (min-height: 1101px) {
  .page-live-stream,
  body.page-viewer-live.page-overlay {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }
}

.viewer-live-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viewer-live-layout[hidden] {
  display: none !important;
}

body.page-viewer-live .viewer-live-layout:not([hidden]) {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
}

body.page-viewer-live .viewer-stream-bar {
  flex-shrink: 0;
}

body.page-viewer-live .bughouse-live-main.viewer-main {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: min(1600px, 100%);
  margin: 0 auto;
  padding: 0 clamp(12px, 2vw, 24px);
  box-sizing: border-box;
}

body.page-viewer-live .panel--live-stream {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0 clamp(12px, 2vw, 24px) clamp(12px, 2vw, 16px);
  box-sizing: border-box;
}

body.page-viewer-live .viewer-stream-grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  align-content: start;
  margin: 0;
  max-width: none;
}

body.page-viewer-live .viewer-stream-cell {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.page-viewer-live .viewer-video-frame {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  width: 100%;
  aspect-ratio: 16 / 9;
}

@media (max-height: 1100px) {
  body.page-live-stream.page-viewer,
  body.page-viewer-live.page-overlay {
    height: auto;
    max-height: none;
    overflow: auto;
  }

  body.page-viewer-live .viewer-live-layout:not([hidden]) {
    max-height: none;
    overflow: visible;
  }

  body.page-viewer-live .bughouse-live-main,
  body.page-viewer-live .panel--live-stream,
  body.page-viewer-live .viewer-stream-grid {
    overflow: visible;
    max-height: none;
    flex: none;
  }

  body.page-viewer-live .viewer-video-frame {
    max-height: none;
  }
}

.page-live-stream .viewer-main {
  flex: 1 1 auto;
  max-width: 100%;
  width: 100%;
  padding-top: 0;
}

.page-live-stream .viewer-page-title {
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
  padding-left: clamp(16px, 3vw, 40px);
  padding-right: clamp(16px, 3vw, 40px);
}

.form-input-compact {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--page-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
}

.viewer-table .form-input-compact {
  box-sizing: border-box;
}

.btn-compact {
  padding: 4px 10px;
  font-size: 12px;
}

/* Page transition — viewer pages only, does not affect OBS overlays */
.page-viewer {
  animation: _viewer-fadein 0.12s ease-out both;
}
@keyframes _viewer-fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Prevent layout shift on first-ever visit before nav cache is populated */
.viewer-nav:empty {
  min-height: 10rem;
}

/* ===========================================================================
 * Mobile layout — narrow viewports
 * ========================================================================= */

@media (max-width: 600px) {
  /* Admin page: tighten outer padding */
  .admin-list-header {
    padding: 16px 14px 14px;
  }

  .admin-list-main {
    padding: 14px 12px;
    gap: 14px;
  }

  .admin-list-section {
    padding: 14px 12px;
  }

  /* New-game / replay forms: collapse 4-column grid to 1 column */
  .form-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Game block player-name rows: 1 column */
  .game-block-names-grid,
  .game-block-names {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  /* Game card info columns (team/eboard panels): 1 column */
  .game-card-grid {
    grid-template-columns: 1fr;
  }

  /* Edit forms inside game/match cards: 1 column */
  .game-edit-grid {
    grid-template-columns: 1fr;
  }

  /* Game block header: let status badge wrap under the title */
  .game-block-head {
    flex-wrap: wrap;
  }

  /* Tighten inner padding on small screens */
  .game-block {
    padding: 12px;
  }

  .game-card {
    padding: 12px;
  }

  /* Live stream camera grid: stack vertically on phones */
  .viewer-stream-grid,
  .viewer-stream-grid--count-2 {
    grid-template-columns: 1fr;
  }
}
