File size: 36,511 Bytes
ec57533
bf458e5
c83b7b9
 
 
ec57533
c83b7b9
 
 
 
 
bf458e5
c83b7b9
bf458e5
 
c83b7b9
ec57533
c83b7b9
 
 
bf458e5
 
 
ec57533
 
 
 
 
 
 
 
bf458e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c83b7b9
 
bf458e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec57533
c83b7b9
7114045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c83b7b9
 
bf458e5
 
 
 
 
c83b7b9
bf458e5
 
 
c83b7b9
ec57533
bf458e5
ec57533
7114045
 
 
 
 
 
 
 
 
 
c83b7b9
 
 
7114045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bf458e5
 
 
 
 
7114045
bf458e5
 
 
 
 
 
 
 
 
 
 
 
ec57533
c83b7b9
bf458e5
 
 
 
 
 
c83b7b9
7114045
ec57533
 
 
7114045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec57533
 
7114045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c83b7b9
7114045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bf458e5
 
 
 
 
 
ec57533
c83b7b9
 
b9fb27b
ec57533
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
<!DOCTYPE html>
<html lang="en" class=""> <!-- class="dark" will be toggled here -->
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Florida Life & Health Insurance Exam Prep</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Inter', sans-serif;
            transition: background-color 0.3s ease, color 0.3s ease;
        }
        .main-card, .card-button, .flashcard-face, .chat-message {
            transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
        }
        .card-button:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
        .dark .card-button:hover {
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
        }
        .progress-bar-fill { transition: width 0.5s ease-in-out; }
        .explanation { max-height: 0; overflow: hidden; transition: all 0.5s ease-in-out; }

        /* Flashcard Styles */
        .flashcard-container { perspective: 1000px; }
        .flashcard { width: 100%; height: 250px; position: relative; transform-style: preserve-3d; transition: transform 0.6s; cursor: pointer; }
        .flashcard.is-flipped { transform: rotateY(180deg); }
        .flashcard-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; border-radius: 1rem; }
        
        /* Chat Styles */
        .chat-message {
            max-width: 85%;
            padding: 8px 12px;
            border-radius: 15px;
            margin-bottom: 8px;
            word-wrap: break-word;
        }
        .user-message {
            background-color: #3b82f6;
            color: white;
            align-self: flex-end;
            border-bottom-right-radius: 5px;
        }
        .ai-message {
            background-color: #e5e7eb;
            color: #1f2937;
            align-self: flex-start;
            border-bottom-left-radius: 5px;
        }
        .dark .ai-message {
            background-color: #4b5563;
            color: #e5e7eb;
        }
        .typing-indicator {
            align-self: flex-start;
            font-style: italic;
            font-size: 0.875rem;
        }

    </style>
