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

body {
    font-family: 'Orbitron', monospace;
    background: #1a1a1a;
    color: #fff;
    overflow: hidden;
}

#gameContainer {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#gameCanvas {
    border: 2px solid #444;
    background: #2a2a2a;
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.3);
}

#ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

#stats {
    position: absolute;
    top: 20px;
    left: 20px;
    font-size: 18px;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

#stats div {
    margin-bottom: 10px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid #00ff00;
    border-radius: 5px;
    backdrop-filter: blur(5px);
}

#zombieCount {
    color: #00ff00;
    font-size: 20px;
}

#score {
    color: #ffff00;
}

#distance {
    color: #00ffff;
}

#gameOver, #tutorial {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    border: 2px solid #ff0000;
    border-radius: 10px;
    padding: 30px;
    text-align: center;
    backdrop-filter: blur(10px);
    pointer-events: auto;
    box-shadow: 0 0 30px rgba(255, 0, 0, 0.5);
}

#tutorial {
    border-color: #00ff00;
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.5);
}

#tutorial h2, #gameOver h2 {
    font-size: 32px;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

#tutorial h2 {
    color: #00ff00;
}

#gameOver h2 {
    color: #ff0000;
}

#instructions {
    text-align: left;
    margin-bottom: 20px;
    line-height: 1.6;
}

#instructions p {
    margin-bottom: 8px;
}

#instructions strong {
    color: #00ff00;
}

#gameControls {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

#gameControls button {
    flex: 1;
    min-width: 120px;
}

#audioToggle {
    background: linear-gradient(45deg, #4444ff, #0000cc);
    font-size: 14px;
}

#audioToggle:hover {
    background: linear-gradient(45deg, #0000cc, #000088);
}

#newHighScore {
    color: #ffff00;
    font-weight: 900;
    font-size: 20px;
    text-shadow: 2px 2px 4px rgba(255, 255, 0, 0.5);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Mobile Controls */
.mobile-only {
    display: none;
}

#mobileControls {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 1000;
    pointer-events: none;
}

#dpad {
    position: relative;
    width: 140px;
    height: 140px;
    pointer-events: auto;
    touch-action: none; /* Prevent scrolling when touching D-pad */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* D-pad structure */
.dpad-horizontal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 140px;
    height: 46px;
    background: rgba(20, 20, 20, 0.8);
    border-radius: 23px;
    border: 2px solid rgba(0, 255, 0, 0.6);
    backdrop-filter: blur(5px);
}

.dpad-vertical {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 140px;
    background: rgba(20, 20, 20, 0.8);
    border-radius: 23px;
    border: 2px solid rgba(0, 255, 0, 0.6);
    backdrop-filter: blur(5px);
}

.dpad-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    background: rgba(0, 255, 0, 0.3);
    border-radius: 16px;
    border: 2px solid rgba(0, 255, 0, 0.5);
    backdrop-filter: blur(3px);
    transition: all 0.1s ease;
}

/* Active touch indicator */
.dpad-center.active {
    background: rgba(0, 255, 0, 0.6);
    border-color: rgba(0, 255, 0, 0.8);
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.4);
}

.dpad-btn {
    width: 40px;
    height: 40px;
    background: linear-gradient(145deg, rgba(0, 255, 0, 0.8), rgba(0, 200, 0, 0.6));
    border: 2px solid rgba(0, 255, 0, 0.9);
    border-radius: 8px;
    color: #000;
    font-weight: bold;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    font-family: 'Orbitron', monospace;
    transition: all 0.15s ease;
    touch-action: manipulation;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0 2px 8px rgba(0, 255, 0, 0.2);
}

.dpad-btn:active,
.dpad-btn.pressed {
    background: linear-gradient(145deg, rgba(0, 255, 0, 1), rgba(0, 220, 0, 0.8));
    transform: scale(0.95);
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.8), inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Positioning within containers */
.dpad-horizontal .dpad-btn.left {
    margin-right: auto;
    margin-left: 4px;
}

.dpad-horizontal .dpad-btn.right {
    margin-left: auto;
    margin-right: 4px;
}

.dpad-vertical .dpad-btn.up {
    margin-bottom: auto;
    margin-top: 4px;
}

.dpad-vertical .dpad-btn.down {
    margin-top: auto;
    margin-bottom: 4px;
}

/* Enhanced pressed state for diagonal combinations */
.dpad-btn.pressed {
    background: linear-gradient(145deg, rgba(0, 255, 0, 1), rgba(0, 255, 100, 0.9)) !important;
    transform: scale(0.95) !important;
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.8), inset 0 2px 4px rgba(0, 0, 0, 0.2) !important;
}

/* Smooth transitions for better feel */
.dpad-horizontal, .dpad-vertical {
    transition: all 0.1s ease;
}

.dpad-horizontal.active {
    background: rgba(20, 20, 20, 0.9);
    border-color: rgba(0, 255, 0, 0.8);
}

