/* style.css - Globale Stile für Herrschaft der Reiche (INTEGRIERTE VERSION) */

/* === Globale Variablen === */
:root {
    --main-bg-color: rgba(40, 30, 20, 0.9);
    --border-color-strong: #6b4c2e;
    --border-color-light: #8c582c;
    --text-color: #FFFFFF;
    --link-color: #ffc107;
    --content-bg-color: rgba(0, 0, 0, 0.7);
    --button-primary-bg: #4CAF50;
    --button-primary-hover: #45a049;
    --button-disabled-bg: #555;
    --button-disabled-text: #999;
    --button-premium-bg: #008CBA;
}

/* === Basis-Stile für Body & HTML === */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text-color);
    background-image: url('images/background.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    box-sizing: border-box; /* Stellt sicher, dass padding und border die Elementgrösse nicht erhöhen */
}

/* Spezielle Regel für die Karten-Seite, damit der Body scrollen kann */
body.map-page {
    overflow-y: auto; /* Erlaubt vertikales Scrollen auf der Kartenseite */
}
/* Standardverhalten: Scrollen verhindern, wenn nicht auf der Karte */
body:not(.map-page) {
    overflow: hidden;
}


/* === Haupt-Layout (Grid-System) === */
.game-container {
    display: grid;
    grid-template-areas:
        "top-bar"
        "resources"
        "village-switcher"
        "main-content-wrapper"; /* Neue Area für den Hauptinhalt, damit die Seitenleiste darüber ist */
    grid-template-columns: 1fr; /* Eine Spalte für mobile Ansicht */
    max-width: 1400px;
    margin: 10px auto;
    background-color: var(--main-bg-color);
    border: 3px solid var(--border-color-strong);
    box-shadow: 0 0 20px rgba(0,0,0,0.7);
    border-radius: 5px;
    min-height: calc(100vh - 20px); /* Damit der Container mindestens die Bildschirmhöhe einnimmt */
}

.top-bar { grid-area: top-bar; } /* Enthält top-nav */
.resources { grid-area: resources; }
.village-switcher { grid-area: village-switcher; }
.main-content-wrapper { 
    grid-area: main-content-wrapper;
    display: flex; /* Für die linke Sidebar und den Hauptinhalt */
    flex-grow: 1; /* Nimmt den restlichen Platz ein */
}

.left-sidebar {
    width: 200px;
    flex-shrink: 0;
    background-color: rgba(0,0,0,0.5);
    padding: 10px;
    border-right: 2px solid var(--border-color-light); /* Trennlinie */
}
.main-content {
    flex-grow: 1;
    padding: 20px;
    background-color: var(--content-bg-color);
    overflow-y: auto; /* Nur der Hauptinhalt scrollt bei Bedarf */
}