</head>
<body class="bg-slate-100 dark:bg-slate-900 text-slate-800 dark:text-slate-200">

    <div id="app-container" class="w-full max-w-6xl mx-auto bg-white dark:bg-slate-800 rounded-2xl shadow-xl p-6 md:p-8 flex flex-col md:flex-row gap-6">

        <!-- Main Content Area -->
        <div id="main-content-area" class="flex-grow md:w-2/3">
            <!-- Main Menu -->
            <div id="main-menu" class="main-card">
                <header class="text-center border-b border-slate-200 dark:border-slate-700 pb-4 mb-6 relative">
                    <h1 class="text-3xl font-bold text-slate-700 dark:text-slate-200">Florida Insurance Exam Companion</h1>
                    <p class="text-slate-500 dark:text-slate-400 mt-1">Your complete study toolkit.</p>
                    <button id="dark-mode-toggle" class="absolute top-0 right-0 p-2 rounded-full text-slate-500 hover:bg-slate-100 dark:hover:bg-slate-700 focus:outline-none">
                        <svg id="sun-icon" xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" /></svg>
                        <svg id="moon-icon" xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 hidden" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z" /></svg>
                    </button>
                </header>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                     <button onclick="showView('topic-selection')" class="card-button bg-sky-500 text-white p-6 rounded-lg text-left">
                        <h2 class="font-bold text-xl">Practice Quizzes</h2>
                        <p class="font-light text-sm mt-1">Focus on specific topics.</p>
                    </button>
                    <button onclick="showView('flashcard-area')" class="card-button bg-emerald-500 text-white p-6 rounded-lg text-left">
                        <h2 class="font-bold text-xl">Flashcard Glossary</h2>
                        <p class="font-light text-sm mt-1">Master key terms.</p>
                    </button>
                    <button onclick="showView('performance-area')" class="card-button bg-amber-500 text-white p-6 rounded-lg text-left">
                        <h2 class="font-bold text-xl">View Progress</h2>
                        <p class="font-light text-sm mt-1">Track your performance.</p>
                    </button>
                    <button onclick="promptExamMode()" class="card-button bg-slate-700 dark:bg-slate-600 text-white p-6 rounded-lg text-left">
                        <h2 class="font-bold text-xl">Practice Exam</h2>
                        <p class="font-light text-sm mt-1">Simulate the real test.</p>
                    </button>
                </div>
            </div>

            <!-- Topic Selection -->
            <div id="topic-selection" class="hidden main-card">
                <h2 class="text-2xl font-bold text-center mb-6 text-slate-700 dark:text-slate-200">Select a Topic</h2>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <button onclick="startQuiz('florida_rules')" class="card-button bg-orange-500 text-white p-4 rounded-lg">Florida Rules & Regs</button>
                    <button onclick="startQuiz('life')" class="card-button bg-emerald-500 text-white p-4 rounded-lg">Life Insurance Policies</button>
                    <button onclick="startQuiz('health')" class="card-button bg-amber-500 text-white p-4 rounded-lg">Health & Disability</button>
                    <button onclick="startQuiz('general')" class="card-button bg-sky-500 text-white p-4 rounded-lg">General Concepts</button>
                </div>
                <button onclick="showView('main-menu')" class="mt-8 w-full text-slate-600 dark:text-slate-400 font-semibold py-2 px-4 rounded-lg hover:bg-slate-100 dark:hover:bg-slate-700 transition">Back to Main Menu</button>
            </div>

            <!-- Quiz Area -->
            <div id="quiz-area" class="hidden main-card">
                <div class="flex justify-between items-center mb-4">
                    <h2 id="quiz-topic-title" class="text-xl font-semibold text-slate-600 dark:text-slate-300"></h2>
                    <div id="timer-display" class="hidden text-lg font-bold text-red-500"></div>
                    <p id="question-counter" class="text-sm text-slate-500 dark:text-slate-400"></p>
                </div>
                <div class="w-full bg-slate-200 dark:bg-slate-700 rounded-full h-2.5 mb-6">
                    <div id="progress-bar" class="bg-blue-600 h-2.5 rounded-full progress-bar-fill" style="width: 0%"></div>
                </div>
                <div id="question-container">
                    <p id="question-text" class="text-lg font-medium mb-6"></p>
                    <div id="options-container" class="space-y-3"></div>
                    <div id="explanation-container" class="mt-4"></div>
                </div>
                <div class="mt-8 flex justify-between items-center">
                    <button id="next-btn" onclick="nextQuestion()" class="hidden bg-slate-600 text-white font-semibold py-2 px-6 rounded-lg hover:bg-slate-700 transition">Next</button>
                    <button id="submit-btn" onclick="submitAnswer()" class="bg-blue-600 text-white font-semibold py-2 px-6 rounded-lg hover:bg-blue-700 transition disabled:bg-slate-400 disabled:cursor-not-allowed ml-auto">Submit</button>
                </div>
            </div>

            <!-- Results Area -->
            <div id="results-area" class="hidden text-center main-card">
                 <h2 id="results-title" class="text-2xl font-bold text-slate-700 dark:text-slate-200 mb-2">Quiz Complete!</h2>
                <p class="text-slate-500 dark:text-slate-400 mb-6">Here's how you did:</p>
                <div id="score-circle" class="w-32 h-32 rounded-full mx-auto flex items-center justify-center mb-6">
                    <p class="text-3xl font-bold"><span id="final-score"></span>%</p>
                </div>
                <p id="score-summary" class="text-lg mb-8"></p>
                <button onclick="showView('main-menu')" class="bg-slate-600 text-white font-semibold py-2 px-8 rounded-lg hover:bg-slate-700 transition">Main Menu</button>
            </div>

            <!-- Flashcard Area -->
            <div id="flashcard-area" class="hidden main-card">
                <h2 class="text-2xl font-bold text-center mb-6 text-slate-700 dark:text-slate-200">Flashcard Glossary</h2>
                <div class="flashcard-container">
                    <div id="flashcard" class="flashcard" onclick="this.classList.toggle('is-flipped')">
                        <div class="flashcard-face bg-slate-800 text-white"><h3 id="flashcard-term" class="text-2xl font-bold"></h3></div>
                        <div class="flashcard-face bg-slate-100 dark:bg-slate-700 text-slate-800 dark:text-slate-200" style="transform: rotateY(180deg);"><p id="flashcard-definition"></p></div>
                    </div>
                </div>
                <div class="flex justify-between items-center mt-6">
                    <button onclick="navigateCard(-1)" class="bg-slate-200 dark:bg-slate-600 text-slate-700 dark:text-slate-200 font-bold py-2 px-4 rounded-lg">&larr; Previous</button>
                    <p id="card-counter" class="text-sm text-slate-500 dark:text-slate-400"></p>
                    <button onclick="navigateCard(1)" class="bg-slate-200 dark:bg-slate-600 text-slate-700 dark:text-slate-200 font-bold py-2 px-4 rounded-lg">Next &rarr;</button>
                </div>
                <button onclick="showView('main-menu')" class="mt-8 w-full text-slate-600 dark:text-slate-400 font-semibold py-2 px-4 rounded-lg hover:bg-slate-100 dark:hover:bg-slate-700 transition">Back to Main Menu</button>
            </div>

            <!-- Performance Area -->
            <div id="performance-area" class="hidden main-card">
                <h2 class="text-2xl font-bold text-center mb-6 text-slate-700 dark:text-slate-200">Your Progress</h2>
                <div id="performance-stats" class="space-y-4"></div>
                <button onclick="showView('main-menu')" class="mt-8 w-full text-slate-600 dark:text-slate-400 font-semibold py-2 px-4 rounded-lg hover:bg-slate-100 dark:hover:bg-slate-700 transition">Back to Main Menu</button>
            </div>
        </div>

        <!-- Persistent AI Chat Sidebar -->
        <div id="ai-chat-sidebar" class="md:w-1/3 flex flex-col bg-slate-50 dark:bg-slate-900 rounded-lg p-4 h-[85vh]">
            <h2 class="text-xl font-bold text-center mb-4 border-b dark:border-slate-700 pb-3">AI Study Buddy</h2>
            <div id="chat-messages" class="flex-grow overflow-y-auto pr-2 flex flex-col space-y-2 mb-4">
                <div class="chat-message ai-message">Hello! I'm your AI Study Buddy. Ask me anything about the Florida Life & Health insurance exam.</div>
            </div>
            <div id="chat-input-area" class="flex gap-2">
                <input type="text" id="chat-input" class="flex-grow border-2 border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 rounded-lg p-2 focus:outline-none focus:ring-2 focus:ring-purple-500" placeholder="Ask a question...">
                <button id="chat-send-btn" class="bg-purple-600 text-white font-semibold py-2 px-4 rounded-lg hover:bg-purple-700 transition">Send</button>
            </div>
        </div>
        
        <!-- Mode Selection Modal -->
        <div id="mode-selection-modal" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4">
            <div class="bg-white dark:bg-slate-800 rounded-lg p-8 text-center">
                <h2 class="text-xl font-bold mb-4 text-slate-700 dark:text-slate-200">Choose Your Challenge</h2>
                <div class="flex gap-4">
                    <button onclick="startPracticeExam('study')" class="bg-sky-500 text-white font-semibold py-2 px-6 rounded-lg flex-1">Study Mode</button>
                    <button onclick="startPracticeExam('timed')" class="bg-red-500 text-white font-semibold py-2 px-6 rounded-lg flex-1">Timed Mode</button>
                </div>
                <button onclick="document.getElementById('mode-selection-modal').classList.add('hidden')" class="text-slate-500 dark:text-slate-400 mt-6 text-sm">Cancel</button>
            </div>
        </div>
    </div>

    <script>
        // --- DATA BANK ---
        const questionBank = {
            general: [
                { q: "What type of contract legally binds only one party to its obligations?", a: ["Bilateral", "Unilateral", "Aleatory", "Adhesion"], c: 1, e: "A Unilateral contract, like an insurance policy, legally obligates only one party (the insurer) to perform as long as the other party (the insured) pays the premium." },
                { q: "What is the term for a cause of loss, such as a fire or a car accident?", a: ["Hazard", "Risk", "Peril", "Exposure"], c: 2, e: "A Peril is the direct cause of a loss. A hazard is a condition that increases the chance of a peril occurring." },
                { q: "The process insurance companies use to select, classify, and rate risks is called:", a: ["Actuarial Science", "Claims Adjustment", "Underwriting", "Marketing"], c: 2, e: "Underwriting is the fundamental process of evaluating an applicant to determine if they are insurable and, if so, at what premium." },
                { q: "A contract of adhesion is one where the terms are set by one party and the other party can only 'take it or leave it'. Who prepares this contract in insurance?", a: ["The Insured", "The Agent", "The Insurer", "The State"], c: 2, e: "The Insurer (insurance company) writes the policy language. Because of this, any ambiguities in the contract are typically ruled in favor of the insured." },
                { q: "Which of the following represents a pure risk?", a: ["Investing in stocks", "Playing poker", "The chance of your house burning down", "Starting a new business"], c: 2, e: "A pure risk involves only the possibility of loss or no loss, with no chance for financial gain. All other options are speculative risks." },
            ],
            life: [
                { q: "A life insurance policy where the policyowner can change the beneficiary is called:", a: ["Irrevocable", "Fixed", "Revocable", "Conditional"], c: 2, e: "A Revocable beneficiary designation gives the policyowner the right to change the beneficiary at any time without their consent." },
                { q: "Which type of life insurance provides permanent protection and builds cash value?", a: ["Term Life", "Whole Life", "Credit Life", "Group Life"], c: 1, e: "Whole Life insurance is designed to last for the insured's entire life and includes a savings component (cash value) that grows over time." },
                { q: "What is the term for a written modification attached to a policy that changes its coverage?", a: ["Endorsement", "Rider", "Provision", "Clause"], c: 1, e: "A Rider is an add-on to a policy that modifies its terms, either by adding or excluding coverage. It is also sometimes called an endorsement." },
                { q: "If an insured commits suicide within the time specified in the suicide clause, what will the insurer pay?", a: ["The full death benefit", "Nothing", "A refund of the premiums paid", "The cash value"], c: 2, e: "The suicide clause, typically for the first 2 years of the policy, stipulates that the insurer will not pay the death benefit but will return all premiums paid if the insured commits suicide during this period." },
                { q: "What is it called when the policyowner and the insured are two different people?", a: ["Key Person Insurance", "Split-Dollar Plan", "Third-Party Ownership", "Cross-Purchase Agreement"], c: 2, e: "Third-Party Ownership occurs when a person buys an insurance policy on someone else's life, such as a spouse insuring their partner or a business insuring a key employee." },
            ],
            health: [
                { q: "A health insurance policy that pays a flat amount per day of hospitalization, regardless of the actual medical expenses, is known as:", a: ["Major Medical", "Indemnity Plan", "HMO", "PPO"], c: 1, e: "A Hospital Indemnity Plan pays a fixed benefit for each day the insured is hospitalized. This payment is made directly to the insured, not the medical provider." },
                { q: "Which of the following is NOT a characteristic of a Health Maintenance Organization (HMO)?", a: ["Requires a Primary Care Physician (PCP)", "Focuses on preventive care", "Freedom to see any provider without a referral", "Operates within a specific geographic area"], c: 2, e: "HMOs are characterized by their managed care model, which requires referrals from a PCP to see specialists and restricts care to a network of providers. Freedom to see any provider is a feature of PPO or indemnity plans." },
                { q: "The period during which a new health insurance policy will not cover sickness-related losses is called the:", a: ["Grace Period", "Free Look Period", "Incontestable Period", "Probationary Period"], c: 3, e: "The Probationary Period is a one-time period at the beginning of a policy (e.g., 15 or 30 days) during which pre-existing conditions or sicknesses are not covered." },
                { q: "What is the name of the federal law that protects consumers from the circulation of inaccurate or obsolete personal or financial information?", a: ["HIPAA", "Fair Credit Reporting Act (FCRA)", "COBRA", "ERISA"], c: 1, e: "The Fair Credit Reporting Act (FCRA) ensures that consumer reporting agencies are fair and equitable in their treatment of consumers' information." },
                 { q: "What disability insurance rider allows an insured to purchase additional amounts of disability income coverage at future dates without evidence of insurability?", a: ["Cost of Living Adjustment (COLA) Rider", "Guaranteed Insurability Rider", "Waiver of Premium Rider", "Social Security Rider"], c: 1, e: "The Guaranteed Insurability Rider (also known as Future Increase Option) allows the policyowner to increase their benefits at specified future times without needing to prove their health." },
            ],
            florida_rules: [
                { q: "In Florida, offering a client free tickets to a sporting event in exchange for buying an insurance policy is an illegal practice known as:", a: ["Twisting", "Sliding", "Coercion", "Rebating"], c: 3, e: "Rebating is the illegal act of offering any inducement in the sale of insurance that is not specified in the policy, such as cash, gifts, or services." },
                { q: "An agent who handles insurance funds must act in a trustworthy capacity. This is known as their:", a: ["Contractual Responsibility", "Fiduciary Responsibility", "Ethical Duty", "Legal Obligation"], c: 1, e: "An agent has a Fiduciary Responsibility to handle the funds of their clients and insurers with the utmost trust and integrity, accounting for and remitting them promptly." },
                { q: "In Florida, what are the three types of agent authority?", a: ["State, Federal, and Local", "Limited, General, and Universal", "Implied, Express, and Apparent", "Primary, Secondary, and Tertiary"], c: 2, e: "Express authority is written in the contract. Implied authority is not written but is necessary to conduct business. Apparent authority is what the public reasonably believes the agent has, based on the insurer's actions." },
                 { q: "An insurer that meets Florida's financial requirements and is approved to transact business in the state is considered a(n) _______ insurer.", a: ["Domestic", "Admitted or Authorized", "Certified", "Non-admitted"], c: 1, e: "An Authorized or Admitted insurer has been issued a Certificate of Authority from the Florida Office of Insurance Regulation, permitting them to sell insurance in the state." },
                { q: "The illegal practice of misrepresenting a policy's terms to induce a policyowner to lapse or switch policies is called:", a: ["Defamation", "Twisting", "Rebating", "Sliding"], c: 1, e: "Twisting involves making incomplete or fraudulent comparisons of policies to convince someone to change their insurance, to the detriment of the policyowner." },
            ]
        };

        const flashcards = [
            { term: "Rider", def: "A written modification attached to a policy that increases or decreases coverage and/or premiums." },
            { term: "Unilateral Contract", def: "A contract where only one of the parties is legally bound to fulfill its obligations after the premium is paid." },
            { term: "Fair Credit Reporting Act", def: "A federal law that protects consumers from the circulation of inaccurate or obsolete personal or financial information." },
            { term: "Agent Authority", def: "The three types are Express (written), Implied (assumed for business), and Apparent (perceived by the public)." },
            { term: "Fiduciary", def: "A person in a position of special trust and confidence, such as an agent handling insurance funds for clients and insurers." },
            { term: "Rebating", def: "The illegal act of offering any inducement (like cash or gifts) not specified in the policy to persuade a client to purchase it." },
            { term: "Authorized Insurer", def: "An insurer who has received a Certificate of Authority from the state's department of insurance and is approved to transact business." },
            { term: "Peril", def: "The specific cause of a loss insured against in a policy, such as a fire, hurricane, or sickness." },
            { term: "Hazard", def: "A condition or situation that increases the probability of a peril occurring. (e.g., storing oily rags is a hazard that increases the peril of fire)." },
            { term: "Contract of Adhesion", def: "A contract offered on a 'take-it-or-leave-it' basis by an insurer, where any ambiguity is ruled in favor of the insured." },
            { term: "Aleatory Contract", def: "A contract in which the participating parties agree to an unequal exchange of value. The premium paid is small compared to the potential benefit." },
            { term: "Twisting", def: "The illegal practice of making misleading comparisons to induce a policyholder to switch policies to their detriment." },
            { term: "Disclosure", def: "The act of providing all relevant and sufficient information to help someone make an informed decision, as required of agents." },
        ];

        // --- STATE MANAGEMENT ---
        let currentView = 'main-menu';
        let currentQuestions = [];
        let currentQuestionIndex = 0;
        let score = 0;
        let selectedAnswers = {};
        let timer;
        let timeLeft;
        let currentCardIndex = 0;
        let performanceData = {
            general: { scores: [], average: 0 },
            life: { scores: [], average: 0 },
            health: { scores: [], average: 0 },
            florida_rules: { scores: [], average: 0 },
            practice: { scores: [], average: 0 }
        };

        // --- ELEMENT SELECTORS ---
        const allViews = document.querySelectorAll('#main-content-area .main-card');
        const darkModeToggle = document.getElementById('dark-mode-toggle');
        const sunIcon = document.getElementById('sun-icon');
        const moonIcon = document.getElementById('moon-icon');
        const htmlEl = document.documentElement;
        // (Other selectors will be defined inside functions for specificity)

        // --- DARK MODE LOGIC ---
        const applyTheme = (theme) => {
            if (theme === 'dark') {
                htmlEl.classList.add('dark');
                sunIcon.classList.add('hidden');
                moonIcon.classList.remove('hidden');
            } else {
                htmlEl.classList.remove('dark');
                sunIcon.classList.remove('hidden');
                moonIcon.classList.add('hidden');
            }
        };

        darkModeToggle.addEventListener('click', () => {
            const isDark = htmlEl.classList.contains('dark');
            const newTheme = isDark ? 'light' : 'dark';
            localStorage.setItem('theme', newTheme);
            applyTheme(newTheme);
        });

        // --- CORE APP LOGIC ---
        function showView(viewId) {
            allViews.forEach(view => view.classList.add('hidden'));
            document.getElementById(viewId).classList.remove('hidden');
            currentView = viewId;

            if (viewId === 'flashcard-area') loadFlashcard();
            if (viewId === 'performance-area') updatePerformanceDisplay();
            if (viewId === 'main-menu') {
                document.getElementById('quiz-area').classList.add('hidden');
                document.getElementById('results-area').classList.add('hidden');
            }
        }
        
        function startQuiz(topic) {
            currentQuestions = [...questionBank[topic]].sort(() => 0.5 - Math.random());
            currentQuestionIndex = 0;
            score = 0;
            selectedAnswers = {};
            document.getElementById('quiz-topic-title').textContent = document.querySelector(`button[onclick="startQuiz('${topic}')"]`).textContent;
            showView('quiz-area');
            displayQuestion();
        }

        function displayQuestion() {
            const question = currentQuestions[currentQuestionIndex];
            document.getElementById('question-text').textContent = question.q;
            const optionsContainer = document.getElementById('options-container');
            optionsContainer.innerHTML = '';
            question.a.forEach((option, index) => {
                const optionEl = document.createElement('button');
                optionEl.className = "w-full text-left p-4 rounded-lg border-2 border-slate-300 dark:border-slate-600 hover:bg-slate-100 dark:hover:bg-slate-700 transition";
                optionEl.textContent = option;
                optionEl.onclick = () => selectAnswer(index, optionEl);
                optionsContainer.appendChild(optionEl);
            });
            document.getElementById('question-counter').textContent = `Question ${currentQuestionIndex + 1} of ${currentQuestions.length}`;
            document.getElementById('progress-bar').style.width = `${((currentQuestionIndex) / currentQuestions.length) * 100}%`;
            document.getElementById('submit-btn').disabled = true;
            document.getElementById('next-btn').classList.add('hidden');
            document.getElementById('explanation-container').innerHTML = '';
        }

        function selectAnswer(index, element) {
            const options = document.getElementById('options-container').children;
            for (let i = 0; i < options.length; i++) {
                options[i].classList.remove('bg-sky-200', 'dark:bg-sky-800', 'border-sky-500');
            }
            element.classList.add('bg-sky-200', 'dark:bg-sky-800', 'border-sky-500');
            selectedAnswers[currentQuestionIndex] = index;
            document.getElementById('submit-btn').disabled = false;
        }

        function submitAnswer() {
            const question = currentQuestions[currentQuestionIndex];
            const selectedAnswer = selectedAnswers[currentQuestionIndex];
            const options = document.getElementById('options-container').children;

            // Disable all option buttons
            for (let i = 0; i < options.length; i++) {
                options[i].disabled = true;
                options[i].classList.remove('hover:bg-slate-100', 'dark:hover:bg-slate-700');
            }
            
            const explanationContainer = document.getElementById('explanation-container');
            explanationContainer.innerHTML = `<div class="p-4 rounded-lg bg-slate-100 dark:bg-slate-700 mt-4"><p class="font-bold">Explanation:</p><p>${question.e}</p></div>`;
            setTimeout(() => {
                explanationContainer.firstElementChild.style.maxHeight = '200px';
            }, 10);
            
            if (selectedAnswer === question.c) {
                score++;
                options[selectedAnswer].classList.add('bg-green-200', 'dark:bg-green-800', 'border-green-500');
            } else {
                options[selectedAnswer].classList.add('bg-red-200', 'dark:bg-red-800', 'border-red-500');
                options[question.c].classList.add('bg-green-200', 'dark:bg-green-800', 'border-green-500');
            }

            document.getElementById('submit-btn').classList.add('hidden');
            document.getElementById('next-btn').classList.remove('hidden');
            document.getElementById('next-btn').textContent = (currentQuestionIndex === currentQuestions.length - 1) ? 'Finish Quiz' : 'Next';
        }

        function nextQuestion() {
            if (currentQuestionIndex < currentQuestions.length - 1) {
                currentQuestionIndex++;
                displayQuestion();
                document.getElementById('submit-btn').classList.remove('hidden');
                document.getElementById('next-btn').classList.add('hidden');
            } else {
                endQuiz();
            }
        }
        
        function endQuiz() {
             const finalScore = Math.round((score / currentQuestions.length) * 100);
            document.getElementById('final-score').textContent = finalScore;
            document.getElementById('score-summary').textContent = `You answered ${score} out of ${currentQuestions.length} questions correctly.`;
            
            const scoreCircle = document.getElementById('score-circle');
            scoreCircle.className = "w-32 h-32 rounded-full mx-auto flex items-center justify-center mb-6 text-white";
            if(finalScore >= 70) {
                scoreCircle.classList.add('bg-green-500');
            } else if (finalScore >= 50) {
                scoreCircle.classList.add('bg-amber-500');
            } else {
                scoreCircle.classList.add('bg-red-500');
            }
            
            showView('results-area');
        }

        // --- FLASHCARD LOGIC ---
        function loadFlashcard() {
            const card = flashcards[currentCardIndex];
            document.getElementById('flashcard-term').textContent = card.term;
            document.getElementById('flashcard-definition').textContent = card.def;
            document.getElementById('card-counter').textContent = `${currentCardIndex + 1} / ${flashcards.length}`;
            document.getElementById('flashcard').classList.remove('is-flipped');
        }

        function navigateCard(direction) {
            currentCardIndex += direction;
            if (currentCardIndex < 0) currentCardIndex = flashcards.length - 1;
            if (currentCardIndex >= flashcards.length) currentCardIndex = 0;
            loadFlashcard();
        }
        
        // --- PERFORMANCE LOGIC ---
        function updatePerformanceDisplay() {
            // This is a placeholder for a more complex implementation
             document.getElementById('performance-stats').innerHTML = `<p class="text-center text-slate-500">Performance tracking coming soon!</p>`;
        }
        
        // --- PRACTICE EXAM LOGIC ---
        function promptExamMode() {
            document.getElementById('mode-selection-modal').classList.remove('hidden');
        }
        
        // --- AI CHATBOT LOGIC ---
        const chatInput = document.getElementById('chat-input');
        const chatSendBtn = document.getElementById('chat-send-btn');
        const chatMessagesContainer = document.getElementById('chat-messages');

        const appendMessage = (text, sender) => {
            const messageDiv = document.createElement('div');
            messageDiv.textContent = text;
            messageDiv.className = `chat-message ${sender}-message`;
            chatMessagesContainer.appendChild(messageDiv);
            chatMessagesContainer.scrollTop = chatMessagesContainer.scrollHeight;
        };
        
        const showTypingIndicator = () => {
            const indicatorDiv = document.createElement('div');
            indicatorDiv.id = 'typing-indicator';
            indicatorDiv.textContent = 'AI Buddy is typing...';
            indicatorDiv.className = 'typing-indicator dark:text-slate-400';
            chatMessagesContainer.appendChild(indicatorDiv);
            chatMessagesContainer.scrollTop = chatMessagesContainer.scrollHeight;
        };

        const removeTypingIndicator = () => {
            const indicator = document.getElementById('typing-indicator');
            if (indicator) indicator.remove();
        };

        const fetchWithRetry = async (url, options, retries = 3, delay = 1000) => {
            for (let i = 0; i < retries; i++) {
                try {
                    const response = await fetch(url, options);
                    if (response.ok) return response;
                } catch (error) { console.error("Fetch attempt failed:", error); }
                await new Promise(res => setTimeout(res, delay * Math.pow(2, i)));
            }
            throw new Error('API request failed after multiple retries.');
        };

        const handleChatMessage = async () => {
            const userQuery = chatInput.value.trim();
            if (!userQuery) return;

            appendMessage(userQuery, 'user');
            chatInput.value = '';
            showTypingIndicator();

            const apiKey = "";
            const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-09-2025:generateContent?key=${apiKey}`;
            const systemPrompt = "You are a friendly and encouraging AI tutor. Your sole purpose is to help users study for the Florida Life & Health insurance exam. Explain concepts clearly, concisely, and in simple terms. If asked a question outside of this topic, gently guide the user back to insurance-related subjects.";

            const payload = {
                contents: [{ parts: [{ text: userQuery }] }],
                systemInstruction: { parts: [{ text: systemPrompt }] },
            };

            try {
                const response = await fetchWithRetry(apiUrl, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(payload)
                });

                const result = await response.json();
                const aiResponse = result.candidates?.[0]?.content?.parts?.[0]?.text || "Sorry, I couldn't process that. Could you ask in another way?";
                
                removeTypingIndicator();
                appendMessage(aiResponse, 'ai');

            } catch (error) {
                removeTypingIndicator();
                appendMessage("I'm having a little trouble connecting right now. Please try again in a moment.", 'ai');
            }
        };

        chatSendBtn.addEventListener('click', handleChatMessage);
        chatInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter') handleChatMessage();
        });
        
        // --- Initial setup ---
        document.addEventListener('DOMContentLoaded', () => {
            const savedTheme = localStorage.getItem('theme') || 'light';
            applyTheme(savedTheme);
            showView('main-menu'); 
        });

    </script>
</body>
</html>