/* --- Local Fonts --- */
/* latin */
@font-face {
  font-family: 'Orbitron';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/v35_yMJRMIlzdpvBhQQL_Qq7dy0.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin */
@font-face {
  font-family: 'Orbitron';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(fonts/v35_yMJRMIlzdpvBhQQL_Qq7dy0.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin */
@font-face {
  font-family: 'Orbitron';
  font-style: normal;
  font-weight: 900;
  font-display: swap;
  src: url(fonts/v35_yMJRMIlzdpvBhQQL_Qq7dy0.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin */
@font-face {
  font-family: 'Share Tech Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/v16_J7aHnp1uDWRBEqV98dVQztYldFcLowEF.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}


/* --- CSS variables for neon palette --- */
:root {
    --neon-purple: #b026ff;
    --neon-pink: #ff007f;
    --neon-blue: #00f0ff;
    --neon-green: #39ff14;
    --neon-orange: #ff9900;
    --neon-red: #ff3333;
    --bg-dark: #070313;
    --bg-darker: #020107;
    --glass-bg: rgba(15, 8, 30, 0.7);
    --glass-border: rgba(176, 38, 255, 0.3);
    --font-cyber: 'Orbitron', 'Segoe UI', sans-serif;
    --font-mono: 'Share Tech Mono', 'Courier New', monospace;
}

/* --- Basic layout & resetting --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-darker);
    color: #ffffff;
    font-family: var(--font-cyber);
    min-height: 100svh; /* svh = small viewport height: correct on mobile with address bar */
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
    position: relative;
    /* Safe area insets for notch/home-indicator on iOS */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* --- Synthwave grid background animation --- */
body::before {
    content: "";
    position: absolute;
    width: 200%;
    height: 200%;
    top: -50%;
    left: -50%;
    background-image: 
        linear-gradient(rgba(176, 38, 255, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(176, 38, 255, 0.07) 1px, transparent 1px);
    background-size: 50px 50px;
    transform: perspective(500px) rotateX(60deg);
    animation: grid-scroll 20s linear infinite;
    z-index: 1;
}

@keyframes grid-scroll {
    0% {
        background-position: 0 0;
    }
    100% {
        background-position: 0 1000px;
    }
}

/* --- CRT Screen simulation overlays --- */
.crt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle, transparent 55%, rgba(0, 0, 0, 0.4) 100%);
    pointer-events: none;
    z-index: 9999;
}

.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(
        rgba(18, 16, 16, 0) 50%, 
        rgba(0, 0, 0, 0.15) 50%
    );
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 9998;
}

/* --- Container layout --- */
.game-container {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 840px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    margin: auto; /* centre vertically when content fits in viewport */
    border-radius: 12px;
    background: radial-gradient(ellipse at center, var(--bg-dark) 0%, var(--bg-darker) 100%);
    border: 1px solid var(--glass-border);
    box-shadow:
        0 0 20px rgba(176, 38, 255, 0.15),
        inset 0 0 15px rgba(176, 38, 255, 0.1);
}

/* --- HUD Panel --- */
.hud-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 12px 20px;
    border-radius: 8px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hud-label {
    font-size: 10px;
    letter-spacing: 2px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 4px;
    font-family: var(--font-mono);
}

.hud-value {
    font-size: 18px;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: 1px;
}

.lives-icons {
    display: flex;
    gap: 6px;
    align-items: center;
    height: 22px;
}

/* Custom mini ship icons using CSS SVG */
.live-ship {
    width: 16px;
    height: 16px;
    background-color: var(--neon-green);
    clip-path: polygon(50% 0%, 0% 100%, 25% 80%, 75% 80%, 100% 100%);
    box-shadow: 0 0 8px var(--neon-green);
    display: inline-block;
}

/* --- Canvas Area --- */
.canvas-wrapper {
    position: relative;
    width: 100%;
    max-width: 800px;
    aspect-ratio: 4 / 3;
    height: auto;
    border-radius: 8px;
    overflow: hidden;
    background: #000000;
    border: 2px solid rgba(0, 240, 255, 0.2);
    box-shadow: 0 0 25px rgba(0, 240, 255, 0.1);
    /* prevent page scroll when touching the canvas on mobile */
    touch-action: none;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* --- Screens & Overlays --- */
.overlay-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: opacity 0.4s ease, visibility 0.4s;
    text-align: center;
    padding: 20px;
    overflow-y: auto; /* allow scroll if content is too tall */
    box-sizing: border-box;
}

.overlay-panel > * {
    flex-shrink: 0;
}

.overlay-panel.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.overlay-panel.active {
    opacity: 1;
    visibility: visible;
}

/* Glassmorphism styling */
.glass-card {
    background: rgba(10, 5, 25, 0.85);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(176, 38, 255, 0.35);
    box-shadow: 
        0 10px 30px rgba(0, 0, 0, 0.8),
        0 0 30px rgba(176, 38, 255, 0.15);
}

.glass-card-dark {
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(0, 240, 255, 0.2);
    padding: 15px 25px;
    border-radius: 8px;
    max-width: 550px;
    margin-top: 25px;
    text-align: left;
    box-shadow: inset 0 0 10px rgba(0, 240, 255, 0.05);
}

/* --- Typographical Highlights & Helper Classes --- */
.font-mono {
    font-family: var(--font-mono);
}

.font-orbitron {
    font-family: var(--font-cyber);
}

.subtitle {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.75);
    margin-bottom: 25px;
    letter-spacing: 1px;
}

.glowing-text-green {
    color: var(--neon-green);
    text-shadow: 0 0 8px rgba(57, 255, 20, 0.6);
}

.glowing-text-blue {
    color: var(--neon-blue);
    text-shadow: 0 0 8px rgba(0, 240, 255, 0.6);
}

.glowing-text-magenta {
    color: var(--neon-pink);
    text-shadow: 0 0 8px rgba(255, 0, 127, 0.6);
}

.glowing-text-red {
    color: var(--neon-red);
    text-shadow: 0 0 10px rgba(255, 51, 51, 0.7);
}

.text-huge {
    font-size: 48px;
    font-weight: 900;
    letter-spacing: 3px;
    margin-bottom: 15px;
}

/* Glitch title styling */
.glitch-title {
    font-size: 56px;
    font-weight: 900;
    letter-spacing: 6px;
    color: #fff;
    position: relative;
    text-shadow: 
        0 0 10px var(--neon-purple),
        0 0 20px var(--neon-purple);
    margin-bottom: 15px;
    animation: title-pulse 2s infinite ease-in-out;
}

@keyframes title-pulse {
    0%, 100% {
        transform: scale(1);
        text-shadow: 0 0 10px var(--neon-purple), 0 0 20px var(--neon-purple);
    }
    50% {
        transform: scale(1.02);
        text-shadow: 0 0 15px var(--neon-pink), 0 0 30px var(--neon-pink);
    }
}

/* --- Controls & Input Elements --- */
.difficulty-section {
    margin: 20px 0;
    display: flex;
    align-items: center;
    gap: 15px;
}

.difficulty-section label {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
}

.cyber-select {
    background: #110825;
    color: var(--neon-blue);
    border: 1px solid var(--neon-blue);
    padding: 8px 12px;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
    font-size: 14px;
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.15);
    transition: all 0.3s;
}

.cyber-select:hover, .cyber-select:focus {
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.4);
    border-color: #ffffff;
}

.cyber-btn {
    background: transparent;
    color: #ffffff;
    border: 2px solid var(--neon-pink);
    padding: 12px 30px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 2px;
    cursor: pointer;
    border-radius: 6px;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: 0 0 12px rgba(255, 0, 127, 0.2);
    position: relative;
    overflow: hidden;
}

.cyber-btn:hover {
    background: var(--neon-pink);
    color: #000;
    box-shadow: 0 0 25px rgba(255, 0, 127, 0.7);
    text-shadow: none;
}

/* Instructions card */
.instructions h3 {
    color: var(--neon-blue);
    font-size: 14px;
    margin-bottom: 8px;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(0, 240, 255, 0.3);
    padding-bottom: 4px;
}

.instructions ul {
    list-style: none;
}

.instructions li {
    font-size: 12px;
    margin-bottom: 6px;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 8px;
}

.instructions .key {
    background: #251846;
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    color: #ffffff;
    box-shadow: 0 2px 0 rgba(0,0,0,0.5);
}

/* Stats summary on GameOver */
.stats-summary {
    margin: 20px 0 30px;
    font-size: 18px;
    line-height: 1.6;
}

/* --- Power-up toast message --- */
.powerup-toast {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 240, 255, 0.15);
    border: 1px solid var(--neon-blue);
    color: #ffffff;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 13px;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    box-shadow: 
        0 0 15px rgba(0, 240, 255, 0.25),
        inset 0 0 8px rgba(0, 240, 255, 0.1);
    animation: pulse-border 1.5s infinite alternate;
    z-index: 150;
    transition: opacity 0.3s;
}

