/* Google Fonts Import */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P:wght@400;700;900&display=swap');

/* Keyframes for animations */
@keyframes titleGlow {
    0%, 100% {
        text-shadow: 
            0 0 3px #4a90e2,
            0 0 6px #4a90e2;
    }
    50% {
        text-shadow: 
            0 0 5px #4a90e2,
            0 0 10px #4a90e2,
            0 0 15px #4a90e2;
    }
}

@keyframes borderGlow {
    0%, 100% {
        box-shadow: 
            0 0 5px #4a90e2,
            0 0 10px #4a90e2,
            0 0 15px #4a90e2,
            inset 0 0 20px rgba(74, 144, 226, 0.1);
    }
    50% {
        box-shadow: 
            0 0 10px #4a90e2,
            0 0 20px #4a90e2,
            0 0 30px #4a90e2,
            inset 0 0 30px rgba(74, 144, 226, 0.2);
    }
}

@keyframes buttonGlow {
    0%, 100% {
        box-shadow: 
            0 0 5px #4a90e2,
            0 0 10px #4a90e2,
            inset 0 0 10px rgba(74, 144, 226, 0.1);
    }
    50% {
        box-shadow: 
            0 0 10px #4a90e2,
            0 0 20px #4a90e2,
            0 0 30px #4a90e2,
            inset 0 0 20px rgba(74, 144, 226, 0.2);
    }
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: linear-gradient(135deg, #1a3a5f, #2d5a8a, #4a90e2, #6ba3e8);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overscroll-behavior-y: contain;
    touch-action: manipulation;
    font-family: 'Press Start 2P', monospace;
    color: white;
    overflow-x: hidden;
}

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

/* Menu Screen */
#menuScreen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    background: radial-gradient(circle at center, rgba(26, 58, 95, 0.8), rgba(10, 20, 40, 0.95));
    padding: 20px;
    box-sizing: border-box;
    position: relative;
}

#menuScreen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 20%, rgba(74, 144, 226, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(107, 163, 232, 0.1) 0%, transparent 50%);
    pointer-events: none;
}

#menuScreen h1 {
    font-size: clamp(1.5rem, 6vw, 2.5rem);
    margin-bottom: 2rem;
    color: #4a90e2;
    text-align: center;
    font-weight: 900;
    letter-spacing: 0.1em;
    animation: titleGlow 3s ease-in-out infinite;
    position: relative;
    z-index: 1;
    text-shadow: 2px 2px 0px #1a3a5f;
}

#menuScreen h1::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    background: linear-gradient(45deg, #4a90e2, #6ba3e8, #4a90e2);
    border-radius: 10px;
    z-index: -1;
    opacity: 0.3;
    filter: blur(20px);
}

#levelButtons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
    max-width: 90vw;
    width: 100%;
    position: relative;
    z-index: 1;
}

.levelButton {
    padding: 1rem 0.5rem;
    font-size: clamp(0.7rem, 3vw, 1rem);
    background: linear-gradient(135deg, rgba(26, 58, 95, 0.9), rgba(45, 90, 138, 0.9));
    color: white;
    border: 3px solid #4a90e2;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    position: relative;
    overflow: hidden;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-shadow: 1px 1px 0px #1a3a5f;
    box-shadow: 3px 3px 0px #1a3a5f;
}

.levelButton::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #4a90e2, #6ba3e8, #4a90e2);
    border-radius: 10px;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
    animation: buttonGlow 2s ease-in-out infinite;
}

.levelButton:hover::before,
.levelButton:active::before {
    opacity: 1;
}

.levelButton:hover, .levelButton:active {
    background: linear-gradient(135deg, rgba(74, 144, 226, 0.3), rgba(107, 163, 232, 0.3));
    color: #4a90e2;
    transform: scale(1.02) translateY(-1px);
    box-shadow: 
        2px 2px 0px #1a3a5f,
        0 5px 10px rgba(74, 144, 226, 0.3);
}

