
:root {
    --bg-color: #1a1a2e;
    --text-color: #e94560;
    --grid-bg: #16213e;
    --tile-size: min(10vw, 40px);
    --p1-color: #4cc9f0;
    --p2-color: #f72585;
    --p3-color: #fee440;
    --p4-color: #9b5de5;
}

* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; -webkit-tap-highlight-color: transparent; }
body { background: var(--bg-color); color: #fff; font-family: sans-serif; height: 100vh; height: 100dvh; overflow: hidden; }

.screen { display: none; height: 100%; flex-direction: column; align-items: center; justify-content: center; padding: 20px; }
.screen.active { display: flex; }

/* Menu */
h1 { font-size: 3rem; color: var(--text-color); margin-bottom: 2rem; letter-spacing: 5px; }
.menu-buttons { display: flex; flex-direction: column; gap: 15px; width: 100%; max-width: 300px; }
button { padding: 15px; border: none; border-radius: 8px; font-weight: bold; cursor: pointer; background: #fff; color: #000; font-size: 1rem; transition: transform 0.1s; }
button:active { transform: scale(0.95); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
input { padding: 15px; border-radius: 8px; border: 1px solid #ccc; text-align: center; font-size: 1rem; background: #eee; color: #000; }
.divider { text-align: center; color: #666; margin: 10px 0; font-size: 0.8rem; }
.error-msg { color: #ff4444; margin-top: 10px; min-height: 20px; text-align: center; }
.hidden { display: none !important; }
.highlight { color: var(--text-color); font-weight: bold; font-family: monospace; font-size: 1.5rem; }

/* Game Screen */
#game-screen { padding: 0; justify-content: space-between; }
.top-bar, .bottom-bar { width: 100%; background: #0f3460; padding: 10px; display: flex; z-index: 10; }
.top-bar { justify-content: space-between; align-items: center; box-shadow: 0 2px 5px rgba(0,0,0,0.5); }
.bottom-bar { flex-direction: column; gap: 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); box-shadow: 0 -2px 5px rgba(0,0,0,0.5); }

.resource-pill { background: #16213e; padding: 5px 10px; border-radius: 15px; font-weight: bold; font-size: 0.9rem; }
.gold { color: #ffd700; border: 1px solid #ffd700; }
.oil { color: #000; background: #aaa; border: 1px solid #fff; }

#board-container { 
    flex: 1; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    overflow: auto; 
    width: 100%; 
    background: #000;
    position: relative;
}

#game-grid {
    display: grid;
    gap: 1px;
    background: #333;
    border: 2px solid #555;
    /* Columns defined in JS */
}

.tile {
    width: var(--tile-size);
    height: var(--tile-size);
    background: var(--grid-bg);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    cursor: pointer;
}

/* Terrain & FOW */
.tile.fog { background: #050505 !important; cursor: default; }
.tile.fog * { display: none !important; } /* Hide contents in fog */
.tile.water { background: #1a4b77; }
.tile.resource { background: #2c3e50; }
.tile.resource::after { content: '💎'; font-size: 0.8em; position: absolute; bottom: 1px; right: 1px; opacity: 0.5; }

/* Units */
.unit {
    width: 100%; height: 100%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    position: absolute;
    z-index: 2;
    pointer-events: none; /* Let clicks pass to tile */
    transition: transform 0.2s;
    /* Add a drop shadow to lift them off the map */
    filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.5));
}

.unit.acted { opacity: 0.6; filter: grayscale(1); }

/* Unit Asset Mapping */
.unit.worker { background-image: url('assets/units/unit_worker.png'); }
.unit.soldier { background-image: url('assets/units/unit_soldier.png'); }
.unit.ground { background-image: url('assets/units/unit_ground.png'); }
.unit.air { background-image: url('assets/units/unit_air.png'); }
.unit.base { background-image: url('assets/units/unit_base.png'); }

/* Stack Badge (for workers) */
.stack-badge {
    position: absolute;
    bottom: 0;
    right: 0;
    background: #000;
    color: #fff;
    font-size: 0.6rem;
    padding: 1px 4px;
    border-radius: 4px;
    border: 1px solid #fff;
    z-index: 3;
}

/* Player Color Tinting */
/* Note: Hue rotate works because the base assets are Cyan/Blueish. */
/* P1: Cyan (No Change) */
.p-color-0 { 
    /* No filter needed for base color, but we keep drop-shadow if not acted */
} 
/* P2: Pink (Rotate ~140deg) */
.p-color-1 { filter: hue-rotate(140deg) drop-shadow(2px 4px 6px rgba(0,0,0,0.5)); }
.p-color-1.acted { filter: hue-rotate(140deg) grayscale(1); }

/* P3: Yellow (Rotate ~220deg) */
.p-color-2 { filter: hue-rotate(220deg) drop-shadow(2px 4px 6px rgba(0,0,0,0.5)); }
.p-color-2.acted { filter: hue-rotate(220deg) grayscale(1); }

/* P4: Purple (Rotate ~80deg) */
.p-color-3 { filter: hue-rotate(80deg) drop-shadow(2px 4px 6px rgba(0,0,0,0.5)); }
.p-color-3.acted { filter: hue-rotate(80deg) grayscale(1); }


/* Selection & Highlights */
.tile.selected { box-shadow: inset 0 0 0 2px #fff; background-color: rgba(255,255,255,0.1); }
.tile.highlight-move { background-color: rgba(76, 201, 240, 0.3); box-shadow: inset 0 0 5px #4cc9f0; }
.tile.highlight-attack { background-color: rgba(233, 69, 96, 0.3); box-shadow: inset 0 0 5px #e94560; }


/* Action Bar */
#status-line { text-align: center; font-size: 0.9rem; color: #ccc; margin-bottom: 5px; min-height: 1.2em; font-weight: bold; }
#action-bar { display: flex; gap: 5px; justify-content: center; }
.act-btn { padding: 10px; flex: 1; font-size: 0.8rem; background: #e94560; color: #fff; border: 2px solid transparent; }
.act-btn.active-mode { border-color: #fff; transform: translateY(-2px); box-shadow: 0 5px 10px rgba(0,0,0,0.3); }
.end-turn { background: #fca311; color: #000; }

/* Modal */
#modal-overlay { position: fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.8); z-index:100; display:flex; justify-content:center; align-items:center; }
.modal { background: #16213e; padding: 20px; border-radius: 10px; min-width: 250px; text-align: center; box-shadow: 0 10px 25px rgba(0,0,0,0.5); }
.modal h3 { color: #e94560; margin-bottom: 15px; }
.modal button { width: 100%; margin-bottom: 10px; border: 1px solid #444; background: #222; color: #fff; }
#modal-cancel { background: #333; color: #aaa; margin-top: 10px; }

@media (min-width: 768px) {
    --tile-size: 50px;
    .menu-buttons { max-width: 400px; }
}
