@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap');

* {
    box-sizing: border-box;
    /* touch-action: none; REMOVED - Causes scrolling issues */
    /* Prevent browser zooming/scrolling */
    user-select: none;
    -webkit-user-select: none;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    color: #fff;
    overflow: hidden;
    font-family: 'Orbitron', sans-serif;
    touch-action: none;
    /* Block default touch actions globally on body */
}

/* ... existing styles ... */

canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    /* Critical for game controls */
}

#ui-layer {
    /* ... */
    touch-action: none;
    /* Prevent touches on UI layer from scrolling */
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    /* Mobile Aspect Ratio Enforcement */
    max-width: 480px;
    margin: 0 auto;
    /* Center on desktop */
    border-left: 2px solid #333;
    /* Visual border for desktop */
    border-right: 2px solid #333;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
    background-color: #000;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let touches pass through to canvas */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
}

#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Better alignment */
    width: 100%;
    pointer-events: auto;
    padding: 10px 15px;
    /* Safe side padding */
    gap: 10px;
    /* Increased gap slightly */
}

#pause-btn {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #00ffcc;
    color: #00ffcc;
    font-size: 12px;
    font-weight: bold;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    box-shadow: 0 0 10px rgba(0, 255, 204, 0.3);
    min-width: 0;
    /* Override global button style */
    padding: 0;
}

#pause-btn:hover {
    background: rgba(0, 255, 204, 0.2);
    box-shadow: 0 0 15px #00ffcc;
    transform: scale(1.1);
}

/* --- Mobile Orientation Enforcement --- */
#rotate-message {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #00ffcc;
    font-family: 'Orbitron', sans-serif;
    padding: 20px;
    text-align: center;
    gap: 15px;
    /* Reduced gap */
}

.rotate-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: rotateIcon 2s infinite ease-in-out;
}

@keyframes rotateIcon {
    0% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-90deg);
    }

    75% {
        transform: rotate(-90deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

@media screen and (orientation: landscape) and (max-width: 900px) {
    #rotate-message {
        display: flex;
    }

    #game-container {
        display: none;
    }
}

#pause-btn:active {
    transform: scale(0.9);
}

#score-board,
#currency-display {
    color: #00ffcc;
    font-size: 12px;
    /* Fixed small size for mobile */
    text-shadow: 0 0 5px #00ffcc;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 10px;
    border-radius: 15px;
    border: 1px solid rgba(0, 255, 204, 0.3);
    white-space: nowrap;
}

#currency-display {
    color: #ffd700;
    text-shadow: 0 0 5px #ffd700;
    border-color: rgba(255, 215, 0, 0.3);
}

#hp-bar {
    display: flex;
    gap: 4px;
    /* Tighter gap */
    margin-top: 4px;
}

.hp-pip {
    width: 25px;
    /* Smaller pips */
    height: 8px;
    background-color: #ff0044;
    border: 1px solid #fff;
    box-shadow: 0 0 5px #ff0044;
    transform: skewX(-20deg);
    transition: all 0.2s;
}

#skill-bar {
    display: flex;
    justify-content: center;
    gap: 15px;
    /* Fixed functional gap */
    pointer-events: auto;
    margin-bottom: 20px;
    /* Safe area padding included in style */
    width: 100%;
    padding-bottom: 10px;
}

.skill-btn {
    position: relative;
    width: 60px;
    height: 60px;
    border: 2px solid #444;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.1s;
    touch-action: manipulation;
}

.skill-btn:active {
    transform: scale(0.9);
}

/* Make images inside skills fit well */
.skill-btn img {
    width: 80%;
    height: 80%;
    object-fit: contain;
}

.cooldown-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background-color: rgba(0, 0, 0, 0.7);
    transition: height 0.1s linear;
    z-index: 10;
}

.key-hint {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 12px;
    color: #00ffcc;
    z-index: 11;
}

/* ... existing styles ... */

/* Screen Containers */
#start-screen,
#game-over-screen,
.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Center vertically default */
    z-index: 20;
    background: radial-gradient(circle at center, rgba(10, 20, 40, 0.95), rgba(0, 0, 0, 0.98));
    text-align: center;
    gap: 15px;
}

#start-screen {
    padding: 20px 20px 250px 20px;
    /* Lift content for Start Screen only */
}

#game-over-screen {
    padding: 20px;
}

.overlay-screen {
    padding: 100px 20px 20px 20px;
    /* Top padding to clear Back button */
    justify-content: flex-start;
    /* Align to top for scrolling lists */
    /* Specialized overlay overrides if needed */
    z-index: 30;
    /* Higher than start/gameover if stacking matters, but usually one at a time */
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 25px;
    /* Wider gap for safety */
    margin-top: 30px;
    width: 100%;
    align-items: center;
    /* Center buttons */
}

button {
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid #00ffcc;
    color: #00ffcc;
    font-family: 'Orbitron', sans-serif;
    font-size: 24px;
    padding: 20px 40px;
    /* Larger vertical padding */
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: all 0.2s ease;
    box-shadow: 0 0 10px rgba(0, 255, 204, 0.2);
    min-width: 250px;
    /* Wider minimum */
    width: 80%;
    /* Responsive width */
    max-width: 400px;
    border-radius: 12px;
    /* Smoother corners */
}

