/* --- RESET & ROOT CONFIG --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* Load Custom JSL Blackletter Font */
@font-face {
    font-family: 'JSLBlackletter';
    src: url('assets/fonts/jsl.TTF') format('truetype');
    font-weight: normal;
    font-style: normal;
}

:root {
    --bg-color: #000000;
    --text-color: #ffffff;
    --gothic-font: 'JSLBlackletter', 'UnifrakturMaguntia', cursive, serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--gothic-font);
    height: 100dvh; /* Lock to exact screen height */
    width: 100vw;
    overflow: hidden; /* Disable scrolling completely */
    display: flex;
    justify-content: center;
    align-items: center;
    filter: brightness(0.85); 
    transition: filter 1s ease;
}

/* --- THEME PALETTES --- */

/* Retro Gameboy Green Filter for Forest Level */
body.forest #dungeon-viewport,
body.forest #minimap-canvas {
    filter: sepia(100%) hue-rotate(65deg) saturate(2.5) contrast(1.1) brightness(0.9);
}

.gothic-text, .gothic-btn, .gothic-link {
    font-family: var(--gothic-font);
    color: #ffffff;
    text-shadow: 0 0 4px #000000;
    text-transform: lowercase; 
}

#game-header, #audio-controls {
    text-transform: lowercase;
}

/* --- UTILITY CLASSES --- */
.screen-hidden { display: none !important; }
.screen-active { display: flex !important; }

/* --- LANDING SCREEN --- */
#landing-screen, #success-screen {
    width: 100%;
    max-width: 480px;
    height: 100%;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    text-align: center;
}

.success-title {
    font-size: 3rem;
    margin-bottom: 20px;
}

.success-sub {
    font-size: 1.4rem;
    margin-bottom: 40px;
}

/* --- LOGO ANIMATION --- */
@keyframes logoPulse {
    0% {
        filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.1)) brightness(0.9);
        transform: scale(1);
    }
    50% {
        filter: drop-shadow(0 0 25px rgba(255, 255, 255, 0.4)) brightness(1.2);
        transform: scale(1.03);
    }
    100% {
        filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.1)) brightness(0.9);
        transform: scale(1);
    }
}

.logo-img {
    max-width: 280px;
    width: 80%;
    height: auto;
    margin-bottom: 40px;
    animation: logoPulse 4.5s ease-in-out infinite;
}

.landing-menu {
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: 100%;
}

.password-input {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #555;
    color: #fff;
    font-family: var(--gothic-font);
    font-size: 1.2rem;
    padding: 10px 15px;
    text-align: center;
    outline: none;
    text-transform: lowercase;
    width: 100%;
    margin-bottom: -10px; 
    transition: border 0.3s ease;
}

.password-input:focus {
    border-color: #ffffff;
}

.gothic-btn {
    background: #000000;
    border: 2px solid #ffffff;
    padding: 14px 20px;
    font-size: 1.4rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.gothic-btn:hover, .gothic-btn:active {
    background: #ffffff;
    color: #000000;
}

.gothic-link {
    font-size: 1.6rem;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border 0.2s ease;
}

.gothic-link:hover {
    border-bottom: 1px solid #ffffff;
}

/* --- GAME SCREEN LAYOUT --- */
#game-screen {
    width: 100%;
    max-width: 650px; 
    height: 100dvh; /* Lock to exact screen height */
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 25px 10px;
    position: relative;
}

#game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 5px 10px; 
    border-bottom: 1px solid #333;
    font-size: clamp(1.2rem, 4vw, 1.45rem);
}

.white-icon {
    color: transparent;
    text-shadow: 0 0 0 #ffffff;
}

/* --- COMPOSITED VIEWPORT --- */
#dungeon-viewport {
    width: 100%;
    /* CRITICAL: Caps the maximum width to 42% of the screen's height, guaranteeing room for controls */
    max-width: min(100%, 42vh); 
    aspect-ratio: 1 / 1;
    flex-shrink: 0; 
    position: relative;
    background-color: #000000;
    border: 2px solid #ffffff;
    overflow: hidden;
}
.render-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    image-rendering: pixelated; 
    object-fit: contain;
    transform-origin: center bottom; 
}

