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

html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
    /* iOS safe area support */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

body {
    font-family: 'Comic Sans MS', 'Marker Felt', 'Chalkboard', cursive;
    background: linear-gradient(135deg, #f5f5dc 0%, #fff8dc 50%, #f5f5dc 100%);
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    -webkit-overflow-scrolling: touch;
    touch-action: none;
    /* Prevent iOS bounce/scroll */
    -webkit-user-select: none;
    user-select: none;
}

.game-container {
    position: relative;
    background: transparent;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    width: 100%;
    max-width: 1200px;
    height: 100%;
    max-height: 600px;
    margin: 0 auto;
}

#gameCanvas {
    display: block;
    background: transparent;
    width: 100%;
    height: 100%;
    touch-action: none;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

@media (max-width: 768px) {
    html {
        padding: 0;
    }
    
    body {
        padding: 0;
        display: flex;
        align-items: stretch;
    }
    
    .game-container {
        border-radius: 0;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
        max-height: 100vh;
        max-height: 100dvh;
        max-width: 100%;
        width: 100vw;
        width: 100dvw; /* Dynamic viewport width */
    }
    
    #gameCanvas {
        width: 100%;
        height: 100%;
    }
}

.ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.score-display {
    position: absolute;
    top: max(10px, env(safe-area-inset-top, 0px));
    left: max(10px, env(safe-area-inset-left, 0px));
    color: #333;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
    pointer-events: none;
    z-index: 10;
    background: rgba(255, 255, 255, 0.7);
    padding: 8px 12px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

.score-display > div {
    margin-bottom: 8px;
}

#powerupStatus {
    margin-top: 10px;
}

.powerup-indicators {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.powerup-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.8);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 14px;
}

.powerup-icon {
    font-size: 16px;
}

.powerup-timer-bar {
    width: 60px;
    height: 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
    overflow: hidden;
}

.powerup-timer-fill {
    height: 100%;
    background: #667eea;
    transition: width 0.1s linear;
}

@media (max-width: 768px) {
    .score-display {
        top: max(5px, env(safe-area-inset-top, 0px));
        left: max(5px, env(safe-area-inset-left, 0px));
        font-size: 12px;
        padding: 6px 10px;
        background: rgba(255, 255, 255, 0.85);
    }
    
    .score-display > div {
        margin-bottom: 3px;
        line-height: 1.3;
    }
}

.start-screen,
.game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    pointer-events: all;
    border: 3px solid #333;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 100;
}

.start-screen h1 {
    font-size: 48px;
    margin-bottom: 20px;
    color: #333;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.start-screen p {
    font-size: 20px;
    margin: 10px 0;
    color: #666;
}

#planeSelection {
    margin-top: 20px;
    max-height: 40vh;
    overflow-y: auto;
    pointer-events: all;
}

.plane-selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-top: 15px;
}

.plane-card {
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #333;
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
    pointer-events: all;
    user-select: none;
}

.plane-card:hover:not(.locked) {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.plane-card.selected {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

.plane-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(200, 200, 200, 0.5);
}

.plane-name {
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 8px;
    color: #333;
}

.plane-stats {
    font-size: 12px;
    color: #666;
}

.plane-stats > div {
    margin: 4px 0;
}

.start-instruction {
    font-size: 24px !important;
    font-weight: bold !important;
    color: #667eea !important;
}

.controls {
    font-size: 16px !important;
    color: #888 !important;
    margin-top: 20px !important;
}

@media (max-width: 768px) {
    .start-screen,
    .game-over {
        padding: 20px 15px !important;
        max-width: 85vw;
        width: auto;
        margin: 0 10px;
        max-height: 80vh;
    }
    
    .start-screen h1 {
        font-size: 28px;
        margin-bottom: 12px;
    }
    
    .start-screen p {
        font-size: 14px;
        margin: 8px 0;
    }
    
    .start-instruction {
        font-size: 18px !important;
    }
    
    .controls {
        font-size: 12px !important;
        margin-top: 12px !important;
    }
    
    .game-over h2 {
        font-size: 24px;
        margin-bottom: 12px;
    }
    
    .game-over p {
        font-size: 16px;
        margin: 8px 0;
    }
}

.game-over {
    display: none;
}

.game-over h2 {
    font-size: 36px;
    margin-bottom: 20px;
    color: #d32f2f;
}

.game-over p {
    font-size: 20px;
    margin: 10px 0;
    color: #333;
}

#restartBtn {
    margin-top: 20px;
    padding: 12px 30px;
    font-size: 18px;
    font-family: inherit;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px; /* iOS minimum touch target */
}

@media (max-width: 768px) {
    #restartBtn {
        padding: 10px 24px;
        font-size: 16px;
        min-height: 44px;
        width: 100%;
        max-width: 200px;
    }
}

.mobile-controls {
    position: absolute;
    bottom: max(20px, env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    display: none;
    z-index: 20;
    pointer-events: all;
    width: 100%;
    justify-content: center;
    align-items: center;
    padding: 0 20px;
}

@media (max-width: 768px) {
    .mobile-controls {
        display: flex;
        bottom: max(15px, env(safe-area-inset-bottom, 0px));
    }
}

.control-btn {
    width: 70px;
    height: 70px;
    min-width: 70px;
    min-height: 70px;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.9);
    border: 3px solid rgba(255, 255, 255, 0.5);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.1s ease;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
}

@media (max-width: 480px) {
    .control-btn {
        width: 60px;
        height: 60px;
        min-width: 60px;
        min-height: 60px;
    }
    
    .control-btn svg {
        width: 20px;
        height: 20px;
    }
}

.control-btn:active {
    transform: scale(0.9);
    background: rgba(102, 126, 234, 1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.control-btn svg {
    pointer-events: none;
}

/* Prevent text selection on mobile */
* {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

button, .control-btn {
    -webkit-user-select: none;
    user-select: none;
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    .game-container {
        /* Fix for iOS Safari viewport issues */
        min-height: -webkit-fill-available;
    }
    
    @media (max-width: 768px) {
        .game-container {
            min-height: -webkit-fill-available;
            height: -webkit-fill-available;
        }
    }
}

