/* ═══════════════════════════════════════════════════════════════════════════
   Checkers — black and green chrome, with the board doing the talking.

   The board is DOM (not canvas) because the E2E suite asserts against it, so
   everything here is about making a grid of divs read as a draughts board that
   is still usable at 14x14 and at 6x7. One CSS variable, --cols, carries the
   width of the board, and the squares, the pieces and the coordinate labels all
   scale from it — which is what keeps a 14-column board legible without a
   per-size stylesheet.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --font-display: 'Bebas Neue', 'DM Sans', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'DM Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --bg: #000000;
  --surface: #0b0b0b;
  --surface2: #131313;
  --surface3: #1c1c1c;
  --border: #232323;
  --border2: #2f2f2f;

  --text: #f5f5f5;
  --muted: #8a8a8a;

  --green: #1db954;
  --green-bright: #1ed760;
  --green-dim: #0f5c2a;
  --red: #e91429;
  --amber: #f5c518;

  /* The board itself: light squares are the "paper", dark squares are playable.
     The two piece colours deliberately do NOT reuse the accent green for both
     sides — a green piece and a green highlight would be one green too many. */
  --sq-light: #d9ddd3;
  --sq-dark: #1c2b21;
  --sq-dark-hover: #2a4031;
  --piece-white: #f2f4f0;
  --piece-white-edge: #9aa39b;
  --piece-black: #14181a;
  --piece-black-edge: #4b5457;
  --target: #1db954;
  --target-ring: rgba(30, 215, 96, 0.85);
  --last-move: #f5c518;
}

html[data-theme='light'] {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface2: #f0f3f0;
  --surface3: #e6eae6;
  --border: #d8ded8;
  --border2: #c6cec6;
  --text: #101410;
  --muted: #5c665c;
  --sq-light: #eef1ea;
  --sq-dark: #8aa892;
  --sq-dark-hover: #7a9a83;
  --piece-white: #ffffff;
  --piece-white-edge: #6d766d;
  --piece-black: #20242a;
  --piece-black-edge: #59606a;
}

/* MANDATORY: an overlay that is only visually hidden still swallows clicks. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.shell { max-width: 1120px; margin: 0 auto; padding: 14px 16px 44px; }

/* ── Header ────────────────────────────────────────────────────────────── */

.header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.home-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 12px; letter-spacing: .08em;
  color: var(--muted); text-decoration: none; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  transition: color .15s, border-color .15s;
}
.home-btn svg { width: 14px; height: 14px; }
.home-btn:hover { color: var(--green); border-color: var(--green-dim); }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { font-size: 22px; color: var(--green); line-height: 1; }
.brand-text { font-family: var(--font-display); font-size: 22px; letter-spacing: .14em; }
.header-right { display: flex; align-items: center; gap: 8px; }
.user-badge { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
  transition: color .15s, border-color .15s;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { color: var(--green); border-color: var(--green-dim); }

/* ── Screens ───────────────────────────────────────────────────────────── */

.screen { display: none; padding-top: 18px; }
.screen.active { display: block; }

.screen-title {
  font-family: var(--font-display); font-size: 40px; letter-spacing: .04em;
  margin: 0 0 6px;
}
.screen-sub { color: var(--muted); font-size: 14px; line-height: 1.55; margin: 0 0 18px; max-width: 78ch; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; align-items: flex-start; }

/* ── Buttons and fields ────────────────────────────────────────────────── */

.btn {
  font-family: var(--font-display); font-size: 16px; letter-spacing: .08em;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border2); border-radius: 10px;
  padding: 9px 16px; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.btn:hover { border-color: var(--green); color: var(--green); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled='true'] { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--green); border-color: var(--green); color: #04140a; font-weight: 700; }
.btn-primary:hover { background: var(--green-bright); color: #04140a; }
.btn-sm { font-size: 13px; padding: 6px 11px; border-radius: 8px; }
.btn-danger:hover { border-color: var(--red); color: var(--red); }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field-label, .field label {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .06em;
  color: var(--muted); text-transform: uppercase;
}
.field input, .field select, select, input[type="text"], input[type="number"] {
  background: var(--surface2); border: 1px solid var(--border2); border-radius: 8px;
  color: var(--text); padding: 8px 10px; font-family: var(--font-body); font-size: 14px;
}
input[type="number"] { width: 92px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--green); }
.checkbox-row label { font-size: 13.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--font-mono); }
.hidden { display: none !important; }

/* ── Menu ──────────────────────────────────────────────────────────────── */

