:root {
    --bg-color: #000;
    --text-color: #fff;
    --border-color: #fff;
    --overlay-bg: rgba(0, 0, 0, 0.92);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'VT323', 'Courier New', Courier, monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

#game-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
}

/* ─── 16:9 Stage (Aspect Ratio Locked for Itch.io Iframes & Displays) ─── */
#stage {
    position: relative;
    aspect-ratio: 16 / 9;
    width: min(100%, calc(100vh * 16 / 9));
    height: min(100%, calc(100vw * 9 / 16));
    max-width: 100%;
    max-height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    background-color: var(--bg-color);
    border: 2px solid var(--border-color);
    display: block;
    width: 100%;
    height: 100%;
}

/* ─── HUD (Pinned to Stage Bounding Box) ─── */
.hud-panel {
    position: absolute;
    top: clamp(10px, 2vmin, 20px);
    pointer-events: none;
    font-size: clamp(20px, 3.2vmin, 36px);
    color: var(--text-color);
    line-height: 1.3;
    z-index: 5;
    text-shadow: 0 0 6px rgba(255, 255, 255, 0.5), 0 2px 4px #000;
    letter-spacing: 1.5px;
}

#hud-left  { left: clamp(12px, 2.5vmin, 28px); }
#hud-right { right: clamp(12px, 2.5vmin, 28px); text-align: right; }

.hud-item {
    margin-bottom: 2px;
}

.hud-score, .hud-hi {
    letter-spacing: 2px;
}

#score-value, #hi-score {
    font-weight: bold;
    letter-spacing: 3px;
}

#lives-value {
    letter-spacing: 6px;
    font-size: 1.1em;
    color: #fff;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.7);
}

.hud-weapon {
    font-size: 0.9em;
    color: #bbb;
    margin-top: 4px;
}

#weapon-value {
    color: #fff;
    font-weight: bold;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.7);
}

/* ─── Overlays ─── */
.overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: var(--overlay-bg);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    gap: 10px;
}
.overlay.active { display: flex; }

.overlay h1 {
    font-size: clamp(42px, 8vmin, 86px);
    margin: 0 0 8px;
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 6px;
    text-shadow: 0 0 16px rgba(255, 255, 255, 0.6);
}

.overlay p {
    font-size: clamp(18px, 2.8vmin, 30px);
    margin: 4px 0;
    letter-spacing: 1.5px;
    text-align: center;
}

/* ─── Menu & Game Over high-score list ─── */
#menu-highscores, #game-over-highscores {
    margin: 8px 0 14px;
    text-align: center;
    font-size: clamp(20px, 3vmin, 32px);
    min-width: clamp(240px, 38vmin, 380px);
}
.hs-title {
    font-size: clamp(18px, 2.5vmin, 26px);
    color: #888;
    margin-bottom: 4px;
    letter-spacing: 2px;
}
#menu-hs-list, #game-over-hs-list {
    list-style: none;
    padding: 0; margin: 0;
}
#menu-hs-list li, #game-over-hs-list li {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    padding: 2px 0;
}
#menu-hs-list li.hs-top, #game-over-hs-list li.hs-top { color: #fff; }
#game-over-hs-list li.hs-current {
    color: #fff;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.9);
}

/* ─── Initials entry ─── */
#initials-entry { text-align: center; margin: 6px 0; }
#initials-boxes { display: flex; gap: 10px; justify-content: center; margin: 10px 0; }

.initial-box {
    width: clamp(48px, 6vmin, 64px);
    height: clamp(56px, 7vmin, 74px);
    background: #000;
    color: #fff;
    border: 2.5px solid #fff;
    font-family: 'VT323', monospace;
    font-size: clamp(38px, 5.5vmin, 52px);
    text-align: center;
    text-transform: uppercase;
    caret-color: transparent;
    outline: none;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}
.initial-box:focus {
    border-color: #fff;
    color: #fff;
    box-shadow: 0 0 16px rgba(255, 255, 255, 0.7);
}

/* ─── Buttons ─── */
button {
    background: #000;
    color: #fff;
    border: 2.5px solid #fff;
    padding: clamp(6px, 1.2vmin, 12px) clamp(18px, 3vmin, 36px);
    font-size: clamp(22px, 3.2vmin, 34px);
    font-family: 'VT323', 'Courier New', Courier, monospace;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
    margin-top: 6px;
}
button:hover, button:focus-visible {
    background: #fff;
    color: #000;
    box-shadow: 0 0 16px rgba(255, 255, 255, 0.8);
    outline: none;
}

#save-score-btn {
    font-size: clamp(20px, 2.6vmin, 28px);
    padding: 6px 20px;
}

/* ─── Clean Mobile Touch Controls (Hidden on Desktop) ─── */
#touch-controls {
    display: none; /* Desktop default: completely invisible */
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 6;
    touch-action: none;
}

/* Only display touch controls on touch-enabled screens */
@media (hover: none) and (pointer: coarse) {
    #touch-controls {
        display: block;
    }
}

.touch-btn {
    pointer-events: auto;
    position: absolute;
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    border: 1.5px solid rgba(255, 255, 255, 0.5);
    font-family: 'VT323', monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0.45;
    transition: opacity 0.1s, background-color 0.1s;
    padding: 0;
    margin: 0;
    touch-action: none;
}
.touch-btn:active {
    opacity: 0.9;
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.touch-pause {
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 44px;
    height: 38px;
    font-size: 20px;
    border-radius: 4px;
}

.touch-group {
    position: absolute;
    bottom: 20px;
    display: flex;
    gap: 14px;
    pointer-events: none;
}

.touch-left {
    left: 18px;
}
.touch-left .touch-btn {
    width: 58px;
    height: 58px;
    font-size: 26px;
    border-radius: 50%;
}

.touch-right {
    right: 18px;
}
.touch-right .touch-btn {
    width: 62px;
    height: 62px;
    font-size: 24px;
    border-radius: 50%;
}

.touch-fire {
    font-size: 22px;
    border-color: rgba(255, 255, 255, 0.7);
}
