/*
 * Chess board drawn by static/js/chess-board.js (game page, player Openings
 * tab): an 8x8 grid of squares, sized by its container and kept square, and
 * the material strips above it.
 */
/* Square colours: the board, and the promotion picker drawn over it. */
.game-board,
.game-promotion {
    --board-light: #dee3e6;
    --board-dark: #8ca2ad;
    --board-highlight: rgba(102, 126, 234, 0.45);
    --board-pick: rgba(20, 85, 30, 0.5);
}
.game-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    aspect-ratio: 1;
    border-radius: var(--border-radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    user-select: none;
}
.game-square {
    position: relative;
    background: var(--board-light);
}
.game-square--dark { background: var(--board-dark); }
.game-square--last::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--board-highlight);
}
.game-square img {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
}
/* Coordinates in the corner of the edge squares, in the other square
   colour so they read on both. */
.game-coord {
    position: absolute;
    z-index: 1;
    font-size: clamp(8px, 2.4vw, 12px);
    font-weight: var(--font-weight-semibold);
    line-height: 1;
    color: var(--board-dark);
    pointer-events: none;
}
.game-square--dark .game-coord { color: var(--board-light); }
.game-coord--rank { top: 2px; left: 2px; }
.game-coord--file { bottom: 2px; right: 3px; }

/* Material strips above the board (renderMaterial in chess-board.js),
   whatever the orientation: the captured white pieces on the left and the
   captured black pieces on the right (net of trades), with the lead of the
   side that captured them. Always one icon tall, empty or not, so the board
   never moves; a long surplus wraps inside its half instead of overflowing. */
.game-materials {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-xs);
}
.game-material {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 6px;
    min-height: 20px;
}
.game-material--black {
    justify-content: flex-end;
}
.game-material-group {
    display: inline-flex;
}
/* The outline keeps black pieces readable on the dark theme's background. */
.game-material-group img {
    display: block;
    width: 20px;
    height: 20px;
    filter: drop-shadow(0 0 1px var(--color-text));
}
/* Pieces of the same type overlap. */
.game-material-group img + img {
    margin-left: -10px;
}
.game-material-lead {
    font-size: var(--font-size-sm);
    line-height: 20px;
    font-weight: var(--font-weight-semibold);
    font-variant-numeric: tabular-nums;
    color: var(--color-text-light);
}
/* Read by screen readers only. */
.game-material-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Engine analysis visuals that belong with the board and, like it, look the
   same in both themes: the evaluation bar and chart (game page) and the
   best-move arrow. */
:root {
    --board-eval-white: #f2f2f2;
    --board-eval-black: #3a3a3a;
    --board-eval-line: #9aa5b1;
    --board-eval-mid: rgba(150, 150, 150, 0.7);
    --board-arrow: rgba(21, 120, 27, 0.75);
}

/* Best-move arrow over the board (renderArrow in chess-board.js): an SVG the
   size of the board, above the pieces, letting clicks through. */
.game-board-wrap {
    position: relative;
}
.game-arrow {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.game-arrow-shaft {
    stroke: var(--board-arrow);
    stroke-width: 0.16;
    stroke-linecap: round;
}
.game-arrow-head {
    fill: var(--board-arrow);
}

/* A piece letter in SAN drawn as the piece (renderSan in chess-board.js): the
   board's piece outline as a mask, filled with the text colour, so it follows
   the theme and the highlighted move. The letter is kept but not shown. */
.san-word {
    white-space: nowrap;
}
.figurine {
    display: inline-block;
    width: 1.15em;
    height: 1.15em;
    margin-right: 1px;
    vertical-align: -0.22em;
    overflow: hidden;
    text-indent: 2em;
    white-space: nowrap;
    background-color: currentColor;
    -webkit-mask: var(--figurine) center / contain no-repeat;
    mask: var(--figurine) center / contain no-repeat;
}
.figurine[data-piece="K"] { --figurine: url('../img/pieces/bK.svg'); }
.figurine[data-piece="Q"] { --figurine: url('../img/pieces/bQ.svg'); }
.figurine[data-piece="R"] { --figurine: url('../img/pieces/bR.svg'); }
.figurine[data-piece="B"] { --figurine: url('../img/pieces/bB.svg'); }
.figurine[data-piece="N"] { --figurine: url('../img/pieces/bN.svg'); }

/* A board that takes moves (attachBoardInput, game analyzer): a drag on it
   moves a piece instead of scrolling the page. */
.game-board--interactive {
    touch-action: none;
    -webkit-touch-callout: none;
}
.game-board--interactive .game-square { cursor: pointer; }
.game-square--selected::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--board-pick);
}
/* Legal targets: a dot on an empty square, a ring on a capture. */
.game-square--target::after,
.game-square--capture::after {
    content: "";
    position: absolute;
    z-index: 2;
    pointer-events: none;
}
.game-square--target::after {
    inset: 36%;
    border-radius: 50%;
    background: var(--board-pick);
}
.game-square--capture::after {
    inset: 0;
    border-radius: 50%;
    background: radial-gradient(transparent 0 62%, var(--board-pick) 63%);
}
.game-square--drop {
    box-shadow: inset 0 0 0 3px var(--board-pick);
}
/* The piece being dragged stays faint on its square; a copy follows the pointer. */
.game-square--lifted img { opacity: 0.3; }
.game-drag-piece {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    pointer-events: none;
    will-change: transform;
}

/* Promotion picker over the board (choosePromotion): the four pieces in a
   column from the promotion square, over a dimmed board. */
.game-promotion {
    position: absolute;
    inset: 0;
    z-index: 5;
    background: var(--color-overlay);
    border-radius: var(--border-radius-sm);
}
.game-promotion-picker {
    position: absolute;
    display: flex;
    width: 12.5%;
    height: 50%;
    box-shadow: var(--shadow-md);
}
.game-promotion-choice {
    flex: 1 1 0;
    display: block;
    padding: 0;
    border: none;
    border-radius: 0;
    background: var(--board-light);
    cursor: pointer;
}
.game-promotion-choice:hover,
.game-promotion-choice:focus-visible {
    background: var(--board-dark);
    outline: none;
}
.game-promotion-choice img {
    display: block;
    width: 100%;
    height: 100%;
}
