/* ═══════════════════════════════════════════════════════════════
   NEON DEFENDER — Retro Arcade Styling
   ═══════════════════════════════════════════════════════════════ */

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

:root {
    --neon-cyan: #00ffff;
    --neon-magenta: #ff00ff;
    --neon-green: #39ff14;
    --neon-yellow: #ffff00;
    --neon-red: #ff3333;
    --neon-orange: #ff8800;
    --bg-dark: #0a0a12;
    --bg-scanner: #0d0d1a;
    --text-primary: #e0e0e0;
    --font-mono: 'JetBrains Mono', monospace;
    --font-display: 'Orbitron', sans-serif;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-mono);
}

/* ── Canvas ──────────────────────────────────────────────────── */
#game-canvas {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: block;
    background: var(--bg-dark);
}

/* ── Title Screen ────────────────────────────────────────────── */
#title-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-dark);
}

.scan-lines {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 255, 255, 0.015) 2px,
        rgba(0, 255, 255, 0.015) 4px
    );
    pointer-events: none;
    z-index: 1;
}

.title-content {
    text-align: center;
    z-index: 2;
}

.game-title {
    font-family: var(--font-display);
    font-size: clamp(3rem, 10vw, 7rem);
    font-weight: 900;
    line-height: 1;
    color: var(--neon-cyan);
    text-shadow:
        0 0 10px var(--neon-cyan),
        0 0 30px var(--neon-cyan),
        0 0 60px rgba(0, 255, 255, 0.4);
    margin-bottom: 0.5em;
    letter-spacing: 0.05em;
}

.title-accent {
    color: var(--neon-magenta);
    text-shadow:
        0 0 10px var(--neon-magenta),
        0 0 30px var(--neon-magenta),
        0 0 60px rgba(255, 0, 255, 0.4);
}

.title-sub {
    font-family: var(--font-display);
    font-size: clamp(0.6rem, 2vw, 1rem);
    color: var(--neon-green);
    letter-spacing: 0.3em;
    margin-bottom: 2em;
    text-shadow: 0 0 8px var(--neon-green);
}

.title-controls {
    margin-bottom: 2.5em;
    font-size: 0.85rem;
    color: #888;
    line-height: 2;
}

.control-row { margin: 0.3em 0; }

.key {
    display: inline-block;
    background: rgba(0, 255, 255, 0.1);
    border: 1px solid rgba(0, 255, 255, 0.3);
    border-radius: 4px;
    padding: 0.15em 0.5em;
    font-size: 0.8rem;
    color: var(--neon-cyan);
    min-width: 2em;
    text-align: center;
}

.neon-btn {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    padding: 0.8em 2.5em;
    background: transparent;
    border: 2px solid var(--neon-cyan);
    color: var(--neon-cyan);
    cursor: pointer;
    letter-spacing: 0.15em;
    transition: all 0.2s;
    text-shadow: 0 0 8px var(--neon-cyan);
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.2), inset 0 0 10px rgba(0, 255, 255, 0.1);
}

.neon-btn:hover, .neon-btn:focus {
    background: rgba(0, 255, 255, 0.1);
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.4), inset 0 0 20px rgba(0, 255, 255, 0.15);
}

.title-hint {
    margin-top: 0.8em;
    font-size: 0.75rem;
    color: #555;
}

.back-link {
    position: absolute;
    bottom: 2em;
    left: 2em;
    color: #555;
    text-decoration: none;
    font-size: 0.8rem;
    z-index: 2;
    transition: color 0.2s;
}
.back-link:hover { color: var(--neon-cyan); }

/* ── HUD ─────────────────────────────────────────────────────── */
#hud {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 50;
    pointer-events: none;
}

#hud.hidden, #game-over.hidden, #wave-banner.hidden,
#initials-entry.hidden, #leaderboard-panel.hidden,
#title-leaderboard.hidden { display: none; }

.hud-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 10px 20px;
    background: linear-gradient(180deg, rgba(10,10,18,0.9) 0%, transparent 100%);
}

.hud-left, .hud-right {
    display: flex;
    gap: 1.5em;
    align-items: center;
}

.hud-right { flex-direction: row; gap: 1.2em; }

.hud-item { text-align: center; }

.hud-label {
    font-family: var(--font-display);
    font-size: 0.6rem;
    color: #666;
    letter-spacing: 0.15em;
    display: block;
}

.hud-value {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--neon-cyan);
    text-shadow: 0 0 6px var(--neon-cyan);
}

.hud-center { flex: 1; max-width: 500px; margin: 0 1em; }

#scanner-canvas {
    width: 100%;
    height: 40px;
    border: 1px solid rgba(0, 255, 255, 0.2);
    background: var(--bg-scanner);
    border-radius: 2px;
}

/* ── Game Over ───────────────────────────────────────────────── */
#game-over {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 18, 0.85);
}

.overlay-content { text-align: center; }

.over-title {
    font-family: var(--font-display);
    font-size: clamp(2rem, 6vw, 4rem);
    font-weight: 900;
    color: var(--neon-red);
    text-shadow: 0 0 20px var(--neon-red), 0 0 40px rgba(255, 51, 51, 0.4);
    margin-bottom: 0.5em;
}

