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

html {
    width: 100%;
    height: 100%;
    background: #000;
}

body {
    background: #0a0a12;
    overflow: hidden;
    cursor: crosshair;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    user-select: none;
    width: 100%;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    overscroll-behavior: none;
    touch-action: none;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

#hud {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    pointer-events: none;
    z-index: 10;
}

#hud-top {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) auto minmax(220px, 1fr);
    align-items: flex-start;
    padding: 15px 25px;
}

#hp-bar-container {
    position: relative;
    width: 280px;
    height: 24px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #333;
    border-radius: 12px;
    overflow: hidden;
}

#hp-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #ff1744, #ff5252);
    transition: width 0.15s ease;
    border-radius: 10px;
}

#hp-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 12px;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

#shield-bar-container {
    position: absolute;
    top: 43px;
    left: 25px;
    width: 280px;
    height: 13px;
    margin: 0;
    background: rgba(0, 0, 0, 0.65);
    border: 1px solid rgba(64, 196, 255, 0.5);
    border-radius: 8px;
    overflow: hidden;
}

#shield-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #0288d1, #b3e5fc);
    transition: width 0.15s ease;
}

#shield-text {
    position: absolute;
    inset: 0;
    color: #dffaff;
    font-size: 9px;
    line-height: 12px;
    text-align: center;
    text-shadow: 1px 1px 2px #000;
}

#stamina-bar-container {
    position: absolute;
    top: 62px;
    left: 25px;
    width: 280px;
    height: 13px;
    background: rgba(0, 0, 0, 0.68);
    border: 1px solid rgba(0, 230, 118, 0.58);
    border-radius: 8px;
    overflow: hidden;
}

#stamina-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #00c853, #b2ff59);
    box-shadow: 0 0 10px rgba(0, 230, 118, 0.5);
    transition: width 0.08s linear;
}

#stamina-text {
    position: absolute;
    inset: 0;
    color: #e8fff1;
    font-size: 9px;
    line-height: 11px;
    text-align: center;
    text-shadow: 1px 1px 2px #000;
}

#score-display {
    grid-column: 3;
    grid-row: 1;
    text-align: right;
    color: #ffd740;
    font-size: clamp(13px, 1.8vw, 22px);
    font-weight: bold;
    text-shadow: 0 0 10px rgba(255, 215, 64, 0.5), 2px 2px 4px rgba(0,0,0,0.8);
}

#stage-display {
    grid-column: 2;
    grid-row: 1;
    text-align: center;
    color: #80deea;
    font-size: clamp(12px, 1.5vw, 18px);
    font-weight: bold;
    text-shadow: 0 0 10px rgba(128, 222, 234, 0.5), 2px 2px 4px rgba(0,0,0,0.8);
}

#weapons-display {
    position: fixed;
    left: 18px;
    bottom: 110px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    max-width: min(44vw, 560px);
}

.weapon-icon {
    min-width: 58px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 3px 6px;
    border: 1px solid currentColor;
    border-left-width: 3px;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.68);
    box-shadow: 0 0 9px currentColor;
    font: 700 10px monospace;
    letter-spacing: 0.4px;
}

.weapon-icon-name { opacity: 0.82; }
.weapon-icon strong { color: #fff; font-size: 11px; }
.weapon-icon.selected {
    background: rgba(255, 255, 255, 0.16);
    box-shadow: 0 0 14px currentColor, inset 0 0 8px currentColor;
}

#relics-display {
    position: fixed;
    left: 18px;
    bottom: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    max-width: min(44vw, 560px);
}

.relic-icon {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid currentColor;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.68);
    font: 700 13px monospace;
    box-shadow: 0 0 9px currentColor;
}

.relic-icon.apex {
    border-width: 2px;
    transform: rotate(45deg);
}

.relic-icon.apex span { transform: rotate(-45deg); }

#abilities-display {
    position: fixed;
    right: 22px;
    bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 7px;
    min-width: 190px;
}

