@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

:root {
    --bg: #050505; 
    --panel: #141110; 
    --panel-border: #4a3a2c; 
    --text: #dcd0c0; 
    --accent: #8a0303; 
    --gold: #c5a059; 
    --hp-green: #4b834b;
}

body {
    font-family: 'VT323', monospace; font-size: 22px; background: var(--bg);
    background-image: radial-gradient(circle at center, #1a1514 0%, #050505 100%);
    color: var(--text); margin: 0; padding: 20px;
    display: flex; justify-content: center; text-shadow: 1px 1px 0px #000;
    transition: background 1s, color 1s;
}

#game-container { width: 100%; max-width: 800px; display: flex; flex-direction: column; gap: 20px; }

.panel {
    background: var(--panel); padding: 20px; border: 4px solid var(--panel-border);
    border-style: ridge; box-shadow: inset 0 0 20px black, 0 5px 15px rgba(0,0,0,0.8);
    transition: background 1s, border-color 1s;
}

header {
    display: flex; flex-direction: column; gap: 8px;
    border-bottom: 2px solid var(--panel-border); padding-bottom: 10px; margin-bottom: 20px;
    background: linear-gradient(to right, transparent, rgba(0,0,0,0.4), transparent);
    transition: border-color 1s;
}

.stats { color: #7bed9f; }
h2, h3, h4 { color: var(--gold); text-transform: uppercase; letter-spacing: 2px; margin-top: 0; text-shadow: 2px 2px 0px #000; }

#screens { min-height: 200px; }
.screen { display: none; text-align: center; }
.screen.active { display: block; }

button {
    background: linear-gradient(to bottom, rgba(255,255,255,0.1), rgba(0,0,0,0.5)); color: var(--text);
    border: 2px outset var(--panel-border); padding: 8px 16px; margin: 5px; cursor: pointer;
    font-family: 'VT323', monospace; font-size: 1.1em; text-transform: uppercase;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.5);
    transition: border-color 0.3s, color 0.3s;
}
button:hover { background: rgba(0,0,0,0.8); color: var(--gold); border-color: var(--gold); }
button:active { border-style: inset; transform: translateY(2px); box-shadow: none; }
button:disabled { background: #111; color: #555; border: 2px solid #222; cursor: not-allowed; transform: none; box-shadow: none; }

select { font-family: 'VT323', monospace; font-size: 1em; background: #333; color: white; padding: 5px; border: 1px solid #555; }

#log-container {
    height: 250px; overflow-y: auto; border: 3px inset #222;
    background: #0a0808; padding: 15px; text-align: left; line-height: 1.2;
}
.log-entry { margin-bottom: 8px; border-bottom: 1px dashed #222; padding-bottom: 4px; }
.log-combat { color: #ff5252; } .log-loot { color: var(--gold); text-shadow: 0 0 5px rgba(241, 196, 15, 0.4); } .log-system { color: #81ecec; }

.split-panel { display: flex; gap: 20px; flex-direction: row; }
.panel-half { flex: 1; border: 1px solid var(--panel-border); padding: 10px; }
.inv-item { display: flex; justify-content: space-between; padding: 10px; border: 1px solid rgba(255,255,255,0.1); background: rgba(0,0,0,0.3); margin-bottom: 5px; align-items: center; text-align: left; }

@keyframes screenShake { 0% { transform: translate(1px, 1px) } 25% { transform: translate(-3px, 0px) } 50% { transform: translate(3px, 2px) } 75% { transform: translate(-1px, -1px) } 100% { transform: translate(0px, 0px) } }
@keyframes flashRed { 0% { background-color: rgba(255, 0, 0, 0.4); } 100% { background-color: transparent; } }
@keyframes slashAnim { 0% { transform: scaleX(0) rotate(-45deg); opacity: 1; } 40% { transform: scaleX(1) rotate(-45deg); opacity: 1; } 100% { transform: scaleX(1.2) rotate(-45deg); opacity: 0; } }
@keyframes enemyStagger { 0% { transform: translateX(0); filter: brightness(1); } 20% { transform: translateX(-10px); filter: brightness(2) drop-shadow(0 0 10px white); } 40% { transform: translateX(10px); } 60% { transform: translateX(-10px); } 80% { transform: translateX(10px); } 100% { transform: translateX(0); } }

.fx-shake { animation: screenShake 0.4s; }
#damage-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 9999; display: none; }
.fx-flash { display: block !important; animation: flashRed 0.4s ease-out; }
#slash-fx { position: fixed; top: 40%; left: 50%; width: 400px; height: 12px; background: white; margin-left: -200px; box-shadow: 0 0 15px white, 0 0 30px var(--text); border-radius: 10px; pointer-events: none; z-index: 9999; display: none; transform-origin: center; }
.fx-slash-active { display: block !important; animation: slashAnim 0.25s ease-out forwards; }
.fx-enemy-stagger { display: inline-block; animation: enemyStagger 0.3s ease-out; }
/* --- ENEMY SPRITE ANIMATIONS --- */
@keyframes enemyBreathe {
    0%, 100% { transform: scale(1) translateY(0); filter: drop-shadow(0 5px 15px rgba(0,0,0,0.5)); }
    50% { transform: scale(1.03) translateY(-4px); filter: drop-shadow(0 10px 20px rgba(0,0,0,0.8)); }
}

.enemy-idle {
    animation: enemyBreathe 3s ease-in-out infinite;
    transform-origin: bottom center; /* Ensures the sprite stays planted on the floor when scaling */
}
/* --- RESPONSIVE LAYOUT ENGINE --- */

/* 1. Fluid Base Container */
#game-container {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-sizing: border-box;
}

/* 2. Fluid Typography */
body {
    font-size: clamp(17px, 4vw, 22px);
    padding: clamp(6px, 2vw, 20px);
}

h2 { font-size: clamp(1.3em, 5vw, 1.8em); }
h3 { font-size: clamp(1.1em, 4vw, 1.4em); }

/* 3. Header Stats Grid */
header > div {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 6px !important;
    text-align: center;
}

/* --- TABLETS & SMALL LAPTOPS (<= 768px) --- */
@media (max-width: 768px) {
    .shop-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        max-height: 320px;
    }

    #log-container {
        height: 180px;
        padding: 10px;
    }
}

/* --- MOBILE PHONES (<= 480px) --- */
@media (max-width: 480px) {
    /* Prevent utility/inline buttons from expanding to 100% */
    .shop-grid-item button,
    .inv-item button,
    #screen-lab button[onclick*="Page"],
    #screen-shop button[onclick*="Page"],
    #screen-shop button[onclick*="setShopFilter"],
    #screen-lab button[onclick*="setLabFilter"] {
        width: auto !important;
        padding: 4px 6px !important;
        font-size: 0.8em !important;
    }

    /* Single-column on very narrow phones */
    .shop-grid {
        grid-template-columns: 1fr;
        max-height: 280px;
    }

    /* Combat controls turn into touch-friendly stacks */
    .combat-row select {
        width: 100% !important;
    }

    .combat-row button {
        flex: 1 1 30%;
        min-width: 90px;
        padding: 10px 6px;
    }

    #enemy-sprite {
        height: 130px;
    }

    /* Floating combat text scales down */
    .fct {
        font-size: 26px;
    }
    .fct-crit {
        font-size: 32px;
    }
}
/* --- FOREST ANIMATIONS --- */
body.theme-forest::before {
    content: '';
    position: fixed;
    top: 0; left: 0; width: 200vw; height: 100vh;
    background: repeating-linear-gradient(to right, transparent 0%, rgba(123, 237, 159, 0.03) 10%, transparent 20%);
    filter: blur(8px);
    animation: mistDrift 40s linear infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes mistDrift {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}
/* Wood-textured, tinted glass panels */
body.theme-forest .panel {
    background-color: rgba(15, 20, 15, 0.85); 
    border: 6px ridge #4e342e; /* Rough wood border */
    border-radius: 4px;
    box-shadow: inset 0 0 40px #000, 0 10px 20px rgba(0,0,0,0.9);
    position: relative;
}

/* Organic moss clusters hanging off the corners using box-shadow blobs */
body.theme-forest .panel::before,
body.theme-forest .panel::after {
    content: '';
    position: absolute;
    background: #2e4a23;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10;
}

/* Top-left moss */
body.theme-forest .panel::before {
    top: -8px; left: -8px;
    width: 30px; height: 20px;
    box-shadow: 20px -2px 0 -2px #3a5f2b, 10px 15px 0 -4px #1e3317, 35px 5px 0 -5px #2e4a23;
}

/* Bottom-right moss */
body.theme-forest .panel::after {
    bottom: -6px; right: -6px;
    width: 40px; height: 25px;
    box-shadow: -20px 2px 0 -3px #3a5f2b, -15px -10px 0 -5px #1e3317, -40px -2px 0 -6px #2e4a23;
}

/* Horizontal woody dividers for the combat rows */
body.theme-forest .combat-row {
    border-bottom: 4px groove #4e342e;
    padding: 20px 0;
    position: relative;
}
body.theme-forest .combat-row:last-child {
    border-bottom: none;
}
/* --- GLOBAL CRT OVERLAY --- */
body::after {
    content: " ";
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: 
        linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.15) 50%), 
        radial-gradient(circle at center, transparent 60%, rgba(0,0,0,0.6) 100%);
    background-size: 100% 4px, 100% 100%;
    pointer-events: none;
    z-index: 9999;
}
/* --- THEME: PLANES OF SECUNDA --- */
body.theme-planes {
    background-color: #1a120c;
    background-image: 
        linear-gradient(to bottom, #2b1d11 0%, #1a120c 60%, #0d0906 100%),
        repeating-linear-gradient(90deg, rgba(200, 150, 50, 0.02) 0px, transparent 2px, transparent 30px);
    background-attachment: fixed;
}

/* Diagonal Wind/Dust Animation */
body.theme-planes::before {
    content: '';
    position: fixed;
    top: -50vh; left: 0; width: 200vw; height: 200vh;
    background-image: radial-gradient(circle at center, rgba(210, 160, 80, 0.15) 1px, transparent 2px);
    background-size: 70px 50px;
    animation: windSweep 12s linear infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes windSweep {
    0% { transform: translate(0, 0); }
    100% { transform: translate(-50%, 25%); }
}

/* Weathered Bone/Stone Panels */
body.theme-planes .panel {
    background-color: rgba(25, 18, 15, 0.85); 
    border: 6px ridge #8b7355; 
    border-radius: 2px;
    box-shadow: inset 0 0 40px #000, 0 10px 20px rgba(0,0,0,0.9);
    position: relative;
}
/* --- FLOATING COMBAT TEXT --- */
@keyframes floatCombatText {
    0% { opacity: 1; transform: translate(-50%, 0) scale(0.5); }
    20% { transform: translate(-50%, -20px) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -60px) scale(1); }
}
.fct-crit { 
    color: #ffa502; 
    font-size: 44px; 
    text-shadow: 0 0 8px rgba(255, 165, 2, 0.8), 2px 2px 0 #000, -2px -2px 0 #000; 
}

.fct {
    position: fixed;
    font-family: 'VT323', monospace;
    font-size: 36px;
    font-weight: bold;
    pointer-events: none;
    z-index: 10000;
    animation: floatCombatText 1s ease-out forwards;
    text-shadow: 2px 2px 0px #000, -2px -2px 0px #000, 2px -2px 0px #000, -2px 2px 0px #000;
}

.fct-dmg { color: #ff5252; }
.fct-miss { color: #dcd0c0; }
.fct-dmg { color: #ff5252; }
.fct-miss { color: #dcd0c0; }
.fct-crit { color: #ffa502; font-size: 44px; text-shadow: 0 0 8px rgba(255, 165, 2, 0.8), 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000; }
.fct-poison { color: #2ed573; text-shadow: 0 0 8px rgba(46, 213, 115, 0.8), 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000; }
.fct-burn { color: #e67e22; text-shadow: 0 0 8px rgba(230, 126, 34, 0.8), 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000; }
.fct-heal { color: #7bed9f; text-shadow: 0 0 8px rgba(123, 237, 159, 0.8), 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000; }

/* Dust and sediment clustered on the panel edges */
body.theme-planes .panel::before,
body.theme-planes .panel::after {
    content: '';
    position: absolute;
    background: #5c452e;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10;
}

/* Top-right sediment */
body.theme-planes .panel::before {
    top: -6px; right: -6px;
    width: 35px; height: 15px;
    box-shadow: -15px 5px 0 -2px #8b7355, -25px 2px 0 -4px #4a3b2c;
}

/* Bottom-left sediment */
body.theme-planes .panel::after {
    bottom: -6px; left: -6px;
    width: 45px; height: 20px;
    box-shadow: 20px -3px 0 -3px #8b7355, 35px -5px 0 -5px #3a2b1f;
}

/* Stone dividers for combat rows */
body.theme-planes .combat-row {
    border-bottom: 4px groove #8b7355;
    padding: 20px 0;
    position: relative;
}
body.theme-planes .combat-row:last-child {
    border-bottom: none;
}
/* --- COMBAT TENSION PULSE --- */
@keyframes panelBreathe {
    0%, 100% { box-shadow: inset 0 0 20px black, 0 5px 15px rgba(0,0,0,0.8); }
    50% { box-shadow: inset 0 0 30px rgba(138, 3, 3, 0.2), 0 5px 25px rgba(138, 3, 3, 0.4); }
}

@keyframes textPulse {
    0%, 100% { text-shadow: 0 0 2px rgba(255, 82, 82, 0.4); }
    50% { text-shadow: 0 0 12px rgba(255, 82, 82, 0.9); }
}

#screen-combat .panel {
    animation: panelBreathe 4s ease-in-out infinite;
}

#enemy-hp {
    animation: textPulse 2s ease-in-out infinite;
}
/* --- TOWN ATMOSPHERE THEMES --- */

/* Prima: Warm, cozy firelight radiating from the bottom */
body.town-0 {
    background: radial-gradient(circle at 50% 100%, #2c1609 0%, #050505 80%);
}

/* Secunda: Frosty, high-altitude blue with static snow particles */
body.town-1 {
    background: linear-gradient(to bottom, #09121c, #050505);
}
body.town-1::before {
    content: ''; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background-image: radial-gradient(#fff 1px, transparent 1px);
    background-size: 40px 40px; opacity: 0.1; pointer-events: none; z-index: 0;
}

/* Tertia: Deep coastal teal with a damp, dark horizon */
body.town-2 {
    background: radial-gradient(ellipse at top, #0a1f29, #050505);
}

/* Quartus: Underwater pressure with faint caustics */
body.town-3 {
    background: radial-gradient(circle at center, #001224, #00040a);
}
body.town-3::after {
    content: ''; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: repeating-linear-gradient(45deg, transparent, transparent 20px, rgba(10, 189, 227, 0.03) 20px, rgba(10, 189, 227, 0.03) 40px);
    pointer-events: none; z-index: 0;
}

/* Quintum: Salvaged tech grid and dull steel */
body.town-4 {
    background: linear-gradient(to bottom, #111, #050505);
}
body.town-4::before {
    content: ''; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background-image: linear-gradient(rgba(251, 197, 49, 0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(251, 197, 49, 0.05) 1px, transparent 1px);
    background-size: 30px 30px; pointer-events: none; z-index: 0;
}

/* Magma Bastion: Searing volcanic glow */
body.town-5 {
    background: radial-gradient(circle at 50% 120%, #4a0e00, #050505 70%);
}
#enemy-sprite {
    image-rendering: pixelated; 
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    border-radius: 4px;
}
/* --- SHOP COMPACT GRID --- */
.shop-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-height: 400px;
    overflow-y: auto;
    padding: 5px;
}

.shop-grid-item {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px;
    text-align: left;
    gap: 8px;
    box-sizing: border-box;
}

@media (max-width: 700px) {
    .shop-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
/* --- WEATHER OVERLAYS --- */
#weather-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    pointer-events: none; /* Prevents interference with clicking buttons */
    z-index: 8000; /* Sits above the UI, but below the damage/slash effects */
    display: none;
    opacity: 0.6;
}

/* Acid Rain: Fast, steep vertical streaks */
.weather-acid_rain {
    display: block !important;
    background: repeating-linear-gradient(170deg, rgba(46, 213, 115, 0.1) 0px, transparent 2px, transparent 20px);
    background-size: 100% 200%;
    animation: fallRain 0.3s linear infinite;
}
@keyframes fallRain {
    0% { background-position: 0 0; }
    100% { background-position: -50px 100vh; }
}

/* Sandstorm: Fast horizontal sweeping noise */
.weather-sandstorm {
    display: block !important;
    background-image: radial-gradient(circle at center, rgba(225, 177, 44, 0.25) 1px, transparent 2px);
    background-size: 40px 30px;
    animation: blowSand 0.8s linear infinite;
    opacity: 0.8 !important;
}
@keyframes blowSand {
    0% { background-position: 0 0; }
    100% { background-position: -200px 50px; }
}

/* Blizzard: Fast diagonal swirling snow */
.weather-blizzard {
    display: block !important;
    background-image: radial-gradient(circle at center, rgba(255, 255, 255, 0.7) 2px, transparent 3px),
                      radial-gradient(circle at center, rgba(129, 236, 236, 0.4) 1px, transparent 2px);
    background-size: 60px 60px, 40px 40px;
    background-position: 0 0, 20px 20px;
    animation: snowStorm 1.2s linear infinite;
}
@keyframes snowStorm {
    0% { background-position: 0 0, 20px 20px; }
    100% { background-position: -80px 100vh, -40px 50vh; }
}