/* Safe-Area CSS Custom Properties für konsistente Verwendung */
:root {
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
}

html {
    /* Höhe auf iOS Safari korrekt berechnen */
    height: 100%;
    height: -webkit-fill-available;
}

body {
    margin: 0;
    overflow: hidden;
    background-color: #0a0a14;
    color: white;
    font-family: 'Arial', sans-serif;
    touch-action: none;
    /* Wichtig: Verhindert Zoom/Scroll auf Mobile */
    display: flex;
    flex-direction: column;
    /* Dynamische Höhe für verschiedene Browser */
    min-height: 100vh;
    min-height: 100dvh;
    /* Dynamic viewport height - berücksichtigt Browser-UI */
    min-height: -webkit-fill-available;
    /* Safe-Area Padding für Top (Notch) und Seiten */
    padding-top: var(--safe-area-inset-top);
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
    box-sizing: border-box;
}

/* --- GAME CONTAINER (OBEN) --- */
#game-container {
    position: relative;
    flex-grow: 1;
    /* Nimmt den verfügbaren Platz ein */
    overflow: hidden;
    background-color: #0a0a14;
}

canvas {
    display: block;
}

/* --- UI ELEMENTS --- */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    pointer-events: none;
    padding: 10px;
    box-sizing: border-box;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    font-size: 18px;
    /* Etwas kleiner für Mobile */
    font-weight: bold;
    text-shadow: 0 0 5px #fff;
}

.hud-lives {
    color: #ff1493;
}

#start-screen,
#game-over-screen,
#win-screen {
    position: absolute;
    top: 40%;
    /* Etwas höher wegen Keypad */
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: rgba(0, 0, 0, 0.85);
    padding: 20px;
    width: 80%;
    border: 2px solid #39ff14;
    border-radius: 10px;
    box-shadow: 0 0 20px #39ff14;
    pointer-events: auto;
    z-index: 10;
}

h1 {
    color: #39ff14;
    margin: 0 0 10px 0;
    text-shadow: 0 0 10px #39ff14;
    font-size: 2em;
}

button.menu-btn {
    background: rgba(0, 255, 255, 0.2);
    color: #00ffff;
    border: 2px solid #00ffff;
    padding: 10px 20px;
    font-size: 1.2em;
    cursor: pointer;
    font-weight: bold;
    text-transform: uppercase;
    box-shadow: 0 0 10px #00ffff;
    margin-top: 10px;
    width: 100%;
    border-radius: 5px;
}

button.menu-btn:active {
    background: #00ffff;
    color: #000;
}

.hidden {
    display: none !important;
}

/* --- KEYPAD (UNTEN) --- */
#keypad {
    /* Flexible Höhe statt fester Wert */
    min-height: 200px;
    background: #111;
    border-top: 2px solid #333;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    /* Etwas engerer Abstand */
    padding: 8px;
    /* WICHTIG: Dynamischer Abstand für Android Nav-Bar/Gesten & iOS Home-Indicator */
    /* Fallback 20px + Safe-Area für maximale Kompatibilität */
    padding-bottom: calc(20px + var(--safe-area-inset-bottom));
    /* Alternativer Fallback für ältere Browser ohne env() Support */
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
    z-index: 20;
    /* Flex-shrink verhindern damit Keypad nicht schrumpft */
    flex-shrink: 0;
}

.key {
    background: #222;
    border: 1px solid #444;
    border-radius: 6px;
    color: white;
    font-size: 22px;
    /* Schrift etwas kleiner angepasst */
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.1s;
}

.key:active {
    background: #444;
    transform: scale(0.98);
}

.key-action {
    background: #003300;
    border-color: #005500;
    color: #39ff14;
}

.key-del {
    background: #330000;
    border-color: #550000;
    color: #ff1493;
}

/* --- QUIT BUTTON --- */
.quit-btn {
    text-decoration: none;
    color: #ff1493;
    /* Pink wie die Leben */
    border: 1px solid #ff1493;
    padding: 2px 8px;
    font-size: 14px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.5);
    transition: all 0.2s;
    height: fit-content;
    pointer-events: auto;
    /* WICHTIG: Damit der Link klickbar ist, da parent pointer-events: none hat */
}

.quit-btn:hover,
.quit-btn:active {
    background: #ff1493;
    color: #fff;
}