body {
    font-family: sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background-color: #f0f0f0;
    padding: 20px 0;
    box-sizing: border-box;
}

#main-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

#board-container {
    position: relative;
    margin: 35px 0; /* Increased margin for player info */
}

#chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: min(90vw, 80vh);
    height: min(90vw, 80vh);
    max-width: 600px;
    max-height: 600px;
    border: 5px solid #333;
    position: relative;
}

.coordinate {
    position: absolute;
    font-size: clamp(12px, 2vw, 16px);
    color: #333;
    user-select: none;
}

.file {
    bottom: -25px;
    width: 12.5%;
    text-align: center;
}

.rank {
    left: -25px;
    height: 12.5%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.square {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(16px, 4vw, 36px);
    user-select: none; /* Prevents text selection on pieces */
    position: relative;
}

.last-move-highlight {
    background-color: rgba(255, 255, 0, 0.5);
}

.light {
    background-color: #f0d9b5;
}

.dark {
    background-color: #b58863;
}

.piece {
    cursor: pointer;
    position: relative;
    transition: top 0.3s ease, left 0.3s ease;
    z-index: 10;
}

.piece.dragging {
    opacity: 0.5;
}

#status-panel {
    font-size: 1.2em;
    text-align: center;
}

.selected {
    background-color: #a5c9a5;
}

.check {
    background-color: #ff7f7f;
}

.valid-move {
    background-color: #a5c9a5;
    opacity: 0.5;
}

.hint-highlight {
    background-color: rgba(100, 100, 255, 0.6);
}

.captured-panel {
    width: 80%;
    max-width: 600px;
    min-height: 40px;
    border: 1px solid #333;
    margin: 10px 0;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    padding: 5px;
    box-sizing: border-box;
    position: relative;
}

#black-captured {
    margin-top: 25px;
}

.player-info {
    position: absolute;
    top: -30px;
    left: 5px;
    display: flex;
    align-items: center;
    font-size: 0.9em;
    font-weight: bold;
}

.player-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: #ccc;
    margin-right: 8px;
    border: 2px solid #555;
}

#promotion-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: none;
    z-index: 2000;
}

#promotion-choices {
    position: absolute;
    background-color: rgba(255, 255, 255, 0.95);
    border: 2px solid #333;
    border-radius: 5px;
    padding: 5px;
    display: flex;
    flex-direction: column;
}

.promotion-choice {
    cursor: pointer;
    font-size: clamp(24px, 5vw, 48px);
    padding: 5px;
    transition: background-color 0.2s;
}

.promotion-choice:hover {
    background-color: #a5c9a5;
}

.move-history-panel {
    width: 80%;
    max-width: 600px;
    height: 150px;
    border: 1px solid #333;
    margin: 10px 0;
    overflow-y: scroll;
}

#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 600px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

#status-panel {
    flex: 1;
    text-align: center;
}

#buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
}

#timers {
    flex: 0;
}

#buttons button {
    background-color: #4a7399;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    margin: 0 5px 10px;
    transition: background-color 0.3s ease;
}

#buttons button:hover {
    background-color: #3a5a78;
}

#buttons button:disabled {
    background-color: #999;
    cursor: not-allowed;
}

.modal-buttons {
    text-align: center;
    margin-top: 20px;
}

.modal-buttons button {
    background-color: #4a7399;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    margin: 0 10px;
}

.modal-buttons button:hover {
    background-color: #3a5a78;
}

#timers {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 400px;
    margin-top: 10px;
}

.timer-box {
    padding: 5px 10px;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}

.active-timer {
    background-color: #a5c9a5;
}

#ai-thinking-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 20px;
    border-radius: 10px;
    z-index: 1001;
}


#game-mode-selection button.selected,
#color-selection button.selected {
    background-color: #3a5a78;
}

#chessboard.flipped {
    transform: rotate(180deg);
}

#chessboard.flipped .piece {
    transform: rotate(180deg);
}

.check {
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% {
        background-color: #f0d9b5; /* light square */
    }
    50% {
        background-color: #ff7f7f;
    }
    100% {
        background-color: #f0d9b5; /* light square */
    }
}

.dark.check {
    animation-name: pulse-red-dark;
}

@keyframes pulse-red-dark {
    0% {
        background-color: #b58863; /* dark square */
    }
    50% {
        background-color: #ff7f7f;
    }
    100% {
        background-color: #b58863; /* dark square */
    }
}

.modal {
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4);
}

.modal-content {
    background-color: #fefefe;
    margin: 15% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 10px 0;
    }

    .captured-panel, .move-history-panel {
        width: 90%;
        margin: 5px 0;
    }

    .move-history-panel {
        height: 100px;
    }
}
