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

:root {
    --c64-blue-dark: #0000AA;
    --c64-blue-light: #8888FF;
    --c64-text: #5555FF;
    --c64-highlight: #FFFFFF;
    --font-retro: 'Press Start 2P', monospace;
    --font-mono: 'VT323', monospace; /* Lesbarere Monospace-Schrift */
    --border-width: 15px;
    --panel-bg: rgba(0, 0, 50, 0.6);
    --panel-border: rgba(136, 136, 255, 0.7);
}

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

html, body {
  width: 100%;
  height: 100%;
  color: white;
  background-color: #000;
  font-family: var(--font-mono);
  font-size: 20px; /* Leichte Erhöhung für bessere Lesbarkeit */
  -webkit-text-size-adjust: 100%; /* Verhindert Auto-Zoom auf iOS */
}

body {
    overflow-x: hidden; /* Verhindert horizontales Scrollen */
}

/* =============================================================== */
/* C64 Retro Theme Haupt-Container
/* =============================================================== */

/* Basis-Layout für die Menü-Zustände auf dem Body anwenden */
body.state-menu,
body.state-gameover {
    font-family: var(--font-mono);
    color: var(--c64-text);
    overflow-y: auto;
    padding: 1rem 0;
}

/* NEU: Animierter Sternenhintergrund für den Startbildschirm */
@keyframes move-stars {
    from { background-position: 0 0; }
    to { background-position: -10000px 5000px; }
}

body.state-menu {
    background-color: #000;
    background-image: 
        radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 40px),
        radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 30px),
        radial-gradient(white, rgba(255,255,255,.1) 2px, transparent 40px),
        radial-gradient(rgba(255,255,255,.4), rgba(255,255,255,.1) 2px, transparent 30px);
    background-size: 550px 550px, 350px 350px, 250px 250px, 150px 150px; 
    background-position: 0 0, 40px 60px, 130px 270px, 70px 100px;
    animation: move-stars 200s linear infinite;
}

body.state-gameover {
    background-color: var(--c64-blue-dark);
}


/* Der "Bildschirm"-Rahmen wird zum Haupt-Container */
.main-container {
    width: 95%;
    max-width: 900px;
    margin: 3vh auto;
    text-align: center;
}

/* NEU: Game-Logo Styling */
.game-title {
    font-family: var(--font-retro);
    color: var(--c64-highlight);
    font-size: clamp(2rem, 8vw, 4rem); /* Responsive Schriftgröße */
    text-shadow: 
        0 0 10px #fff,
        0 0 20px var(--c64-blue-light),
        3px 3px 0px #000,
        -3px -3px 0px #000;
    margin-bottom: 2rem;
    line-height: 1.2;
    word-break: break-word; /* Verhindert Überlaufen bei extremen Breiten */
}

/* NEU: Das "Cockpit Panel" für die Interaktion */
.start-panel {
    background: var(--panel-bg);
    border: 2px solid var(--panel-border);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: 10px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 0 25px rgba(0,0,100,0.5);
}

/* Der alte C64-Container wird für Game Over und Pause wiederverwendet */
.c64-container {
    border: var(--border-width) solid var(--c64-blue-light);
    box-shadow: inset 0 0 25px rgba(0,0,0,0.7);
    background-color: var(--c64-blue-dark);
    padding: 2rem 3rem;
    width: 95%;
    max-width: 900px;
    text-align: center;
    margin: 3vh auto; /* Zentriert den Container und gibt Abstand */
    /* NEU: Flexbox für eine bessere Ausrichtung der Kinder, besonders auf Mobilgeräten */
    display: flex;
    flex-direction: column;
}

.c64-container h1,
.c64-container h2 {
    font-family: var(--font-retro);
    color: var(--c64-highlight);
    font-size: 2em;
    margin-bottom: 2rem;
    line-height: 1.2;
}

.c64-container h3 {
    font-family: var(--font-retro);
    color: var(--c64-blue-light);
    font-size: 1.1em;
    margin-bottom: 1rem;
    text-align: left;
}

.c64-container p {
    margin: 1.5rem 0;
    line-height: 1.5;
    text-align: center;
}

/* =============================================================== */
/* C64 Komponenten (Buttons, Inputs etc.)
/* =============================================================== */

