@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Fredoka:wght@600;700&display=swap');

:root {
    --arcade-blue: #0a1e64;
    --arcade-ocean: #103898;
    --arcade-gold: #ffd166;
    --arcade-red: #ff3b30;
    --arcade-green: #48bb78;
    --arcade-cyan: #00f0ff;
    --panel-bg: rgba(8, 18, 48, 0.95);
    --border-color: #2b4c96;
}

/* --- RESET & VIEWPORT --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--arcade-blue);
    font-family: 'Press Start 2P', monospace;
    color: #ffffff;
    position: fixed;
}

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

/* --- MAIN 3D CANVAS --- */
#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    display: block;
    touch-action: none;
}

/* --- IN-GAME 1942 RETRO HUD (Image 1 Style) --- */
#gameHUD {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
}

.hud-score-block {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.hud-label {
    font-size: 11px;
    color: var(--arcade-gold);
    letter-spacing: 1px;
    text-shadow: 0 2px 0 #000;
}

.hud-val {
    font-size: clamp(16px, 3.5vw, 24px);
    color: #ffffff;
    letter-spacing: 2px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.9);
}

.hud-lives-block {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-lives-icons {
    font-size: 18px;
    letter-spacing: 4px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
}

.hud-btn {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: transform 0.15s;
}

.hud-btn:hover {
    transform: scale(1.1);
    border-color: var(--arcade-gold);
}

/* Floating Power-up Banner (Top pinned, unobtrusive) */
#powerupBanner {
    position: absolute;
    top: max(86px, calc(env(safe-area-inset-top) + 78px));
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    background: rgba(0, 0, 0, 0.88);
    border: 2px solid var(--arcade-gold);
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 10px;
    letter-spacing: 1px;
    color: var(--arcade-gold);
    text-shadow: 0 0 8px rgba(255, 209, 102, 0.7);
    opacity: 0;
    pointer-events: none;
    text-align: center;
    white-space: nowrap;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 16px rgba(0,0,0,0.8);
    z-index: 25;
}

#powerupBanner.visible {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* Retro Arcade Boss Health Bar (Compact Top HUD Bar) */
.boss-bar-container {
    position: absolute;
    top: max(58px, calc(env(safe-area-inset-top) + 50px));
    left: 50%;
    transform: translateX(-50%);
    width: min(250px, 75vw);
    background: rgba(8, 12, 28, 0.9);
    border: 1.5px solid #ff3b30;
    border-radius: 6px;
    padding: 3px 8px 5px 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6), 0 0 10px rgba(255, 59, 48, 0.4);
    pointer-events: none;
    animation: bossPulse 1.2s ease-in-out infinite alternate;
    z-index: 20;
}

@keyframes bossPulse {
    0% { border-color: #ff3b30; box-shadow: 0 0 8px rgba(255, 59, 48, 0.35); }
    100% { border-color: #ff8888; box-shadow: 0 0 14px rgba(255, 59, 48, 0.7); }
}

.boss-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 8px;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.boss-name-text {
    color: #ffea00;
    text-shadow: 0 0 4px rgba(255, 234, 0, 0.8);
    font-weight: bold;
    font-size: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 175px;
}

.boss-hp-val {
    color: #ffffff;
    font-size: 8px;
    text-shadow: 0 0 3px #000;
    font-family: 'Press Start 2P', monospace;
}

.boss-bar-track {
    width: 100%;
    height: 5px;
    background: rgba(30, 10, 10, 0.9);
    border: 1px solid #661111;
    border-radius: 3px;
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.8);
}

.boss-bar-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #ff3b30, #ff8800, #ffe600);
    box-shadow: 0 0 6px rgba(255, 59, 48, 0.8);
    transition: width 0.15s ease-out;
}

/* Bottom Controls & Roll Counter (Image 1 R:03) */
.hud-bottom {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    width: 100%;
}

.hud-bottom-left {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
    pointer-events: auto;
}

.hud-roll-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #e63946;
    padding: 6px 12px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

.roll-label {
    font-size: 10px;
    color: #ff9999;
}

.roll-badge {
    font-size: 13px;
    color: #ffd166;
    font-weight: bold;
    letter-spacing: 1px;
}

