/* Grundlegende Resets und Fonts */
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&family=Press+Start+2P&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
}

:root {
    --primary-color: #00ffaa;
    --secondary-color: #ff00aa;
    --background-color: #111122;
    --text-color: #ffffff;
    --panel-bg: rgba(0, 0, 0, 0.8);
    --glow-effect: 0 0 10px var(--primary-color);
}

body {
    font-family: 'Orbitron', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(0, 255, 170, 0.1) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(255, 0, 170, 0.1) 0%, transparent 20%);
    overflow: hidden;
}

.game-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    aspect-ratio: 16 / 9;
    margin: 0 auto;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.6);
    background-color: var(--panel-bg);
}

@media (max-width: 480px) {
    .game-container {
        aspect-ratio: auto;
        height: 100vh;
        border-radius: 0;
    }
    
    body {
        margin: 0;
        padding: 0;
        height: 100vh;
        display: flex;
        flex-direction: column;
    }
}

/* Bildschirme (Start, Game, Game Over, Leaderboard) */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
    padding: 20px;
    text-align: center;
    box-sizing: border-box; /* Wichtig: Padding in die Gesamt-Dimension einrechnen */
    overflow-y: auto; /* Bei Bedarf scrollen lassen */
}

.hidden {
    display: none;
}

/* Spiel-Elemente */
#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background-color: transparent;
}

/* Aktualisierte game-stats Klasse */
.game-stats {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    color: var(--primary-color);
    text-shadow: 0 0 5px var(--primary-color);
    display: flex;
    flex-direction: column;
    gap: 5px;
    background-color: rgba(0, 0, 0, 0.5);
    padding: 8px;
    border-radius: 5px;
    min-width: 150px;
}

.game-stats div {
    text-align: left;
    padding: 2px 0;
    border-bottom: 1px solid rgba(0, 255, 170, 0.2);
}

.game-stats div:last-child {
    border-bottom: none;
}

.personal-highscore {
    font-family: 'Press Start 2P', cursive;
    font-size: 1rem;
    color: var(--primary-color);
    margin-top: 20px;
    margin-bottom: 10px;
    text-shadow: 0 0 10px var(--primary-color);
    background-color: rgba(0, 0, 0, 0.3);
    padding: 10px 20px;
    border-radius: 5px;
    border: 1px solid var(--primary-color);
    text-align: center;
    width: auto;
    max-width: 90%;
    margin-left: auto;
    margin-right: auto;
}

/* Neuer Highscore Alert */
.new-highscore-alert {
    position: absolute;
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.7);
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 15px 30px;
    font-family: 'Press Start 2P', cursive;
    font-size: 1.2rem;
    text-shadow: 0 0 10px var(--primary-color);
    border-radius: 5px;
    z-index: 10;
    pointer-events: none;
    text-align: center;
    width: auto;
    max-width: 80%;
}

.highscore-message {
    text-align: center;
    margin: 10px 0;
    width: 100%;
}

/* Mobile Anpassungen */
@media (max-width: 480px) {
    .game-container {
        width: 100%;
        height: 100vh;
        max-width: 100%;
        margin: 0;
        border-radius: 0;
    }
    
    h1 {
        font-size: 1.5rem;
        margin-bottom: 15px;
        margin-top: 10px;
    }
    
    h2 {
        font-size: 1.5rem;
        margin-bottom: 15px;
    }
    
    p {
        font-size: 0.8rem;
        margin-bottom: 15px;
        max-width: 95%;
    }
    
    .btn {
        padding: 8px 16px;
        font-size: 0.8rem;
        margin: 5px;
    }
    
    .buttons {
        display: flex;
        flex-direction: column;
        gap: 10px;
        width: 80%;
        max-width: 250px;
    }
    
    .personal-highscore {
        font-size: 0.7rem;
        padding: 5px 10px;
        margin-top: 15px;
    }
    
    .game-stats {
        font-size: 8px; /* Kleinere Schrift auf sehr kleinen Bildschirmen */
        min-width: 100px;
        padding: 5px;
    }
    
    .new-highscore-alert {
        font-size: 0.9rem;
        padding: 10px 15px;
        width: 80%;
    }
    
    #player-name {
        width: 80%;
        max-width: 200px;
        font-size: 0.9rem;
    }
    
    #game-over-screen {
        padding-top: 10vh; /* Mehr Platz nach oben */
    }
    
    #game-over-screen .buttons {
        margin-top: 10px;
    }
    
    #highscore-form {
        width: 90%;
        margin: 10px 0;
    }
    
    .control-btn {
        width: 50px;
        height: 50px;
    }
    
    /* Mehr Kontrast für die Sichtbarkeit */
    .screen {
        background-color: rgba(0, 0, 0, 0.7);
    }
    
    /* Scrollbar bei Bedarf */
    .screen {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translateX(-50%) scale(0.5); }
    20% { opacity: 1; transform: translateX(-50%) scale(1.1); }
    80% { opacity: 1; transform: translateX(-50%) scale(1); }
    100% { opacity: 0; transform: translateX(-50%) scale(0.8); }
}

