* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: radial-gradient(ellipse at center, #1a1a2e 0%, #0f0f1e 50%, #000 100%);
    background-attachment: fixed;
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Press Start 2P', monospace, Arial, sans-serif;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Performance optimization */
    contain: layout style paint;
    /* Prevent text selection during gameplay */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ========== Game Container ========== */
#gameContainer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-width: 100vw;
    overflow: hidden;
}

/* ========== Canvas ========== */
#gameCanvas {
    /* Pixel-perfect rendering - browser compatibility */
    image-rendering: -webkit-optimize-contrast; /* Edge */
    image-rendering: pixelated;                 /* Modern browsers */
    -ms-interpolation-mode: nearest-neighbor;   /* IE */
    
    /* Arcade glow effect */
    box-shadow: 
        0 0 20px rgba(0, 255, 255, 0.3),
        0 0 40px rgba(255, 0, 255, 0.2),
        0 0 60px rgba(255, 255, 0, 0.1),
        0 0 100px rgba(0, 255, 255, 0.05);
    
    background: #000;
    border: 4px solid #2a2a3e;
    border-radius: 8px;
    
    /* Smooth transitions */
    transition: box-shadow 0.3s ease;
    cursor: crosshair;
    
    /* Performance optimization */
    contain: layout paint;
    
    /* Responsive: scaled via JS, but set a base */
    display: block;
    flex-shrink: 1;
}

/* Enhanced glow on hover (desktop only) */
@media (hover: hover) {
    #gameCanvas:hover {
        box-shadow: 
            0 0 30px rgba(0, 255, 255, 0.5),
            0 0 60px rgba(255, 0, 255, 0.3),
            0 0 90px rgba(255, 255, 0, 0.2),
            0 0 120px rgba(0, 255, 255, 0.1);
    }
}

#gameCanvas:focus {
    outline: none;
}

/* ========== Touch Controls ========== */
#touchControls {
    display: none; /* Hidden by default, shown via JS on touch devices */
    width: 100%;
    max-width: 480px;
    min-height: 132px;
    padding: 10px max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    justify-content: space-between;
    align-items: flex-end;
    gap: 18px;
    flex-shrink: 0;
    -webkit-touch-callout: none;
    touch-action: none;
}

#touchControls.visible {
    display: flex;
}

.touch-dpad {
    display: grid;
    grid-template-columns: repeat(3, 58px);
    grid-template-rows: repeat(3, 42px);
    gap: 4px;
    align-items: center;
    justify-items: center;
    flex: 0 0 auto;
}

.touch-action {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex: 1 1 auto;
}

#touchControls.pacman-mode .touch-action {
    display: none;
}

#touchControls.pacman-mode {
    justify-content: center;
}

.touch-btn {
    width: 58px;
    height: 58px;
    border-radius: 10px;
    border: 3px solid rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 28px;
    font-family: 'Press Start 2P', monospace, Arial, sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    transition: background 0.1s, border-color 0.1s;
}

.touch-btn-up {
    grid-column: 2;
    grid-row: 1;
}

.touch-btn-left {
    grid-column: 1;
    grid-row: 2;
}

.touch-btn-right {
    grid-column: 3;
    grid-row: 2;
}

.touch-btn-down {
    grid-column: 2;
    grid-row: 3;
}

.touch-btn:active,
.touch-btn.pressed {
    background: rgba(0, 255, 0, 0.3);
    border-color: #00ff00;
}

.touch-btn-fire {
    width: min(128px, 28vw);
    height: 86px;
    font-size: 11px;
    letter-spacing: 1px;
    border-radius: 14px;
    border-color: rgba(255, 100, 100, 0.6);
    background: rgba(255, 50, 50, 0.15);
}

.touch-btn-fire:active,
.touch-btn-fire.pressed {
    background: rgba(255, 50, 50, 0.4);
    border-color: #ff4444;
}

/* ========== Mobile responsive ========== */
@media (max-width: 768px) {
    #gameCanvas {
        /* Reduce glow on mobile for performance */
        box-shadow: 
            0 0 10px rgba(0, 255, 255, 0.2),
            0 0 20px rgba(255, 0, 255, 0.1);
        border-width: 2px;
    }
}

/* Small phones */
@media (max-width: 400px) {
    #touchControls {
        min-height: 116px;
        gap: 10px;
        padding-top: 8px;
    }
    .touch-dpad {
        grid-template-columns: repeat(3, 50px);
        grid-template-rows: repeat(3, 36px);
        gap: 3px;
    }
    .touch-btn {
        width: 50px;
        height: 50px;
        font-size: 22px;
    }
    .touch-btn-fire {
        width: min(112px, 30vw);
        height: 76px;
        font-size: 10px;
    }
}

/* Landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
    #touchControls {
        min-height: 86px;
        padding-top: 4px;
        padding-bottom: max(4px, env(safe-area-inset-bottom));
    }
    .touch-dpad {
        grid-template-columns: repeat(3, 42px);
        grid-template-rows: repeat(3, 26px);
        gap: 2px;
    }
    .touch-btn {
        width: 42px;
        height: 42px;
        font-size: 20px;
    }
    .touch-btn-fire {
        width: min(104px, 24vw);
        height: 58px;
        font-size: 9px;
    }
}

/* Loading animation */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}