.menu-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}
.mode-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
  transition: border-color .15s, transform .15s;
}
.mode-card:hover { border-color: var(--green-dim); transform: translateY(-2px); }
.mode-icon { font-size: 26px; line-height: 1; }
.mode-name { font-family: var(--font-display); font-size: 22px; letter-spacing: .06em; }
.mode-desc { color: var(--muted); font-size: 13px; line-height: 1.5; flex: 1; }
.mode-form { display: flex; flex-direction: column; gap: 8px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; min-width: 0; font-family: var(--font-mono); letter-spacing: .2em; text-align: center; }

.banner {
  margin-top: 16px; padding: 10px 14px; border-radius: 10px;
  background: var(--surface2); border: 1px solid var(--border2);
  font-size: 13.5px;
}
.banner.error { border-color: var(--red); color: #ff9aa5; }
.banner.good { border-color: var(--green-dim); color: var(--green); }

/* ── HUD ───────────────────────────────────────────────────────────────── */

.hud {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  justify-content: space-between; padding: 10px 0 12px;
  border-bottom: 1px solid var(--border); margin-bottom: 12px;
}
.hud-left { display: flex; align-items: center; gap: 10px; }
.turn-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border2); background: var(--piece-white);
  transition: background .2s;
}
.turn-dot.black { background: var(--piece-black); }
.hud-turns { display: flex; flex-direction: column; line-height: 1.15; }
.hud-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; }
.hud-value { font-family: var(--font-display); font-size: 20px; letter-spacing: .06em; }
.hud-stats { display: flex; flex-wrap: wrap; gap: 16px; }
.hud-stat { display: flex; flex-direction: column; line-height: 1.2; }
.hud-mode { font-size: 14px; }
.hud-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.online-strip {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 12px; margin-bottom: 12px; font-size: 13px;
}
.online-strip strong { font-family: var(--font-mono); font-size: 18px; letter-spacing: .18em; color: var(--green); }

/* ── The compulsory-capture cue ────────────────────────────────────────── */

.capture-banner {
  display: flex; align-items: center; gap: 10px;
  background: rgba(245, 197, 24, 0.10);
  border: 1px solid var(--amber); border-radius: 10px;
  padding: 8px 12px; margin-bottom: 12px;
  font-size: 13.5px; color: var(--amber);
}
.capture-icon { font-size: 16px; }

/* ── Board ─────────────────────────────────────────────────────────────── */

.board-wrap { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }

.board {
  /* --cols is set by app.js. The grid is square (aspect-ratio below) and never
     wider than 640px, so 14 columns still leaves ~44px a square on a desktop
     and the whole board shrinks with the viewport on a phone. */
  display: grid;
  grid-template-columns: repeat(var(--cols, 8), 1fr);
  gap: 0;
  width: min(100%, 640px);
  aspect-ratio: 1 / 1;
  border: 2px solid var(--border2);
  border-radius: 8px;
  overflow: hidden;
  background: var(--sq-dark);
  user-select: none;
  touch-action: manipulation;
}

.square {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 1 / 1;
  cursor: default;
}
.square.dark { background: var(--sq-dark); }
.square.light { background: var(--sq-light); cursor: default; }
.square.dark.playable { cursor: pointer; }
.square.dark.playable:hover { background: var(--sq-dark-hover); }

/* Coordinates: row letters down the left edge, column numbers along the bottom.
   Rendered with ::after so they add no DOM nodes for the E2E suite to trip on. */
.board.show-coords .square[data-coord-row]::before,
.board.show-coords .square[data-coord-col]::after {
  position: absolute; font-family: var(--font-mono); font-size: 9px;
  color: color-mix(in srgb, var(--text) 55%, transparent); pointer-events: none;
}
.board.show-coords .square[data-coord-row]::before { content: attr(data-coord-row); top: 2px; left: 3px; }
.board.show-coords .square[data-coord-col]::after { content: attr(data-coord-col); bottom: 1px; right: 3px; }

