/* Gomoku — 15×15 board (assets/js/games/gomoku.js). Classes are prefixed gm-. */
:root {
  --gm-wood: #f1d29b; --gm-wood-2: #e6bf7f; --gm-frame: #c68f4e; --gm-frame-press: #9d6b33;
  --gm-ink: rgba(70, 42, 12, .62); --gm-star: rgba(70, 42, 12, .8); --gm-coord: #6e4a1f;
}
:root[data-theme="dark"] {
  --gm-wood: #b98d57; --gm-wood-2: #a87b46; --gm-frame: #6e4a26; --gm-frame-press: #4a3017;
  --gm-ink: rgba(38, 22, 6, .7); --gm-star: rgba(38, 22, 6, .85); --gm-coord: #e7c99a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --gm-wood: #b98d57; --gm-wood-2: #a87b46; --gm-frame: #6e4a26; --gm-frame-press: #4a3017;
    --gm-ink: rgba(38, 22, 6, .7); --gm-star: rgba(38, 22, 6, .85); --gm-coord: #e7c99a;
  }
}

.gm-wrap { width: min(100%, 600px, max(300px, calc(100vh - 290px))); gap: 10px; container-type: inline-size; }
.gm-frame { position: relative; width: 100%; padding: 8px; border-radius: 16px; background: var(--gm-frame); box-shadow: 0 5px 0 var(--gm-frame-press), var(--shadow); transition: box-shadow .25s; }
.gm-frame.turn.me-x { box-shadow: 0 0 0 3px var(--brand), 0 5px 0 var(--gm-frame-press), var(--shadow); }
.gm-frame.turn.me-o { box-shadow: 0 0 0 3px var(--blue), 0 5px 0 var(--gm-frame-press), var(--shadow); }
.gm-board { position: relative; width: 100%; aspect-ratio: 1; border-radius: 9px; background: radial-gradient(120% 90% at 30% 20%, var(--gm-wood), var(--gm-wood-2)); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08), inset 0 2px 6px rgba(0, 0, 0, .12); touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.gm-lines, .gm-lines svg, .gm-win, .gm-win svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.gm-lines path { stroke: var(--gm-ink); fill: none; vector-effect: non-scaling-stroke; stroke-width: 1px; }
.gm-lines .gm-edge { fill: none; stroke: var(--gm-ink); stroke-width: 2px; vector-effect: non-scaling-stroke; }
.gm-lines circle { fill: var(--gm-star); }
.gm-grid { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(15, 1fr); grid-template-rows: repeat(15, 1fr); }
.gm-row { display: contents; }
.gm-pt { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; }
.gm-board.can .gm-pt.open { cursor: pointer; }
.gm-pt:focus { outline: none; }

