xAPI + AI Integration Summary
-----------------------------
Original file: Monsoon_Mastery_Checkpoint_20260302.zip
Base mode: quiz
AI used: yes
AI provider: openai
AI model: gpt-5.2
AI status: success

Custom Instructions:
For each concept (Season, Temperature, Pressure, etc.), explicitly track the student's Score Percentage, the total number of Attempts they took, and a history of their Confidence Levels for that specific concept.

AI Explanation:
- Wraps everything in an IIFE to avoid polluting globals and to be safe for injection.
- Defines retry logic to wait briefly for `window.storeState` (required), without reading endpoint/auth from URL and without any network calls.
- Maintains a session timer (`sessionStart`) and a rolling `history` array capped to 50 events.
- Infers a “concept” for each interaction using:
  - `data-concept` on the element or ancestors
  - nearby headings/section labels
  - element label/name/id/class keywords (Season/Temperature/Pressure/etc.)
  - fallback to “General”
- Tracks required per-concept analytics:
  - Attempts: incremented on checkbox toggles, dragstart/drop, and media play/pause/ended
  - Confidence history: captured from inputs that look like confidence controls (data-confidence, name/id/label contains “confidence”)
  - Score percentage: computed as `bestScore/maxScore*100` (default maxScore=100). If correctness can be detected (via `data-correct`, `.correct/.incorrect`, `aria-invalid`, or drop target `data-accept`), it updates bestScore to 100 for correct; otherwise it remains unchanged (typically 0).
- Mirrors concept analytics into `quiz.items` so SLS has a stable place to read per-concept metrics:
  - Each item has `id: concept:<ConceptName>`
  - `marks` is the concept score percentage (0–100)
  - `userSelection` includes Score%, Attempts, and ConfidenceHistory JSON
- Calls `window.storeState(payload)` on each meaningful event with a contract-compatible payload:
  - `score`, `max`, `feedback`, `reason`, `quiz`, `history`
- Adds page lifecycle tracking (`pagehide` and `visibilitychange`) to flush a final state.