body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    font-family: monospace;
    color: white;
    
    /* NEU: Setzt background.png als Hintergrund des gesamten Browsers */
    background-image: url('background.png');
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    background-attachment: fixed; /* Optional: Fixiert das Bild beim Scrollen */
    background-color: #1a1a2e; /* Fallback-Farbe */

    overflow: hidden; /* Keine Scrollbalken, das Spiel wird stattdessen skaliert */
    touch-action: manipulation; /* Kein Doppeltipp-Zoom auf Tablets */
    user-select: none;
    -webkit-user-select: none;
}

/* --- Startbildschirm --- */
#splash {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #0b0b1e;
    cursor: pointer;
    transition: opacity 0.6s;
}

#splash img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

#splash.fade-out {
    opacity: 0;
    pointer-events: none;
}

/* Blinkender Hinweis wie "PRESS FIRE" bei alten Heimcomputer-Spielen */
#splash-prompt {
    position: absolute;
    bottom: 6%;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    font-family: monospace;
    font-size: clamp(16px, 3vw, 28px);
    font-weight: bold;
    color: white;
    white-space: nowrap;
    background-color: rgba(0, 0, 0, 0.6);
    border: 3px solid gold;
    border-radius: 8px;
    animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
    to { visibility: hidden; }
}

/* --- Wrapper: Spielfeld + Steuerleiste, wird per JS skaliert --- */
#game-wrapper {
    width: 806px; /* 800px Spielfeld + 2 * 3px Rand */
    /* Position und Größe setzt fitToScreen() in script.js */
    position: fixed;
    top: 0;
    left: 0;
    transform-origin: top left;
}

/* --- Spielfeld und Hintergrund (Sterne/Transparenz) --- */
#game-container {
    width: 800px;
    height: 800px; 
    border: 3px solid gold;
    
    /* NEU: Hintergrund ist transparent, damit das Body-Bild durchscheint */
    background-color: rgba(15, 15, 28, 0.85); 
    
    position: relative;
    overflow: hidden; 
    

}

/* Visuelle Spalten-Trennung */
#game-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: repeating-linear-gradient(
        to right,
        transparent,
        transparent calc(100% / 5 - 1px),
        rgba(255, 255, 255, 0.1) calc(100% / 5 - 1px),
        rgba(255, 255, 255, 0.1) calc(100% / 5)
    );
    pointer-events: none;
}

#status-bar {
    position: absolute;
    top: 10px;
    width: 100%;
    text-align: center;
    font-size: 20px;
    z-index: 50;
}

/* --- Abwehr/Kanone (Player) gestalten --- */
#player {
    /* Neue Maße für das Bild */
    width: 100px; 
    height: 90px;
    
    background-image: url('defender.png'); /* <--- NEU: Bild einfügen */
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    background-color: transparent; 
    
    position: absolute;
    bottom: 10px;
    transition: left 0.1s linear;
    z-index: 30;
}




