:root {
    --color-p1: #00FFFF;
    --color-p2: #FF00FF;
    --color-p3: #FFFF00;
    --color-p4: #00FF88;
    --color-bg: #000000;
    --color-ui-bg: rgba(0, 5, 20, 0.93);
    --color-ui-border: #1a2a4a;
    --color-text: #8ab4d8;
    --font-game: 'Orbitron', 'Courier New', monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: var(--font-game);
    color: var(--color-text);
    touch-action: none;
}

/* ─── SPIELFELD-CONTAINER ──────────────────────────────── */

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 480px;
    margin: 0 auto;
}

#game-canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* touch-action wird über body vererbt-ähnlich gesteuert; explizites none
       auf dem Canvas kann auf iOS Safari die Touch-Routen für Overlay-Buttons
       stören – deshalb weglassen. Das touchstart-preventDefault in input.js
       übernimmt die Scroll-Prävention während der Partie. */
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    will-change: transform;
}

/* ─── OVERLAYS ─────────────────────────────────────────── */

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--color-ui-bg);
    z-index: 10;
    /* Safe Area für iPhone X+ Notch und Home-Indicator */
    padding: max(28px, env(safe-area-inset-top, 0px))
             max(24px, env(safe-area-inset-right, 0px))
             max(28px, env(safe-area-inset-bottom, 0px))
             max(24px, env(safe-area-inset-left, 0px));
    gap: 18px;
}

.overlay.active {
    display: flex;
}

.overlay.hud-overlay {
    background: transparent;
    pointer-events: none;
}

.overlay.hud-overlay button {
    pointer-events: all;
}

/* ─── TITEL ────────────────────────────────────────────── */

.game-title {
    font-size: clamp(26px, 9vw, 52px);
    font-weight: 900;
    text-align: center;
    line-height: 1.15;
    color: var(--color-p1);
    text-shadow: 0 0 12px var(--color-p1), 0 0 30px var(--color-p1);
    letter-spacing: 5px;
    margin-bottom: 4px;
}

.game-title span {
    color: var(--color-p2);
    text-shadow: 0 0 12px var(--color-p2), 0 0 30px var(--color-p2);
}

.overlay-title {
    font-size: clamp(16px, 5vw, 26px);
    font-weight: 700;
    text-align: center;
    color: var(--color-p1);
    text-shadow: 0 0 10px var(--color-p1);
    letter-spacing: 3px;
    margin-bottom: 4px;
}

/* ─── BUTTONS ──────────────────────────────────────────── */

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 280px;
}

.btn-neon {
    width: 100%;
    padding: 14px 20px;
    background: transparent;
    border: 2px solid var(--color-p1);
    color: var(--color-p1);
    font-family: var(--font-game);
    font-size: clamp(11px, 3.5vw, 15px);
    font-weight: 700;
    letter-spacing: 3px;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0,255,255,0.15);
    text-shadow: 0 0 8px var(--color-p1);
    box-shadow: 0 0 8px rgba(0,255,255,0.3), inset 0 0 8px rgba(0,255,255,0.03);
    transition: background 0.12s, box-shadow 0.12s;
    min-height: 50px;
}

.btn-neon:active {
    background: rgba(0, 255, 255, 0.12);
    box-shadow: 0 0 18px rgba(0,255,255,0.6), inset 0 0 18px rgba(0,255,255,0.08);
}

.btn-neon.btn-secondary {
    border-color: var(--color-ui-border);
    color: var(--color-text);
    text-shadow: none;
    box-shadow: none;
    opacity: 0.7;
}

.btn-neon.btn-secondary:active {
    background: rgba(255, 255, 255, 0.05);
}

/* ─── KONFIGURATION ────────────────────────────────────── */

.config-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 300px;
    gap: 12px;
}

.config-row label {
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--color-text);
    opacity: 0.65;
    flex-shrink: 0;
}

.counter-control {
    display: flex;
    align-items: center;
    gap: 14px;
}

