:root {
    --primary: #667eea;
    --secondary: #764ba2;
    --accent: #f093fb;
    --success: #4facfe;
    --danger: #fa7478;
    --warning: #feca57;
    --dark: #2d3748;
    --light: #f7fafc;
    --neon-blue: #00f2fe;
    --neon-pink: #ff006e;
    --neon-green: #8ac926;
    --gradient-main: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-neon: linear-gradient(45deg, #ff006e, #8338ec, #3a86ff);
    --card-shadow: 0 25px 50px rgba(102, 126, 234, 0.4);
}

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

body {
    font-family: 'Poppins', sans-serif;
    background: #0f0f23;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow-x: hidden;
    position: relative;
}

/* Animated Background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 80%, rgba(255, 0, 110, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(79, 172, 254, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(131, 56, 236, 0.1) 0%, transparent 50%);
    animation: backgroundShift 12s ease-in-out infinite;
    z-index: -2;
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    animation: patternMove 20s linear infinite;
    z-index: -1;
}

@keyframes backgroundShift {
    0%, 100% { 
        background: 
            radial-gradient(circle at 20% 80%, rgba(255, 0, 110, 0.15) 0%, transparent 50%),
            radial-gradient(circle at 80% 20%, rgba(79, 172, 254, 0.15) 0%, transparent 50%),
            radial-gradient(circle at 40% 40%, rgba(131, 56, 236, 0.1) 0%, transparent 50%);
    }
    33% {
        background: 
            radial-gradient(circle at 60% 20%, rgba(138, 201, 38, 0.15) 0%, transparent 50%),
            radial-gradient(circle at 20% 60%, rgba(255, 0, 110, 0.15) 0%, transparent 50%),
            radial-gradient(circle at 80% 80%, rgba(79, 172, 254, 0.1) 0%, transparent 50%);
    }
    66% {
        background: 
            radial-gradient(circle at 80% 60%, rgba(131, 56, 236, 0.15) 0%, transparent 50%),
            radial-gradient(circle at 40% 20%, rgba(138, 201, 38, 0.15) 0%, transparent 50%),
            radial-gradient(circle at 20% 40%, rgba(255, 0, 110, 0.1) 0%, transparent 50%);
    }
}

@keyframes patternMove {
    0% { transform: translate(0, 0); }
    100% { transform: translate(60px, 60px); }
}

/* Preloader */
.preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, #0f0f23 0%, #1a1a2e 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: all 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.preloader.hidden {
    opacity: 0;
    visibility: hidden;
    transform: scale(1.1);
}

.loader {
    position: relative;
    width: 150px;
    height: 150px;
}

.loader-ring {
    position: absolute;
    border: 4px solid transparent;
    border-radius: 50%;
    animation: spin 2s linear infinite;
}

.loader-ring:nth-child(1) {
    width: 150px;
    height: 150px;
    border-top: 4px solid var(--neon-pink);
    animation-delay: 0s;
}

.loader-ring:nth-child(2) {
    width: 120px;
    height: 120px;
    top: 15px;
    left: 15px;
    border-right: 4px solid var(--neon-blue);
    animation-delay: -0.5s;
    animation-direction: reverse;
}

.loader-ring:nth-child(3) {
    width: 90px;
    height: 90px;
    top: 30px;
    left: 30px;
    border-bottom: 4px solid var(--neon-green);
    animation-delay: -1s;
}

.loader-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Orbitron', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.preloader-text {
    margin-top: 40px;
    font-family: 'Orbitron', monospace;
    font-size: 1.8rem;
    color: white;
    font-weight: 600;
    text-align: center;
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from {
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    }
    to {
        text-shadow: 0 0 20px rgba(255, 255, 255, 0.8), 0 0 30px rgba(255, 0, 110, 0.6);
    }
}

/* Main Container */
main {
    max-width: 600px;
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(30px);
    padding: 2rem;
    border-radius: 30px;
    box-shadow: 
        var(--card-shadow),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    opacity: 0;
    transform: translateY(100px) scale(0.8);
    animation: slideInUp 1.2s cubic-bezier(0.4, 0, 0.2, 1) 0.5s forwards;
    position: relative;
    overflow: hidden;
}

