:root {
    --bg-color: #1a2a33;
    --cell-color: #1f3641;
    --x-color: #31c3bd;
    --o-color: #f2b137;
    --text-color: #a8bfc9;
    --shadow-color: #10212a;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    text-align: center;
}

.game-container {
    width: 90%;
    max-width: 400px;
}

header {
    margin-bottom: 2rem;
}

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

.status-text {
    font-size: 1.2rem;
    font-weight: bold;
    height: 2rem;
    text-transform: uppercase;
}

.rules-text {
    font-size: 0.9rem;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 0.8rem; /* Slightly reduced gap for mobile */
    width: 100%; /* Ensure board takes full width of container */
    max-width: 300px; /* Limit board size on larger screens */
    margin: 0 auto; /* Center the board */
}

.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 8px 0 var(--shadow-color);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.cell::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: bold;
}

.cell:hover {
    background-color: #2c4a58;
}

.cell.x, .cell.o {
    font-size: 4rem;
    font-weight: bold;
}

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

/* Style for the oldest piece, about to be removed */
.cell.oldest {
    opacity: 0.5;
    transition: opacity 0.3s ease-in-out;
}

/* Animation for the piece actively being removed */
.cell.shrinking::before {
    animation: shrink 0.4s ease-in-out forwards;
}

@keyframes shrink {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
}

footer {
    margin-top: 2rem;
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

#reset-button, .back-to-hub, .secondary-button, #close-rules-button {
    display: inline-block;
    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);
}

#reset-button, .back-to-hub {
    background: var(--cell-color);
    color: var(--text-color);
}

.secondary-button, #close-rules-button {
    background: var(--text-color);
    color: var(--bg-color);
    box-shadow: 0 4px 0 #6b7f8a;
}

#reset-button:hover, .back-to-hub:hover {
    background-color: #2c4a58;
}

.secondary-button:hover, #close-rules-button:hover {
    background-color: #dbe8ef;
}

/* --- Modal Styles --- */
.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(--o-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(--o-color);
    margin-right: 0.5rem;
    font-weight: bold;
}

/* 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(--o-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 (max-width: 480px) {
    header h1 {
        font-size: 2rem;
    }

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

    .rules-text {
        font-size: 0.8rem;
    }

    .board {
        gap: 0.5rem;
        max-width: 270px; /* Smaller board for very small screens */
    }

    .cell::before {
        font-size: 3rem; /* Smaller X/O for smaller cells */
    }

    #reset-button, .back-to-hub, .secondary-button, #close-rules-button, #play-again-button {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

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