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

html {
    background-color: #000;
    color-scheme: dark;
}

body {
    background-color: #000000; /* Tiefschwarz */
    color: #f0f0f0;
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    overflow: auto;
}

.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    background-color: #000000; /* Tiefschwarz */
    position: relative;
    overflow: auto;
}

h1 {
    margin-bottom: 20px;
    color: #ffd700;
}

.subtitle {
    font-size: 1.125rem;
    font-weight: 600;
    color: #ffd700;
    margin-top: -18px;
    margin-bottom: 20px;
    font-style: normal;
    margin-left: 50px;
    text-decoration: none;
    cursor: pointer;
}

.controls {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    gap: 10px;
}

button {
    padding: 10px 15px;
    background-color: #4a6ea9;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
}

button:hover {
    background-color: #3a5a89;
}

/* Einheitenleiste */
.units-panel {
    margin-bottom: 0;
    background: none;
    border: none;
    border-radius: 5px;
    padding: 10px;
}

.units-panel h3 {
    color: #ffd700;
    margin-bottom: 0;
}

.units-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    overflow: visible;
}

.panels-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin-bottom: 0;
    align-items: stretch;
    justify-content: space-between;
    overflow: auto;
}

.units-panel, .resource-panel, .terrain-controls {
    display: flex;
    flex-direction: column;
    min-height: 280px;
}

.units-panel {
    min-width: 280px;
    max-width: 280px;
    flex: 0 0 auto;
}

.units-panel .units-selector {
    grid-template-columns: repeat(3, 1fr);
    justify-content: center;
    overflow: visible;
}

.resource-panel {
    min-width: 380px;
    max-width: 450px;
    flex: 0 0 auto;
    background: none;
    border: none;
}

.resource-panel .units-selector {
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
    justify-content: space-between;
    align-items: flex-start;
    background: none;
    border: none;
}

.terrain-controls {
    min-width: 400px;
    max-width: 400px;
    flex: 0 0 auto;
}

.units-selector, .resource-selector, .terrain-items {
    display: grid;
    gap: 10px;
    flex: 1;
    align-content: start;
    overflow: auto;
    padding-bottom: 5px;
}

/* Ressourcen in einer Reihe */
.resource-panel .units-selector {
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
    justify-content: space-between;
    align-items: flex-start;
}

/* Terrain-Controls */
.terrain-items.units-selector {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 15px;
}

.input-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.percent-sign {
    font-size: 12px;
    color: #ddd;
}

.terrain-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 3px;
    background-color: rgba(255, 255, 255, 0.1);
    padding: 8px 5px;
    border-radius: 5px;
    min-width: 110px;
    height: auto;
    min-height: 105px;
}

.terrain-control .terrain-icon {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    margin-bottom: 3px;
    background-size: cover;
}

.terrain-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.terrain-info span {
    font-size: 12px;
    margin-bottom: 2px;
}

.terrain-info input {
    width: 40px;
    text-align: center;
    background-color: #444;
    border: 1px solid #555;
    color: white;
    border-radius: 3px;
    padding: 2px;
    font-size: 12px;
}

.unit-item, .resource-item {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 5px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.unit-item {
    width: 80px;
}

.resource-item {
    width: 50px;
    height: auto;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: none;
    border: none;
    border-radius: 5px;
    padding: 5px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: none;
}

.resource-item:hover {
    background: none;
    box-shadow: none;
}

.resource-item.selected {
    background: none;
    box-shadow: none;
}

.resource-item img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    margin-bottom: 5px;
    filter: none;
}

.resource-item span {
    font-size: 12px;
    text-align: center;
}

.resource-item .max-count {
    display: none;
}

.resource-item .counter-container {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 5px;
}

.resource-item .counter {
    font-size: 32px;
    font-weight: bold;
    color: #ffd700;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 215, 0, 0.3);
}

.resource-config {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
    background-color: rgba(255, 255, 255, 0.1);
    padding: 8px;
    border-radius: 5px;
}

.resource-config label {
    font-size: 14px;
}

.resource-config input[type="range"] {
    width: 150px;
}

.resource-config span {
    min-width: 45px;
    text-align: right;
}

.resource-controls {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 5px;
    font-size: 12px;
}

.resource-max {
    width: 45px;
    padding: 2px;
    text-align: center;
    background-color: #444;
    border: 1px solid #555;
    color: white;
    border-radius: 3px;
}

.unit-item:hover {
    background-color: #444;
}

.unit-item.selected {
    background-color: #4a6ea9;
}

.unit-item img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    margin-bottom: 5px;
}

.unit-item span {
    font-size: 12px;
}

/* Karte */
.map-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    cursor: grab;
    background-color: var(--ui-bg-deep, #000000);
}

.map-container:active {
    cursor: grabbing;
}

#map {
    position: relative;
    transform-origin: 0 0;
    transition: transform 0.05s ease-out;
    /* Grid-Layout entfernt für hexagonale Anordnung */
    width: 300px;
    height: 300px;
    margin-left: 16px; /* Hälfte der Breite eines Hexagons */
    background-color: var(--ui-bg-deep, #000000);
}

