body { 
    background-color: #111; 
    color: var(--ui-color); 
    font-family: 'Courier New', Courier, monospace; 
    padding: 0; 
    margin: 0; 
    height: 100vh; 
    overflow: hidden; 
    display: flex; 
    flex-direction: column; 
    /* NEU: Scrollbar-Farben für Firefox */
    scrollbar-width: thin;
    scrollbar-color: var(--ui-color) #111;
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #111; border-left: 1px solid var(--ui-color); }
::-webkit-scrollbar-thumb { background: var(--ui-color); }
::-webkit-scrollbar-thumb:hover { background: #afa; }

:root {
    --ui-color: #0f0;
    --ui-glow: rgba(0, 255, 0, 0.2);
    --ui-highlight-dark: #aa0;
    --ui-highlight-dark-glow: rgba(170, 170, 0, 0.2);
    --ui-info-dark: #0aa;
    --ui-info-dark-glow: rgba(0, 170, 170, 0.2);
    --ui-danger-light: #f55;
    --ui-danger-light-glow: rgba(255, 85, 85, 0.2);
}

#toastContainer {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
}

.toast-message {
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid var(--ui-color);
    color: var(--ui-color);
    padding: 10px 20px;
    margin-bottom: 10px;
    font-weight: bold;
    box-shadow: 0 0 10px var(--ui-color);
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity 0.3s, transform 0.3s;
    font-family: 'Courier New', monospace;
}

.toast-message.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-message.error {
    border-color: var(--ui-danger-light);
    color: var(--ui-danger-light);
    box-shadow: 0 0 10px var(--ui-danger-light);
}

#authOverlay { 
    position: fixed; 
    top: 0; left: 0; 
    width: 100%; height: 100%; 
    background: rgba(0,0,0,0.9); 
    z-index: 2000; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
}
.auth-box { 
    background: #000; 
    border: 2px solid var(--ui-color); 
    padding: 30px; 
    width: 350px; 
    text-align: center; 
    box-shadow: 0 0 15px var(--ui-color); 
}
.auth-input { 
    background: #222; 
    border: 1px solid var(--ui-color); 
    color: var(--ui-color); 
    padding: 8px; 
    width: 80%; 
    margin-bottom: 15px; 
    font-family: 'Courier New', monospace; 
}
.auth-btn { 
    background: var(--ui-color); 
    color: #000; 
    border: none; 
    padding: 10px 20px; 
    cursor: pointer; 
    font-weight: bold; 
    font-family: 'Courier New', monospace; 
    width: 85%; 
    margin-bottom: 10px; 
}
.auth-btn:hover { background: #cfc; }
.auth-link { font-size: 0.8em; cursor: pointer; color: gray; text-decoration: underline; }
.auth-link:hover { color: var(--ui-color); }

.top-bar-container { 
    display: none; 
    flex-direction: column; 
    background-color: #000; 
    border-bottom: 2px solid var(--ui-color); 
    z-index: 100; 
}
.top-bar-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 10px 20px; 
    /*border-bottom: 1px dashed var(--ui-color);*/ 
}
.top-bar-resources { 
    display: flex; 
    justify-content: space-evenly; 
    padding: 10px 20px; 
    background-color: #050505; 
    /* NEU: Erlaubt Umbrüche auf kleinen Bildschirmen */
    flex-wrap: wrap;
    gap: 10px; 
}

.base-select { 
    background: #222; 
    color: var(--ui-color); 
    border: 1px solid var(--ui-color); 
    font-family: 'Courier New', monospace; 
    font-size: 1.2em; 
    font-weight: bold; 
    padding: 5px; 
    cursor: pointer; 
}

