:root {
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
    background: #000;
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    font-family: 'Segoe UI', 'Arial', sans-serif;
    height: 100dvh;
    width: 100vw;
    position: fixed;
    top: 0;
    left: 0;
}

@media (orientation: portrait) and (pointer: coarse) and (max-width: 600px) and (min-height: 700px) {
    html,
    body {
        width: 100dvh;
        height: 100dvw;
        min-width: 100dvh;
        min-height: 100dvw;
    }

    body {
        transform: rotate(90deg) translateY(-100%);
        transform-origin: top left;
    }

    #gameCanvas,
    #hud,
    .menu,
    .gacha-panel,
    .drone-select-overlay {
        width: 100dvh;
        height: 100dvw;
    }
}

#gameCanvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#hud {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

body.main-menu-active #gameCanvas {
    visibility: hidden;
}

body.main-menu-active #hud > *:not(#cargo-status) {
    display: none;
}

body.main-menu-active #cargo-status {
    opacity: 0;
}

body.pause-active #hud {
    filter: brightness(0.45);
}

#crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    pointer-events: none;
}

#crosshair::before,
#crosshair::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.8);
}

#crosshair::before {
    width: 2px;
    height: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 1px;
}

#crosshair::after {
    height: 2px;
    width: 100%;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 1px;
}

#crosshair .dot {
    position: absolute;
    width: 6px;
    height: 6px;
    background: #ff4444;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 8px #ff4444;
}

#cargo-status {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #555;
    border-radius: 25px;
    padding: 8px 20px;
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    letter-spacing: 1px;
    text-align: center;
    transition: all 0.3s;
    pointer-events: none;
}

#objective-hint {
    position: absolute;
    top: 18px;
    left: 50%;
    transform: translateX(-50%);
    max-width: min(680px, calc(100vw - 360px));
    padding: 10px 18px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 4px;
    color: #fff;
    background: rgba(0, 0, 0, 0.58);
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.85);
    pointer-events: none;
}

#cargo-status.loaded {
    border-color: #4caf50;
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.4);
}

#cargo-status.empty {
    border-color: #f44336;
    box-shadow: 0 0 15px rgba(244, 67, 54, 0.4);
    animation: pulse-empty 1.2s infinite;
}

#cargo-status.reloading {
    border-color: #ff9800;
    box-shadow: 0 0 20px rgba(255, 152, 0, 0.6);
    animation: pulse-reload 0.5s infinite;
}

@keyframes pulse-empty {
    0%,
    100% {
        box-shadow: 0 0 10px rgba(244, 67, 54, 0.3);
    }
    50% {
        box-shadow: 0 0 25px rgba(244, 67, 54, 0.7);
    }
}

@keyframes pulse-reload {
    0%,
    100% {
        box-shadow: 0 0 15px rgba(255, 152, 0, 0.4);
    }
    50% {
        box-shadow: 0 0 30px rgba(255, 152, 0, 0.9);
    }
}

#score-display {
    position: absolute;
    top: 18px;
    right: 20px;
    color: #fff;
    font-size: 28px;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.8);
    pointer-events: none;
    letter-spacing: 1px;
}

#info-text {
    position: absolute;
    top: 18px;
    left: 24px;
    color: #fff;
    font-size: 17px;
    pointer-events: none;
    line-height: 1.42;
    font-weight: 700;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.95), 0 1px 2px rgba(0, 0, 0, 0.9);
}

#altitude-display {
    position: absolute;
    top: 54px;
    right: 20px;
    left: auto;
    color: #00ff00;
    font-size: 18px;
    font-weight: bold;
    pointer-events: none;
    line-height: 1.5;
    text-shadow: 0 0 8px rgba(0, 255, 0, 0.8);
    background-color: rgba(0, 0, 0, 0.42);
    padding: 5px 10px;
    border-radius: 4px;
}

#wind-display {
    position: absolute;
    top: 108px;
    right: 20px;
    color: #9ed8ff;
    font-size: 18px;
    font-weight: bold;
    pointer-events: none;
    text-shadow: 0 0 8px rgba(0, 80, 180, 0.8);
    background-color: rgba(0, 0, 0, 0.35);
    padding: 5px 10px;
    border-radius: 4px;
}

#wind-display.strong {
    color: #ffdf6e;
    text-shadow: 0 0 10px rgba(255, 190, 40, 0.9);
}

#drone-hp {
    position: absolute;
    top: 144px;
    right: 20px;
    width: 170px;
    pointer-events: none;
    color: #fff;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.85);
}

#damage-flash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.16s ease;
}

#damage-flash.hit {
    opacity: 1;
    background: radial-gradient(circle, rgba(255, 255, 255, 0) 42%, rgba(255, 0, 0, 0.42) 100%);
    box-shadow: inset 0 0 90px rgba(255, 0, 0, 0.65);
}

#damage-flash.miss {
    opacity: 1;
    background: linear-gradient(90deg, transparent, rgba(255, 220, 80, 0.18), transparent);
}

#under-fire {
    position: absolute;
    top: 17%;
    left: 50%;
    transform: translateX(-50%);
    padding: 7px 18px;
    border: 1px solid rgba(255, 80, 70, 0.8);
    border-radius: 4px;
    color: #fff;
    background: rgba(140, 0, 0, 0.68);
    font-size: 19px;
    font-weight: 800;
    letter-spacing: 1px;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.9);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
}