/* --- Angreifer (Gleichungen) gestalten --- */
.equation {
    position: absolute;
    width: 150px; 
    height: 100px; /* NEU: Höhe auf Bildhöhe angepasst */
    line-height: 100px; 
    text-align: center;
    
    /* Hintergrund ist nun das Bild */
    background-image: url('spaceship.png');
    background-size: cover;
    background-repeat: no-repeat;
    background-color: transparent; 
    
    border: none; /* Ränder entfernen */
    box-sizing: border-box;
    font-size: 18px;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 2px black;

    /* Alte futuristische Kanten entfernen */
    clip-path: none; 
    z-index: 10;
    
    /* NEU: Schwarzer Hintergrund für den Gleichungstext */
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Hinzufügen eines inneren span für den schwarzen Text-Hintergrund */
.equation span {
    padding: 5px 10px;
    background-color: rgba(0, 0, 0, 0.5); /* Schwarzer, leicht transparenter Hintergrund */
    border-radius: 5px;
    line-height: 1.2;
}




/* Modus "Zwei Schritte" (Erfahrene Defender): eigenes Raumschiff, kleinere Schrift für längere Gleichungen */
.equation.twostep {
    background-image: url('spaceship2.png');
    background-size: contain; /* Bild ist etwas höher als 3:2 – so werden die Flammen nicht abgeschnitten */
    background-position: center;
}

.equation.twostep span {
    font-size: 16px;
}

/* --- Rückmeldung zu groß (lila) / zu klein (petrol) --- */
:root {
    --too-big: #b040ff;
    --too-small: #00a893;
}

.too-big { color: var(--too-big); }
.too-small { color: var(--too-small); }

/* Gleichung wackelt und blinkt in der passenden Farbe */
.equation.wrong-too-big,
.equation.wrong-too-small {
    animation: wrongShake 0.4s;
}

.equation.wrong-too-big span {
    animation: flashTooBig 0.6s;
}

.equation.wrong-too-small span {
    animation: flashTooSmall 0.6s;
}

@keyframes flashTooBig {
    0%, 60% { background-color: var(--too-big); }
    100% { background-color: rgba(0, 0, 0, 0.5); }
}

@keyframes flashTooSmall {
    0%, 60% { background-color: var(--too-small); }
    100% { background-color: rgba(0, 0, 0, 0.5); }
}

/* Feuerball an der Trefferstelle */
.fireball {
    position: absolute;
    width: 70px;
    height: 70px;
    margin: -35px 0 0 -35px; /* um die Trefferstelle zentrieren */
    border-radius: 50%;
    z-index: 25;
    pointer-events: none;
    animation: fireball 0.6s ease-out forwards;
}

.fireball.too-big {
    background: radial-gradient(circle, #fff 0%, #e0a0ff 20%, var(--too-big) 50%, transparent 72%);
}

.fireball.too-small {
    background: radial-gradient(circle, #fff 0%, #90ffe8 20%, var(--too-small) 50%, transparent 72%);
}

@keyframes fireball {
    0% { transform: scale(0.3); opacity: 1; }
    100% { transform: scale(1.8); opacity: 0; }
}

/* Text "zu groß!" / "zu klein!" unter dem Raumschiff (nur in den ersten Leveln) */
.size-hint {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 3px 10px;
    border-radius: 6px;
    color: white;
    font-size: 18px;
    font-weight: bold;
    line-height: 1.2;
    white-space: nowrap;
    animation: hintFade 1.5s forwards;
}

.size-hint.too-big { background-color: var(--too-big); color: white; }
.size-hint.too-small { background-color: var(--too-small); color: white; }

@keyframes hintFade {
    0%, 70% { opacity: 1; }
    100% { opacity: 0; }
}

/* --- Erklärseite "Die Probe" --- */
.equation.demo {
    position: relative; /* im Menü nicht frei schwebend wie im Spiel */
    margin: 10px 0;
}

.probe-rows {
    display: grid;
    grid-template-columns: auto auto auto;
    align-items: center;
    gap: 10px 20px;
    font-size: 20px;
    margin: 5px 0 10px;
}

.probe-ball {
    width: 36px;
    height: 36px;
    line-height: 36px;
    text-align: center;
    border-radius: 50%;
    font-weight: bold;
    color: black;
}

.probe-ball.too-big { background-color: var(--too-big); color: white; box-shadow: 0 0 10px var(--too-big); }
.probe-ball.too-small { background-color: var(--too-small); color: white; box-shadow: 0 0 10px var(--too-small); }
.probe-ball.correct { background-color: #ffff00; box-shadow: 0 0 10px #ffff00; }

.probe-result.correct { color: #ffff00; }

.button-row {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

#overlay .button-row button.back-button {
    margin-top: 10px;
}

/* Falscher Schuss: Gleichung wackelt und blinkt rot */
.equation.wrong {
    animation: wrongShake 0.4s;
}

.equation.wrong span {
    animation: wrongFlash 0.6s;
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-10px); }
    40% { transform: translateX(10px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}

@keyframes wrongFlash {
    0%, 60% { background-color: rgba(230, 0, 0, 0.9); }
    100% { background-color: rgba(0, 0, 0, 0.5); }
}

/* Überhitzte Kanone nach Fehlschuss: rot glühend, Zahlenknöpfe ausgegraut */
#player.overheated {
    filter: sepia(1) saturate(6) hue-rotate(-30deg) brightness(0.8);
    animation: wrongShake 0.4s;
}

#controls.overheated button:not(.pause-button):not(.sound-button) {
    opacity: 0.35;
}

/* Einblendungen (Level-Up, Kombo, Überhitzung) */
.game-message {
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 15px;
    color: white;
    font-size: 36px;
    font-weight: bold;
    white-space: nowrap;
    border-radius: 10px;
    z-index: 150;
    pointer-events: none;
    animation: fadeOut 2s forwards;
}

@keyframes fadeOut {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}

/* Styling für das fliegende Geschoss */
.projectile {
    position: absolute;
    width: 30px; 
    height: 30px;
    line-height: 30px; 
    text-align: center;
    background-color: #ffff00; 
    color: black; 
    font-size: 16px;
    font-weight: bold;
    border-radius: 50%; 
    box-shadow: 0 0 5px #ffff00, 0 0 10px rgba(255, 255, 0, 0.5); 
    z-index: 20;
}

/* --- Game Over / Start / Modus-Auswahl / PAUSE Overlays (Korrekturen für Buttons) --- */
#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 30px;
    z-index: 100;
    display: none; 
    padding: 20px;
    box-sizing: border-box;
}

/* Stil für die kleineren Anweisungs-Überschriften */
#overlay h4 {
    margin-top: 20px;
    margin-bottom: 5px;
    font-size: 20px; 
}

/* Stil für normale Textabsätze in Overlays */
#overlay p {
    font-size: 18px;
    margin: 5px 0;
    text-align: center;
}

