`;
showModal(html);
overlay.querySelectorAll(".tech[data-t]").forEach(el=>{el.onclick=()=>{const tk=el.getAttribute("data-t"),T=TECH[tk];if(pl.tech.has(tk))return;if(T.pre&&!pl.tech.has(T.pre)){toast("Research "+TECH[T.pre].name+" first.");return;}if(pl.stars{u.maxhp+=1;u.hp+=1;});closeModal();openTech();updateHUD();draw();toast(`Learned ${T.name}!`);};});
}
/* ================= HUD ================= */
function updateHUD(){
if(!G)return;const pl=G.players[HUMAN];
$("#tribeName").textContent=pl.tribe.name;
$("#cTribe").querySelector(".ico").textContent=pl.tribe.emo;
$("#starN").textContent=pl.stars;
$("#starInc").textContent="+"+totalIncome(HUMAN);
$("#cityN").textContent=countCities(HUMAN);
}
/* ================= TOAST / MODAL ================= */
let toastTimer=null;
function toast(m){const el=$("#toast");el.textContent=m;el.classList.add("show");clearTimeout(toastTimer);toastTimer=setTimeout(()=>el.classList.remove("show"),1700);}
function showModal(html){overlay.innerHTML=`
${html}
`;overlay.style.display="block";}
function closeModal(){overlay.style.display="none";overlay.innerHTML="";}
/* ================= START / HELP ================= */
function showStart(){
closeModal();
const picks=TRIBES.map(t=>`
${t.emo}
${t.name}
${t.blurb}
`).join("");
showModal(`
MARATOPIA
A Polytopia-style strategy game by Marathon Handbook. Grow your running empire, train units, research training, and conquer the map.
Choose your tribe
${picks}
Map size
Small
Quick game
Medium
Balanced
Large
Epic
⚔️ Attack🛡️ Defense👟 Move🎯 Range⭐ Stars
Tap a unit → tap a glowing tile to move, red tile to attack. Tap your city to train. Capture every enemy city to win.
`);
overlay.querySelector('.card').dataset.lock="1";
let chosen=null,size=9;
overlay.querySelectorAll("#tribeRow .pick").forEach(p=>p.onclick=()=>{overlay.querySelectorAll("#tribeRow .pick").forEach(x=>x.classList.remove("sel"));p.classList.add("sel");chosen=p.getAttribute("data-tribe");const b=$("#startBtn");b.disabled=false;b.textContent="Start Game ▶";});
overlay.querySelectorAll("#sizeRow .pick").forEach(p=>p.onclick=()=>{overlay.querySelectorAll("#sizeRow .pick").forEach(x=>x.classList.remove("sel"));p.classList.add("sel");size=+p.getAttribute("data-size");});
$("#startBtn").onclick=()=>{if(!chosen)return;MAP=size;closeModal();newGame(chosen);toast("Your empire begins!");};
}
function showHelp(){showModal(`
How to play
Goal: Capture every enemy city, or hold the top score by turn 30.
⭐ Stars are your currency. Cities produce stars each turn — spend them to train units, upgrade cities, and research training.
Move & fight: Tap a unit, then tap a glowing tile to move or a red tile to attack. Units heal in your own territory.
Cities: Tap your city to train or upgrade. Move onto a village or enemy city to capture it.
Terrain: Forests 🌲 and hills ⛰️ boost defense; mountains 🏔️ need Hill Training but grant great vision & defense.