/* CSS Custom Properties for Safe Areas */
:root {
    --sat: env(safe-area-inset-top);
    --sar: env(safe-area-inset-right);
    --sab: env(safe-area-inset-bottom);
    --sal: env(safe-area-inset-left);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    height: 100vh;
    overflow: hidden;
    font-family: 'Arial', sans-serif;
    font-weight: bold;
    background: linear-gradient(180deg, #1a0033 0%, #2d0a4e 50%, #000000 100%);
    color: white;
    touch-action: manipulation;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--sat, 0) var(--sar, 0) var(--sab, 0) var(--sal, 0);
}

/* Mobile HUD */
#mobile-hud {
    position: absolute;
    top: calc(var(--sat, 0px) + 10px);
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 20;
    height: 50px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    padding: 0 15px;
    backdrop-filter: blur(8px);
}

.hud-button {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(138, 43, 226, 0.8);
    color: white;
    font-size: 18px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.hud-button:active {
    background: rgba(138, 43, 226, 1);
    transform: scale(0.95);
}

#score-display {
    font-size: 16px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

#lives-display {
    font-size: 18px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

/* Wave Banner */
.slide-banner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(45deg, #ff6600, #ffaa00);
    color: white;
    padding: 20px 40px;
    border-radius: 15px;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    box-shadow: 0 8px 20px rgba(255, 102, 0, 0.4);
    z-index: 30;
    display: none;
    animation: slideInOut 2s ease-in-out;
}

@keyframes slideInOut {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    20%, 80% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
}

/* Game Canvas */
#gameCanvas {
    border: 2px solid rgba(138, 43, 226, 0.8);
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(138, 43, 226, 0.4);
    background: linear-gradient(180deg, #2a0845 0%, #000000 100%);
    touch-action: none;
}

/* Touch Controls */
#touch-controls {
    position: absolute;
    bottom: calc(var(--sab, 0px) + 20px);
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 30px;
    z-index: 15;
    height: 120px;
}

/* Virtual Joystick */
#joystick-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

#joystick-base {
    position: relative;
    width: 80px;
    height: 80px;
    border: 3px solid rgba(138, 43, 226, 0.8);
    border-radius: 50%;
    background: rgba(138, 43, 226, 0.2);
    box-shadow: 
        0 0 15px rgba(138, 43, 226, 0.4),
        inset 0 0 10px rgba(138, 43, 226, 0.2);
}

#joystick-stick {
    position: absolute;
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, #8a2be2, #6a1f82);
    border: 2px solid #ffffff;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: transform 0.1s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

#joystick-label,
#fire-label,
#special-label {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.8);
    text-align: center;
    font-weight: bold;
}

/* Fire Button */
#fire-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.control-button {
    width: 80px;
    height: 80px;
    border: 3px solid #ff6600;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(255, 102, 0, 0.9), rgba(255, 102, 0, 0.6));
    color: white;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.1s ease;
    box-shadow: 
        0 0 15px rgba(255, 102, 0, 0.5),
        0 4px 8px rgba(0, 0, 0, 0.3);
}

.control-button:active {
    background: linear-gradient(135deg, rgba(255, 102, 0, 1), rgba(255, 150, 0, 0.8));
    transform: scale(0.9);
    box-shadow: 
        0 0 20px rgba(255, 102, 0, 0.8),
        0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Special Button */
#special-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.special-button {
    border-color: #ffff00;
    background: linear-gradient(135deg, rgba(255, 255, 0, 0.9), rgba(255, 255, 0, 0.6));
    box-shadow: 
        0 0 15px rgba(255, 255, 0, 0.5),
        0 4px 8px rgba(0, 0, 0, 0.3);
}

.special-button:active {
    background: linear-gradient(135deg, rgba(255, 255, 0, 1), rgba(255, 255, 100, 0.8));
    box-shadow: 
        0 0 20px rgba(255, 255, 0, 0.8),
        0 2px 4px rgba(0, 0, 0, 0.3);
}

.special-button.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.cooldown-indicator {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 0;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 0 0 50% 50%;
    transition: height 0.1s ease;
    pointer-events: none;
}

/* Health Bar */
#health-container {
    position: absolute;
    bottom: calc(var(--sab, 0px) + 150px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.4);
    padding: 8px 15px;
    border-radius: 20px;
    backdrop-filter: blur(5px);
    z-index: 10;
}

#health-bar {
    width: 200px;
    height: 12px;
    background: rgba(255, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 6px;
    overflow: hidden;
}

#health-fill {
    height: 100%;
    background: #00ff00;
    transition: width 0.3s ease, background-color 0.3s ease;
    border-radius: 4px;
}

#health-text {
    font-size: 14px;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    min-width: 30px;
    text-align: center;
}

/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
}

.menu-content {
    text-align: center;
    max-width: 350px;
    width: 100%;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(138, 43, 226, 0.5);
    border-radius: 15px;
    backdrop-filter: blur(5px);
}

