xAPI + AI Integration Summary
-----------------------------
Original file: Interactive_20260221102302.zip
Base mode: quiz
AI used: yes
AI provider: gemini
AI model: gemini-3-flash-preview
AI status: success

Custom Instructions:
Track scores such that if correct answer is selected on first attempt, 3 marks is awarded. For each incorrect answer, penalise 1 mark. A minimum of 0 mark can be awarded.

AI Explanation:
- **Lines 10-18**: Defines the local session state. It stores the start time to calculate the `t` (seconds offset) for history events, and an `interactions` object to keep track of stateful scoring.
- **Lines 23-56**: The `dispatchState` function. This maps our local session data into the specific SLS JSON contract. It calculates `score`, `max`, and populates `quiz.items` dynamically based on interactions detected.
- **Lines 61-94**: This is the heart of the custom scoring logic. 
    - It creates a new interaction entry if it's the first time an element is clicked.
    - If `isCorrect` is true and it's the 1st attempt, it sets `marks` to 3.
    - If `isCorrect` is true but there were previous failures, it calculates `3 - (penalties)`.
    - If `isIncorrect`, it increments the attempt counter (which reduces the potential final score).
- **Lines 99-122**: Media event listeners. Since the content has "Play/Pause" features, these listeners track when the user engages or disengages with the timeline, sending this to the `history` log.
- **Lines 127-152**: Event delegation. It watches all clicks on the page. If a clicked element has attributes/classes suggesting it's a "correct" or "incorrect" answer, it triggers the scoring logic. Otherwise, it just logs a generic engagement click.
- **Lines 157-172**: Initialization logic with a retry mechanism. This ensures that even if `xAPI.js` (the vendor glue) loads slowly, our script waits for `window.storeState` to be available before attempting to send the 'initialized' event.