.tile {
    width: 32px;
    height: 28px; /* Reduzierte Höhe für Überlappung */
    position: absolute;
    background-size: cover;
    background-position: center;
    /* Hexagon-Form */
    -webkit-clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

/* Hexagon-spezifische Positionen werden im JavaScript gesetzt */

.grassland {
    background-image: url('terrain/grassland.png?v=2');
}

.forest {
    background-image: url('terrain/forest.png?v=2');
}

.hills {
    background-image: url('terrain/hills.png?v=2');
}

.mountains {
    background-image: url('terrain/mountains.png?v=2');
}

.desert {
    background-image: url('terrain/desert.png?v=2');
}

.sea {
    background-image: url('terrain/sea.png?v=2');
}

/* Einheiten auf der Karte */
.unit {
    position: absolute;
    width: 32px;
    height: 32px;
    transform-origin: center;
    z-index: 100;
    cursor: pointer;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    filter: none;
    transition: transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform;
    margin-top: -4px;
}

/* Gekaufte Einheiten (fire, green, pink) haben einen höheren z-index */
.unit.fire, .unit.green, .unit.pink {
    z-index: 200; /* Höherer z-index als normale Einheiten */
}

.unit.warrior {
    background-image: url('units/warrior.png?v=3');
    height: 46px; /* 15% höher als die Standardhöhe von 40px */
    margin-top: -12px; /* Verschiebt die Einheit zusätzlich nach oben auf dem Bildschirm */
}

.unit.archer {
    background-image: url('units/archer.png?v=3');
}

.unit.horseman {
    background-image: url('units/horseman.png?v=4');
}

.unit.catapult {
    background-image: url('units/catapult.gif?v=3');
}

.unit.settler {
    background-image: url('units/settler.gif?v=3');
}

.unit.selected {
    filter: drop-shadow(0 0 5px #ffcc00);
    z-index: 11;
}

/* Einheiten nur im aktuellen Sichtfeld sichtbar (besuchte Nebel-Felder: komplett ausblenden) */
.unit.fog-of-war,
.unit.fog-of-war-visited {
    opacity: 0 !important;
    pointer-events: none;
}

/* Animation für unzulässige Züge */
.tile.invalid-move {
    box-shadow: none;
    z-index: 15;
}

@keyframes blink {
    from {
        box-shadow: 0 0 0 2px orange;
    }
    to {
        box-shadow: 0 0 0 4px orange;
    }
}

.zoom-controls {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 5px;
    border-radius: 5px;
    display: flex;
    gap: 5px;
    z-index: 10;
}

.zoom-indicator {
    color: white;
    padding: 0 5px;
    display: flex;
    align-items: center;
}

/* Ressourcen-Stile */
.resource {
    position: absolute;
    z-index: 20;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    pointer-events: none; /* Erlaubt Klicks durch die Ressource hindurch */
    transition: none;
    filter: none;
    box-shadow: none;
    border: none;
    outline: none;
}

@keyframes surprise-hunt-pulse {
    0%, 100% { box-shadow: 0 0 0 2px rgba(220, 40, 40, 0.95), 0 0 14px rgba(255, 60, 60, 0.55); }
    50% { box-shadow: 0 0 0 4px rgba(255, 80, 80, 1), 0 0 22px rgba(255, 100, 100, 0.75); }
}

.resource.resource--surrounded {
    border-radius: 8px;
    animation: surprise-hunt-pulse 1.1s ease-in-out infinite;
    z-index: 25;
}

.tile:hover .resource {
    transform: none; /* Entfernt die Vergrößerung beim Hover */
}

/* Entferne den Schatten */
.resource::after {
    display: none;
}

/* Fog of War Effekt */
.fog-of-war {
    opacity: 0.1;
    filter: grayscale(100%) brightness(30%);
    pointer-events: none;
    transition: opacity 0.3s ease, filter 0.3s ease;
}

/* Ressourcen in Fog of War Bereichen ausblenden */
.fog-of-war .resource {
    opacity: 0;
}

/* Bereits besuchte, aber momentan nicht sichtbare Felder */
.fog-of-war-visited {
    opacity: 0.4;
    filter: grayscale(70%) brightness(50%);
    pointer-events: none;
    transition: opacity 0.3s ease, filter 0.3s ease;
}

/* Ressourcen in besuchten, aber nicht sichtbaren Bereichen teilweise sichtbar machen */
.fog-of-war-visited .resource {
    opacity: 0.3;
}

/* Ressourcen verstecken, wenn sie nicht sichtbar sein sollen */
.hidden-resource {
    opacity: 0;
    pointer-events: none;
}

/* Responsive Styles */

.city {
    position: absolute;
    width: 32px;
    height: 32px;
    z-index: 50;
    background-image: url('ui/city.png');
    background-size: 130%; /* 30% größer */
    background-repeat: no-repeat;
    background-position: center;
    transform: translate(-50%, -50%);
    margin-left: 16px;
    margin-top: 12px; /* 2px nach unten verschoben */
    filter: none;
    transition: opacity 0.3s ease;
}

.city-name {
    display: none;
}

/* Städte in Fog of War Bereichen ausblenden */
.fog-of-war.city {
    opacity: 0;
    pointer-events: none;
}

/* Besuchtes Gebiet außerhalb Sicht: wie Geländekachel abgedunkelt */
.fog-of-war-visited.city {
    opacity: 0.4;
    filter: grayscale(70%) brightness(50%);
    pointer-events: none;
}

/* Namen von besuchten, aber nicht direkt sichtbaren Städten */
.fog-of-war-visited .city-name {
    opacity: 0.7;
    background-color: rgba(0, 0, 0, 0.5);
}

/* Mobile-Optimierungen */
@media screen and (max-width: 768px) {
    .container {
        flex-direction: column;
        height: 100%;
        min-height: 100%;
        overflow: hidden;
    }
    
    .panels-container {
        flex-direction: column;
        gap: 10px;
        overflow: visible;
    }
    
    .units-panel, .resource-panel, .terrain-controls {
        min-width: 100%;
        max-width: 100%;
        min-height: auto;
        max-height: none;
    }
    
    .units-panel .units-selector {
        grid-template-columns: repeat(5, 1fr);
    }
    
    .terrain-items.units-selector {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .resource-panel .units-selector {
        flex-wrap: wrap;
        justify-content: space-around;
    }
    
    .resource-item {
        min-width: 45%;
        margin-bottom: 10px;
    }
    
    /* Größere Touch-Ziele */
    .unit-item, .resource-item, .terrain-control {
        padding: 8px;
    }
    
    input[type="number"] {
        height: 30px;
        min-height: 40px;
        min-width: 40px;
        font-size: 16px; /* Verhindert Zoom auf iOS */
    }
    
    button {
        padding: 12px 20px;
        font-size: 16px;
        margin: 5px;
        min-height: 44px;
    }
    
    /* Zoom-Indikator und Zoom-Buttons in mobilen Ansicht ausblenden */
    .zoom-indicator, .zoom-controls {
        display: none;
    }
}

/* Seitlicher Abstand für Handys im Hochformat */
@media screen and (max-width: 480px) {
    body {
        padding: 0;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .container {
        padding: 5px;
        overflow: visible;
    }
    
    .map-container {
        height: 50vh; /* Kleinere Höhe für sehr kleine Bildschirme */
        margin-bottom: 20px;
        border: 1px solid #444;
    }
    
    button {
        padding: 12px;
        font-size: 16px;
    }
    
    h1 {
        font-size: 20px;
        margin: 10px 0;
    }
    
    .panels-container {
        gap: 5px;
        margin-bottom: 5px;
    }
    
    .units-panel .units-selector {
        grid-template-columns: repeat(3, 1fr); /* 3 Spalten für sehr kleine Bildschirme */
    }
    
    /* Optimiere Terrain-Panel für kleine Bildschirme */
    .terrain-items.units-selector {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Stadt-Namen lesbarer machen */
    .city-name {
        font-size: 8px;
    }
}

/* Touch-Feedback */
.tile:active, .unit:active {
    filter: none;
}

/* Hervorhebung bei Touch-Ereignissen */
.touch-active {
    background-color: transparent !important;
    transform: none;
    transition: none;
}

/* Verhindern von Browser-Zoom und Gesten auf der Karte */
.map-container {
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
}

/* Stile für Explosionsanimation und Eliminierungszähler */
.explosion {
    position: absolute;
    width: 64px; /* 2 Hexfelder breit (32px * 2) */
    height: 64px; /* 2 Hexfelder hoch (32px * 2) */
    background: radial-gradient(circle, 
        rgba(255,0,0,0.9) 0%, 
        rgba(255,165,0,0.8) 20%, 
        rgba(255,255,0,0.6) 40%, 
        rgba(255,255,255,0.4) 60%, 
        rgba(255,255,255,0) 80%);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: enhancedExplode 1.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
    z-index: 1000;
    box-shadow: 
        0 0 20px rgba(255,0,0,0.8),
        0 0 40px rgba(255,165,0,0.6),
        0 0 60px rgba(255,255,0,0.4);
}

.explosion::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, 
        rgba(255,255,255,0.8) 0%, 
        rgba(255,255,255,0) 70%);
    transform: translate(-50%, -50%);
    animation: shockwave 1.5s ease-out forwards;
}

.explosion::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, 
        rgba(255,0,0,0.6) 0%, 
        rgba(255,0,0,0) 70%);
    transform: translate(-50%, -50%);
    animation: fireRing 1.5s ease-out forwards;
}

.explosion-text {
    position: absolute;
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    text-shadow: 
        0 0 10px rgba(255,0,0,0.8),
        0 0 20px rgba(255,165,0,0.6),
        0 0 30px rgba(255,255,0,0.4);
    white-space: nowrap;
    animation: enhancedTextFade 2s ease-in-out forwards;
    z-index: 1001;
    pointer-events: none;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 100%;
}

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

@keyframes shockwave {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0.8;
    }
    100% {
        transform: translate(-50%, -50%) scale(2);
        opacity: 0;
    }
}