.ability-card {
    display: grid;
    grid-template-columns: 52px 1fr auto;
    align-items: center;
    gap: 9px;
    min-height: 34px;
    padding: 5px 9px;
    color: #e8fbff;
    border: 1px solid rgba(128, 222, 234, 0.35);
    border-left: 3px solid #00e5ff;
    border-radius: 5px;
    background: linear-gradient(90deg, rgba(3, 18, 30, 0.9), rgba(2, 8, 18, 0.65));
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.35);
    font-family: monospace;
    letter-spacing: 0.7px;
}

.ability-card kbd {
    padding: 3px 5px;
    color: #07121d;
    background: #dffaff;
    border-radius: 3px;
    text-align: center;
    font: 700 10px monospace;
}

.ability-card span { font-size: 11px; font-weight: 700; }
.ability-card em { color: #69f0ae; font: normal 10px monospace; }
.ability-card.cooling { opacity: 0.62; border-left-color: #607d8b; }
.ability-card.cooling em { color: #90a4ae; }
#missile-ability { border-left-color: #ffea00; }
#bomb-ability { border-left-color: #ffab00; }

#powerups-display {
    position: fixed;
    bottom: 61px;
    left: 18px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: min(44vw, 560px);
}

.powerup-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 2px solid rgba(255,255,255,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    position: relative;
    background: rgba(0, 0, 0, 0.6);
}

.powerup-timer {
    position: absolute;
    bottom: -2px;
    left: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 0 0 6px 6px;
}

#boss-hp-container {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
}

#boss-hp-bar {
    width: min(520px, 70vw);
    height: 14px;
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid #6a1;
    border-radius: 7px;
    overflow: hidden;
}

#boss-hp-container.colossus #boss-hp-bar {
    width: min(760px, 84vw);
    height: 18px;
    border-color: #80d8ff;
    box-shadow: 0 0 18px rgba(64, 196, 255, 0.38);
}

#boss-hp-container.colossus #boss-name {
    font-size: clamp(10px, 1.3vw, 15px);
    letter-spacing: 2px;
}

#boss-hp-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #7b1fa2, #ce93d8);
    transition: width 0.2s ease;
    border-radius: 5px;
}

#boss-name {
    display: block;
    color: #ce93d8;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(206, 147, 216, 0.5);
    margin-bottom: 4px;
    letter-spacing: 3px;
}

#boss-objective {
    display: block;
    min-height: 15px;
    margin-top: 4px;
    color: #e1f5fe;
    font: 700 11px monospace;
    letter-spacing: 1px;
    text-shadow: 0 0 8px rgba(128, 216, 255, 0.7);
}

#boss-parts-status {
    display: flex;
    justify-content: center;
    gap: 5px;
    min-height: 8px;
    margin-top: 4px;
}

.boss-part-pip {
    width: 34px;
    height: 5px;
    border: 1px solid rgba(255,255,255,0.45);
    background: rgba(255,255,255,0.12);
    transform: skewX(-18deg);
}

.boss-part-pip.alive { background: #40c4ff; box-shadow: 0 0 7px #40c4ff; }
.boss-part-pip.optional.alive { background: #ffab40; box-shadow: 0 0 7px #ffab40; }
.boss-part-pip.destroyed { border-color: rgba(255,82,82,0.45); background: rgba(255,23,68,0.18); }

#orientation-hint {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 90;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 10px;
    padding: 24px;
    color: #e8fbff;
    text-align: center;
    background: rgba(3, 5, 14, 0.94);
    pointer-events: none;
}

.orientation-glyph {
    color: #ffd740;
    font-size: 54px;
    line-height: 1;
    text-shadow: 0 0 24px rgba(255, 215, 64, 0.6);
}

#orientation-hint strong {
    color: #ffd740;
    font: 700 15px monospace;
    letter-spacing: 1.5px;
}

#orientation-hint span {
    color: #9bb8c0;
    font: 12px monospace;
}

#mobile-controls {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 40;
    pointer-events: none;
}

body.mobile-device #mobile-controls { display: block; }

