:root {
    --dark-square: #769656;
    --light-square: #eeeed2;
    --highlight: rgba(255, 255, 0, 0.4);
    --possible-move: rgba(0, 0, 0, 0.2);
    --check-highlight: rgba(255, 0, 0, 0.5);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    background-color: #2e2e2e;
    color: #fff;
}

.header {
    margin-bottom: 20px;
    text-align: center;
}

.header h1 {
    font-size: 2.5rem;
    margin-bottom: 0;
}

.header p {
    font-size: 1.2rem;
    margin-top: 5px;
    color: #ccc;
}

.game-container {
    display: flex;
    flex-direction: row;
    gap: 20px;
    background-color: #3c3c3c;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
}

.left-column {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.board-container {
    position: relative;
    flex-shrink: 0;
}

.chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 560px;
    height: 560px;
    border: 8px solid #272522;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    /* Make the board maintain aspect ratio but fit within viewport */
    max-width: 100%;
    max-height: 100vw;
}

.square {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
}

.light {
    background-color: var(--light-square);
}

.dark {
    background-color: var(--dark-square);
}

.piece {
    width: 80%;
    height: 80%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 1;
}

.highlighted {
    background-color: var(--highlight);
}

.check {
    background-color: var(--check-highlight);
}

.possible-move::after {
    content: '';
    position: absolute;
    width: 25%;
    height: 25%;
    border-radius: 50%;
    background-color: var(--possible-move);
}

.coordinates {
    position: absolute;
    font-size: 12px;
    color: #ccc;
    user-select: none;
}

.rank {
    left: -20px;
    top: 50%;
    transform: translateY(-50%);
}

.file {
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
}

.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.game-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #272522;
    padding: 15px;
    border-radius: 8px;
    width: 300px;
}

.turn-indicator {
    font-size: 1.2rem;
    margin-bottom: 10px;
}

.game-status {
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: #ffcc00;
    font-weight: bold;
    min-height: 1.1rem;
}

.move-history {
    width: 100%;
    max-height: 350px;
    overflow-y: auto;
    background-color: #222;
    border-radius: 5px;
    padding: 10px;
    box-sizing: border-box;
    margin-bottom: 10px;
}

.notation-table {
    width: 100%;
    border-collapse: collapse;
    font-family: monospace;
    color: #eee;
}

.notation-table th {
    text-align: left;
    padding: 5px;
    font-weight: bold;
    border-bottom: 1px solid #444;
}

.notation-table td {
    padding: 5px 10px;
    white-space: nowrap;
}

.notation-table tr:hover {
    background-color: #333;
    cursor: pointer;
}

.notation-table td.active {
    background-color: #303030;
    font-weight: bold;
    color: white;
}

.captured-pieces {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-top: 10px;
}

.captured-white,
.captured-black {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 5px;
    border-radius: 4px;
    background-color: #333;
    min-height: 30px;
    width: 48%;
}

.captured-piece {
    width: 20px;
    height: 20px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

button {
    background-color: #4d4d4d;
    color: white;
    border: none;
    padding: 10px 15px;
    margin: 5px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #666;
}

button:active {
    background-color: #555;
}

button:disabled {
    background-color: #333;
    color: #777;
    cursor: not-allowed;
}

.move-navigation {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin: 10px 0;
}

.move-navigation button {
    min-width: 40px;
    font-weight: bold;
}

.game-buttons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
    background-color: #272522;
    border-radius: 8px;
    width: 100%;
    box-sizing: border-box;
}

/* Promotion dialog */
.promotion-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.promotion-container {
    background-color: #3c3c3c;
    padding: 20px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.promotion-container h2 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #fff;
}

.promotion-pieces {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

.promotion-piece {
    width: 60px;
    height: 60px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    cursor: pointer;
    background-color: var(--light-square);
    border-radius: 4px;
    transition: transform 0.2s;
}

.promotion-piece:hover {
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(255, 255, 0, 0.5);
}

/* Enhanced media queries for better mobile support */
@media (max-width: 1000px) {
    .game-container {
        flex-direction: column;
        align-items: center;
        padding: 15px;
        width: 100%;
        box-sizing: border-box;
    }

    .game-info {
        width: 100%;
        max-width: 560px;
    }

    .left-column {
        width: 100%;
        max-width: 560px;
    }
}

@media (max-width: 600px) {
    .chessboard {
        width: 100%;
        height: 100vw;
    }

    .board-container {
        width: 100%;
    }

    /* Adjust piece size for smaller boards */
    .piece {
        width: 85%;
        height: 85%;
    }

    /* Make coordinates more readable on small screens */
    .coordinates {
        font-size: 10px;
    }

    /* Adjust the header for smaller screens */
    .header h1 {
        font-size: 2rem;
    }

    .header p {
        font-size: 1rem;
    }

    /* Adjust the game buttons for smaller screens */
    .game-buttons {
        padding: 8px;
    }

    button {
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    /* Adjust the game info section for mobile */
    .game-info {
        padding: 10px;
    }

    /* Adjust promotion modal for small screens */
    .promotion-container h2 {
        font-size: 1.2rem;
    }

    .promotion-piece {
        width: 50px;
        height: 50px;
    }
}

/* Additional adjustments for very small screens */
@media (max-width: 400px) {
    .game-container {
        padding: 10px;
    }

    button {
        padding: 6px 10px;
        margin: 3px;
        font-size: 0.8rem;
    }

    .coordinates {
        font-size: 8px;
    }

    .rank {
        left: -15px;
    }

    .file {
        bottom: -15px;
    }
}
