:root { 
    --uiScale: 1; 
}
/* KI-Dungeon Crawler CSS */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Ready+Player+One&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Press Start 2P', 'Courier New', monospace !important;
}

body {
    font-family: 'Press Start 2P', 'Courier New', monospace !important;
    background: radial-gradient(120% 120% at 50% 10%, #1a1209 0%, #0c0906 55%, #070604 100%);
    color: #f8eedf;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#gameContainer {
    text-align: center;
    background: linear-gradient(180deg, #1b140a 0%, #120d08 60%, #0f0a06 100%);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 30px rgba(255, 160, 40, 0.25), 0 0 90px rgba(255, 120, 0, 0.15);
    border: 2px solid #8a5523;
    position: relative; /* für absolute Kinder wie Zahnrad/Settings */
}

/* Warmes Ambient-Licht & Vignette */
#gameContainer::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(120% 70% at 10% 0%, rgba(255, 181, 72, 0.09), rgba(0,0,0,0) 55%),
        radial-gradient(120% 70% at 90% 0%, rgba(255, 181, 72, 0.09), rgba(0,0,0,0) 55%),
        radial-gradient(120% 100% at 50% 0%, rgba(255, 170, 60, 0.06), rgba(0,0,0,0) 60%),
        radial-gradient(100% 120% at 50% 60%, rgba(0,0,0,0) 60%, rgba(0,0,0,0.35) 100%);
    mix-blend-mode: screen;
}

/* Einstellungen Button + Panel */
#settingsBtn {
    position: absolute;
    right: 8px;
    top: 8px;
    background: transparent;
    color: #ffd166;
    border: 0;
    padding: 0;
    border-radius: 0;
    font-size: 18px;
    cursor: pointer;
    text-shadow: 0 0 8px rgba(255, 170, 60, 0.5);
}

#settingsPanel {
    position: absolute;
    right: 8px;
    top: 42px;
    width: 220px;
    background: rgba(40, 28, 18, 0.95);
    border: 2px solid #d29a3a;
    border-radius: 8px;
    padding: 10px;
    text-align: left;
    z-index: 3000;
    box-shadow: 0 10px 20px rgba(0,0,0,.4), 0 0 20px rgba(255,140,0,.2) inset;
}

#settingsPanel .settingsRow {
    display: grid;
    grid-template-columns: 60px 1fr 42px;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
    font-size: 9px;
}

#settingsPanel input[type="range"] {
    accent-color: #ffb347;
}

/* Touch-Steuerung (mobil) */
#touchControls {
    position: absolute;
    left: 8px;
    bottom: 8px;
    display: grid;
    grid-template-areas:
        ". up . attack"
        "left . right attack"
        ". down . attack";
    grid-template-columns: 40px 40px 40px 80px;
    grid-template-rows: 40px 40px 40px;
    gap: 6px;
    z-index: 2500;
    touch-action: manipulation;
}

#btnUp { grid-area: up; }
#btnLeft { grid-area: left; }
#btnRight { grid-area: right; }
#btnDown { grid-area: down; }
#btnAttack { grid-area: attack; width: 80px; }

#touchControls button {
    background: rgba(58, 42, 31, 0.9);
    color: #f8eedf;
    border: 2px solid #d29a3a;
    border-radius: 8px;
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
}

@media (max-width: 768px) {
    #settingsPanel {
        right: 6px;
        top: 38px;
        width: min(92vw, 260px);
    }
    #touchControls {
        grid-template-columns: 36px 36px 36px 72px;
        grid-template-rows: 36px 36px 36px;
    }
}

h1 {
    color: #ffd166;
    margin-bottom: 20px;
    font-size: 16px;
    text-shadow: 0 0 6px rgba(255, 170, 60, 0.7), 2px 2px 0px #3a2a1f;
}

#hud {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    font-size: 8px;
    background: rgba(45, 28, 12, 0.8);
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #8a5523;
    backdrop-filter: blur(2px);
    transform: scale(var(--uiScale));
    transform-origin: top left;
    box-shadow: 0 0 12px rgba(255, 140, 0, 0.15) inset;
}
#teleportCD{ color:#ffd700; font-weight:bold; }

#playerStats, #gameStats {
    display: flex;
    flex-direction: row;
    gap: 8px;
    flex-wrap: wrap;
}

#playerStats div, #gameStats div {
    background: #3a2a1f;
    padding: 3px 6px;
    border-radius: 3px;
    border: 1px solid #8a5523;
}

/* Canvas mit Pixel-Perfect Rendering */
#gameCanvas {
    border: 3px solid #d29a3a;
    border-radius: 5px;
    background: #000;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    box-shadow: 0 0 18px rgba(255, 140, 0, 0.45);
    touch-action: none; /* Keine Scroll-/Zoom-Gesten auf dem Canvas */
}

