/* Room games (T31b, §22.4): header button, gomoku panel (phones: above the messages, collapsible;
   ≥ 1024px: a column right of the messages), SVG board, invite cards, the result / replay bars under
   the board (§22.12), the 「玩遊戲」 sheet, system message rows and the room-list mark. UI colours come from the styles.css tokens; the wood
   board and the stones have their own tokens below (light + dark). */

:root {
  --board-bg: #e2b46e;
  --board-line: rgba(70, 44, 12, 0.78);
  --board-label: rgba(70, 44, 12, 0.72);
  --board-last: #e0343a;
  --board-win: #0b7f73;
  --stone-b: #1c1e21;
  --stone-b-edge: #000000;
  --stone-w: #fcfbf7;
  --stone-w-edge: #7d7466;
  --game-col: clamp(320px, 42vh, 460px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --board-bg: #a57d47; --board-line: rgba(28, 16, 2, 0.82); --board-label: rgba(28, 16, 2, 0.8);
    --board-last: #ff4a50; --board-win: #5ff0da;
    --stone-b: #0d0e10; --stone-b-edge: rgba(255, 255, 255, 0.28); --stone-w: #ece9e1; --stone-w-edge: #5b5446;
  }
}
:root[data-theme="dark"] {
  --board-bg: #a57d47; --board-line: rgba(28, 16, 2, 0.82); --board-label: rgba(28, 16, 2, 0.8);
  --board-last: #ff4a50; --board-win: #5ff0da;
  --stone-b: #0d0e10; --stone-b-edge: rgba(255, 255, 255, 0.28); --stone-w: #ece9e1; --stone-w-edge: #5b5446;
}

/* ---------------------------------------------------------------- header button */
.game-dot {
  position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--surface); pointer-events: none;
}
.game-dot.hot { background: var(--danger); }