/* === Top Navigation & Ressourcen === */
.top-nav nav {
    padding: 10px;
    text-align: center;
}
.top-nav a {
    color: var(--link-color);
    text-decoration: none;
    padding: 5px 8px;
    white-space: nowrap; /* Verhindert Umbrüche in Menüpunkten */
}
.top-nav a:hover { text-decoration: underline; }
.nav-notification { font-weight: bold; color: #ff5555 !important; }

.resources {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    padding: 10px;
    background-color: rgba(0,0,0,0.4);
    border-bottom: 2px solid var(--border-color-light);
}
.resource-item { display: inline-flex; align-items: center; gap: 5px; }
.resource-icon { width: 18px; height: 18px; }
.resource-item-separator { color: #666; }

.sync-button {
    margin-left: auto; /* Schiebt den Sync-Button nach rechts */
    font-size: 1.5em;
    text-decoration: none;
    color: var(--link-color);
}
.sync-button:hover {
    color: white;
}

.village-switcher {
    padding: 10px;
    text-align: center;
    border-bottom: 2px solid var(--border-color-light);
}
.village-switcher select {
    padding: 5px;
    border-radius: 4px;
    border: 1px solid var(--border-color-light);
    background-color: rgba(0,0,0,0.5);
    color: var(--text-color);
}

/* === Dorfansicht Layout === */
.village-layout {
    display: flex;
    gap: 20px;
}
.village-column-left { flex: 1; display: flex; flex-direction: column; gap: 20px; }
.village-column-right { flex: 2; display: flex; flex-direction: column; gap: 20px; }
.village-box {
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid #555;
    border-radius: 5px;
    padding: 15px;
}
.village-box h2 {
    margin-top: 0;
    border-bottom: 1px solid #666;
    padding-bottom: 10px;
    margin-bottom: 15px;
}
.village-table { width: 100%; border-collapse: collapse; }
.village-table td { padding: 8px 5px; border-bottom: 1px solid #444; }
.village-table tr:last-child td { border-bottom: none; }
.info-table td:last-child { text-align: right; }

.queue-table td { padding: 10px 5px; }
.queue-item-indented { padding-left: 20px !important; color: #bbb; }
.cancel-link { color: #ff6666 !important; text-decoration: none; font-size: 0.9em; }
.cancel-link:hover { text-decoration: underline; }

.build-details { font-size: 0.9em; color: #ccc; margin-top: 4px; }
.build-detail-item { margin-right: 12px; display: inline-flex; align-items: center; }
.build-detail-item::before { content: ''; display: inline-block; width: 16px; height: 16px; margin-right: 4px; background-size: contain; background-repeat: no-repeat; vertical-align: middle; }
.build-detail-item.res-wood::before { background-image: url('images/wood_icon.png'); }
.build-detail-item.res-clay::before { background-image: url('images/clay_icon.png'); }
.build-detail-item.res-iron::before { background-image: url('images/iron_icon.png'); }

.afford-time { font-size: 0.9em; color: #c58210; margin-top: 4px; }
.build-table .build-action-cell { width: 150px; text-align: right; vertical-align: middle; }

/* Premium & Ausbau Buttons */
.build-link, .build-link-disabled, .build-link-free, .build-link-premium {
    display: inline-block; padding: 8px 15px; border-radius: 4px; text-decoration: none; font-weight: bold; text-align: center;
}
.build-link { background-color: var(--button-primary-bg); color: white; border: 1px solid var(--button-primary-hover); }
.build-link:hover { background-color: var(--button-primary-hover); }
.build-link-disabled { background-color: var(--button-disabled-bg); color: var(--button-disabled-text); border: 1px solid #444; cursor: not-allowed; }
.premium-actions td { padding-top: 10px; border-top: 1px solid #555; text-align: center; }
.build-link-free { background-color: var(--button-primary-bg); color: white; margin: 0 5px; padding: 6px 12px; }
.build-link-premium { background-color: var(--button-premium-bg); color: white; margin: 0 5px; padding: 6px 12px; }

/* Feedback-Nachrichten */
.feedback-message { padding: 10px; border-radius: 4px; margin-bottom: 15px; }
.feedback-message.success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.feedback-message.error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }


/* === NEUE UND INTEGRIERTE STILE FÜR DIE KARTE === */

/* Hier überlagern wir die vorherigen "main-content" Stile für die Karte */
.main-content.map-content { /* Eine spezielle Klasse für den main-content, wenn die Karte angezeigt wird */
    padding: 0; /* Kein Padding, damit die Karte bis zum Rand geht */
    overflow: hidden; /* Die Karte selbst kümmert sich um das Scrollen */
    display: flex; /* Um die Karte und die Sidebar nebeneinander zu legen */
    gap: 15px;
}

#map-viewport {
    flex-grow: 1;
    height: 80vh; /* Höhe des sichtbaren Bereichs auf Desktop */
    overflow: hidden; /* Alles ausserhalb wird abgeschnitten */
    position: relative;
    background-color: #1a251a;
    border: 2px solid #5a4b3c;
    cursor: grab;
}
#map-viewport:active {
    cursor: grabbing;
}

#map-grid {
    display: grid;
    grid-template-columns: repeat(100, 50px);
    grid-template-rows: repeat(100, 50px);
    width: 5000px; /* 100 * 50px */
    height: 5000px; /* 100 * 50px */
    position: relative; /* Wichtig für die Positionierung */
}

.tile {
    width: 50px;
    height: 50px;
    background-size: cover;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
    border: 1px solid rgba(0,0,0,0.2);
}
.tile.has-village:hover {
    outline: 2px solid yellow;
    z-index: 10;
}

/* Terrain- & Dorf-Bilder */
.tile.grass { background-image: url('images/terrain_grass.png'); }
.tile.forest { background-image: url('images/terrain_forest.png'); }
.tile.mountain { background-image: url('images/terrain_mountain.png'); }
.tile.lake { background-image: url('images/terrain_lake.png'); }
.tile.own-village { background-image: url('images/village_own_square.png'); }
.tile.barbarian-village { background-image: url('images/village_barbarian_square.png'); }
.tile.alliance-village { background-image: url('images/village_alliance_square.png'); } /* HIER BILD HOCHLADEN! */
.tile.enemy-village { background-image: url('images/village_other_square.png'); }

/* Rechte Karten-Steuerung (Minimap, Filter) */
#map-controls {
    width: 220px;
    flex-shrink: 0;
    padding: 10px;
    background-color: rgba(0,0,0,0.3);
    border-radius: 5px;
}
#map-controls h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--text-color);
}
#map-controls hr {
    border: none;
    border-top: 1px solid var(--border-color-light);
    margin: 15px 0;
}

/* Minimap */
#minimap-container {
    position: relative;
    width: 200px;
    height: 200px;
    border: 2px solid var(--border-color-strong);
    cursor: pointer;
    background-color: #3d522d; /* Basis-Minimap-Farbe */
}
#minimap-canvas {
    width: 100%;
    height: 100%;
    display: block; /* Entfernt zusätzlichen Platz um das Canvas */
}
#minimap-viewport-indicator {
    position: absolute;
    border: 1px solid white;
    box-sizing: border-box;
    pointer-events: none; /* Ignoriert Mausklicks */
    background-color: rgba(255, 255, 255, 0.2); /* Leicht transparentes Overlay */
}