.levelButton:disabled {
    background: linear-gradient(135deg, rgba(102, 102, 102, 0.5), rgba(51, 51, 51, 0.5));
    border-color: rgba(102, 102, 102, 0.5);
    color: #999;
    cursor: not-allowed;
    transform: none;
    box-shadow: 1px 1px 0px #333;
}

.levelButton:disabled::before {
    opacity: 0;
}

/* Perfect completion styling */
.levelButton.perfect-completed {
    border-color: #FFD700;
    box-shadow: 0 0 10px #FFD700;
    position: relative;
}

.levelButton.perfect-completed::before {
    background: linear-gradient(45deg, #FFD700, #FFA500, #FFD700);
    opacity: 0.3;
}

.levelButton.perfect-completed:hover {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 165, 0, 0.2));
    color: #FFD700;
    box-shadow: 
        0 10px 20px rgba(255, 215, 0, 0.3),
        0 0 30px rgba(255, 215, 0, 0.2);
}

.levelButton.perfect-completed:disabled {
    border-color: #FFD700;
    box-shadow: 0 0 5px #FFD700;
    background: linear-gradient(135deg, rgba(102, 102, 102, 0.5), rgba(51, 51, 51, 0.5));
    color: #999;
}

#aboutButton {
    padding: 1rem 2rem;
    font-size: clamp(0.8rem, 3vw, 1rem);
    background: linear-gradient(135deg, rgba(26, 58, 95, 0.9), rgba(45, 90, 138, 0.9));
    color: white;
    border: 3px solid #4a90e2;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-shadow: 1px 1px 0px #1a3a5f;
    box-shadow: 3px 3px 0px #1a3a5f;
}

#aboutButton::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #4a90e2, #6ba3e8, #4a90e2);
    border-radius: 10px;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#aboutButton:hover::before,
#aboutButton:active::before {
    opacity: 1;
}

#aboutButton:hover, #aboutButton:active {
    background: linear-gradient(135deg, rgba(74, 144, 226, 0.3), rgba(107, 163, 232, 0.3));
    color: #4a90e2;
    transform: scale(1.02) translateY(-1px);
    box-shadow: 
        2px 2px 0px #1a3a5f,
        0 5px 10px rgba(74, 144, 226, 0.3);
}

/* Game Over Screen */
#gameOverScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at center, rgba(10, 20, 40, 0.9), rgba(26, 58, 95, 0.95));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    box-sizing: border-box;
    backdrop-filter: blur(10px);
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

#gameOverScreen.show {
    opacity: 1;
    transform: scale(1);
}

/* Stats Panel */
#levelStats {
    background: linear-gradient(135deg, rgba(74, 144, 226, 0.1), rgba(107, 163, 232, 0.1));
    border: 3px solid #4a90e2;
    border-radius: 8px;
    padding: 1.5rem;
    margin: 1.5rem 0;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    box-shadow: 
        3px 3px 0px #1a3a5f,
        0 0 20px rgba(74, 144, 226, 0.2);
}

#levelStats::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #4a90e2, #6ba3e8, #4a90e2);
    border-radius: 10px;
    z-index: -1;
    opacity: 0.3;
    animation: borderGlow 3s ease-in-out infinite;
}

#levelStats p {
    margin: 0.5rem 0;
    font-size: clamp(0.8rem, 2.5vw, 1rem);
    color: #4a90e2;
    text-shadow: 1px 1px 0px #1a3a5f;
    font-weight: 600;
    letter-spacing: 0.05em;
}

/* Special styling for bonus counter */
#bonusesUsed {
    background: linear-gradient(135deg, #8B4513, #A0522D, #CD853F);
    border: 2px solid #654321;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 0.8rem 0;
    color: #F5DEB3;
    text-shadow: 1px 1px 0px #654321;
    font-weight: 700;
    letter-spacing: 0.05em;
    box-shadow: 2px 2px 0px #654321;
}

/* Perfect Score Badge */
#perfectBadge {
    color: #FFD700 !important;
    text-shadow: 0 0 10px #FFD700, 0 0 20px #FFD700 !important;
    font-weight: 700 !important;
    font-size: clamp(1rem, 4vw, 1.3rem) !important;
    animation: titleGlow 2s ease-in-out infinite;
}

