@font-face {
    font-family: 'ChessKaiTiPro';
    src: url('KaitiSimple.woff2') format('woff2');
    font-display: block;
}

.turn-indicator.red {
    background-color: #ff6b6b;
    color: #fff;
}

.turn-indicator.black {
    background-color: #34495e;
    color: #fff;
}

.check-alert {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: transparent;
    z-index: 1000;
    animation: pulse 0.5s ease-in-out infinite alternate;
    display: flex;
    align-items: center;
    justify-content: center;
}

.check-alert-img {
    width: 256px;
    height: auto;
    opacity: 0.9;
}

@keyframes pulse {
    from {
        transform: translate(-50%, -50%) scale(1);
    }

    to {
        transform: translate(-50%, -50%) scale(1.1);
    }
}

.chessboard {
    padding: 12px 13px;
    width: 100%;
    max-width: 772px;
    aspect-ratio: 9 / 10;
    margin: 0 auto;
    grid-template-columns: repeat(9, minmax(0, 1fr));
    grid-template-rows: repeat(10, minmax(0, 1fr));
    border: 2px solid #8b4513;
    background-image: url('table.jpeg');
    background-size: 100% 100%;
    background-position: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    container-type: inline-size;
}

.cell {
    border: none;
    height: 100%;
    min-height: 0;
    aspect-ratio: 1 / 1;
    transition: background-color 0.2s ease;
}

.cell:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.cell.selected {
    background-color: rgba(100, 200, 100, 0.5);
}

.cell.valid-move {
    background-color: rgba(100, 200, 100, 0.5) !important;
    z-index: 2;
}

.cell.last-move {
    background-color: rgba(100, 149, 237, 0.5) !important;
    z-index: 1;
}

.piece {
    width: 88%;
    height: 88%;
    font-family: 'ChessKaiTiPro';
    font-size: clamp(1rem, 6.5cqi, 3rem);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.3s ease;
    position: relative;
    z-index: 1;
    background: linear-gradient(180deg, #f8edd2 0%, #efddb0 58%, #e3ca93 100%);
    border: 1px solid rgba(135, 102, 58, 0.42);
    box-shadow: inset 0 1px 0 rgba(255, 251, 240, 0.62), inset 0 0 0 2px rgba(248, 235, 198, 0.18), inset 0 -1px 0 rgba(166, 131, 83, 0.2), 0 2px 4px rgba(0, 0, 0, 0.18);
}

.piece:hover {
    transform: scale(1.1);
}

.piece.moving {
    transition: transform 0.3s ease-in-out;
}

.piece.captured {
    animation: capture 0.5s ease-in-out forwards;
}

@keyframes capture {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.5;
    }

    100% {
        transform: scale(0);
        opacity: 0;
    }
}

.piece.red,
.piece.black {
    background: linear-gradient(180deg, #f8edd2 0%, #efddb0 58%, #e3ca93 100%);
}

.piece.red {
    color: #b3372a;
    text-shadow: 0 1px 0 rgba(255, 249, 240, 0.35);
}

.piece.black {
    color: #34495e;
    text-shadow: 0 1px 0 rgba(255, 249, 240, 0.28);
}

#game-over-modal .modal-content {
    min-width: 300px;
}

#game-over-message {
    font-size: 1.2rem;
    margin: 1rem 0;
    color: #e74c3c;
    font-weight: bold;
}

#rematch-waiting-modal .modal-content,
#opponent-left-modal .modal-content,
#player-left-modal .modal-content {
    min-width: 280px;
}

#opponent-left-modal p,
#player-left-modal p,
#all-players-left-modal p {
    color: #e74c3c;
}

#all-players-left-modal .modal-content {
    min-width: 320px;
}

.forbidden-modal {
    max-width: 380px;
    text-align: center;
}

.forbidden-icon {
    font-size: 48px;
    margin-bottom: 10px;
}

#forbidden-move-modal h3 {
    color: #c0392b;
    margin-bottom: 0.5rem;
}

#forbidden-move-message {
    font-size: 1rem;
    color: #333;
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

@media (min-width: 1179px) {
    .game-layout {
        container-type: size;
    }

    .chessboard {
        width: min(100%, 772px, 90cqh);
        max-width: 772px;
        max-height: 100cqh;
    }
}

@media (min-width: 1179px) and (max-height: 850px) {
    .game-layout {
        align-items: flex-start;
    }
}

@media (max-width: 1178px) {
    .spectator-controls {
        gap: 0.5rem;
        justify-content: center;
    }

    .left-sidebar {
        flex: 1;
        align-items: center;
    }

    .right-sidebar {
        flex: 1;
        flex-direction: column;
        align-items: center;
        gap: 1rem;
    }

    .game-room-info,
    .turn-indicator {
        margin-bottom: 0;
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 2.5rem;
        min-width: 111px;
        max-height: 49px;
        white-space: nowrap;
    }

    .turn-indicator.spectator {
        flex: 2;
        white-space: nowrap;
    }

    .game-buttons {
        gap: 0.5rem;
        flex: 1;
        justify-content: center;
    }

    .right-sidebar:has(.turn-indicator.spectator) .game-buttons {
        display: none;
    }

    .right-sidebar:has(.turn-indicator.spectator) {
        justify-content: space-between;
    }

    .right-sidebar:has(.turn-indicator.spectator) .game-room-info,
    .right-sidebar:has(.turn-indicator.spectator) .turn-indicator {
        flex: 1;
        min-width: 159px;
    }

    .game-btn {
        padding: 0.5rem 1rem;
        font-size: 1rem;
        min-width: 64px;
    }
}

@media (max-width: 1024px) {
    .chessboard {
        width: 85vw;
        height: auto;
        max-width: 85dvh;
        aspect-ratio: 9 / 10;
    }
}