.cheat-toggle {
    position: absolute;
    bottom: 24px;
    left: 24px;
    top: auto;
    right: auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: radial-gradient(circle at 30% 30%, #ffe4e6, #fbcfe8);
    box-shadow: 0 4px 10px rgba(0, 0, 0, .15), 0 0 0 2px rgba(255, 255, 255, .6) inset;
    color: #7c2d12;
    font-size: 18px;
    line-height: 36px;
    text-align: center;
    cursor: pointer;
    z-index: 20
}

.cheat-toggle:hover {
    transform: translateY(-1px)
}

.cheat-toggle.active {
    box-shadow: 0 6px 14px rgba(16, 185, 129, .3), 0 0 0 2px rgba(16, 185, 129, .5) inset;
    animation: cheatPulse 1.2s ease-in-out infinite
}

@keyframes cheatPulse {
    0% {
        filter: drop-shadow(0 0 0 rgba(16, 185, 129, 0))
    }

    50% {
        filter: drop-shadow(0 0 8px rgba(16, 185, 129, .6))
    }

    100% {
        filter: drop-shadow(0 0 0 rgba(16, 185, 129, 0))
    }
}

body,
html {
    height: 100%;
    margin: 0;
    background: #0c1118;
    color: #1d2a2f;
    font-family: LongToday, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    overflow: hidden;
    user-select: none
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(160deg, #b8fff3 0, #fff7e6 42%, #ffe6cf 100%)
}

#game-viewport {
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0 auto;
    overflow: hidden;
    background: #000;
    /* Letterbox color */
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}

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

#hud-top-left {
    position: absolute;
    top: 12px;
    left: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}

#hud-top-right {
    position: absolute;
    top: 12px;
    right: 14px;
    z-index: 15;
    text-align: right;
    /* Ensure distance doesn't overlap radar (bottom right) */
}

.hud-absolute {
    position: absolute;
}

.chip {
    background: rgba(255, 255, 255, .75);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(0, 0, 0, .06);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .06);
    border-radius: 999px;
    padding: 6px 12px;
    font-weight: 700;
    color: #093a36;
    display: inline-block;
}

/* Custom Positions */
#lives-container {
    top: 100px;
    left: 14px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    max-width: 150px;
    pointer-events: none;
}

.life-heart {
    font-size: 24px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

#ammo-container {
    top: 50%;
    left: 14px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 2px;
    pointer-events: none;
}

.ammo-spear {
    font-size: 24px;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    transform: rotate(45deg);
}

#relics-container {
    top: 200px;
    right: 14px;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(4px);
    padding: 6px 12px;
    border-radius: 99px;
    font-weight: 700;
    color: #b45309;
    border: 1px solid rgba(180, 83, 9, 0.2);
}

#air-container {
    top: 20px;
    left: 50%;
    bottom: auto;
    transform: translateX(-50%);
    background: rgba(14, 165, 183, 0.85);
    /* More opaque for visibility */
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #ffffff;
    padding: 6px 16px;
    border-radius: 99px;
    font-weight: 800;
    font-size: 18px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    box-shadow: 0 4px 12px rgba(14, 165, 183, 0.3);
    z-index: 50;
    transition: opacity 0.3s;
}

.hidden {
    display: none !important;
}

/* Fire Button */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.btn-fire {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.5);
    /* Semi-transparent red */
    border: 2px solid rgba(255, 255, 255, 0.6);
    color: white;
    font-size: 14px;
    font-weight: 800;
    text-transform: uppercase;
    backdrop-filter: blur(4px);
    box-shadow: 0 8px 32px rgba(220, 38, 38, 0.25);
    cursor: pointer;
    display: grid;
    place-items: center;
    pointer-events: auto;
    transition: transform 0.1s ease;
}

.btn-fire:active {
    transform: scale(0.92);
    background: rgba(239, 68, 68, 0.75);
}

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.85);
    text-align: center;
    color: #143e3a;
    transition: opacity .3s ease;
    z-index: 3000
}

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