/* Stil für Listen in Overlays (Bedienhinweise) */
#overlay ul {
    list-style: none;
    padding: 0;
    text-align: left;
    max-width: 400px;
    margin-bottom: 20px;
}

#overlay li {
    margin: 5px 0;
    font-size: 16px;
}

/* Bestenliste auf dem Game-Over-Bildschirm */
#overlay ol.highscores {
    font-size: 20px;
    margin: 5px 0 15px;
    padding-left: 40px;
}

#overlay ol.highscores li {
    font-size: 20px;
}

#overlay ol.highscores li.new-entry {
    color: gold;
    font-weight: bold;
}

#overlay .new-record {
    color: gold;
    font-size: 26px;
    font-weight: bold;
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

/* Wichtig für die Größe und Sichtbarkeit aller Buttons im Overlay */
#overlay button, #overlay .mode-selection button { 
    padding: 10px 20px;
    margin: 10px;
    font-size: 20px;
    cursor: pointer;
    background-color: #00aaff;
    border: none;
    color: white;
    border-radius: 5px;
    transition: background-color 0.2s;
}

#overlay button:hover {
    background-color: #0099ee;
}

.mode-selection {
    display: grid;
    grid-template-columns: 1fr 1fr; /* 2 Spalten: einzelne Rechenarten, darunter gemischte */
    max-width: 640px;
}

/* Bereich mit nur einem Modus: eine Spalte statt zwei */
.mode-selection.single {
    grid-template-columns: 1fr;
}

/* --- Startseite: die beiden Defender zum Anklicken ---
   Alle Figuren gleich breit, unten bündig: so bleibt der junge Defender kleiner (Bild ist niedriger). */
.defender-choice {
    display: flex;
    align-items: flex-end;
    gap: 40px;
    margin-top: 20px;
}

#overlay button.defender-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    width: 250px;
    padding: 20px 10px;
    margin: 0;
    background-color: rgba(255, 255, 255, 0.05);
    border: 3px solid rgba(255, 215, 0, 0.4);
    border-radius: 15px;
    font-family: monospace;
    transition: transform 0.15s, border-color 0.15s, background-color 0.15s;
}

#overlay button.defender-card:hover {
    background-color: rgba(255, 215, 0, 0.12);
    border-color: gold;
    transform: scale(1.05);
}

.defender-card img {
    width: 130px;
    height: auto;
}

.defender-card .defender-name {
    color: gold;
    font-size: 22px;
    font-weight: bold;
}

.defender-card small {
    color: #ccc;
    font-size: 15px;
}

/* --- Unterseite: gewählte Figur links, Modus-Knöpfe rechts --- */
.defender-group {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-top: 15px;
}

.defender-group img {
    width: 150px;
    height: auto;
}

/* Zurück-Knopf dezenter als die Modus-Knöpfe */
#overlay button.back-button {
    margin-top: 25px;
    font-size: 16px;
    background-color: #555;
}

#overlay button.back-button:hover {
    background-color: #666;
}

/* --- PAUSE Zustand --- */
#pause-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 40px;
    z-index: 99;
    display: none;
}

/* --- Bildschirm-Steuerung (Zahlen-Buttons zum Schießen + Pause) --- */
#controls {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    margin-top: 10px;
}

#controls button {
    flex: 1;
    height: 70px;
    padding: 0;
    font-family: monospace;
    font-size: 28px;
    font-weight: bold;
    color: black;
    background-color: #ffff00;
    border: none;
    border-radius: 10px;
    box-shadow: 0 0 6px rgba(255, 255, 0, 0.6);
    cursor: pointer;
    touch-action: manipulation;
}

#controls button:active {
    transform: scale(0.92);
    background-color: #ffd000;
}

#controls .pause-button {
    background-color: #00aaff;
    color: white;
    box-shadow: none;
}

#controls .pause-button:active {
    background-color: #0099ee;
}

#controls .sound-button {
    background-color: #555;
    color: white;
    box-shadow: none;
}

#controls .sound-button:active {
    background-color: #444;
}
