/* General Page Structure */
body {
    background-color: #f8f9fa;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    color: #343a40;
    line-height: 1.6;
}

main {
    /* max-width: 1200px; */ /* Removed to allow board to grow */
    margin: 0 auto;
    padding: 3rem 2rem;
}

/* Game Section */
#game-section {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    padding: 2.5rem;
    margin-bottom: 3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem; /* Reduced gap to bring elements closer */
}

.game-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem; /* Tight gap between game-status, captured-pieces, and controls */
    margin-top: 0.5rem; /* Small margin from board */
}

#game-status {
    font-size: 1.25rem;
    font-weight: bold;
    padding: 0.5rem 0;
    text-align: center;
    color: black;
}

#game-status.red-turn {
    color: black;
}

#game-status.black-turn {
    color: black;
}

.checkers-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 35vh; /* Use viewport height to make it large */
    height: 35vh; /* Use viewport height to make it large */
    max-width: 90vw;
    aspect-ratio: 1 / 1;
    border: 10px solid #8b4513; /* Darker, richer wood color */
    border-radius: 8px;
    background-color: #f0d9b5; /* Light square color */
    user-select: none;
    box-shadow: 0 10px 20px rgba(0,0,0,0.2), inset 0 0 10px rgba(0,0,0,0.1);
}

.square {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

.square.dark {
    background-color: #b58863; /* Classic wood dark square */
}

.square.light {
    background-color: #f0d9b5; /* Classic wood light square */
}

.square.valid-move::after {
    content: '';
    position: absolute;
    width: 35%;
    height: 35%;
    background-color: rgba(40, 167, 69, 0.6);
    border-radius: 50%;
    pointer-events: none;
    z-index: 5;
}

.square.valid-move:hover {
    cursor: pointer;
    background-color: #cdaa7d !important; /* Highlight for hover */
}

.piece {
    width: 85%;
    height: 85%;
    border-radius: 50%;
    box-shadow: inset 0 -4px 6px rgba(0,0,0,0.2), 0 5px 8px rgba(0,0,0,0.3);
    position: relative;
    transition: transform 0.2s ease-out;
    cursor: pointer;
    z-index: 10;
}

.piece.red {
    background: radial-gradient(circle at 65% 35%, #ff8a8a, #c92a2a 80%);
    border: 2px solid #a61e1e;
}

.piece.black {
    background: radial-gradient(circle at 65% 35%, #6c757d, #212529 80%);
    border: 2px solid #000;
}

.piece.king::before {
    content: '👑'; /* Using a more universally recognized crown emoji */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ffd700;
    font-size: calc(min(2.5vw, 28px)); /* Responsive font size */
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

.controls {
    margin: 0; /* Removed margin-top to bring closer */
}

.btn {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s;
}

.btn:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

/* Info Sections & Cards (borrowed from xo.css for consistency) */
.info-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 3rem;
}

.info-section-centered {
    display: block;
}

.info-card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    padding: 2.5rem;
}

.info-card h2 {
    font-size: 2rem;
    font-weight: 600;
    color: #003366;
    margin-top: 0;
    margin-bottom: 1.5rem;
}

.info-card h4 {
    font-size: 1.4rem;
    color: #005f9e;
    margin-bottom: 0.5rem;
}

.info-card p, .info-card li {
    color: #343a40;
}

.info-card ul {
    padding-left: 20px;
}

/* Modal styles */
.winner-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.winner-content {
    background: white;
    padding: 2.5rem 3rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    transform: scale(0.95);
    animation: modal-pop 0.3s ease-out forwards;
}

@keyframes modal-pop {
    to {
        transform: scale(1);
    }
}

.winner-content h2 {
    font-size: 2rem;
    margin-bottom: 1.5rem;
}

/* Responsive Design */
@media (max-width: 992px) {
    .info-section {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    main {
        padding: 2rem 1rem;
    }
    #game-section, .info-card {
        padding: 1.5rem;
    }
    .checkers-board {
        max-width: 90vw;
    }
}

@media (max-width: 540px) {
    #game-section {
        padding: 1.25rem;
    }
    .checkers-board {
        width: min(82vw, 320px);
        height: min(82vw, 320px);
        border-width: 8px;
    }
    .captured-pieces-container {
        width: min(92vw, 360px);
        flex-direction: column;
        align-items: center;
    }
    .captured-side {
        min-height: 70px;
    }
    .btn {
        width: 100%;
        max-width: 240px;
    }
}

@media (orientation: portrait) and (max-width: 480px) {
    .checkers-board {
        width: min(90vw, 300px);
        height: min(90vw, 300px);
    }
    .captured-pieces-container {
        width: 95vw;
    }
    .btn {
        max-width: 200px;
    }
}

@media (orientation: portrait) and (max-width: 430px) {
    .checkers-board {
        width: min(88vw, 290px);
        height: min(88vw, 290px);
    }
    .captured-pieces-container {
        width: 94vw;
    }
    .btn {
        max-width: 190px;
    }
}

@media (orientation: landscape) and (max-height: 520px) {
    #game-section {
        padding: 1rem;
    }
    .checkers-board {
        width: min(78vw, 62vh);
        height: min(78vw, 62vh);
        border-width: 8px;
    }
    .captured-pieces-container {
        width: min(88vw, 70vh);
        flex-direction: row;
        gap: 0.5rem;
    }
    .captured-side {
        min-height: 64px;
    }
    .btn {
        width: auto;
        min-width: 160px;
    }
}

.winner-message {
    font-size: 1.2rem;
    font-weight: bold;
    color: #000000;
    margin-top: 1rem;
    text-align: center;
    min-height: 2.5rem;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Captured Pieces Display */
.captured-pieces-container {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    width: 35vh;
    max-width: 90vw;
    margin: 0; /* Removed margin-top to bring closer */
}

.captured-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.captured-label {
    font-size: 0.9rem;
    font-weight: bold;
    color: #333;
    text-align: center;
}

.captured-side {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 5px;
    min-height: 90px; /* Fixed height to prevent shape change */
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background-color: #f8f8f8;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
    align-content: flex-start;
    box-sizing: border-box;
}

/* Border highlighting for clarity */
#player-captured {
    border-top: 3px solid #c92a2a; /* Red theme */
}

#ai-captured {
    border-top: 3px solid #212529; /* Black theme */
}

.captured-piece {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    position: relative;
}

.captured-piece.red {
    background: radial-gradient(circle at 65% 35%, #ff8a8a, #c92a2a 80%);
    border: 1px solid #a61e1e;
}

.captured-piece.black {
    background: radial-gradient(circle at 65% 35%, #6c757d, #212529 80%);
    border: 1px solid #000;
}

.captured-piece.king::before {
    content: '👑';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ffd700;
    font-size: 12px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}


/* AI Last Move Highlight */
@keyframes ai-move-glow {
    0% {
        box-shadow: inset 0 0 15px 5px rgba(173, 216, 230, 0);
    }
    50% {
        box-shadow: inset 0 0 15px 5px rgba(233, 238, 97, 0.7);
    }
    100% {
        box-shadow: inset 0 0 15px 5px rgba(173, 216, 230, 0);
    }
}

.square.ai-last-move {
    animation: ai-move-glow 2s infinite;
}

