/* ============================================================
   XQCHESS — Game CSS  (lobby + game board)
   ============================================================ */

/* ── Lobby page ─────────────────────────────────────────────── */
.lobby-page {
  max-width: 780px;
  margin: 0 auto;
  padding: 2rem 1.25rem 5rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

/* Hero */
.lobby-hero {
  text-align: center;
  padding: 2.5rem 1rem 1rem;
}
.lobby-title {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  margin-bottom: .5rem;
}
.lobby-title-char {
  font-size: 1em;
  line-height: 1;
  color: var(--jade-l);
}
.lobby-subtitle {
  color: var(--text-dim);
  font-size: .95rem;
  margin-bottom: 1.25rem;
}
.lobby-elo-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  background: var(--ground-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .6rem 1.5rem;
  gap: 2px;
}
.lobby-elo-badge .eyebrow {
  font-size: 10px;
}
.lobby-elo-val {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--jade-l);
  font-variant-numeric: tabular-nums;
}

/* Matchmaking card */
.lobby-card {
  background: var(--ground-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  overflow: hidden;
  position: relative;
}
.lc-state {
  display: flex;
  gap: 2rem;
  align-items: center;
}
.lc-state--hidden { display: none !important; }
.lc-body {
  flex: 1;
  min-width: 0;
}
.lc-body h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .5rem;
}
.lc-desc {
  color: var(--text-dim);
  font-size: .875rem;
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

/* Time control buttons */
.lc-options { margin-bottom: 1.25rem; }
.lc-option-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: .5rem;
}
.lc-time-btns {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.lc-time-btn {
  background: var(--ground-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .4rem .9rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.lc-time-btn:hover { border-color: var(--border-h); color: var(--text); }
.lc-time-btn.active {
  border-color: var(--jade-l);
  color: var(--jade-l);
  background: color-mix(in srgb, var(--jade-l) 12%, transparent);
}

/* Find match button */
.btn-find-match {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  background: var(--jade-l);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: .75rem 1.75rem;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn-find-match:hover { opacity: .9; }
.btn-find-match:active { transform: scale(.97); }
.btn-find-icon {
  font-size: 1.2rem;
  line-height: 1;
}

/* Board preview (mini canvas) */
.lobby-board-preview {
  flex-shrink: 0;
}
.lobby-board-preview canvas {
  display: block;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* Searching state */
.lobby-spinner {
  position: relative;
  width: 72px;
  height: 72px;
  flex-shrink: 0;
}
.spinner-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--jade-l);
  animation: spin 1s linear infinite;
}
.spinner-char {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  color: var(--text-dim);
}
@keyframes spin { to { transform: rotate(360deg); } }

.lc-wait-time {
  color: var(--text-dim);
  font-size: .875rem;
  margin-bottom: .25rem;
}
.lc-wait-time strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.lc-queue-pos {
  color: var(--text-dim);
  font-size: .8rem;
  margin-bottom: 1rem;
  min-height: 1.2em;
}
.btn-cancel {
  background: transparent;
  border: 1px solid var(--border-h);
  border-radius: 8px;
  padding: .4rem 1rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.btn-cancel:hover { border-color: #C06060; color: #C06060; }

/* Found state */
.lobby-found-icon {
  font-size: 3rem;
  animation: pop .4s cubic-bezier(.175,.885,.32,1.275);
  flex-shrink: 0;
  width: 72px;
  text-align: center;
}
@keyframes pop {
  from { transform: scale(0) rotate(-30deg); opacity: 0; }
  to   { transform: scale(1) rotate(0);     opacity: 1; }
}

/* Info section */
.lobby-info-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1rem;
}
.lobby-info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
.lib-card {
  background: var(--ground-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.25rem 1.5rem;
}
.lib-icon {
  display: block;
  font-size: 2rem;
  margin-bottom: .75rem;
  color: var(--text-dim);
}
.lib-card h3 {
  font-size: .875rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .4rem;
}
.lib-card p {
  font-size: .8rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ── Game page ──────────────────────────────────────────────── */
.game-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem .75rem 2rem;
  gap: .75rem;
  max-width: 560px;
  margin: 0 auto;
}

/* Player row */
.game-player {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .5rem .75rem;
  background: var(--ground-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.gp-info {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-width: 0;
}
.gp-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--ground-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  border: 2px solid var(--border);
  flex-shrink: 0;
}
.game-player--bottom .gp-avatar { border-color: var(--jade-l); }

.gp-name {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
/* Text on this page uses --text-dim, never --text-faint: 1.8:1 on --ground-2, under the 4.5:1 minimum (§5.6) */
.gp-elo {
  font-size: .75rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  display: block;
}

/* Active turn highlight on player row */
.gp--active-turn {
  border-color: var(--jade-l);
  background: color-mix(in srgb, var(--jade-l) 7%, var(--ground-2));
  transition: border-color .25s, background .25s;
}

/* Timer */
.gp-timer {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
  padding: .25rem .6rem;
  border-radius: 6px;
  background: var(--ground-3);
  border: 1px solid var(--border);
  transition: color .3s, border-color .3s, background .3s;
}
.gp-timer--active {
  color: var(--text);
  border-color: var(--jade-l);
  background: color-mix(in srgb, var(--jade-l) 10%, transparent);
}
.gp-timer--low {
  color: #C06060;
  border-color: #C06060;
  background: color-mix(in srgb, #C06060 10%, transparent);
  animation: pulse-low 1s ease-in-out infinite;
}
@keyframes pulse-low {
  0%, 100% { opacity: 1; }
  50%       { opacity: .65; }
}

/* Board wrapper */
.game-board-wrap {
  width: 100%;
}
.game-board-wrap canvas {
  display: block;
  max-width: 100%;
  cursor: pointer;
  touch-action: manipulation;
}

/* Toast — brief visible feedback for a rejected action (Cờ Úp) */
.game-toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translate(-50%, 12px);
  max-width: min(90vw, 360px);
  background: rgba(20, 16, 12, 0.94);
  color: #F0E6D6;
  border: 1px solid rgba(232, 220, 200, 0.18);
  border-radius: 8px;
  padding: .6rem 1rem;
  font-size: .82rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 200;
}
.game-toast--show {
  opacity: 1;
  transform: translate(-50%, 0);
}
@media (prefers-reduced-motion: reduce) {
  .game-toast { transition: none; }
}

/* Captured pieces tray (Cờ Úp) */
.game-captured-tray {
  display: flex;
  gap: .75rem;
  width: 100%;
}
.gct-side {
  flex: 1;
  background: var(--ground-2);
  border: 1px solid var(--border-h);
  border-radius: 8px;
  padding: .5rem .65rem;
  min-height: 2.4rem;
}
.gct-label {
  display: block;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--text-dim);
  margin-bottom: .3rem;
}
.gct-list {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}
.gct-piece {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  font-size: .8rem;
  font-family: serif;
  flex-shrink: 0;
}
.gct-piece--red   { background: rgba(192,0,0,.14);  border: 1px solid rgba(192,0,0,.4);  color: #F07B6E; }   /* #C00000 was 2.6:1 (BUG-P2-07) */
.gct-piece--black { background: rgba(28,28,28,.14); border: 1px solid rgba(28,28,28,.4); color: var(--text); }

/* Controls */
.game-controls {
  display: flex;
  gap: .75rem;
  width: 100%;
}
.gc-btn {
  flex: 1;
  background: var(--ground-2);
  border: 1px solid var(--border-h);
  border-radius: 8px;
  padding: .55rem 1rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.gc-btn:hover { border-color: var(--text-dim); color: var(--text); }
.gc-btn--danger:hover { border-color: #C06060; color: #C06060; }

/* Game overlay */
.game-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1.5rem;
}
.game-overlay[hidden] { display: none; }
html.ads-on .game-overlay { bottom: var(--ad-zone); }   /* result / rematch buttons stay clear of the ad */
html.ads-on .game-toast { bottom: calc(var(--ad-zone) + 1.25rem); }
.go-card {
  background: var(--ground-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem 2.5rem;
  text-align: center;
  max-width: 340px;
  width: 100%;
  animation: slide-up .3s cubic-bezier(.175,.885,.32,1.275);
}
@keyframes slide-up {
  from { transform: translateY(24px) scale(.95); opacity: 0; }
  to   { transform: translateY(0)    scale(1);   opacity: 1; }
}
.go-icon {
  font-size: 3rem;
  margin-bottom: .75rem;
}
.go-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: .4rem;
}
.go-sub {
  color: var(--text-dim);
  font-size: .9rem;
  margin-bottom: 1.25rem;
}
.go-actions {
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.go-btn {
  width: 100%;
  padding: .65rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border-h);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.go-btn:hover { opacity: .85; }
.go-btn--primary {
  background: var(--jade);   /* white on --jade-l was 3.3:1; on --jade 4.9:1 (BUG-P2-07) */
  color: #fff;
  border-color: transparent;
}
.go-btn--ghost {
  background: transparent;
  color: var(--text-dim);
}
.go-btn--accept {
  background: var(--jade-l);
  color: #fff;
  border-color: transparent;
}
.go-btn--decline {
  background: transparent;
  color: #C06060;
  border-color: #C06060;
}

/* ── Guest badge (lobby hero) ────────────────────────────────── */
.lobby-guest-badge {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  background: var(--ground-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .6rem 1.25rem;
}
.lgb-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--ground-3);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  color: var(--text-dim);
  flex-shrink: 0;
}
.lgb-label {
  display: block;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
}
.lgb-sub {
  display: block;
  font-size: .75rem;
  color: var(--text-dim);
  margin-top: 1px;
}

/* ── Guest notice banner (inside idle card) ─────────────────── */
.lc-guest-notice {
  background: color-mix(in srgb, var(--gold) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
  border-radius: 8px;
  padding: .6rem .9rem;
  font-size: .8rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 1rem;
}
.lc-guest-notice a {
  color: var(--jade-l);
  text-decoration: underline;
}

/* ── Ranked vs Unranked modes section ───────────────────────── */
.lobby-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.lmode-card {
  background: var(--ground-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: .75rem;
}
.lmode-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
  line-height: 1;
  margin-top: 2px;
}
.lmode-card h3 {
  font-size: .875rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .25rem;
}
.lmode-card p {
  font-size: .775rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ── Ranked badge (game board) ──────────────────────────────── */
.game-rank-badge {
  width: 100%;
  text-align: center;
}
.grb {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .75rem;
  font-weight: 600;
  border-radius: 20px;
  padding: .25rem .75rem;
  border: 1px solid transparent;
}
.grb--ranked {
  color: var(--jade-l);
  border-color: color-mix(in srgb, var(--jade-l) 30%, transparent);
  background: color-mix(in srgb, var(--jade-l) 10%, transparent);
}
.grb--unranked {
  color: var(--text-dim);
  border-color: var(--border);
  background: var(--ground-2);
}

/* AI badge in rank badge area */
.grb--ai {
  color: var(--jade-l);
  border-color: color-mix(in srgb, var(--jade-l) 25%, transparent);
  background: color-mix(in srgb, var(--jade-l) 8%, transparent);
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  .lobby-info-grid { grid-template-columns: 1fr; }
  .lobby-modes     { grid-template-columns: 1fr; }
  .lc-state { flex-direction: column; }
  .lobby-board-preview { display: none; }
  .lobby-spinner { width: 56px; height: 56px; }
}
@media (max-width: 420px) {
  .lobby-card { padding: 1.25rem; }
  .gp-timer { font-size: 1rem; }
}

/* ── In-game chat (game-chat.js) ─────────────────────────── */
/* The bubble replaces the ELO line under the sender's name for a few seconds.
   min-width:0 lets the name block shrink so a long message ellipsizes
   instead of pushing over the timer. */
.gp-info > div { min-width: 0; }
.game-player.has-bubble .gp-elo { display: none; }
.chat-bubble {
  display: block; width: fit-content; max-width: 100%; margin-top: 2px;
  padding: 0 .55rem; border-radius: 999px;
  background: var(--ground-3); border: 1px solid var(--border-h); color: var(--text);
  font-size: .78rem; line-height: 1.45; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  animation: chat-pop .18s ease-out;
}
.chat-bubble--me { border-color: rgba(61,158,136,.45); }
@keyframes chat-pop { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.chat-bar { width: 100%; display: flex; flex-direction: column; gap: .5rem; }
.chat-bar[hidden] { display: none; }
.chat-log {
  list-style: none; margin: 0; padding: .5rem .75rem; max-height: 150px; overflow-y: auto;
  background: var(--ground-2); border: 1px solid var(--border); border-radius: 10px;
  font-size: .85rem; color: var(--text-dim); display: flex; flex-direction: column; gap: .25rem;
  overflow-wrap: anywhere;
}
.chat-log:empty { display: none; }
.chat-log strong { color: var(--text); font-weight: 600; }
.chat-log li.is-me strong { color: var(--jade-l); }
.chat-form { display: flex; gap: .5rem; }
.chat-input {
  flex: 1; min-width: 0;
  background: var(--ground-3); color: var(--text);
  border: 1px solid var(--border-h); border-radius: 8px;
  font: 400 .9rem var(--font-body); padding: .5rem .75rem; min-height: 38px;
}
.chat-input:focus { outline: none; border-color: var(--jade-l); box-shadow: 0 0 0 3px rgba(61,158,136,.15); }
.chat-btn {
  background: var(--ground-2); border: 1px solid var(--border-h); border-radius: 8px;
  color: var(--text-dim); font: 600 .85rem var(--font-body); padding: .5rem .85rem; cursor: pointer;
  min-height: 38px; flex-shrink: 0;
}
.chat-btn:hover { color: var(--text); border-color: var(--text-dim); }
.chat-send { color: #fff; background: var(--jade-l); border-color: var(--jade-l); }
.chat-send:hover { color: #fff; opacity: .9; }
.chat-btn--icon { padding: .5rem .65rem; }
.chat-btn--icon[aria-pressed="true"] { color: #C06060; border-color: rgba(192,96,96,.5); }
.chat-status { font-size: .78rem; color: var(--text-dim); margin: 0; }
.chat-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* After-game message box on the result overlay (rematch window) */
.go-chat { display: flex; gap: .4rem; margin-top: 1rem; padding-top: .9rem; border-top: 1px solid var(--border); }
.go-chat[hidden] { display: none; }

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .spinner-ring { animation: none; }
  .gp-timer--low { animation: none; }
  .lobby-found-icon, .go-card { animation: none; }
  .chat-bubble { animation: none; }
}
/* Chat report form (game-chat.js, docs/phan-tich-quan-tri.md §4.7) */
.chat-report{display:flex;flex-direction:column;gap:.5rem;margin-top:.5rem;padding:.7rem .8rem;border:1px solid var(--border-h);border-radius:var(--r);background:var(--ground-2);font-size:13px;text-align:left}
.chat-report[hidden]{display:none}
.chat-report-title{font-weight:700;margin:0}
.chat-report-note{margin:0;color:var(--text-dim)}
.chat-report label{display:flex;flex-direction:column;gap:.25rem;color:var(--text-dim)}
.chat-report select,.chat-report input{background:var(--ground);color:var(--text);border:1px solid var(--border-h);border-radius:6px;padding:.4rem .5rem;font:13px var(--font-body);min-height:34px}
.chat-report-actions{display:flex;gap:.5rem;flex-wrap:wrap}

/* ── Game page layout (docs/phan-tich-co-may.md §5.2) ─────────────────
   The page is exactly one screen tall; the board row takes what is left and
   public/js/board-layout.js sizes the canvas to fit it (width AND height).
   Wide screens and phones held sideways get two columns: board | panel.
   One column (phones): the board comes first — while playing, only the two
   player rows (captured pieces inside them) and the controls row sit around it;
   the move list and the chat open from buttons in that row (GameExtras.initPanels). */
.game-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto var(--board-h, minmax(200px, 1fr)) auto auto;
  grid-template-areas: "top" "board" "bottom" "controls";
  align-items: start;
  align-content: center;
  align-content: safe center;   /* if it ever overflows, overflow downwards, never under the nav bar */
  max-width: 760px;
  width: 100%;
  height: calc(100vh - var(--nav-h));
  height: calc(100dvh - var(--nav-h));
  min-height: 420px;
  padding: .25rem max(4px, env(safe-area-inset-right)) calc(.25rem + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
  gap: .25rem;
}
/* With an ad (public/js/ads.js): the page ends above the reserved ad zone, and
   board-layout.js sizes the board to what is left — never under or near the ad */
html.ads-on .game-page {
  height: calc(100vh - var(--nav-h) - var(--ad-zone));
  height: calc(100dvh - var(--nav-h) - var(--ad-zone));
  min-height: 0;
}
#player-top { grid-area: top; }
#player-bottom { grid-area: bottom; }
.game-controls { grid-area: controls; }
.chat-bar { grid-area: chat; }
.gp-nav { display: none; }   /* phones held sideways only, below */
/* One column: the move list and the chat wait behind their buttons; the analysis opens the list */
.game-page .game-moves, .game-page .chat-bar { display: none; }
.game-page.show-moves .game-moves, .game-page.is-analysis .game-moves { display: block; }
.game-page.show-chat .chat-bar:not([hidden]) { display: flex; }
/* Scoped to .game-page: the replay page also loads this file, and `contain: size`
   outside this grid collapses its board to zero height */
.game-page .game-board-wrap {
  grid-area: board;
  align-self: stretch;
  min-height: 0;
  overflow: hidden;
  contain: size;            /* the canvas must not stretch the grid rows it spans */
  display: flex;
  align-items: center;
  justify-content: center;
}
.game-board-wrap canvas { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* Keyboard play (§5.6): the board shows its own cursor; the focus ring marks the board itself */
.game-board-wrap canvas:focus { outline: none; }
.game-board-wrap canvas:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }   /* inside: the wrap clips overflow */
/* "Your turn" in words, next to the row's border (§5.6) */
.gp-turn { flex-shrink: 0; padding: .1rem .45rem; border-radius: 999px; border: 1px solid var(--jade-l); color: var(--jade-l); font-size: .72rem; font-weight: 700; white-space: nowrap; }
.gp-turn[hidden] { display: none; }
/* Buttons on the game page: a visible focus ring in the site's gold */
.gc-btn:focus-visible, .go-btn:focus-visible, .game-moves summary:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.gc-btn { min-height: 44px; touch-action: manipulation; }
.game-player { padding: .4rem .65rem; }

/* Player rows (this page only — the replay page shares .game-player): one thin line —
   avatar, name + rating, "your turn", captured pieces, clock */
.game-page .game-player { padding: .3rem .5rem; gap: .5rem; border-radius: 8px; }
.game-page .gp-info { gap: .45rem; flex: 0 1 auto; }
.game-page .gp-info > div { display: flex; align-items: baseline; gap: .4rem; min-width: 0; overflow: hidden; }
.game-page .gp-name { min-width: 1.5rem; flex: 0 1 auto; }
.game-page .gp-elo { white-space: nowrap; min-width: 0; flex: 0 3 auto; overflow: hidden; text-overflow: ellipsis; }
.game-page .gp-avatar { width: 28px; height: 28px; font-size: .85rem; }
.game-page .gp-timer { font-size: 1.05rem; padding: .15rem .5rem; }
.game-page .chat-bubble { margin-top: 0; min-width: 0; }
/* Captured pieces: one line, same pieces grouped (卒×3, GameExtras.compactCaptured) */
.gp-cap { flex: 1 1 2.5rem; min-width: 0; display: flex; justify-content: flex-end; overflow: hidden; }
/* Pieces that don't fit wrap onto a hidden second line: never a piece cut in half */
.gp-cap .gct-list { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px; height: 1.2rem; overflow: hidden; }
.gp-cap .gct-piece { width: auto; min-width: 1.2rem; height: 1.2rem; padding: 0 .15rem; border-radius: 999px; font-size: .66rem; }
.gct-n { font: 700 .58rem var(--font-body); margin-left: 1px; }
/* Narrow phones, and the narrow side panel of phones held sideways: the rating gives
   way to the name, the turn and the captures */
@media (max-width: 399.98px), (orientation: landscape) and (max-height: 600px) and (max-width: 900px) {
  .game-page .gp-elo { display: none; }
  .game-page .gc-btn > span[aria-hidden="true"] { display: none; }   /* "⚑ Đầu hàng" → "Đầu hàng": stays on one line */
}
/* The side panel of phones held sideways is narrow: the avatar (the name's first letter) gives way to the name */
@media (orientation: landscape) and (max-height: 600px) and (max-width: 900px) {
  .game-page .gp-avatar { display: none; }
}
/* Controls: one row — two text buttons share what the icon buttons leave */
.game-page .game-controls { gap: .3rem; }
.game-page .gc-btn { padding: .45rem .5rem; }
.game-page .gc-btn:not(.gc-btn--icon) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-page .gc-btn--icon { flex: 0 0 40px; }
.gc-btn--panel { position: relative; }
.gc-btn--panel[aria-expanded="true"] { border-color: var(--jade-l); color: var(--text); }
.gc-btn--panel.has-unread::after { content: ''; position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

/* Two columns: board on the left, everything else beside it */
@media (min-width: 1024px), (orientation: landscape) and (max-height: 600px) {
  .game-page {
    --layout: wide;
    --panel-w: 320px;
    max-width: none;
    min-height: 0;
    padding: .5rem max(8px, env(safe-area-inset-right)) calc(.5rem + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    gap: .5rem;
    grid-template-columns: var(--board-w, 480px) var(--panel-w);
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas: "board top" "board bottom" "board moves" "board controls" "board chat";
    justify-content: center;
    align-content: stretch;
    column-gap: 1rem;
  }
  .game-page .game-board-wrap { height: 100%; }
  .chat-bar { min-height: 0; overflow: auto; }
  /* The side panel has room: the move list and the chat stay in it, no buttons */
  .game-page .game-moves { display: block; }
  .game-page .chat-bar:not([hidden]) { display: flex; }
  .game-page .gc-btn--panel { display: none; }
}
/* Phones held sideways: the site's top bar would take a sixth of the height — on this
   page it gives way to .gp-nav (logo + menu) at the top of the side panel */
@media (orientation: landscape) and (max-height: 600px) {
  body:has(#game-page) { --nav-h: 0px; }
  body:has(#game-page) .nav { display: none; }
  .game-page {
    grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
    grid-template-areas: "board nav" "board top" "board bottom" "board moves" "board controls" "board chat";
  }
  .gp-nav { grid-area: nav; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
  .gp-nav-logo { display: inline-flex; align-items: center; gap: .45rem; color: var(--text); text-decoration: none; font-weight: 700; font-size: .8rem; letter-spacing: 3px; text-transform: uppercase; }
  .gp-nav-logo .nav-piece { width: 26px; height: 26px; font-size: 13px; }
  .gp-nav-menu { min-width: 40px; min-height: 36px; background: var(--ground-2); border: 1px solid var(--border-h); border-radius: 8px; color: var(--text); font-size: 1.1rem; cursor: pointer; }
  .gp-nav-menu:focus-visible, .gp-nav-logo:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
}

/* Move list (game-extras.js) */
.game-moves { grid-area: moves; background: var(--ground-2); border: 1px solid var(--border); border-radius: 10px; padding: .35rem .65rem; font-size: .82rem; color: var(--text-dim); }
.game-moves summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }
.game-moves summary > span:first-child { margin-right: .3rem; }
/* One column: the list is a short box under the board (the board keeps the room) */
.move-list { list-style: none; margin: .25rem 0 0; padding: 0; max-height: 9rem; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; font-variant-numeric: tabular-nums; }
.move-list li { display: grid; grid-template-columns: 2.2rem 1fr 1fr; gap: .4rem; padding: .1rem 0; }
/* Two columns: the panel fills the room its grid row gets and scrolls only when the
   moves no longer fit; the title stays on top. (Scrolling the <details> itself, not a
   flex child of it: flex layout inside <details> is unreliable in Safari.) */
@media (min-width: 1024px), (orientation: landscape) and (max-height: 600px) {
  .game-moves { align-self: stretch; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding-top: 0; }
  .game-moves summary { position: sticky; top: 0; z-index: 1; padding-top: .35rem; background: var(--ground-2); }
  .game-moves .move-list { max-height: none; overflow: visible; }
}
.ml-n { color: var(--text-dim); }
.ml-red { color: #E07A6E; }
.ml-black { color: var(--text); }

/* Post-game analysis (§4.3): marks after a move, the better move under it */
.ml-mark { font-weight: 700; }
.ml-mark--blunder { color: #F07B6E; }
.ml-mark--mistake { color: var(--gold); }
.ml-mark--good { color: var(--jade-l, #5FC4A8); }
.ml-best { display: block; font-size: .74rem; color: var(--text-dim); }
.ml-analysis { margin: .3rem 0 .4rem; padding: .45rem .55rem; border: 1px solid var(--border); border-radius: 8px; background: var(--ground-3); color: var(--text); }
.ml-analysis[hidden] { display: none; }
.mla-msg { margin: 0 0 .35rem; line-height: 1.45; }
.mla-note { margin: 0 0 .4rem; font-size: .76rem; color: var(--text-dim); line-height: 1.4; }
.mla-progress { display: block; width: 100%; height: 6px; margin: 0 0 .4rem; accent-color: var(--jade); }
.mla-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.mla-actions .gc-btn { flex: 0 0 auto; min-height: 36px; padding: .3rem .8rem; }
/* One column (the negation of the two-column query above) with the analysis, the move
   list or the chat open: they no longer fit one screen, so the page grows and scrolls —
   a fixed height let them spill over the footer. board-layout.js keeps the board at its size. */
@media (max-width: 1023.98px) and (orientation: portrait), (max-width: 1023.98px) and (min-height: 600.02px) {
  .game-page.is-analysis, .game-page.is-panel {
    grid-template-rows: auto var(--board-h, minmax(200px, 1fr)) auto auto auto auto;
    grid-template-areas: "top" "board" "bottom" "controls" "moves" "chat";
  }
  .game-page.is-analysis, .game-page.is-panel,
  html.ads-on .game-page.is-analysis, html.ads-on .game-page.is-panel { height: auto; }
  /* Tall phones: the board is limited by the width, and the height it can't use (empty
     bands above and below it) goes to the move list, open under the controls —
     board-layout.js sets .roomy when that room is at least ~110px */
  .game-page.roomy:not(.is-analysis):not(.is-panel) {
    grid-template-rows: auto var(--board-h, minmax(200px, 1fr)) auto auto minmax(0, 1fr);
    grid-template-areas: "top" "board" "bottom" "controls" "moves";
    align-content: stretch;
  }
  .game-page.roomy:not(.is-analysis):not(.is-panel) .game-moves {
    display: block; align-self: stretch; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding-top: 0;
  }
  .game-page.roomy:not(.is-analysis):not(.is-panel) .game-moves summary { position: sticky; top: 0; z-index: 1; padding-top: .35rem; background: var(--ground-2); }
  .game-page.roomy:not(.is-analysis):not(.is-panel) .move-list { max-height: none; overflow: visible; }
  /* The list stays while the chat is open; its button is only needed to close a list opened by hand */
  .game-page.roomy.show-chat .game-moves { display: block; }
  .game-page.roomy:not(.show-moves) #btn-moves { display: none; }
}

/* Icon toggles in the controls row */
.gc-btn--icon { flex: 0 0 44px; padding: .4rem; font-size: 1.05rem; }
.gc-btn--icon.is-off { opacity: .45; filter: grayscale(1); }
.gc-btn--icon[hidden] { display: none; }

/* The computer's comment bubble (reuses .chat-bubble) */
.ai-bubble { border-color: rgba(61, 158, 136, .45); }

/* ── vs-computer lobby picker (views/partials/ai-lobby-picker.ejs, §5.4) ── */
.ai-tabs { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: .9rem; background: var(--ground-3); border: 1px solid var(--border); border-radius: 999px; }
.ai-tabs a { padding: .4rem 1rem; min-height: 36px; display: inline-flex; align-items: center; border-radius: 999px; color: var(--text-dim); text-decoration: none; font-size: .85rem; font-weight: 600; }
.ai-tabs a.is-active { background: var(--ground-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-h); }
.ai-levels { display: flex; flex-direction: column; gap: .55rem; margin: .4rem 0 1rem; }
.ai-level {
  display: flex; align-items: center; gap: .9rem; width: 100%; text-align: left;
  padding: .75rem .9rem; min-height: 64px; border-radius: 12px; cursor: pointer;
  background: var(--ground-2); border: 1px solid var(--border-h); color: var(--text);
  transition: border-color .15s, background .15s;
}
.ai-level:hover { border-color: var(--text-dim); }
.ai-level:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.ai-level[aria-checked="true"] { border-color: var(--jade-l); background: rgba(61, 158, 136, .1); box-shadow: inset 3px 0 0 var(--jade-l); }
.ai-seal {
  flex: 0 0 44px; width: 44px; height: 44px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #F6E7C8; font: 700 1.3rem/1 serif; box-shadow: 0 0 0 2px var(--gold);
}
.ai-level-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.ai-level-top { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.ai-level-name { font-weight: 700; font-size: 1rem; }
.ai-level-elo { font-size: .78rem; color: var(--gold); font-variant-numeric: tabular-nums; }
.ai-level-desc { font-size: .85rem; color: var(--text-dim); line-height: 1.4; }
.ai-level-stats { display: block; margin-top: .15rem; font-size: .8rem; color: var(--text); font-variant-numeric: tabular-nums; }
.ai-level-stats[hidden] { display: none; }
.ai-colors { border: 0; padding: 0; margin: 0 0 1rem; display: flex; flex-wrap: wrap; gap: .4rem; }
.ai-colors legend { font-size: .82rem; color: var(--text-dim); margin-bottom: .4rem; padding: 0; }
.ai-color { display: inline-flex; align-items: center; gap: .4rem; min-height: 40px; padding: .35rem .8rem; border: 1px solid var(--border-h); border-radius: 999px; cursor: pointer; font-size: .88rem; color: var(--text); background: var(--ground-2); }
.ai-color:has(input:checked) { border-color: var(--jade-l); background: rgba(61, 158, 136, .1); }
.ai-color input { accent-color: var(--jade-l); margin: 0; }
.ai-error { margin: 0 0 .8rem; padding: .55rem .8rem; border: 1px solid var(--accent); border-radius: 8px; background: rgba(192, 58, 43, .12); color: var(--text); font-size: .85rem; }
.ai-error[hidden] { display: none; }
.ai-start { width: 100%; justify-content: center; min-height: 48px; }
.ai-note { margin: .6rem 0 0; font-size: .8rem; color: var(--text-dim); text-align: center; }
#lc-select .lc-desc { margin-top: 1rem; font-size: .8rem; }
@media (prefers-reduced-motion: reduce) { .ai-level { transition: none; } }
/* Phones held sideways: the side panel must fit too (chat input included) */
@media (orientation: landscape) and (max-height: 430px) {
  .game-rank-badge, .game-moves, .game-page .game-moves { display: none; }
  .gct-label { display: none; }
  .gct-side { padding: .2rem .4rem; min-height: 0; }
  .gct-piece { width: 1.2rem; height: 1.2rem; font-size: .65rem; }
  /* Messages still show as bubbles in the player rows; the log would push the input off-screen (BUG-P1-04) */
  .chat-log { display: none; }
  .gc-btn { min-height: 40px; padding: .35rem .6rem; }
}
@media (orientation: landscape) and (max-height: 600px) and (max-width: 900px) {
  .game-page { --panel-w: 250px; row-gap: .35rem; padding-top: .35rem; }
  .game-player { padding: .3rem .5rem; }
  .gp-avatar { width: 28px; height: 28px; }
}

/* The computer is thinking: three dots after its name */
.gp--thinking .gp-name::after {
  content: ' • • •';
  color: var(--jade-l);
  letter-spacing: .05em;
  animation: ai-dots 1.2s ease-in-out infinite;
}
@keyframes ai-dots { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* Browsers without color-mix() (Safari < 16.2, Chrome < 111, Firefox < 113) */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
  .gp--active-turn { background: rgba(61, 158, 136, .08); }
  .gp-timer--active { background: rgba(61, 158, 136, .12); }
  .gp-timer--low { background: rgba(192, 96, 96, .12); }
  .grb--ai { border-color: rgba(61, 158, 136, .3); }
}

@media (prefers-reduced-motion: reduce) {
  .gp--thinking .gp-name::after { animation: none; opacity: 1; }
}
