* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Arial', sans-serif;
    transition: background-color 0.3s, color 0.3s;
}

:root {
    --bg-color: #f5f5f5;
    --text-color: #333;
    --container-bg: white;
    --container-shadow: rgba(0, 0, 0, 0.1);
    --heading-color: #2c3e50;
    --cell-bg: #ecf0f1;
    --cell-hover: #d6dbdf;
    --x-color: #e74c3c;
    --o-color: #3498db;
    --button-bg: #3498db;
    --button-hover: #2980b9;
}

body {
    background-color: var(--bg-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
}

.hidden {
    display: none;
}

:root {
    --bg-color: #1a202c;
    --text-color: #e2e8f0;
    --container-bg: #2d3748;
    --container-shadow: rgba(0, 0, 0, 0.3);
    --heading-color: #90cdf4;
    --cell-bg: #4a5568;
    --cell-hover: #718096;
    --button-bg: #2b6cb0;
    --button-hover: #1e4e8c;
}

.theme-toggle, .music-toggle {
    display: none;
}

.container {
    background-color: var(--container-bg);
    border-radius: 10px;
    box-shadow: 0 4px 10px var(--container-shadow);
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    text-align: center;
    margin-top: 1rem;
}

h1 {
    margin-bottom: 2rem;
    color: var(--heading-color);
}

h2 {
    margin-bottom: 1.5rem;
    color: var(--heading-color);
}

.buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

button {
    background-color: var(--button-bg);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s;
}

button:hover {
    background-color: var(--button-hover);
}

#restart-game, #back-to-menu {
    margin-top: 1.5rem;
}

.rules {
    background-color: var(--container-bg);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.rules h2 {
    color: var(--heading-color);
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
}

.rules ul {
    text-align: left;
    padding-left: 1.5rem;
    margin: 0;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 10px;
    margin: 2rem auto;
    max-width: 300px;
}

.cell {
    background-color: var(--cell-bg);
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    border-radius: 5px;
    transition: background-color 0.2s, color 0.2s, opacity 0.5s;
}

.cell:hover {
    background-color: var(--cell-hover);
}

.cell.x {
    color: var(--x-color);
}

.cell.o {
    color: var(--o-color);
}

.cell.fading {
    opacity: 0.4;
    animation: pulse 1.5s infinite alternate;
}

@keyframes pulse {
    0% { opacity: 0.4; }
    100% { opacity: 0.7; }
}

.hidden {
    display: none;
}

/* Dark theme variables */
:root.dark-theme {
    --bg-color: #1a202c;
    --text-color: #e2e8f0;
    --container-bg: #2d3748;
    --container-shadow: rgba(0, 0, 0, 0.3);
    --heading-color: #90cdf4;
    --cell-bg: #4a5568;
    --cell-hover: #718096;
    --button-bg: #2b6cb0;
    --button-hover: #1e4e8c;
}

/* Theme toggle button - positioned outside media query for all screen sizes */
.theme-toggle, .music-toggle {
    position: absolute;
    top: 1rem;
    background-color: var(--button-bg);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.3s, transform 0.2s;
    z-index: 100;
}

.theme-toggle {
    right: 1rem;
}

.music-toggle {
    right: 4rem;
}

.theme-toggle:hover {
    background-color: var(--button-hover);
    transform: scale(1.1);
}

.theme-toggle:active {
    transform: scale(0.95);
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .container {
        padding: 1.5rem;
    }
    
    .game-board {
        grid-gap: 5px;
        max-width: 250px;
    }
    
    .cell {
        font-size: 1.5rem;
    }
    
    button {
        padding: 0.7rem 1.2rem;
    }
    
    h1 {
        margin-bottom: 1rem;
    }
}