#game-title {
    font-size: 36px;
    background: linear-gradient(45deg, #ff6600, #ffaa00, #ff6600);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
    animation: titleGlow 3s ease-in-out infinite;
    line-height: 1.2;
}

@keyframes titleGlow {
    0%, 100% {
        background-position: 0% 50%;
        text-shadow: 0 0 10px rgba(255, 102, 0, 0.5);
    }
    50% {
        background-position: 100% 50%;
        text-shadow: 0 0 20px rgba(255, 170, 0, 0.8);
    }
}

#subtitle {
    font-size: 14px;
    color: #8a2be2;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(138, 43, 226, 0.5);
}

/* Buttons */
.large-button {
    width: 100%;
    padding: 15px 20px;
    font-size: 18px;
    font-weight: bold;
    background: linear-gradient(135deg, #ff6600, #ff8800);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    margin: 10px 0;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 4px 8px rgba(255, 102, 0, 0.3);
    transition: all 0.2s ease;
}

.large-button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(255, 102, 0, 0.3);
}

.medium-button {
    width: 100%;
    padding: 12px 15px;
    font-size: 14px;
    font-weight: bold;
    background: linear-gradient(135deg, #8a2be2, #9932cc);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin: 5px 0;
    transition: all 0.2s ease;
}

.medium-button:active {
    transform: translateY(2px);
}

.settings-button {
    padding: 10px 20px;
    font-size: 14px;
    background: rgba(138, 43, 226, 0.3);
    color: white;
    border: 2px solid rgba(138, 43, 226, 0.5);
    border-radius: 8px;
    cursor: pointer;
    margin: 10px 0;
    transition: all 0.2s ease;
}

/* Tutorial Section */
#tutorial-section {
    margin: 20px 0;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
}

#tutorial-section h3 {
    color: #ffaa00;
    margin-bottom: 15px;
    font-size: 16px;
}

.tutorial-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 0;
    font-size: 12px;
    text-align: left;
}

.tutorial-icon {
    font-size: 16px;
    width: 30px;
    text-align: center;
}

/* Settings */
.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 15px 0;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.setting-item label {
    font-size: 14px;
    color: white;
}

.toggle-btn {
    padding: 8px 15px;
    font-size: 12px;
    font-weight: bold;
    background: rgba(255, 0, 0, 0.3);
    color: white;
    border: 2px solid rgba(255, 0, 0, 0.5);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-btn.active {
    background: rgba(0, 255, 0, 0.3);
    border-color: rgba(0, 255, 0, 0.5);
}

/* High Score */
#high-score-mobile {
    margin-top: 15px;
    font-size: 14px;
    color: #00ff00;
    text-shadow: 0 0 8px rgba(0, 255, 0, 0.5);
}

/* Responsive Design */
@media (max-height: 600px) {
    #mobile-hud {
        height: 40px;
        padding: 0 10px;
    }
    
    .hud-button {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    #score-display {
        font-size: 14px;
    }
    
    #touch-controls {
        height: 100px;
        bottom: calc(var(--sab, 0px) + 10px);
    }
    
    .control-button,
    #joystick-base {
        width: 70px;
        height: 70px;
    }
    
    #joystick-stick {
        width: 25px;
        height: 25px;
    }
    
    .control-button {
        font-size: 24px;
    }
    
    #health-container {
        bottom: calc(var(--sab, 0px) + 120px);
    }
    
    #health-bar {
        width: 160px;
        height: 10px;
    }
}

@media (max-width: 350px) {
    #touch-controls {
        padding: 0 20px;
    }
    
    .control-button,
    #joystick-base {
        width: 60px;
        height: 60px;
    }
    
    #joystick-stick {
        width: 20px;
        height: 20px;
    }
    
    .control-button {
        font-size: 20px;
    }
    
    #game-title {
        font-size: 28px;
    }
    
    .menu-content {
        padding: 15px;
    }
}

/* Landscape Mode */
@media (orientation: landscape) and (max-height: 500px) {
    #game-container {
        flex-direction: row;
    }
    
    #touch-controls {
        position: fixed;
        bottom: 20px;
        height: 80px;
    }
    
    #mobile-hud {
        top: 10px;
        height: 40px;
    }
    
    #health-container {
        bottom: 110px;
    }
    
    .control-button,
    #joystick-base {
        width: 60px;
        height: 60px;
    }
    
    #joystick-stick {
        width: 20px;
        height: 20px;
    }
    
    .control-button {
        font-size: 20px;
    }
}

/* PWA and iOS specific styles */
@media (display-mode: standalone) {
    body {
        padding-top: constant(safe-area-inset-top);
        padding-top: env(safe-area-inset-top);
        padding-bottom: constant(safe-area-inset-bottom);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .slide-banner,
    #game-title {
        animation: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .control-button {
        border-width: 4px;
    }
    
    #joystick-base {
        border-width: 4px;
    }
    
    .overlay {
        background: rgba(0, 0, 0, 0.95);
    }
}