.c64-input {
    background: transparent;
    border: 3px solid var(--c64-blue-light);
    color: var(--c64-highlight);
    font-family: var(--font-mono);
    font-size: 1.2em;
    padding: 10px;
    text-align: center;
    width: 80%;
    max-width: 400px;
    image-rendering: pixelated; /* Für scharfe Kanten */
}

.c64-input::placeholder {
    color: var(--c64-text);
    opacity: 0.8;
}

.c64-input:focus {
    outline: 3px solid var(--c64-highlight);
    background-color: #00000030;
}

.c64-button {
    font-family: var(--font-retro);
    background: transparent;
    border: none;
    color: var(--c64-highlight);
    font-size: 1.2em;
    padding: 1rem 2rem;
    cursor: pointer;
    margin-top: 1.5rem;
    text-shadow: 2px 2px #00000050;
    text-transform: uppercase;
}

.c64-button:hover::before, .c64-button:focus::before {
    content: '> ';
    animation: blinker 1s linear infinite;
}
.c64-button:hover::after, .c64-button:focus::after {
    content: ' <';
    animation: blinker 1s linear infinite;
}

@keyframes blinker {
    50% { opacity: 0; }
}

/* Radio buttons C64 style */
.c64-radio-label {
    display: inline-block;
    margin: 0.5rem 1rem;
    cursor: pointer;
    color: var(--c64-text);
}

.c64-radio-label input[type="radio"] {
    opacity: 0; /* Verstecken, aber für Accessibility erreichbar halten */
    position: absolute;
    width: 0;
}

.c64-radio-label span::before {
    content: '[ ]';
    display: inline-block;
    margin-right: 0.5rem;
    color: var(--c64-blue-light);
}

.c64-radio-label input[type="radio"]:checked + span::before {
    content: '[X]';
    color: var(--c64-highlight);
}

.c64-radio-label input[type="radio"]:checked + span {
    color: var(--c64-highlight);
}

.c64-radio-label input[type="radio"]:focus + span {
    outline: 2px solid var(--c64-highlight);
    outline-offset: 2px;
}

.help-text {
    font-size: 0.9em;
    opacity: 0.9;
}
.help-text-small {
    font-size: 0.8em;
    opacity: 0.8;
    max-width: 300px;
    margin: 0.5rem auto;
    line-height: 1.3;
}

/* =============================================================== */
/* Layout und spezifische Sektionen
/* =============================================================== */

/* Zuweisung des Themes an die UI-Zustände */
body.state-menu #startScreen,
body.state-gameover #gameOverScreen {
    display: block;
}

#startScreen {
    /* Kein spezielles Styling mehr hier, wird über main-container und start-panel gesteuert */
}

#controlsInfo {
    margin-top: 2rem;
    background: var(--panel-bg);
    border: 2px solid var(--panel-border);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: 10px;
    padding: 2rem;
}

#controlsInfo h2 {
    font-family: var(--font-retro);
    color: var(--c64-highlight);
    margin-bottom: 1.5rem;
    font-size: 1.5em;
}

#controlsInfo .controls-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 3rem;
    justify-content: center;
    margin-top: 1rem;
}

#controlsInfo article {
    flex-basis: 300px;
    text-align: left;
}

#controlsInfo ul {
    list-style: none;
    padding-left: 0;
}

#controlsInfo li {
    margin-bottom: 0.5rem;
}


/* Responsive Anpassungen */
@media (max-width: 768px) {
    body {
        font-size: 16px;
    }
    .c64-screen {
        padding: 1rem;
    }
    .c64-container {
        border-width: 10px;
        padding: 1.5rem;
        margin: 1rem auto; /* Weniger Margin auf Mobilgeräten */
    }
    .c64-container h1,
    .c64-container h2 {
        font-size: 1.5em;
    }
    .main-container {
        margin: 1rem auto;
    }
    .highscore-container-desktop {
        flex-direction: column;
        gap: 1rem; /* Abstand zwischen den Listen auf Mobilgeräten */
    }
}