/* stones */
.gm-st { position: relative; width: 86%; height: 86%; border-radius: 50%; z-index: 2; pointer-events: none; }
.gm-st.x { background: radial-gradient(circle at 34% 28%, #ffc2b2 0, #ff7a5c 34%, #ff6b4a 55%, #d9462a 100%); box-shadow: 0 2px 0 #b7391f, 0 3px 5px rgba(0, 0, 0, .3); }
.gm-st.o { background: radial-gradient(circle at 34% 28%, #b9d0ff 0, #5b8ff9 34%, #3d7bf7 55%, #2559c9 100%); box-shadow: 0 2px 0 #1f4aa6, 0 3px 5px rgba(0, 0, 0, .3); }
.gm-st.last::after { content: ""; position: absolute; left: 50%; top: 50%; width: 30%; height: 30%; border-radius: 50%; transform: translate(-50%, -50%); background: #fff; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, .18); }
.gm-st.win { box-shadow: 0 0 0 2px #fff6d6, 0 0 12px 3px rgba(255, 197, 49, .95), 0 2px 0 rgba(0, 0, 0, .25); z-index: 3; }
.gm-st.drop { animation: gm-drop .34s var(--spring) both; }
.gm-st.winpop { animation: gm-winpop .3s var(--spring) both; }
.gm-ripple { position: absolute; width: 86%; height: 86%; border-radius: 50%; border: 2px solid var(--brand); z-index: 1; pointer-events: none; animation: gm-ripple .6s ease-out .08s both; }
.gm-ripple.o { border-color: var(--blue); }
@keyframes gm-drop { 0% { transform: translateY(-30%) scale(1.45); opacity: 0; } 55% { transform: translateY(0) scale(.9); opacity: 1; } 100% { transform: scale(1); } }
@keyframes gm-winpop { 0% { transform: scale(1); } 45% { transform: scale(1.22); } 100% { transform: scale(1); } }
@keyframes gm-ripple { 0% { transform: scale(1); opacity: .8; } 100% { transform: scale(2.3); opacity: 0; } }

/* winning line */
.gm-win { z-index: 4; }
.gm-win line { stroke-width: .16; stroke-linecap: round; stroke: #fff6d6; filter: drop-shadow(0 0 .12px rgba(120, 70, 0, .9)); opacity: .92; }
.gm-win.anim line { animation: gm-line .28s ease-out .02s forwards; }
@keyframes gm-line { to { stroke-dashoffset: 0; } }

/* hover ghost (mouse) and touch preview */
.gm-pt::before { content: ""; position: absolute; width: 86%; height: 86%; border-radius: 50%; opacity: 0; transform: scale(.7); transition: opacity .12s, transform .12s; pointer-events: none; z-index: 2; }
.gm-board.me-x .gm-pt::before { background: var(--brand); }
.gm-board.me-o .gm-pt::before { background: var(--blue); }
@media (hover: hover) {
  .gm-board.can .gm-pt.open:hover::before { opacity: .45; transform: scale(1); }
}
.gm-board.can .gm-pt.pend::before { opacity: .72; transform: scale(1); box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(0, 0, 0, .25); animation: gm-pend 1s ease-in-out infinite alternate; }
@keyframes gm-pend { from { opacity: .55; } to { opacity: .85; } }
.gm-cross { position: absolute; display: none; pointer-events: none; z-index: 1; background: rgba(255, 255, 255, .55); }
.gm-cross.h { left: 0; right: 0; height: 3px; transform: translateY(-50%); }
.gm-cross.v { top: 0; bottom: 0; width: 3px; transform: translateX(-50%); }
.gm-board.pending .gm-cross, .gm-board.can.kfocus .gm-cross { display: block; }
/* keyboard focus (roving tabindex): ghost stone with a ring */
.gm-board .gm-pt:focus-visible::before { opacity: .55; transform: scale(1); box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--blue); }
.gm-board:not(.can) .gm-pt:focus-visible::before { background: transparent; }

/* coordinates: only when the board is wide enough */
.gm-coords { display: none; position: absolute; pointer-events: none; color: var(--gm-coord); font-size: 11px; font-weight: 700; line-height: 1; }
.gm-coords span { position: absolute; }
.gm-coords.x { left: 0; right: 0; top: calc(100% + 5px); height: 12px; }
.gm-coords.x span { transform: translateX(-50%); }
.gm-coords.y { top: 0; bottom: 0; right: calc(100% + 5px); width: 16px; }
.gm-coords.y span { right: 0; transform: translateY(-50%); }
@container (min-width: 440px) {
  .gm-frame { padding: 8px 10px 22px 26px; }
  .gm-coords { display: block; }
}

/* touch confirm bar */
.gm-bar { width: 100%; display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); min-height: 52px; }
.gm-bar.hidden { display: none; }
.gm-bar-t { flex: 1 1 auto; min-width: 0; font-size: 14px; line-height: 1.25; font-weight: 600; color: var(--ink-2); overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow-wrap: anywhere; }
@media (max-width: 400px) { .gm-bar-t { font-size: 13px; } }
.gm-bar .btn { height: 40px; flex: 0 0 auto; }
.gm-bar .gm-no { width: 40px; padding: 0; }
.gm-bar .btn:disabled { opacity: .45; }

/* Room/bot stage on narrow phones: the shared player bars must not widen the page (long names, "thinking" tag);
   they keep their width and clip the secondary line instead. Scoped to Gomoku stages only. */
.stage:has(.gm-wrap) .pbar { contain: inline-size; }
.stage:has(.gm-wrap) .pbar .pn, .stage:has(.gm-wrap) .pbar .pn small { overflow: hidden; }
.stage:has(.gm-wrap) .pbar .pn small > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.stage:has(.gm-wrap) .pbar .pn small .conn::before { display: inline-block; margin-right: 5px; vertical-align: 1px; }

@media (max-width: 640px) {
  .gm-wrap { width: 100%; }
  .gm-frame { padding: 5px; border-radius: 12px; }
  .gm-board { border-radius: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  .gm-st.drop, .gm-st.winpop, .gm-ripple, .gm-board.can .gm-pt.pend::before { animation: none; }
  .gm-win.anim line { animation: none; stroke-dashoffset: 0 !important; }
  .gm-pt::before { transition: none; }
}
