* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    background: #0a0a0f;
    font-family: 'Press Start 2P', monospace;
    height: 100%;
    width: 100%;
    overflow: hidden;
    color: #fff;
    position: fixed;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#game-container {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center, #1a1a2e 0%, #0a0a0f 100%);
    overflow: hidden;
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none;
}

/* Loading Screen */
#loading-screen,
#start-screen,
#game-over-screen {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(10, 10, 15, 0.95);
    z-index: 10;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.loading-content,
.start-content,
.gameover-content {
    text-align: center;
    padding: 1.5rem;
    max-width: 100%;
    max-height: 100%;
    overflow-y: auto;
}

.title-glow {
    font-size: clamp(0.8rem, 4vw, 1.5rem);
    color: #4ade80;
    text-shadow: 0 0 10px #22c55e,
                 0 0 20px #16a34a,
                 0 0 40px #15803d;
    margin-bottom: 1rem;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.subtitle {
    font-size: 0.5rem;
    color: #a78bfa;
    margin-bottom: 1.5rem;
    letter-spacing: 2px;
}

#loading-status {
    font-size: 0.45rem;
    color: #fbbf24;
    margin-bottom: 0.8rem;
}

.progress-bar {
    width: min(200px, 80vw);
    height: 14px;
    background: #2d2d2d;
    border: 3px solid #5a4a3a;
    margin: 0 auto 0.5rem;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4ade80, #22c55e);
    transition: width 0.3s;
}

#loading-percent {
    font-size: 0.5rem;
    color: #4ade80;
}

/* Start Screen */
.sprite-preview {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin: 1rem 0;
    flex-wrap: wrap;
}

.sprite-preview canvas {
    image-rendering: pixelated;
    border: 2px solid #5a4a3a;
    background: #1a1a1a;
    width: 40px;
    height: 40px;
}

.arcade-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.6rem;
    padding: 0.8rem 1.5rem;
    background: linear-gradient(180deg, #4ade80 0%, #22c55e 50%, #16a34a 100%);
    border: none;
    color: #fff;
    cursor: pointer;
    margin: 0.4rem;
    text-shadow: 2px 2px 0 #0d4a20;
    box-shadow: 0 4px 0 #15803d,
                0 0 20px rgba(74, 222, 128, 0.3);
    transition: all 0.1s;
    touch-action: manipulation;
}

.arcade-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #15803d,
                0 0 30px rgba(74, 222, 128, 0.5);
}

.arcade-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #15803d;
}

.arcade-btn.small {
    font-size: 0.45rem;
    padding: 0.5rem 0.8rem;
}

.controls-info {
    margin: 1rem 0;
    font-size: 0.4rem;
    color: #888;
    line-height: 1.8;
}

.controls-info .mobile-hint {
    color: #4ade80;
    margin-top: 0.4rem;
}

.difficulty-select {
    margin: 0.8rem 0;
    font-size: 0.4rem;
    color: #fbbf24;
}

.diff-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.35rem;
    padding: 0.4rem 0.6rem;
    background: #2d2d2d;
    border: 2px solid #5a4a3a;
    color: #888;
    cursor: pointer;
    margin: 0.15rem;
    transition: all 0.2s;
    touch-action: manipulation;
}

.diff-btn:hover {
    border-color: #4ade80;
    color: #4ade80;
}

.diff-btn.active {
    background: #4ade80;
    color: #0a0a0f;
    border-color: #22c55e;
}

/* Game Over */
.gameover-title {
    font-size: clamp(1rem, 5vw, 2rem);
    color: #ef4444;
    text-shadow: 0 0 10px #dc2626,
                 0 0 20px #b91c1c;
    margin-bottom: 1rem;
    animation: flash 0.5s ease-in-out infinite alternate;
}

@keyframes flash {
    from { opacity: 0.7; }
    to { opacity: 1; }
}

#final-score {
    font-size: 0.8rem;
    color: #fbbf24;
    margin-bottom: 0.8rem;
}

#high-score-msg {
    font-size: 0.6rem;
    color: #4ade80;
    animation: rainbow 1s linear infinite;
    margin-bottom: 0.8rem;
}

