/* ==========================================================================
   Chess Board — Squares, pieces, highlights, animations
   ========================================================================== */

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 3px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* Squares */
.square {
    position: relative;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s;
}

/*
 * Square colors read from --board-theme-light/--board-theme-dark, which
 * board-settings.js sets on the persistent .chess-board container (not on
 * individual .square elements). Because custom properties cascade to
 * descendants, this lets chess-engine.js freely rebuild the squares on every
 * move/flip/hint without losing the player's chosen board theme.
 */
.square--light {
    background-color: var(--board-theme-light, #f0d9b5);
}

.square--dark {
    background-color: var(--board-theme-dark, #b58863);
}

[data-theme="dark"] .square--light {
    background-color: var(--board-theme-light, #6e8a5e);
}

[data-theme="dark"] .square--dark {
    background-color: var(--board-theme-dark, #4a6741);
}

/* Pieces */
.piece {
    font-size: clamp(1.8rem, 5vw, 3.5rem);
    line-height: 1;
    pointer-events: none;
    filter: drop-shadow(1px 1px 1px rgba(0, 0, 0, 0.3));
    transition: transform 0.15s;
}

/*
 * Custom piece sets: board-settings.js sets one --piece-<code> image URL per
 * piece per chosen set, plus [data-piece-set] on .chess-board, instead of
 * injecting <img> tags into individual .piece elements. Same reasoning as the
 * square colors above — these survive chess-engine.js's re-renders because
 * they live on the container, not on the children being rebuilt.
 */
.chess-board[data-piece-set] .piece {
    font-size: 0;
    display: block;
    width: 100%;
    height: 100%;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 82%;
    filter: none;
}

.chess-board[data-piece-set] .piece[data-piece="K"] { background-image: var(--piece-wK); }
.chess-board[data-piece-set] .piece[data-piece="Q"] { background-image: var(--piece-wQ); }
.chess-board[data-piece-set] .piece[data-piece="R"] { background-image: var(--piece-wR); }
.chess-board[data-piece-set] .piece[data-piece="B"] { background-image: var(--piece-wB); }
.chess-board[data-piece-set] .piece[data-piece="N"] { background-image: var(--piece-wN); }
.chess-board[data-piece-set] .piece[data-piece="P"] { background-image: var(--piece-wP); }
.chess-board[data-piece-set] .piece[data-piece="k"] { background-image: var(--piece-bK); }
.chess-board[data-piece-set] .piece[data-piece="q"] { background-image: var(--piece-bQ); }
.chess-board[data-piece-set] .piece[data-piece="r"] { background-image: var(--piece-bR); }
.chess-board[data-piece-set] .piece[data-piece="b"] { background-image: var(--piece-bB); }
.chess-board[data-piece-set] .piece[data-piece="n"] { background-image: var(--piece-bN); }
.chess-board[data-piece-set] .piece[data-piece="p"] { background-image: var(--piece-bP); }

/* Piece colors */
.piece[data-piece="K"], .piece[data-piece="Q"], .piece[data-piece="R"],
.piece[data-piece="B"], .piece[data-piece="N"], .piece[data-piece="P"] {
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.piece[data-piece="k"], .piece[data-piece="q"], .piece[data-piece="r"],
.piece[data-piece="b"], .piece[data-piece="n"], .piece[data-piece="p"] {
    color: #1a1a1a;
    text-shadow: 0 1px 2px rgba(255,255,255,0.15);
}

/* Square states */
.square--selected {
    background-color: rgba(255, 255, 100, 0.6) !important;
    box-shadow: inset 0 0 0 3px rgba(255, 200, 0, 0.8);
}

.square--correct {
    background-color: rgba(76, 175, 80, 0.5) !important;
    animation: squarePulse 0.5s ease;
}

.square--incorrect {
    background-color: rgba(244, 67, 54, 0.5) !important;
    animation: squareShake 0.4s ease;
}

.square--hint {
    background-color: rgba(33, 150, 243, 0.4) !important;
    animation: squarePulse 0.8s ease infinite;
}

.square--last-move {
    background-color: rgba(156, 204, 101, 0.4) !important;
}

/* Labels */
.square__label {
    position: absolute;
    font-size: 0.6rem;
    font-weight: 700;
    opacity: 0.7;
    pointer-events: none;
}

.square__label--rank {
    top: 2px;
    left: 3px;
}

.square__label--file {
    bottom: 2px;
    right: 3px;
}

.square--light .square__label { color: #b58863; }
.square--dark .square__label { color: #f0d9b5; }

/* Board shake animation */
.board--shake {
    animation: boardShake 0.4s ease;
}

/* Move list */
.move-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    min-height: 40px;
}

.move-list__move {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-family: var(--font-mono);
}

.move-list__move--player {
    background: var(--color-primary-500);
    color: #fff;
}

.move-list__move--computer {
    background: var(--color-border-light);
    color: var(--color-text);
}

/* Animations */
@keyframes squarePulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes squareShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

@keyframes boardShake {
    0%, 100% { transform: translateX(0); }
    10% { transform: translateX(-6px); }
    30% { transform: translateX(5px); }
    50% { transform: translateX(-4px); }
    70% { transform: translateX(3px); }
    90% { transform: translateX(-2px); }
}
