html, body {
    background-color: #050508;
    color: #fff;
    font-family: system-ui, -apple-system, sans-serif;
    margin: 0; padding: 0; width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
    overflow: hidden; box-sizing: border-box; -webkit-text-size-adjust: 100%;
}

#gameContainer {
    position: relative; width: 96vw; max-width: 800px; max-height: 96vh;
    display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,0.8);
    background: #15161e; border-radius: 12px; overflow: hidden; padding: 6px;
}

/* RETTET: Startskærmen tilpasser sig nu skærmen flydende uden fastlåste pixel-proportioner */
#startScreen {
    width: 100%;
    min-height: 250px; /* Giver plads på mobilen, men tvinger ikke en enorm højde */
    height: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #0f1015;
    text-align: center;
    padding: 20px 0;
    box-sizing: border-box;
}

#startScreen h1 { font-size: 1.8rem; margin-bottom: 15px; color: #00ffcc; text-shadow: 0 0 10px rgba(0, 255, 204, 0.3); }

.difficulty-btn {
    background: #1f2330; color: white; border: 2px solid #2f354a; padding: 12px 20px;
    margin: 6px; font-size: 15px; font-weight: bold; cursor: pointer; border-radius: 8px; width: 85%; max-width: 250px;
}

#gameGrid { width: 100%; display: flex; flex-direction: column; position: relative; }

canvas {
    width: 100%; height: auto; aspect-ratio: 800 / 450; background-color: #0a0a12;
    display: block; border-radius: 6px;
    image-rendering: -moz-crisp-edges; image-rendering: -webkit-crisp-edges; image-rendering: pixelated;
    filter: drop-shadow(0 0 4px rgba(0, 210, 255, 0.15));
}

#topBar {
    display: flex; justify-content: space-between; align-items: center; background: #11121a;
    padding: 8px 12px; font-size: 14px; font-weight: bold; border-bottom: 2px solid #1f2330; margin-bottom: 4px; border-radius: 6px;
}
#errorLog { color: #ff3333; font-size: 12px; font-weight: bold; transition: opacity 0.3s ease; opacity: 0; }

#menuBar {
    display: flex; background: #11121a; padding: 8px; justify-content: space-between;
    align-items: center; border-top: 2px solid #1f2330; margin-top: 4px; border-radius: 6px; gap: 6px;
}

.tower-btn { background: #1f2330; color: white; border: 2px solid #2f354a; padding: 6px 4px; cursor: pointer; border-radius: 6px; text-align: center; flex: 1; min-width: 0; font-size: 11px; font-weight: bold; }
.tower-btn.selected { border-color: #00ffcc; background: #16352b; }
.tower-btn div { font-size: 9px; color: #a0a8c2; margin-top: 1px; font-weight: normal; }

.game-controls { display: flex; gap: 4px; align-items: center; }
.game-controls button { width: 34px; height: 34px; border: none; border-radius: 50%; font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 6px rgba(0,0,0,0.3); }

#waveBtn { background: #2ecc71; color: white; width: 34px; height: 34px; border: none; border-radius: 50%; font-size: 14px; cursor: pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.3); }
#pauseBtn { background: #3498db; color: white; }
#speedBtn { background: #9b59b6; color: white; }

/* NY FÆLLES STYLING FOR INDER-VINDUER / POPUPS */
.ingame-popup {
    display: none; /* Skjult som standard */
    position: absolute;
    background: rgba(15, 16, 22, 0.95);
    border-radius: 8px; padding: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.7);
    flex-direction: column; z-index: 100;
}

#upgradeMenu { top: 15px; left: 15px; width: 150px; border: 2px solid #00ffcc; }
#upgradeMenu h3 { margin: 0 0 4px 0; font-size: 12px; color: #00ffcc; }
#upgradeMenu p { margin: 0 0 8px 0; font-size: 11px; color: #a0a8c2; line-height: 1.3; }
#upgradeConfirmBtn, #sellTowerBtn, #upgradeCloseBtn { padding: 5px 6px; font-weight: bold; font-size: 11px; border: none; cursor: pointer; border-radius: 4px; color: white; flex: 1; text-align: center; }
#upgradeConfirmBtn { background: #27ae60; }
#sellTowerBtn { background: #e67e22; }
#upgradeCloseBtn { background: #c0392b; }

#enemyInfoPanel {
    display: none !important; /* Tvinger loggen til at starte som helt lukket og skjult */
    position: absolute;
    top: 15px;
    right: 15px;
    width: 140px;
    background: rgba(15, 16, 22, 0.95);
    border: 2px solid #3498db;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.7);
    flex-direction: column;
    z-index: 100;
}
#enemyInfoPanel h3 { margin: 0 0 6px 0; font-size: 11px; color: #3498db; text-transform: uppercase; }
.enemy-type-row { font-size: 10px; color: #a0a8c2; margin: 3px 0; line-height: 1.2; font-weight: bold; }

#gameOverScreen { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(5,5,8,0.9); flex-direction: column; justify-content: center; align-items: center; color: #ff3333; font-size: 1.8rem; font-weight: bold; z-index: 200; }
/* Gør at "Prøv Igen" knappen lyser op og reagerer, når man holder fingeren/musen over den */
#gameOverScreen button:hover {
    background: #27ae60 !important;
    transform: scale(1.05);
}

/* ==========================================================================
   OPDATERET RUMMELIG PROCENT-BASERET FULD SKÆRM
   ========================================================================== */

/* Containeren låser sig over hele skærmen */
#gameContainer.fullscreen-active {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 0 !important;
    z-index: 99999 !important;
    background-color: #050508; 
    
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
}

