@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Roboto:wght@400;700&display=swap');

body {
    margin: 0;
    overflow: hidden;
    background-color: #05140a;
    font-family: 'Roboto', sans-serif;
    touch-action: none;
    
    background: linear-gradient(135deg, #05140a, #0a2e36, #062111, #0f3d3e);
    background-size: 400% 400%;
    animation: gradientBG 20s ease infinite;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

#game-container { position: relative; width: 100vw; height: 100dvh; }

#ui-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; display: none;
    flex-direction: column; justify-content: space-between;
    padding: 20px; box-sizing: border-box;
    z-index: 150;
}

/* --- HP BARS LAYER --- */
#hp-bars-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 50;
}
.hp-bar-container {
    position: absolute; width: 28px; height: 4px;
    background: #222; border: 1px solid #000;
    transform: translate(-50%, -45px); 
    pointer-events: none; display: none; 
}
.hp-fill { height: 100%; background: #ff0000; width: 100%; transition: width 0.2s; }

.status-indicator {
    position: absolute; top: -8px; width: 6px; height: 6px; border-radius: 50%;
    border: 1px solid #000;
}
.status-poison { background: #9c27b0; left: 0; }
.status-burn { background: #ff5722; right: 0; }

/* --- MENUS --- */
#start-screen, #options-menu, #pause-menu {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 200;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    transition: opacity 0.5s;
    pointer-events: auto; /* Ensure layers are clickable */
}

#options-menu, #pause-menu { display: none; z-index: 210; background: rgba(10, 20, 30, 0.95); }

.title-text {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(2rem, 5vw, 4rem);
    color: #ffd700; text-align: center;
    line-height: 1.5; margin-bottom: 40px;
    text-shadow: 4px 4px 0px #b71c1c, 8px 8px 0px #000;
    animation: floatTitle 3s ease-in-out infinite;
}
@keyframes floatTitle { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-15px); } }

.menu-buttons { 
    display: flex; flex-direction: column; gap: 15px; 
    pointer-events: auto; /* Fix for unclickable buttons */
}

#play-btn, #options-back-btn, #restart-btn, #resume-btn {
    background: #2e7d32; color: white; border: none;
    padding: 15px 50px; font-size: 1.2rem;
    border-radius: 4px; box-shadow: 0 6px 0 #003300;
    cursor: pointer; text-transform: uppercase;
    font-family: 'Press Start 2P', cursive;
    transition: transform 0.1s; pointer-events: auto;
}
#play-btn:active, #options-back-btn:active, #restart-btn:active, #resume-btn:active {
    transform: translateY(4px); box-shadow: 0 2px 0 #003300;
}

.secondary-btn {
    background: #455a64; color: #fff;
    border: none; padding: 12px 30px;
    font-size: 0.8rem; border-radius: 4px;
    box-shadow: 0 4px 0 #263238; cursor: pointer;
    text-transform: uppercase; font-family: 'Press Start 2P', cursive;
    pointer-events: auto;
}
.secondary-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #263238; }

/* --- OPTIONS STYLES --- */
.opt-scroll-container {
    max-height: 60vh; overflow-y: auto; 
    width: 100%; display: flex; flex-direction: column; align-items: center;
    padding: 10px 0;
}
.opt-scroll-container::-webkit-scrollbar { width: 8px; }
.opt-scroll-container::-webkit-scrollbar-track { background: #111; }
.opt-scroll-container::-webkit-scrollbar-thumb { background: #444; border-radius: 4px; }

.menu-title { font-family: 'Press Start 2P'; color: #ffd700; margin-bottom: 20px; text-shadow: 2px 2px 0 #000; }
.opt-group { margin-bottom: 20px; text-align: center; width: 100%; }
.opt-group label {
    display: block; font-family: 'Press Start 2P'; font-size: 0.6rem;
    color: #81d4fa; margin-bottom: 8px;
}
.toggle-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.opt-toggle {
    background: #333; color: #888; border: 2px solid #555;
    padding: 8px 12px; font-family: 'Press Start 2P'; font-size: 0.55rem;
    cursor: pointer; min-width: 40px;
}
.opt-toggle.selected {
    background: #ffd700; color: #000; border-color: #fff;
    box-shadow: 0 0 10px #ffd700;
}

/* --- HUD & TUTORIAL --- */
#tutorial-popup {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%); width: 85%; max-width: 450px;
    background: rgba(10, 25, 35, 0.98); border: 2px solid #4fc3f7;
    border-radius: 8px; padding: 25px;
    color: #fff; font-family: 'Roboto', sans-serif;
    z-index: 150; display: none; box-shadow: 0 10px 40px rgba(0,0,0,0.9);
    pointer-events: auto; text-align: center;
}
#tut-close-x {
    position: absolute; top: 10px; right: 15px;
    font-family: 'Press Start 2P', cursive; color: #ff5252;
    font-size: 1.2rem; cursor: pointer; text-shadow: 2px 2px 0 #000;
}
#tut-close-x:hover { color: #ff0000; }

#tut-title {
    color: #ffd700; font-family: 'Press Start 2P', cursive;
    font-size: 1.0rem; margin-bottom: 15px; display: block;
    text-shadow: 2px 2px 0 #000;
}
#tut-content { font-size: 0.95rem; line-height: 1.6; margin-bottom: 20px; color: #e0e0e0; }
.recipe-list {
    text-align: left; background: rgba(0,0,0,0.3);
    padding: 10px; border-radius: 4px; margin: 10px 0;
    font-size: 0.85rem; font-family: monospace; border: 1px solid #333;
}
.recipe-item { margin-bottom: 5px; color: #81d4fa; }
#tut-btn {
    background: #4fc3f7; color: #000; border: none;
    padding: 12px 24px; font-weight: bold; cursor: pointer;
    border-radius: 4px; text-transform: uppercase;
    font-family: 'Press Start 2P', cursive; font-size: 0.7rem;
    box-shadow: 0 4px 0 #0277bd;
}
#tut-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #0277bd; }

