<?php elseif ($view === 'quiz'): ?>
<!-- ═══════════════════════════════════════ QUIZ VIEW ══════════════════════ -->
<div class="ep-read-wrap">
  <div class="ep-breadcrumb">
    <a href="/events.php">← All Events</a>
    <span class="ep-crumb-sep">/</span>
    <a href="/events.php?id=<?= $event['id'] ?>&view=read"><?= htmlspecialchars($event['title']) ?></a>
    <span class="ep-crumb-sep">/</span>
    <span>Quiz</span>
  </div>

  <div class="quiz-wrap" id="quizWrap">
    <div class="quiz-header">
      <h2 class="quiz-title">📝 <?= htmlspecialchars($event['title']) ?></h2>
      <p class="quiz-subtitle"><?= count($questions) ?> questions &mdash; answer all to see your result</p>
      <?php if ($bestScore): ?>
      <div class="quiz-best-badge">Your best: <?= $bestScore['score'] ?>/<?= $bestScore['total'] ?> (<?= round($bestScore['score']/$bestScore['total']*100) ?>%)</div>
      <?php endif; ?>
    </div>

    <form class="quiz-form" id="quizForm">
      <?php foreach ($questions as $i => $q): ?>
      <div class="quiz-question-block" id="qblock_<?= $q['id'] ?>">
        <div class="quiz-q-num">Q<?= $i+1 ?></div>
        <p class="quiz-q-text"><?= htmlspecialchars($q['question']) ?></p>
        <div class="quiz-options">
          <?php foreach (['a','b','c','d'] as $opt): ?>
          <label class="quiz-option" data-qid="<?= $q['id'] ?>" data-opt="<?= $opt ?>">
            <input type="radio" name="q_<?= $q['id'] ?>" value="<?= $opt ?>">
            <span class="quiz-opt-letter"><?= strtoupper($opt) ?></span>
            <span class="quiz-opt-text"><?= htmlspecialchars($q["option_$opt"]) ?></span>
          </label>
          <?php endforeach; ?>
        </div>
        <div class="quiz-feedback" id="feedback_<?= $q['id'] ?>" style="display:none;"></div>
      </div>
      <?php endforeach; ?>

      <div class="quiz-submit-row">
        <button type="button" class="btn-quiz-submit" id="btnSubmit" onclick="submitQuiz()">
          Submit Answers
        </button>
        <span class="quiz-answered-count" id="answeredCount">0 / <?= count($questions) ?> answered</span>
      </div>
    </form>

    <!-- Results panel (hidden until submitted) -->
    <div class="quiz-results-panel" id="quizResults" style="display:none;">
      <div class="quiz-score-circle" id="scoreCircle"></div>
      <h3 class="quiz-result-label" id="resultLabel"></h3>
      <p class="quiz-result-msg" id="resultMsg"></p>
      <div class="quiz-result-actions">
        <a href="/events.php?id=<?= $event['id'] ?>&view=read" class="btn-secondary">← Back to Reading</a>
        <button class="btn-quiz-retry" onclick="retryQuiz()">Try Again</button>
        <a href="/events.php" class="btn-secondary">All Events</a>
      </div>
    </div>
  </div>
</div>

<script>
const QUIZ_TYPE    = 'event';