/* Mobile On-screen Buttons */
.mobile-controls-row {
    display: flex;
    gap: 12px;
    pointer-events: auto;
}

.retro-touch-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    padding: 12px 16px;
    border-radius: 12px;
    border: 3px solid #ffffff;
    cursor: pointer;
    box-shadow: 0 6px 0 rgba(0,0,0,0.5), 0 10px 20px rgba(0,0,0,0.4);
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.retro-touch-btn:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.5);
}

.roll-btn {
    background: linear-gradient(180deg, #ff3b30, #b71c1c);
    color: #ffffff;
    border-color: #ffb4a2;
}

.shoot-btn {
    background: linear-gradient(180deg, #ff9f1c, #d35400);
    color: #ffffff;
    border-color: #ffd166;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.shoot-btn:active, .shoot-btn.pressed {
    transform: translateY(4px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.5);
    background: linear-gradient(180deg, #ffd166, #ff9f1c);
    color: #000000;
}

/* --- RETRO ARCADE MODALS & CARDS --- */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 50;
    background: rgba(5, 12, 35, 0.88);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.arcade-card {
    background: var(--panel-bg);
    border: 4px solid var(--border-color);
    box-shadow: 0 16px 45px rgba(0, 0, 0, 0.9), inset 0 0 30px rgba(16, 56, 152, 0.4);
    border-radius: 20px;
    padding: 28px 24px;
    max-width: 580px;
    width: 100%;
    text-align: center;
    animation: popIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-height: 92vh;
    overflow-y: auto;
}

@keyframes popIn {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* --- IMAGE 2 RETRO PLANE GAME MENU STYLES --- */
.menu-sky-bg {
    background: #4a9be0 url('../assets/menu_bg.png') center bottom / cover no-repeat !important;
    backdrop-filter: none !important;
    position: relative;
    overflow: hidden;
}

/* Fluffy Pixel Cloud bank disabled as menu_bg.png already includes lush landscape and clouds */
.menu-sky-bg::before {
    display: none;
}

.plane-game-menu-card {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 660px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 24px;
    user-select: none;
    background: rgba(10, 28, 68, 0.52);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 3px solid rgba(255, 255, 255, 0.4);
    border-radius: 20px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(96, 171, 223, 0.25);
}

/* Exact Image 2 Retro Title: PLANE GAME */
.plane-game-title {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(34px, 6.5vw, 50px);
    color: #e58a26;
    letter-spacing: 3px;
    text-shadow: 
        -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000,
        0 4px 0 #000, 3px 4px 0 #000, -3px 4px 0 #000,
        0 6px 0 #000, 4px 6px 0 #000, -4px 6px 0 #000;
    margin-bottom: 32px;
    text-align: center;
}

.plane-game-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 16px;
}

/* Vertical Menu Options */
.plane-menu-options {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: flex-start;
    flex: 1;
    padding-left: 24px;
}

.plane-menu-btn {
    background: none;
    border: none;
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(14px, 2.8vw, 19px);
    color: #e58a26;
    text-shadow: 
        -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000,
        0 3px 0 #000, 2px 3px 0 #000, -2px 3px 0 #000;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: 1px;
    transition: transform 0.12s ease, color 0.12s ease;
    padding: 6px 8px;
}

.plane-menu-btn .menu-cursor {
    color: #e58a26;
    font-size: 15px;
    visibility: hidden;
    transform: scale(1.1);
}

.plane-menu-btn:hover, .plane-menu-btn.active, .plane-menu-btn.active-mode {
    color: #ffd166;
    transform: translateX(6px);
}

.plane-menu-btn:hover .menu-cursor, .plane-menu-btn.active .menu-cursor, .plane-menu-btn.active-mode .menu-cursor {
    visibility: visible;
    color: #ffd166;
}

/* Biplane Illustration on Right */
/* Biplane Illustration & Skin Selector on Right */
.plane-menu-illustration {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.skin-selector-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.skin-selector-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.skin-arrow-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 16px;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: linear-gradient(180deg, #ffe17d 0%, #e58a26 100%);
    color: #2b1100;
    border: 3px solid #ffffff;
    box-shadow: 0 4px 0 #8b4500, 0 6px 14px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.12s ease;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.skin-arrow-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.15);
    box-shadow: 0 6px 0 #8b4500, 0 10px 18px rgba(0, 0, 0, 0.45);
}

.skin-arrow-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #8b4500;
}

.skin-plane-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 170px;
}

.menu-biplane-img {
    width: clamp(165px, 28vw, 235px);
    height: auto;
    image-rendering: pixelated;
    filter: drop-shadow(0 10px 18px rgba(10, 40, 80, 0.35));
    animation: biplaneHover 3.2s ease-in-out infinite alternate;
}

.skin-badge-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    background: rgba(10, 25, 55, 0.75);
    border: 2px solid #60abdf;
    padding: 8px 18px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35), inset 0 0 10px rgba(96, 171, 223, 0.25);
}