/* Karten-Filter */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}
.control-group label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 14px;
}
.control-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--link-color); /* Farbe des Hakens */
}

/* === Popup-Menü für Dörfer === */
#map-popup {
    position: fixed;
    background-color: #2d231a;
    border: 2px solid var(--border-color-strong);
    border-radius: 5px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.7);
    color: var(--text-color);
    z-index: 1000;
    width: 200px;
    font-size: 14px;
    display: none; /* Standardmässig versteckt */
}
#popup-header {
    background-color: #4a382a;
    padding: 8px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
}
#popup-info {
    padding: 8px;
    line-height: 1.4;
}
#popup-actions {
    list-style: none;
    padding: 0;
    margin: 0;
    border-top: 1px solid var(--border-color-light);
}
#popup-actions li a {
    display: block;
    padding: 8px 12px;
    color: var(--link-color);
    text-decoration: none;
}
#popup-actions li a:hover {
    background-color: var(--border-color-light);
    color: white;
}

/* === Filter-Anzeigeregeln für Dörfer auf der Karte === */
#map-grid.hide-own .own-village { display: none; }
#map-grid.hide-alliance .alliance-village { display: none; }
#map-grid.hide-enemy .enemy-village { display: none; }
#map-grid.hide-barbarian .barbarian-village { display: none; }


/* === Responsive Anpassungen (Tablet & Mobile) === */
@media screen and (min-width: 901px) { /* Desktop Ansicht: 3 Spalten */
    .game-container {
        grid-template-areas:
            "top-bar top-bar top-bar"
            "resources resources resources"
            "village-switcher village-switcher village-switcher"
            "left-sidebar main-content-wrapper ."; /* Die rechte Sidebar (map-controls) ist jetzt Teil des main-content-wrapper für die Karte */
        grid-template-columns: 200px 1fr 200px; /* Linke Sidebar, Hauptinhalt, leerer Platz rechts (oder für map-controls) */
    }
    .main-content-wrapper {
        border-left: 2px solid var(--border-color-light);
    }
}

@media screen and (max-width: 900px) { /* Mobile / Tablet Ansicht: 1 Spalte */
    html, body {
        padding: 0;
    }
    .game-container {
        margin: 0;
        border: none;
        border-radius: 0;
        min-height: 100vh; /* Nimmt auf Mobile die volle Höhe ein */
    }
    .main-content-wrapper {
        flex-direction: column; /* Sidebars und Hauptinhalt untereinander */
    }
    .left-sidebar {
        width: auto; /* Nimmt volle Breite ein */
        border-right: none;
        border-bottom: 2px solid var(--border-color-light);
        order: 3; /* Positioniert die linke Sidebar unter dem Main Content auf Mobile */
    }
    .main-content {
        padding: 10px;
        border-left: none;
        border-right: none;
        overflow-y: visible; /* Oder auto, je nach spezifischem Inhalt */
        order: 2; /* Positioniert den Main Content über der Sidebar auf Mobile */
    }
    .top-nav nav, .resources, .village-switcher {
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
        padding: 5px;
        font-size: 0.9em;
    }
    .top-nav a {
        padding: 3px 6px;
        font-size: 0.85em;
    }
    .sync-button {
        margin-left: 0;
        width: 100%;
        text-align: center;
    }
    .village-switcher select {
        width: 100%;
        box-sizing: border-box;
    }

    /* Mobile spezifische Anpassungen für die Karte */
    .main-content.map-content {
        flex-direction: column; /* Karte und Steuerung untereinander */
        gap: 10px;
        padding: 10px;
    }
    #map-viewport {
        height: 60vh; /* Weniger Höhe, um Platz für die Steuerung zu lassen */
    }
    #map-controls {
        width: auto; /* Nimmt die volle Breite ein */
        padding: 10px;
        order: 2; /* Unter der Karte */
    }
}