/* Spielbereich */
#playArea {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    justify-content: center;
}

#eventPanel {
    width: 356px;
    height: 576px;
    border: 3px solid #d29a3a;
    border-radius: 5px;
    background: rgba(40, 28, 18, 0.9);
    box-shadow: 0 0 15px rgba(255, 140, 0, 0.3);
    padding: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(2px);
    transform: scale(var(--uiScale));
    transform-origin: top left;
}

#eventPanel h3 {
    color: #ffd166;
    font-size: 12px;
    margin-bottom: 8px;
}

#eventLog {
    flex: 1;
    font-size: 10px;
    line-height: 1.4;
    background: rgba(40, 28, 18, 0.6);
    border: 1px solid #8a5523;
    border-radius: 4px;
    padding: 8px;
    overflow-y: auto;
    scrollbar-width: thin;
}

#eventLog .line {
    margin-bottom: 6px;
}

#eventLog .line.system { color: #cbd5e1; }
#eventLog .line.player { color: #ffd166; }
#eventLog .line.monster { color: #f87171; }

#inventoryHeader { display: none; }

#toggleInventoryBtn {
    background: #3a2a1f;
    color: #f8eedf;
    border: 2px solid #d29a3a;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: 'Press Start 2P', cursive;
    font-size: 8px;
    cursor: pointer;
}

/* Inventar-Modal */
#inventoryOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: none; /* via JS toggeln */
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

/* Shop-Modal */
#shopOverlay{ position:fixed; inset:0; background:rgba(0,0,0,0.55); display:none; align-items:center; justify-content:center; z-index:2100; }
#shopOverlay.show{ display:flex; }
#shopModal{ background:#2b1f14; color:#f8eedf; border:2px solid #d29a3a; width:420px; max-width:90vw; border-radius:8px; box-shadow:0 10px 30px rgba(0,0,0,0.6), 0 0 30px rgba(255,140,0,0.2) inset; }
#shopModal .modalHeader{ display:flex; align-items:center; justify-content:space-between; border-bottom:1px solid #8a5523; padding:10px 12px; }
#shopContent{ padding:12px; max-height:60vh; overflow:auto; }
#shopContent .item{ display:flex; align-items:center; justify-content:space-between; padding:8px 6px; border-bottom:1px solid #8a5523; }
#shopContent .item button{ background:#3a2a1f; color:#f8eedf; border:2px solid #d29a3a; padding:5px 10px; border-radius:4px; cursor:pointer; }
#shopContent .item button[disabled]{ background:#333; border-color:#555; cursor:not-allowed; }

#inventoryModal {
    width: 520px;
    max-height: 70vh;
    background: #2b1f14;
    border: 3px solid #d29a3a;
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(255, 160, 40, 0.25);
    padding: 12px;
    display: flex;
    flex-direction: column;
}

#inventoryModal .modalHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

#inventoryModal #inventoryList {
    overflow-y: auto;
    background: #3a2a1f;
    border: 1px solid #8a5523;
    border-radius: 4px;
    padding: 8px;
}

#inventoryList .item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border-bottom: 1px solid #1e3a5f;
}

#inventoryList .item .name {
    font-size: 10px;
}

#inventoryList .item button, #toggleInventoryBtn, #closeInventoryBtn {
    background: #3a2a1f;
    color: #f8eedf;
    border: 2px solid #d29a3a;
    padding: 3px 6px;
    border-radius: 4px;
    font-family: 'Press Start 2P', cursive;
    font-size: 8px;
    cursor: pointer;
}

@media (max-width: 1024px) {
    #playArea {
        flex-direction: column;
        align-items: center;
    }
    /* Panel darf mitwachsen (NPC-Chat braucht Platz), aber nie den Screen fluten */
    #eventPanel { order:2; width:94vw; height:auto; min-height:160px; max-height:45vh; overflow-y:auto; }
}

#controls {
    margin-top: 15px;
    font-size: 8px;
    color: #aaa;
    line-height: 1.4;
    transform: scale(var(--uiScale));
    transform-origin: top left;
}

/* Overlays skalieren leicht mit */
#inventoryModal, #shopModal, #characterModal { transform: scale(var(--uiScale)); transform-origin: center; }

/* Audio-Hinweis */
#audioHint{position:absolute; top:8px; right:48px; background:rgba(40,28,18,0.85); color:#ffd166; padding:4px 8px; border:1px solid #d29a3a; border-radius:4px; font-size:9px; z-index:4000}

/* Pause Menü */
#pauseMenu {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #2b1f14;
    border: 3px solid #d29a3a;
    border-radius: 10px;
    padding: 20px;
    z-index: 1000;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8), 0 0 20px rgba(255,140,0,0.25) inset;
}