.skin-name-badge {
    font-family: 'Press Start 2P', monospace;
    font-size: 11px;
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
    letter-spacing: 1px;
    text-align: center;
    white-space: nowrap;
}

.skin-counter-tag {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    color: #ffd166;
    letter-spacing: 1px;
}

@keyframes biplaneHover {
    0% { transform: translateY(0) rotate(-1.5deg); }
    50% { transform: translateY(-8px) rotate(1deg); }
    100% { transform: translateY(4px) rotate(-0.5deg); }
}

/* Menu Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.arcade-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 13px;
    padding: 14px 20px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    box-shadow: 0 5px 0 rgba(0,0,0,0.5), 0 8px 15px rgba(0,0,0,0.4);
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.arcade-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.arcade-btn:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.5);
}

.arcade-btn.primary {
    background: linear-gradient(180deg, #ffb703, #fb8500);
    color: #0a1e64;
}

.arcade-btn.secondary {
    background: linear-gradient(180deg, #2b4c96, #162854);
    color: #ffffff;
    border: 2px solid var(--border-color);
}

.arcade-btn.danger {
    background: linear-gradient(180deg, #ff3b30, #c1121f);
    color: #ffffff;
}

/* Controls Guide */
.controls-guide {
    background: rgba(0, 0, 0, 0.45);
    border-radius: 12px;
    padding: 14px;
    font-family: 'Fredoka', cursive, sans-serif;
    font-size: 13px;
    color: #d1d5db;
    text-align: left;
    line-height: 1.55;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.controls-guide strong {
    color: #ffffff;
}

.guide-title {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: var(--arcade-gold);
    margin-bottom: 8px;
}

/* Game Over Stats */
.game-over-stats {
    background: rgba(0, 0, 0, 0.45);
    border-radius: 12px;
    padding: 16px 20px;
    margin: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 1px solid var(--border-color);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
}

.stat-row.highlight {
    color: var(--arcade-gold);
    font-size: 13px;
}

/* Responsive Media Queries */
@media (max-width: 600px) {
    .plane-game-menu-card {
        padding: 16px 14px;
        max-width: 95vw;
        border-radius: 16px;
    }

    .plane-game-title {
        font-size: clamp(20px, 5.5vw, 26px);
        letter-spacing: 1.5px;
        margin-bottom: 14px;
        text-shadow: 
            -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000,
            0 3px 0 #000, 2px 3px 0 #000, -2px 3px 0 #000;
    }

    .plane-game-content {
        flex-direction: column-reverse;
        gap: 14px;
        align-items: center;
    }

    .plane-menu-options {
        align-items: center;
        padding-left: 0;
        gap: 10px;
        width: 100%;
    }

    .plane-menu-btn {
        font-size: 13px;
        padding: 5px 8px;
        justify-content: center;
    }

    .menu-biplane-img {
        width: 125px;
    }

    .skin-arrow-btn {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }

    .skin-badge-container {
        padding: 6px 14px;
    }

    .skin-name-badge {
        font-size: 9px;
    }

    .skin-counter-tag {
        font-size: 8px;
    }

    .arcade-card {
        padding: 20px 16px;
    }

    .game-title {
        font-size: 28px;
    }

    .hero-plane-img {
        width: 90px;
        height: 90px;
    }

    .retro-touch-btn {
        padding: 10px 12px;
        font-size: 9px;
    }

    .arcade-btn {
        font-size: 11px;
        padding: 12px 14px;
    }
}

@media (max-height: 520px) {
    .plane-game-menu-card {
        padding: 10px 18px;
        max-height: 96vh;
    }

    .plane-game-title {
        font-size: 22px;
        margin-bottom: 8px;
    }

    .plane-game-content {
        flex-direction: row;
        gap: 12px;
    }

    .plane-menu-btn {
        font-size: 12px;
        padding: 3px 6px;
    }

    .menu-biplane-img {
        width: 95px;
    }

    .skin-arrow-btn {
        width: 32px;
        height: 32px;
    }
}

/* --- RETRO ARCADE LOADING SCREEN --- */
#loadingScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    background: radial-gradient(circle at center, #0e2a82 0%, #051036 60%, #020718 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: opacity 0.4s ease-out;
}