/* ---------------------------------------------------------------- panel (phones / narrow) */
.game-panel {
  flex: none; position: relative; z-index: 4; min-width: 0;
  background: var(--glass); backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-bottom: 1px solid var(--line);
}
.game-panel.expanded {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 6px calc(12px + var(--safe-r)) 10px calc(12px + var(--safe-l));
}
.game-head { display: flex; align-items: center; gap: 4px; width: 100%; min-height: 40px; }
.game-player {
  display: flex; align-items: center; gap: 6px; min-width: 0; flex: 0 1 auto; max-width: 31%;
  padding: 3px 9px 3px 3px; border-radius: 999px; transition: background 0.15s, box-shadow 0.15s;
}
.game-player.turn { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.gp-av { position: relative; flex: none; display: flex; }
.gp-stone {
  position: absolute; right: -3px; bottom: -3px; width: 13px; height: 13px; border-radius: 50%;
  box-shadow: 0 0 0 1.5px var(--surface);
}
.gp-stone.b { background: var(--stone-b); }
.gp-stone.w { background: var(--stone-w); box-shadow: 0 0 0 1.5px var(--surface), inset 0 0 0 1px var(--stone-w-edge); }
.gp-name { font-size: 13.5px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
/* Computer game (§22.11): the level under 「電腦」, inside the chip's height (the header must not grow). */
.gp-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.gp-sub { font-size: 10.5px; font-weight: 600; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-player.turn .gp-sub { color: var(--accent-text); }
.game-mid {
  flex: 1; min-width: 0; align-self: stretch; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 1px;
}
.game-status {
  font-size: 13px; font-weight: 600; color: var(--text-2); max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.game-status.mine { color: var(--accent-text); }
/* The result now lives in the header's status (§22.12): 「你贏了 🎉 · 9 手」 gets the accent. */
.game-status.won { color: var(--accent-text); font-weight: 700; }
.game-score { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; font-variant-numeric: tabular-nums; }
/* 落子 (touch two-step) sits over the status / score lines instead of between them: it is taller than
   the two text lines together, and the header (so the board under it) must not move on the first tap. */
.game-confirm { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); min-width: 76px; z-index: 1; }
.btn.game-confirm:active { transform: translate(-50%, -50%) scale(0.98); }
.game-mid.confirming > .game-status, .game-mid.confirming > .game-score { visibility: hidden; }
.game-tools { display: flex; flex: none; }
/* Practice (§22.9): 「練習模式」 takes the score line's place (same box, so the header height is the same). */
.game-practice-note { font-weight: 650; letter-spacing: 0.02em; }

.game-board-wrap {
  position: relative; flex: none;
  width: min(100%, calc(var(--app-h, 100dvh) * 0.46)); aspect-ratio: 1 / 1;
}
.game-solo { width: 100%; display: flex; justify-content: center; padding: 2px 0; }

/* ---------------------------------------------------------------- board */
.gomoku {
  display: block; width: 100%; height: 100%; border-radius: 6px; box-shadow: var(--shadow-1);
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
/* A tap / click focuses the board too: no ring then (Chromium's SVG :focus ring included); keyboard
   focus (.kbd from GomokuBoard, or :focus-visible) gets the app's ring. */
.gomoku:focus { outline: none; }
.gomoku:focus-visible, .gomoku.kbd:focus { outline: 2.5px solid var(--accent); outline-offset: 3px; }
.gomoku.disabled { cursor: default; }
.gb-bg { fill: var(--board-bg); }
.gb-lines line { stroke: var(--board-line); stroke-width: 0.45; }
.gb-stars circle { fill: var(--board-line); }
.gb-labels text { font-size: 4.1px; fill: var(--board-label); font-family: var(--font); font-weight: 600; }
.stone.b { fill: var(--stone-b); stroke: var(--stone-b-edge); stroke-width: 0.35; }
.stone.w { fill: var(--stone-w); stroke: var(--stone-w-edge); stroke-width: 0.45; }
.stone.pending { stroke: var(--accent); stroke-width: 0.8; stroke-dasharray: 1.4 1; }
.stone.ghost { opacity: 0.45; pointer-events: none; }
.stone.ghost.sel { opacity: 0.68; stroke: var(--accent); stroke-width: 0.9; }
.gb-stones circle:last-child { transform-box: fill-box; transform-origin: center; animation: stone-in 0.14s ease-out; }
@keyframes stone-in { from { transform: scale(0.6); opacity: 0.4; } to { transform: none; opacity: 1; } }
.gb-last { fill: var(--board-last); pointer-events: none; }
.gb-win circle { fill: none; stroke: var(--board-win); stroke-width: 1.3; pointer-events: none; }
.gb-cursor { fill: none; stroke: var(--accent); stroke-width: 0.8; pointer-events: none; }

/* ---------------------------------------------------------------- cards (invite / rematch / cancelled) */
.game-overlay {
  position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; justify-content: center; pointer-events: none;
}
.game-overlay .game-card { pointer-events: auto; }
.game-card {
  width: 100%; max-width: 320px; padding: 12px 14px; border-radius: 16px; text-align: center;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-3);
  animation: game-card-in 0.16s ease-out;
}
.game-solo .game-card { box-shadow: none; background: var(--surface-2); max-width: 420px; }
@keyframes game-card-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.game-card-title { font-weight: 800; font-size: 17px; line-height: 1.35; }
.game-card-sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.game-card-score { font-size: 13px; color: var(--text-2); margin-top: 2px; font-variant-numeric: tabular-nums; }
.game-card-actions { display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- result bar / replay bar (§22.12)
   Under the board of a finished game, as wide as the board, about 52px: the board stays whole (no card
   over it). The replay bar has the same box so 復盤 ↔ 結束復盤 does not move anything. */
.game-result-bar, .game-replay-bar {
  flex: none; display: flex; align-items: center; gap: 8px; min-height: 52px;
  width: min(100%, calc(var(--app-h, 100dvh) * 0.46));
  padding: 4px 4px 4px 12px; border-radius: 14px; background: var(--surface-2); color: var(--text);
  animation: game-card-in 0.16s ease-out;
}
.game-result-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.game-result-sub {
  font-size: 13.5px; font-weight: 650; line-height: 1.3; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.game-result-score {
  font-size: 11.5px; color: var(--text-3); line-height: 1.3; font-variant-numeric: tabular-nums;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.game-result-actions { flex: none; display: flex; gap: 6px; }
.game-result-actions .btn-sm, .game-replay-end { padding: 0 11px; }
/* 復盤 / 結束復盤 are secondary buttons: the plain .btn grey is the bar's own colour, so a step lighter. */
.game-replay-start, .game-replay-end { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.game-replay-start:hover, .game-replay-end:hover { background: var(--surface-3); }
.game-replay-bar { gap: 2px; padding: 4px 4px 4px 2px; }
.game-replay-bar:focus { outline: none; }
.game-replay-bar:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }
.game-replay-bar .icon-btn.sm { width: 38px; flex: none; }
.game-replay-pos {
  flex: 1; min-width: 0; text-align: center; font-size: 13px; font-weight: 650; line-height: 1.3;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.game-replay-end { flex: none; margin-left: 4px; }

/* ---------------------------------------------------------------- collapsed: status bar */
.game-bar {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px;
  padding: 6px calc(12px + var(--safe-r)) 6px calc(12px + var(--safe-l));
  border: 0; background: transparent; color: var(--text); font: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.game-bar:hover { background: var(--surface-2); }
.game-bar-icon { color: var(--accent-text); display: flex; flex: none; }
.game-bar-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.game-bar.mine .game-bar-text { color: var(--accent-text); }
.game-bar-cta { display: inline-flex; align-items: center; gap: 2px; flex: none; font-size: 13px; color: var(--text-2); }
.game-bar.flash { animation: game-flash 0.18s ease-in-out 4 alternate; }
@keyframes game-flash { from { background: transparent; } to { background: var(--accent-soft-2); } }

/* ---------------------------------------------------------------- mini: phone keyboard up (§22.10)
   One button: a small read-only board on the left, the status on the right. 4px + 160px + 4px + the
   1px border stays under 170px; the board takes no pointer events (the tap is the button's). */
.game-mini {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 4px calc(12px + var(--safe-r)) 4px calc(12px + var(--safe-l));
  border: 0; background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.game-mini:hover { background: var(--surface-2); }
.game-mini-board { flex: none; display: block; width: min(42vw, 160px); aspect-ratio: 1 / 1; }
.game-mini .gomoku { pointer-events: none; box-shadow: var(--shadow-1); }
.game-mini-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.game-mini-status {
  font-size: 15px; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
}
.game-mini.mine .game-mini-status { color: var(--accent-text); }
.game-mini-hint { font-size: 12.5px; color: var(--text-3); }
.game-mini.flash { animation: game-flash 0.18s ease-in-out 4 alternate; }

/* ---------------------------------------------------------------- wide: a column right of the messages */
@media (min-width: 1024px) {
  .chat.game-open {
    display: grid; grid-template-columns: minmax(0, 1fr) var(--game-col);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  }
  .chat.game-open > * { grid-column: 1 / -1; }
  .chat.game-open > .chat-head { grid-row: 1; }
  .chat.game-open > .chat-body { grid-column: 1; grid-row: 4; }
  .chat.game-open > .composer { grid-column: 1; grid-row: 5; }
  .chat.game-open > .game-panel {
    grid-column: 2; grid-row: 4 / 6; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    border-bottom: 0; border-left: 1px solid var(--line); background: var(--surface);
    backdrop-filter: none; -webkit-backdrop-filter: none; padding: 12px 14px; gap: 10px;
  }
  .chat.game-open .game-board-wrap, .chat.game-open .game-result-bar, .chat.game-open .game-replay-bar { width: 100%; }
  .chat.game-open .game-player { max-width: 34%; }

  /* collapsed: a small card at the top right of the messages */
  .game-panel.collapsed { height: 0; border: 0; background: none; backdrop-filter: none; -webkit-backdrop-filter: none; z-index: 6; }
  .game-panel.collapsed .game-bar {
    position: absolute; top: 10px; right: 14px; width: auto; max-width: min(360px, 70%);
    background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-2); padding: 6px 10px 6px 12px;
  }
  .game-panel.collapsed .game-bar:hover { background: var(--surface-2); }
}

/* ---------------------------------------------------------------- 「玩遊戲」 sheet */
.game-sheet-sec { margin: 4px 0 16px; }
.game-kind {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px;
  background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent);
}
.game-kind .check-ui { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.game-kind-icon {
  position: relative; width: 40px; height: 40px; border-radius: 10px; background: var(--board-bg); flex: none;
}
.gk-stone { position: absolute; width: 16px; height: 16px; border-radius: 50%; }
.gk-stone.b { left: 6px; top: 7px; background: var(--stone-b); }
.gk-stone.w { right: 6px; bottom: 7px; background: var(--stone-w); box-shadow: inset 0 0 0 1px var(--stone-w-edge); }
.game-kind-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.game-kind-text b { font-size: 16px; }
.game-kind-text small { font-size: 13px; color: var(--text-2); }
.game-online { color: var(--ok); font-weight: 600; }
.game-sheet-empty { margin: 4px; }
/* Mode (§22.11): 邀請成員 / 跟電腦下 / 練習模式, radio cards */
.game-modes { display: flex; flex-direction: column; gap: 6px; }
.game-mode {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border: 0; border-radius: 14px;
  background: var(--surface-2); color: inherit; font: inherit; text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent; transition: background 0.15s, box-shadow 0.15s;
}
.game-mode:hover:not(:disabled):not(.on) { background: var(--surface-3, var(--surface-2)); }
.game-mode:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }
.game-mode.on { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.game-mode:disabled { cursor: default; opacity: 0.5; }
.game-mode-icon {
  width: 34px; height: 34px; border-radius: 10px; flex: none; display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--text-2);
}
.game-mode.on .game-mode-icon { color: var(--accent-text); }
.game-mode-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.game-mode-text b { font-size: 15px; }
.game-mode-text small { font-size: 12.5px; color: var(--text-2); }
.game-mode.on .check-ui { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.game-send .spinner { border-top-color: var(--accent-ink); }

/* ---------------------------------------------------------------- system messages, room list */
button.game-msg { border: 0; font: inherit; cursor: pointer; }
button.game-msg:hover { background: var(--surface); }
.game-msg .icon, .game-msg-cta, .game-msg .sys-time { flex: none; }
.sys-game .icon { opacity: 0.85; }
.game-msg-cta {
  font-size: 12px; font-weight: 700; padding: 0 9px; border-radius: 999px; line-height: 20px;
  background: var(--accent-soft-2); color: var(--accent-text);
}
.room-game { top: -2px; bottom: auto; background: var(--accent); color: var(--accent-ink); }

@media (prefers-reduced-motion: reduce) {
  .gb-stones circle:last-child, .game-card, .game-result-bar, .game-replay-bar, .game-bar.flash, .game-mini.flash { animation: none; }
  .game-bar.flash, .game-mini.flash { background: var(--accent-soft-2); }
  .game-player, .game-mode { transition: none; }
}