#pauseMenu h3 {
    color: #ffd166;
    margin-bottom: 15px;
    font-size: 12px;
}

#pauseMenu button {
    background: #3a2a1f;
    color: #f8eedf;
    border: 2px solid #d29a3a;
    padding: 8px 15px;
    margin: 5px;
    border-radius: 5px;
    font-family: 'Press Start 2P', cursive;
    font-size: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

/* Spieler-Stats als Label- und Werte-Kästchen auf einer Linie */
#playerStats { gap: 6px; }
#playerStats .statRow { display: flex; align-items: center; gap: 6px; }
#playerStats .statLabel { background:#3a2a1f; padding: 3px 6px; border-radius: 3px; border: 1px solid #8a5523; text-align: left; }
#playerStats .statValue { background:#4a3526; padding: 3px 8px; border-radius: 3px; border: 1px solid #8a5523; min-width: 46px; text-align: center; }

/* Golden-Ratio Annäherung: Seitenpanel etwas schmaler */
#eventPanel { width: 356px; }

#pauseMenu button:hover {
    background: #d29a3a;
    color: #1b140a;
    box-shadow: 0 0 10px rgba(255, 170, 60, 0.55);
}

#monsterFavorites {
    margin-top: 15px;
    font-size: 8px;
}

/* Responsive Design */
@media (max-width: 768px) {
    #gameContainer {
        padding: 8px;
    }
    
    #gameCanvas {
        width: 94vw;
        height: auto;
        aspect-ratio: 1 / 1; /* Quadrat halten */
        max-width: 94vw;
        max-height: 94vw;
    }
    
    #hud {
        font-size: 6px;
    }

    #playArea {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }
    #eventPanel { order:2; width:94vw; height:160px; }
    #controls { font-size: 7px; }
}

/* Character Modal Styles */
#characterOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#characterModal {
    background: #2b1f14;
    border: 1px solid #8a5523;
    border-radius: 8px;
    min-width: 520px;
    max-width: 720px;
    color: #f8eedf;
    padding: 12px;
    font-family: 'Press Start 2P', cursive !important;
}

#characterModal .modalHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #2a4a6b;
    margin-bottom: 8px;
}

#characterContent .row {
    display: flex;
    gap: 12px;
    margin: 8px 0;
}

#characterContent .card {
    flex: 1;
    border: 1px solid #8a5523;
    padding: 8px;
    border-radius: 6px;
    background: #3a2a1f;
}

#characterContent .stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 4px 0;
}

#characterContent button {
    background: #3a2a1f;
    color: #f8eedf;
    border: 1px solid #d29a3a;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive !important;
}

#characterContent button:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* Fackeln oben links/rechts mit flackerndem Licht */
.torch {
    position: absolute;
    width: 48px;
    image-rendering: pixelated;
    pointer-events: none;
    z-index: 500;
    filter: drop-shadow(0 0 6px rgba(255, 170, 60, 0.6)) drop-shadow(0 0 18px rgba(255, 120, 0, 0.35));
}
.torch img { width: 100%; height: auto; display:block; }

#torchLeft { left: 14px; top: 56px; }
#torchRight { right: 14px; bottom: 56px; top: auto; transform: scaleX(-1); }

.torch::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 8px;
    width: 220px;
    height: 220px;
    transform: translateX(-50%);
    background: radial-gradient(ellipse at center, rgba(255, 210, 110, 0.35) 0%, rgba(255, 170, 60, 0.22) 28%, rgba(255, 120, 0, 0.10) 55%, rgba(0,0,0,0) 70%);
    filter: blur(6px);
    mix-blend-mode: screen;
    animation: torchGlow 2s infinite ease-in-out;
    border-radius: 50%;
}

@keyframes torchGlow {
    0%   { opacity: .6; transform: translateX(-50%) scale(1); }
    50%  { opacity: .9; transform: translateX(-50%) scale(1.05); }
    100% { opacity: .65; transform: translateX(-50%) scale(0.98); }
}

/* Optional kleines Flackern für die gesamte Fackel */
.torch { animation: torchFlicker 1.8s infinite steps(20); }
@keyframes torchFlicker {
    0% { filter: drop-shadow(0 0 6px rgba(255,170,60,.55)) drop-shadow(0 0 18px rgba(255,120,0,.32)); }
    50% { filter: drop-shadow(0 0 9px rgba(255,190,90,.8)) drop-shadow(0 0 22px rgba(255,140,0,.45)); }
    100% { filter: drop-shadow(0 0 6px rgba(255,170,60,.55)) drop-shadow(0 0 18px rgba(255,120,0,.32)); }
}

@media (max-width: 768px) {
    #torchLeft { left: 10px; top: 50px; }
    #torchRight { right: 10px; bottom: 46px; top: auto; }
}