/**
 * SBS CHESS - Chess Board & Game Arena Styling
 * Brand: SBS TECHNOLOGIES
 * Website: https://sbstechnologies.in
 */

:root {
    --chess-board-max: 600px;
    --chess-light-sq: #f0d9b5;
    --chess-dark-sq: #b58863;
    --chess-sq-selected: rgba(246, 246, 105, 0.65);
    --chess-sq-last-move: rgba(155, 199, 0, 0.45);
    --chess-sq-check: radial-gradient(circle, rgba(235, 59, 90, 0.85) 0%, rgba(235, 59, 90, 0.2) 65%, transparent 70%);
    --chess-legal-dot: rgba(20, 20, 20, 0.25);
    --chess-legal-capture: rgba(235, 59, 90, 0.35);
}

/* Arena Layout */
.chess-arena-container {
    max-width: 1140px;
    margin: 0 auto;
}

.chess-board-wrapper {
    position: relative;
    width: 100%;
    max-width: var(--chess-board-max);
    aspect-ratio: 1 / 1;
    margin: 0 auto;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    overflow: hidden;
    background: #262421;
    border: 4px solid #36322d;
    container-type: inline-size;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* 8x8 Board Grid */
.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
}

/* Squares */
.chess-square {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.35rem, 8.5cqw, 3.8rem);
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 0.15s ease;
}

.chess-square.light {
    background-color: var(--chess-light-sq);
    color: #111;
}

.chess-square.dark {
    background-color: var(--chess-dark-sq);
    color: #111;
}

/* Piece Appearance */
.chess-piece {
    position: relative;
    z-index: 2;
    transition: transform 0.1s ease;
    cursor: grab;
    pointer-events: none; /* Let square receive click */
    user-select: none;
    -webkit-user-select: none;
    line-height: 1;
}

.chess-piece.white-piece {
    color: #ffffff;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.85)) drop-shadow(0 0 1px #000);
}

.chess-piece.black-piece {
    color: #1a1a1a;
    filter: drop-shadow(0 2px 3px rgba(255, 255, 255, 0.45)) drop-shadow(0 0 1px rgba(255, 255, 255, 0.6));
}

/* Square Highlight States */
.chess-square.selected {
    background-color: var(--chess-sq-selected) !important;
}

.chess-square.last-move {
    background-color: var(--chess-sq-last-move) !important;
}

.chess-square.in-check {
    background: var(--chess-sq-check) !important;
    animation: pulseCheck 1.2s infinite ease-in-out;
}

@keyframes pulseCheck {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.25); }
}

/* Legal Move Indicators */
.chess-square.legal-move::after {
    content: '';
    position: absolute;
    width: 28%;
    height: 28%;
    background-color: var(--chess-legal-dot);
    border-radius: 50%;
    z-index: 3;
    pointer-events: none;
}

.chess-square.legal-capture::after {
    content: '';
    position: absolute;
    width: 82%;
    height: 82%;
    border: 5px solid var(--chess-legal-capture);
    border-radius: 50%;
    z-index: 3;
    pointer-events: none;
    box-sizing: border-box;
}

/* Coordinate Markers */
.coord-marker {
    position: absolute;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
    user-select: none;
    opacity: 0.8;
}

.coord-file {
    bottom: 2px;
    right: 4px;
}

.coord-rank {
    top: 2px;
    left: 4px;
}

.chess-square.light .coord-marker {
    color: var(--chess-dark-sq);
}

.chess-square.dark .coord-marker {
    color: var(--chess-light-sq);
}

/* Player Info Bar & Clock */
.player-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    background: #1f242d;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    min-height: 54px;
}

.player-bar.bottom-bar {
    margin-top: 0.5rem;
    margin-bottom: 0;
}

.player-bar.active-turn {
    border-color: #f39c12;
    box-shadow: 0 0 12px rgba(243, 156, 18, 0.25);
}

.player-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex: 1 1 auto;
}

.player-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: #15181e;
    flex-shrink: 0;
}

.player-name {
    font-weight: 600;
    font-size: 1rem;
    color: #f1f2f6;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.player-rating {
    font-size: 0.8rem;
    color: #a4b0be;
    white-space: nowrap;
}