/* --- KEY ITEM ANIMATIONS --- */
@keyframes keyGlowPulse {
    0% { filter: drop-shadow(0 0 2px #ffffff) brightness(1); transform: scale(1); }
    50% { filter: drop-shadow(0 0 12px #ffffff) brightness(1.7); transform: scale(1.06); }
    100% { filter: drop-shadow(0 0 2px #ffffff) brightness(1); transform: scale(1); }
}

.key-glow {
    animation: keyGlowPulse 1.2s infinite ease-in-out;
}

@keyframes keyAcquiredBounce {
    0% { transform: scale(1) translateY(0); opacity: 1; filter: drop-shadow(0 0 12px #ffffff) brightness(1.7); }
    50% { transform: scale(1.3) translateY(-15%); opacity: 1; filter: drop-shadow(0 0 20px #ffffff) brightness(2); }
    100% { transform: scale(0.5) translateY(-30%); opacity: 0; filter: drop-shadow(0 0 0px #ffffff) brightness(1); }
}

.key-acquired-anim {
    animation: keyAcquiredBounce 0.8s ease-out forwards;
    z-index: 100;
}

/* --- HEAD BOB ANIMATIONS --- */
@keyframes bobStep {
    0% { transform: translateY(0); }
    50% { transform: translateY(1.7px); } 
    100% { transform: translateY(0); }
}

@keyframes bobTurnLeft {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(-0.35deg); } 
    100% { transform: rotate(0deg); }
}

@keyframes bobTurnRight {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(0.35deg); } 
    100% { transform: rotate(0deg); }
}

.bob-step .render-layer:not(.key-acquired-anim) { animation: bobStep 0.15s ease-in-out; }
.bob-turn-l .render-layer:not(.key-acquired-anim) { animation: bobTurnLeft 0.15s ease-in-out; }
.bob-turn-r .render-layer:not(.key-acquired-anim) { animation: bobTurnRight 0.15s ease-in-out; }

/* --- D-PAD CONTROLS --- */
#dpad-container {
    margin-top: 10px;
    margin-bottom: 10px;
}

.dpad-grid {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.dpad-middle-row {
    display: flex;
    gap: 10px;
}

.dpad-btn {
    background: #000000;
    color: #ffffff;
    border: 2px solid #ffffff;
    width: 60px;
    height: 60px;
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
}

.dpad-btn:active {
    background: #ffffff;
    color: #000000;
}

/* --- AUDIO FOOTER --- */
#audio-controls {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem; 
    padding: 5px 10px;
}

.small-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 1.2rem;
}

#message-bar {
    width: 100%;
    min-height: 1.5rem; 
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: clamp(1.4rem, 6vw, 2.2rem);
    color: #ffffff;
    margin-top: 1%;
    margin-bottom: 1%;
    text-transform: lowercase;
    padding: 0 10px;
}

.minimap-container {
    display: flex;
    height: 20vh;
    justify-content: center;
    align-items: center;
    margin: 8px 0;
}

#minimap-canvas {
    background-color: #000000;
    border: 1px solid #ffffff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
    image-rendering: pixelated;
}

/* --- NEW ITEM ANIMATIONS --- */

@keyframes flaskSway {
    0% { transform: rotate(-1.5deg); filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.3)); }
    50% { transform: rotate(1.5deg); filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.7)); }
    100% { transform: rotate(-1.5deg); filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.3)); }
}

.flask-sway {
    animation: flaskSway 4s ease-in-out infinite;
    transform-origin: top center;
}

/* Blown out Fairy: High brightness and crushed contrast force black pixels to wash out to white */
@keyframes fairyHover {
    0% { 
        transform: translateY(0); 
        filter: drop-shadow(0 0 15px #fff) drop-shadow(0 0 30px #fff) contrast(0.2) brightness(3); 
    }
    50% { 
        transform: translateY(-12px); 
        filter: drop-shadow(0 0 25px #fff) drop-shadow(0 0 50px #fff) contrast(0.05) brightness(5); 
    }
    100% { 
        transform: translateY(0); 
        filter: drop-shadow(0 0 15px #fff) drop-shadow(0 0 30px #fff) contrast(0.2) brightness(3); 
    }
}

.fairy-hover {
    animation: fairyHover 2.5s ease-in-out infinite;
}

@keyframes teleporterPulse {
    0% { filter: drop-shadow(0 0 2px #fff); opacity: 0.8; }
    50% { filter: drop-shadow(0 0 15px #fff); opacity: 1; }
    100% { filter: drop-shadow(0 0 2px #fff); opacity: 0.8; }
}

.teleporter-pulse {
    animation: teleporterPulse 2s infinite;
}

.blood-flask {
    color: transparent;
    text-shadow: 0 0 0 #ff0000;
}
/* --- VOLUME SLIDER --- */
.volume-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

#volume-icon {
    font-size: 1.2rem;
}

#volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    background: transparent;
    outline: none;
}

#volume-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: #ffffff;
}

#volume-slider::-webkit-slider-thumb {
    height: 14px;
    width: 8px;
    background: #000000;
    border: 1px solid #ffffff;
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -5px;
}

#volume-slider::-moz-range-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: #ffffff;
}

#volume-slider::-moz-range-thumb {
    height: 14px;
    width: 8px;
    background: #000000;
    border: 1px solid #ffffff;
    cursor: pointer;
    border-radius: 0;
}
/* --- MOBILE OPTIMIZATIONS --- */

/* 1. Disable double-tap to zoom on UI elements */
button, input, a, .dpad-btn, .gothic-btn, .small-btn {
    touch-action: manipulation;
}

/* 2. Hide Volume Slider strictly on touch devices */
@media (pointer: coarse) {
    .volume-container {
        display: none !important;
    }
}
/* 3. Shrink minimap on mobile screens */
@media (max-width: 600px) {
    #minimap-canvas {
        max-width: 140px; /* Adjust this number to make it smaller or larger */
        height: auto;
        border-width: 1px; /* Keeps the border from looking chunky when scaled */
    }
    
    .minimap-container {
        margin: 5px 0; /* Reduces the empty space around the smaller map */
    }
}