@keyframes rainbow {
    0% { color: #ef4444; }
    33% { color: #4ade80; }
    66% { color: #60a5fa; }
    100% { color: #ef4444; }
}

/* Touch Controls - hidden by default, shown on desktop only */
#touch-controls {
    position: absolute;
    bottom: calc(10px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 5;
}

.touch-zone {
    width: 70px;
    height: 55px;
    background: rgba(74, 222, 128, 0.15);
    border: 3px solid rgba(74, 222, 128, 0.4);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.6);
    user-select: none;
    touch-action: manipulation;
}

.touch-zone:active {
    background: rgba(74, 222, 128, 0.4);
}

#touch-fire {
    width: 90px;
    font-size: 0.5rem;
    background: rgba(251, 191, 36, 0.15);
    border-color: rgba(251, 191, 36, 0.4);
}

#touch-fire:active {
    background: rgba(251, 191, 36, 0.4);
}

/* Settings */
#settings-toggle {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top));
    right: calc(10px + env(safe-area-inset-right));
    font-size: 1.3rem;
    cursor: pointer;
    z-index: 20;
    opacity: 0.5;
    transition: opacity 0.3s;
}

#settings-toggle:hover {
    opacity: 1;
}

#settings-panel {
    position: fixed;
    top: calc(45px + env(safe-area-inset-top));
    right: calc(10px + env(safe-area-inset-right));
    background: rgba(20, 20, 25, 0.95);
    border: 3px solid #5a4a3a;
    padding: 0.8rem;
    z-index: 20;
    font-size: 0.45rem;
}

#settings-panel label {
    display: block;
    margin: 0.4rem 0;
    cursor: pointer;
}

#settings-panel input {
    margin-right: 0.4rem;
}

/* Gallery */
#gallery-modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 15, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.gallery-content {
    text-align: center;
    padding: 1.5rem;
}

.gallery-title {
    font-size: 0.8rem;
    color: #4ade80;
    margin-bottom: 1rem;
}

#gallery-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.gallery-item {
    text-align: center;
}

.gallery-item canvas {
    display: block;
    image-rendering: pixelated;
    border: 3px solid #5a4a3a;
    background: #1a1a1a;
    margin-bottom: 0.4rem;
    width: 56px;
    height: 56px;
}

.gallery-item span {
    font-size: 0.35rem;
    color: #888;
}

/* Footer */
footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 0.5rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    font-size: 0.4rem;
    color: #444;
    background: linear-gradient(transparent, rgba(10, 10, 15, 0.9));
    z-index: 5;
    pointer-events: none;
}

footer a {
    color: #4ade80;
    text-decoration: none;
    pointer-events: auto;
}

footer a:hover {
    text-shadow: 0 0 10px #22c55e;
}

/* Hidden */
.hidden {
    display: none !important;
}

/* Mobile adjustments */
@media (max-width: 500px) {
    .touch-zone {
        width: 60px;
        height: 48px;
    }
    
    #touch-fire {
        width: 70px;
    }
    
    .arcade-btn {
        padding: 0.7rem 1.2rem;
        font-size: 0.55rem;
    }
    
    /* Hide desktop control hints on mobile */
    .controls-info p:not(.mobile-hint) {
        display: none;
    }
    
    .controls-info .mobile-hint {
        display: block;
    }
    
    .title-glow {
        font-size: clamp(0.7rem, 5vw, 1.2rem);
    }
}

/* Desktop - show keyboard hints, hide mobile hint */
@media (min-width: 501px) {
    .controls-info .mobile-hint {
        display: none;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .loading-content,
    .start-content,
    .gameover-content {
        padding: 0.8rem;
    }
    
    .title-glow {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    .subtitle {
        margin-bottom: 0.8rem;
    }
    
    .sprite-preview {
        margin: 0.5rem 0;
    }
    
    .sprite-preview canvas {
        width: 32px;
        height: 32px;
    }
    
    .controls-info {
        margin: 0.5rem 0;
    }
    
    .difficulty-select {
        margin: 0.5rem 0;
    }
    
    footer {
        display: none;
    }
}