button:hover {
    background: #00ffcc;
    color: #000;
    box-shadow: 0 0 20px #00ffcc;
    transform: scale(1.02);
    /* Subtle scale */
}

button:active {
    transform: scale(0.95);
    background: rgba(0, 255, 204, 0.8);
}

#shop-credits {
    margin-bottom: 20px;
    font-size: 24px;
    color: #ffd700;
}

.game-logo {
    width: clamp(200px, 80vw, 400px);
    margin-bottom: 20px;
    filter: drop-shadow(0 0 20px rgba(0, 255, 204, 0.5));
    animation: floating 3s ease-in-out infinite;
}

.result-icon {
    width: 100px;
    height: 100px;
    object-fit: contain;
    margin-bottom: 10px;
    filter: drop-shadow(0 0 15px rgba(255, 255, 255, 0.5));
}

/* Mission Select Screen - Mobile First Overhaul */
#stage-select-screen {
    justify-content: flex-start;
    padding-top: 80px;
    /* Space for back button */
    background: radial-gradient(circle at center, rgba(10, 20, 60, 0.95), rgba(0, 0, 0, 0.98));
}

#stage-select-screen h1 {
    font-size: 32px;
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(0, 255, 204, 0.5);
    letter-spacing: 3px;
    flex-shrink: 0;
}

#stage-grid-container {
    width: 100%;
    max-width: 800px;
    flex: 1;
    overflow-y: auto;
    /* Allow scrolling if content overflows */
    padding: 20px;
    margin-bottom: 20px;

    margin-bottom: 20px;

    /* Scrollbar Styling */
    scrollbar-width: none;
    -ms-overflow-style: none;
    /* IE 10+ */
    touch-action: pan-y !important;
    /* Force enable vertical swipe scrolling */

    /* Ensure touches are received */
    pointer-events: auto;
}

#stage-grid-container::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

/* 
#stage-grid-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

#stage-grid-container::-webkit-scrollbar-thumb {
    background: #00ffcc;
    border-radius: 10px;
} 
*/

#stage-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 320px;
    /* Constrain width to keep it tight on mobile */
    margin: 0 auto;
    padding-bottom: 40px;
}

/* Tablet/Desktop overrides can remain or be simplified */
@media (min-width: 600px) {
    #stage-grid {
        max-width: 600px;
        gap: 20px;
    }
}

@media (min-width: 900px) {
    #stage-grid {
        max-width: 800px;
        gap: 25px;
    }

    #stage-select-screen {
        justify-content: center;
        /* padding-top: 0; removed to keep consistent padding */
    }
}

.stage-btn {
    width: 50px;
    height: 50px;
    background: rgba(0, 20, 40, 0.6);
    border: 1px solid #00ffcc;
    border-radius: 8px;
    color: #fff;
    font-family: 'Orbitron', sans-serif;
    font-size: 16px;
    /* Smaller font */
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 0 10px rgba(0, 255, 204, 0.1), inset 0 0 10px rgba(0, 255, 204, 0.05);
    text-shadow: 0 0 5px #00ffcc;
}

.stage-btn:hover:not(.locked) {
    background: rgba(0, 255, 204, 0.2);
    box-shadow: 0 0 25px #00ffcc, inset 0 0 30px rgba(0, 255, 204, 0.2);
    transform: scale(1.05);
    /* Slight pop */
    border-color: #fff;
}

.stage-btn:active:not(.locked) {
    transform: scale(0.95);
    background: rgba(0, 255, 204, 0.4);
}

.stage-btn.locked {
    background: rgba(20, 20, 20, 0.8);
    opacity: 0.5;
    border-color: #444;
    color: #555;
    cursor: not-allowed;
    box-shadow: none;
    text-shadow: none;
}

.back-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    padding: 15px 30px;
    /* Larger tap area */
    font-size: 18px;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid #ff0044;
    /* Distinct colour for BACK */
    color: #ff0044;
    box-shadow: 0 0 10px rgba(255, 0, 68, 0.2);
    min-width: auto;
    border-radius: 30px;
    /* Pill shape */
    z-index: 100;
}

.back-btn:hover {
    background: #ff0044;
    color: white;
    box-shadow: 0 0 20px #ff0044;
}

#ship-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    /* max-width removed to allow full width on mobile */
    max-width: 600px;
    height: 60vh;
    /* Keep scrollable area */
    overflow-y: auto;
    padding-right: 10px;
    padding-left: 10px;
    /* Add padding for scrollbar clearance */
    touch-action: pan-y !important;
    /* Force enable vertical swipe scrolling */
    pointer-events: auto;
    /* Ensure interaction */
    scrollbar-width: none;
    /* Firefox */
}

#ship-list::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.ship-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #444;
    border-radius: 16px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    transition: 0.3s;
    /* Flex wrap for very small screens */
    flex-wrap: wrap;
}

.ship-card.selected {
    border-color: #00ffcc;
    background: rgba(0, 255, 204, 0.05);
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.1);
}