.over-score, .over-wave {
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--neon-cyan);
    margin-bottom: 0.5em;
    letter-spacing: 0.1em;
}

#game-over .neon-btn { margin-top: 1.5em; }

/* ── Initials Entry ──────────────────────────────────────────── */
.initials-prompt {
    font-family: var(--font-display);
    font-size: 0.8rem;
    color: var(--neon-yellow);
    letter-spacing: 0.15em;
    margin: 1em 0 0.5em;
    text-shadow: 0 0 8px var(--neon-yellow);
}

.initials-slots {
    display: flex;
    justify-content: center;
    gap: 0.3em;
    margin-bottom: 0.5em;
}

.initial-slot {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 900;
    color: var(--neon-cyan);
    text-shadow: 0 0 10px var(--neon-cyan);
    width: 1.5em;
    text-align: center;
    border-bottom: 2px solid rgba(0, 255, 255, 0.4);
    padding-bottom: 0.1em;
}

.initial-slot.active {
    border-bottom-color: var(--neon-cyan);
    animation: slotBlink 0.6s infinite;
}

@keyframes slotBlink {
    0%, 100% { border-bottom-color: var(--neon-cyan); }
    50% { border-bottom-color: transparent; }
}

#mobile-letter-controls {
    display: flex;
    justify-content: center;
    gap: 0.8em;
    margin-top: 0.6em;
}

#mobile-letter-controls.hidden { display: none; }

.letter-nav-btn {
    font-family: var(--font-display);
    font-size: 1.2rem;
    width: 48px;
    height: 48px;
    background: rgba(0, 255, 255, 0.08);
    border: 1.5px solid rgba(0, 255, 255, 0.3);
    border-radius: 8px;
    color: var(--neon-cyan);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.letter-nav-btn:active {
    background: rgba(0, 255, 255, 0.2);
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.3);
}

.letter-ok-btn {
    font-size: 0.8rem;
    font-weight: 700;
    background: rgba(57, 255, 20, 0.1);
    border-color: rgba(57, 255, 20, 0.4);
    color: var(--neon-green);
    letter-spacing: 0.1em;
}

.letter-ok-btn:active {
    background: rgba(57, 255, 20, 0.25);
    box-shadow: 0 0 10px rgba(57, 255, 20, 0.3);
}

/* ── Leaderboard ─────────────────────────────────────────────── */
.lb-title {
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--neon-magenta);
    letter-spacing: 0.2em;
    margin-bottom: 0.6em;
    text-shadow: 0 0 8px var(--neon-magenta);
}

.lb-list {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.8;
    color: #888;
}

.lb-row {
    display: flex;
    justify-content: center;
    gap: 1.5em;
}