.btn-counter {
    width: 44px;
    height: 44px;
    background: transparent;
    border: 1px solid var(--color-ui-border);
    color: var(--color-text);
    font-size: 22px;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(255,255,255,0.1);
    font-family: var(--font-game);
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-counter:active {
    background: rgba(255,255,255,0.08);
}

#ai-count-display {
    font-size: 22px;
    font-weight: 700;
    color: var(--color-p1);
    min-width: 28px;
    text-align: center;
    text-shadow: 0 0 8px var(--color-p1);
}

/* ─── SCHWIERIGKEITS-BUTTONS ───────────────────────────── */

.difficulty-buttons {
    display: flex;
    gap: 6px;
}

.btn-difficulty {
    padding: 8px 10px;
    background: transparent;
    border: 1px solid var(--color-ui-border);
    color: var(--color-text);
    font-family: var(--font-game);
    font-size: 8px;
    letter-spacing: 1px;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(255,255,255,0.1);
    opacity: 0.55;
    min-height: 44px;
    transition: all 0.1s;
}

.btn-difficulty.active {
    border-color: var(--color-p1);
    color: var(--color-p1);
    text-shadow: 0 0 6px var(--color-p1);
    opacity: 1;
}

/* ─── HUD ──────────────────────────────────────────────── */

.hud-corner {
    position: absolute;
    padding: 5px 9px;
    font-size: 9px;
    letter-spacing: 1px;
    line-height: 1.5;
    background: rgba(0,0,0,0.55);
    border: 1px solid rgba(255,255,255,0.08);
    min-width: 70px;
}

/* Safe Area: HUD-Ecken nicht unter Notch/Home-Indicator */
.hud-top-left     { top:    max(10px, env(safe-area-inset-top,    0px)); left:  max(10px, env(safe-area-inset-left,  0px)); }
.hud-top-right    { top:    max(10px, env(safe-area-inset-top,    0px)); right: max(10px, env(safe-area-inset-right, 0px)); text-align: right; }
.hud-bottom-left  { bottom: max(10px, env(safe-area-inset-bottom, 0px)); left:  max(10px, env(safe-area-inset-left,  0px)); }
.hud-bottom-right { bottom: max(10px, env(safe-area-inset-bottom, 0px)); right: max(10px, env(safe-area-inset-right, 0px)); text-align: right; }

.hud-corner.player-dead {
    opacity: 0.28;
    filter: grayscale(0.75);
    border-color: rgba(255,255,255,0.05) !important;
    transition: opacity 0.4s ease, filter 0.4s ease;
}

.hud-corner {
    transition: opacity 0.4s ease, filter 0.4s ease;
}

.hud-corner .player-name {
    font-weight: 700;
    font-size: 10px;
}

.hud-corner .player-wins {
    font-size: 8px;
    opacity: 0.75;
}

.hud-center-btns {
    position: absolute;
    top: max(10px, env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    align-items: center;
}

.btn-pause,
.btn-mute {
    background: rgba(0,0,0,0.55);
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.5);
    font-size: 16px;
    width: 44px;
    height: 44px;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(255,255,255,0.12);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-pause:active,
.btn-mute:active {
    background: rgba(255,255,255,0.1);
}

.btn-mute.muted {
    color: rgba(255,80,80,0.7);
    border-color: rgba(255,80,80,0.3);
}

.hud-round {
    position: absolute;
    top: max(62px, calc(env(safe-area-inset-top, 0px) + 52px));
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    letter-spacing: 3px;
    color: rgba(255,255,255,0.35);
    background: rgba(0,0,0,0.4);
    padding: 3px 10px;
    white-space: nowrap;
    border: 1px solid rgba(255,255,255,0.06);
}

@keyframes countdownPop {
    0%   { transform: translate(-50%, -50%) scale(0.3);  opacity: 0; }
    12%  { transform: translate(-50%, -50%) scale(1.18); opacity: 1; }
    26%  { transform: translate(-50%, -50%) scale(0.94); }
    38%  { transform: translate(-50%, -50%) scale(1.0);  }
    62%  { opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1.0);  opacity: 0; }
}

.countdown {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(72px, 22vw, 130px);
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 20px #fff, 0 0 50px var(--color-p1), 0 0 80px var(--color-p1);
    pointer-events: none;
    opacity: 0;
    letter-spacing: 0;
}

.countdown.visible {
    animation: countdownPop 0.92s ease-out forwards;
}