#under-fire.visible {
    opacity: 1;
}

#combat-callout {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8vw;
    color: #fff;
    font-size: clamp(28px, 4.8vw, 68px);
    font-weight: 900;
    line-height: 1.05;
    text-align: center;
    text-transform: uppercase;
    text-shadow: 0 0 18px rgba(0, 0, 0, 0.95), 0 0 32px rgba(255, 90, 20, 0.65);
    opacity: 0;
    transform: scale(0.96);
    transition: opacity 0.16s ease, transform 0.16s ease;
    pointer-events: none;
}

#combat-callout.visible {
    opacity: 1;
    transform: scale(1);
}

#combat-callout.good {
    color: #fff1a8;
}

#combat-callout.bad {
    color: #ff8a7a;
}

#drone-hp-text {
    margin-bottom: 4px;
    font-size: 15px;
    font-weight: bold;
    text-align: right;
}

#drone-hp-track {
    width: 100%;
    height: 12px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.55);
}

@media (max-width: 900px) {
    #objective-hint {
        top: 86px;
        max-width: calc(100vw - 36px);
        font-size: 17px;
    }

    #info-text {
        font-size: 15px;
    }

    #score-display {
        font-size: 22px;
    }

    #altitude-display,
    #wind-display {
        font-size: 15px;
    }
}

#drone-hp-fill {
    width: 100%;
    height: 100%;
    border-radius: 4px;
    background: #41d35f;
    box-shadow: 0 0 10px rgba(65, 211, 95, 0.45);
    transition: width 0.18s ease, background 0.18s ease;
}

#drone-hp-fill.medium {
    background: #ffb02e;
    box-shadow: 0 0 10px rgba(255, 176, 46, 0.5);
}

#drone-hp-fill.low {
    background: #f44336;
    box-shadow: 0 0 12px rgba(244, 67, 54, 0.55);
}

.health-bar-container {
    position: absolute;
    pointer-events: none;
    transform: translate(-50%, -100%);
    width: 50px;
    height: 6px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    overflow: hidden;
}

.health-bar-fill {
    height: 100%;
    background: #f44336;
    border-radius: 2px;
    transition: width 0.2s;
}

.health-bar-fill.medium {
    background: #ff9800;
}

.health-bar-fill.low {
    background: #f44336;
}

#mobile-controls {
    position: fixed;
    bottom: calc(20px + var(--safe-bottom));
    left: 0;
    width: 100%;
    pointer-events: none;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 20px;
    gap: 16px;
}

#mobile-action-buttons {
    display: flex;
    align-items: center;
    gap: 14px;
    pointer-events: auto;
}

#joystick-zone {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.2);
    position: relative;
    pointer-events: auto;
    touch-action: none;
}

#joystick-thumb {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.2);
}

#drop-btn {
    width: 92px;
    height: 92px;
    border-radius: 50%;
    background: rgba(244, 67, 54, 0.7);
    border: 3px solid rgba(255, 255, 255, 0.5);
    pointer-events: auto;
    touch-action: manipulation;
    font-weight: bold;
    color: #fff;
    font-size: 13px;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.2;
    box-shadow: 0 0 25px rgba(244, 67, 54, 0.5);
    transition: all 0.15s;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

#altitude-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: auto;
}

#altitude-buttons button {
    width: 84px;
    height: 58px;
    border-radius: 14px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    background: rgba(40, 120, 220, 0.72);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    touch-action: none;
    box-shadow: 0 0 18px rgba(50, 130, 255, 0.28);
}

#altitude-buttons button:active {
    transform: scale(0.94);
    background: rgba(65, 150, 255, 0.9);
}

#drop-btn:active {
    background: rgba(200, 30, 30, 0.9);
    transform: scale(0.9);
    box-shadow: 0 0 40px rgba(255, 50, 50, 0.8);
}

#drop-btn.disabled {
    background: rgba(100, 100, 100, 0.5);
    border-color: rgba(150, 150, 150, 0.3);
    box-shadow: none;
    pointer-events: none;
}

#camera-hint {
    position: absolute;
    right: 25px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.5);
    font-size: 11px;
    pointer-events: none;
    text-align: center;
    letter-spacing: 1px;
}

@media (min-width: 1025px) {
    #mobile-controls {
        display: none;
    }
    #cargo-status {
        bottom: 30px;
    }
    #camera-hint {
        display: none;
    }
}

@media (max-width: 1024px) {
    #crosshair {
        width: 30px;
        height: 30px;
    }
    #crosshair .dot {
        width: 4px;
        height: 4px;
    }
    #cargo-status {
        bottom: 130px;
        font-size: 12px;
        padding: 6px 14px;
    }

    #altitude-display,
    #wind-display,
    #drone-hp {
        left: 20px;
        right: auto;
        width: 180px;
        box-sizing: border-box;
    }

    #altitude-display {
        top: auto;
        bottom: calc(240px + var(--safe-bottom));
    }

    #wind-display {
        top: auto;
        bottom: calc(198px + var(--safe-bottom));
    }

    #drone-hp {
        top: auto;
        bottom: calc(145px + var(--safe-bottom));
    }

    #drone-hp-text {
        text-align: left;
        font-size: 13px;
    }

    #drone-hp-track {
        height: 10px;
    }

    #camera-hint {
        display: none;
    }
}