/* Überschriften und Text */
h1 {
    font-family: 'Press Start 2P', cursive;
    font-size: 2.5rem;
    margin-bottom: 15px;
    color: var(--primary-color);
    text-shadow: var(--glow-effect);
    letter-spacing: 3px;
    transform: perspective(500px) rotateX(10deg);
    text-align: center;
}

h2 {
    font-family: 'Press Start 2P', cursive;
    font-size: 2rem;
    margin-bottom: 20px;
    color: var(--secondary-color);
    text-shadow: 0 0 10px var(--secondary-color);
    text-align: center;
}

p {
    font-size: 1rem;
    margin-bottom: 30px;
    max-width: 80%;
    line-height: 1.5;
    text-align: center;
}

/* Sound Toggle */
.sound-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
}

.sound-label {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.sound-icon {
    font-size: 24px;
    color: var(--primary-color);
    text-shadow: 0 0 8px var(--primary-color);
    transition: all 0.3s ease;
}

#sound-checkbox {
    display: none;
}

#sound-checkbox:not(:checked) + .sound-icon {
    color: rgba(255, 255, 255, 0.5);
    text-shadow: none;
}

/* Buttons */
.buttons {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 5px;
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.primary-btn {
    background-color: var(--primary-color);
    color: var(--background-color);
    box-shadow: 0 0 15px rgba(0, 255, 170, 0.5);
}

.primary-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 0 20px rgba(0, 255, 170, 0.8);
}

.secondary-btn {
    background-color: transparent;
    color: var(--secondary-color);
    border: 2px solid var(--secondary-color);
    box-shadow: 0 0 10px rgba(255, 0, 170, 0.3);
}

.secondary-btn:hover {
    background-color: rgba(255, 0, 170, 0.1);
    box-shadow: 0 0 15px rgba(255, 0, 170, 0.5);
}

/* Mobile Controls */
#mobile-controls {
    position: absolute;
    bottom: 20px;
    left: 0;
    width: 100%;
    z-index: 2;
    display: flex;
    justify-content: space-around;
    padding: 0 10%;
}

.control-btn {
    width: 70px;
    height: 70px;
    background-color: rgba(0, 255, 170, 0.2);
    border: 2px solid var(--primary-color);
    border-radius: 50%;
    color: var(--primary-color);
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 10px rgba(0, 255, 170, 0.3);
}

.control-btn:active {
    background-color: rgba(0, 255, 170, 0.5);
}

/* Rangliste */
#leaderboard-list {
    width: 100%;
    max-width: 400px;
    margin: 0 auto 20px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    padding: 10px;
    max-height: 300px;
    overflow-y: auto;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    align-items: center;
    max-width: 100%;
}

.leaderboard-item:nth-child(1) {
    color: gold;
    font-weight: bold;
}

.leaderboard-item:nth-child(2) {
    color: silver;
    font-weight: bold;
}

.leaderboard-item:nth-child(3) {
    color: #cd7f32; /* Bronze */
    font-weight: bold;
}

.rank {
    width: 30px;
    text-align: center;
    flex-shrink: 0;
}

.player-name {
    flex-grow: 1;
    text-align: left;
    padding: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0; /* Wichtig für Flexbox-Überlauf */
    max-width: 60%; /* Begrenzung auf 60% der Breite */
}

.player-score {
    text-align: right;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.8rem;
    flex-shrink: 0;
    min-width: 50px; /* Stellt sicher, dass genug Platz für die Punktzahl ist */
}

#highscore-form {
    margin: 10px 0;
    animation: fadeIn 0.5s ease;
    text-align: center;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

#player-name {
    padding: 10px;
    border: 2px solid var(--primary-color);
    background-color: rgba(0, 0, 0, 0.7);
    color: var(--text-color);
    border-radius: 5px;
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    margin-bottom: 15px;
    width: 100%;
    max-width: 250px;
    text-align: center;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

#player-name:focus {
    outline: none;
    box-shadow: 0 0 8px var(--primary-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .game-container {
        width: 95%;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    p {
        font-size: 0.9rem;
    }

    .btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    .game-stats {
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.5rem;
    }

    .control-btn {
        width: 60px;
        height: 60px;
    }
}

/* Animationen */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.pulse {
    animation: pulse 1.5s infinite ease-in-out;
}

/* Mobile Anpassungen für Navigationsleiste */
@media (max-width: 768px) {
  /* Sicherer Bereich am unteren Rand */
  #game-canvas {
    height: calc(100% - 60px); /* 60px Abstand am unteren Rand */
  }
  
  /* Mobile Controls höher positionieren */
  #mobile-controls {
    bottom: 80px; /* Mehr Abstand vom unteren Rand */
  }
}

/* iPhone mit Notch und anderen Geräten mit "safe area" */
@supports (padding: max(0px)) {
  #mobile-controls {
    bottom: max(80px, env(safe-area-inset-bottom) + 60px);
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  
  #game-canvas {
    height: calc(100% - max(60px, env(safe-area-inset-bottom) + 40px));
  }
}

/* Verhindert Zoom durch Doppeltipp auf iOS */
* {
    touch-action: manipulation;
}

/* Zusätzliche Eigenschaften, um Zoomen zu verhindern */
html, body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}

/* Verhindert Pull-to-refresh und Überscroll-Effekte auf iPhone */
body {
    overscroll-behavior: none;
    overscroll-behavior-y: none;
}