.countdown.go.visible {
    color: var(--color-p1);
    text-shadow: 0 0 20px var(--color-p1), 0 0 55px var(--color-p1), 0 0 110px var(--color-p1);
    animation-duration: 0.72s;
}

/* ─── SCORES ───────────────────────────────────────────── */

.scores-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 280px;
}

.score-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    border: 1px solid var(--color-ui-border);
    font-size: 12px;
    letter-spacing: 2px;
}

.score-entry.winner {
    box-shadow: 0 0 10px currentColor;
}

/* ─── TOGGLE-BUTTON ────────────────────────────────────── */

.btn-toggle {
    padding: 8px 18px;
    background: transparent;
    border: 1px solid var(--color-p1);
    color: var(--color-p1);
    font-family: var(--font-game);
    font-size: 10px;
    letter-spacing: 2px;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0,255,255,0.12);
    min-height: 44px;
    min-width: 68px;
    transition: all 0.1s;
}

.btn-toggle[data-on="false"] {
    border-color: var(--color-ui-border);
    color: var(--color-text);
    opacity: 0.45;
}

/* ─── EINSTELLUNGEN ────────────────────────────────────── */

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
    max-width: 310px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.setting-row label {
    font-size: 10px;
    letter-spacing: 2px;
    opacity: 0.65;
    flex-shrink: 0;
}

/* ─── SPIELER-KONFIGURATIONSLISTE ──────────────────────── */

#player-config-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 300px;
}

.player-config-entry {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border: 1px solid var(--color-ui-border);
}

.player-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 6px currentColor;
}

.player-name-input {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--color-ui-border);
    color: #fff;
    font-family: var(--font-game);
    font-size: 11px;
    letter-spacing: 2px;
    padding: 4px 0;
    outline: none;
    min-height: 36px;
}

.player-name-input:focus {
    border-bottom-color: var(--color-p1);
}

/* ─── TOUCH-INDIKATOR ──────────────────────────────────── */

/* Kleiner Hinweistext im Hauptmenü, nur auf Touch-Geräten */
.touch-hint {
    font-size: 8px;
    letter-spacing: 2px;
    opacity: 0.35;
    text-align: center;
    margin-top: -8px;
}

@media (hover: hover) and (pointer: fine) {
    /* Desktop: Touch-Hinweis ausblenden */
    .touch-hint { display: none; }
}

/* ─── VERSIONS-BADGE ───────────────────────────────────── */

.version {
    position: absolute;
    bottom: 14px;
    font-size: 8px;
    opacity: 0.25;
    letter-spacing: 2px;
}

/* ─── ONLINE-OVERLAYS ──────────────────────────────────── */

.hidden { display: none !important; }

.online-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 300px;
}

.online-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.online-field label {
    font-size: 9px;
    letter-spacing: 2px;
    opacity: 0.55;
}

.online-join-row {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 300px;
    align-items: center;
}

.room-code-field {
    flex: 1;
    text-align: center;
    letter-spacing: 6px;
    font-size: 18px;
    font-weight: 700;
}

.online-error {
    font-size: 10px;
    letter-spacing: 1px;
    color: #ff6060;
    text-shadow: 0 0 6px #ff6060;
    min-height: 16px;
    text-align: center;
    max-width: 280px;
}

/* ─── LOBBY ────────────────────────────────────────────── */

.room-code-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 24px;
    border: 1px solid var(--color-p1);
    box-shadow: 0 0 12px rgba(0,255,255,0.2), inset 0 0 12px rgba(0,255,255,0.05);
}

.room-code-label {
    font-size: 8px;
    letter-spacing: 3px;
    opacity: 0.5;
}

.room-code-value {
    font-size: clamp(28px, 10vw, 44px);
    font-weight: 900;
    color: var(--color-p1);
    text-shadow: 0 0 12px var(--color-p1), 0 0 30px var(--color-p1);
    letter-spacing: 10px;
}

.lobby-status {
    font-size: 9px;
    letter-spacing: 2px;
    opacity: 0.45;
    text-align: center;
}

.score-entry.player-disconnected {
    opacity: 0.35;
    text-decoration: line-through;
}