/* Perfect Score Stats Highlight */
#levelStats.perfect {
    border-color: #FFD700;
    box-shadow: 
        0 0 30px rgba(255, 215, 0, 0.4),
        0 0 60px rgba(255, 215, 0, 0.2);
}

#levelStats.perfect::before {
    background: linear-gradient(45deg, #FFD700, #FFA500, #FFD700);
    opacity: 0.5;
    animation: borderGlow 2s ease-in-out infinite;
}

/* Game Over Buttons Container */
#gameOverButtons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

/* Updated button styling for game over screen */
#gameOverButtons button {
    padding: 1rem 2rem;
    font-size: clamp(0.8rem, 3vw, 1rem);
    border: 3px solid #4a90e2;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    font-weight: 700;
    letter-spacing: 0.05em;
    background: linear-gradient(135deg, rgba(26, 58, 95, 0.9), rgba(45, 90, 138, 0.9));
    color: white;
    text-shadow: 1px 1px 0px #1a3a5f;
    box-shadow: 3px 3px 0px #1a3a5f;
}

#gameOverButtons button::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #4a90e2, #6ba3e8, #4a90e2);
    border-radius: 10px;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#gameOverButtons button:hover::before,
#gameOverButtons button:active::before {
    opacity: 1;
}

#gameOverButtons button:hover, 
#gameOverButtons button:active {
    background: linear-gradient(135deg, rgba(74, 144, 226, 0.3), rgba(107, 163, 232, 0.3));
    color: #4a90e2;
    transform: scale(1.02) translateY(-1px);
    box-shadow: 
        2px 2px 0px #1a3a5f,
        0 5px 10px rgba(74, 144, 226, 0.3);
}

/* Next Level button special styling */
#nextLevel {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 165, 0, 0.2)) !important;
    color: #FFD700 !important;
}

#nextLevel::before {
    background: linear-gradient(45deg, #FFD700, #FFA500, #FFD700) !important;
}

#nextLevel:hover, 
#nextLevel:active {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.3), rgba(255, 165, 0, 0.3)) !important;
    color: #FFD700 !important;
    box-shadow: 
        0 10px 20px rgba(255, 215, 0, 0.3),
        0 0 30px rgba(255, 215, 0, 0.2) !important;
}

#gameOverScreen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 30% 30%, rgba(74, 144, 226, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 70% 70%, rgba(107, 163, 232, 0.1) 0%, transparent 50%);
    pointer-events: none;
}

#gameOverScreen h2 {
    font-size: clamp(1.2rem, 5vw, 2rem);
    color: #4a90e2;
    margin-bottom: 2rem;
    text-shadow: 
        2px 2px 0px #1a3a5f,
        0 0 10px #4a90e2;
    text-align: center;
    font-weight: 900;
    letter-spacing: 0.1em;
    position: relative;
    z-index: 1;
}

#returnToMenu, #retryLevel {
    padding: 1rem 2rem;
    font-size: clamp(1rem, 4vw, 1.2rem);
    border: 2px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0.5rem;
    position: relative;
    overflow: hidden;
    font-weight: 700;
    letter-spacing: 0.05em;
}

#returnToMenu, #retryLevel {
    background: linear-gradient(135deg, rgba(0, 255, 0, 0.2), rgba(0, 255, 204, 0.2));
    color: #00ff00;
}

#returnToMenu::before, #retryLevel::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #00ff00, #00ffcc, #00ff00);
    border-radius: 14px;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#returnToMenu:hover::before, #retryLevel:hover::before,
#returnToMenu:active::before, #retryLevel:active::before {
    opacity: 1;
}

#returnToMenu:hover, #returnToMenu:active {
    background: linear-gradient(135deg, rgba(0, 255, 0, 0.3), rgba(0, 255, 204, 0.3));
    color: #00ff00;
    transform: scale(1.05) translateY(-2px);
    box-shadow: 
        0 10px 20px rgba(0, 255, 0, 0.3),
        0 0 30px rgba(0, 255, 0, 0.2);
}

