:root {
    --bg-color: #282A36;
    --cell-color: #44475A;
    --x-color: #50FA7B;
    --o-color: #FF79C6;
    --text-color: #F8F8F2;
    --shadow-color: #21222C;
}

body {
    font-family: 'Montserrat', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column; /* Arrange children vertically */
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    overflow-y: auto; /* Allow scrolling if content overflows */
}

.game-container {
    width: 90%;
    max-width: 400px;
    background-color: var(--cell-color);
    padding: 1.5rem;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

header {
    width: 100%;
}

header h1 {
    font-size: 2.5rem;
    margin: 0 0 0.5rem 0;
    color: var(--text-color);
}

.status-text {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-color);
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 0.8rem; /* Responsive gap */
    width: 100%; /* Take full width of container */
    max-width: 300px; /* Limit board size on larger screens */
    margin: 0 auto; /* Center the board */
    position: relative; /* For absolute positioning of cells */
    z-index: 5;
    background-color: var(--shadow-color); /* Distinct background for grid lines */
    padding: 0.8rem; /* Padding to show the background color around the cells */
    border-radius: 10px; /* Match cell border-radius */
}

.cell {
    width: 100%; /* Take full width of grid column */
    padding-bottom: 100%; /* Maintain aspect ratio (1:1) */
    position: relative; /* For absolute positioning of content */
    background-color: var(--cell-color);
    border-radius: 10px;
    box-shadow: 0 6px 0 var(--shadow-color);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.2s;
}

.cell.x::before, .cell.o::before { /* Use pseudo-element for content to center it */
    content: attr(data-value); /* Will be 'X' or 'O' from JS */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem; /* Default large size */
    font-weight: 700;
    line-height: 1;
    text-shadow: 0 4px 6px rgba(0,0,0,0.2);
}

.cell.x { color: var(--x-color); }
.cell.o { color: var(--o-color); }

/* Style for the piece selected to be moved */
.cell.selected {
    background-color: #527a8e;
    box-shadow: 0 0 20px yellow;
    transform: scale(1.05);
}





/* --- Game Actions below board --- */
#game-actions {
    margin-top: 2rem;
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap; /* Allow buttons to wrap on smaller screens */
    z-index: 5; /* Ensure it's above other elements if needed */
}

.action-button {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.2s;
    box-shadow: 0 4px 0 var(--shadow-color);
    background-color: var(--bg-color);
    color: var(--text-color);
}

.action-button:hover {
    background-color: #3a4a5a;
}

/* --- Modal Styles (re-used) --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-box {
    background: var(--cell-color);
    padding: 2rem 3rem;
    border-radius: 15px;
    text-align: left;
    position: relative;
    box-shadow: 0 10px 0 var(--shadow-color);
    transform: scale(1);
    transition: transform 0.5s ease;
    max-width: 500px;
}

.modal-overlay.hidden .modal-box {
    transform: scale(0.7);
}

.modal-box h2 {
    text-align: center;
    margin-top: 0;
    color: var(--x-color);
}

.modal-box ul {
    list-style: none;
    padding: 0;
    margin-bottom: 2rem;
}

.modal-box ul li {
    margin-bottom: 1rem;
    line-height: 1.5;
}

.modal-box ul li::before {
    content: '›';
    color: var(--x-color);
    margin-right: 0.5rem;
    font-weight: bold;
}

#close-rules-button {
    /* Apply action-button style */
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.2s;
    box-shadow: 0 4px 0 var(--shadow-color);
    background-color: var(--x-color); /* Make it stand out */
    color: var(--bg-color);
}

#close-rules-button:hover {
    background-color: #40e0a0; /* Lighter green on hover */
}

/* Specific style for victory box content */
.victory-box {
    text-align: center;
}

#victory-message {
    font-size: 2.5rem;
    margin: 0 0 1.5rem 0;
    color: var(--x-color);
    text-transform: uppercase;
}

#play-again-button {
    padding: 0.8rem 2rem;
    font-size: 1.2rem;
    cursor: pointer;
    border: none;
    border-radius: 8px;
    background-color: var(--text-color);
    color: var(--bg-color);
    font-weight: bold;
    transition: background-color 0.3s;
    box-shadow: 0 4px 0 #6b7f8a;
}

#play-again-button:hover {
    background-color: #dbe8ef;
}

/* Confetti Styles */
.confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
}

.confetti {
    position: absolute;
    width: 8px;
    height: 16px;
    background-color: #f1c40f;
    top: -20px;
    opacity: 0.8;
    animation: fall 5s linear infinite;
}

@keyframes fall {
    to {
        transform: translateY(100vh) rotate(360deg);
        opacity: 0;
    }
}

/* Media Queries for Responsiveness */
@media (max-width: 480px) {
    .game-container {
        padding: 1rem;
        gap: 1rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .status-text {
        font-size: 1rem;
    }

    .board {
        gap: 0.5rem;
        max-width: 270px;
    }

    .cell.x::before, .cell.o::before {
        font-size: 3rem;
    }

    #game-actions {
        gap: 0.5rem;
    }

    .action-button, #close-rules-button, #play-again-button {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    #victory-message {
        font-size: 2rem;
    }
}

/* Media Queries for Responsiveness */