.mobile-stick {
    position: absolute;
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: 148px;
    height: 148px;
    color: rgba(214, 250, 255, 0.72);
    pointer-events: auto;
    touch-action: none;
}

#mobile-move-stick { left: calc(12px + env(safe-area-inset-left)); }
#mobile-aim-stick { right: calc(48px + env(safe-area-inset-right)); }

.stick-label {
    position: absolute;
    top: 2px;
    left: 0;
    right: 0;
    color: rgba(214, 250, 255, 0.62);
    font: 700 9px monospace;
    letter-spacing: 1px;
    text-align: center;
    text-shadow: 0 1px 4px #000;
}

.stick-base {
    position: absolute;
    left: 50%;
    top: 55%;
    width: 106px;
    height: 106px;
    border: 2px solid rgba(128, 222, 234, 0.48);
    border-radius: 50%;
    background:
        radial-gradient(circle,
            rgba(128, 222, 234, 0.16) 0 23%,
            transparent 24% 41%,
            rgba(128, 222, 234, 0.58) 42% 44%,
            transparent 45% 77%,
            rgba(255, 171, 0, 0.72) 78% 80%,
            transparent 81%),
        radial-gradient(circle, rgba(21, 67, 85, 0.46), rgba(3, 17, 28, 0.58));
    box-shadow: inset 0 0 20px rgba(0, 229, 255, 0.16), 0 0 16px rgba(0, 229, 255, 0.12);
    transform: translate(-50%, -50%);
}

.stick-base::before,
.stick-base::after {
    content: '';
    position: absolute;
    background: rgba(128, 222, 234, 0.2);
}

.stick-base::before { left: 50%; top: 9px; bottom: 9px; width: 1px; }
.stick-base::after { top: 50%; left: 9px; right: 9px; height: 1px; }

.stick-knob {
    --stick-x: 0px;
    --stick-y: 0px;
    position: absolute;
    left: calc(50% + var(--stick-x));
    top: calc(50% + var(--stick-y));
    width: 42px;
    height: 42px;
    border: 2px solid #dffaff;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #b2ebf2, #00acc1 70%, #006064);
    box-shadow: 0 0 16px rgba(0, 229, 255, 0.65);
    transform: translate(-50%, -50%);
}

.mobile-action {
    min-width: 62px;
    min-height: 42px;
    padding: 7px 5px;
    color: #e8fbff;
    border: 1px solid rgba(128, 222, 234, 0.48);
    border-radius: 7px;
    background: linear-gradient(145deg, rgba(9, 47, 62, 0.92), rgba(2, 13, 24, 0.9));
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.42), inset 0 0 10px rgba(0, 229, 255, 0.08);
    font: 700 9px monospace;
    letter-spacing: 0.6px;
    touch-action: none;
}

.mobile-action:active,
.mobile-action.active {
    color: #07121d;
    background: #80deea;
    box-shadow: 0 0 20px rgba(128, 222, 234, 0.7);
}

.orbit-action {
    position: absolute;
    z-index: 4;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    color: #e8fbff;
    border: 2px solid rgba(128, 222, 234, 0.7);
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, rgba(32, 108, 128, 0.96), rgba(2, 20, 32, 0.96));
    box-shadow: 0 0 14px rgba(0, 229, 255, 0.24), inset 0 0 9px rgba(0, 229, 255, 0.18);
    font: 800 16px monospace;
    touch-action: none;
}

.orbit-action:active {
    color: #07121d;
    background: #80deea;
    box-shadow: 0 0 22px rgba(128, 222, 234, 0.8);
}

#mobile-aim-stick .orbit-missile {
    left: 50%;
    top: -4px;
    transform: translate(-50%, -50%);
    color: #fff176;
    border-color: rgba(255, 234, 0, 0.8);
}

#mobile-aim-stick .orbit-bomb {
    right: -6px;
    top: 55%;
    transform: translate(50%, -50%);
    color: #ffcc80;
    border-color: rgba(255, 171, 0, 0.8);
}

