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

body {
    font-family: 'Courier New', monospace;
    background: linear-gradient(180deg, #000428 0%, #004e92 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: #fff;
    overflow: hidden;
}

.game-container {
    position: relative;
    text-align: center;
    width: 100%;
    max-width: 800px;
}

.title {
    font-size: 2.5em;
    font-weight: bold;
    color: #00ff00;
    text-shadow: 0 0 10px #00ff00, 0 0 20px #00ff00;
    margin-bottom: 10px;
    letter-spacing: 5px;
}

#gameCanvas {
    border: 3px solid #00ff00;
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.5);
    background: linear-gradient(180deg, #001a33 0%, #003366 100%);
    display: block;
    margin: 0 auto;
    width: 100%;
    max-width: 800px;
    aspect-ratio: 4 / 3;
    touch-action: none;
}

.hud {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #00ff00;
    border-top: none;
    margin: 0 auto;
    max-width: 800px;
    flex-wrap: wrap;
    gap: 6px;
}

.hud-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.hud-label {
    color: #00ff00;
    font-weight: bold;
    font-size: 0.85em;
}

.hud-value {
    color: #fff;
    font-size: 1.1em;
    font-weight: bold;
    min-width: 24px;
}

.health-bar, .shield-bar {
    width: 120px;
    height: 16px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid #00ff00;
    border-radius: 8px;
    overflow: hidden;
}

.health-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #ff0000 0%, #ff6600 100%);
    transition: width 0.3s ease;
}

.shield-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #00ccff 0%, #0066ff 100%);
    transition: width 0.3s ease;
}

/* ── Screens ─────────────────────────────────────────────────── */
.screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    padding: 32px 48px;
    border: 3px solid #00ff00;
    border-radius: 10px;
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.5);
    z-index: 10;
    width: max-content;
    max-width: 95vw;
}

.screen h2 {
    font-size: 2.2em;
    color: #00ff00;
    text-shadow: 0 0 10px #00ff00;
    margin-bottom: 16px;
}

.screen p {
    font-size: 1em;
    margin-bottom: 10px;
}

.controls-info {
    text-align: left;
    margin: 16px 0;
    padding: 14px;
    background: rgba(0, 255, 0, 0.08);
    border-radius: 5px;
    font-size: 0.85em;
    line-height: 1.7;
}

button {
    background: #00ff00;
    color: #000;
    border: none;
    padding: 12px 36px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    border-radius: 5px;
    margin-top: 16px;
    transition: all 0.2s ease;
    font-family: 'Courier New', monospace;
    -webkit-tap-highlight-color: transparent;
}

button:hover, button:active {
    background: #00cc00;
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.8);
    transform: scale(1.05);
}

.hidden { display: none !important; }

/* ── Credits ──────────────────────────────────────────────── */
.credits {
    text-align: center;
    padding: 5px 8px 4px;
    font-size: 0.65em;
    color: rgba(0, 255, 0, 0.7);
    letter-spacing: 0.3px;
    line-height: 1.4;
    pointer-events: none;
    user-select: none;
    max-width: 800px;
    margin: 0 auto;
}

/* ── Jet selection ───────────────────────────────────────────── */
.screen#jetSelectScreen {
    padding: 24px 28px;
    max-width: 92vw;
}

.jet-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 18px;
}

.jet-option {
    cursor: pointer;
    padding: 10px 8px;
    border: 2px solid #336633;
    border-radius: 10px;
    background: rgba(0, 40, 0, 0.6);
    transition: all 0.2s ease;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
}

.jet-option:hover,
.jet-option.selected {
    border-color: #00ff00;
    background: rgba(0, 255, 0, 0.12);
    transform: scale(1.04);
    box-shadow: 0 0 16px rgba(0, 255, 0, 0.5);
}

.jet-preview-img {
    width: 70px;
    height: 90px;
    object-fit: contain;
    display: block;
    margin: 0 auto 6px;
    filter: drop-shadow(0 0 5px rgba(0, 200, 255, 0.4));
}

.jet-name {
    font-size: 0.78em;
    color: #00ff00;
    font-weight: bold;
    margin: 3px 0 2px;
}

.jet-desc {
    font-size: 0.66em;
    color: #aaa;
    margin-bottom: 5px;
}

.jet-stats {
    display: flex;
    flex-direction: column;
    gap: 1px;
    font-size: 0.62em;
    color: #88cc88;
    text-align: left;
    padding: 0 2px;
}

/* ── Touch controls ──────────────────────────────────────────── */
#touchControls {
    display: none; /* hidden on desktop */
    position: relative;
    width: 100%;
    max-width: 800px;
    height: 140px;
    margin: 0 auto;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #224422;
    border-top: none;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    touch-action: none;
}

#joystickZone {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: rgba(0, 255, 0, 0.06);
    border: 2px solid rgba(0, 255, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    user-select: none;
    flex-shrink: 0;
}

#joystickBase {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: rgba(0, 255, 0, 0.08);
    border: 1px solid rgba(0, 255, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

#joystickThumb {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #00ff88, #007744);
    border: 2px solid #00ff00;
    box-shadow: 0 0 12px rgba(0, 255, 0, 0.6);
    position: absolute;
    transition: box-shadow 0.1s;
    touch-action: none;
    pointer-events: none;
}