.lb-row .lb-rank { color: #666; width: 2em; text-align: right; }
.lb-row .lb-name { color: var(--neon-cyan); width: 3em; text-align: center; }
.lb-row .lb-score { color: var(--text-primary); width: 6em; text-align: right; }
.lb-row .lb-wave { color: #666; width: 3em; text-align: right; }

.lb-row.highlight .lb-name,
.lb-row.highlight .lb-score {
    color: var(--neon-yellow);
    text-shadow: 0 0 6px var(--neon-yellow);
}

.lb-row.gold .lb-rank { color: #ffd700; }
.lb-row.silver .lb-rank { color: #c0c0c0; }
.lb-row.bronze .lb-rank { color: #cd7f32; }

#title-leaderboard {
    position: absolute;
    bottom: 5em;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 2;
}

#leaderboard-panel { margin-top: 1em; }

/* ── Music Toggle ────────────────────────────────────────────── */
.music-btn {
    position: fixed;
    bottom: 1.5em;
    right: 1.5em;
    z-index: 200;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    padding: 0.4em 0.8em;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(0, 255, 255, 0.3);
    color: #666;
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.2s;
}

.music-btn:hover { border-color: var(--neon-cyan); color: var(--neon-cyan); }
.music-btn.active { color: var(--neon-cyan); border-color: var(--neon-cyan); }

/* ── Wave Banner ─────────────────────────────────────────────── */
#wave-banner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 80;
    pointer-events: none;
}

.wave-text {
    font-family: var(--font-display);
    font-size: clamp(2rem, 6vw, 4rem);
    font-weight: 900;
    color: var(--neon-yellow);
    text-shadow: 0 0 20px var(--neon-yellow), 0 0 50px rgba(255, 255, 0, 0.3);
    letter-spacing: 0.2em;
    animation: wavePulse 2s ease-out forwards;
}

@keyframes wavePulse {
    0%   { opacity: 0; transform: scale(0.5); }
    20%  { opacity: 1; transform: scale(1.1); }
    40%  { transform: scale(1); }
    80%  { opacity: 1; }
    100% { opacity: 0; }
}

/* ── Touch Controls ──────────────────────────────────────────── */
#touch-controls {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 60;
    pointer-events: none;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 12px 12px;
    height: 200px;
}

#touch-controls.hidden { display: none; }

.touch-zone-left, .touch-zone-right {
    pointer-events: auto;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* D-Pad */
.dpad {
    display: grid;
    grid-template-columns: 56px 56px 56px;
    grid-template-rows: 56px 56px 56px;
    gap: 3px;
}

.dpad-btn {
    background: rgba(0, 255, 255, 0.08);
    border: 1px solid rgba(0, 255, 255, 0.25);
    border-radius: 8px;
    color: rgba(0, 255, 255, 0.5);
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

.dpad-btn:active, .dpad-btn.pressed {
    background: rgba(0, 255, 255, 0.2);
    border-color: var(--neon-cyan);
    color: var(--neon-cyan);
    box-shadow: 0 0 12px rgba(0, 255, 255, 0.3);
}

.dpad-center {
    background: transparent;
    border-color: transparent;
}

.dpad-up    { grid-column: 2; grid-row: 1; }
.dpad-left  { grid-column: 1; grid-row: 2; }
.dpad-center{ grid-column: 2; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down  { grid-column: 2; grid-row: 3; }

/* Action Buttons */
.touch-zone-right {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
}

.touch-action-btn {
    font-family: var(--font-display);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    border-radius: 50%;
    width: 58px;
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

.fire-btn {
    background: rgba(0, 255, 255, 0.1);
    border: 2px solid rgba(0, 255, 255, 0.4);
    color: var(--neon-cyan);
    width: 70px;
    height: 70px;
    font-size: 0.75rem;
}

.fire-btn:active, .fire-btn.pressed {
    background: rgba(0, 255, 255, 0.25);
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.4);
}

.bomb-btn {
    background: rgba(255, 255, 0, 0.08);
    border: 1.5px solid rgba(255, 255, 0, 0.3);
    color: var(--neon-yellow);
}

.bomb-btn:active, .bomb-btn.pressed {
    background: rgba(255, 255, 0, 0.2);
    box-shadow: 0 0 12px rgba(255, 255, 0, 0.3);
}

.hyper-btn {
    background: rgba(255, 0, 255, 0.08);
    border: 1.5px solid rgba(255, 0, 255, 0.3);
    color: var(--neon-magenta);
}

.hyper-btn:active, .hyper-btn.pressed {
    background: rgba(255, 0, 255, 0.2);
    box-shadow: 0 0 12px rgba(255, 0, 255, 0.3);
}

/* ── Responsive — Small Screens ──────────────────────────────── */
@media (max-width: 600px) {
    .hud-top { padding: 6px 10px; }
    .hud-label { font-size: 0.5rem; }
    .hud-value { font-size: 0.9rem; }
    #scanner-canvas { height: 28px; }
    .title-controls { font-size: 0.75rem; }
    .music-btn { bottom: 0.8em; right: 0.8em; font-size: 0.65rem; }
    #title-leaderboard { bottom: 3em; }
}

/* ── Responsive — Mobile Landscape ──────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
    /* Compact HUD for landscape */
    .hud-top { padding: 4px 10px; }
    .hud-label { font-size: 0.45rem; }
    .hud-value { font-size: 0.85rem; }
    #scanner-canvas { height: 22px; }

    /* Smaller touch controls in landscape */
    #touch-controls {
        height: 140px;
        padding: 0 8px 6px;
    }

    .dpad {
        grid-template-columns: 42px 42px 42px;
        grid-template-rows: 42px 42px 42px;
        gap: 2px;
    }

    .dpad-btn { font-size: 0.8rem; }

    .touch-action-btn { width: 46px; height: 46px; font-size: 0.55rem; }
    .fire-btn { width: 54px; height: 54px; font-size: 0.65rem; }
    .touch-zone-right { gap: 5px; }

    /* Compact title for landscape */
    .game-title { font-size: clamp(2rem, 8vw, 4rem); margin-bottom: 0.3em; }
    .title-sub { font-size: 0.6rem; margin-bottom: 1em; }
    .title-controls { font-size: 0.65rem; line-height: 1.6; margin-bottom: 1em; }
    .neon-btn { font-size: 0.9rem; padding: 0.5em 2em; }
    .title-hint { margin-top: 0.4em; }
    #title-leaderboard { bottom: 1.5em; }

    /* Game over compact */
    .over-title { font-size: clamp(1.5rem, 5vw, 2.5rem); margin-bottom: 0.3em; }
    .over-score, .over-wave { font-size: 0.8rem; margin-bottom: 0.3em; }
    #game-over .neon-btn { margin-top: 0.8em; }
    .lb-list { font-size: 0.7rem; line-height: 1.5; }

    /* Music button above touch controls */
    .music-btn { bottom: 150px; right: 8px; }
}

/* ── Landscape prompt on portrait mobile ────────────────────── */
@media (max-width: 600px) and (orientation: portrait) {
    .rotate-hint { display: block !important; }
}

.rotate-hint {
    display: none;
    position: fixed;
    bottom: 3em;
    left: 50%;
    transform: translateX(-50%);
    z-index: 101;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: #555;
    text-align: center;
    white-space: nowrap;
}

.rotate-hint span {
    display: inline-block;
    animation: rotateHint 2s ease-in-out infinite;
}

@keyframes rotateHint {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}
