:root {
    --accent: #00FFAA;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body {
    background: #000;
    overflow: hidden;
    font-family: 'Courier New', Courier, monospace;
    color: #fff;
    overscroll-behavior: none;
    height: 100vh;
    height: 100dvh;
}
canvas#game {
    display: block;
    touch-action: none;
}

#hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 0.8rem calc(1.5rem + env(safe-area-inset-right, 0px)) 0.8rem calc(1.5rem + env(safe-area-inset-left, 0px));
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 0.9rem;
    letter-spacing: 0.1em;
    pointer-events: none;
    z-index: 10;
    background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}

#effects-display {
    position: fixed;
    top: 2.8rem;
    left: calc(1.5rem + env(safe-area-inset-left, 0px));
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    pointer-events: none;
    z-index: 10;
}

.hud-home {
    position: fixed;
    top: 0.6rem;
    left: calc(1rem + env(safe-area-inset-left, 0px));
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1.5px solid #444;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    pointer-events: auto;
    z-index: 25;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.hud-home:hover {
    border-color: var(--accent);
    background: rgba(0, 255, 170, 0.08);
    box-shadow: 0 0 10px rgba(0, 255, 170, 0.2);
}

.hud-home svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: #888;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke 0.2s;
}

.hud-home:hover svg { stroke: var(--accent); }

/* Fullscreen toggle — replaces the home button on games that want a
   fullscreen entry point instead (Iron Clash, etc.). Pinned to the
   bottom-right corner so it never overlaps the HUD readouts (score,
   wave, lives) that anchor the top of the screen. */
.hud-fullscreen {
    position: fixed;
    bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px));
    right: calc(1rem + env(safe-area-inset-right, 0px));
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1.5px solid #444;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    color: #888;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s, color 0.2s;
    z-index: 20;
}
.hud-fullscreen:hover,
.hud-fullscreen:focus-visible {
    border-color: var(--accent);
    background: rgba(0, 255, 170, 0.08);
    box-shadow: 0 0 10px rgba(0, 255, 170, 0.2);
    color: var(--accent);
    outline: none;
}
.hud-fullscreen svg {
    width: 14px;
    height: 14px;
}

/* Icon swap: show only the relevant glyph for the current state.
   Using class toggle on the button (not the `hidden` attribute on
   the SVGs) because the attribute can be flaky inside flex parents
   in some browsers. */
.hud-fullscreen .icon-exit { display: none; }
.hud-fullscreen.is-fullscreen .icon-enter { display: none; }
.hud-fullscreen.is-fullscreen .icon-exit { display: block; }

#overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
    background: rgba(0,0,0,0.7);
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

#overlay.hidden { display: none; }

#overlay h2 {
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 3rem;
    letter-spacing: 0.2em;
    margin-bottom: 0.5rem;
    text-shadow: 0 0 30px rgba(0, 255, 170, 0.3), 0 0 60px rgba(0, 255, 170, 0.1);
}

#overlay p {
    color: #888;
    font-size: 0.95rem;
    margin-bottom: 0.3rem;
}

#overlay .score-display {
    font-size: 1.2rem;
    margin: 1rem 0;
    color: var(--accent);
}

.controls-hint {
    margin-top: 1.5rem;
    color: #555;
    font-size: 0.7rem;
    text-align: center;
    line-height: 1.8;
}

.beta-upsell {
    display: inline-block;
    margin-top: 1.2rem;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 3px;
    background: rgba(0, 255, 170, 0.06);
    text-decoration: none;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    transition: background 0.15s ease;
}

.beta-upsell:hover {
    background: rgba(0, 255, 170, 0.15);
}

/* In-game follow bar — sits at the bottom of the title / game-over
   overlay. Hidden during pause so the resume CTA stays focal. */
