—
—
—
—
'+p.eq+'
';});document.getElementById('sheet').innerHTML=html;document.getElementById('wrong-panel').style.display='none';resetMetrics();} function liveCheck(inp){ const v=inp.value.trim(),d=document.getElementById('d-'+inp.id); const correct=parseFloat(v)===inp.dataset.ans*1; const prevState=inp.dataset.state||'empty'; if(!v){ inp.className='ai';d.className='prob'; inp.dataset.state='empty';inp.dataset.checked='0'; } else if(correct){ inp.className='ai correct';d.className='prob correct'; if(prevState!=='correct'){ inp.dataset.state='correct'; streak++;addXP(5+(streak>=5?2:0)); playSound('correct'); if(streak===5)showToast('5 in a row! Bonus XP!','good'); else if(streak===10)showToast('10 streak! On fire!','good'); inp.dataset.checked='1'; } } else { inp.className='ai wrong';d.className='prob wrong'; if(prevState==='correct'){ streak=0;addXP(-1); inp.dataset.state='wrong';inp.dataset.checked='1'; } else if(prevState==='empty'){ inp.dataset.state='typing'; } } updateMetrics(); } function finalCheck(inp){ const v=inp.value.trim(); if(!v)return; const correct=parseFloat(v)===inp.dataset.ans*1; const state=inp.dataset.state||'typing'; if(!correct && state==='typing'){ playSound('wrong'); streak=0;addXP(-1); inp.dataset.state='wrong';inp.dataset.checked='1'; inp.className='ai wrong'; document.getElementById('d-'+inp.id).className='prob wrong'; updateMetrics(); } } function updateMetrics(){const ins=document.querySelectorAll('.ai');let att=0,cor=0,wrg=0;const os={add:{c:0,t:0},sub:{c:0,t:0},mul:{c:0,t:0},div:{c:0,t:0}};ins.forEach(function(inp){const v=inp.value.trim(),op=inp.dataset.op;if(!v)return;att++;if(op)os[op].t++;if(parseFloat(v)===inp.dataset.ans*1){cor++;if(op)os[op].c++;}else wrg++;});document.getElementById('m-att').textContent=att;document.getElementById('m-cor').textContent=cor;document.getElementById('m-wrg').textContent=wrg;document.getElementById('m-str').textContent=streak;document.getElementById('m-pct').textContent=att?Math.round(cor/att*100)+'%':'—';['add','sub','mul','div'].forEach(function(op){const c=os[op].c,t=os[op].t,pct=t?Math.round(c/t*100):0;const bar=document.getElementById('pb-'+op),lbl=document.getElementById('pp-'+op);if(bar)bar.style.width=(t?pct:0)+'%';if(lbl)lbl.textContent=t?pct+'%':'—';});} function resetMetrics(){['m-att','m-cor','m-wrg','m-str'].forEach(function(id){document.getElementById(id).textContent='0';});document.getElementById('m-pct').textContent='—';['add','sub','mul','div'].forEach(function(op){const b=document.getElementById('pb-'+op),l=document.getElementById('pp-'+op);if(b)b.style.width='0%';if(l)l.textContent='—';});} function nx(e,id){if(e.key==='Enter'||e.key==='Tab'){e.preventDefault();const ins=Array.from(document.querySelectorAll('.ai'));const i=ins.findIndex(function(x){return x.id===id;});if(i
';});html+='
';panel.innerHTML=html;panel.style.display='block';}
function revealAll(){document.querySelectorAll('.ai').forEach(function(inp){if(!inp.value.trim())document.getElementById('r-'+inp.id).textContent=inp.dataset.ans;});}
function showOp(op,btn){document.querySelectorAll('.pill-row .pill').forEach(function(p){if(['all','+','−','×','÷'].includes(p.textContent.trim()))p.classList.remove('p-active');});btn.classList.add('p-active');render(op);}
function setDiff(d,btn){document.querySelectorAll('.pill.d1,.pill.d2,.pill.d3').forEach(function(p){p.classList.remove('p-active');});btn.classList.add('p-active');curDiff=d;generate();render(curOp);}
function regen(){generate();render(curOp);resetTimer();}
function toggleSound(btn){soundOn=!soundOn;btn.innerHTML=' sound';}
generate();render('all');