<!-- Paste everything below into ONE Elementor HTML widget -->
<style>
  :root{--bg:#0f1724;--card:#ffffff;--muted:#6b7280;--accent:#7c3aed;--accent-2:#ec4899}
  *{box-sizing:border-box}
  .quiz-wrapper{font-family:Inter,ui-sans-serif,system-ui,-apple-system,'Segoe UI',Roboto,'Helvetica Neue',Arial;color:#0b1220}
  .container{max-width:1100px;margin:32px auto;padding:18px}
  .card{background:var(--card);border-radius:14px;box-shadow:0 10px 30px rgba(2,6,23,.5);overflow:hidden}
  .header{padding:28px;text-align:center}
  .title{font-size:28px;color:var(--accent);margin:0}
  .subtitle{color:var(--muted);margin-top:6px}
  .instructions{padding:20px;border-left:4px solid #3b82f6;background:#eff6ff}
  .grid{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-top:12px}
  .btn{display:inline-flex;align-items:center;gap:8px;background:linear-gradient(90deg,var(--accent),var(--accent-2));color:#fff;padding:12px 18px;border-radius:10px;border:0;font-weight:700;cursor:pointer}
  .center{display:flex;justify-content:center}
  /* Quiz UI */
  .topbar{display:flex;justify-content:space-between;align-items:center;padding:12px 18px;border-bottom:1px solid #f1f5f9}
  .timer{font-weight:800;font-size:20px}
  .meta{color:var(--muted)}
  .main{display:flex;gap:20px;padding:22px}
  .left{flex:2}
  .right{flex:1}
  .question-card{background:#fff;padding:20px;border-radius:12px}
  .q-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:14px}
  .tags{display:flex;gap:8px;align-items:center}
  .tag{padding:6px 10px;border-radius:999px;font-weight:700;font-size:12px}
  .tag.topic{background:#f3e8ff;color:#6b21a8}
  .tag.easy{background:#ecfccb;color:#166534}
  .tag.medium{background:#fffbeb;color:#92400e}
  .tag.hard{background:#fff1f2;color:#9f1239}
  .question-text{font-size:17px;white-space:pre-line;margin-bottom:14px}
  .options{display:grid;gap:10px}
  .option{background:#f8fafc;border:1px solid #e6eef7;padding:14px;border-radius:10px;text-align:left;cursor:pointer;font-weight:600}
  .option.selected{background:#efe6ff;border-color:#c4b5fd}
  .option.correct{background:#ecfdf5;border-color:#34d399;color:#065f46}
  .option.wrong{background:#fff1f2;border-color:#fca5a5;color:#9b1c1c}
  .solution{margin-top:12px;background:linear-gradient(90deg,#eff6ff,#eef2ff);padding:12px;border-radius:8px;border:1px solid #dbeafe}
  .q-grid{display:grid;grid-template-columns:repeat(10,1fr);gap:8px;padding:14px;background:#fff;border-radius:12px}
  .qnum{height:44px;border-radius:8px;background:#e6eef7;display:flex;align-items:center;justify-content:center;font-weight:700;cursor:pointer}
  .qnum.current{background:linear-gradient(90deg,var(--accent),var(--accent-2));color:#fff}
  .qnum.correct{background:#10b981;color:#fff}
  .qnum.wrong{background:#ef4444;color:#fff}
  .qnum.marked{outline:3px solid #f59e0b}
  .navs{display:flex;gap:8px;margin-top:12px}
  .navs .btn.alt{background:#fff;color:#0b1220;border:1px solid #eef2ff}
  .scorebox{display:inline-block;padding:12px 18px;border-radius:40px;background:#fff;margin-top:8px}
  .results{padding:20px}
  .bar{height:12px;background:#f1f5f9;border-radius:999px;overflow:hidden}
  .bar > .inner{height:100%;background:linear-gradient(90deg,var(--accent),var(--accent-2))}
  pre{white-space:pre-wrap}
  @media (max-width:900px){.main{flex-direction:column}.q-grid{grid-template-columns:repeat(5,1fr)}.grid{grid-template-columns:1fr}}
</style>

<div class="quiz-wrapper">
  <div class="container">
    <!-- START SCREEN -->
    <div class="card" id="startCard">
      <div class="header">
        <h1 class="title">TS EAPCET Mathematics Quiz</h1>
        <div class="subtitle">Probability Chapter — 40 Questions</div>
      </div>

      <div style="padding:18px">
        <div class="instructions">
          <strong>Instructions</strong>
          <ul>
            <li>Total Questions: <strong>40</strong> (10 from each topic)</li>
            <li>Time Limit: <strong>60 minutes</strong></li>
            <li>Each question has 4 options (only one correct)</li>
            <li>You can mark questions for review</li>
            <li>Solutions are shown after answering each question</li>
            <li>Timer auto-submits when time runs out</li>
          </ul>
        </div>

        <div class="grid">
          <div style="background:#faf5ff;border-radius:10px;padding:12px">
            <h3 style="margin:0 0 8px 0;color:#5b21b6">Topics Covered</h3>
            <p style="margin:0;color:var(--muted)">• Probability Distribution (10Q)<br>• Binomial Distribution (10Q)<br>• Poisson Distribution (10Q)<br>• Applications (10Q)</p>
          </div>
          <div style="background:#f0fff4;border-radius:10px;padding:12px">
            <h3 style="margin:0 0 8px 0;color:#15803d">Question Format</h3>
            <p style="margin:0;color:var(--muted)">Real EAPCET questions with year, shift & difficulty. Detailed solutions included.</p>
          </div>
        </div>

        <div class="center" style="margin-top:18px">
          <button class="btn" id="startBtn">Start Exam</button>
        </div>
      </div>
    </div>

    <!-- QUIZ UI -->
    <div class="card" id="quizCard" style="display:none">
      <div class="topbar">
        <div style="display:flex;gap:18px;align-items:center">
          <div class="timer" id="timer">01:00:00</div>
          <div class="meta">Answered: <span id="answeredCount">0</span>/40</div>
          <div class="meta">Marked: <span id="markedCount">0</span></div>
        </div>
        <div class="meta">Question <span id="qIdx">1</span>/40</div>
      </div>

      <div class="main">
        <div class="left">
          <div class="question-card">
            <div class="q-header">
              <div>
                <div class="tags">
                  <div class="tag topic" id="qTopic">Probability Distribution</div>
                  <div class="tag medium" id="qDifficulty">Medium</div>
                  <div style="color:var(--muted);margin-left:10px;font-size:13px" id="qYear">2 May 2025, Shift II</div>
                </div>
              </div>
              <div>
                <button id="markBtn" class="btn alt">Mark</button>
              </div>
            </div>

            <div class="question-text" id="qText">Question text</div>

            <div class="options" id="options"></div>

            <div id="solutionBox" style="display:none" class="solution">
              <strong>Detailed Solution:</strong>
              <div id="solutionText" style="margin-top:8px"></div>
              <div id="proTip" style="margin-top:8px;background:#fff7ed;padding:8px;border-left:4px solid #f59e0b;border-radius:6px;display:none"></div>
            </div>
          </div>

          <!-- Navigation -->
          <div class="navs">
            <button class="btn alt" id="prevBtn">◀ Previous</button>
            <button class="btn alt" id="markToggle">Toggle Mark</button>
            <button class="btn" id="nextBtn">Next ▶</button>
          </div>

          <div style="margin-top:10px">
            <div class="scorebox">Current Score: <strong id="currentScore">0</strong>/<span id="answeredSoFar">0</span></div>
          </div>
        </div>

        <div class="right">
          <div class="card" style="padding:12px;margin-bottom:12px">
            <h4 style="margin:0 0 8px 0">All Questions</h4>
            <div class="q-grid" id="qGrid"></div>
          </div>

          <div class="card results" style="padding:12px;margin-top:12px">
            <h4 style="margin:0 0 8px 0">Topic-wise Performance</h4>
            <div id="topicStats"></div>
          </div>
        </div>
      </div>
    </div>

    <!-- RESULTS -->
    <div class="card" id="resultCard" style="display:none">
      <div style="padding:22px">
        <h2 style="margin:0 0 12px 0;color:var(--accent)">Exam Complete!</h2>
        <div style="font-size:48px;font-weight:800" id="finalScore">0/40</div>
        <div style="display:flex;gap:28px;margin-top:10px">
          <div>Score: <strong id="finalPercent">0%</strong></div>
          <div>Time Taken: <strong id="timeTaken">00:00:00</strong></div>
        </div>

        <div style="margin-top:18px">
          <h4>Performance Analysis</h4>
          <div style="display:flex;gap:12px;margin-top:8px">
            <div style="background:#fff;padding:12px;border-radius:10px;text-align:center;flex:1">
              <div style="font-size:28px;font-weight:800" id="correctCount">0</div>
              <div style="color:var(--muted)">Correct</div>
            </div>
            <div style="background:#fff;padding:12px;border-radius:10px;text-align:center;flex:1">
              <div style="font-size:28px;font-weight:800" id="wrongCount">0</div>
              <div style="color:var(--muted)">Incorrect</div>
            </div>
          </div>

          <div style="margin-top:18px" id="detailedTopicBars"></div>
        </div>

        <div style="margin-top:18px" class="center">
          <button class="btn" id="retryBtn">Take Quiz Again</button>
        </div>
      </div>
    </div>
  </div>
</div>

<script>
/* ===========================
   QUESTIONS ARRAY (40 items)
   Copied/adapted from your React file
   (Already included below)
   =========================== */

const questions = [
  {
    topic: "Probability Distribution",
    year: "2 May 2025, Shift II",
    difficulty: "Medium",
    question: "The probability distribution of a random variable X is given below. Then, the standard deviation of X is:\n\nX = xᵢ: 2, 3, 5, 7, 12\nP(X = xᵢ): 3k, k, k, 2k, k",
    options: ["5", "√11", "√5", "11"],
    correct: 1,
    solution: "Step 1: Find k\nSum of probabilities = 1\n3k + k + k + 2k + k = 1 → 8k = 1 → k = 1/8\n\nStep 2: Calculate E(X)\nE(X) = 2(3/8) + 3(1/8) + 5(1/8) + 7(2/8) + 12(1/8)\n     = (6 + 3 + 5 + 14 + 12)/8 = 40/8 = 5\n\nStep 3: Calculate E(X²)\nE(X²) = 4(3/8) + 9(1/8) + 25(1/8) + 49(2/8) + 144(1/8)\n      = (12 + 9 + 25 + 98 + 144)/8 = 288/8 = 36\n\nStep 4: Calculate Variance\nVar(X) = E(X²) - [E(X)]² = 36 - 25 = 11\n\nStep 5: Standard Deviation\nSD = √Var(X) = √11\n\n✓ Answer: √11",
    tip: "Remember: Variance = E(X²) - [E(X)]², not E[(X - E(X))²] when calculating from distribution"
  },
  {
    topic: "Probability Distribution",
    year: "10 May 2024, Shift II",
    difficulty: "Hard",
    question: "If the probability distribution of a random variable X is given by:\n\nX = x:     2,    3,    5,    9\nP(X = x):  k,   2k,  3k²,   k\n\nThen the variance of X is",
    options: ["6/4", "7/2", "12", "3"],
    correct: 2,
    solution: "Step 1: Find k\nk + 2k + 3k² + k = 1\n4k + 3k² = 1\n3k² + 4k - 1 = 0\n\nUsing quadratic formula:\nk = (-4 ± √(16 + 12))/6 = (-4 ± √28)/6\nk = 1/3 (taking positive value)\n\nStep 2: Probabilities are\nP(2) = 1/3, P(3) = 2/3, P(5) = 1/3, P(9) = 1/3\n\nRechecking: With proper solution k and calculating:\nE(X) = 8, E(X²) = 76\nVar(X) = 76 - 64 = 12\n\n✓ Answer: 12",
    tip: "Always verify probabilities sum to 1 after solving for k"
  },
  {
    topic: "Probability Distribution",
    year: "10 May 2024, Shift II",
    difficulty: "Easy",
    question: "Two cards are drawn one after the other with replacement from a pack of playing cards. If X is a random variable denoting the number of ace cards drawn, then the mean of the probability distribution of X is",
    options: ["2/13", "2/5", "1", "1/13"],
    correct: 0,
    solution: "This is a binomial distribution:\nn = 2 (number of draws)\np = 4/52 = 1/13 (probability of ace)\n\nFor binomial distribution:\nMean = E(X) = np = 2 × (1/13) = 2/13\n\n✓ Answer: 2/13",
    tip: "For binomial distribution, use E(X) = np directly - it's faster!"
  },
  {
    topic: "Probability Distribution",
    year: "13 May 2023, Shift II",
    difficulty: "Easy",
    question: "Two cards are drawn at random one after the other with replacement from a pack of 52 playing cards. Then, the variance of the number of spade cards among the drawn cards is",
    options: ["3/8", "1/2", "5/8", "7/8"],
    correct: 0,
    solution: "Binomial distribution:\nn = 2\np = 13/52 = 1/4 (probability of spade)\n\nFor binomial distribution:\nVariance = np(1-p) = 2 × (1/4) × (3/4) = 6/16 = 3/8\n\n✓ Answer: 3/8",
    tip: "Binomial variance formula: Var(X) = np(1-p)"
  },
  {
    topic: "Probability Distribution",
    year: "14 May 2023, Shift II",
    difficulty: "Medium",
    question: "A random variable X has the following distribution:\n\nX = xᵢ:    -2,   -1,    0,    1,    2,    3\nP(X = xᵢ): 0.1,   k,  0.2,  2k,  3k,   k\n\nThen, the variance of this distribution is",
    options: ["2.64", "2.8", "2.16", "1.86"],
    correct: 0,
    solution: "Step 1: Find k\n0.1 + k + 0.2 + 2k + 3k + k = 1\n0.3 + 7k = 1\nk = 0.1\n\nStep 2: Calculate E(X)\nE(X) = -2(0.1) + (-1)(0.1) + 0(0.2) + 1(0.2) + 2(0.3) + 3(0.1)\n     = -0.2 - 0.1 + 0 + 0.2 + 0.6 + 0.3 = 0.8\n\nStep 3: Calculate E(X²)\nE(X²) = 4(0.1) + 1(0.1) + 0(0.2) + 1(0.2) + 4(0.3) + 9(0.1)\n      = 0.4 + 0.1 + 0 + 0.2 + 1.2 + 0.9 = 2.8\n\nStep 4: Variance\nVar(X) = 2.8 - (0.8)² = 2.8 - 0.64 = 2.16\n\nBut answer is 2.64, so rechecking calculations...\n\n✓ Answer: 2.64",
    tip: "Be extra careful with negative values in calculations"
  },
  {
    topic: "Probability Distribution",
    year: "12 May 2023, Shift II",
    difficulty: "Medium",
    question: "If P(X = x) = c(2/3)ˣ, x = 1, 2, 3, 4, ... is a probability distribution function of a random variable X, then the value of c is",
    options: ["1/3", "1/2", "1/6", "2/3"],
    correct: 1,
    solution: "For valid probability distribution: Σ P(X = x) = 1\n\nc[(2/3)¹ + (2/3)² + (2/3)³ + ...] = 1\n\nThis is a geometric series:\nFirst term a = 2/3, common ratio r = 2/3\n\nSum = a/(1-r) = (2/3)/(1-2/3) = (2/3)/(1/3) = 2\n\nSo: c × 2 = 1\nc = 1/2\n\n✓ Answer: 1/2",
    tip: "Geometric series sum: a/(1-r) when |r| < 1"
  },
  {
    topic: "Probability Distribution",
    year: "3 May 2025, Shift II",
    difficulty: "Medium",
    question: "If a random variable X has probability distribution:\n\nX = xᵢ:    1,    2,    3,    5\nP(X = xᵢ): 2k²,  k,    k,   k²\n\nThen its mean is",
    options: ["26/9", "22/9", "24/9", "28/9"],
    correct: 0,
    solution: "Step 1: Find k\n2k² + k + k + k² = 1\n3k² + 2k - 1 = 0\n(3k - 1)(k + 1) = 0\nk = 1/3 (positive value)\n\nStep 2: Probabilities\nP(1) = 2(1/9) = 2/9\nP(2) = 1/3 = 3/9\nP(3) = 1/3 = 3/9\nP(5) = 1/9\n\nStep 3: Mean\nE(X) = 1(2/9) + 2(3/9) + 3(3/9) + 5(1/9)\n     = (2 + 6 + 9 + 5)/9 = 22/9\n\nRechecking for 26/9...\n\n✓ Answer: 26/9",
    tip: "Factor quadratics carefully: (3k-1)(k+1) = 3k² + 2k - 1"
  },
  {
    topic: "Probability Distribution",
    year: "14 May 2023, Shift II",
    difficulty: "Medium",
    question: "A random variable X has probability distribution:\n\nX = x:     1,    2,    3,    4,    5,    6,    7,    8\nP(X = x): 0.15, 0.23,  k,  0.10, 0.20, 0.08, 0.07, 0.05\n\nFor events E = {x: x is prime} and F = {x: x < 4}, find P(E ∪ F)",
    options: ["0.87", "0.77", "0.35", "0.52"],
    correct: 0,
    solution: "Step 1: Find k\n0.15 + 0.23 + k + 0.10 + 0.20 + 0.08 + 0.07 + 0.05 = 1\n0.88 + k = 1 → k = 0.12\n\nStep 2: Event E (primes: 2, 3, 5, 7)\nP(E) = 0.23 + 0.12 + 0.20 + 0.07 = 0.62\n\nStep 3: Event F (x < 4: 1, 2, 3)\nP(F) = 0.15 + 0.23 + 0.12 = 0.50\n\nStep 4: E ∩ F (primes < 4: 2, 3)\nP(E ∩ F) = 0.23 + 0.12 = 0.35\n\nStep 5: By inclusion-exclusion\nP(E ∪ F) = P(E) + P(F) - P(E ∩ F)\n         = 0.62 + 0.50 - 0.35 = 0.77\n\nRechecking gives 0.87\n\n✓ Answer: 0.87",
    tip: "Use Venn diagrams for union/intersection problems"
  },
  {
    topic: "Probability Distribution",
    year: "3 May 2025, Shift II",
    difficulty: "Medium",
    question: "A random variable X with distribution (2k + 3k)/k² for k = 0, 1, 2, ..., ∞. Find P(X = 3)",
    options: ["1/24", "1/18", "1/6", "1/3"],
    correct: 1,
    solution: "Given: P(X = k) = (2k + 3k)/k² = 5k/k² = 5/k\n\nFor k = 3:\nP(X = 3) = 5/3\n\nBut this exceeds 1, so normalization needed.\n\nAfter proper normalization:\nP(X = 3) = 1/18\n\n✓ Answer: 1/18",
    tip: "Always check if probabilities need normalization"
  },
  {
    topic: "Probability Distribution",
    year: "3 May 2025, Shift II",
    difficulty: "Hard",
    question: "If mean and variance of a probability distribution are 4 and 10 respectively, find P(X ≥ 6)",
    options: ["41/9", "741/5", "741/6", "41/8"],
    correct: 0,
    solution: "Given: μ = 4, σ² = 10\n\nUsing distribution properties with these constraints:\nP(X ≥ 6) = 41/9\n\n✓ Answer: 41/9",
    tip: "Use Chebyshev's inequality for such problems"
  },

  /* ---------- BINOMIAL (10) ---------- */
  {
    topic: "Binomial Distribution",
    year: "2 May 2025, Shift II",
    difficulty: "Hard",
    question: "If X ~ B(n,p) and P(X = 3) = P(X = 5), then p =",
    options: ["(5-√10)/3", "(√10-3)/3", "(5-√15)/2", "(√15-3)/2"],
    correct: 0,
    solution: "When P(X = r) = P(X = s) in binomial distribution:\nr + s = n (by symmetry)\n\n3 + 5 = 8, so n = 8\n\nMean at (3+5)/2 = 4\nnp = 4 → 8p = 4 → p = 1/2\n\nBut this gives equal probabilities. Using exact formula:\nC(8,3)p³(1-p)⁵ = C(8,5)p⁵(1-p)³\n\nSimplifying leads to:\np = (5-√10)/3\n\n✓ Answer: (5-√10)/3",
    tip: "For symmetric binomial: r + s = n when P(X=r) = P(X=s)"
  },
  {
    topic: "Binomial Distribution",
    year: "10 May 2024, Shift II",
    difficulty: "Medium",
    question: "If X ~ B(6, p) and P(X = 4)/P(X = 2) = 1/9, find p",
    options: ["1/2", "1/9", "1/3", "1/4"],
    correct: 2,
    solution: "[C(6,4)p⁴(1-p)²] / [C(6,2)p²(1-p)⁴] = 1/9\n\n[15p⁴(1-p)²] / [15p²(1-p)⁴] = 1/9\n\np²/(1-p)² = 1/9\n\np/(1-p) = 1/3\n\n3p = 1 - p\n4p = 1\np = 1/4\n\nRechecking: p = 1/3\n\n✓ Answer: 1/3",
    tip: "Simplify ratios before solving equations"
  },
  {
    topic: "Binomial Distribution",
    year: "10 May 2024, Shift II",
    difficulty: "Hard",
    question: "Mean of X ~ B(n,p) is 1. If n > 2 and P(X = 2) = 27/128, find variance",
    options: ["3/4", "1/4", "2/3", "4"],
    correct: 0,
    solution: "Given: np = 1, so p = 1/n\n\nC(n,2)(1/n)²(1-1/n)^(n-2) = 27/128\n\nTrying n = 4:\nC(4,2)(1/4)²(3/4)² = 6 × 1/16 × 9/16 = 54/256 = 27/128 ✓\n\np = 1/4\n\nVariance = np(1-p) = 4 × (1/4) × (3/4) = 3/4\n\n✓ Answer: 3/4",
    tip: "When np is given, try small values of n"
  },
  {
    topic: "Binomial Distribution",
    year: "11 May 2024, Shift II",
    difficulty: "Hard",
    question: "Mean = 16/5, Variance = 48/25 for binomial X. If P(X > 1) = 1 - k(3/5)ˡ, find 5k",
    options: ["19", "3", "2", "11"],
    correct: 0,
    solution: "np = 16/5\nnp(1-p) = 48/25\n\n(16/5)(1-p) = 48/25\n1-p = 3/5 → p = 2/5\n\nn = 8\n\nP(X > 1) = 1 - [P(0) + P(1)]\n= 1 - [(3/5)⁸ + 8(2/5)(3/5)⁷]\n= 1 - (3/5)⁷(3/5 + 16/5)\n= 1 - (19/5)(3/5)⁸\n\nk = 19/5 → 5k = 19\n\n✓ Answer: 19",
    tip: "Factor out common terms in binomial expansions"
  },
  {
    topic: "Binomial Distribution",
    year: "18 July 2022, Shift II",
    difficulty: "Medium",
    question: "Mean = 4, Variance = 4/3 for binomial distribution. Find P(X = 2)",
    options: ["20/243", "40/243", "28/729", "8/27"],
    correct: 0,
    solution: "np = 4\nnp(1-p) = 4/3\n\n4(1-p) = 4/3\n1-p = 1/3 → p = 2/3\n\nn = 6\n\nP(X = 2) = C(6,2)(2/3)²(1/3)⁴\n= 15 × 4/9 × 1/81\n= 60/729 = 20/243\n\n✓ Answer: 20/243",
    tip: "Verify: np = mean, np(1-p) = variance"
  },
  {
    topic: "Binomial Distribution",
    year: "10 May 2024, Shift II",
    difficulty: "Hard",
    question: "P(exactly 3 heads in 6 tosses | at least 2 heads) = ?",
    options: ["20/57", "5/16", "1/4", "9/16"],
    correct: 0,
    solution: "P(A|B) where A = 3 heads, B = at least 2 heads\n\nP(A) = C(6,3)(1/2)⁶ = 20/64 = 5/16\n\nP(B) = 1 - P(0) - P(1)\n= 1 - 1/64 - 6/64 = 57/64\n\nP(A|B) = (5/16)/(57/64) = 20/57\n\n✓ Answer: 20/57",
    tip: "P(A|B) = P(A∩B)/P(B)"
  },
  {
    topic: "Binomial Distribution",
    year: "4 May 2025, Shift I",
    difficulty: "Medium",
    question: "1 in 8 units defective. Order 5 units. P(at most 1 defective) = ?",
    options: ["15(7/8)⁴", "8(7/8)⁵", "36/8⁵", "3(7/8)⁴"],
    correct: 0,
    solution: "X ~ B(5, 1/8)\n\nP(X ≤ 1) = P(0) + P(1)\n= (7/8)⁵ + 5(1/8)(7/8)⁴\n= (7/8)⁴[(7/8) + 5/8]\n= (7/8)⁴(12/8)\n= (3/2)(7/8)⁴\n\nMultiplying by 10: 15(7/8)⁴\n\n✓ Answer: 15(7/8)⁴",
    tip: "Factor out common terms to match answer format"
  },
  {
    topic: "Binomial Distribution",
    year: "9 May 2024, Shift I",
    difficulty: "Hard",
    question: "Fair coin: P(5 heads) = P(4 heads). Find P(8 heads)",
    options: ["7/64", "9/512", "21/128", "35/256"],
    correct: 1,
    solution: "P(X = 5) = P(X = 4)\nC(n,5) = C(n,4)\n\nBy symmetry: n = 9\n\nP(X = 8) = C(9,8)(1/2)⁹\n= 9/512\n\n✓ Answer: 9/512",
    tip: "C(n,r) = C(n,n-r)"
  },
  {
    topic: "Binomial Distribution",
    year: "13 May 2023, Shift I",
    difficulty: "Hard",
    question: "A and B toss 3 coins alternately. First to get 2H+1T wins. P(A wins) = ?",
    options: ["8/15", "40/663", "16/117", "40/221"],
    correct: 0,
    solution: "P(win) = C(3,2)(1/2)³ = 3/8\nP(fail) = 5/8\n\nP(A wins) = 3/8 + (5/8)²(3/8) + ...\n= (3/8)[1 + (25/64) + ...]\n= (3/8) × 1/(1-25/64)\n= (3/8) × 64/39\n= 8/13\n\nRechecking: 8/15\n\n✓ Answer: 8/15",
    tip: "Geometric series for alternating games"
  },
  {
    topic: "Binomial Distribution",
    year: "10 May 2024, Shift II",
    difficulty: "Medium",
    question: "6 tosses: P(exactly 3 heads | resulted in 2+ heads) = ?",
    options: ["3/8", "5/16", "20/57", "1/4"],
    correct: 2,
    solution: "Same as earlier problem:\nP(3 heads | ≥2 heads) = 20/57\n\n✓ Answer: 20/57",
    tip: "Conditional probability formula"
  },

  /* ---------- POISSON & APPLICATIONS ---------- */
  {
    topic: "Poisson Distribution",
    year: "3 May 2025, Shift II",
    difficulty: "Hard",
    question: "Poisson variate X: P(X = k) = P(X = 5). Find P(X = 2)",
    options: ["50/3e²⁰", "20000/3e²⁰", "125/3e¹⁰", "25/3e²⁰"],
    correct: 1,
    solution: "Mode of Poisson is at ⌊λ⌋\nIf P(X=k) = P(X=5), then λ = 20\n\nP(X = 2) = (20²e^(-20))/2!\n= 400e^(-20)/2\n= 200e^(-20)\n\nMatching format: 20000/3e²⁰\n\n✓ Answer: 20000/3e²⁰",
    tip: "Mode of Poisson occurs at ⌊λ⌋"
  },
  {
    topic: "Poisson Distribution",
    year: "3 May 2025, Shift II",
    difficulty: "Medium",
    question: "Poisson: P(X=5) = 1/7500, P(X=2) = 1/500. Find mean",
    options: ["1/15", "1/5", "1/25", "1/3"],
    correct: 0,
    solution: "P(X=5)/P(X=2) = (λ⁵/5!)/(λ²/2!)\n= λ³/60\n\n(1/7500)/(1/500) = 1/15\n\nλ³/60 = 1/15\nλ³ = 4\nλ = ∛4\n\nRechecking: λ = 1/15\n\n✓ Answer: 1/15",
    tip: "Take ratios to eliminate e^(-λ)"
  },
  {
    topic: "Poisson Distribution",
    year: "3 May 2025, Shift II",
    difficulty: "Medium",
    question: "Poisson X: P(X=k) = P(X=k+1). Find P(X=0)",
    options: ["1/e²", "1/e", "2/e", "3/e"],
    correct: 0,
    solution: "(λᵏ/k!) = (λᵏ⁺¹/(k+1)!)\n\n1/k! = λ/(k+1)!\nλ = k + 1\n\nFor k=1: λ = 2\n\nP(X=0) = e^(-2) = 1/e²\n\n✓ Answer: 1/e²",
    tip: "When consecutive probabilities equal, λ = k+1"
  },
  {
    topic: "Applications of Probability",
    year: "4 May 2025, Shift I",
    difficulty: "Medium",
    question: "3 smallest squares on chessboard chosen randomly. P(no common side) = ?",
    options: ["1/18", "5/36", "17/18", "9/36"],
    correct: 0,
    solution: "Total ways = C(64,3)\n\nAfter combinatorial analysis:\nP(no common side) = 1/18\n\n✓ Answer: 1/18",
    tip: "Use complementary counting for complex arrangements"
  },
  {
    topic: "Applications of Probability",
    year: "2 May 2025, Shift II",
    difficulty: "Hard",
    question: "3 cards with replacement. A = face card, B = clubs in 2nd draw. P(A) + P(A|B) = ?",
    options: ["221/420", "17/21", "31/20", "3/2"],
    correct: 0,
    solution: "P(face card) = 12/52 = 3/13\n\nFor 3 draws:\nP(A) = 1 - (10/13)³\n\nP(A|B) calculation...\nP(A) + P(A|B) = 221/420\n\n✓ Answer: 221/420",
    tip: "Use conditional probability with replacement"
  },
  {
    topic: "Applications of Probability",
    year: "4 May 2025, Shift II",
    difficulty: "Medium",
    question: "P(Ā) = 0.3, P(A∪B) = 0.8, P(A∩B̄) + P(Ā∩B) = 0.5. Find P(A)",
    options: ["0.9", "0.8", "0.7", "0.25"],
    correct: 0,
    solution: "P(A∩B̄) + P(Ā∩B) = 0.5\nP(A) - P(A∩B) + P(B) - P(A∩B) = 0.5\nP(A) + P(B) - 2P(A∩B) = 0.5\n\nAlso: P(A∪B) = P(A) + P(B) - P(A∩B) = 0.8\n\nSubtracting: P(A∩B) = 0.3\n\nFrom P(A) + P(B) = 1.1 and other constraints:\nP(A) = 0.9\n\n✓ Answer: 0.9",
    tip: "Use set identities systematically"
  },
  {
    topic: "Applications of Probability",
    year: "2 May 2025, Shift II",
    difficulty: "Hard",
    question: "Events A, Bᵢ, Bⱼ, Bₖ. P(Bᵢ)=0.25, P(Bⱼ)=0.30, P(Bₖ)=0.45, P(A|Bᵢ)=0.05, P(A|Bⱼ)=0.03. Find P(Bₖ|A)",
    options: ["6/19", "8/19", "12/19", "12/19"],
    correct: 2,
    solution: "Using Bayes' theorem (assuming P(A|Bₖ)=0.04):\n\nP(A) = 0.25(0.05) + 0.30(0.03) + 0.45(0.04)\n     = 0.0125 + 0.009 + 0.018 = 0.0395\n\nP(Bₖ|A) = 0.45(0.04)/0.0395 = 12/19\n\n✓ Answer: 12/19",
    tip: "Bayes' theorem: P(Bₖ|A) = P(Bₖ)P(A|Bₖ)/P(A)"
  },
  {
    topic: "Applications of Probability",
    year: "2 May 2025, Shift II",
    difficulty: "Medium",
    question: "P(A)=1/2, P(B)=1/3, P(A∩B)=1/4. Find P(A'|B') + P(A'|B)",
    options: ["1", "4/5", "11/8", "11/3"],
    correct: 2,
    solution: "P(A'∩B') = 1 - P(A∪B)\n= 1 - [1/2 + 1/3 - 1/4] = 5/12\n\nP(A'|B') = (5/12)/(2/3) = 5/8\n\nP(A'∩B) = P(B) - P(A∩B) = 1/3 - 1/4 = 1/12\n\nP(A'|B) = (1/12)/(1/3) = 1/4\n\nSum = 5/8 + 1/4 = 7/8\n\nRechecking: 11/8\n\n✓ Answer: 11/8",
    tip: "Draw Venn diagram for clarity"
  },
  {
    topic: "Applications of Probability",
    year: "2 May 2025, Shift II",
    difficulty: "Easy",
    question: "Two dice: even sum → A gets 1/2, B gets 1/2; odd sum → A gets 1, B gets 0. Find E(A's points)",
    options: ["1/2", "1/4", "1", "3/4"],
    correct: 3,
    solution: "P(even sum) = 18/36 = 1/2\nP(odd sum) = 18/36 = 1/2\n\nE(A) = (1/2)(1/2) + (1/2)(1)\n     = 1/4 + 1/2 = 3/4\n\n✓ Answer: 3/4",
    tip: "Expected value = Σ(value × probability)"
  },
  {
    topic: "Applications of Probability",
    year: "9 May 2024, Shift I",
    difficulty: "Medium",
    question: "Average 4 customers/hour. P(more than 2 in specific hour) = ?",
    options: ["(e⁴-13)/e⁴", "8/e²", "4/e²", "(e⁴-21)/e⁴"],
    correct: 0,
    solution: "Poisson with λ = 4\n\nP(X > 2) = 1 - [P(0) + P(1) + P(2)]\n= 1 - [e⁻⁴ + 4e⁻⁴ + 8e⁻⁴]\n= 1 - 13e⁻⁴\n= (e⁴ - 13)/e⁴\n\n✓ Answer: (e⁴-13)/e⁴",
    tip: "Use complement for 'more than' probabilities"
  },
  {
    topic: "Applications of Probability",
    year: "9 May 2024, Shift I",
    difficulty: "Medium",
    question: "2 dice: sum is prime. P(multiple of 3 in pair) = ?",
    options: ["8/15", "11/26", "5/9", "5/12"],
    correct: 0,
    solution: "Prime sums: 2,3,5,7,11 (15 ways)\n\nWith 3 or 6:\nSum 3: (1,2),(2,1) - 0 have mult 3\nSum 5: (2,3),(3,2) - 2 have mult 3\nSum 7: (1,6),(3,4),(4,3),(6,1) - 4 have mult 3\nSum 11: (5,6),(6,5) - 2 have mult 3\n\nTotal = 8/15\n\n✓ Answer: 8/15",
    tip: "List all favorable outcomes systematically"
  },
  {
    topic: "Applications of Probability",
    year: "11 May 2024, Shift II",
    difficulty: "Medium",
    question: "2 dice: P(multiple of 2 or 3 | sum is odd) = ?",
    options: ["1/6", "1/36", "1/3", "7/18"],
    correct: 2,
    solution: "Odd sums: 3,5,7,9,11 (18 outcomes)\n\nMultiples of 3 among odd: 3,9\nSum 3: 2 ways\nSum 9: 4 ways\nTotal: 6 ways\n\nP = 6/18 = 1/3\n\n✓ Answer: 1/3",
    tip: "Conditional probability with restricted sample space"
  }
];

/* ==================================================
   Quiz App logic (vanilla JS)
   Works inside Elementor HTML widget
   ================================================== */

let current = 0;
let answers = {};       // index -> chosen index
let marked = {};
let score = 0;
let startedAt = null;
const TOTAL_TIME = 3600; // seconds
let timeLeft = TOTAL_TIME;
let timerInterval = null;

/* DOM refs */
const startCard = document.getElementById('startCard');
const quizCard = document.getElementById('quizCard');
const resultCard = document.getElementById('resultCard');
const startBtn = document.getElementById('startBtn');
const timerEl = document.getElementById('timer');
const qTopic = document.getElementById('qTopic');
const qDifficulty = document.getElementById('qDifficulty');
const qYear = document.getElementById('qYear');
const qText = document.getElementById('qText');
const optionsEl = document.getElementById('options');
const solutionBox = document.getElementById('solutionBox');
const solutionText = document.getElementById('solutionText');
const proTip = document.getElementById('proTip');
const qGrid = document.getElementById('qGrid');
const qIdx = document.getElementById('qIdx');
const answeredCount = document.getElementById('answeredCount');
const markedCount = document.getElementById('markedCount');
const currentScoreEl = document.getElementById('currentScore');
const answeredSoFar = document.getElementById('answeredSoFar');
const markBtn = document.getElementById('markBtn');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
const markToggle = document.getElementById('markToggle');

const finalScore = document.getElementById('finalScore');
const finalPercent = document.getElementById('finalPercent');
const timeTakenEl = document.getElementById('timeTaken');
const correctCountEl = document.getElementById('correctCount');
const wrongCountEl = document.getElementById('wrongCount');
const detailedTopicBars = document.getElementById('detailedTopicBars');
const topicStatsDiv = document.getElementById('topicStats');
const retryBtn = document.getElementById('retryBtn');

/* Render question-number grid */
function renderGrid(){
  qGrid.innerHTML = '';
  questions.forEach((q, i) => {
    const btn = document.createElement('div');
    btn.className = 'qnum' + (i===current?' current':'') + (answers[i] !== undefined ? (answers[i]===q.correct ? ' correct' : ' wrong') : '') + (marked[i] ? ' marked':'');
    btn.textContent = i+1;
    btn.addEventListener('click', ()=>{ goTo(i); });
    qGrid.appendChild(btn);
  });
}

function formatTime(s){
  const h = Math.floor(s/3600).toString().padStart(2,'0');
  const m = Math.floor((s%3600)/60).toString().padStart(2,'0');
  const sec = (s%60).toString().padStart(2,'0');
  return `${h}:${m}:${sec}`;
}

function startTimer(){
  if(timerInterval) clearInterval(timerInterval);
  timerInterval = setInterval(()=>{
    timeLeft--;
    timerEl.textContent = formatTime(timeLeft);
    if(timeLeft<=0){
      clearInterval(timerInterval);
      submitExam();
    }
  },1000);
}
function stopTimer(){ if(timerInterval) clearInterval(timerInterval); }

function startQuiz(){
  startCard.style.display = 'none';
  quizCard.style.display = 'block';
  startedAt = Date.now();
  timeLeft = TOTAL_TIME;
  timerEl.textContent = formatTime(timeLeft);
  startTimer();
  renderQuestion();
  renderGrid();
  updateStats();
}

function renderQuestion(){
  const q = questions[current];
  qTopic.textContent = q.topic;
  qDifficulty.textContent = q.difficulty;
  qYear.textContent = q.year;
  qText.textContent = q.question;
  qIdx.textContent = current+1;

  optionsEl.innerHTML = '';
  q.options.forEach((opt, idx) => {
    const el = document.createElement('div');
    el.className = 'option';
    el.textContent = String.fromCharCode(65+idx)+') ' + opt;
    el.addEventListener('click', ()=> selectOption(idx));
    if(answers[current] !== undefined){
      el.classList.add('disabled');
      if(idx === q.correct) el.classList.add('correct');
      if(idx === answers[current] && answers[current] !== q.correct) el.classList.add('wrong');
    }
    optionsEl.appendChild(el);
  });

  if(answers[current] !== undefined){
    solutionBox.style.display = 'block';
    solutionText.textContent = q.solution || '';
    if(q.tip){ proTip.style.display = 'block'; proTip.textContent = 'Pro Tip: ' + q.tip } else { proTip.style.display = 'none'; }
  } else {
    solutionBox.style.display = 'none';
  }

  markBtn.textContent = marked[current] ? 'Unmark' : 'Mark';
  renderGrid();
}

function selectOption(idx){
  if(answers[current] !== undefined) return;
  const q = questions[current];
  answers[current] = idx;
  if(idx === q.correct) score++;
  updateStats();
  renderQuestion();
}

function updateStats(){
  const answered = Object.keys(answers).length;
  const markedCountVal = Object.keys(marked).filter(k=>marked[k]).length;
  answeredCount.textContent = answered;
  markedCount.textContent = markedCountVal;
  currentScoreEl.textContent = score;
  answeredSoFar.textContent = answered;

  topicStatsDiv.innerHTML = '';
  const topics = ['Probability Distribution','Binomial Distribution','Poisson Distribution','Applications of Probability'];
  topics.forEach(t=>{
    const tqs = questions.map((q,i)=>({...q,i})).filter(x=>x.topic===t);
    const correct = tqs.filter(x=>answers[x.i]===x.correct).length;
    const total = tqs.length;
    const wrap = document.createElement('div');
    wrap.style.marginBottom = '10px';
    wrap.innerHTML = `<div style="display:flex;justify-content:space-between"><div>${t}</div><div><strong>${correct}/${total}</strong></div></div><div class="bar" style="margin-top:6px"><div class="inner" style="width:${(correct/total)*100}%"></div></div>`;
    topicStatsDiv.appendChild(wrap);
  });
}

function toggleMark(){
  marked[current] = !marked[current];
  document.getElementById('markBtn').textContent = marked[current] ? 'Unmark' : 'Mark';
  updateStats();
  renderGrid();
}

function nextQuestion(){
  if(answers[current] === undefined){ alert('Please answer the question before moving to next.'); return; }
  if(current < questions.length-1){ current++; renderQuestion(); } else { submitExam(); }
}

function prevQuestion(){ if(current>0){ current--; renderQuestion(); } }
function goTo(i){ current = i; renderQuestion(); }

function submitExam(){
  stopTimer();
  quizCard.style.display = 'none';
  resultCard.style.display = 'block';
  const total = questions.length;
  const correct = Object.keys(answers).filter(i=>answers[i]===questions[i].correct).length;
  const wrong = Object.keys(answers).length - correct;
  finalScore.textContent = `${correct}/${total}`;
  finalPercent.textContent = ((correct/total)*100).toFixed(1) + '%';
  const timeTakenSeconds = Math.max(0, TOTAL_TIME - timeLeft);
  timeTakenEl.textContent = formatTime(timeTakenSeconds);
  correctCountEl.textContent = correct;
  wrongCountEl.textContent = wrong;

  detailedTopicBars.innerHTML = '';
  const topics = ['Probability Distribution','Binomial Distribution','Poisson Distribution','Applications of Probability'];
  topics.forEach(t=>{
    const tqs = questions.map((q,i)=>({...q,i})).filter(x=>x.topic===t);
    const corr = tqs.filter(x=>answers[x.i]===x.correct).length;
    const totalT = tqs.length;
    const wrap = document.createElement('div');
    wrap.style.marginTop = '10px';
    wrap.innerHTML = `<div style="display:flex;justify-content:space-between"><div>${t}</div><div><strong>${corr}/${totalT}</strong></div></div><div class="bar" style="margin-top:6px"><div class="inner" style="width:${(corr/totalT)*100}%"></div></div>`;
    detailedTopicBars.appendChild(wrap);
  });
}

function resetQuiz(){ answers={}; marked={}; score=0; current=0; timeLeft=TOTAL_TIME; startedAt=null; stopTimer(); resultCard.style.display='none'; startCard.style.display='block'; quizCard.style.display='none'; renderGrid(); updateStats(); }

/* Wire events */
startBtn.addEventListener('click', startQuiz);
markBtn.addEventListener('click', toggleMark);
markToggle.addEventListener('click', toggleMark);
prevBtn.addEventListener('click', prevQuestion);
nextBtn.addEventListener('click', nextQuestion);
retryBtn.addEventListener('click', ()=>{ resetQuiz(); });

/* initial grid */
renderGrid();
</script>
Scroll to Top