.panel {
    width: min(680px, 92vw);
    background: #ffffff;
    border: 1px solid #e5f2f0;
    border-radius: 16px;
    padding: 50px 30px 40px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .15);
    position: relative;
    z-index: 21;
    min-height: 200px
}

.panel h1 {
    margin: 0 0 8px;
    font-weight: 700
}

.panel p {
    margin: 6px 0 18px;
    color: #305a56
}

.overlay .panel .credits {
    color: #083a30
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    position: relative;
    z-index: 50
}

.btn {
    position: relative;
    z-index: 2000;
    pointer-events: auto;
    appearance: none;
    border: 1px solid #0f766e;
    background: #159e91;
    color: #fff;
    border-radius: 12px;
    font-weight: 700;
    letter-spacing: .2px;
    padding: 10px 16px;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, background .2s ease
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, .12);
    background: #128d82
}

.btn.secondary {
    background: #fbbf24;
    border-color: #f59e0b;
    color: #1c1917
}

.btn.ghost {
    background: #fff;
    border-color: #e2e8f0;
    color: #0f172a
}

[data-hs] {
    position: relative;
    z-index: 5
}

.toggles {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    margin: 8px 0 0
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    padding: 6px 10px
}

.toggle input {
    accent-color: #10b981
}

.cta-ribbon {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    margin-top: 14px
}

.cta-ribbon a {
    text-decoration: none;
    color: #0f2e2a;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 9px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center
}

.cta-ribbon a:hover {
    box-shadow: 0 12px 28px rgba(0, 0, 0, .08);
    transform: translateY(-1px)
}

.mobile-controls {
    position: absolute;
    bottom: 18px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 14px;
    pointer-events: none
}

.mobile-controls .btn {
    width: 60px;
    height: 60px;
    padding: 0;
    border-radius: 50%;
    font-size: 24px;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s, background 0.1s;
}

.mobile-controls .btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

.toast {
    position: absolute;
    top: 18px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    background: rgba(255, 255, 255, .9);
    border: 1px solid #e2e8f0;
    color: #0f2e2a;
    border-radius: 12px;
    padding: 8px 14px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .12);
    transition: opacity .25s ease
}

.toast.hidden {
    opacity: 0;
    pointer-events: none
}

.game-settings {
    position: absolute;
    top: 64px;
    right: 16px;
    left: auto;
    transform: none;
    display: grid;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, .78);
    border: 1px solid rgba(0, 0, 0, .07);
    backdrop-filter: blur(10px);
    box-shadow: 0 14px 40px rgba(0, 0, 0, .12);
    z-index: 3001;
    pointer-events: auto;
    color: #0f2e2a;
    width: 190px
}

.game-settings.hidden {
    display: none !important
}

.game-settings .settings-title {
    font-weight: 800;
    letter-spacing: .6px;
    text-transform: uppercase;
    font-size: 11px;
    opacity: .8;
    text-align: center
}

.game-settings .settings-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    font-size: 12px;
    font-weight: 700
}

.game-settings select {
    appearance: none;
    border: 1px solid rgba(15, 118, 110, .25);
    border-radius: 999px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, .9);
    color: #0f2e2a;
    font-weight: 800;
    letter-spacing: .2px;
    cursor: pointer
}

.game-settings select:focus {
    outline: 2px solid rgba(15, 118, 110, .35);
    outline-offset: 2px
}

.sound-toggle {
    position: absolute;
    right: 16px;
    bottom: 84px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, .55);
    color: #fff;
    font-size: 20px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
    cursor: pointer;
    z-index: 30
}

.sound-toggle:hover {
    background: rgba(0, 0, 0, .7)
}

.sound-toggle.muted {
    background: rgba(30, 30, 30, .7);
    color: #bbb
}

