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

body {
    font-family: Arial, sans-serif;
    background: linear-gradient(135deg, #0f172a, #1e293b, #312e81, #1e293b);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: white;
    overflow: hidden;
}

@keyframes gradientShift {
    0% {
        background-position: 0 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0 50%;
    }
}

#game-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 20px;
    max-width: 600px;
    width: 100%;
}

#loading-screen {
    position: fixed;
    inset: 0;
    background: #0f172a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.5s;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader {
    width: 80px;
    height: 80px;
    border: 4px solid rgba(74, 222, 128, 0.2);
    border-top-color: #4ade80;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    color: #4ade80;
    font-size: 18px;
    font-weight: bold;
    letter-spacing: 2px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

#header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 500px;
    gap: 10px;
}

.score-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(30, 41, 59, 0.5);
    backdrop-filter: blur(10px);
    padding: 10px 16px;
    border-radius: 8px;
    border: 2px solid rgba(255, 193, 7, 0.3);
}

.score-box.highscore {
    border-color: rgba(168, 85, 247, 0.3);
}

.score-icon {
    font-size: 20px;
}

.score-value {
    font-size: 18px;
    font-weight: bold;
    color: #fbbf24;
}

.highscore .score-value {
    color: #a855f7;
}

#canvas-container {
    position: relative;
}

#game-canvas {
    border: 4px solid #4ade80;
    border-radius: 10px;
    box-shadow: 0 0 30px rgba(74, 222, 128, 0.5);
    background: #1a1a1a;
    display: block;
}

#score-increase {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 48px;
    font-weight: bold;
    color: #4ade80;
    text-shadow: 0 0 20px #4ade80;
    pointer-events: none;
    opacity: 0;
    transition: all 0.6s ease-out;
    z-index: 50;
}

#score-increase.show {
    animation: scorePopAnimation 0.6s ease-out;
}

@keyframes scorePopAnimation {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(0.5);
    }

    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -60%) scale(1);
    }
}

#game-over {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
}

#game-over.show {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

#game-over h1 {
    color: #ef4444;
    font-size: 48px;
    margin-bottom: 20px;
    text-shadow: 0 0 30px #ef4444;
    animation: pulse 1.5s ease-in-out infinite;
}

#final-score {
    color: #4ade80;
    font-size: 24px;
    margin-bottom: 10px;
}

#new-highscore {
    color: #fbbf24;
    font-size: 18px;
    margin-bottom: 20px;
    display: none;
}

#new-highscore.show {
    display: block;
    animation: bounce 1s ease-in-out infinite;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

#restart-btn {
    background: #4ade80;
    color: #0f172a;
    border: none;
    padding: 15px 30px;
    font-size: 16px;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 20px rgba(74, 222, 128, 0.4);
}

#restart-btn:hover {
    background: #22c55e;
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(74, 222, 128, 0.6);
}

#restart-btn:active {
    transform: scale(0.95);
}

#mobile-controls {
    display: none;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 200px;
    margin-top: 10px;
}

@media (max-width: 768px) {
    #mobile-controls {
        display: grid;
    }

    #game-canvas {
        max-width: 100%;
        height: auto;
    }
}

.control-btn {
    background: rgba(74, 222, 128, 0.2);
    border: 2px solid #4ade80;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:active {
    background: rgba(74, 222, 128, 0.4);
    transform: scale(0.95);
}

.control-btn svg {
    width: 24px;
    height: 24px;
    stroke: #4ade80;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.control-btn.empty {
    background: transparent;
    border: none;
    cursor: default;
}

#instructions {
    text-align: center;
    color: #94a3b8;
    font-size: 14px;
}

.desktop-only {
    display: block;
}

.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none;
    }

    .mobile-only {
        display: block;
    }
}