.res-item { font-size: 0.9em; }
.res-item strong {
    color: var(--ui-info);
}
.top-bar-right button { 
    background: #222; 
    color: var(--ui-color); 
    border: 1px solid var(--ui-color); 
    padding: 5px 15px; 
    cursor: pointer; 
    margin-left: 10px; 
    font-family: 'Courier New', monospace; 
    transition: background 0.3s, color 0.3s;
}
.top-bar-right button:hover { background: var(--ui-color); color: #000; }
.top-bar-right .logout-btn { background: #440000; color: var(--ui-danger-light); border-color: var(--ui-danger-light); }
.top-bar-right .logout-btn:hover { background: var(--ui-danger-light); color: #000; }

.view-section { 
    display: none; 
    flex-grow: 1; 
    padding: 20px; 
    max-width: 95%; 
    margin: 0 auto; 
    width: 100%; 
    box-sizing: border-box; 
    overflow-y: auto; 
}
.game-layout-inner {
    display: grid;
    grid-template-columns: 1fr 345px 345px; /* Nur noch 3 Spalten (Center, Rechts, Ganz Rechts) */
    gap: 20px;
    height: 100%;
    overflow: hidden;
}
.scrollable-column { overflow-y: auto; height: 100%; padding-right: 5px; }
.panel { border: 1px solid var(--ui-color); padding: 15px; background-color: #000; margin-bottom: 15px; position: relative; }
h2 { margin-top: 0; border-bottom: 1px solid var(--ui-color); padding-bottom: 5px; }

.map-container { 
    border: 1px solid var(--ui-color); 
    background-color: #000; 
    padding: 10px; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;

    /* --- NEU: Höhen-Limit auch für den äußeren Container --- */
    max-height: calc(100vh - 150px);
}
#strategyMap { 
    display: grid; 
    gap: 2px; 
    background-color: #111; 
    padding: 2px; 
    border: 1px solid var(--ui-color); 
    cursor: grab; 
    overflow: hidden; 

    /* --- DIE ABSOLUTE LÖSUNG --- */
    height: calc(100vh - 250px); /* Zwingt die Karte exakt in die verfügbare Bildschirmhöhe */
    width: calc(100vh - 250px);  /* Setzt die Breite auf exakt den gleichen Wert -> Perfektes Quadrat */
    max-width: 100%;             /* Sicherheitsgurt: Verhindert horizontales Überlappen bei kleinen Fenstern */
    margin: 0 auto;              /* Zentriert das Radar */
}
#strategyMap:active { cursor: grabbing; }

.map-tile { aspect-ratio: 1; background-color: #000; border: 1px dashed #333; display: flex; align-items: center; justify-content: center; font-size: 9px; color: var(--ui-color); user-select: none; transition: background-color 0.2s; }
.map-tile:hover { background-color: var(--ui-color); color: #000; }
.map-tile.base { background-color: #005500; font-weight: bold; }
.map-tile.explored { background-color: #002200; color: #0b0; font-size: 0.7em; }
.map-tile.camp { background-color: #440000; border: 1px solid #f55 !important; color: #f30; font-size: 0.7em; }
.map-tile.node { background-color: #aa5500; border: 1px solid #ffaa00 !important; color: #fff; font-size: 0.65em; }
.map-tile.fog { background-color: #333; border: 1px solid #444; color: transparent; }
.map-tile.fog:hover { background-color: #555; color: #ccc; }
.chunk-edge-r { border-right: 1px solid var(--ui-color) !important; }
.chunk-edge-b { border-bottom: 1px solid var(--ui-color) !important; }
.chunk-edge-l { border-left: 1px solid var(--ui-color) !important; }
.chunk-edge-u { border-top: 1px solid var(--ui-color) !important; } 

/* Report Split-Screen Styles */
.report-cat { padding: 12px 15px; cursor: pointer; border-bottom: 1px solid #222; transition: background 0.2s; position: relative; font-weight: bold; }
.report-cat:hover { background: #111; }
.report-cat.active { background: #222; color: var(--ui-color); border-left: 4px solid var(--ui-color); }
.unread-badge { background: var(--ui-danger-light); color: #fff; border-radius: 10px; padding: 2px 8px; font-size: 0.8em; position: absolute; right: 10px; top: 12px; }

.report-item { margin: 0; border-bottom: 1px solid #222; padding: 10px 15px; cursor: pointer; transition: background 0.2s; }
.report-item:hover { background-color: #111; }

.tooltip { cursor: help;}

.jump-input { width: 40px; background: #222; color: var(--ui-color); border: 1px solid var(--ui-color); text-align: center; font-family: 'Courier New', monospace; }
.jump-input::-webkit-inner-spin-button, .jump-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
table { width: 100%; border-collapse: collapse; margin-top: 10px; margin-bottom: 30px; }
th, td { border: 1px solid var(--ui-color); padding: 8px; text-align: left; }
th { background-color: #222; }

.retreat-btn { 
    background: #440000; 
    color: var(--ui-danger-light); 
    border: 1px solid var(--ui-danger-light); 
    padding: 2px 5px; 
    cursor: pointer; 
    font-size: 0.8em; 
    margin-left: 5px; 
}
.retreat-btn:hover { background: var(--ui-danger-light); color: #000; }

#centerActionContent p,
#techtreeDisplay td {
    word-break: break-word;
    hyphens: auto;
}

#warningContainer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px; 
}

.attack-warning {
    background: rgba(150, 0, 0, 0.9);
    border: 2px solid var(--ui-danger-light);
    color: #fff;
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
    box-shadow: 0 0 10px var(--ui-danger-light);
    font-family: 'Courier New', monospace;
    animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 5px var(--ui-danger-light); }
    50% { box-shadow: 0 0 15px var(--ui-danger-light); }
    100% { box-shadow: 0 0 5px var(--ui-danger-light); }
}

/* --- CYBER TOGGLE SWITCH (URLAUB) --- */
.cyber-switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 30px;
}
.cyber-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.cyber-switch .slider-switch {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #222;
    border: 1px solid #555;
    transition: .4s;
    border-radius: 4px;
}
.cyber-switch .slider-switch:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: var(--ui-color);
    transition: .4s;
    border-radius: 2px;
}
.cyber-switch input:checked + .slider-switch {
    background-color: #440000;
    border-color: var(--ui-danger);
}
.cyber-switch input:checked + .slider-switch:before {
    transform: translateX(30px);
    background-color: var(--ui-danger-light);
    box-shadow: 0 0 10px var(--ui-danger);
}

/* --- DIAMANTEN MAP-NODE --- */
.map-tile.node-diamond { 
    background-color: #002244; 
    border: 1px solid #00ffff !important; 
    color: #0ff; 
    font-size: 0.65em; 
    box-shadow: inset 0 0 10px rgba(0, 255, 255, 0.5); 
    text-shadow: 0 0 3px #0ff;
}

/* ==========================================================================
   ?? MOBILE OPTIMIERUNG (Für Bildschirme schmaler als 900px)
   ========================================================================== */
@media (max-width: 900px) {

    /* --- 1. NATIVES SCROLLEN & GRUNDLAYOUT --- */
    body {
        height: auto !important;
        overflow-y: auto !important;
    }

    /* Hauptansicht nur zwingen, wenn sie NICHT per JS versteckt wurde */
    #view-main:not([style*="display: none"]) {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        gap: 15px !important;
    }

    /* Fallback für die Spalten, ohne das Verstecken zu blockieren */
    .game-layout-inner {
        flex-direction: column !important;
        height: auto !important;
        gap: 15px !important;
    }

    /* Alle Spalten und Sektionen auf volle Breite zwingen */
    .view-section, 
    .scrollable-column,
    .column-right, 
    .column-far-right {
        height: auto !important;
        width: 100% !important;
        max-width: 100vw !important;
        margin: 0 !important;
        padding: 10px !important;
        overflow: visible !important;
        box-sizing: border-box !important;
    }

    .panel {
        width: 100% !important;
        box-sizing: border-box !important;
        overflow-wrap: break-word !important; 
    }

    /* --- 2. MOBILE OVERLAY MENÜ (Linke Spalte) --- */
    #mobileMenuBtn {
        display: block !important;
    }

    .column-left {
        position: fixed !important;
        top: 0;
        bottom: 0; /* Zieht das Menü absolut verlässlich bis GANZ nach unten */
        left: -100%; /* Versteckt außerhalb des Bildschirms */
        width: 85% !important;
        max-width: 350px !important;
        /* height: 100vh !important; <-- RAUS, bottom: 0 ist viel sicherer! */
        z-index: 3000 !important;
        background: #000 !important;
        border-right: 2px solid var(--ui-color) !important;
        transition: left 0.3s ease-in-out !important;
        padding-top: 60px !important; /* Platz für Top-Bar */
        padding-bottom: 20px !important; /* Etwas Luft unten für den letzten Eintrag */
        box-shadow: 5px 0 15px rgba(0,0,0,0.9);
        
        /* --- SCROLL-LOGIK --- */
        overflow-y: auto !important; 
        -webkit-overflow-scrolling: touch !important; /* Butterweich auf dem iPhone */
        box-sizing: border-box !important; /* WICHTIG: Verhindert, dass das Padding das Menü künstlich vergrößert/verkleinert */
    }

    .column-left.open {
        left: 0 !important;
    }

    /* Navigation Grid im Menü */
    #leftMenuButtons {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: space-between !important;
        gap: 5px !important;
    }

    #leftMenuButtons > h3 {
        width: 100% !important; 
        margin-top: 15px !important;
        margin-bottom: 5px !important;
        font-size: 1em !important;
        text-align: center !important;
    }

    #leftMenuButtons > div {
        flex: 1 1 calc(50% - 5px) !important; /* 2 Buttons nebeneinander */
        box-sizing: border-box !important;
        margin-bottom: 0 !important;
        padding: 12px 5px !important; 
        font-size: 0.85em !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
    }

    #leftMenuButtons > div:first-child {
        flex: 1 1 100% !important; /* Radar-Button bleibt volle Breite */
        font-size: 1.1em !important;
        padding: 15px !important;
        background: #220000 !important; 
    }

    /* --- 3. TAKTISCHES RADAR --- */
    .map-container {
        max-height: none !important;
        height: auto !important; 
        padding: 5px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    #strategyMap { 
    display: grid; 
    gap: 2px; 
    background-color: #111; 
    padding: 2px; 
    border: 1px solid var(--ui-color); 
    cursor: grab; 
    overflow: hidden; 

    /* --- DIE RETTUNG: Verbietet dem Browser das Scrollen auf der Karte --- */
    touch-action: none; 

    height: calc(100vh - 250px); 
    width: calc(100vh - 250px);  
    max-width: 100%;             
    margin: 0 auto;              
    }

    .map-tile {
        min-width: 0 !important;
        min-height: 0 !important;
        overflow: hidden !important;
        font-size: 8px !important;
        line-height: 1 !important;
        word-break: break-all !important;
    }

    .map-tile.base, .map-tile.camp, .map-tile.node, .map-tile.explored {
        font-size: 8px !important;
    }

    #radarDisplay p {
        white-space: normal !important;
        word-break: break-word !important;
    }

    /* --- 4. BAUEN & TRUPPEN --- */
    #centerActionContent {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
    }

    #centerActionContent > div {
        width: 100% !important;
        max-width: 350px !important;
        margin: 0 auto 15px auto !important;
        box-sizing: border-box !important;
    }

    /* --- 5. NACHRICHTEN (POSTEINGANG) --- */
    #view-reports {
        width: 100% !important;
        max-width: 500px !important;
        margin: 0 auto !important;
        padding: 10px !important;
        box-sizing: border-box !important;
    }

    #view-reports > div {
        display: flex !important;
        flex-direction: column !important; 
        width: 100% !important;
        box-sizing: border-box !important;
    }

    #reportCategories {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 5px !important;
        margin-bottom: 15px !important;
        justify-content: center !important; 
    }

    .report-cat {
        flex-grow: 1 !important;
        text-align: center !important;
        border: 1px solid #333 !important;
    }

    .report-cat.active {
        border: 1px solid var(--ui-color) !important;
        border-left: 1px solid var(--ui-color) !important;
    }

    #reportList {
        width: 100% !important;
        max-height: 30vh !important; 
        overflow-y: auto !important;
        border: 1px solid var(--ui-color) !important;
        background: #111 !important;
        margin-bottom: 15px !important;
        padding: 5px !important;
        box-sizing: border-box !important;
    }

    #reportDetail {
        width: 100% !important;
        height: auto !important;
        min-height: 250px !important;
        border: 1px solid var(--ui-color) !important;
        background: #0a0a0a !important;
        padding: 15px !important;
        box-sizing: border-box !important;
    }

    #reportDetail, #reportDetail div, #reportDetail p, #reportDetail pre {
        white-space: pre-wrap !important; 
        word-wrap: break-word !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
        max-width: 100% !important;
    }

    /* --- 6. TABELLEN-FIX & OVERLAYS --- */
    .auth-box {
        width: 90% !important;
        max-width: 350px !important;
        padding: 20px !important;
        box-sizing: border-box !important;
        margin: 0 auto !important;
    }

    .auth-input, .auth-btn {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #customConfirmOverlay > div {
        width: 90% !important;
        max-width: 380px !important;
        box-sizing: border-box !important;
    }

    .view-section table {
        display: block !important;
        width: 100% !important;
        overflow-x: auto !important; /* Erlaubt horizontales Wischen */
        -webkit-overflow-scrolling: touch; 
        white-space: nowrap !important; 
        border: 1px solid var(--ui-color) !important;
        box-sizing: border-box !important;
    }

    .view-section th, .view-section td {
        padding: 5px 10px !important;
        font-size: 0.9em !important;
    }
    
    /* --- FIX: ABGESCHNITTENE INHALTE (OVERFLOW) --- */
    /* Überschreibt die inline-Styles aus dem HTML, die das Scrollen blockieren */
    body > div[style*="flex-grow: 1"] {
        display: block !important;
        overflow: visible !important;
        height: auto !important;
    }
    
    #mainContentArea {
        display: block !important;
        overflow: visible !important;
        height: auto !important;
    }

    /* --- FIX: TOP-BAR (Level & Punkte sichtbar machen) --- */
    .top-bar-header {
        flex-wrap: wrap !important; /* Erlaubt Elemente in die nächste Zeile zu rutschen */
        justify-content: center !important;
        gap: 10px !important;
        padding: 10px 5px !important;
    }
    
    .top-bar-header > select, 
    .top-bar-header > div {
        margin: 0 !important; /* Starre Seitenabstände entfernen */
        text-align: center !important;
    }
    
    #scoreDisplay {
        font-size: 1.3em !important; /* Leicht verkleinern für's Smartphone */
        display: block !important;
    }

    #hq-container {
        width: 100% !important; /* Zwingt das HQ-Level in eine eigene, mittige Zeile */
        margin: 5px 0 !important;
    }

    /* --- FIX: SYSTEMMENÜS (Einstellungen, Highscore, Eco) --- */
    .view-section {
        max-width: 100vw !important;
        padding: 10px !important;
        margin: 0 !important;
    }
    
    .view-section .panel {
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: hidden !important; /* Verhindert, dass Ränder nach rechts rausbrechen */
        box-sizing: border-box !important;
    }
}

