:root {
    --board-bg: #1a1a1a;
    --cell-bg: #2d2d2d;
    --player1-color: #3498db; /* Blue */
    --player2-color: #e74c3c; /* Red */
    --text-color: #ecf0f1;
}

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

.game-container {
    width: 95%;
    max-width: 800px;
}

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

.status-text {
    font-size: 1.2rem;
    height: 2rem;
    color: #bdc3c7;
}

.game-layout {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin: 2rem 0;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
}

/* Player piece containers */
.player-pieces {
    display: flex;
    flex-direction: column;
    gap: 1rem; /* Slightly reduced gap */
    margin: 1rem; /* Add some margin */
}

.piece-container {
    cursor: pointer;
    opacity: 1;
    transition: opacity 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.piece-container.used {
    opacity: 0.3;
    cursor: not-allowed;
}

.piece-container.selected .piece {
    box-shadow: 0 0 15px yellow;
}

.piece-count {
    font-size: 1rem;
    font-weight: bold;
}

/* The board */
.board {
    display: grid;
    grid-template-columns: repeat(3, min(100px, 15vw)); /* Responsive cell size */
    grid-template-rows: repeat(3, min(100px, 15vw)); /* Responsive cell size */
    gap: 8px; /* Responsive gap */
    background-color: #111;
    padding: 8px;
    border-radius: 10px;
    margin: 0 auto; /* Center the board */
}

.cell {
    background-color: var(--cell-bg);
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative; /* For stacking pieces */
}

.cell:hover {
    background-color: #444;
}

/* Piece styling */
.piece {
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    /* font-size will be set by specific size classes */
    transition: all 0.3s ease;
    position: relative; /* Default position */
}

.cell .piece {
    position: absolute; /* For stacking inside a cell */
}

.piece.large { width: 8vw; height: 8vw; max-width: 90px; max-height: 90px; } /* Use vw for responsiveness, max-width for desktop */
.piece.medium { width: 6vw; height: 6vw; max-width: 65px; max-height: 65px; }
.piece.small { width: 4vw; height: 4vw; max-width: 40px; max-height: 40px; }

/* Player 1 (X) pieces */
.piece.player1 {
    background-color: var(--player1-color);
    border: 4px solid #2980b9;
}
.piece.player1::after { content: 'X'; }

/* Player 2 (O) pieces */
.piece.player2 {
    background-color: var(--player2-color);
    border: 4px solid #c0392b;
}
.piece.player2::after { content: 'O'; }

/* Adjust font sizes for X/O based on piece size */
.piece.large::after { font-size: 2.5rem; }
.piece.medium::after { font-size: 1.8rem; }
.piece.small::after { font-size: 1rem; }


.cell.win-cell {
    background-color: #27ae60; /* A green color for winning */
    box-shadow: 0 0 20px #27ae60;
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

/* Footer buttons */
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.3s;
}

#reset-button, .back-to-hub {
    background: #333;
    color: white;
}

.secondary-button, #close-rules-button {
    background: #4f6d7a;
    color: white;
}


#reset-button:hover, .back-to-hub:hover {
    background: #555;
}

.secondary-button:hover, #close-rules-button:hover {
    background: #5a7e8e;
}

/* --- 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: #2c3e50;
    padding: 2rem 3rem;
    border-radius: 15px;
    text-align: left;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    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: #f1c40f;
}

.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(--player1-color);
    margin-right: 0.5rem;
    font-weight: bold;
}

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

#victory-message {
    font-size: 3rem;
    margin: 0 0 1.5rem 0;
    color: #f1c40f;
}

#play-again-button {
    padding: 0.8rem 2rem;
    font-size: 1.2rem;
    cursor: pointer;
    border: none;
    border-radius: 8px;
    background-color: #f1c40f;
    color: #2c3e50;
    font-weight: bold;
    transition: background-color 0.3s;
}

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

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

.confetti {
    position: absolute;
    width: 10px;
    height: 20px;
    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: 768px) {
    .game-layout {
        flex-direction: column; /* Stack player pieces and board vertically */
        gap: 1rem; /* Add some gap between sections */
    }

    .player-pieces {
        flex-direction: row; /* Arrange pieces horizontally for mobile */
        justify-content: space-around; /* Distribute pieces more evenly */
        width: 90%; /* Slightly less than 100% to allow padding */
        margin: 0.5rem auto; /* Center and reduce vertical margin */
        padding: 0.5rem;
        border-radius: 10px;
        background-color: rgba(0, 0, 0, 0.2); /* Subtle background for player pieces */
    }

    .piece-container {
        flex-direction: column; /* Stack piece and count vertically */
        align-items: center;
        gap: 0.2rem; /* Reduced gap */
    }

    .piece-count {
        font-size: 0.8rem; /* Smaller count text */
    }

    header h1 {
        font-size: 2rem;
    }

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

    .board {
        gap: 5px;
        grid-template-columns: repeat(3, min(90px, 25vw)); /* Slightly larger cells */
        grid-template-rows: repeat(3, min(90px, 25vw));
        max-width: 300px; /* Adjust max-width slightly */
    }

    .piece {
        font-size: 1.5rem; /* Adjusted piece text size */
    }

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

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