/* Chess Clocks */
.chess-clock {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.45rem;
    font-weight: 700;
    padding: 0.35rem 0.85rem;
    border-radius: 6px;
    background: #13161c;
    color: #ced6e0;
    border: 1px solid #2f3542;
    min-width: 95px;
    text-align: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chess-clock.active-clock {
    background: #2f3542;
    color: #ffffff;
    border-color: #f1c40f;
    box-shadow: 0 0 10px rgba(241, 196, 15, 0.3);
}

.chess-clock.low-time {
    color: #ff4757;
    border-color: #ff4757;
    animation: clockBlink 1s infinite;
}

@keyframes clockBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Captured Pieces Display */
.captured-pieces {
    font-size: 1.15rem;
    min-height: 24px;
    color: #dfe4ea;
    display: flex;
    gap: 2px;
    align-items: center;
    line-height: 1;
    user-select: none;
    -webkit-user-select: none;
}

/* Game Info Card & Notation Table */
.game-sidebar {
    background: #1e222a;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 680px;
}

.notation-scroll {
    flex: 1;
    overflow-y: auto;
    max-height: 380px;
    background: #171a21;
    border-radius: 6px;
    padding: 0.5rem;
    font-family: monospace;
    font-size: 0.95rem;
    -webkit-overflow-scrolling: touch;
}

.move-row {
    display: flex;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    transition: background 0.15s;
}

.move-row:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.move-row.current-move {
    background: rgba(243, 156, 18, 0.18);
    font-weight: bold;
}

.move-num {
    width: 45px;
    color: #747d8c;
}

.move-white, .move-black {
    flex: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 3px;
}

.move-white:hover, .move-black:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Pawn Promotion Modal Options */
.promotion-choices {
    display: flex;
    justify-content: center;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.promotion-piece-btn {
    font-size: 3rem;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2f3542;
    border: 2px solid #57606f;
    border-radius: 8px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.15s, background-color 0.15s;
}

.promotion-piece-btn:hover {
    transform: scale(1.08);
    background: #f39c12;
    color: #111;
}

/* Responsive Scaling & Mobile Optimization */
@media (max-width: 991px) {
    .chess-board-wrapper {
        width: 100%;
        max-width: min(100%, 540px);
        margin: 0 auto;
    }
    .game-sidebar {
        margin-top: 1rem;
        max-height: none;
        display: flex;
        flex-direction: column;
    }
    .game-sidebar .game-actions-panel {
        order: 1;
        margin-bottom: 1rem;
        padding-top: 0 !important;
        border-top: none !important;
    }
    .game-sidebar .game-notation-panel {
        order: 2;
        margin-bottom: 0 !important;
    }
    .notation-scroll {
        max-height: 200px;
    }
}

@media (max-width: 576px) {
    .chess-arena-container {
        padding-left: 8px;
        padding-right: 8px;
    }
    .chess-board-wrapper {
        border-width: 3px;
        border-radius: 6px;
        max-width: 100%;
    }
    .chess-square {
        font-size: clamp(1.25rem, 8.8cqw, 2.5rem);
    }
    .coord-marker {
        font-size: 0.52rem;
        opacity: 0.7;
    }
    .coord-file {
        bottom: 1px;
        right: 2px;
    }
    .coord-rank {
        top: 1px;
        left: 2px;
    }
    .chess-square.legal-capture::after {
        border-width: 3px;
        width: 86%;
        height: 86%;
    }
    .player-bar {
        padding: 0.4rem 0.6rem;
        min-height: 48px;
        margin-bottom: 0.35rem;
    }
    .player-bar.bottom-bar {
        margin-top: 0.35rem;
    }
    .player-avatar {
        width: 32px;
        height: 32px;
    }
    .player-profile {
        gap: 0.45rem;
    }
    .player-name {
        font-size: 0.85rem;
        max-width: 100px;
    }
    .player-rating {
        font-size: 0.7rem;
    }
    .chess-clock {
        font-size: 1.15rem;
        padding: 0.2rem 0.5rem;
        min-width: 72px;
    }
    .captured-pieces {
        font-size: 0.95rem;
        max-width: 75px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    .promotion-choices {
        gap: 0.65rem;
    }
    .promotion-piece-btn {
        font-size: 2.1rem;
        width: 58px;
        height: 58px;
    }
    .notation-scroll {
        max-height: 160px;
        font-size: 0.85rem;
    }
}

@media (max-width: 375px) {
    .player-name {
        max-width: 80px;
        font-size: 0.8rem;
    }
    .player-rating {
        font-size: 0.68rem;
    }
    .chess-clock {
        font-size: 1.05rem;
        min-width: 64px;
        padding: 0.15rem 0.4rem;
    }
    .captured-pieces {
        max-width: 50px;
    }
    .promotion-choices {
        gap: 0.45rem;
    }
    .promotion-piece-btn {
        font-size: 1.85rem;
        width: 50px;
        height: 50px;
    }
}

@media (max-width: 330px) {
    .captured-pieces {
        display: none !important;
    }
    .player-name {
        max-width: 70px;
    }
    .promotion-piece-btn {
        font-size: 1.6rem;
        width: 44px;
        height: 44px;
    }
}