/* The piece. Its size and its crowning ring both scale from --cols. */
.piece {
  width: 76%; height: 76%; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(min(3.2vw, 20px));
  line-height: 1;
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, .35), 0 1px 2px rgba(0, 0, 0, .4);
  transition: transform .12s ease-out;
}
.piece[data-colour='white'] {
  background: radial-gradient(circle at 35% 30%, #ffffff, var(--piece-white) 60%, var(--piece-white-edge));
  border: 1px solid var(--piece-white-edge);
  color: #2a2f2a;
}
.piece[data-colour='black'] {
  background: radial-gradient(circle at 35% 30%, #3b4348, var(--piece-black) 65%, #05070a);
  border: 1px solid var(--piece-black-edge);
  color: var(--green);
}
.piece[data-king='true']::after {
  content: '♛';
  font-size: calc(min(2.6vw, 16px));
  opacity: .95;
}
.piece.animating { transform: scale(1.06); }

/* Selection and destinations. A destination is drawn as a ring rather than a
   disc so it can never be mistaken for a piece standing there. */
.square.selected { box-shadow: inset 0 0 0 3px var(--target-ring); }
.square.target::after {
  content: ''; position: absolute; width: 34%; height: 34%;
  border-radius: 50%; border: 3px solid var(--target);
  background: color-mix(in srgb, var(--target) 25%, transparent);
  pointer-events: none;
}
.square.target-capture::after { border-color: var(--red); background: color-mix(in srgb, var(--red) 22%, transparent); }
.square.last-move { box-shadow: inset 0 0 0 2px var(--last-move); }

/* Chain building. The head is a re-drawn (NOT moved) piece: the engine position
   is untouched until the chain is committed, so this is purely a preview. */
.square.chain-origin .piece { opacity: .35; }
.square.chain-head::before {
  content: ''; position: absolute; width: 76%; height: 76%; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, var(--piece-white) 60%, var(--piece-white-edge));
  border: 2px dashed var(--green);
  pointer-events: none;
}
.square.chain-head.black::before {
  background: radial-gradient(circle at 35% 30%, #3b4348, var(--piece-black) 65%, #05070a);
}
.square.chain-hop { box-shadow: inset 0 0 0 2px var(--green); }
.square.chain-taken .piece { opacity: .25; filter: grayscale(1); }

/* When a capture is compulsory, every piece that cannot take is visibly out of
   the game — the plan's "why can't I move?" answered before it is asked. */
.board.capture-only .square:not(.capturable):not(.target) .piece { opacity: .45; filter: saturate(.3); }
.board.capture-only .square.capturable { cursor: pointer; }
.board.capture-only .square.capturable .piece { box-shadow: 0 0 0 2px var(--amber), 0 1px 2px rgba(0,0,0,.4); }

.board.locked { opacity: .82; }
.board.locked .square { cursor: default; }

/* ── Side panel: the move list in real notation ────────────────────────── */

.side-panel {
  flex: 1 1 240px; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px;
}
.panel-title {
  font-family: var(--font-display); font-size: 18px; letter-spacing: .08em;
  margin: 0 0 8px; color: var(--muted);
}
.move-list {
  list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7;
}
.move-list li { display: flex; gap: 8px; border-bottom: 1px solid var(--border); padding: 1px 0; }
.move-list .mv-no { color: var(--muted); min-width: 26px; }
.move-list .mv-white { color: var(--text); min-width: 74px; }
.move-list .mv-black { color: var(--green); }
.move-empty { color: var(--muted); }

/* ── Puzzles ───────────────────────────────────────────────────────────── */

.puzzle-list {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.puzzle-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; gap: 6px; cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.puzzle-card:hover { border-color: var(--green-dim); transform: translateY(-2px); }
.puzzle-card.solved { border-color: var(--green-dim); }
.puzzle-name { font-family: var(--font-display); font-size: 20px; letter-spacing: .05em; display: flex; align-items: center; gap: 8px; }
.puzzle-tick { color: var(--green); font-size: 15px; }
.puzzle-blurb { color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.puzzle-meta { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

/* ── Settings ──────────────────────────────────────────────────────────── */

.settings-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
}
code { font-family: var(--font-mono); font-size: 12px; color: var(--green); }

/* ── Overlay ───────────────────────────────────────────────────────────── */

.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .72);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: 20px;
}
.overlay-card {
  background: var(--surface); border: 1px solid var(--border2); border-radius: 16px;
  padding: 22px 24px; max-width: 420px; width: 100%; text-align: center;
}
.overlay-title { font-family: var(--font-display); font-size: 32px; letter-spacing: .05em; margin: 0 0 8px; }
.overlay-body { color: var(--muted); font-size: 14px; line-height: 1.55; margin: 0 0 18px; }
.overlay-actions { display: flex; gap: 10px; justify-content: center; }

@media (max-width: 720px) {
  .board-wrap { flex-direction: column; }
  .board { width: 100%; }
  .screen-title { font-size: 32px; }
}