@media (max-width: 480px) {
    body {
        font-size: 14px;
    }
    .c64-container {
        padding: 1rem;
    }
    .c64-container h1,
    .c64-container h2 {
        font-size: 1.3em;
    }
    .c64-button {
        font-size: 1em;
        padding: 0.8rem 1.5rem;
    }
    .volume-slider {
        flex-direction: column;
        gap: 5px;
    }
    input[type="range"] {
        width: 100%;
    }
    .level-button {
        padding: 10px 15px;
        font-size: 0.9em;
    }
}


/* =============================================================== */
/* GENERAL GAME STYLES (wird teilweise vom C64 Theme überschrieben)
/* =============================================================== */

a {
  color: var(--c64-blue-light);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
  color: var(--c64-highlight);
}

button {
  cursor: pointer;
  border: 1px solid white;
  background-color: #333;
  color: white;
  padding: 10px 20px;
  border-radius: 5px;
}

button:hover {
  background-color: #555;
}

input[type="text"] {
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

/* Globale Klassen für Spielzustände */
body.state-menu #gameArea,
body.state-menu #gameOverScreen,
body.state-menu #levelSelect {
  display: none;
}

body.state-playing #startScreen,
body.state-playing #gameOverScreen {
  display: none;
}

body.state-gameover #startScreen,
body.state-gameover #gameArea,
body.state-gameover #levelSelect {
  display: none;
}

/* Spezifische Sektionen */
#gameOverScreen,
#levelSelect {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  z-index: 1000;
}

#startScreen, /* Wird nun von .c64-screen gehandhabt */
#gameOverScreen {
    /* display: flex; auskommentiert, da es oben schon definiert ist */
    /* flex-direction: column; */
    /* justify-content: center; */
    /* align-items: center; */
    /* height: 100vh; */ /* Wird von .c64-screen gehandhabt */
    /* padding: 20px; */
}

#levelSelect {
    display: none; /* Initial versteckt */
    justify-content: center;
    align-items: center;
}

.level-select-content {
    /* background-color: transparent; */ /* Fehlerhafte Regel entfernt */
    /* padding: 0; */
    /* border: none; */
    /* box-shadow: none; */
    text-align: center;
    max-width: 700px; /* Etwas breiter für die Level-Buttons */
}

.volume-controls {
    margin: 20px 0;
    border-top: 3px solid var(--c64-blue-light);
    border-bottom: 3px solid var(--c64-blue-light);
    padding: 1.5rem 0;
}
.volume-slider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px 0;
}
.volume-slider label {
    margin-right: 10px;
    width: 100px;
    text-align: right;
    font-size: 1.1em;
    color: var(--c64-highlight);
}

/* C64 Style für Range Inputs */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 200px;
  height: 15px;
  background: var(--c64-blue-dark);
  border: 2px solid var(--c64-blue-light);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  background: var(--c64-highlight);
  border: 2px solid var(--c64-blue-light);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 25px;
  height: 25px;
  background: var(--c64-highlight);
  border: 2px solid var(--c64-blue-light);
  cursor: pointer;
}


#levelButtons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin: 2rem 0;
}

.level-button {
    font-family: var(--font-retro);
    background-color: transparent;
    border: 3px solid var(--c64-text);
    color: var(--c64-text);
    padding: 15px 20px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.2s;
}

.level-button:hover, .level-button:focus {
    border-color: var(--c64-highlight);
    color: var(--c64-highlight);
    background-color: var(--c64-text);
}

.level-button.unlocked {
    border-color: var(--c64-blue-light);
    color: var(--c64-blue-light);
}

.level-button.unlocked:hover, .level-button.unlocked:focus {
    background-color: var(--c64-blue-light);
    color: var(--c64-blue-dark);
}

.level-button.completed {
    border-color: var(--c64-highlight);
    color: var(--c64-highlight);
}
.level-button.completed:hover, .level-button.completed:focus {
    background-color: var(--c64-highlight);
    color: var(--c64-blue-dark);
}


#highscoreBoard {
  margin: 20px 0;
  width: 100%;
  max-width: 800px;
}

#highscoreList {
  list-style: none;
  padding: 0;
}

.highscore-container-desktop {
    display: flex;
    justify-content: space-around;
    gap: 2rem;
}
.score-list-wrapper {
    background: rgba(0,0,0,0.3);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid #444;
    flex-grow: 1;
    min-width: 250px; /* Stellt sicher, dass die Boxen nicht zu schmal werden */
}