@keyframes fireRing {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0.6;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 0.4;
    }
    100% {
        transform: translate(-50%, -50%) scale(2);
        opacity: 0;
    }
}

@keyframes enhancedTextFade {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2);
    }
    40% {
        transform: translate(-50%, -50%) scale(1);
    }
    80% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -150%) scale(1);
    }
}

/* Stil für den Eliminierungszähler */
.counter-panel {
    display: flex;
    align-items: center;
    background-color: #333;
    color: white;
    padding: 8px 15px;
    border-radius: 5px;
    margin: 10px 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.counter-icon {
    font-size: 24px;
    margin-right: 10px;
}

.counter-value {
    font-size: 18px;
    font-weight: bold;
    color: #ff5252;
    margin-right: 8px;
}

.counter-label {
    font-size: 14px;
}

/* Position des Zähler-Panels anpassen */
#elimination-counter-container {
    position: relative;
    margin-top: 10px;
    width: fit-content;
}

/* Stil für den Einheiten-Zähler */
.unit-counter {
    font-size: 14px;
    color: #ffd700;
    margin-top: 5px;
    font-weight: bold;
}

/* Stil für die zentrale Explosion im Sichtfeld */
.central-explosion {
    position: absolute;
    z-index: 1000;
    pointer-events: none; /* Durchklickbar */
    animation: pulse 1s ease-in-out;
}

.central-explosion img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

@keyframes pulse {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(0.9); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

/* Mobile-Hilfetexte */
.mobile-help {
    display: none; /* Standardmäßig ausgeblendet */
    position: absolute;
    bottom: 70px;
    left: 20px;
    right: 20px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px;
    border-radius: 5px;
    font-size: 14px;
    z-index: 1000;
    text-align: left;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.mobile-help p {
    margin: 5px 0;
}

/* Stelle sicher, dass Einheiten über dem Terrain erscheinen */
.unit {
    z-index: 100; /* Höherer z-index als Terrain */
}

.city {
    z-index: 50; /* Höherer z-index als Terrain */
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 5000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
}

.modal-content {
    background-color: #1a1a1a;
    margin: 15% auto;
    padding: 20px;
    border: 1px solid #444;
    border-radius: 5px;
    width: 80%;
    max-width: 500px;
    position: relative;
    color: #f0f0f0;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #fff;
}

.modal pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    margin-top: 20px;
    font-family: Arial, sans-serif;
    line-height: 1.5;
}

.unit-item[data-unit="horseman"] img {
    background-image: url('units/horseman.png?v=4');
}

.unit-item[data-unit="warrior"] img {
    height: 46px; /* 15% höher als die Standardhöhe von 40px */
}

.unit-item[data-unit="settler"] img {
    height: 20px; /* 50% kleiner als die Standardhöhe */
}

.unit-item[data-unit="catapult"] img {
    height: 20px; /* 50% kleiner als die Standardhöhe */
}

/* Animation für das Meer, wenn eine Einheit hineinfällt */
@keyframes seaSwallow {
    0% { filter: brightness(100%); }
    50% { filter: brightness(0%); }
    100% { filter: brightness(100%); }
}

@keyframes unitDrown {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    50% {
        transform: translateY(10px) scale(0.8);
        opacity: 0.5;
    }
    100% {
        transform: translateY(20px) scale(0.5);
        opacity: 0;
    }
}

.sea-swallowing {
    animation: seaSwallow 1s ease-in-out;
}

.unit-drowning {
    animation: unitDrown 1s ease-in-out forwards;
    pointer-events: none;
}

/* Mudd-Felder */
.mudd-field {
    position: absolute;
    width: 28px;
    height: 28px;
    z-index: 40;
    background-image: url('ui/Mudd.gif');
    background-size: cover;
    background-position: center;
    -webkit-clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    transform: translate(-50%, -50%);
    margin-left: 16px;
    margin-top: 14px;
    display: block;
    opacity: 1;
    cursor: pointer; /* Ändere den Cursor zu einem Pointer */
}

/* Mudd-Felder im Sichtfeld der aktiven Einheit */
.tile.visible .mudd-field {
    display: block; /* Sichtbar im Sichtfeld */
    opacity: 1; /* 10% Transparenz beibehalten */
}

/* Mudd-Felder: Klasse liegt auf dem Overlay selbst (nicht als Kind der Kachel) */
.mudd-field.fog-of-war {
    opacity: 0;
    filter: grayscale(100%) brightness(30%);
    pointer-events: none;
}

/* Besuchtes Gebiet außerhalb Sicht: wie Geländekachel abgedunkelt */
.mudd-field.fog-of-war-visited {
    opacity: 0.4;
    filter: grayscale(70%) brightness(50%);
    pointer-events: none;
}

/* Castle-Felder */
.castle-field {
    position: absolute;
    width: 45px; /* 50% kleiner als ursprünglich (32px) */
    height: 45px; /* 50% kleiner als ursprünglich (28px) */
    z-index: 35; /* Zwischen Terrain (10) und Einheiten/Ressourcen (20/100) */
    background-image: url('ui/castle.png');
    background-size: cover;
    background-position: center;
    /* Hexagon-Form */
    -webkit-clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    transform: translate(-50%, -50%);
    margin-left: 16px;
    margin-top: 16px;
    pointer-events: none; /* Erlaubt Klicks durch das Mudd-Feld hindurch */
    display: block; /* Standardmäßig sichtbar */
    opacity: 1; /* 10% Transparenz */
}

.castle-field.fog-of-war {
    opacity: 0;
    pointer-events: none;
    filter: grayscale(100%) brightness(30%);
}

/* Besuchtes Gebiet außerhalb Sicht: wie Geländekachel abgedunkelt */
.castle-field.fog-of-war-visited {
    opacity: 0.4;
    filter: grayscale(70%) brightness(50%);
    pointer-events: none;
}

/* Spezielle Stile für Settler und Catapult im Marktfenster */
.buy-unit-item[data-unit="settler"] img,
.buy-unit-item[data-unit="catapult"] img {
    width: 50%;
    height: 50%;
    margin: auto;
    display: block;
}

/* Spezielle Stile für Settler und Catapult auf dem Spielfeld */
.tile .unit[data-unit="settler"],
.tile .unit[data-unit="catapult"] {
    width: 50%;
    height: 50%;
    left: 25%;
    top: 25%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.tile .unit[data-unit="settler"] img,
.tile .unit[data-unit="catapult"] img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Zusätzliche Transformation nur für Catapult */
.tile .unit[data-unit="catapult"] {
    transform: scale(0.5);
}

/* Zusätzliche Transformation für Settler */
.tile .unit[data-unit="settler"] {
    transform: scale(0.5);
}
/* ======================================================
   Aus index.html migrierte Styles
   ====================================================== */

/* Panels */
.units-panel, .resource-panel {
    padding: 5px;
    margin: 0;
    background-color: rgba(102, 13, 13, 0.7);
    border-radius: 3px;
}
.units-panel h3, .resource-panel h3 {
    margin: 0 0 5px 0;
    font-size: 14px;
    color: #ffd700;
}
.unit-counter, .counter-container {
    font-size: 20px;
    margin-left: 3px;
}
.panels-container {
    position: absolute;
    top: 40px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 0;
    z-index: 100;
    max-width: 200px;
}

/* Controls */
.controls {
    position: absolute;
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2600;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 20px;
    background-color: rgb(0, 0, 0);
    padding: 5px 15px;
    border-radius: 5px;
}
.button-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Units selector */
.units-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    background: none;
    padding: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    padding-left: 15px;
    flex-wrap: nowrap;
}
.unit-item {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 15px;
    background-color: rgb(0, 0, 0);
    border-radius: 3px;
    font-size: 16px;
    min-width: auto;
    white-space: nowrap;
    flex-shrink: 0;
}
.unit-item img { width: 48px; height: 48px; margin: 0; }
.counter { font-size: 16px; color: #ffd700; margin-left: 8px; font-weight: bold; }
.max-count { font-size: 12px; color: rgba(255, 215, 0, 0.7); }
.counter-container { display: flex; align-items: center; gap: 2px; }

/* Map container */
.map-container {
    position: relative;
    margin: 0;
    padding: 0;
    width: 100%;
    height: calc(100vh - 40px);
    overflow: hidden;
}

/* Header */
.header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 15px;
    margin: 0;
    background-color: rgba(0, 0, 0, 0.7);
    height: 40px;
}
.header-left { display: flex; align-items: center; gap: 15px; }
.header-center { flex: 1; text-align: center; }
.header-right { display: flex; gap: 5px; }

/* Buttons */
#generate-map {
    background-color: #ffd700;
    color: #333;
    border: none;
    padding: 5px 15px;
    border-radius: 3px;
    font-weight: bold;
    cursor: pointer;
    white-space: nowrap;
}
#generate-map:hover { background-color: #ffcc00; }
.readme-button {
    background-color: #ffd700;
    color: #333;
    padding: 4px 12px;
    font-size: 12px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    white-space: nowrap;
    font-weight: bold;
    transition: background-color 0.2s;
}
.readme-button:hover { background-color: #ffcc00; }

/* Subtitle & Heading */
.subtitle { font-size: 1.125rem; font-weight: 600; color: #ffd700; margin: 0; text-decoration: none; cursor: pointer; }
h1 { font-size: 20px; margin: 0; color: #ffd700; }

/* Resource panel scrollbar */
.resource-panel { max-height: 200px; overflow-y: auto; }
.resource-panel::-webkit-scrollbar { width: 6px; }
.resource-panel::-webkit-scrollbar-track { background: rgba(255,255,255,0.1); }
.resource-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 3px; }
.resource-panel::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.4); }