main::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

@keyframes slideInUp {
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
h1 {
    font-family: 'Orbitron', monospace;
    background: var(--gradient-neon);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    text-align: center;
    font-weight: 900;
    letter-spacing: 2px;
    position: relative;
    animation: titlePulse 3s ease-in-out infinite;
}

h1::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 3px;
    background: var(--gradient-neon);
    border-radius: 2px;
    animation: lineExpand 2s ease-in-out infinite alternate;
}

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

@keyframes lineExpand {
    0% { width: 100px; }
    100% { width: 200px; }
}

/* Game Mode Selector */
.game-mode-selector {
    text-align: center;
    margin-bottom: 2rem;
    animation: fadeInDown 1s ease-out 0.8s both;
}

.game-mode-selector h2 {
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 1.5rem;
    font-size: 1.4rem;
    font-weight: 600;
    font-family: 'Orbitron', monospace;
}

.mode-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.mode-button {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.2);
    padding: 0.8rem 2rem;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    font-family: 'Orbitron', monospace;
}

.mode-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: var(--gradient-neon);
    transition: left 0.4s ease;
    z-index: -1;
}

.mode-button:hover::before {
    left: 0;
}

.mode-button:hover {
    color: white;
    border-color: transparent;
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 10px 25px rgba(255, 0, 110, 0.4);
}

.mode-button.active {
    background: var(--gradient-neon);
    color: white;
    border-color: transparent;
    box-shadow: 0 8px 20px rgba(255, 0, 110, 0.5);
    animation: activeButton 2s ease-in-out infinite;
}

@keyframes activeButton {
    0%, 100% { box-shadow: 0 8px 20px rgba(255, 0, 110, 0.5); }
    50% { box-shadow: 0 12px 30px rgba(255, 0, 110, 0.8); }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Game Board */
table {
    margin: 1rem auto;
    border-collapse: separate;
    border-spacing: 12px;
    background: transparent;
    animation: fadeIn 1s ease-out 1s both;
}

.square {
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 25px;
    cursor: pointer;
    position: relative;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    backdrop-filter: blur(10px);
}

.square::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--gradient-neon);
    opacity: 0;
    transition: all 0.4s ease;
    border-radius: 23px;
}

.square:hover::before {
    opacity: 0.2;
}

.square:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 
        0 15px 35px rgba(255, 0, 110, 0.3),
        0 0 20px rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.4);
}

.square input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 3;margin-top: -40px;
}

.square span {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    font-weight: 900;
    z-index: 2;
    font-family: 'Orbitron', monospace;
}

.square[data-check="X"] {
    background: rgba(250, 116, 120, 0.2);
    border-color: var(--danger);
}

.square[data-check="X"] span::after {
    content: "✕";
    color: var(--danger);
    animation: 
        bounceInRotate 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55),
        xGlow 2s ease-in-out infinite alternate;
    text-shadow: 0 0 15px rgba(250, 116, 120, 0.8);
}

.square[data-check="O"] {
    background: rgba(79, 172, 254, 0.2);
    border-color: var(--success);
}

.square[data-check="O"] span::after {
    content: "⭕";
    color: var(--success);
    animation: 
        bounceInScale 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55),
        oGlow 2s ease-in-out infinite alternate;
    text-shadow: 0 0 15px rgba(79, 172, 254, 0.8);
}

@keyframes bounceInRotate {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.3) rotate(-90deg);
        opacity: 0.8;
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

@keyframes bounceInScale {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.4);
        opacity: 0.8;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes xGlow {
    0% { text-shadow: 0 0 15px rgba(250, 116, 120, 0.8); }
    100% { text-shadow: 0 0 25px rgba(250, 116, 120, 1), 0 0 35px rgba(250, 116, 120, 0.6); }
}

@keyframes oGlow {
    0% { text-shadow: 0 0 15px rgba(79, 172, 254, 0.8); }
    100% { text-shadow: 0 0 25px rgba(79, 172, 254, 1), 0 0 35px rgba(79, 172, 254, 0.6); }
}

.winning-cell {
    animation: winCelebration 1.5s ease-in-out infinite;
    z-index: 10;
}