/* ==========================================================================
   ?? LANDSCAPE OPTIMIERUNG (Querformat auf Smartphones)
   ========================================================================== */
@media (max-height: 600px) and (orientation: landscape) {
    
    /* 1. Top-Bar radikal verdichten, da vertikaler Platz extrem wertvoll ist */
    .top-bar-header {
        padding: 2px 10px !important;
        gap: 5px !important;
    }

    .top-bar-resources {
        padding: 2px 5px !important;
        font-size: 0.85em !important;
        gap: 5px !important;
    }

    #mobileMenuBtn {
        padding: 2px 8px !important;
        margin: 0 !important;
    }

    /* 2. Menü-Overlay anpassen */
    .column-left {
        padding-top: 50px !important; /* Weniger Platz für die nun schmalere Top-Bar */
        width: 45% !important; /* Darf im Querformat breiter sein */
        max-width: 320px !important;
        overflow-y: auto !important; /* Zwingend scrollbar für kleine Höhen */
    }

    /* 3. Taktisches Radar an die Höhe koppeln (statt an die Breite) */
    .map-container {
        padding: 2px !important;
    }

    #strategyMap {
        height: 55vh !important; 
        width: 55vh !important; 
        max-width: 100% !important;
        margin: 0 auto !important;
    }

    /* 4. Abstände im Content verringern */
    .view-section {
        padding: 5px !important;
        gap: 5px !important;
    }

    .panel {
        padding: 10px !important;
        margin-bottom: 5px !important;
    }
}

/* --- RANGLISTE: Name und Level trennen --- */
.highscore-name-cell {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding-right: 15px !important; /* Etwas Luft zum rechten Rand */
}

.highscore-level {
    color: var(--ui-info); /* Macht das Level farblich passend zum Rest */
    font-size: 0.9em;
    opacity: 0.8;
}