/* Terrain controls */
.terrain-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 10px 0;
    padding: 10px;
    background-color: #333;
    border-radius: 5px;
    color: white;
}
.terrain-controls h3 { margin: 0 0 10px 0; }
.terrain-items { display: flex; flex-wrap: wrap; gap: 10px; }
.terrain-control {
    display: flex;
    align-items: center;
    gap: 5px;
    background-color: rgba(255,255,255,0.1);
    padding: 5px;
    border-radius: 5px;
    min-width: 110px;
}
.terrain-control label { margin-right: 3px; min-width: 60px; font-size: 14px; }
.terrain-control input { width: 35px; text-align: center; background-color: #444; border: 1px solid #555; color: white; border-radius: 3px; padding: 2px; }
.terrain-control .terrain-icon { width: 32px; height: 32px; border-radius: 4px; margin-right: 5px; background-size: cover; }
.terrain-icon.sea { background-color: #005a87; }
.terrain-icon.mountains { background-color: #6d6552; }
.terrain-icon.desert { background-color: #e3d37e; }
.terrain-icon.hills { background-color: #7d8462; }
.terrain-icon.forest { background-color: #4a592d; }
.terrain-icon.grassland { background-color: #7db35b; }
.total-percent {
    font-weight: bold;
    margin-left: 10px;
    display: flex;
    align-items: center;
    background-color: rgba(255,255,255,0.1);
    padding: 5px 10px;
    border-radius: 5px;
}

/* Sound toggle */
.sound-toggle {
    display: flex;
    align-items: center;
    margin-left: 20px;
    background-color: #444;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.sound-toggle:hover { background-color: #555; }
.sound-toggle img { width: 24px; height: 24px; margin-right: 5px; }

/* Game rules */
.game-rules {
    background-color: rgba(0,0,0,0.7);
    color: #fff;
    padding: 12px;
    border-radius: 5px;
    margin: 10px 0;
    font-size: 14px;
    border-left: 4px solid #ff5252;
}
.game-rules h3 { margin-top: 0; margin-bottom: 8px; color: #ff5252; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 5000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.7);
    overflow: auto;
}
.modal-content {
    background-color: #333;
    color: #f0f0f0;
    margin: 5% auto;
    padding: 20px;
    border: 1px solid #666;
    border-radius: 8px;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}
.modal-close {
    position: absolute;
    top: 10px; right: 15px;
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}
.modal-close:hover { color: #fff; }
.readme-content { font-family: Arial, sans-serif; line-height: 1.6; }
.readme-content h1, .readme-content h2 { color: #ffd700; margin-top: 20px; margin-bottom: 10px; }
.readme-content h1 { font-size: 24px; border-bottom: 1px solid #555; padding-bottom: 10px; }
.readme-content h2 { font-size: 20px; }
.readme-content h3 { color: #ddd; font-size: 18px; margin-top: 15px; margin-bottom: 5px; }
.readme-content p, .readme-content ul, .readme-content ol { margin-bottom: 15px; }
.readme-content ul, .readme-content ol { padding-left: 20px; }
.readme-content code { background-color: #444; padding: 2px 4px; border-radius: 3px; font-family: monospace; }
.readme-content pre { background-color: #444; padding: 10px; border-radius: 5px; overflow-x: auto; margin-bottom: 15px; }
.readme-content a { color: #8ecfff; text-decoration: underline; text-underline-offset: 2px; }
.readme-content a:hover { color: #fff; }
.readme-content .readme-donate-wrap {
    text-align: center;
    margin-top: 10px;
    margin-bottom: 0;
}

/* README-Modal: Breite an Inhalt (nicht volle 800px) */
#readme-modal .modal-content {
    width: fit-content;
    max-width: min(34rem, 94vw);
    margin: 7vh auto;
    box-sizing: border-box;
}
#readme-modal .readme-content {
    max-width: 30rem;
}
#readme-modal .readme-content h1 {
    margin-top: 0;
}
@media screen and (max-width: 768px) {
    .modal-content { margin: 10% auto; width: 90%; padding: 15px; }
    #readme-modal .modal-content {
        width: 92%;
        max-width: 92%;
    }
    #readme-modal .readme-content {
        max-width: none;
    }
}

/* Resource controls */
.resource-controls { display: flex; align-items: center; gap: 2px; margin-left: 3px; }
.resource-controls input { width: 40px; padding: 1px; font-size: 12px; }
.resource-selector {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 5px !important;
    margin: 0 !important;
    background: none !important;
    padding: 0 !important;
    border-left: 1px solid rgba(255,255,255,0.2) !important;
    padding-left: 15px !important;
    flex-wrap: nowrap !important;
}
.resource-item {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 2px !important;
    padding: 2px 5px !important;
    background-color: rgba(255,255,255,0.1) !important;
    border-radius: 3px !important;
    font-size: 11px !important;
    min-width: auto !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
}
.resource-item img { width: 10px !important; height: 10px !important; margin: 0 !important; }
.resource-item .counter-container { display: flex !important; flex-direction: row !important; align-items: center !important; gap: 1px !important; font-size: 11px !important; color: #ffd700 !important; margin-left: 2px !important; }
.resource-item .counter { font-size: 11px !important; }
.resource-item .max-count { font-size: 11px !important; color: rgba(255,215,0,0.7) !important; }

/* Score display */
.score-display {
    background-color: rgba(0,0,0,0.7);
    color: #ffd700;
    padding: 5px 10px;
    border-radius: 5px;
    margin-right: 10px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 5px;
}
#total-score { font-size: 18px; }

/* BUY button */
#buy-button {
    background-color: #ff0000;
    color: #fff;
    border: none;
    padding: 5px 15px;
    border-radius: 3px;
    font-weight: bold;
    cursor: pointer;
    white-space: nowrap;
}
#buy-button:hover { background-color: #cc0000; }

/* Buy Modal */
.buy-modal {
    display: none;
    position: fixed;
    z-index: 5000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.7);
    pointer-events: auto;
}
.buy-modal-content {
    background-color: #2c3e50;
    margin: 15% auto;
    padding: 20px;
    border-radius: 10px;
    width: 80%;
    max-width: 500px;
    position: relative;
    pointer-events: auto;
}
.buy-modal-close {
    position: absolute;
    right: 10px; top: 10px;
    z-index: 20;
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}
.buy-modal-close:hover { color: #fff; }
.buy-units-container { display: flex; flex-direction: column; gap: 15px; margin-top: 20px; }
.buy-unit-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
    background-color: rgba(255,255,255,0.1);
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}
.buy-unit-item img { width: 48px; height: 48px; object-fit: contain; }
.buy-unit-info { display: flex; align-items: center; gap: 10px; }
.buy-unit-price { color: #ffd700; font-weight: bold; font-size: 1.2em; }
.buy-unit-item.selected { background-color: rgba(255,215,0,0.3); border: 2px solid #ffd700; }
.pay-button {
    display: none;
    background-color: #27ae60;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    margin-top: 20px;
    width: 100%;
    transition: background-color 0.3s;
}
.pay-button:hover { background-color: #219a52; }
.pay-button:disabled { background-color: #666; cursor: not-allowed; }
.insufficient-funds { color: #ff5252; text-align: center; margin-top: 10px; display: none; }
.buy-instructions { color: #ffd700; margin-top: 20px; text-align: center; font-style: italic; }

/* EARN button */
#earn-button {
    background-color: #0066cc;
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    margin-top: 20px;
    width: 100%;
    transition: background-color 0.3s;
}
#earn-button:hover { background-color: #0052a3; }

/* Ad Modal (Rewarded — dunkel, großes Video) */
.ad-modal {
    display: none;
    position: fixed;
    z-index: 5001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    box-sizing: border-box;
    padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.ad-content {
    position: relative;
    width: min(720px, 100%);
    max-width: 100%;
    margin: 0 auto;
    padding: clamp(18px, 3.5vw, 28px) clamp(16px, 3vw, 28px) clamp(20px, 3vw, 28px);
    border-radius: 16px;
    text-align: center;
    background: linear-gradient(165deg, rgba(28, 26, 24, 0.98) 0%, #0c0c0c 50%, #000000 100%);
    border: 1px solid rgba(232, 197, 71, 0.28);
    box-shadow:
        0 28px 90px rgba(0, 0, 0, 0.85),
        0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    font-family: var(--ui-font, "Segoe UI", system-ui, sans-serif);
}
.ad-close {
    position: absolute;
    right: 12px;
    top: 10px;
    color: rgba(255, 255, 255, 0.35);
    font-size: 26px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    display: none;
}
.ad-close:hover { color: rgba(255, 255, 255, 0.75); }
.ad-eyebrow {
    margin: 0 0 6px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: rgba(232, 197, 71, 0.75);
}
.ad-message {
    font-size: clamp(1rem, 2.8vw, 1.2rem);
    font-weight: 700;
    line-height: 1.35;
    margin: 0 0 14px;
    color: var(--ui-text, #e8eaef);
}
.ad-timer-row {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    color: rgba(232, 234, 239, 0.72);
    font-size: 0.9rem;
}
.ad-timer-label { font-weight: 500; }
.ad-timer {
    font-size: clamp(1.75rem, 5vw, 2.25rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--ui-accent, #e8c547);
    line-height: 1;
    text-shadow: 0 0 24px rgba(232, 197, 71, 0.35);
}
.ad-timer-suffix {
    font-weight: 600;
    color: rgba(232, 234, 239, 0.55);
    font-size: 1rem;
}
.ad-media {
    width: 100%;
    margin: 0 auto 16px;
    border-radius: 12px;
    overflow: hidden;
    background: #000000;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-sizing: border-box;
    aspect-ratio: 16 / 9;
    max-height: min(58vh, 620px);
    display: flex;
    align-items: center;
    justify-content: center;
}
.ad-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.ad-link {
    display: inline-block;
    margin-top: 4px;
    padding: 8px 14px;
    border-radius: 999px;
    color: var(--ui-accent, #e8c547);
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    text-decoration: none;
    border: 1px solid rgba(232, 197, 71, 0.35);
    background: rgba(232, 197, 71, 0.08);
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.ad-link:hover {
    text-decoration: none;
    color: #f5e6a8;
    border-color: rgba(232, 197, 71, 0.55);
    background: rgba(232, 197, 71, 0.14);
}

/* Mobile */
@media (max-width: 768px) {
    html {
        height: -webkit-fill-available;
        overscroll-behavior: none;
    }
    body {
        position: fixed;
        width: 100%;
        height: 100dvh;
        min-height: 100dvh;
        max-height: 100dvh;
        overflow: hidden;
        overscroll-behavior: none;
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
    }
    .container {
        min-height: 0;
    }
    /* Header: alles sichtbar — eine Zeile wird zu schmal, daher umbrechen + Mitte darf schrumpfen */
    .header-container {
        flex-wrap: wrap;
        row-gap: 6px;
        column-gap: 6px;
        padding-left: max(8px, env(safe-area-inset-left, 0px));
        padding-right: max(8px, env(safe-area-inset-right, 0px));
        padding-top: 6px;
        align-items: center;
        justify-content: space-between;
        background: #000000 !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: none;
    }
    .header-left {
        flex: 0 1 auto;
        min-width: 0;
    }
    .header-container h1 {
        font-size: 0.85rem;
        line-height: 1.2;
        white-space: nowrap;
    }
    .header-center {
        flex: 1 1 100px;
        min-width: 0;
        overflow: hidden;
        text-align: center;
    }
    .header-center .subtitle {
        font-size: 0.7rem;
        display: block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .top-ui-dock__bar-right {
        gap: 5px;
    }

    .top-ui-dock__player-mount.top-ui-dock__player-mount--has-name {
        max-width: min(46vw, 9.5rem);
    }

    .top-ui-dock__bar {
        background: #000000 !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: none;
    }

    .top-ui-dock__bar-left .turn-display {
        font-size: 0.72rem;
        margin: 0;
    }
    .top-ui-dock__bar-right .score-display {
        padding: 4px 8px;
        font-size: 0.7rem;
        margin-right: 0 !important;
    }
    .header-right {
        flex: 1 1 auto;
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        align-items: center;
        align-content: center;
        gap: 4px 6px;
        min-width: 0;
        max-width: 100%;
    }
    .header-right .readme-button {
        padding: 5px 8px;
        font-size: 0.62rem;
        white-space: nowrap;
        flex-shrink: 0;
    }
    /* Leaderboard-Panel (per JS eingefügt): unter Header, mit Safe-Area und Scroll */
    .leaderboard {
        top: calc(env(safe-area-inset-top, 0px) + 56px) !important;
        right: max(8px, env(safe-area-inset-right, 0px)) !important;
        left: auto !important;
        max-width: calc(100vw - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) !important;
        max-height: min(72vh, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 140px)) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        font-size: 0.88rem !important;
        padding: 10px 12px !important;
        box-sizing: border-box !important;
    }
    body > .player-name-display {
        top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
        right: max(10px, env(safe-area-inset-right, 0px)) !important;
        font-size: 0.8rem !important;
        z-index: 4800 !important;
        max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    #total-score { font-size: 15px; }
    .map-container {
        flex: 1 1 0%;
        min-height: 0;
        margin-top: 0;
        padding-bottom: max(8px, env(safe-area-inset-bottom, 0));
        overflow: hidden;
        /* pan-x/pan-y lässt den Browser Geste „stehlen“; Kartenpan läuft per JS in setupTouchControls */
        touch-action: none;
        -webkit-overflow-scrolling: auto;
    }
    .terrain-controls { position: fixed !important; top: 50% !important; left: 50% !important; transform: translate(-50%, -50%) !important; width: 90% !important; max-width: 400px !important; margin: 0 auto !important; z-index: 1001 !important; }
    .terrain-controls .units-panel { width: 100% !important; max-height: 80vh !important; overflow-y: auto !important; }
    /* Units + START/BUY: wie Desktop oben — im Fluss unter dem Header, nicht am unteren Bildschirmrand */
    .controls { position: relative; bottom: auto; top: auto; left: auto; right: auto; transform: none; width: 100%; max-width: 100%; box-sizing: border-box; border-radius: 0; padding: 10px; padding-bottom: 10px; justify-content: flex-start; background-color: rgb(0,0,0); box-shadow: 0 2px 10px rgba(0,0,0,0.45); z-index: 1; overflow-x: auto; }
    .units-selector { display: flex; align-items: center; gap: 10px; padding: 5px; -webkit-overflow-scrolling: touch; scrollbar-width: none; -ms-overflow-style: none; width: auto; min-width: min-content; margin-left: 10px; }
    .units-selector::-webkit-scrollbar { display: none; }
    #generate-map { flex-shrink: 0; margin-right: 10px; }
    .unit-item { padding: 8px 15px; min-height: 44px; }
    .unit-item img { width: 48px; height: 48px; }
    .counter { font-size: 16px; margin-left: 8px; }
    /* START/BUY am linken Rand fixieren, damit sie beim horizontalen Scrollen der Einheiten-Slots sichtbar bleiben */
    .controls .button-group {
        position: sticky;
        left: 0;
        z-index: 2;
        background-color: rgb(0,0,0);
        padding-right: 6px;
        flex-shrink: 0;
    }
}

/* Mobile Landscape (Hochformat-Layout würde hier komplett zerquetscht werden) */
@media (max-width: 950px) and (orientation: landscape) and (max-height: 500px) {
    .header-container { min-height: 36px; padding: 4px 12px; }
    .header-container h1 { font-size: 0.95rem; }
    .controls { padding: 6px 10px !important; padding-bottom: 6px !important; }
    .map-container { padding-bottom: max(8px, env(safe-area-inset-bottom, 0)) !important; }
    .unit-item img { width: 32px; height: 32px; }
    .unit-item { padding: 4px 10px; }
    #generate-map, #buy-button { padding: 6px 14px; font-size: 14px; min-height: 36px; }
    .leaderboard {
        top: calc(env(safe-area-inset-top, 0px) + 58px) !important;
        max-height: min(58vh, calc(100dvh - 58px - env(safe-area-inset-bottom, 0px))) !important;
        font-size: 0.8rem !important;
        padding: 8px 10px !important;
    }
}

/* ========== Modern UI refresh (überschreibt nur gezielt oben) ========== */
:root {
    --ui-bg-deep: #000000;
    --ui-bg-elevated: rgba(24, 24, 36, 0.78);
    --ui-glass: rgba(255, 255, 255, 0.06);
    --ui-border: rgba(255, 255, 255, 0.1);
    --ui-accent: #e8c547;
    --ui-accent-dim: rgba(232, 197, 71, 0.22);
    --ui-text: #e8eaef;
    --ui-muted: rgba(232, 234, 239, 0.65);
    --ui-radius: 12px;
    --ui-radius-sm: 8px;
    --ui-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
    --ui-font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    font-family: var(--ui-font);
    background-color: #000000;
    background-image: none;
    color: var(--ui-text);
    -webkit-font-smoothing: antialiased;
}

.container {
    background-color: var(--ui-bg-deep);
}

.header-container {
    height: auto;
    min-height: 40px;
    padding: 6px 14px;
    position: relative;
    z-index: 400;
    background: var(--ui-bg-elevated);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--ui-border);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

.header-container h1 {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ui-accent);
    text-shadow: 0 0 28px rgba(232, 197, 71, 0.25);
    margin: 0;
}

.subtitle {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--ui-accent);
    font-style: normal;
    margin: 0;
    letter-spacing: 0.03em;
    text-decoration: none;
    cursor: pointer;
}

.subtitle:hover {
    color: #fff;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.turn-display {
    font-size: 0.8rem;
    color: var(--ui-accent);
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
    opacity: 0.95;
}

.header-right {
    gap: 8px;
    align-items: center;
    position: relative;
    z-index: 500;
    pointer-events: auto;
}

#readme-button,
#board-button,
#donate-button {
    position: relative;
    z-index: 1;
    pointer-events: auto;
}

.score-display {
    background: var(--ui-glass);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
    padding: 6px 12px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* Foldable strip: eine Kopleiste (Turn | Pfeil | Name+Funds), darunter Controls + Header */
.top-ui-dock {
    flex-shrink: 0;
    position: relative;
    z-index: 500;
}

.top-ui-dock__bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 4px 8px;
    width: 100%;
    padding: 3px 10px;
    padding-top: max(3px, env(safe-area-inset-top, 0px));
    padding-left: max(10px, env(safe-area-inset-left, 0px));
    padding-right: max(10px, env(safe-area-inset-right, 0px));
    flex-shrink: 0;
    background: var(--ui-bg-elevated);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--ui-border);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
    position: relative;
    z-index: 40;
}

.top-ui-dock__bar-left {
    min-width: 0;
    justify-self: start;
}

.top-ui-dock__bar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
    justify-self: end;
}

.top-ui-dock__bar-left .turn-display {
    margin: 0;
    min-width: 0;
    text-align: left;
}

.top-ui-dock__bar-right .score-display {
    margin: 0;
    flex-shrink: 0;
}

.top-ui-dock__player-mount {
    display: none;
    min-width: 0;
    max-width: 100%;
    flex: 0 1 auto;
}

.top-ui-dock__player-mount.top-ui-dock__player-mount--has-name {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: max-content;
    max-width: min(36vw, 11rem);
}

.top-ui-dock__player-mount .player-name-display {
    position: static !important;
    top: auto !important;
    right: auto !important;
    left: auto !important;
    width: max-content;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 3px 8px;
    font-size: 0.74rem;
    font-weight: 600;
    text-align: center;
    background: var(--ui-glass);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
    color: var(--ui-text);
    z-index: auto !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Pfeil zentriert in der Mittelspalte; nur Wrapper sichtbar — Text per aria-label + .toggle-label versteckt */
.top-ui-dock__toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    margin: 0;
    padding: 2px 4px;
    border: none;
    cursor: pointer;
    font-family: var(--ui-font);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ui-accent);
    background: transparent;
    box-shadow: none;
    transition: color 0.2s ease;
}

.top-ui-dock__toggle-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.top-ui-dock__toggle:hover {
    color: #fff;
}

.top-ui-dock__toggle:hover .top-ui-dock__chevron-wrap {
    border-color: rgba(255, 243, 180, 0.85);
    background: rgba(232, 197, 71, 0.28);
}

.top-ui-dock__toggle:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 2px;
    border-radius: 10px;
}

/* Wrapper macht den Pfeil als „Klick hier“-Affordance erkennbar */
.top-ui-dock__chevron-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(232, 197, 71, 0.2);
    border: 2px solid rgba(232, 197, 71, 0.65);
    box-shadow:
        0 0 0 0 rgba(232, 197, 71, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.14);
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.top-ui-dock__chevron {
    display: block;
    width: 0;
    height: 0;
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-top: 12px solid #fff8dc;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
    transition: transform 0.22s ease;
}

@keyframes top-ui-dock-chevron-pulse {
    0%, 100% {
        box-shadow:
            0 0 0 0 rgba(232, 197, 71, 0.45),
            inset 0 1px 0 rgba(255, 255, 255, 0.14);
        transform: scale(1);
    }
    50% {
        box-shadow:
            0 0 0 10px rgba(232, 197, 71, 0.08),
            inset 0 1px 0 rgba(255, 255, 255, 0.14);
        transform: scale(1.06);
    }
}

/* Mobil: Puls nur wenn zu — Hinweis „hier aufklappen“. Desktop: siehe nächster Block. */
@media (max-width: 768px) {
    .top-ui-dock:not(.is-top-ui-open) .top-ui-dock__chevron-wrap {
        animation: top-ui-dock-chevron-pulse 2.4s ease-in-out infinite;
    }
}

@media (min-width: 769px) {
    /* Wie mobil (geschlossen): runder Pfeil-Wrapper immer mit Puls — auch bei geöffneter Leiste */
    .top-ui-dock .top-ui-dock__chevron-wrap {
        animation: top-ui-dock-chevron-pulse 2.4s ease-in-out infinite;
    }
}

.top-ui-dock.is-top-ui-open .top-ui-dock__chevron {
    transform: rotate(180deg);
}

@media (min-width: 769px) {
    .top-ui-dock:not(.top-ui-dock--collapsed) .top-ui-dock__chevron {
        transform: rotate(180deg);
    }

    .top-ui-dock.top-ui-dock--collapsed .top-ui-dock__chevron {
        transform: rotate(0deg);
    }
}

.top-ui-dock__body {
    display: block;
}

@media (max-width: 768px) {
    .top-ui-dock__body {
        display: none;
    }

    .top-ui-dock.is-top-ui-open .top-ui-dock__body {
        display: block;
    }
}

@media (min-width: 769px) {
    .top-ui-dock.top-ui-dock--collapsed .top-ui-dock__body {
        display: none !important;
    }

    .top-ui-dock__body {
        display: flex;
        flex-direction: column;
        gap: 0;
        position: relative;
        z-index: 10;
    }

    .top-ui-dock__body .controls {
        border: none;
        border-bottom: 1px solid var(--ui-border);
        border-radius: 0;
        box-shadow: none;
        margin-bottom: 0;
        padding: 8px 12px;
        gap: 10px;
        z-index: 1;
    }

    .top-ui-dock__body .controls .button-group {
        margin-left: 20%;
    }

    .top-ui-dock__body .header-container {
        min-height: 32px;
        padding: 4px 12px;
    }
}

.controls {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    transform: none;
    width: 100%;
    max-width: 100%;
    padding: 8px 14px;
    background: var(--ui-bg-elevated);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius);
    box-shadow: var(--ui-shadow);
    z-index: 2600;
}

.map-container {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    height: auto;
    position: relative;
    overflow: hidden;
}

.panels-container {
    top: 56px;
}

#generate-map {
    padding: 8px 18px;
    border-radius: var(--ui-radius-sm);
    background: linear-gradient(145deg, #f0d060, #c9a227);
    color: #1a1508;
    font-weight: 700;
    letter-spacing: 0.03em;
    box-shadow: 0 4px 14px rgba(232, 197, 71, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

#generate-map:hover {
    filter: brightness(1.06);
    box-shadow: 0 6px 20px rgba(232, 197, 71, 0.45);
}

#generate-map:active {
    transform: scale(0.97);
}

#buy-button {
    border-radius: var(--ui-radius-sm);
    padding: 8px 18px;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: linear-gradient(145deg, #e64545, #b32020);
    box-shadow: 0 4px 16px rgba(230, 69, 69, 0.35);
    transition: transform 0.15s ease, filter 0.15s ease;
}

#buy-button:hover {
    filter: brightness(1.08);
}

#buy-button:active {
    transform: scale(0.97);
}

.readme-button {
    border-radius: var(--ui-radius-sm);
    padding: 7px 14px;
    font-size: 0.75rem;
    background: var(--ui-glass);
    color: var(--ui-text);
    border: 1px solid var(--ui-border);
    font-weight: 600;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.readme-button:hover {
    background: var(--ui-accent-dim);
    border-color: rgba(232, 197, 71, 0.45);
    color: #fff;
}

.units-selector {
    border-left-color: var(--ui-border);
    padding-left: 18px;
}

.unit-item {
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 12px 8px;
    min-width: 76px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
    font-size: 0.72rem;
    color: var(--ui-muted);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease, background 0.2s ease;
}

.unit-item:hover {
    border-color: rgba(232, 197, 71, 0.35);
    background: rgba(255, 255, 255, 0.04);
}

.unit-item.selected {
    border-color: var(--ui-accent);
    box-shadow: 0 0 0 2px var(--ui-accent-dim), 0 8px 24px rgba(0, 0, 0, 0.4);
    background: rgba(232, 197, 71, 0.08);
    color: var(--ui-text);
}

.unit-item img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.45));
}

.unit-item .counter {
    margin-left: 0;
    font-size: 0.95rem;
    color: var(--ui-accent);
}

#minimap {
    border-radius: var(--ui-radius-sm) !important;
    border: 1px solid var(--ui-border) !important;
    box-shadow: var(--ui-shadow);
}

.modal-content,
.buy-modal-content {
    border-radius: var(--ui-radius);
    border: 1px solid var(--ui-border);
    box-shadow: var(--ui-shadow);
}

.buy-modal-content {
    background: linear-gradient(165deg, #2a3042 0%, #1f2433 100%);
}

.modal-content {
    background: linear-gradient(165deg, #2a2a32 0%, #1a1a22 100%);
}

button:focus-visible,
.readme-button:focus-visible,
#generate-map:focus-visible,
#buy-button:focus-visible,
a.subtitle:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 2px;
}

/* Story dialog panel (Zelda-inspired look, UI-only — no AI backend) */

.zelda-story-feed {
    position: fixed;
    left: 50%;
    top: auto;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 2800;
    width: min(90vw, 480px);
    max-width: 100%;
    pointer-events: none;
    filter: drop-shadow(0 12px 32px rgba(0, 0, 0, 0.6));
}

/* Parent pointer-events:none does not block hits on children with default auto — those would steal map pans */
.zelda-story-feed * {
    pointer-events: none;
}

.zelda-story-feed__scroll,
.zelda-story-feed__scroll * {
    pointer-events: auto;
}

/* Hint is outside __scroll — must receive clicks (parent has * { pointer-events: none }) */
.zelda-story-feed .zelda-story-feed__hint {
    pointer-events: auto;
}

.zelda-story-feed__frame {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 10px 14px 8px 14px;
    border-radius: 4px;
    background: linear-gradient(165deg, #1e4a3d 0%, #0f2a24 48%, #0a1f1a 100%);
    border: 3px solid #c9a227;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.12),
        inset 0 -2px 0 rgba(0, 0, 0, 0.35),
        0 0 0 1px rgba(0, 0, 0, 0.5);
}

.zelda-story-feed__frame::before {
    content: "";
    position: absolute;
    inset: 5px;
    border: 1px solid rgba(201, 162, 39, 0.35);
    border-radius: 2px;
    pointer-events: none;
}

.zelda-story-feed__scroll {
    position: relative;
    z-index: 1;
    /* Match story typography so max-height = exactly 3 lines (see .chunk inherit). */
    font-size: clamp(0.88rem, 2.8vw, 1.02rem);
    line-height: 1.55;
    max-height: calc(3 * 1.55 * 1em + 6px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    padding: 2px 6px 4px;
    margin: 0 -2px;
}

.zelda-story-feed__scroll::-webkit-scrollbar {
    width: 6px;
}

.zelda-story-feed__scroll::-webkit-scrollbar-thumb {
    background: rgba(201, 162, 39, 0.45);
    border-radius: 3px;
}

.zelda-story-feed__lines {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.zelda-story-feed__chunk {
    position: relative;
    z-index: 1;
    margin: 0;
    text-align: left;
    font-family: Georgia, "Times New Roman", serif;
    font-size: inherit;
    line-height: inherit;
    letter-spacing: 0.02em;
    color: #f4eed8;
    text-shadow:
        0 1px 0 rgba(0, 0, 0, 0.85),
        0 0 12px rgba(0, 0, 0, 0.4);
}

.zelda-story-feed__typed {
    display: inline;
    vertical-align: baseline;
}

.zelda-story-feed__caret {
    display: inline-block;
    width: 2px;
    height: 0.95em;
    margin-left: 3px;
    vertical-align: -0.1em;
    background: #e8c547;
    box-shadow: 0 0 8px rgba(232, 197, 71, 0.55);
    animation: zelda-story-caret-blink 0.55s step-end infinite;
}

@keyframes zelda-story-caret-blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.zelda-story-feed__hint {
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    margin: 8px 0 0 0;
    padding: 6px 4px 2px;
    width: 100%;
    box-sizing: border-box;
    text-align: left;
    font-size: 0.75rem;
    font-family: inherit;
    line-height: 1;
    color: #e8c547;
    text-shadow: 0 0 8px rgba(232, 197, 71, 0.45);
    animation: zelda-story-blink 1.4s ease-in-out infinite;
    border: none;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.zelda-story-feed__hint:hover {
    color: #fff3c4;
}

.zelda-story-feed__hint:focus-visible {
    outline: 2px solid #e8c547;
    outline-offset: 2px;
}

@keyframes zelda-story-blink {
    0%, 100% { opacity: 0.45; }
    50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .zelda-story-feed__hint {
        animation: none;
        opacity: 0.85;
    }
    .zelda-story-feed__caret {
        animation: none;
        opacity: 0.85;
    }
    .zelda-story-feed__scroll {
        scroll-behavior: auto;
    }
    .top-ui-dock__chevron {
        transition: none;
    }
    .top-ui-dock__chevron-wrap {
        animation: none !important;
    }
    #generate-map,
    #buy-button,
    .unit-item,
    .readme-button {
        transition: none;
    }
    #generate-map:active,
    #buy-button:active {
        transform: none;
    }
}

@media (max-width: 768px) {
    .zelda-story-feed {
        bottom: 0;
        z-index: 2400;
    }

    .zelda-story-feed__frame {
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    }

    .zelda-story-feed__scroll {
        max-height: calc(3 * 1.55 * 1em + 6px);
    }

    .controls {
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: 1px solid var(--ui-border);
        position: relative !important;
        top: auto !important;
        bottom: auto !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        align-items: center !important;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background-color: rgba(0, 0, 0, 0.92);
    }
    .map-container {
        flex: 1 1 0% !important;
        min-height: 0 !important;
        overflow: hidden;
    }
}