* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Courier New', monospace;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a0a2e 50%, #0a0a0a 100%);
    color: #0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    text-shadow: 0 0 10px #0f0, 0 0 20px #0f0;
    overflow: hidden;
    transition: all 0.5s ease;
    --primary: #0f0;
    --secondary: #0ff;
    --accent: #0f0;
}

body[data-difficulty="easy"] {
    --primary: #0f0;
    --secondary: #0ff;
    --accent: #0f0;
    background: linear-gradient(135deg, #0a0a0a 0%, #0a1a0a 50%, #0a0a0a 100%);
    color: #0f0;
    text-shadow: 0 0 10px #0f0, 0 0 20px #0f0;
}

body[data-difficulty="medium"] {
    --primary: #ff0;
    --secondary: #f90;
    --accent: #ff0;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a0a 50%, #0a0a0a 100%);
    color: #ff0;
    text-shadow: 0 0 10px #ff0, 0 0 20px #ff0;
}

body[data-difficulty="hard"] {
    --primary: #f00;
    --secondary: #f0f;
    --accent: #f00;
    background: linear-gradient(135deg, #0a0a0a 0%, #2a0a0a 50%, #0a0a0a 100%);
    color: #f00;
    text-shadow: 0 0 10px #f00, 0 0 20px #f00;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        linear-gradient(90deg, transparent 49%, rgba(255, 255, 255, 0.03) 50%, transparent 51%),
        linear-gradient(0deg, transparent 49%, rgba(255, 255, 255, 0.03) 50%, transparent 51%);
    background-size: 50px 50px;
    pointer-events: none;
    z-index: -1;
}

.container {
    text-align: center;
    padding: 30px;
    background: rgba(10, 10, 30, 0.9);
    border-radius: 20px;
    position: relative;
    z-index: 1;
}

.container::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    background: conic-gradient(from 0deg, #0ff, #f0f, #ff0, #0f0, #0ff);
    border-radius: 22px;
    z-index: -2;
    animation: rotateBorder 3s linear infinite;
}

.container::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    right: 3px;
    bottom: 3px;
    background: rgba(10, 10, 30, 0.95);
    border-radius: 17px;
    z-index: -1;
}

@keyframes rotateBorder {
    0% { filter: hue-rotate(0deg); }
    100% { filter: hue-rotate(360deg); }
}

h1 {
    font-size: 3em;
    margin-bottom: 20px;
    letter-spacing: 8px;
    background: linear-gradient(90deg, #0ff, #f0f, #0ff);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 3s linear infinite;
}

/* Beat animations for different difficulty tempos */
@keyframes beatPulseEasy {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

@keyframes beatPulseMedium {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes beatPulseHard {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}

body.music-playing h1 {
    animation: shimmer 3s linear infinite, beatPulseEasy 0.75s ease-in-out infinite;
}

body.music-playing[data-difficulty="medium"] h1 {
    animation: shimmer 3s linear infinite, beatPulseMedium 0.545s ease-in-out infinite;
}

body.music-playing[data-difficulty="hard"] h1 {
    animation: shimmer 3s linear infinite, beatPulseHard 0.428s ease-in-out infinite;
}

@keyframes shimmer {
    0% { background-position: 0% center; }
    100% { background-position: 200% center; }
}

.difficulty-selector {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    font-size: 1em;
}

.diff-btn {
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    padding: 8px 16px;
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
}

.diff-btn:hover {
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--primary);
}

.diff-btn.active {
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    color: #000;
    border-color: transparent;
    box-shadow: 0 0 20px var(--primary);
    text-shadow: none;
}

.scoreboard {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
    padding: 15px;
    border: 2px solid var(--primary);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.5);
    transition: border-color 0.5s ease;
}

.score {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.score-label {
    font-size: 0.9em;
    opacity: 0.8;
}

.score-value {
    font-size: 2em;
    font-weight: bold;
    text-shadow: 0 0 10px currentColor;
}

.game-info {
    margin-bottom: 20px;
}

#status {
    font-size: 1.5em;
    min-height: 30px;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 120px);
    grid-template-rows: repeat(3, 120px);
    gap: 10px;
    margin: 20px auto;
    padding: 20px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid var(--primary);
    border-radius: 15px;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
    transition: border-color 0.5s ease;
}

.cell {
    background: rgba(20, 20, 40, 0.8);
    border: 2px solid var(--primary);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.cell::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(0, 255, 255, 0.1), transparent);
    transform: rotate(45deg);
    transition: all 0.5s;
    opacity: 0;
}

