@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
    --neon-cyan: #00f0ff;
    --neon-pink: #ff00aa;
    --neon-purple: #aa00ff;
    --neon-yellow: #ffee00;
    --neon-green: #00ff88;
    --neon-orange: #ff8800;
    --bg-dark: #050510;
    --bg-darker: #02020a;
}

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

body {
    background: #000;
    overflow: hidden;
    font-family: 'Press Start 2P', monospace;
    user-select: none;
    -webkit-user-select: none;
    color: var(--neon-cyan);
}

.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════════
   STARTBILDSCHIRM
═══════════════════════════════════════════════════════════════ */
#startScreen {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh; height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, #0a0a20 0%, #050510 60%, #02020a 100%);
    z-index: 50;
}

#startCanvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1;
}

#startContent {
    position: relative;
    z-index: 5;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(20px, 5vh, 50px);
}

#logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(4px, 1vh, 10px);
}

#logoAlien {
    font-size: clamp(32px, 9vw, 72px);
    color: var(--neon-green);
    text-shadow:
        0 0 8px var(--neon-green),
        0 0 20px var(--neon-green),
        0 0 40px rgba(0,255,136,0.5);
    letter-spacing: clamp(2px, 1vw, 8px);
    animation: logoPulse 2s ease-in-out infinite;
}

#logoPacman {
    font-size: clamp(36px, 10vw, 80px);
    color: var(--neon-yellow);
    text-shadow:
        0 0 8px var(--neon-yellow),
        0 0 20px var(--neon-yellow),
        0 0 40px rgba(255,238,0,0.5);
    letter-spacing: clamp(2px, 1vw, 8px);
    animation: logoPulse 2s ease-in-out infinite 0.5s;
}

@keyframes logoPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

#startInfo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(10px, 2.5vh, 20px);
}

#insertCoin {
    font-size: clamp(10px, 2.5vw, 16px);
    color: var(--neon-cyan);
    opacity: 0.6;
    animation: blink 1.2s steps(2) infinite;
}

#pressStart {
    font-size: clamp(14px, 3.5vw, 22px);
    color: var(--neon-pink);
    text-shadow: 0 0 10px var(--neon-pink), 0 0 25px rgba(255,0,170,0.5);
    animation: blink 0.8s steps(2) infinite;
    cursor: pointer;
    padding: clamp(8px, 2vw, 16px) clamp(16px, 4vw, 32px);
}

#startHighScore {
    font-size: clamp(10px, 2.5vw, 14px);
    color: var(--neon-yellow);
    opacity: 0.85;
}

#startHint {
    font-size: clamp(7px, 1.8vw, 10px);
    color: rgba(0,240,255,0.4);
    margin-top: clamp(10px, 2vh, 20px);
}

@keyframes blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0.15; }
}

#startScanlines {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: repeating-linear-gradient(0deg,
        rgba(0,0,0,0) 0px, rgba(0,0,0,0) 2px,
        rgba(0,0,0,0.12) 3px, rgba(0,0,0,0.12) 4px);
    pointer-events: none;
    z-index: 10;
}

/* ═══════════════════════════════════════════════════════════════
   SPIELBILDSCHIRM
═══════════════════════════════════════════════════════════════ */
#gameScreen {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh; height: 100dvh;
    background: #02020a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: clamp(6px, 1.5vh, 12px) clamp(10px, 3vw, 20px);
    z-index: 20;
    pointer-events: none;
    gap: clamp(4px, 1vh, 8px);
}

.hud-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 700px;
    gap: clamp(8px, 3vw, 24px);
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(2px, 0.5vh, 4px);
}

.hud-label {
    font-size: clamp(7px, 1.8vw, 10px);
    color: rgba(0,240,255,0.5);
}

.hud-val {
    font-size: clamp(10px, 2.5vw, 14px);
    color: var(--neon-cyan);
    text-shadow: 0 0 6px rgba(0,240,255,0.6);
}

#hudLives { color: var(--neon-green); text-shadow: 0 0 6px rgba(0,255,136,0.6); }
#hudMult { color: var(--neon-yellow); text-shadow: 0 0 6px rgba(255,238,0,0.6); }
#hudLevel { color: var(--neon-pink); text-shadow: 0 0 6px rgba(255,0,170,0.6); }

#bgCanvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1;
    opacity: 0.85;
}

#gameCanvas {
    position: relative;
    z-index: 5;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#levelBanner {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 30;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

#levelBanner.show {
    opacity: 1;
    animation: bannerShow 2.5s ease forwards;
}

@keyframes bannerShow {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.2); }
}

#levelBanner .banner-level {
    font-size: clamp(10px, 2.5vw, 16px);
    color: var(--neon-cyan);
    margin-bottom: clamp(6px, 1vh, 12px);
}

#levelBanner .banner-name {
    font-size: clamp(16px, 4vw, 28px);
    color: var(--neon-yellow);
    text-shadow: 0 0 12px var(--neon-yellow), 0 0 30px rgba(255,238,0,0.5);
}

#gameScanlines {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: repeating-linear-gradient(0deg,
        rgba(0,0,0,0) 0px, rgba(0,0,0,0) 2px,
        rgba(0,0,0,0.08) 3px, rgba(0,0,0,0.08) 4px);
    pointer-events: none;
    z-index: 15;
}

/* ═══════════════════════════════════════════════════════════════
   TOUCH-CONTROLS
═══════════════════════════════════════════════════════════════ */
#touchControls {
    position: absolute;
    bottom: clamp(10px, 3vh, 30px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 25;
    display: none;
}

