/* ---------- Tokens ---------- */
/* Near-black and quiet, so the boards are the colour on the page; one blue
   accent (buttons, selection, the current move), with red and blue also the
   games' own sides. */
:root {
  --bg: #0e0f11;
  --surface: #16181b;
  --surface-2: #1e2125;
  --surface-3: #282c31;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);
  --hover: rgba(255, 255, 255, 0.05);
  --text: #f3f2ee;
  --text-muted: #8d929a;
  --text-faint: #5f646c;
  --accent: #2f6fed;
  --accent-hover: #4a82f2;
  --accent-ink: #fff;
  --link: #7fa8ff;
  --red: #e5534b;
  --blue: #3d7be0;
  --win: #5cc98a;
  --loss: #ef6461;
  --radius: 18px;
  --radius-m: 12px;
  --radius-s: 8px;
  --header-h: 60px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;

  /* Board colours (the ⚙ menu's Board row, <html data-board>): slate by
     default, or Lichess's blue, brown or green. */
  --square-light: #e6e8ec;
  --square-dark: #9aa6b4;
  --coord-on-light: #7d8896;
  --coord-on-dark: #eef0f3;
  --piece-black: #2a2c31;
  --piece-black-top: #3a3d44;
  --piece-white: #f4efe6;
  --piece-white-top: #ffffff;
  --crown: #e8b64c;
  /* Highlights, the same on every board. */
  --hl-last: rgba(246, 196, 83, 0.42);
  --hl-selected: rgba(246, 196, 83, 0.62);
  --hl-dot: rgba(18, 20, 24, 0.24);
  --hl-hint: rgba(61, 123, 224, 0.5);
}
:root[data-board="blue"] {
  --square-light: #dee3e6;
  --square-dark: #8ca2ad;
  --coord-on-light: #788a94;
  --coord-on-dark: #dee3e6;
}
:root[data-board="brown"] {
  --square-light: #f0d9b5;
  --square-dark: #b58863;
  --coord-on-light: #946f51;
  --coord-on-dark: #f0d9b5;
}
:root[data-board="green"] {
  --square-light: #ffffdd;
  --square-dark: #86a666;
  --coord-on-light: #6d8753;
  --coord-on-dark: #ffffdd;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { color: #a3c1ff; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--text-muted); }
[hidden] { display: none !important; }
h1, h2, h3 { letter-spacing: -0.02em; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-m);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}
.btn:hover { background: var(--accent-hover); color: var(--accent-ink); }
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.35; cursor: default; transform: none; background: var(--accent); }
.btn-block { display: flex; width: 100%; }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--hover); color: var(--text); }
.btn-danger { background: var(--loss); color: #fff; }
.btn-danger:hover { background: #f47c79; color: #fff; }
.btn-small { min-height: 32px; padding: 5px 12px; font-size: 0.85rem; border-radius: var(--radius-s); }
.text-btn {
  padding: 6px 10px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
}
.text-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.icon-btn:hover, .icon-btn[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }
.icon { width: 20px; height: 20px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  background: rgba(14, 15, 17, 0.8);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.logo { display: inline-flex; align-items: center; gap: 10px; color: var(--text); }
.logo:hover { color: var(--text); }
.logo-mark { display: block; width: 28px; height: 28px; }
.logo-word { font-weight: 750; font-size: 1.05rem; letter-spacing: -0.03em; }
.header-left { display: flex; align-items: center; gap: 4px; min-width: 0; }
.game-title { margin: 0; font-size: 1rem; font-weight: 650; }

.nav { display: flex; align-items: center; gap: 4px; }
.nav-link { padding: 7px 12px; border-radius: 999px; color: var(--text-muted); font-weight: 550; font-size: 0.92rem; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.user-menu { position: relative; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 12px 3px 3px;
  border-radius: 999px;
  list-style: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
}
.user-chip::-webkit-details-marker { display: none; }
.user-chip:hover, .user-menu[open] .user-chip { background: var(--surface-2); }
.avatar {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
}
.user-pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 190px;
  padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.user-pop form { margin: 0; }
.pop-row {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
}
.pop-row:hover { background: var(--hover); color: var(--text); }
@media (max-width: 520px) {
  .nav-link, .user-name { display: none; }
  .user-chip { padding: 3px; }
}

/* ---------- Log in ---------- */
.auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 32px 16px;
  background: radial-gradient(60% 50% at 50% 0%, rgba(47, 111, 237, 0.12), transparent 70%);
}
.auth-brand .logo { flex-direction: column; gap: 14px; }
.auth-brand .logo-mark { width: 56px; height: 56px; }
.auth-brand .logo-word { font-size: 1.7rem; }
.auth-tagline { max-width: 340px; margin: 10px 0 28px; color: var(--text-muted); text-align: center; }
.auth-card { width: min(380px, 100%); padding: 28px; }
.auth-card h1 { margin: 0 0 20px; font-size: 1.3rem; }
.input-field { display: block; margin-bottom: 16px; }
.input-field span { display: block; margin-bottom: 6px; font-size: 0.85rem; font-weight: 550; color: var(--text-muted); }
.input-field input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-m);
  background: var(--bg);
  font-size: 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.25); }