@keyframes pulse-border {
    0% { border-color: var(--neon-blue); box-shadow: 0 0 10px rgba(0, 240, 255, 0.2); }
    100% { border-color: var(--neon-pink); box-shadow: 0 0 15px rgba(255, 0, 127, 0.4); }
}

/* --- Footer HUD Panel --- */
.footer-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 10px 20px;
    border-radius: 8px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.developer-info {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 1px;
}

.audio-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-icon-btn .icon {
    width: 20px;
    height: 20px;
    fill: var(--neon-blue);
    filter: drop-shadow(0 0 3px rgba(0, 240, 255, 0.5));
    transition: fill 0.3s;
}

.control-icon-btn:hover .icon {
    fill: var(--neon-pink);
    filter: drop-shadow(0 0 5px rgba(255, 0, 127, 0.7));
}

.volume-slider-container {
    display: flex;
    align-items: center;
    width: 70px;
}

.cyber-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.15);
    outline: none;
}

.cyber-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--neon-blue);
    box-shadow: 0 0 6px var(--neon-blue);
    cursor: pointer;
    transition: background 0.3s;
}

.cyber-slider::-webkit-slider-thumb:hover {
    background: var(--neon-pink);
    box-shadow: 0 0 8px var(--neon-pink);
}

/* Utility classes */
.blink {
    animation: blinker 1.5s linear infinite;
}