#top-hud { display: flex; justify-content: space-between; width: 100%; align-items: center; }
.hud-center { display: flex; gap: 20px; }
.hud-left, .hud-right { width: 50px; display: flex; justify-content: center; }

.stat-box { text-align: center; font-family: 'Press Start 2P', cursive; text-shadow: 2px 2px 0 #000; }
.stat-label { font-size: 0.5rem; margin-bottom: 5px; color: #aaa; text-transform: uppercase; letter-spacing: 1px; display: block; }
.stat-value { font-size: 1.0rem; display: inline-block; padding: 5px 10px; background: rgba(0,0,0,0.5); border-radius: 4px; }
#wave-val { color: #ffd700; border-bottom: 2px solid #ffd700; }
#containment-val { color: #00e676; border-bottom: 2px solid #00e676; }
#hp-val { color: #ff5252; border-bottom: 2px solid #ff5252; }

#recipe-btn, #pause-btn {
    background: rgba(255, 255, 255, 0.2); border: 1px solid #fff;
    color: #fff; width: 30px; height: 30px; border-radius: 50%;
    font-family: 'Press Start 2P'; font-size: 12px;
    cursor: pointer; pointer-events: auto; display: flex; align-items: center; justify-content: center;
}
#pause-btn { font-size: 10px; letter-spacing: -1px; }

#bottom-hud {
    pointer-events: none; display: flex; flex-direction: column;
    align-items: center; width: 100%; 
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
#actions-counter {
    color: #fff; font-family: 'Press Start 2P', cursive; font-size: 0.6rem;
    text-shadow: 1px 1px 0 #000; background: rgba(0,0,0,0.6);
    padding: 4px 8px; border-radius: 4px; margin-bottom: 10px;
    pointer-events: auto; border: 1px solid #4fc3f7;
}
#message-area {
    margin-bottom: 10px; color: #fff; font-family: 'Roboto', sans-serif;
    font-weight: bold; font-size: 0.9rem; text-shadow: 1px 1px 2px black;
    opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
#hand-container { display: flex; gap: 10px; justify-content: center; margin-bottom: 15px; pointer-events: auto; }
.card {
    width: 60px; height: 80px; background: #f5f5f5; border-radius: 8px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    box-shadow: 0 5px 0 #888, 0 10px 10px rgba(0,0,0,0.3);
    cursor: pointer; transition: transform 0.1s, margin 0.1s;
    border: 2px solid #fff; position: relative; user-select: none; touch-action: none;
}
.card:active { transform: translateY(5px); box-shadow: 0 0 0 #888; }
.card.selected { transform: translateY(-15px); box-shadow: 0 15px 20px rgba(0,230,118,0.4); border: 2px solid #00e676; z-index: 5; }
.card-icon { font-size: 1.5rem; }
.card-label { font-size: 0.5rem; font-weight: bold; color: #333; margin-top: 4px; text-transform: uppercase; font-family: 'Press Start 2P', cursive; }
.card-wheat { background: #fff9c4; }
.card-iron { background: #cfd8dc; }
.card-wood { background: #d7ccc8; }
#end-turn-btn {
    background: #d32f2f; color: white; border: none; padding: 12px 30px;
    font-size: 0.8rem; border-radius: 4px; box-shadow: 0 4px 0 #7f0000;
    cursor: pointer; text-transform: uppercase; font-family: 'Press Start 2P', cursive;
    pointer-events: auto; transition: all 0.1s;
}
#end-turn-btn:active { transform: translateY(4px); box-shadow: 0 0 0 #7f0000; }
#end-turn-btn:disabled { background: #555; box-shadow: none; color: #888; cursor: not-allowed; }

/* --- MODAL --- */
#game-over-modal {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.9); display: none; flex-direction: column;
    align-items: center; justify-content: center; z-index: 100;
    color: white; pointer-events: auto;
}
.modal-content { text-align: center; }
#modal-title { font-size: 2rem; margin-bottom: 20px; text-shadow: 4px 4px 0 #000; font-family: 'Press Start 2P', cursive; }
#modal-score { font-family: 'Press Start 2P'; font-size: 0.7rem; line-height: 2; }
.victory-text { color: #ffd700; }
.defeat-text { color: #ff5252; }