.score-list {
    list-style-type: none;
    padding: 0;
}
.score-entry, .score-header-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem;
    border-bottom: 1px solid #333;
    font-family: var(--font-mono); /* Einheitliche Schrift */
    font-size: 1em;
}
.score-header-row {
    font-weight: bold;
    color: #00ffff;
    font-family: var(--font-retro);
    font-size: 0.8em;
}
.score-entry.top-score {
    color: gold;
    font-weight: bold;
}
.score-entry span, .score-header-row span {
    flex-basis: 33%;
    text-align: left;
}
.score-entry span:nth-child(2), .score-header-row span:nth-child(2) {
    text-align: center;
}
.score-entry span:nth-child(3), .score-header-row span:nth-child(3) {
    text-align: right;
}


#gameArea {
    position: relative;
    width: 100%;
    height: 100%;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    background-color: #000;
}

/* NEU: HUD-Styling */
#gameHUD {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 1vw 2vw;
    color: white;
    font-family: var(--font-mono); /* Angepasst */
    font-size: 2vw; /* Vergrößert für Lesbarkeit */
    display: flex;
    justify-content: space-between;
    pointer-events: none; /* Klicks gehen durch das HUD zur Canvas */
    box-sizing: border-box;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.7);
}

#gameHUD p {
    margin: 0;
    padding: 0.2vw 0;
    text-align: left;
}

.hud-right {
    text-align: right;
}

#powerupBars {
    margin-top: 1vw;
    min-width: 15vw;
}

.powerup-bar {
    width: 100%;
    height: 10px;
    background-color: #555;
    border: 1px solid white;
    margin-top: 5px;
}

.powerup-bar > div {
    height: 100%;
    transition: width 0.2s linear;
}

/* Spezifische Anpassungen für Touch-Geräte */
.is-touch #gameHUD {
    font-size: 3.5vw; /* Größere Schrift für bessere Lesbarkeit */
}

/* Verstecke Desktop-spezifische Anleitungen auf Touch-Geräten */
.is-touch #controlsInfo article:first-child {
    display: none;
}
/* Zeige Touch-spezifische Anleitungen nur auf Touch-Geräten */
#controlsInfo article:last-child {
    display: none;
}
.is-touch #controlsInfo article:last-child {
    display: block;
}


/* Touch-Steuerung */
#touchControls {
    position: absolute;
    bottom: 20px;
    left: 0;
    width: 100%;
    display: none; /* Standardmäßig ausgeblendet */
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 20px;
    pointer-events: none;
}

.is-touch #touchControls {
    display: flex;
}

.dpad, .action-buttons {
    pointer-events: auto;
}

.dpad {
    position: relative;
    width: 150px;
    height: 150px;
}

.dpad-btn {
    position: absolute;
    width: 50px;
    height: 50px;
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.5);
    color: white;
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
}
#dpad-up { top: 0; left: 50px; }
#dpad-left { top: 50px; left: 0; }
#dpad-right { top: 50px; left: 100px; }

.touch-btn {
    width: 70px;
    height: 70px;
    background: rgba(255,255,255,0.3);
    border: 2px solid rgba(255,255,255,0.7);
    color: white;
    font-size: 28px;
    border-radius: 50%;
    margin-left: 15px;
}

/* Mobile Responsiveness für Touch-Steuerung */
@media (max-aspect-ratio: 1/1) { /* Portrait-Modus */
    #touchControls {
        bottom: 5vh;
        padding: 0 5vw;
    }
    .dpad { transform: scale(0.9); }
    .action-buttons { transform: scale(0.9); }
}

@media (max-height: 450px) { /* Niedrige Querformat-Bildschirme */
     #touchControls {
        bottom: 10px;
    }
    .dpad { transform: scale(0.8); }
    .action-buttons { transform: scale(0.8); }
}

/* Verhindert unerwünschte Touch-Effekte */
.dpad-btn, .touch-btn {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* Globaler Sound-Button */
#globalSoundToggle {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 100;
    width: 50px;
    height: 50px;
    font-size: 24px;
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: 50%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

footer {
    width: 100%;
    text-align: center;
    color: var(--c64-text);
    font-size: 0.9em;
    padding: 1rem;
}

.state-playing footer, .state-gameover footer {
    display: none;
}

