10:$view    = $_GET['view'] ?? 'list';   // list | read | quiz
18:if ($eventId > 0 && in_array($view, ['read','quiz'])) {
24:    if ($view === 'quiz') {
25:        $stmt = $db->prepare('SELECT * FROM quiz_questions WHERE entity_type = ? AND entity_id = ? ORDER BY sort_order');
31:// Best quiz result for this event
34:    $stmt = $db->prepare('SELECT score, total FROM quiz_results WHERE user_id = ? AND entity_type = ? AND entity_id = ? ORDER BY score DESC LIMIT 1');
39:// Best scores for list view
41:$stmt = $db->prepare('SELECT entity_id, MAX(score) as best_score, MAX(total) as total FROM quiz_results WHERE user_id = ? AND entity_type = ? GROUP BY entity_id');
54:    <p class="ep-header-sub">Explore the defining moments of the New Testament — read each account in depth, then test your knowledge with a quiz.</p>
62:    $pct    = $best ? round($best['best_score'] / $best['total'] * 100) : null;
74:        <div class="ep-badge <?= $badgeClass ?>" title="Best quiz score"><?= $pct ?>%</div>
84:        <span class="ep-card-retake">Retake quiz</span>
125:    <div class="ep-prev-score">
126:      <span>🏆 Your best score: <strong><?= $bestScore['score'] ?>/<?= $bestScore['total'] ?></strong> (<?= round($bestScore['score']/$bestScore['total']*100) ?>%)</span>
132:      <a href="/events.php?id=<?= $event['id'] ?>&view=quiz" class="btn-cta-quiz">
139:<?php elseif ($view === 'quiz'): ?>
150:  <div class="quiz-wrap" id="quizWrap">
151:    <div class="quiz-header">
152:      <h2 class="quiz-title">📝 <?= htmlspecialchars($event['title']) ?></h2>
153:      <p class="quiz-subtitle"><?= count($questions) ?> questions &mdash; answer all to see your result</p>
155:      <div class="quiz-best-badge">Your best: <?= $bestScore['score'] ?>/<?= $bestScore['total'] ?> (<?= round($bestScore['score']/$bestScore['total']*100) ?>%)</div>
159:    <form class="quiz-form" id="quizForm">
161:      <div class="quiz-question-block" id="qblock_<?= $q['id'] ?>">
162:        <div class="quiz-q-num">Q<?= $i+1 ?></div>
163:        <p class="quiz-q-text"><?= htmlspecialchars($q['question']) ?></p>
164:        <div class="quiz-options">
166:          <label class="quiz-option" data-qid="<?= $q['id'] ?>" data-opt="<?= $opt ?>">
168:            <span class="quiz-opt-letter"><?= strtoupper($opt) ?></span>
169:            <span class="quiz-opt-text"><?= htmlspecialchars($q["option_$opt"]) ?></span>
173:        <div class="quiz-feedback" id="feedback_<?= $q['id'] ?>" style="display:none;"></div>
177:      <div class="quiz-submit-row">
178:        <button type="button" class="btn-quiz-submit" id="btnSubmit" onclick="submitQuiz()">
181:        <span class="quiz-answered-count" id="answeredCount">0 / <?= count($questions) ?> answered</span>
185:    <!-- Results panel (hidden until submitted) -->
186:    <div class="quiz-results-panel" id="quizResults" style="display:none;">
187:      <div class="quiz-score-circle" id="scoreCircle"></div>
188:      <h3 class="quiz-result-label" id="resultLabel"></h3>
189:      <p class="quiz-result-msg" id="resultMsg"></p>
190:      <div class="quiz-result-actions">
192:        <button class="btn-quiz-retry" onclick="retryQuiz()">Try Again</button>