.touch-buttons {
    display: flex;
    gap: 16px;
    align-items: center;
}

.touch-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 2px solid #00ff00;
    background: rgba(0, 60, 0, 0.7);
    color: #fff;
    font-size: 0.7em;
    font-weight: bold;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.3;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    user-select: none;
}

.touch-btn:active,
.touch-btn.active {
    background: rgba(0, 200, 0, 0.3);
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.7);
    transform: scale(0.94);
}

.shield-touch-btn {
    border-color: #00ccff;
    box-shadow: 0 0 10px rgba(0, 150, 255, 0.3);
}

.shield-touch-btn.active {
    background: rgba(0, 100, 200, 0.4);
    box-shadow: 0 0 20px rgba(0, 200, 255, 0.7);
}

/* ── Tablet touch devices (iPad, large Android tablets) ────────── */
@media (pointer: coarse) and (min-width: 650px) {
    /* Show touch controls — weapons + joystick */
    #touchControls {
        display: flex;
    }

    /* Scale canvas to fit tablet viewport while preserving 4:3 */
    #gameCanvas {
        width: 100%;
        max-width: min(800px, calc(100vw - 40px));
        aspect-ratio: 4 / 3;
    }

    /* Slightly compact HUD on tablet */
    .hud {
        padding: 6px 12px;
        gap: 8px;
    }
    .health-bar, .shield-bar {
        width: 80px;
        height: 12px;
    }
    .hud-label { font-size: 0.75em; }
    .hud-value { font-size: 0.9em; }
}

/* ── Phone touch devices (< 650px) ────────────────────────────── */
@media (pointer: coarse) and (max-width: 649px) {
    /* Body: full viewport, no scroll */
    body {
        align-items: flex-start;
        padding: 0;
        min-height: unset;
        height: 100dvh;
        overflow: hidden;
    }
    html {
        overflow-x: hidden;
    }

    /* Game container fills entire viewport as flex column */
    .game-container {
        display: flex;
        flex-direction: column;
        height: 100dvh;
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
        position: relative;
    }

    /* Title compact on mobile */
    .title {
        font-size: 1.4em;
        flex-shrink: 0;
        padding: 6px 0 2px;
    }

    .credits {
        flex-shrink: 0;
        font-size: 0.52em;
        padding: 3px 8px 2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Canvas fills remaining space between HUD and touch controls, no horizontal overflow */
    #gameCanvas {
        flex: 1 1 auto;
        min-height: 0;
        width: 100% !important;
        max-width: 100% !important;
        aspect-ratio: unset !important;
    }

    /* HUD stays compact, doesn't grow */
    .hud {
        flex-shrink: 0;
        padding: 5px 8px;
        gap: 4px;
    }

    /* Selection/game-over screens — centered modal, not fullscreen */
    .screen {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: calc(100% - 24px);
        max-height: calc(100% - 60px);
        border-radius: 10px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        padding: 20px 14px 24px;
    }

    #touchControls {
        display: flex;
        flex-shrink: 0;
        height: 120px;
    }

    .health-bar, .shield-bar {
        width: 70px;
        height: 12px;
    }

    .hud-label { font-size: 0.7em; }
    .hud-value { font-size: 0.85em; }

    .screen h2 { font-size: 1.6em; margin-bottom: 10px; }
    .screen p  { font-size: 0.88em; }

    /* Jet selection — horizontal swipe carousel */
    .jet-grid {
        display: flex;
        flex-direction: row;
        overflow-x: scroll;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 12px;
        /* Side padding creates peek effect — partial next card visible */
        padding: 8px 12vw 20px 12vw;
        margin-top: 14px;
        grid-template-columns: unset;
        width: 100%;
    }
    .jet-grid::-webkit-scrollbar { display: none; }
    .jet-grid::after {
        content: '⟵ swipe ⟶';
        flex: 0 0 auto;
        align-self: center;
        font-size: 0.6em;
        color: rgba(0, 255, 0, 0.4);
        white-space: nowrap;
        pointer-events: none;
        padding: 0 20px;
    }
    .jet-option {
        flex: 0 0 76vw;
        scroll-snap-align: center;
        padding: 14px 10px;
    }
    .jet-preview-img { width: 80px; height: 104px; }
    .jet-name { font-size: 0.7em; }
    .jet-desc { font-size: 0.6em; }
    .jet-stats { font-size: 0.56em; }

    /* Hint for direct drag */
    #touchControls::before {
        content: '✦ drag jet with finger';
        position: absolute;
        top: 4px;
        left: 50%;
        transform: translateX(-50%);
        font-size: 0.55em;
        color: rgba(0,255,0,0.4);
        white-space: nowrap;
        pointer-events: none;
    }
}

/* Very small phones (<400px) — narrower carousel cards */
@media (pointer: coarse) and (max-width: 400px) {
    .jet-option { flex: 0 0 84vw; }
    .jet-preview-img { width: 56px; height: 72px; }
    .jet-name { font-size: 0.68em; }
    .jet-desc { font-size: 0.6em; }
    .jet-stats { font-size: 0.56em; }
}
