/* Board games: the shared frame, then Reversi and Gomoku boards. */

.bg [hidden] { display: none !important; }
.bg { max-width: 640px; margin: 0 auto; padding: clamp(28px, 5vw, 48px) 0 72px; }
.bg-title { text-align: center; margin-bottom: 24px; }

/* ----------------------------------------------------------------- menu */

.bg-setup { display: grid; gap: 16px; max-width: 420px; margin: 0 auto; }
.bg-option { display: grid; gap: 12px; padding: 20px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.bg-option .btn { width: 100%; font-size: 18px; padding: 16px 20px; }
.bg-pick { display: flex; gap: 12px; flex-wrap: wrap; }
.bg-pick label { flex: 1 1 140px; display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.bg-pick select {
  font: 500 16px var(--body); color: var(--ink); background: var(--paper);
  border: 2px solid var(--line); border-radius: 10px; padding: 9px 10px;
}

/* --------------------------------------------------------------- players */

.bg-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.bg-player {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 10px 14px; border: 2px solid var(--line); border-radius: 14px; background: var(--card);
  transition: border-color .2s ease, box-shadow .2s ease;
}
.bg-player.is-turn { border-color: var(--mustard); box-shadow: 0 0 0 3px color-mix(in srgb, var(--mustard) 30%, transparent); }
.bg-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bg-score { font: 800 22px/1 var(--display); }
.bg-dot { width: 22px; height: 22px; border-radius: 50%; flex: none; box-shadow: inset 0 -2px 3px rgba(0,0,0,.35); }
.bg-dot.is-black { background: radial-gradient(circle at 35% 30%, #555 0, #111 60%); }
.bg-dot.is-white { background: radial-gradient(circle at 35% 30%, #fff 0, #d8d4cc 70%); border: 1px solid #bdb6a8; }

.bg-status { text-align: center; font: 700 20px/1.3 var(--display); min-height: 1.3em; margin: 14px 0; }
.bg-status.is-end { color: var(--tomato); font-size: 24px; }

.bg-room { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 14px; margin: 16px 0 0; font-size: 15px; }
.bg-room b { font-family: var(--mono); letter-spacing: .08em; }
.bg-room .btn-small { margin: 0; }
.bg-watchers { color: var(--ink-2); }
.bg-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 18px; }
.bg-actions .btn-small { margin: 0; }
.bg-actions .btn[disabled] { opacity: .6; cursor: default; transform: none; box-shadow: none; }

.bg-board { margin: 0 auto; width: min(100%, 560px); aspect-ratio: 1; display: grid; user-select: none; -webkit-tap-highlight-color: transparent; }
.bg-board button { min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0; background: none; font: inherit; color: inherit; cursor: default; position: relative; }
.bg-board button:focus-visible { outline: 3px solid var(--mustard); outline-offset: -3px; border-radius: 4px; }

/* --------------------------------------------------------------- Reversi */

.reversi-board {
  grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); gap: 2px; padding: 8px;
  background: #0F3D28; border-radius: 16px;
  box-shadow: 0 1px 0 rgba(255,255,255,.08) inset, 0 16px 34px -18px rgba(0,0,0,.6);
}
.rv-cell { background: #1E6B47 !important; border-radius: 3px; display: grid; place-items: center; }
.rv-disc { width: 82%; height: auto; aspect-ratio: 1; border-radius: 50%; transform: scale(0); transition: transform .18s ease, background .18s ease; }
.rv-disc.is-black, .rv-disc.is-white { transform: scale(1); }
.rv-disc.is-black { background: radial-gradient(circle at 35% 30%, #5a5a5a 0, #141414 55%, #000 100%); box-shadow: 0 2px 3px rgba(0,0,0,.5); }
.rv-disc.is-white { background: radial-gradient(circle at 35% 30%, #fff 0, #ecebe6 55%, #c9c5ba 100%); box-shadow: 0 2px 3px rgba(0,0,0,.45); }
.rv-disc.is-flip { animation: rv-flip .32s ease; }
@keyframes rv-flip { 0% { transform: scaleX(1); } 50% { transform: scaleX(.05); } 100% { transform: scaleX(1); } }
.rv-cell.is-hint { cursor: pointer; }
.rv-cell.is-hint::after { content: ""; position: absolute; width: 22%; height: 22%; border-radius: 50%; background: rgba(255,255,255,.28); }
.rv-cell.is-hint:hover::after { width: 70%; height: 70%; background: rgba(255,255,255,.2); }
.reversi-board[data-me="2"] .rv-cell.is-hint:hover::after { background: rgba(255,255,255,.45); }
.reversi-board[data-me="1"] .rv-cell.is-hint:hover::after { background: rgba(0,0,0,.35); }
.rv-cell.is-last .rv-disc::after { content: ""; display: block; width: 18%; height: 18%; margin: 41% auto 0; border-radius: 50%; background: var(--tomato); }

/* ---------------------------------------------------------------- Gomoku */

.gomoku-board {
  grid-template-columns: repeat(15, 1fr); grid-template-rows: repeat(15, 1fr); padding: 3.2%;
  background: linear-gradient(135deg, #E6BF7A, #D9A95A 55%, #CD9A4B);
  border-radius: 12px; box-shadow: 0 16px 34px -18px rgba(0,0,0,.6), inset 0 0 0 1px rgba(0,0,0,.15);
}
.gm-pt { display: grid; place-items: center; }
/* The grid lines: each point draws the half-lines to its neighbours. */
.gm-pt::before, .gm-pt::after { content: ""; position: absolute; background: #5B3A16; opacity: .75; pointer-events: none; }
.gm-pt::before { left: 0; right: 0; top: calc(50% - .5px); height: 1px; }
.gm-pt::after { top: 0; bottom: 0; left: calc(50% - .5px); width: 1px; }
.gm-pt.l::before { left: 50%; } .gm-pt.r::before { right: 50%; }
.gm-pt.t::after { top: 50%; } .gm-pt.b::after { bottom: 50%; }
.gm-pt.star .gm-stone:not(.is-black):not(.is-white) { width: 24%; background: #5B3A16; transform: none; box-shadow: none; }
.gm-stone { width: 88%; height: auto; aspect-ratio: 1; border-radius: 50%; z-index: 1; transform: scale(0); transition: transform .14s ease; }
.gm-stone.is-black, .gm-stone.is-white { transform: scale(1); }
.gm-stone.is-black { background: radial-gradient(circle at 35% 30%, #5c5c5c 0, #161616 55%, #000 100%); box-shadow: 1px 2px 3px rgba(0,0,0,.45); }
.gm-stone.is-white { background: radial-gradient(circle at 35% 30%, #fff 0, #efece4 55%, #cfc9bb 100%); box-shadow: 1px 2px 3px rgba(0,0,0,.4); }
.gomoku-board.is-live .gm-pt:not([disabled]) { cursor: pointer; }
.gomoku-board.is-live .gm-pt:not([disabled]):hover .gm-stone { transform: scale(1); opacity: .45; width: 88%; }
.gomoku-board.is-live[data-me="black"] .gm-pt:not([disabled]):hover .gm-stone { background: #111; }
.gomoku-board.is-live[data-me="white"] .gm-pt:not([disabled]):hover .gm-stone { background: #fff; }
.gm-pt.is-last .gm-stone::after { content: ""; display: block; width: 26%; height: 26%; margin: 37% auto 0; border-radius: 50%; background: var(--tomato); }
.gm-pt.is-win .gm-stone { box-shadow: 0 0 0 2px var(--tomato), 0 0 12px 2px color-mix(in srgb, var(--tomato) 70%, transparent); }

@media (prefers-reduced-motion: reduce) {
  .rv-disc, .gm-stone { transition: none; }
  .rv-disc.is-flip { animation: none; }
}
@media (max-width: 560px) {
  .bg-player { padding: 8px 10px; gap: 8px; }
  .bg-name { font-size: 14px; }
  .reversi-board { padding: 5px; gap: 1.5px; }
}

/* ------------------------------------------------------------- move list */

.bg-moves {
  max-width: 560px; margin: 14px auto 0; padding: 10px 14px 10px 44px; max-height: 150px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  columns: 3 120px; column-gap: 24px; font: 500 14px/1.7 var(--mono); white-space: pre;
}
.bg-moves li::marker { color: var(--ink-2); }

/* ----------------------------------------------------------------- Chess */

.chess-board {
  grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 8px; overflow: hidden; container-type: inline-size;
  box-shadow: 0 0 0 6px #5a3a22, 0 16px 34px -18px rgba(0,0,0,.6);
}
.ch-sq { display: grid; place-items: center; }
.ch-sq.light { background: #EEDCB5 !important; }
.ch-sq.dark { background: #B58863 !important; }
.ch-pc { font-family: "Noto Sans Symbols 2", "Segoe UI Symbol", serif; font-size: 10cqw; line-height: 1; pointer-events: none; z-index: 1; }
.ch-pc.w { color: #fff; -webkit-text-stroke: .045em #1d1b16; paint-order: stroke fill; text-shadow: 0 2px 2px rgba(0,0,0,.25); }
.ch-pc.b { color: #1d1b16; -webkit-text-stroke: .02em #1d1b16; text-shadow: 0 2px 2px rgba(0,0,0,.25); }
.ch-sq.is-last { box-shadow: inset 0 0 0 100cqw rgba(242,177,52,.38); }
.ch-sq.is-sel { box-shadow: inset 0 0 0 100cqw rgba(76,195,184,.5); }
.ch-sq.is-check { background: radial-gradient(circle, #ff5a46 0, #e0412e 40%, transparent 72%) !important; }
.chess-board.is-live .ch-sq.is-movable, .ch-sq.is-target { cursor: pointer; }
.ch-sq.is-target::after { content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: rgba(29,27,22,.28); }
.ch-sq.is-capture::after { width: 88%; height: 88%; background: none; box-shadow: inset 0 0 0 4px rgba(29,27,22,.3); }
.ch-sq[data-file]::before, .ch-sq[data-rank]::before { position: absolute; font: 700 2.2cqw var(--body); opacity: .75; }
.ch-sq[data-file]::before { content: attr(data-file); right: 4%; bottom: 2%; }
.ch-sq[data-rank]::before { content: attr(data-rank); left: 4%; top: 2%; }
.ch-sq[data-file][data-rank]::before { content: attr(data-rank); }
.ch-sq.light::before { color: #B58863; } .ch-sq.dark::before { color: #EEDCB5; }
.ch-promo { border: 0; border-radius: 18px; padding: 16px; background: var(--card); box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.ch-promo::backdrop { background: rgba(0,0,0,.35); }
.ch-promo button { font-size: 56px; width: 76px; height: 76px; border: 0; border-radius: 12px; background: #EEDCB5; cursor: pointer; margin: 4px; }
.ch-promo button:hover { background: #F2B134; }

/* --------------------------------------------------------------- Xiangqi */

.xiangqi-board {
  position: relative; display: block; aspect-ratio: 9 / 10; container-type: inline-size;
  background: linear-gradient(135deg, #EACB8C, #DDB06A 55%, #D2A25A); color: #6B4118;
  border-radius: 12px; box-shadow: 0 16px 34px -18px rgba(0,0,0,.6), inset 0 0 0 1px rgba(0,0,0,.15);
}
.xq-lines { position: absolute; inset: 0; width: 100%; height: 100%; }
.xq-river { font: 700 4.6px "Noto Serif SC", "Songti SC", serif; fill: currentColor; text-anchor: middle; letter-spacing: .6px; opacity: .8; }
.xq-pts { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(10, 1fr); }
.xq-pt { display: grid; place-items: center; }
.xq-pc {
  width: 88%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; line-height: 1;
  font: 900 6.4cqw "Noto Serif SC", "Songti SC", "SimSun", serif; pointer-events: none; z-index: 1;
}
.xq-pc.red, .xq-pc.black {
  background: radial-gradient(circle at 40% 35%, #FFF8E8 0, #F3E1BA 70%, #D9BD86 100%);
  box-shadow: 0 2px 4px rgba(0,0,0,.4), inset 0 0 0 .5cqw #F9EDD2, inset 0 0 0 .75cqw currentColor;
}
.xq-pc.red { color: #B3261E; }
.xq-pc.black { color: #1D1B16; }
.xq-pt.is-last .xq-pc { box-shadow: 0 0 0 .6cqw #F2B134, 0 2px 4px rgba(0,0,0,.4), inset 0 0 0 .75cqw currentColor; }
.xq-pt.is-sel .xq-pc { box-shadow: 0 0 0 .8cqw #2BA59C, 0 4px 10px rgba(0,0,0,.45), inset 0 0 0 .75cqw currentColor; transform: translateY(-3%); }
.xq-pt.is-check .xq-pc { box-shadow: 0 0 0 .8cqw #E4572E, 0 0 18px 4px rgba(228,87,46,.6), inset 0 0 0 .75cqw currentColor; }
.xiangqi-board.is-live .xq-pt.is-movable, .xq-pt.is-target { cursor: pointer; }
.xq-pt.is-target::after { content: ""; position: absolute; width: 26%; height: 26%; border-radius: 50%; background: rgba(43,165,156,.75); z-index: 2; }
.xq-pt.is-capture::after { width: 92%; height: 92%; background: none; box-shadow: inset 0 0 0 .7cqw rgba(43,165,156,.9); }

/* Red and black swatches in the players bar for Xiangqi. */
.bg-dot.is-red { background: radial-gradient(circle at 35% 30%, #ff7a6b 0, #B3261E 65%); }