#mobile-aim-stick .orbit-weapon {
    left: -8px;
    top: 55%;
    transform: translate(-50%, -50%);
    color: #b2ebf2;
}

#mobile-pause {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    min-width: 42px;
    width: 42px;
    height: 38px;
    padding: 0;
    color: #ffd740;
    border-color: rgba(255, 215, 64, 0.6);
    pointer-events: auto;
    font-size: 15px;
}

.mobile-start-controls { display: none; }
body.mobile-device .desktop-controls { display: none; }
body.mobile-device .mobile-start-controls { display: block; }
.mobile-install-tip { max-width: 340px; color: #7f9da5 !important; font-size: 10px !important; line-height: 1.45 !important; }

body.mobile-device #hud-top {
    grid-template-columns: 1fr auto;
    padding: 10px 12px;
}
body.mobile-device #hp-bar-container { width: min(210px, 42vw); }
body.mobile-device #shield-bar-container { left: 12px; top: 38px; width: min(210px, 42vw); }
body.mobile-device #stamina-bar-container { left: 12px; top: 56px; width: min(210px, 42vw); }
body.mobile-device #stage-display { display: none; }
body.mobile-device #weapons-display {
    left: calc(8px + env(safe-area-inset-left));
    top: 43%;
    bottom: auto;
    transform: translateY(-50%);
    max-width: 31vw;
    justify-content: flex-start;
}
body.mobile-device .weapon-icon {
    min-width: 44px;
    height: 24px;
    gap: 3px;
    padding: 2px 4px;
    font-size: 8px;
    letter-spacing: 0.2px;
}
body.mobile-device .weapon-icon strong { font-size: 9px; }
body.mobile-device #score-display { grid-column: 2; }
body.mobile-device #abilities-display { display: none; }
body.mobile-device #relics-display {
    bottom: calc(174px + env(safe-area-inset-bottom));
    max-width: 38vw;
}
body.mobile-device #powerups-display {
    left: auto;
    right: calc(8px + env(safe-area-inset-right));
    top: 43%;
    bottom: auto;
    transform: translateY(-50%);
    max-width: 24vw;
    justify-content: flex-end;
}
body.mobile-device .powerup-icon {
    width: 32px;
    height: 32px;
    font-size: 15px;
}
body.mobile-device #boss-hp-container {
    top: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: min(400px, 42vw);
    max-width: calc(100vw - 20px);
}
body.mobile-device #boss-hp-container #boss-name { order: 1; margin-bottom: 0; font-size: 10px; letter-spacing: 1.5px; }
body.mobile-device #boss-hp-container #boss-objective { order: 2; min-height: 12px; margin-top: 0; font-size: 9px; }
body.mobile-device #boss-hp-container #boss-hp-bar { order: 3; width: 100%; }
body.mobile-device #boss-hp-container #boss-parts-status { order: 4; margin-top: 1px; }

#start-screen, #game-over-screen, #victory-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(5, 5, 15, 0.92);
    z-index: 100;
    pointer-events: auto;
}

#start-screen h1 {
    color: #ffd740;
    font-size: clamp(28px, 5vw, 52px);
    text-shadow: 0 0 30px rgba(255, 215, 64, 0.6), 0 0 60px rgba(255, 215, 64, 0.3);
    margin-bottom: 10px;
}

#start-screen h2 {
    color: #80deea;
    font-size: 24px;
    margin-bottom: 40px;
    text-shadow: 0 0 15px rgba(128, 222, 234, 0.4);
}

.controls {
    color: #aaa;
    font-size: 16px;
    margin-bottom: 40px;
    text-align: center;
    line-height: 2;
}

.controls p {
    color: #ccc;
}

.controls p strong {
    color: #ffd740;
}

button {
    padding: 15px 50px;
    font-size: 20px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#start-btn {
    background: linear-gradient(135deg, #ffd740, #ffab00);
    color: #1a1a2e;
    box-shadow: 0 0 30px rgba(255, 215, 64, 0.3);
}

#start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 50px rgba(255, 215, 64, 0.5);
}

