/* Xiangqi additions on top of the shared uTable styles (same tokens, same layout).
   The page serves one game at a time: <html data-game> hides the other game's parts. */
:root[data-game="xiangqi"] .only-gomoku, :root:not([data-game="xiangqi"]) .only-xiangqi { display: none !important; }
:root {
  --piece-face: #f7ead0;
  --piece-edge: #dcc08a;
  --piece-red: #b0291c;
  --piece-black: #23241f;
  --check: #c2412b;
  --target: rgba(35, 41, 37, .55);
}

/* Board: 9 × 10 intersections, same single-column rule as Gomoku. */
:root[data-game="xiangqi"] .app { --col: min(504px, 100%, calc((100dvh - 244px) * .9)); }
.xq-wrap { aspect-ratio: 9 / 10; container-type: inline-size; }
.xq-wrap::before, .xq-wrap::after { display: none; }
.xq-lines { position: absolute; inset: 2.6%; width: 94.8%; height: 94.8%; pointer-events: none; }
.xq-lines line, .xq-lines path, .xq-lines rect { stroke: var(--grid); fill: none; vector-effect: non-scaling-stroke; }
.xq-lines .frame { stroke-width: 2; }
.xq-lines .mark { stroke-width: 1; }
.xq-lines text { fill: rgba(92, 70, 36, .55); font: 500 4.6px var(--xiangqi-font); letter-spacing: 3px; dominant-baseline: central; text-anchor: middle; }
.xq-grid { position: absolute; inset: 2.6%; z-index: 1; display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(10, 1fr); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.xq-grid .cell { border-radius: 50%; }

/* Pieces: ivory disc, inner ring, calligraphy glyph. */
.piece { position: relative; display: grid; place-items: center; width: 88%; aspect-ratio: 1; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 38% 30%, #fffaf0, var(--piece-face) 55%, var(--piece-edge));
  box-shadow: 0 2px 3px rgba(60, 40, 10, .35), inset 0 -2px 0 rgba(120, 85, 30, .25);
  font: 500 5.9cqw/1 var(--xiangqi-font);
  transition: transform .14s ease-out, box-shadow .14s; }
.piece::before { position: absolute; inset: 9%; content: ''; border: 1.5px solid currentColor; border-radius: 50%; opacity: .55; }
.piece.red { color: var(--piece-red); }
.piece.black { color: var(--piece-black); }

.cell.is-selected .piece { transform: translateY(-3%) scale(1.07); box-shadow: 0 0 0 3px var(--ink), 0 6px 10px rgba(60, 40, 10, .3); }
.cell.is-origin-preview .piece { opacity: .35; }
.piece.is-preview { opacity: .75; outline: 2px solid var(--accent); outline-offset: 2px; }
.piece.is-ghost { opacity: .5; }

/* Legal targets: dot on empty points, ring on capturable pieces. */
.cell.is-target::after { position: absolute; content: ''; width: 26%; aspect-ratio: 1; border-radius: 50%; background: var(--target); pointer-events: none; }
.cell.is-target.has-piece::after { width: 96%; background: none; border: 3px solid var(--target); }
.cell.is-target { cursor: pointer; }

/* Last move: faint ring at origin, clay corner marks on the moved piece. */
.cell.is-from::before { position: absolute; content: ''; width: 34%; aspect-ratio: 1; border: 2px solid var(--accent); border-radius: 50%; opacity: .5; pointer-events: none; }
.cell.is-to .piece { box-shadow: 0 0 0 2.5px var(--accent), 0 2px 3px rgba(60, 40, 10, .35); }

/* Check: the threatened general glows red. */
.cell.is-check .piece { box-shadow: 0 0 0 3px var(--check), 0 0 14px 3px rgba(194, 65, 43, .55); animation: check-pulse 1.2s ease-in-out infinite; }
@keyframes check-pulse { 50% { box-shadow: 0 0 0 3px var(--check), 0 0 4px 1px rgba(194, 65, 43, .35); } }
.cell.is-win .piece { box-shadow: 0 0 0 3px #f2c84b, 0 2px 6px rgba(0, 0, 0, .35); }

/* Chips use a tiny general instead of a stone. */
.piece-icon { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, #fffaf0, var(--piece-face) 55%, var(--piece-edge));
  box-shadow: 0 1px 2px rgba(60, 40, 10, .3); font: 500 15px/1 var(--xiangqi-font); }
.piece-icon-red { color: var(--piece-red); }
.piece-icon-black { color: var(--piece-black); }
.player-chip.is-turn .piece-icon { box-shadow: 0 0 0 3px var(--surface), 0 0 0 4.5px var(--ink); }
.player-chip.is-check .piece-icon { box-shadow: 0 0 0 3px var(--surface), 0 0 0 4.5px var(--check); }
.turn-indicator[data-state="check"] { color: var(--check); }
.turn-indicator[data-state="check"] .turn-dot { background: var(--check); animation: pulse 1s ease-in-out infinite; }
.mini-piece { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--piece-face); box-shadow: inset 0 0 0 1px var(--piece-edge); color: var(--piece-red); font: 500 11px/1 var(--xiangqi-font); }
.result-bar .result-piece { width: 40px; height: 40px; font-size: 22px; }


/* Captured pieces under the board. */
.captured-row { display: flex; justify-content: space-between; gap: 12px; width: var(--col); margin-top: 10px; min-height: 22px; }
.captured { display: flex; align-items: center; gap: 6px; min-width: 0; }
.captured-right { flex-direction: row-reverse; }
.captured small { flex: none; color: var(--muted); font-size: 12px; }
.captured-list { display: flex; flex-wrap: wrap; gap: 2px; }
.captured-list span { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--piece-face); box-shadow: inset 0 0 0 1px var(--piece-edge); font: 500 12px/1 var(--xiangqi-font); }
.captured-list .red { color: var(--piece-red); }
.captured-list .black { color: var(--piece-black); }

@media (max-width: 520px) {
  .piece-icon { width: 24px; height: 24px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) { .cell.is-check .piece { animation: none; } }

/* Rooms list and repetition hint */
.room-game { display: inline-block; margin-right: 6px; padding: 1px 7px; border-radius: 999px; background: var(--paper); color: var(--muted); font-size: 11px; font-weight: 600; vertical-align: 1px; }
.room-game-xq { background: #f6e3dc; color: var(--piece-red); }
.repeat-hint { width: var(--col); margin: 10px 0 0; padding: 9px 12px; border-radius: 12px; background: var(--warn); color: var(--warn-ink); font-size: 13px; line-height: 1.45; }