/* Selve spillet holdes samlet og udnytter procenter af skærmen i stedet for pixels */
#gameContainer.fullscreen-active #gameGrid {
    display: flex;
    flex-direction: column;
    
    /* Spillet fylder nu op til 95% af skærmens bredde eller 85% af højden, 
       så det altid bliver så stort som muligt uden at blive skåret af */
    width: min(95vw, calc(83vh * 800 / 450)) !important;
    max-width: none !important; /* RETTET: Fjerner 800px grænsen fuldstændigt! */
    height: auto !important;
    margin: auto !important;
}

/* Canvas, topBar og menuBar følger nu spillets nye store procent-bredde */
#gameContainer.fullscreen-active canvas,
#gameContainer.fullscreen-active #topBar,
#gameContainer.fullscreen-active #menuBar {
    width: 100% !important;
    height: auto !important;
}


@media (max-width: 600px) {
    #topBar { padding: 6px 10px; font-size: 12px; }
    .tower-btn { font-size: 10px; padding: 4px 2px; }
    .tower-btn div { font-size: 8px; }
}
/* ULTRA-OPTIMERET TIL SMÅ MOBILSKÆRME PÅ LANGS (F.eks. iPhone 12) */
@media (orientation: landscape) and (max-height: 450px) {
    #gameContainer {
        width: auto;
        height: 100vh !important; /* Udnytter absolut hele skærmens højde */
        max-height: 100vh !important;
        aspect-ratio: 800 / 450; /* Justeret for at give mere plads til bunden */
        padding: 2px !important;
    }
    
    #topBar { 
        padding: 3px 8px !important; 
        font-size: 11px !important; 
        margin-bottom: 2px !important; 
    }
    
    #menuBar { 
        padding: 4px !important; 
        margin-top: 2px !important;
        gap: 4px !important;
    }
    
    /* RETTET: Gør knapperne højere og fordeler tekst/pris på 2 rækker */
    .tower-btn { 
        font-size: 10px !important; 
        padding: 4px 2px !important; 
        display: flex !important;
        
        /* RETTET: Sætter tekst og pris i en lodret kolonne (2 rækker) */
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 2px !important;
        
        /* Holder knapperne 100% symmetriske og lige store */
        flex: 1 1 0% !important;
        width: 0 !important;
        
        /* RETTET: Tillader nu teksten at dele sig naturligt */
        white-space: normal !important; 
        
        /* Sætter en god minimumshøjde så prisen altid kan ses */
        min-height: 36px !important; 
    }
    
    /* Gør prisen på række 2 tydelig og flot */
    .tower-btn div { 
        display: block !important; 
        font-size: 9px !important; 
        margin-top: 0px !important; 
        color: #00ffcc !important; /* Gør prisen neon-grøn så den skiller sig ud */
        font-weight: bold !important;
    }
    
    /* Krymper kontrolknapperne en smule */
    .game-controls button, #waveBtn { 
        width: 28px !important; 
        height: 28px !important; 
        font-size: 11px !important; 
    }
}
/* SIKRING: Når spillet er aktivt, tvinges startskærmen til 0px højde, 
   så den overhovedet ikke kan skubbe bundmenuen ud af skærmen! */
#gameContainer.fullscreen-active #startScreen {
    display: none !important;
    height: 0 !important;
    min-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
}