/* Chess. The board is a square sized by app.js (--side) to the room .board-wrap is given.
   Wide screens: the board with the players, the turn line and the move list beside it.
   Upright screens: the players in a row on top, the board, then the turn line. */
.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 26px; padding: 12px max(12px, var(--gk-safe-end)) max(12px, var(--gk-safe-bottom)) max(12px, var(--gk-safe-start)); }
.board-wrap { flex: 0 1 auto; min-width: 0; min-height: 0; height: 100%; max-height: 760px; aspect-ratio: 1; display: grid; place-items: center; }
.frame { --side: 360px; width: var(--side); height: var(--side); padding: calc(var(--side) * .025); border-radius: calc(var(--side) * .03);
  background: linear-gradient(145deg, var(--gk-raise), var(--gk-rim)); border: 1px solid var(--gk-gold-deep); box-shadow: 0 0 0 3px var(--gk-rim), var(--gk-shadow-2), var(--gk-inset); }
/* The board itself: warm light squares and slate dark ones; the pieces are ivory and navy. */
.board { --light: var(--board-light, #dccaa0); --dark: var(--board-dark, #557178); width: 100%; height: 100%; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr));
  direction: ltr; border-radius: calc(var(--side) * .01); overflow: hidden; box-shadow: 0 0 0 2px var(--gk-rim); user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.square { position: relative; min-width: 0; min-height: 0; padding: 6%; border: 0; border-radius: 0; background: var(--light); cursor: pointer; display: grid; place-items: center; }
.square.dark { background: var(--dark); }
.square:not(:disabled):hover { filter: brightness(1.08); }
.square:disabled { cursor: default; }
.square:focus-visible { outline: var(--gk-focus); outline-offset: -3px; z-index: 5; }
/* The player's chess skins (app.js) give the board and the pieces their colours; these are the plain ones. */
.white-piece { --piece-fill: var(--wp-fill, #fff4d9); --piece-stroke: var(--wp-stroke, #745a39); }
.black-piece { --piece-fill: var(--bp-fill, #142c40); --piece-stroke: var(--bp-stroke, #9ab4c6); }
.piece-art { display: block; width: 100%; height: 100%; min-width: 0; min-height: 0; pointer-events: none; }
.piece-art svg, .seat-piece svg, .captured svg, .promotion svg { display: block; width: 100%; height: 100%; fill: var(--piece-fill); stroke: var(--piece-stroke); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.piece-art svg { position: relative; z-index: 2; filter: drop-shadow(0 2px 1px #17222a66); }
.square.fresh .piece-art svg { animation: piece-in .2s ease-out; }
@keyframes piece-in { from { opacity: 0; scale: .7; } }
.square.last-move { box-shadow: inset 0 0 0 100vmax color-mix(in srgb, var(--gk-gold) 38%, transparent); }
.square.selected { background: var(--gk-gold-warm); box-shadow: inset 0 0 0 3px var(--gk-gold-pale); }
.square.legal::after { content: ''; position: absolute; inset: 39%; border-radius: 50%; background: var(--gk-rim); opacity: .55; z-index: 3; }
.square.legal.occupied::after { inset: 4%; border: 3px solid var(--gk-gold-pale); background: transparent; opacity: 1; z-index: 4; }
.square.check { background: radial-gradient(circle, #f29a7f, #aa6558); box-shadow: inset 0 0 0 3px #f4ac8a; }
.coordinate { position: absolute; z-index: 4; font-size: var(--gk-text-xs); font-weight: var(--gk-number); line-height: 1; color: var(--dark); pointer-events: none; }
.square.dark .coordinate { color: var(--light); }
.coordinate.rank { top: 3px; left: 3px; }
.coordinate.file { bottom: 3px; right: 3px; }
/* A clear board behind New game and while a room waits for its people. */
html.gk-clear .piece-art { visibility: hidden; }

/* The column beside the board. */
.side { flex: none; width: 300px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.seats { display: grid; gap: 8px; }
.seat-white { --seat: var(--gk-gold-pale); }
.seat-black { --seat: var(--gk-info); }
.seat-piece { flex: none; width: 34px; height: 34px; padding: 3px; border-radius: 50%; }
/* Navy pieces sit on a light disc so they stand out from the navy panel. */
:is(.seat-piece, .captured).black-piece { background: var(--gk-ink-soft); }
/* On the player's face the king is a small badge, on the same disc. */
.gk-face > .seat-piece.gk-face-badge { padding: .06em; }
.gk-face > .seat-piece.black-piece.gk-face-badge { background-color: var(--gk-ink-soft); }
.captured { flex: none; max-width: 45%; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0 1px; padding: 2px 4px; border-radius: var(--gk-r-sm); direction: ltr; }
.captured:empty { display: none; }
.captured svg { width: 14px; height: 17px; }
.talk { min-height: 3.4em; padding-inline: 4px; }
.talk.check .gk-turn { color: var(--gk-bad); }
.history { min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--gk-line); border-radius: 12px; background: var(--gk-well); }
.history summary { min-height: var(--gk-tap); display: flex; align-items: center; padding: 0 14px; cursor: pointer; color: var(--gk-ink-soft); font-size: var(--gk-text-sm); font-weight: var(--gk-medium); }
.history ol { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 18px; max-height: 220px; overflow: auto; margin: 0; padding: 4px 14px 12px 34px; color: var(--gk-ink-soft); font-size: var(--gk-text-xs); line-height: 1.5; }
.history li::marker { color: var(--gk-gold-deep); }
/* The promotion choice (a shared pop-up). */
.promotion { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; direction: ltr; }
.promotion .gk-btn { flex-direction: column; gap: 4px; min-height: 96px; padding: 8px 4px; }
.promotion .gk-btn i { display: block; width: 46px; height: 52px; }
.promotion .gk-btn span { font-size: var(--gk-text-xs); }

/* Upright screens: players, board, turn line. */
@media (orientation: portrait) {
  .stage { flex-direction: column; gap: 10px; }
  .side { display: contents; }
  .seats { order: -1; width: min(100%, 600px); grid-template-columns: 1fr 1fr; }
  .board-wrap { width: min(100%, 760px); height: auto; max-height: 100%; }
  .talk { min-height: 0; text-align: center; }
  .history { display: none; }
}
@media (max-width: 599px) {
  .gk-seat { padding: 6px 8px; gap: 6px; }
  .seat-piece { width: 26px; height: 26px; padding: 2px; }
  .captured svg { width: 10px; height: 13px; }
  .coordinate { font-weight: var(--gk-medium); }
}
@media (min-width: 600px) and (max-width: 1023px) and (orientation: portrait) {
  .stage { gap: 16px; padding-top: 16px; }
  .gk-turn { font-size: var(--gk-text-lg); }
}
/* A sideways phone. */
@media (orientation: landscape) and (max-height: 560px) {
  .stage { gap: 14px; padding-top: 6px; padding-bottom: max(6px, var(--gk-safe-bottom)); }
  .side { width: 250px; gap: 8px; }
  .gk-seat { padding: 5px 10px; }
  .gk-seat-note { display: none; }
  .talk { min-height: 0; }
  .history { display: none; }
}
@media (prefers-reduced-motion: reduce) { .square.fresh .piece-art svg { animation: none; } }