.follow-bar-game {
    margin-top: 1.4rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.follow-bar-game-label {
    color: #555;
    font-size: 0.62rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

.follow-bar-game-icons {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.follow-btn-game {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #333;
    background: transparent;
    transition: border-color 0.2s, background 0.2s;
    text-decoration: none;
}

.follow-btn-game:hover,
.follow-btn-game:focus-visible {
    border-color: var(--accent);
    background: rgba(0, 255, 170, 0.05);
}

.follow-btn-game:hover svg path,
.follow-btn-game:focus-visible svg path {
    fill: var(--accent);
}

body.game-paused .follow-bar-game {
    display: none;
}

.noscript-msg {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    color: #888;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    text-align: center;
    padding: 2rem;
    z-index: 100;
}

/* ── Virtual Touch Controls ──────────────────────────────── */
.touch-controls {
    display: none;
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 15;
}

.touch-controls.active {
    display: block;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

.touch-joystick {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.03);
    pointer-events: auto;
    touch-action: none;
}

.touch-joystick-thumb {
    position: absolute;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: 1.5px solid rgba(255,255,255,0.3);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: background 0.1s;
}

.touch-joystick.active .touch-joystick-thumb {
    background: rgba(255,255,255,0.25);
}

.touch-btn {
    position: absolute;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    touch-action: none;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 0.6rem;
    color: rgba(255,255,255,0.4);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    user-select: none;
    -webkit-user-select: none;
}

.touch-btn.active {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.4);
}

.touch-fire {
    width: 64px;
    height: 64px;
}

.touch-reload {
    width: 48px;
    height: 48px;
    font-size: 0.5rem;
}

/* ── Mobile portrait adjustments ────────────────────────── */
@media (max-width: 600px) {
    #hud {
        font-size: 0.7rem;
        gap: 0.4rem 0.6rem;
        flex-wrap: wrap;
        padding: 0.5rem calc(0.8rem + env(safe-area-inset-right, 0px)) 0.5rem calc(0.8rem + env(safe-area-inset-left, 0px));
        padding-left: calc(2.8rem + env(safe-area-inset-left, 0px));
    }
    .hud-home {
        width: 26px;
        height: 26px;
        top: 0.4rem;
        left: calc(0.6rem + env(safe-area-inset-left, 0px));
    }
    .hud-home svg {
        width: 11px;
        height: 11px;
    }
    #overlay {
        padding: calc(1rem + env(safe-area-inset-top, 0px)) calc(1rem + env(safe-area-inset-right, 0px)) calc(1rem + env(safe-area-inset-bottom, 0px)) calc(1rem + env(safe-area-inset-left, 0px));
        overflow-y: auto;
    }
    #overlay h2 {
        font-size: 1.8rem;
        letter-spacing: 0.12em;
        margin-bottom: 0.3rem;
    }
    #overlay p {
        font-size: 0.8rem;
        margin-bottom: 0.2rem;
    }
    #overlay .score-display {
        font-size: 1rem;
        margin: 0.5rem 0;
    }
    .controls-hint {
        margin-top: 0.8rem;
        font-size: 0.6rem;
        line-height: 1.6;
        padding: 0 0.5rem;
    }
    #effects-display {
        top: 2.2rem;
        left: calc(0.8rem + env(safe-area-inset-left, 0px));
        font-size: 0.6rem;
    }
}

/* ── Very small screens / short landscape ──────────────── */
@media (max-height: 500px) {
    #overlay h2 {
        font-size: 1.5rem;
        margin-bottom: 0.2rem;
    }
    #overlay p {
        font-size: 0.75rem;
        margin-bottom: 0.1rem;
    }
    #overlay .score-display {
        font-size: 0.9rem;
        margin: 0.3rem 0;
    }
    .controls-hint {
        margin-top: 0.5rem;
        font-size: 0.55rem;
        line-height: 1.4;
    }
}

/* ── Touch devices: hide keyboard control hints ────────── */
@media (pointer: coarse) {
    .controls-hint { display: none; }
}

@media (pointer: fine) {
    .touch-controls { display: none !important; }
}
