`).join('');
return `
${flashcardSet.title}
${cardsHtml}`;
};
pdfRenderContainer.innerHTML = type === 'results' ? buildResultsPdfHtml() : buildCardsPdfHtml();
html2canvas(pdfRenderContainer, { scale: 2, useCORS: true })
.then(canvas => {
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: 'a4' });
const imgData = canvas.toDataURL('image/png');
const pdfWidth = pdf.internal.pageSize.getWidth();
const ratio = canvas.width / canvas.height;
const pdfHeight = pdfWidth / ratio;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save(`${type === 'results' ? 'Study_Report' : 'Flashcards'}_${flashcardSet.title.replace(/\s+/g, '_')}.pdf`);
});
};
// --- Initial Load ---
switchToTab('create');
});