.dpad-vertical.active {
    background: rgba(20, 20, 20, 0.9);
    border-color: rgba(0, 255, 0, 0.8);
}

/* Responsive adjustments */
@media (max-width: 480px) {
    #mobileControls {
        bottom: 15px;
        left: 15px;
    }
    
    #dpad {
        width: 120px;
        height: 120px;
    }
    
    .dpad-horizontal {
        width: 120px;
        height: 40px;
        border-radius: 20px;
    }
    
    .dpad-vertical {
        width: 40px;
        height: 120px;
        border-radius: 20px;
    }
    
    .dpad-center {
        width: 28px;
        height: 28px;
        border-radius: 14px;
    }
    
    .dpad-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
}

#finalStats {
    margin-bottom: 20px;
}

#finalStats p {
    margin-bottom: 8px;
    font-size: 18px;
}

button {
    font-family: 'Orbitron', monospace;
    font-size: 18px;
    font-weight: 700;
    padding: 12px 24px;
    background: linear-gradient(45deg, #00ff00, #00cc00);
    border: none;
    border-radius: 5px;
    color: #000;
    cursor: pointer;
    text-transform: uppercase;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 255, 0, 0.3);
}

button:hover {
    background: linear-gradient(45deg, #00cc00, #009900);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 255, 0, 0.4);
}

button:active {
    transform: translateY(0);
}

#restartBtn {
    background: linear-gradient(45deg, #ff4444, #cc0000);
    color: #fff;
    box-shadow: 0 4px 15px rgba(255, 0, 0, 0.3);
}

#restartBtn:hover {
    background: linear-gradient(45deg, #cc0000, #990000);
    box-shadow: 0 6px 20px rgba(255, 0, 0, 0.4);
}

.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

/* Show tutorial by default */
#tutorial {
    display: block;
}

/* Screen shake animation */
@keyframes shake {
    0%, 100% { transform: translate(0, 0); }
    10% { transform: translate(-2px, -2px); }
    20% { transform: translate(2px, -2px); }
    30% { transform: translate(-2px, 2px); }
    40% { transform: translate(2px, 2px); }
    50% { transform: translate(-2px, -2px); }
    60% { transform: translate(2px, -2px); }
    70% { transform: translate(-2px, 2px); }
    80% { transform: translate(2px, 2px); }
    90% { transform: translate(-2px, -2px); }
}

.screen-shake {
    animation: shake 0.5s ease-in-out;
}

/* Responsive design */
@media (max-width: 1250px) {
    #gameCanvas {
        width: 95vw;
        height: 60vh;
    }
}

@media (max-width: 768px) {
    body {
        overflow: hidden;
    }

    #gameContainer {
        height: 100vh;
        width: 100vw;
    }

    #gameCanvas {
        width: 100vw;
        height: 70vh;
        max-height: 70vh;
    }
    
    #stats {
        font-size: 12px;
        top: 10px;
        left: 10px;
    }
    
    #stats div {
        margin-bottom: 5px;
        padding: 5px 8px;
    }
    
    #tutorial, #gameOver {
        padding: 15px;
        max-width: 95vw;
        max-height: 80vh;
        overflow-y: auto;
    }
    
    #tutorial h2, #gameOver h2 {
        font-size: 20px;
    }
    
    #instructions {
        font-size: 14px;
    }
    
    button {
        font-size: 14px;
        padding: 8px 16px;
    }

    #gameControls {
        flex-direction: column;
        gap: 10px;
    }

    #gameControls button {
        width: 100%;
        min-width: auto;
    }
    
    /* Show mobile controls on small screens and touch devices */
    .mobile-only {
        display: block !important;
    }
    
    /* Adjust mobile controls for smaller screens */
    #mobileControls {
        bottom: 10px;
        left: 10px;
    }
    
    #dpad {
        width: 100px;
        height: 100px;
    }
    
    .dpad-btn {
        width: 30px;
        height: 30px;
        font-size: 14px;
    }
    
    .dpad-center {
        width: 25px;
        height: 25px;
    }
}

/* Landscape mobile orientation */
@media (max-width: 768px) and (orientation: landscape) {
    #gameCanvas {
        height: 85vh;
    }
    
    #stats {
        font-size: 10px;
    }
    
    #mobileControls {
        bottom: 5px;
        left: 5px;
    }
    
    #dpad {
        width: 80px;
        height: 80px;
    }
    
    .dpad-btn {
        width: 25px;
        height: 25px;
        font-size: 12px;
    }
    
    .dpad-center {
        width: 20px;
        height: 20px;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    #tutorial h2, #gameOver h2 {
        font-size: 18px;
    }
    
    #instructions {
        font-size: 12px;
    }
    
    button {
        font-size: 12px;
        padding: 6px 12px;
    }
    
    #stats {
        font-size: 10px;
    }
}