.form-error, .form-ok { margin: 0 0 16px; padding: 10px 14px; border-radius: var(--radius-m); font-size: 0.9rem; }
.form-error { background: rgba(239, 100, 97, 0.1); color: #ff8f8c; }
.form-ok { background: rgba(92, 201, 138, 0.1); color: var(--win); }
.hint-text { margin: 4px 0 16px; color: var(--text-muted); font-size: 0.85rem; }
.auth-switch { margin: 18px 0 0; text-align: center; color: var(--text-muted); font-size: 0.9rem; }

/* ---------- Home ---------- */
.home { max-width: 1080px; margin: 0 auto; padding: 56px 20px 64px; }
.home-title { margin: 0 0 24px; font-size: clamp(1.7rem, 3vw, 2.2rem); font-weight: 750; line-height: 1.1; letter-spacing: -0.035em; }

.game-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.game-card {
  display: flex;
  flex-direction: column;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: transform 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}
.game-card:hover { transform: translateY(-3px); border-color: var(--border-strong); background: var(--surface-2); color: var(--text); }
.thumb { display: block; width: 100%; aspect-ratio: 1; border-radius: 12px; }
.game-card-body { display: flex; flex-direction: column; padding: 16px 8px 6px; }
.game-card-name { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
.game-card-blurb { color: var(--text-muted); font-size: 0.92rem; }
.game-card-rating { display: flex; align-items: baseline; gap: 8px; margin: auto 8px 6px; padding-top: 14px; }
.game-card-play {
  margin-left: auto;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-3);
  font-size: 0.82rem;
  font-weight: 650;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.game-card:hover .game-card-play { background: var(--accent); color: var(--accent-ink); }
.rating-num { font-size: 1.15rem; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.rating-games { color: var(--text-muted); font-size: 0.8rem; }
@media (max-width: 760px) {
  .home { padding-top: 32px; }
  .game-cards { grid-template-columns: 1fr; gap: 12px; }
  .game-card { flex-direction: row; align-items: center; gap: 14px; }
  .thumb { width: 76px; flex: none; }
  .game-card-body { flex: 1; padding: 0; }
  .game-card-rating { flex-direction: column; align-items: flex-end; gap: 0; margin: 0 8px 0 0; padding: 0; }
  .game-card-play { display: none; }
}
.xq-thumb { position: relative; overflow: hidden; background: var(--square-light); }
.xq-thumb svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.xq-thumb-lines line { stroke: var(--coord-on-light); stroke-width: 0.03; }
.xq-thumb .xq-piece { position: absolute; width: 20%; height: 20%; }

/* ---------- Leaderboard and credits ---------- */
.narrow { max-width: 760px; margin: 0 auto; padding: 40px 20px 56px; }
.page-title { margin: 0 0 20px; font-size: 1.9rem; font-weight: 750; letter-spacing: -0.03em; }
.tabs-links { margin-bottom: 16px; }
.empty { padding: 28px; text-align: center; color: var(--text-muted); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; overflow: hidden; }
.table th, .table td { padding: 13px 16px; border-bottom: 1px solid var(--border); text-align: left; }
.table tr:last-child td { border-bottom: 0; }
.table th { color: var(--text-faint); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .rank { color: var(--text-muted); width: 3rem; font-variant-numeric: tabular-nums; }
.table tr.is-you td { background: rgba(47, 111, 237, 0.08); }
.player-link { color: var(--text); font-weight: 600; }
.player-link:hover { color: var(--link); }
@media (max-width: 520px) { .wide-only { display: none; } }
.prose .card { padding: 6px 24px 20px; }
.prose h2 { margin: 20px 0 8px; font-size: 1.05rem; }
.prose ul { margin: 0; padding-left: 1.2rem; color: var(--text-muted); }
.prose li { margin-bottom: 6px; }
.prose li strong { color: var(--text); }

/* ---------- Tabs and segmented controls ---------- */
.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
}
.tab {
  flex: 1;
  padding: 8px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.92rem;
  text-align: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"], .tab[aria-current="page"] { background: var(--surface-3); color: var(--text); }
.field-label { margin: 20px 0 8px; color: var(--text-faint); font-size: 0.72rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  height: 40px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.seg button:hover { border-color: var(--border-strong); }
.seg button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg-levels button { font-variant-numeric: tabular-nums; }

/* Each side's colour: the player bars, Play as, histories. */
.side-dot { display: inline-block; flex: none; width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.2); }
[data-game="xiangqi"] .side-0, [data-game="hex"] .side-0, .side-0[data-game="xiangqi"], .side-0[data-game="hex"] { background: var(--red); }
[data-game="xiangqi"] .side-1, .side-1[data-game="xiangqi"] { background: #1b1b1d; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.35); }
[data-game="hex"] .side-1, .side-1[data-game="hex"] { background: var(--blue); }
[data-game="checkers"] .side-0, .side-0[data-game="checkers"] { background: var(--piece-black); box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.35); }
[data-game="checkers"] .side-1, .side-1[data-game="checkers"] { background: var(--piece-white); box-shadow: none; }

/* ---------- The game page ---------- */
/* The board column (a player bar, the board, a player bar) beside the panel
   on wide screens, the panel under it on narrow ones. The board is as big
   as fits: the width the panel leaves, or the height under the header less
   the two bars, whichever is smaller. */
.play {
  --panel-w: 340px;
  --bar-h: 48px;
  --bar-gap: 12px;
  --gap: 28px;
  --pad: 20px;
  --avail-w: calc(100vw - 2 * var(--pad) - var(--gap) - var(--panel-w));
  --avail-h: calc(100dvh - var(--header-h) - env(safe-area-inset-top) - 2 * var(--pad) - 2 * (var(--bar-h) + var(--bar-gap)));
  --board-w: min(var(--avail-w), var(--avail-h), 860px);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: var(--gap);
  padding: var(--pad);
}
.play[data-game="xiangqi"] { --board-w: min(var(--avail-w), (var(--avail-h) - 8px) * 0.9, 780px); }
.play[data-game="hex"] { --board-w: min(var(--avail-w), 1000px); }
.board-col { flex: none; width: var(--board-w); }
.panel { flex: none; width: var(--panel-w); padding: 18px; }
@media (max-width: 860px) {
  .play {
    --pad: 10px;
    --bar-h: 44px;
    --bar-gap: 8px;
    --avail-w: calc(100vw - 2 * var(--pad));
    --board-w: min(var(--avail-w), max(var(--avail-h), 300px));
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
  }
  .play[data-game="xiangqi"] { --board-w: min(var(--avail-w), max((var(--avail-h) - 8px) * 0.9, 300px)); }
  .play[data-game="hex"] { --board-w: var(--avail-w); }
  .panel { width: min(100%, 560px); }
}

/* ---------- Player bars ---------- */
.player-bar { display: flex; align-items: center; gap: 12px; height: var(--bar-h); }
#bar-top { margin-bottom: var(--bar-gap); }
#bar-bottom { margin-top: var(--bar-gap); }
.pb-avatar { position: relative; width: 34px; height: 34px; font-size: 0.9rem; }
.pb-avatar .pb-side { position: absolute; right: -2px; bottom: -2px; width: 13px; height: 13px; border: 2px solid var(--bg); box-sizing: content-box; }
.pb-who { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.pb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.pb-rating { color: var(--text-muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.pb-rating:empty { display: none; }
.pb-captured { display: flex; flex: 1; align-items: center; justify-content: flex-end; min-width: 0; overflow: hidden; }
.pb-clock {
  flex: none;
  min-width: 100px;
  padding: 7px 14px;
  border-radius: var(--radius-m);
  background: var(--surface-2);
  color: var(--text-faint);
  font-size: 1.35rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  text-align: right;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.pb-clock.running { background: var(--text); color: #121316; }
.pb-clock.low { color: var(--loss); }
.pb-clock.running.low { background: var(--loss); color: #fff; }
.player-bar.is-turn .pb-avatar { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }

/* Pieces taken, in each side's bar. */
.captured-piece { flex: none; width: 22px; height: 22px; }
.captured-piece.same { margin-left: -12px; }
.captured-disc { flex: none; width: 14px; height: 14px; margin-left: -5px; border-radius: 50%; }
.captured-disc:first-child { margin-left: 0; }
.captured-disc.black { background: var(--piece-black); box-shadow: 0 0 0 1.5px var(--bg), inset 0 0 0 1px rgba(255, 255, 255, 0.25); }
.captured-disc.white { background: var(--piece-white); box-shadow: 0 0 0 1.5px var(--bg); }
.captured-score { margin-left: 8px; color: var(--text-muted); font-size: 0.8rem; font-weight: 650; }

/* ---------- Boards (checkers and xiangqi) ---------- */
.board-wrap { position: relative; }
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 10px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06), 0 24px 60px rgba(0, 0, 0, 0.45);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.board.can-move { cursor: pointer; }
:root:not([data-drag="off"]) .board { touch-action: none; }
.square { position: relative; }
.square.light { background: var(--square-light); }
.square.dark { background: var(--square-dark); }
.square.last::before, .square.selected::before { content: ''; position: absolute; inset: 0; background: var(--hl-last); }
.square.selected::before { background: var(--hl-selected); }
.square.hint { box-shadow: inset 0 0 0 100vmax var(--hl-hint); }
.square.target::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--hl-dot);
}
.square.target.capture::after { width: 86%; height: 86%; background: transparent; box-shadow: inset 0 0 0 5px var(--hl-dot); }
.square.target.drag-over::after { width: 100%; height: 100%; border-radius: 0; background: var(--hl-dot); }
/* A general in check: a red glow round the point, wider than the piece. */
.square.check { background: radial-gradient(circle closest-side, rgba(239, 68, 68, 0.95) 60%, rgba(239, 68, 68, 0.45) 85%, transparent 100%); }

/* Pieces on their own layer, placed with left/top so a move slides. */
.pieces { position: absolute; inset: 0; pointer-events: none; }
.piece {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  transition: left 0.2s cubic-bezier(0.3, 0.7, 0.4, 1), top 0.2s cubic-bezier(0.3, 0.7, 0.4, 1), opacity 0.2s ease;
}
.pieces.no-anim .piece { transition: none; }
.piece.dragging { z-index: 10; transition: none; cursor: grabbing; scale: 1.08; }
.piece.captured { opacity: 0; }
.board-arrows { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; opacity: 0.6; overflow: visible; pointer-events: none; }

/* Checkers men: flat discs with a lip underneath; kings wear a crown. */
.piece.black::before, .piece.white::before { content: ''; position: absolute; inset: 12%; border-radius: 50%; }
.piece.black::before {
  background: linear-gradient(180deg, var(--piece-black-top), var(--piece-black));
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 3px 8px rgba(0, 0, 0, 0.35);
}
.piece.white::before {
  background: linear-gradient(180deg, var(--piece-white-top), var(--piece-white));
  box-shadow: inset 0 -4px 0 rgba(120, 100, 70, 0.22), 0 3px 8px rgba(0, 0, 0, 0.3);
}
.piece.king::after {
  content: '';
  position: absolute;
  inset: 32% 30% 34%;
  background: var(--crown);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 18'%3E%3Cpath d='M2 16h20v2H2zM1 4l6 5 5-8 5 8 6-5-2 10H3z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 18'%3E%3Cpath d='M2 16h20v2H2zM1 4l6 5 5-8 5 8 6-5-2 10H3z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.checkers-board { container-type: inline-size; }
.square-number {
  display: none;
  position: absolute;
  top: 3px;
  right: 5px;
  z-index: 1;
  font-size: calc(12.5cqw * 0.15);
  font-weight: 650;
  line-height: 1.2;
  color: var(--coord-on-dark);
  opacity: 0.85;
  pointer-events: none;
}
.show-numbers .square-number { display: block; }

/* Xiangqi: 9 x 10 points, one cell round each, over an SVG of the lines. */
.board.xiangqi-board { grid-template-columns: repeat(9, 1fr); aspect-ratio: 9 / 10; background: var(--square-light); }
.xq-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.xq-line, .xq-mark { stroke: var(--coord-on-light); stroke-width: 0.028; fill: none; stroke-linecap: round; }
.xq-mark { stroke-width: 0.02; }
.xq-frame { stroke: var(--coord-on-light); stroke-width: 0.055; fill: none; }
.xq-river { fill: var(--coord-on-light); font: 600 44px var(--font); letter-spacing: 40px; text-anchor: middle; dominant-baseline: central; opacity: 0.55; }
.xiangqi-board .piece { width: calc(100% / 9); height: 10%; }
.xiangqi-board .piece { filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.28)); }
.xiangqi-board .piece.dragging { filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.35)); }
.xiangqi-board .piece.in-check { filter: drop-shadow(0 0 3px #ef4444) drop-shadow(0 0 6px #ef4444) drop-shadow(0 0 12px rgba(239, 68, 68, 0.9)); }
.xiangqi-board .square.target::after { width: 24%; height: 24%; }
/* A piece covers most of its cell, so these are circles a little bigger
   than it: a ring round a piece, a disc on an empty point. */
.xiangqi-board .square.last::before, .xiangqi-board .square.selected::before { inset: -4%; border-radius: 50%; }
.xiangqi-board .square.selected::before { background: rgba(246, 196, 83, 0.85); }
/* A piece that can be taken: a dark ring just outside it, like the move dots
   (a ring inside would be hidden by the piece). Dragging over it fills the
   ring's circle instead of the whole cell. */
.xiangqi-board .square.target.capture::after,
.xiangqi-board .square.target.drag-over::after { inset: -6%; width: auto; height: auto; border-radius: 50%; box-shadow: none; }
.xiangqi-board .square.target.capture::after { background: radial-gradient(circle closest-side, transparent 79%, rgba(18, 20, 24, 0.5) 81%, rgba(18, 20, 24, 0.5) 97%, transparent 100%); }
.xiangqi-board .square.target.drag-over::after { background: rgba(18, 20, 24, 0.3); }
.xq-piece { background-size: 100% 100%; background-repeat: no-repeat; }
.xq-files {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  grid-template-columns: repeat(9, 1fr);
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  color: var(--text-faint);
  pointer-events: none;
}
.xq-files:first-child { top: -14px; }
.xq-files:last-child { bottom: -14px; }
.xiangqi-wrap:has(.show-numbers) .xq-files { display: grid; }

/* Hex: its own colours whatever the Board setting: cream cells with thin
   gaps, flat red and blue stones, rounded edge bars. The script sizes the
   SVG to the area. */
.hex-wrap { display: flex; justify-content: center; }
.hex-area {
  --hex-cell: #ece3d1;
  --hex-gap: #0e0f11;
  --hex-red: var(--red);
  --hex-blue: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: min(var(--avail-h), 860px);
}
@media (max-width: 860px) {
  .hex-area { height: clamp(280px, var(--avail-h), calc(var(--avail-w) * 1.25)); }
}
.hex-board { display: block; max-width: 100%; max-height: 100%; overflow: visible; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.hex-cell { fill: var(--hex-cell); stroke: var(--hex-gap); stroke-width: 0.09; stroke-linejoin: round; transition: fill 0.15s ease; }
.hex-cell.playable, .hex-cell.swappable { cursor: pointer; }
@media (hover: hover) {
  .hex-cell.playable:hover { fill: #ddd1ba; }
}
.hex-cell.last { fill: color-mix(in srgb, var(--hex-cell) 58%, rgb(246, 196, 83)); }
.hex-cell.hint { fill: color-mix(in srgb, var(--hex-cell) 45%, var(--blue)); }
.hex-edge { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.hex-edge.red { stroke: var(--hex-red); }
.hex-edge.blue { stroke: var(--hex-blue); }
.hex-coords { display: none; fill: var(--text-faint); font-size: 0.34px; font-weight: 600; pointer-events: none; }
.show-numbers .hex-coords { display: inline; }
.hex-stones, .hex-path { pointer-events: none; }
.hex-stone { stroke: rgba(0, 0, 0, 0.18); stroke-width: 0.05; transform-box: fill-box; transform-origin: center; }
.hex-stone.red { fill: var(--hex-red); }
.hex-stone.blue { fill: var(--hex-blue); }
.hex-stone.placed { animation: pop-in 0.22s cubic-bezier(0.3, 0.7, 0.4, 1.3); }
.hex-path-mark { fill: rgba(255, 255, 255, 0.92); }
@keyframes pop-in { from { opacity: 0; scale: 0.5; } }

/* ---------- The panel ---------- */
.mode-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 18px 0 14px;
  padding: 16px;
  background: var(--surface-2);
  border-radius: var(--radius-m);
}
.mode-icon { flex: none; width: 26px; height: 26px; color: var(--link); }
.mode-title { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em; }
.mode-sub { color: var(--text-muted); font-size: 0.85rem; }
.mode-rating { margin-left: auto; text-align: right; }
.mode-rating .rating-num { line-height: 1.2; }
#body-computer .btn { margin-top: 22px; }
.seeking {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 8px 8px 8px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-m);
  font-weight: 600;
}
.seeking .text-btn { margin-left: auto; }
.spinner {
  flex: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.note { margin: 14px 0 0; color: var(--text-muted); font-size: 0.875rem; text-align: center; }

.status-row { display: flex; flex-direction: column; gap: 8px; }
.mode-pill {
  align-self: flex-start;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}
.status { margin: 0; font-size: 1.1rem; font-weight: 650; letter-spacing: -0.01em; }
.actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; margin-top: 18px; }
.action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 12px 4px 10px;
  border: 0;
  border-radius: var(--radius-m);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.action svg { width: 20px; height: 20px; }
.action:hover:not(:disabled) { background: var(--surface-3); }
.action:disabled { opacity: 0.3; cursor: default; }
.action.is-busy { opacity: 1; animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }
#resign-btn:hover:not(:disabled) { color: #ff8f8c; }
.draw-offer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-m);
  background: rgba(47, 111, 237, 0.1);
  border: 1px solid rgba(47, 111, 237, 0.3);
  font-weight: 600;
}
.draw-offer-actions { display: flex; gap: 6px; }
.result { margin-top: 16px; padding: 18px; border-radius: var(--radius-m); background: var(--surface-2); text-align: center; }
.result-title { margin: 0; font-size: 1.5rem; font-weight: 750; }
.result[data-outcome="win"] .result-title { color: var(--win); }
.result[data-outcome="loss"] .result-title { color: var(--loss); }
.result-detail { margin: 4px 0 0; color: var(--text-muted); }
.result-rating { margin: 10px 0 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.after-actions { display: grid; gap: 8px; margin-top: 14px; }

/* ---------- Profile ---------- */
.profile { max-width: 1000px; margin: 0 auto; padding: 40px 20px 64px; }
.profile-head { display: flex; align-items: center; gap: 20px; padding: 24px; }
.profile-head p { margin: 4px 0 0; }
.avatar-big { width: 72px; height: 72px; font-size: 2rem; background: var(--accent); color: var(--accent-ink); }
.profile-name { margin: 0; font-size: 2rem; font-weight: 750; letter-spacing: -0.03em; }
.section-title { margin: 40px 0 14px; font-size: 1.15rem; font-weight: 700; }
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stat-card { display: flex; flex-direction: column; padding: 18px; }
.stat-head { display: flex; align-items: center; gap: 10px; }
.stat-thumb { width: 32px; flex: none; }
.stat-thumb .thumb { width: 100%; border-radius: 8px; }
.stat-name { flex: 1; font-weight: 650; }
.rank-pill { padding: 3px 10px; border-radius: 999px; background: var(--surface-2); font-size: 0.78rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-rating { margin: 14px 0 12px; font-size: 2.4rem; font-weight: 750; line-height: 1; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.wdl { display: flex; gap: 2px; height: 6px; overflow: hidden; border-radius: 999px; background: var(--surface-2); }
.wdl span { border-radius: 999px; }
.wdl-win { background: var(--win); }
.wdl-draw { background: var(--text-faint); }
.wdl-loss { background: var(--loss); }
.stat-list { display: grid; grid-template-columns: repeat(5, auto); gap: 4px 10px; margin: 14px 0 0; }
.stat-list div { display: flex; flex-direction: column; }
.stat-list dt { color: var(--text-faint); font-size: 0.72rem; }
.stat-list dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat-empty { margin: 4px 0 0; }
.stat-computer { margin: auto 0 0; padding-top: 14px; font-size: 0.85rem; }
.history { overflow: hidden; }
.history-row {
  display: grid;
  grid-template-columns: 8.5rem 1fr 11rem 4.5rem 6.5rem;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  transition: background-color 0.15s ease;
}
.history-row:last-child { border-bottom: 0; }
.history-row:hover { background: var(--hover); color: var(--text); }
.history-game { display: flex; align-items: center; gap: 9px; font-weight: 650; }
.history-opp { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-result { display: flex; align-items: center; gap: 8px; }
.history-reason { font-size: 0.8rem; white-space: nowrap; }
.result-pill { padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; }
.result-pill.win { background: rgba(92, 201, 138, 0.13); color: var(--win); }
.result-pill.loss { background: rgba(239, 100, 97, 0.13); color: #ff8f8c; }
.result-pill.draw { background: var(--surface-2); color: var(--text-muted); }
.history-change { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-muted); }
.history-change.up { color: var(--win); }
.history-change.down { color: #ff8f8c; }
.history-date { text-align: right; font-size: 0.85rem; }
.pager { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.password-card { max-width: 580px; padding: 24px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 820px) {
  .stat-cards { grid-template-columns: 1fr; }
  .history-row { grid-template-columns: 1fr auto; gap: 4px 12px; }
  .history-game { grid-column: 1; }
  .history-opp { grid-column: 1; grid-row: 2; color: var(--text-muted); }
  .history-result { grid-column: 2; grid-row: 1; justify-content: flex-end; }
  .history-reason { display: none; }
  .history-change { grid-column: 2; grid-row: 2; }
  .history-date { display: none; }
  .field-pair { grid-template-columns: 1fr; gap: 0; }
}

/* ---------- Reviewing a game ---------- */
.replay-panel { display: flex; flex-direction: column; gap: 16px; max-height: calc(100dvh - var(--header-h) - 2 * var(--pad)); }
.replay-players { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 600; }
.replay-players a { display: inline-flex; align-items: center; gap: 7px; color: var(--text); }
.replay-players a:hover { color: var(--link); }
.replay-result { margin-top: 10px; font-size: 1.5rem; font-weight: 750; letter-spacing: -0.02em; }
.replay-result[data-outcome="win"] { color: var(--win); }
.replay-result[data-outcome="loss"] { color: var(--loss); }
.replay-meta { font-size: 0.85rem; }
.move-list {
  position: relative;
  flex: 1;
  min-height: 120px;
  max-height: 420px;
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  list-style: none;
  background: var(--bg);
  border-radius: var(--radius-m);
  font-variant-numeric: tabular-nums;
}
.move-row { display: grid; grid-template-columns: 2.6rem 1fr 1fr; align-items: center; border-radius: 8px; }
.move-row:nth-child(even) { background: rgba(255, 255, 255, 0.025); }
.move-num { padding-left: 10px; color: var(--text-faint); font-size: 0.82rem; }
.mv {
  padding: 6px 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font-weight: 600;
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
}
.mv:hover { background: var(--hover); }
.mv.is-current { background: var(--accent); color: var(--accent-ink); }
.mv-empty { color: var(--text-faint); cursor: default; }
.move-empty { padding: 14px; text-align: center; }
.replay-nav { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.replay-nav .action { padding: 11px 4px; }
.when-playing, .is-playing .when-paused { display: none; }
.is-playing .when-playing { display: block; }
@media (max-width: 860px) {
  .replay-panel { max-height: none; }
  .move-list { max-height: 220px; }
}

/* ---------- The ⚙ menu ---------- */
.settings { position: relative; }
#settings-btn svg { transition: transform 0.3s ease; }
#settings-btn[aria-expanded="true"] svg { transform: rotate(60deg); }
.settings-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 50;
  width: 240px;
  padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  font-size: 14px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.settings-row:hover { background: var(--hover); }
.settings-row.static { cursor: default; }
.settings-row.static:hover { background: transparent; }
.settings-divider { height: 1px; margin: 4px 6px; background: var(--border); }
.settings-hint { color: var(--text-muted); }
.settings-select { padding: 5px 8px; border: 1px solid var(--border-strong); border-radius: 7px; background: var(--bg); font-size: 13px; }
.switch { position: relative; flex: none; width: 32px; height: 19px; border-radius: 999px; background: var(--surface-3); transition: background-color 0.2s ease; }
.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.2s ease, background-color 0.2s ease;
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(13px); background: #fff; }

/* ---------- Dialogs ---------- */
.dialog {
  width: min(380px, calc(100% - 2rem));
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.dialog[open] { animation: dialog-in 0.2s cubic-bezier(0.3, 0.7, 0.4, 1); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.dialog::backdrop { background: rgba(5, 6, 8, 0.6); backdrop-filter: blur(3px); }
.dialog h2 { margin: 0 0 6px; font-size: 1.4rem; font-weight: 750; outline: none; }
.dialog-text { margin: 0; color: var(--text-muted); }
.dialog-rating { margin: 12px 0 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.result-dialog { text-align: center; }
.result-dialog .dialog-actions { flex-wrap: wrap; }
.result-dialog .dialog-actions > * { flex: 1 1 0; }
#dialog-again { order: -1; flex-basis: 100%; }
.result-dialog[data-outcome="win"] h2 { color: var(--win); }
.result-dialog[data-outcome="loss"] h2 { color: var(--loss); }

/* ---------- Animations off (the ⚙ menu) ---------- */
[data-anim="off"] *, [data-anim="off"] *::before, [data-anim="off"] *::after {
  transition: none !important;
  animation: none !important;
}
[data-anim="off"] .spinner { animation: spin 0.8s linear infinite !important; }
