`;
verbGrid.appendChild(card);
});
}
function filterVerbs(cat) {
currentFilter = cat;
document.querySelectorAll('.category-btn').forEach(b => {
b.classList.remove('active');
if(b.innerText.toLowerCase().includes(cat.toLowerCase()) || (cat==='All' && b.innerText==='ALL VERBS')) b.classList.add('active');
});
renderVerbs(cat, searchInput.value);
}
searchInput.addEventListener('input', () => renderVerbs(currentFilter, searchInput.value));
let quizState = { active: false, q: [], idx: 0, score: 0 };
function startQuiz() {
const shuffled = [...VERB_DATA].sort(() => 0.5 - Math.random());
quizState = { active: true, q: shuffled.slice(0, 10), idx: 0, score: 0 };
document.getElementById('quizIntro').classList.add('hidden');
document.getElementById('quizResult').classList.add('hidden');
document.getElementById('quizContainer').classList.remove('hidden');
showQuestion();
}
function showQuestion() {
const current = quizState.q[quizState.idx];
const target = Math.random() > 0.5 ? 'V2' : 'V3';
const answer = target === 'V2' ? current.v2 : current.v3;
document.getElementById('questionProgress').innerText = `Question ${quizState.idx + 1}/10`;
document.getElementById('quizScore').innerText = `Score: ${quizState.score}`;
document.getElementById('questionText').innerHTML = `
Find the ${target} form of
"${current.v1}"?
(${current.meanings[0]})
`;
const distractors = VERB_DATA
.filter(v => v.v1 !== current.v1)
.map(v => target === 'V2' ? v.v2 : v.v3)
.filter((v, i, a) => a.indexOf(v) === i)
.sort(() => 0.5 - Math.random())
.slice(0, 3);
const options = [...distractors, answer].sort(() => 0.5 - Math.random());
const optionsBox = document.getElementById('quizOptions');
optionsBox.innerHTML = '';
options.forEach(opt => {
const btn = document.createElement('button');
btn.className = 'p-5 rounded-2xl bg-white border border-slate-200 text-lg font-bold text-slate-700 hover:border-indigo-400 hover:bg-indigo-50 transition-all text-left shadow-sm min-w-0 break-words';
btn.innerText = opt;
btn.onclick = () => checkAnswer(opt, answer, btn);
optionsBox.appendChild(btn);
});
}
function checkAnswer(choice, correct, btn) {
const buttons = document.querySelectorAll('#quizOptions button');
buttons.forEach(b => b.disabled = true);
if(choice === correct) {
btn.classList.add('bg-teal-500', 'text-white', 'border-teal-500');
quizState.score += 10;
} else {
btn.classList.add('bg-rose-500', 'text-white', 'border-rose-500');
buttons.forEach(b => {
if(b.innerText === correct) b.classList.add('bg-teal-50', 'text-teal-700', 'border-teal-400');
});
}
setTimeout(() => {
quizState.idx++;
if(quizState.idx < 10) showQuestion();
else endQuiz();
}, 1200);
}
function endQuiz() {
document.getElementById('quizContainer').classList.add('hidden');
document.getElementById('quizResult').classList.remove('hidden');
document.getElementById('finalScore').innerText = `${quizState.score}%`;
let feedback = quizState.score >= 80 ? "চমৎকার! আপনি ভার্ব মাস্টার!" :
quizState.score >= 50 ? "ভালো হয়েছে! আরো প্র্যাকটিস করুন।" : "আবার চেষ্টা করুন, আপনি পারবেন!";
document.getElementById('resultFeedback').innerText = feedback;
}
function resetQuiz() {
document.getElementById('quizResult').classList.add('hidden');
document.getElementById('quizIntro').classList.remove('hidden');
}
function init() {
renderVerbs();
window.initialized = true;
}
document.addEventListener('DOMContentLoaded', init);
setTimeout(() => { if(!window.initialized) init(); }, 1500);