.cell:hover {
    background: rgba(30, 30, 60, 0.9);
    border-color: var(--primary);
    box-shadow: 0 0 20px var(--primary), inset 0 0 20px rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

.cell:hover::before {
    opacity: 1;
    animation: shine 0.5s ease-out;
}

@keyframes shine {
    0% { left: -50%; }
    100% { left: 150%; }
}

.cell.x {
    color: #0ff;
    text-shadow: 0 0 10px #0ff, 0 0 20px #0ff, 0 0 30px #0ff;
    animation: popIn 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.cell.o {
    color: #f0f;
    text-shadow: 0 0 10px #f0f, 0 0 20px #f0f, 0 0 30px #f0f;
    animation: popIn 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes popIn {
    0% { transform: scale(0) rotate(-180deg); opacity: 0; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.cell.winning {
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    color: #000;
    text-shadow: none;
    animation: winPulse 0.5s ease-in-out infinite, popIn 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    border-color: #fff;
}

@keyframes winPulse {
    0%, 100% { 
        box-shadow: 0 0 20px var(--primary), 0 0 40px var(--secondary);
        transform: scale(1);
    }
    50% { 
        box-shadow: 0 0 40px var(--primary), 0 0 60px var(--secondary);
        transform: scale(1.1);
    }
}

#restart {
    font-family: 'Courier New', monospace;
    font-size: 1.2em;
    padding: 15px 40px;
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
    border-radius: 30px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 3px;
    transition: all 0.3s;
    margin-top: 20px;
    position: relative;
    overflow: hidden;
}

#restart::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    transition: left 0.5s;
    opacity: 0.4;
}

#restart:hover {
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    color: #000;
    box-shadow: 0 0 30px var(--primary), 0 0 60px var(--secondary);
    text-shadow: none;
    transform: translateY(-2px);
}

#restart:hover::before {
    left: 100%;
}

#restart:active {
    transform: scale(0.95) translateY(0);
}

#music-toggle {
    font-family: 'Courier New', monospace;
    font-size: 1em;
    padding: 10px 20px;
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
    border-radius: 20px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: all 0.3s;
    margin-top: 10px;
    margin-left: 10px;
}

#music-toggle:hover {
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    color: #000;
    box-shadow: 0 0 20px var(--primary);
    text-shadow: none;
}

/* Rainbow win state */
@keyframes rainbowBorder {
    0% { filter: hue-rotate(0deg); }
    100% { filter: hue-rotate(360deg); }
}

@keyframes rainbowGlow {
    0% { 
        border-color: #ff0000;
        box-shadow: 0 0 20px #ff0000;
    }
    17% { 
        border-color: #ff8800;
        box-shadow: 0 0 20px #ff8800;
    }
    33% { 
        border-color: #ffff00;
        box-shadow: 0 0 20px #ffff00;
    }
    50% { 
        border-color: #00ff00;
        box-shadow: 0 0 20px #00ff00;
    }
    67% { 
        border-color: #0088ff;
        box-shadow: 0 0 20px #0088ff;
    }
    83% { 
        border-color: #ff00ff;
        box-shadow: 0 0 20px #ff00ff;
    }
    100% { 
        border-color: #ff0000;
        box-shadow: 0 0 20px #ff0000;
    }
}

body.player-won {
    animation: rainbowBorder 1s linear infinite;
}

body.player-won .container::before {
    background: conic-gradient(from 0deg, #ff0000, #ff8800, #ffff00, #00ff00, #0088ff, #ff00ff, #ff0000);
    animation: rotateBorder 0.5s linear infinite;
}

body.player-won .board {
    animation: rainbowGlow 1s linear infinite;
}

body.player-won .scoreboard {
    animation: rainbowGlow 1s linear infinite;
}

body.player-won .cell {
    animation: rainbowGlow 1s linear infinite;
}

body.player-won h1 {
    background: linear-gradient(90deg, #ff0000, #ff8800, #ffff00, #00ff00, #0088ff, #ff00ff, #ff0000);
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    animation: shimmer 0.5s linear infinite;
}

body.player-won #restart,
body.player-won #music-toggle,
body.player-won .diff-btn {
    animation: rainbowGlow 1s linear infinite;
}

/* Lose animation - pieces fall off screen */
@keyframes fallOff {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

body.player-lost .cell {
    animation: fallOff 1.5s ease-in forwards;
}

body.player-lost .cell:nth-child(1) { animation-delay: 0.1s; }
body.player-lost .cell:nth-child(2) { animation-delay: 0.2s; }
body.player-lost .cell:nth-child(3) { animation-delay: 0.05s; }
body.player-lost .cell:nth-child(4) { animation-delay: 0.25s; }
body.player-lost .cell:nth-child(5) { animation-delay: 0.15s; }
body.player-lost .cell:nth-child(6) { animation-delay: 0.3s; }
body.player-lost .cell:nth-child(7) { animation-delay: 0s; }
body.player-lost .cell:nth-child(8) { animation-delay: 0.35s; }
body.player-lost .cell:nth-child(9) { animation-delay: 0.2s; }