@keyframes winCelebration {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 15px 35px rgba(255, 0, 110, 0.3);
    }
    25% {
        transform: scale(1.1) rotate(2deg);
        box-shadow: 0 20px 40px rgba(138, 201, 38, 0.5);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 25px 50px rgba(255, 0, 110, 0.7);
    }
    75% {
        transform: scale(1.1) rotate(-2deg);
        box-shadow: 0 20px 40px rgba(79, 172, 254, 0.5);
    }
}

/* Game Status */
.messages {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 1rem;
    margin: 1rem 0;
    text-align: center;
    backdrop-filter: blur(20px);
    position: relative;
    overflow: hidden;
}

.messages::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--gradient-neon);
    animation: progressBar 3s ease-in-out infinite;
}

@keyframes progressBar {
    0%, 100% { width: 100%; }
    50% { width: 20%; }
}

.messages p {
    color: white;
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    font-family: 'Orbitron', monospace;
    animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% {
        transform: scale(1);
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    }
    50% {
        transform: scale(1.05);
        text-shadow: 0 0 20px rgba(255, 255, 255, 0.8);
    }
}

/* Reset Button */
button[type="reset"] {
    width: 100%;
    background: var(--gradient-neon);
    color: white;
    padding: 1.2rem 2rem;
    border: none;
    border-radius: 20px;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    font-family: 'Orbitron', monospace;
    text-transform: uppercase;
    letter-spacing: 1px;
}

button[type="reset"]::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.6s ease;
}

button[type="reset"]:hover::before {
    left: 100%;
}

button[type="reset"]:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 
        0 15px 35px rgba(255, 0, 110, 0.5),
        0 0 30px rgba(255, 255, 255, 0.3);
}

button[type="reset"]:active {
    transform: translateY(-1px) scale(0.98);
}

/* Special Effects */
.firework {
    position: fixed;
    border-radius: 50%;
    animation: fireworkExplosion 2s ease-out;
    pointer-events: none;
    z-index: 1000;
}

@keyframes fireworkExplosion {
    0% {
        transform: scale(0) rotate(0deg);
        opacity: 1;
    }
    50% {
        transform: scale(2) rotate(180deg);
        opacity: 0.8;
    }
    100% {
        transform: scale(6) rotate(360deg);
        opacity: 0;
    }
}

.win-celebration {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
}

.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    pointer-events: none;
    z-index: 1001;
    animation: confettiFall 3s linear infinite;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-10vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(110vh) rotate(720deg);
        opacity: 0;
    }
}

/* Floating Particles */
.particle {
    position: fixed;
    pointer-events: none;
    z-index: 998;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    animation: floatUp 4s linear infinite;
}

@keyframes floatUp {
    0% {
        transform: translateY(100vh) rotate(0deg) scale(0);
        opacity: 0;
    }
    10% {
        opacity: 1;
        transform: translateY(90vh) rotate(36deg) scale(1);
    }
    90% {
        opacity: 1;
        transform: translateY(10vh) rotate(324deg) scale(1);
    }
    100% {
        transform: translateY(-10px) rotate(360deg) scale(0);
        opacity: 0;
    }
}

/* Sound Control */
.sound-control {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.sound-control:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.sound-control.muted {
    opacity: 0.5;
}

/* Responsive Design */
@media (max-width: 600px) {
    main {
        padding: 2rem;
        margin: 0.5rem;
    }
    
    .square {
        width: 80px;
        height: 80px;
    }
    
    .square span {
        font-size: 3rem;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    table {
        border-spacing: 8px;
    }

    .mode-buttons {
        flex-direction: column;
        align-items: center;
    }

    .mode-button {
        width: 200px;
    }
}

/* Accessibility */
.visually-hidden {
    position: absolute !important;
    clip: rect(1px 1px 1px 1px);
    clip: rect(1px, 1px, 1px, 1px);
    padding: 0 !important;
    border: 0 !important;
    height: 1px !important;
    width: 1px !important;
    overflow: hidden;
}

.square input[type="checkbox"]:focus + span {
    outline: 3px solid var(--accent);
    outline-offset: 4px;
    border-radius: 15px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}