@media (max-width:640px) {
    .panel {
        padding: 80px 16px 20px;
        max-height: 85vh;
        overflow-y: auto;
        width: 90vw;
    }

    .panel h1 {
        font-size: 22px;
        margin-bottom: 6px;
    }

    .panel p {
        font-size: 13px;
        margin: 4px 0 12px;
        line-height: 1.4;
    }

    .panel .btn {
        padding: 8px 12px;
        font-size: 13px;
    }

    .game-settings {
        top: 10px;
        right: 10px;
        width: auto;
        transform: scale(0.85);
        transform-origin: top right;
        padding: 6px 10px;
        background: rgba(255, 255, 255, 0.95);
    }

    .game-settings .settings-title {
        display: none;
        /* Hide title to save space */
    }

    .cta-ribbon {
        margin-top: 10px;
        gap: 6px;
    }

    .cta-ribbon a {
        padding: 6px 8px;
        font-size: 12px;
    }

    /* Scaling HUD Elements for Mobile */
    #lives-container {
        transform: scale(0.7);
        transform-origin: top left;
        top: 80px;
        left: 10px;
    }

    #ammo-container {
        transform: translateY(-50%) scale(0.7);
        transform-origin: left center;
        left: 10px;
    }

    #relics-container,
    #air-container {
        transform: scale(0.75);
        transform-origin: top right;
        right: 10px;
    }

    /* Attempt to target common absolute positioned HUD elements (like Radar) */
    .hud-absolute {
        max-width: 80vw;
        /* Prevent overflow */
    }


}

#distance {
    display: none !important;
}

/* Win Banner Styles */
.win-banner {
    margin-top: 10px;
    background: #ef4444;
    color: white;
    padding: 12px;
    border-radius: 8px;
    display: inline-block;
    font-size: 18px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.win-subtext {
    font-size: 14px;
    opacity: 0.9;
}

@media (max-width: 640px) {
    .win-banner {
        padding: 6px;
        font-size: 11px;
        /* Significantly reduced */
        line-height: 1.4;
        width: 100%;
        /* Ensure it doesn't overflow horizontally */
        box-sizing: border-box;
        white-space: normal;
        /* Force wrapping */
        word-wrap: break-word;
    }

    .win-banner strong {
        font-size: 13px;
        /* Keep key info slightly larger */
    }

    .win-subtext {
        display: block;
        margin-top: 4px;
        font-size: 9px;
        /* Very small for subtext */
        line-height: 1.2;
    }
}

/* Landscape / Short Screen Optimizations */
@media (max-height: 600px) {
    .panel {
        padding: 10px 16px;
        /* Minimal padding */
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    /* REORDERING: Prioritize Highscore Input */
    .panel .h1,
    .panel p {
        order: -2;
        /* Top */
    }

    .panel [data-hs] {
        order: -1;
        /* Below text, above buttons */
        margin-top: 4px !important;
        max-height: 160px !important;
        /* Compact list */
    }

    .panel .btn-row {
        order: 0;
        /* Middle */
        margin-top: 6px !important;
    }

    .panel .cta-ribbon {
        order: 1;
        /* Bottom */
        margin-top: 6px;
        gap: 6px;
        grid-template-columns: repeat(2, 1fr);
        /* Force side-by-side */
    }

    .panel #credits {
        order: 2;
        /* Very bottom */
    }

    .panel h1 {
        font-size: 18px;
        margin-bottom: 4px;
    }

    .panel p {
        margin: 4px 0 8px;
        font-size: 12px;
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        line-clamp: 3;
        /* Limit lines if really needed */
        -webkit-box-orient: vertical;
    }

    .win-banner {
        margin-top: 4px;
        padding: 6px;
        font-size: 11px;
    }

    .win-subtext {
        display: none;
        /* Hide subtext on very short screens to save space */
    }

    .cta-ribbon a {
        padding: 4px 8px;
        font-size: 11px;
        height: 28px;
        /* Fixed height compact */
    }

    .game-settings {
        transform: scale(0.7);
        top: 4px;
        right: 4px;
    }

    /* Ensure scrollability if still too tall */
    .panel {
        max-height: 95vh;
        overflow-y: auto;
    }
}