#joystick {
    width: clamp(100px, 30vw, 140px);
    height: clamp(100px, 30vw, 140px);
    border-radius: 50%;
    border: 2px solid rgba(0,240,255,0.3);
    background: rgba(0,20,40,0.3);
    position: relative;
    touch-action: none;
}

#joystickKnob {
    width: 40%;
    height: 40%;
    border-radius: 50%;
    background: rgba(0,240,255,0.4);
    border: 2px solid var(--neon-cyan);
    box-shadow: 0 0 12px rgba(0,240,255,0.5);
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    transition: transform 0.05s;
}

body.touch #touchControls { display: block; }

/* ═══════════════════════════════════════════════════════════════
   GAME OVER
═══════════════════════════════════════════════════════════════ */
#gameOverScreen {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh; height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(2,2,10,0.92);
    z-index: 60;
}

#gameOverContent {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(12px, 3vh, 24px);
}

#gameOverTitle {
    font-size: clamp(28px, 7vw, 56px);
    color: var(--neon-pink);
    text-shadow: 0 0 12px var(--neon-pink), 0 0 30px rgba(255,0,170,0.5);
    margin-bottom: clamp(10px, 2vh, 20px);
    animation: gameOverShake 0.5s ease;
}

@keyframes gameOverShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.go-stat {
    font-size: clamp(10px, 2.5vw, 14px);
    color: var(--neon-cyan);
    line-height: 1.8;
}

.go-stat span {
    color: var(--neon-yellow);
}

#gameOverButtons {
    display: flex;
    gap: clamp(12px, 4vw, 24px);
    margin-top: clamp(16px, 4vh, 32px);
}

.go-btn {
    font-size: clamp(10px, 2.5vw, 14px);
    color: var(--neon-green);
    border: 2px solid var(--neon-green);
    padding: clamp(10px, 2.5vw, 16px) clamp(16px, 4vw, 28px);
    cursor: pointer;
    background: rgba(0,255,136,0.08);
    text-shadow: 0 0 8px rgba(0,255,136,0.6);
    box-shadow: 0 0 12px rgba(0,255,136,0.2);
    transition: all 0.15s;
}

.go-btn:hover, .go-btn:active {
    background: rgba(0,255,136,0.2);
    box-shadow: 0 0 20px rgba(0,255,136,0.4);
}

/* ═══════════════════════════════════════════════════════════════
   HIGHSCORE SCREEN
═══════════════════════════════════════════════════════════════ */
#highScoreScreen {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh; height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #02020a;
    z-index: 70;
}

#hsContent {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(16px, 4vh, 28px);
}

#hsTitle {
    font-size: clamp(18px, 5vw, 32px);
    color: var(--neon-yellow);
    text-shadow: 0 0 10px var(--neon-yellow);
}

#hsList {
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 1.5vh, 10px);
    min-width: clamp(240px, 70vw, 440px);
}

/* Spaltenraster für Kopfzeile und Einträge der Bestenliste */
#hsHead,
.hs-entry {
    display: grid;
    grid-template-columns: 2.2em 1fr 3.2em auto;
    align-items: baseline;
    gap: clamp(6px, 2vw, 14px);
    font-size: clamp(9px, 2.2vw, 13px);
    padding: clamp(4px, 1vh, 8px) clamp(8px, 2vw, 16px);
}

#hsHead {
    color: rgba(0,240,255,0.5);
    border-bottom: 2px solid rgba(0,240,255,0.25);
}

.hs-entry {
    color: var(--neon-cyan);
    border-bottom: 1px solid rgba(0,240,255,0.15);
}

.hs-entry .hs-rank { color: var(--neon-pink); }
.hs-entry .hs-val { color: var(--neon-yellow); text-align: right; }
.hs-entry .hs-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hs-entry .hs-lv { color: rgba(0,240,255,0.6); }

/* Eigener Eintrag wird hervorgehoben */
.hs-entry.hs-mine {
    background: rgba(0,255,136,0.12);
    box-shadow: 0 0 12px rgba(0,255,136,0.25);
}

/* Hinweis, solange noch niemand gespielt hat */
.hs-entry.hs-empty {
    display: block;
    text-align: center;
    color: rgba(0,240,255,0.5);
}

/* ── Namenseingabe auf dem Game-Over-Bildschirm ────────────── */
#nameEntry {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(8px, 1.5vh, 12px);
    margin-top: clamp(12px, 3vh, 24px);
}

#nameEntryLabel {
    font-size: clamp(8px, 2vw, 11px);
    color: rgba(0,240,255,0.6);
}

#nameEntryRow {
    display: flex;
    align-items: stretch;
    gap: clamp(8px, 2vw, 14px);
}

#playerName {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(10px, 2.5vw, 14px);
    color: var(--neon-yellow);
    background: rgba(0,20,40,0.6);
    border: 2px solid rgba(0,240,255,0.5);
    padding: clamp(8px, 2vw, 12px) clamp(10px, 2.5vw, 16px);
    width: clamp(130px, 40vw, 220px);
    outline: none;
    text-transform: uppercase;
}

#playerName::placeholder {
    color: rgba(0,240,255,0.3);
}

#playerName:focus {
    border-color: var(--neon-cyan);
    box-shadow: 0 0 14px rgba(0,240,255,0.4);
}

#playerName:disabled {
    opacity: 0.5;
}

#saveScore {
    display: flex;
    align-items: center;
    margin-top: 0;
}

#saveStatus {
    font-size: clamp(8px, 2vw, 11px);
    min-height: 1.4em;
    color: var(--neon-yellow);
}

#nameEntry.saved #playerName,
#nameEntry.saved #saveScore {
    display: none;
}