* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #0a0a0f;
    background-image:
            radial-gradient(circle at 20% 50%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
            radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.3) 0%, transparent 50%),
            radial-gradient(circle at 40% 80%, rgba(120, 219, 255, 0.3) 0%, transparent 50%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    user-select: none;
    overflow: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="%23ffffff" opacity="0.02"/><circle cx="75" cy="75" r="1" fill="%23ffffff" opacity="0.02"/><circle cx="50" cy="10" r="1" fill="%23ffffff" opacity="0.01"/><circle cx="10" cy="90" r="1" fill="%23ffffff" opacity="0.02"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
    pointer-events: none;
    z-index: -1;
}

.game-container {
    text-align: center;
    padding: 30px;
    background: rgba(15, 15, 25, 0.8);
    border-radius: 24px;
    backdrop-filter: blur(20px);
    box-shadow:
            0 0 60px rgba(120, 119, 198, 0.2),
            inset 0 1px 0 rgba(255, 255, 255, 0.1),
            0 20px 40px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

.game-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg,
    rgba(120, 119, 198, 0.1) 0%,
    rgba(255, 119, 198, 0.05) 50%,
    rgba(120, 219, 255, 0.1) 100%);
    border-radius: 24px;
    z-index: -1;
}

.header {
    margin-bottom: 25px;
}

.header h1 {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 15px;
    background: linear-gradient(135deg, #00f5ff, #ff00ff, #00ff88);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 3s ease-in-out infinite;
    text-shadow: 0 0 30px rgba(0, 245, 255, 0.3);
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.score {
    font-size: 1.4rem;
    font-weight: 600;
    color: #00f5ff;
    text-shadow: 0 0 20px rgba(0, 245, 255, 0.5);
    padding: 8px 16px;
    background: rgba(0, 245, 255, 0.1);
    border: 1px solid rgba(0, 245, 255, 0.3);
    border-radius: 12px;
    display: inline-block;
}

.game-board-container {
    position: relative;
    display: inline-block;
    margin: 20px 0;
}

#gameCanvas {
    background: #0f0f19;
    border: 2px solid rgba(120, 119, 198, 0.3);
    border-radius: 16px;
    box-shadow:
            0 0 40px rgba(120, 119, 198, 0.2),
            inset 0 0 40px rgba(0, 0, 0, 0.5);
    max-width: 100%;
    height: auto;
    position: relative;
}

#gameCanvas::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #00f5ff, #ff00ff, #00ff88, #00f5ff);
    background-size: 300% 300%;
    border-radius: 18px;
    z-index: -1;
    animation: borderGlow 2s ease-in-out infinite;
    opacity: 0.6;
}

@keyframes borderGlow {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(5, 5, 15, 0.95);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    display: none;
    backdrop-filter: blur(15px);
    border: 2px solid rgba(255, 0, 100, 0.3);
    box-shadow:
            0 0 60px rgba(255, 0, 100, 0.3),
            0 20px 40px rgba(0, 0, 0, 0.5);
}

.game-over h2 {
    color: #ff0066;
    margin-bottom: 20px;
    font-size: 2.2rem;
    font-weight: 700;
    text-shadow: 0 0 30px rgba(255, 0, 100, 0.5);
    animation: pulseRed 1s ease-in-out infinite;
}

@keyframes pulseRed {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.05); }
}

.game-over p {
    margin-bottom: 25px;
    font-size: 1.3rem;
    color: rgba(255, 255, 255, 0.9);
}

#restartBtn {
    background: linear-gradient(135deg, #00f5ff, #0099ff);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow:
            0 0 30px rgba(0, 245, 255, 0.3),
            0 8px 25px rgba(0, 153, 255, 0.2);
    position: relative;
    overflow: hidden;
}

#restartBtn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

#restartBtn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow:
            0 0 40px rgba(0, 245, 255, 0.5),
            0 12px 35px rgba(0, 153, 255, 0.3);
}

#restartBtn:hover::before {
    left: 100%;
}

.controls {
    margin-top: 20px;
}

.instructions {
    margin-bottom: 15px;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
}

.mobile-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.control-row {
    display: flex;
    gap: 10px;
}

.control-btn {
    width: 55px;
    height: 55px;
    background: rgba(15, 15, 25, 0.8);
    border: 2px solid rgba(0, 245, 255, 0.3);
    border-radius: 14px;
    color: #00f5ff;
    font-size: 1.4rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    touch-action: manipulation;
    position: relative;
    overflow: hidden;
}

.control-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: radial-gradient(circle, rgba(0, 245, 255, 0.3), transparent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s, height 0.3s;
}

.control-btn:hover,
.control-btn:active {
    background: rgba(0, 245, 255, 0.1);
    border-color: rgba(0, 245, 255, 0.6);
    transform: scale(0.95);
    box-shadow: 0 0 20px rgba(0, 245, 255, 0.3);
}

.control-btn:hover::before,
.control-btn:active::before {
    width: 100px;
    height: 100px;
}

.particle-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    pointer-events: none;
}

.eat-particle {
    background: radial-gradient(circle, #00ff88, #00cc66);
    box-shadow: 0 0 10px #00ff88;
    animation: eatParticle 0.8s ease-out forwards;
}

.death-particle {
    background: radial-gradient(circle, #ff0066, #cc0044);
    box-shadow: 0 0 10px #ff0066;
    animation: deathParticle 1.2s ease-out forwards;
}

@keyframes eatParticle {
    0% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: scale(0) rotate(360deg) translateY(-50px);
    }
}

@keyframes deathParticle {
    0% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: scale(0.5) rotate(720deg) translateY(-80px);
    }
}


@media (max-width: 480px) {
    .game-container {
        padding: 15px;
        margin: 10px;
    }

    .header h1 {
        font-size: 2rem;
    }

    #gameCanvas {
        width: 300px;
        height: 300px;
    }

    .mobile-controls {
        display: flex;
    }

    .control-btn {
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
    }
}

@media (min-width: 481px) {
    .mobile-controls {
        display: none;
    }
}