@keyframes blinker {
    50% { opacity: 0; }
}

.hidden {
    display: none !important;
}

/* --- Touch/Keyboard instruction visibility --- */
.touch-only   { display: none; }
.keyboard-only { display: block; }

@media (pointer: coarse) {
    .touch-only   { display: block; }
    .keyboard-only { display: none; }
}

/* --- Mobile Touch Controls --- */
/* Base: hidden on all devices */
.mobile-controls {
    display: none;
}

/* On touch devices, reveal only when game is PLAYING (JS sets data-visible) */
@media (pointer: coarse) {
    .mobile-controls[data-visible="true"] {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        gap: 12px;
        padding: 4px 0;
    }

    .move-btns {
        display: flex;
        gap: 12px;
    }

    .mobile-btn {
        background: rgba(15, 8, 30, 0.85);
        border: 2px solid var(--neon-blue);
        color: #ffffff;
        /* minimum 48×48 px tap target (WCAG) */
        min-width: 60px;
        min-height: 54px;
        padding: 10px 18px;
        font-size: 22px;
        border-radius: 10px;
        cursor: pointer;
        outline: none;
        touch-action: none;
        user-select: none;
        -webkit-user-select: none;
        -webkit-tap-highlight-color: transparent;
        box-shadow: 0 0 8px rgba(0, 240, 255, 0.2);
        transition: background 0.08s, box-shadow 0.08s;
    }

    .mobile-btn:active {
        background: var(--neon-blue);
        color: #000000;
        box-shadow: 0 0 18px rgba(0, 240, 255, 0.7);
    }

    .fire-btn {
        border-color: var(--neon-pink);
        font-size: 15px;
        font-weight: bold;
        letter-spacing: 1px;
        flex-grow: 1;
        max-width: 220px;
        box-shadow: 0 0 8px rgba(255, 0, 127, 0.2);
    }

    .fire-btn:active {
        background: var(--neon-pink);
        color: #000000;
        box-shadow: 0 0 18px rgba(255, 0, 127, 0.7);
    }
}

/* ---- Responsive tweaks for narrow screens ---- */
@media (max-width: 520px) {
    .game-container {
        padding: 8px;
        gap: 8px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .hud-panel {
        padding: 8px 10px;
        gap: 4px;
    }

    .hud-label {
        font-size: 8px;
        letter-spacing: 1px;
    }

    .hud-value {
        font-size: 14px;
    }

    .overlay-panel {
        /* Prevent flexbox from centering and clipping the top when content overflows */
        justify-content: flex-start;
        padding: 10px;
    }

    .glitch-title {
        font-size: 24px;
        letter-spacing: 2px;
        margin-top: 10px;
        margin-bottom: 5px;
    }

    .subtitle {
        font-size: 10px;
        margin-bottom: 8px;
    }

    .cyber-btn {
        padding: 8px 16px;
        font-size: 12px;
    }

    .difficulty-section {
        flex-direction: column;
        gap: 4px;
        margin: 5px 0 10px 0;
    }
    
    .difficulty-section label {
        font-size: 10px;
    }

    .cyber-select {
        font-size: 11px;
        padding: 6px;
    }

    .text-huge {
        font-size: 26px;
    }

    .footer-panel {
        padding: 8px 10px;
    }

    .developer-info {
        display: none; /* hide version text on tiny screens */
    }

    .glass-card-dark {
        padding: 8px 10px;
        margin-top: 5px;
    }
    
    .instructions h3 {
        font-size: 11px;
        margin-bottom: 4px;
    }

    .instructions li {
        font-size: 9px;
        margin-bottom: 3px;
    }
}

/* ---- Landscape mobile: collapse vertical space ---- */
@media (max-height: 520px) and (pointer: coarse) {
    .game-container {
        gap: 5px;
        padding: 5px;
    }

    .hud-panel {
        padding: 5px 10px;
    }

    .hud-label {
        display: none; /* hide labels, keep values */
    }

    .hud-value {
        font-size: 12px;
    }

    .footer-panel {
        display: none; /* hide footer in landscape to save space */
    }

    @media (pointer: coarse) {
        .mobile-controls[data-visible="true"] {
            gap: 8px;
            padding: 2px 0;
        }

        .mobile-btn {
            min-height: 44px;
            padding: 8px 14px;
            font-size: 18px;
        }

        .fire-btn {
            font-size: 13px;
        }
    }
}