#retryLevel {
    background: linear-gradient(135deg, rgba(255, 102, 0, 0.2), rgba(255, 68, 0, 0.2));
    color: #ff6600;
}

#retryLevel:hover, #retryLevel:active {
    background: linear-gradient(135deg, rgba(255, 102, 0, 0.3), rgba(255, 68, 0, 0.3));
    color: #ff6600;
    box-shadow: 
        0 10px 20px rgba(255, 102, 0, 0.3),
        0 0 30px rgba(255, 102, 0, 0.2);
}

#retryLevel::before {
    background: linear-gradient(45deg, #ff6600, #ff4400, #ff6600);
}

/* Game Wrapper */
#gameWrapper {
    position: relative;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100vw;
    height: calc(100dvh - 100px);
    overflow: hidden;
    background: radial-gradient(circle at center, rgba(26, 26, 46, 0.8), rgba(10, 10, 10, 0.95));
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

#gameWrapper.show {
    opacity: 1;
    transform: scale(1);
}

#gameCanvas {
    width: auto;
    height: 100%;
    max-height: 100%;
    max-width: 100%;
    aspect-ratio: 3 / 4;
    image-rendering: pixelated;
    border: 3px solid #4a90e2;
    border-radius: 8px;
    background: 
        linear-gradient(45deg, #4a90e2, #6ba3e8, #4a90e2) border-box;
    box-shadow: 
        3px 3px 0px #1a3a5f,
        0 0 20px rgba(74, 144, 226, 0.5),
        0 0 40px rgba(74, 144, 226, 0.3),
        inset 0 0 30px rgba(74, 144, 226, 0.1);
    animation: borderGlow 4s ease-in-out infinite;
    position: relative;
}

#gameCanvas::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    background: linear-gradient(45deg, #4a90e2, #6ba3e8, #4a90e2);
    border-radius: 11px;
    z-index: -1;
    opacity: 0.5;
    filter: blur(10px);
}

#touchControlArea {
    position: fixed;
    bottom: 0;
    width: 100vw;
    height: 100px;
    background: transparent;
    z-index: 10;
}

/* Perfect completion legend */
#perfectLegend {
    text-align: center;
    margin-top: 10px;
    font-size: 12px;
    color: #FFD700;
    font-weight: bold;
    text-shadow: 0 0 5px #FFD700;
    letter-spacing: 0.05em;
}

/* Mobile-specific improvements */
@media (max-width: 768px) {
    #menuScreen {
        padding: 10px;
        justify-content: space-around;
    }
    
    #levelButtons {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        max-width: 95vw;
    }
    
    .levelButton {
        padding: 0.8rem 0.3rem;
        min-height: 45px;
        font-size: 0.9rem;
        /* Improve touch targets */
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Perfect completion styling for mobile */
    .levelButton.perfect-completed {
        box-shadow: 0 0 8px #FFD700;
    }
    
    .levelButton.perfect-completed:active {
        transform: scale(0.95);
        box-shadow: 0 0 12px #FFD700;
    }
    
    #aboutButton {
        padding: 0.8rem 1.5rem;
        min-height: 45px;
        font-size: 1rem;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    #gameOverScreen h2 {
        margin-bottom: 1.5rem;
    }
    
    #levelStats {
        padding: 1rem;
        margin: 1rem 0;
    }
    
    #levelStats p {
        font-size: clamp(0.8rem, 2.5vw, 1rem);
        margin: 0.3rem 0;
    }
    
    #gameOverButtons button {
        padding: 0.8rem 1.5rem;
        min-height: 45px;
        font-size: 1rem;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Perfect legend for mobile */
    #perfectLegend {
        font-size: 11px;
        margin-top: 8px;
    }
}

@media (max-width: 480px) {
    #levelButtons {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.4rem;
    }
    
    .levelButton {
        padding: 0.6rem 0.2rem;
        min-height: 40px;
        font-size: 0.8rem;
    }
    
    #menuScreen h1 {
        margin-bottom: 1.5rem;
    }
}

 