#restart-btn, #play-again-btn {
    background: linear-gradient(135deg, #ff5252, #d32f2f);
    color: white;
    box-shadow: 0 0 30px rgba(255, 82, 82, 0.3);
}

#restart-btn:hover, #play-again-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 50px rgba(255, 82, 82, 0.5);
}

#game-over-screen h1, #victory-screen h1 {
    font-size: 56px;
    margin-bottom: 20px;
}

#game-over-screen h1 {
    color: #ff5252;
    text-shadow: 0 0 30px rgba(255, 82, 82, 0.5);
}

#victory-screen h1 {
    color: #ffd740;
    text-shadow: 0 0 30px rgba(255, 215, 64, 0.5), 0 0 60px rgba(255, 215, 64, 0.2);
}

#final-score, #victory-score {
    color: #ffd740;
    font-size: 28px;
    margin-bottom: 10px;
}

#victory-screen p {
    color: #aaa;
    font-size: 18px;
    margin-bottom: 30px;
}

@media (max-width: 760px) {
    #hud-top {
        grid-template-columns: 1fr auto;
        padding: 10px 12px;
    }
    #hp-bar-container { width: 210px; }
    #shield-bar-container { left: 12px; top: 38px; width: 210px; }
    #stamina-bar-container { left: 12px; top: 56px; width: 210px; }
    #stage-display { display: none; }
    #weapons-display {
        left: calc(10px + env(safe-area-inset-left));
        bottom: calc(250px + env(safe-area-inset-bottom));
        max-width: 42vw;
    }
    #score-display { grid-column: 2; }
    #abilities-display { right: 10px; bottom: 10px; min-width: 155px; }
    #relics-display { left: 10px; bottom: 10px; max-width: 42vw; }
    .relic-icon { width: 26px; height: 26px; font-size: 11px; }
    .ability-card { grid-template-columns: 44px 1fr auto; padding: 4px 6px; }
    #boss-hp-container.colossus { bottom: 140px; }
    #start-screen h2 { font-size: 16px; text-align: center; padding: 0 14px; }
    .controls { font-size: 13px; }

    body.mobile-device #abilities-display { display: none; }
    body.mobile-device #relics-display {
        bottom: calc(174px + env(safe-area-inset-bottom));
        max-width: 38vw;
    }
    body.mobile-device #powerups-display {
        left: auto;
        right: calc(8px + env(safe-area-inset-right));
        top: 43%;
        bottom: auto;
        transform: translateY(-50%);
        max-width: 24vw;
    }
    body.mobile-device #boss-hp-container {
        top: auto;
        bottom: calc(12px + env(safe-area-inset-bottom));
        max-width: calc(100vw - 20px);
    }
    body.mobile-device #boss-hp-container.colossus { top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); }
    body.mobile-device .desktop-controls { display: none; }
    body.mobile-device .mobile-start-controls { display: block; }
}

@media (max-width: 420px) {
    #relics-display {
        left: 10px;
        bottom: 150px;
        max-width: calc(100vw - 20px);
    }
}

@media (orientation: portrait) and (max-width: 900px) {
    body.mobile-device #orientation-hint { display: flex; }
}

@media (max-width: 700px) and (orientation: landscape) {
    body.mobile-device #boss-hp-container {
        top: auto;
        bottom: calc(148px + env(safe-area-inset-bottom));
        width: calc(100vw - 24px);
    }
    body.mobile-device #boss-hp-container.colossus {
        top: auto;
        bottom: calc(142px + env(safe-area-inset-bottom));
    }
}

@media (max-height: 430px) and (orientation: landscape) {
    .mobile-stick {
        width: 126px;
        height: 126px;
        bottom: calc(8px + env(safe-area-inset-bottom));
    }
    .stick-base { width: 92px; height: 92px; }
    .stick-knob { width: 36px; height: 36px; }
    .orbit-action { width: 42px; height: 42px; min-width: 42px; min-height: 42px; }
    .mobile-action { min-height: 34px; padding: 5px 3px; }
}