.ship-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
}

.ship-info {
    flex: 1;
}

.ship-info h3 {
    margin: 0;
    color: #00ffcc;
}

.ship-info p {
    margin: 5px 0;
    font-size: 12px;
    opacity: 0.7;
}

.ship-action-btn {
    padding: 15px 20px;
    font-size: 16px;
    font-weight: bold;
    min-width: 120px;
    background: #444;
    color: #fff;
    border: none;
    border-radius: 8px;
    /* Slightly more rounded */
    cursor: pointer;
    /* Reset global button styles if needed */
    box-shadow: none;
    width: auto;
    /* Allow sizing based on content or flex */
    max-width: none;
}

.ship-action-btn:active {
    background: #666;
}

.ship-action-btn.owned {
    background: #0088ff;
    box-shadow: 0 0 10px rgba(0, 136, 255, 0.5);
}

.ship-action-btn.selected {
    background: #00ffcc;
    color: black;
    box-shadow: 0 0 10px rgba(0, 255, 204, 0.5);
}

.glow-text {
    text-shadow: 0 0 15px #ff0044;
    letter-spacing: 5px;
}

#shop-credits {
    margin-bottom: 20px;
    font-size: 24px;
    color: #ffd700;
}

/* Scrollbar styling */
#ship-list::-webkit-scrollbar {
    width: 6px;
}

#ship-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

#ship-list::-webkit-scrollbar-thumb {
    background: #00ffcc;
    border-radius: 10px;
}

.story-narrative {
    margin: 15px 0;
    padding: 15px;
    background: rgba(0, 255, 204, 0.05);
    border-left: 3px solid #00ffcc;
    font-size: 14px;
    color: #eee;
    max-width: 90%;
    text-align: left;
    min-height: 80px;
    line-height: 1.4;
    font-family: 'Orbitron', sans-serif;
}

.ending-content.cinematic {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.planet-container {
    position: relative;
    width: clamp(200px, 50vw, 400px);
    height: clamp(200px, 50vw, 400px);
    margin: 0 auto;
}

#game-logo {
    width: 80%;
    max-width: 300px;
    margin-bottom: 20px;
    /* Reduced space as requested */
    /* More space before title */
    filter: drop-shadow(0 0 20px rgba(0, 255, 204, 0.4));
    animation: floatLogo 3s ease-in-out infinite;
}

@keyframes floatLogo {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.new-world-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 50px rgba(0, 255, 204, 0.5));
}

.landing-ship {
    position: absolute;
    width: 60px;
    top: 50%;
    left: 50%;
    transform: translate(-300%, -300%) rotate(45deg);
    animation: landing 8s ease-out forwards;
}

.story-box {
    background: rgba(0, 0, 0, 0.7);
    border-left: 5px solid #00ffcc;
    padding: 20px;
    margin: 20px 0;
    line-height: 1.6;
    text-align: left;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    min-height: 120px;
    font-size: 14px;
}

.prime-btn {
    background: linear-gradient(45deg, #00ffcc, #0088ff) !important;
    color: black !important;
    font-weight: bold;
    box-shadow: 0 0 20px #00ffcc !important;
}

.credits-roll {
    padding: 20px;
    background: rgba(255, 215, 0, 0.1);
    border-radius: 12px;
    border: 1px solid #ffd700;
}

.credits-roll h3 {
    color: #ffd700;
    margin: 0;
}

@keyframes rotate-slow {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

#next-level-btn {
    background: rgba(0, 255, 204, 0.2);
    border-color: #ffd700;
    color: #ffd700;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
}

#next-level-btn:hover {
    background: #ffd700;
    color: black;
    box-shadow: 0 0 25px #ffd700;
}

@keyframes landing {
    0% {
        transform: translate(-400%, -400%) rotate(45deg);
        opacity: 0;
    }

    30% {
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) rotate(45deg);
        scale: 0.5;
    }
}

@keyframes floating {
    0% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-10px);
    }

    100% {
        transform: translateY(0px);
    }
}

@media (max-width: 600px) {
    #stage-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .landing-ship {
        width: 40px;
    }
}

.hidden {
    display: none !important;
}

.back-btn {
    width: auto !important;
    min-width: 100px !important;
    /* Reasonable small min-width */
    padding: 8px 16px !important;
    font-size: 16px !important;
    margin-bottom: 10px;
    align-self: center;
    /* Helper if in flex column */
}

/* Happy Pilots Container */
.happy-pilots {
    position: absolute;
    bottom: 20px;
    /* Stand on the planet */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

/* Individual Pilot Images */
.happy-pilot-img {
    width: 80px;
    /* Adjusted size */
    height: 80px;
    object-fit: contain;
    filter: drop-shadow(0 0 10px rgba(0, 255, 204, 0.8));
    transition: transform 0.2s ease-out;
    /* Smooth transition */
}

/* Jump Class controlled by JS */
.pilot-img.jumping {
    transform: translateY(-20px);
}

/* 
   Removed infinite keyframe animation (jump-joy) 
   to allow JS to control the state 
*/