.loading-card {
    background: rgba(6, 16, 50, 0.94);
    border: 4px solid var(--arcade-cyan);
    border-radius: 16px;
    box-shadow: 0 0 35px rgba(0, 240, 255, 0.45), inset 0 0 20px rgba(0, 0, 0, 0.8);
    padding: clamp(24px, 5vw, 40px) clamp(20px, 4vw, 36px);
    max-width: 480px;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.loading-title {
    font-family: 'Fredoka', cursive, sans-serif;
    font-size: clamp(30px, 7.5vw, 44px);
    color: #ffffff;
    -webkit-text-stroke: 2px #0a1e64;
    text-shadow: 0 4px 0 #0055ff, 0 8px 16px rgba(0,0,0,0.8);
    letter-spacing: 2px;
    line-height: 1;
}

.loading-subtitle {
    font-size: 10px;
    color: var(--arcade-gold);
    letter-spacing: 2px;
    text-shadow: 0 2px 4px #000;
}

.loading-plane-container {
    width: 110px;
    height: 110px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin: 8px 0;
}

.loading-plane-sprite {
    width: 85px;
    height: 85px;
    image-rendering: pixelated;
    animation: loadingPlaneHover 1.8s ease-in-out infinite alternate;
    filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.7));
}

@keyframes loadingPlaneHover {
    0% {
        transform: translateY(6px) scale(0.96) rotate(-2deg);
    }
    100% {
        transform: translateY(-8px) scale(1.04) rotate(2deg);
    }
}

.loading-bar-border {
    width: 100%;
    height: 24px;
    background: #020718;
    border: 2px solid var(--arcade-gold);
    border-radius: 12px;
    overflow: hidden;
    padding: 2px;
    box-shadow: 0 0 12px rgba(255, 209, 102, 0.4), inset 0 2px 6px #000;
    position: relative;
}

.loading-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #00f0ff 0%, #39ff14 50%, #ffd166 100%);
    background-size: 30px 30px;
    border-radius: 8px;
    transition: width 0.2s cubic-bezier(0.1, 0.9, 0.2, 1.0);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.8);
}

.loading-info-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 9px;
    color: #a8d5ff;
    letter-spacing: 1px;
    margin-top: -6px;
}

.loading-status-text {
    color: #ffffff;
    max-width: 80%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

.loading-percent-text {
    color: var(--arcade-gold);
    font-size: 11px;
    font-weight: bold;
}

.loading-hint-badge {
    background: rgba(0, 0, 0, 0.5);
    border: 1px dashed rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 8px;
    line-height: 1.6;
    color: #cfe2ff;
    margin-top: 4px;
}

/* Fullscreen Button in Menu Header */
.menu-fullscreen-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    background: rgba(0, 0, 0, 0.65);
    border: 2px solid var(--arcade-gold);
    color: var(--arcade-gold);
    padding: 6px 12px;
    border-radius: 6px;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    cursor: pointer;
    transition: transform 0.15s, background 0.2s;
    z-index: 15;
    display: flex;
    align-items: center;
    gap: 6px;
}

.menu-fullscreen-btn:hover {
    transform: scale(1.05);
    background: rgba(255, 209, 102, 0.2);
}

