File size: 43,533 Bytes
a6c4032
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Punjab Board Paper Generator - BISE Gujranwala</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/lucide@latest"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Nastaliq+Urdu&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Inter', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
        }
        .urdu-text {
            font-family: 'Noto Nastaliq Urdu', serif;
            line-height: 2.5;
        }
        .paper-sheet {
            background: white;
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
            min-height: 297mm;
        }
        .subject-card {
            transition: all 0.3s ease;
            cursor: pointer;
        }
        .subject-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
        }
        .subject-card.active {
            border-color: #667eea;
            background-color: #f0f4ff;
            transform: scale(1.05);
        }
        @media print {
            body { background: white; }
            .no-print { display: none !important; }
            .paper-sheet { box-shadow: none; }
        }
        .section-divider {
            border-top: 2px dashed #cbd5e1;
            margin: 2rem 0;
        }
        .question-edit:focus {
            outline: 2px solid #667eea;
            background-color: #f8fafc;
            padding: 0.5rem;
            border-radius: 0.375rem;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
    </style>
</head>
<body class="p-4 md:p-8">

    <!-- Header -->
    <header class="no-print text-white mb-8 text-center">
        <div class="flex justify-center items-center gap-3 mb-2">
            <i data-lucide="file-text" class="w-10 h-10"></i>
            <h1 class="text-3xl md:text-4xl font-bold">Punjab Board Paper Generator</h1>
        </div>
        <p class="text-white/80 text-lg">BISE Gujranwala | 9th & 10th Class Examination System</p>
        <div class="mt-2 text-sm text-white/60">بورڈ آف انٹرمیڈیٹ اینڈ سیکنڈری ایجوکیشن گوجرانوالہ</div>
    </header>

    <!-- Main Container -->
    <div class="max-w-6xl mx-auto">
        
        <!-- Control Panel -->
        <div class="no-print bg-white rounded-2xl shadow-xl p-6 mb-8">
            <!-- Grade Selection -->
            <div class="mb-6">
                <label class="block text-sm font-semibold text-gray-700 mb-3 uppercase tracking-wide">Select Grade</label>
                <div class="flex gap-4">
                    <button onclick="selectGrade('9th')" id="grade-9th" class="grade-btn flex-1 py-3 px-6 rounded-xl border-2 border-gray-200 font-semibold text-gray-600 hover:border-indigo-500 hover:text-indigo-600 transition-all">
                        9th Class
                    </button>
                    <button onclick="selectGrade('10th')" id="grade-10th" class="grade-btn flex-1 py-3 px-6 rounded-xl border-2 border-gray-200 font-semibold text-gray-600 hover:border-indigo-500 hover:text-indigo-600 transition-all">
                        10th Class
                    </button>
                </div>
            </div>

            <!-- Subject Selection -->
            <div class="mb-6">
                <label class="block text-sm font-semibold text-gray-700 mb-3 uppercase tracking-wide">Select Subject</label>
                <div class="grid grid-cols-2 md:grid-cols-4 gap-4" id="subject-grid">
                    <div onclick="selectSubject('Mathematics')" class="subject-card border-2 border-gray-200 rounded-xl p-4 text-center" data-subject="Mathematics">
                        <i data-lucide="calculator" class="w-8 h-8 mx-auto mb-2 text-blue-600"></i>
                        <div class="font-semibold text-sm">Mathematics</div>
                        <div class="text-xs text-gray-500 mt-1">ریاضی</div>
                    </div>
                    <div onclick="selectSubject('Physics')" class="subject-card border-2 border-gray-200 rounded-xl p-4 text-center" data-subject="Physics">
                        <i data-lucide="atom" class="w-8 h-8 mx-auto mb-2 text-purple-600"></i>
                        <div class="font-semibold text-sm">Physics</div>
                        <div class="text-xs text-gray-500 mt-1">فزکس</div>
                    </div>
                    <div onclick="selectSubject('Chemistry')" class="subject-card border-2 border-gray-200 rounded-xl p-4 text-center" data-subject="Chemistry">
                        <i data-lucide="flask-conical" class="w-8 h-8 mx-auto mb-2 text-green-600"></i>
                        <div class="font-semibold text-sm">Chemistry</div>
                        <div class="text-xs text-gray-500 mt-1">کیمسٹری</div>
                    </div>
                    <div onclick="selectSubject('Biology')" class="subject-card border-2 border-gray-200 rounded-xl p-4 text-center" data-subject="Biology">
                        <i data-lucide="leaf" class="w-8 h-8 mx-auto mb-2 text-emerald-600"></i>
                        <div class="font-semibold text-sm">Biology</div>
                        <div class="text-xs text-gray-500 mt-1">حیاتیات</div>
                    </div>
                    <div onclick="selectSubject('Computer Science')" class="subject-card border-2 border-gray-200 rounded-xl p-4 text-center" data-subject="Computer Science">
                        <i data-lucide="monitor" class="w-8 h-8 mx-auto mb-2 text-indigo-600"></i>
                        <div class="font-semibold text-sm">Computer Science</div>
                        <div class="text-xs text-gray-500 mt-1">کمپیوٹر سائنس</div>
                    </div>
                    <div onclick="selectSubject('Islamiyat')" class="subject-card border-2 border-gray-200 rounded-xl p-4 text-center" data-subject="Islamiyat">
                        <i data-lucide="book-open" class="w-8 h-8 mx-auto mb-2 text-teal-600"></i>
                        <div class="font-semibold text-sm">Islamiyat</div>
                        <div class="text-xs text-gray-500 mt-1">اسلامیات</div>
                    </div>
                    <div onclick="selectSubject('Pakistan Studies')" class="subject-card border-2 border-gray-200 rounded-xl p-4 text-center" data-subject="Pakistan Studies">
                        <i data-lucide="map" class="w-8 h-8 mx-auto mb-2 text-red-600"></i>
                        <div class="font-semibold text-sm">Pakistan Studies</div>
                        <div class="text-xs text-gray-500 mt-1">پاکستان اسٹڈیز</div>
                    </div>
                    <div onclick="selectSubject('English')" class="subject-card border-2 border-gray-200 rounded-xl p-4 text-center" data-subject="English">
                        <i data-lucide="languages" class="w-8 h-8 mx-auto mb-2 text-orange-600"></i>
                        <div class="font-semibold text-sm">English</div>
                        <div class="text-xs text-gray-500 mt-1">انگلش</div>
                    </div>
                    <div onclick="selectSubject('Urdu')" class="subject-card border-2 border-gray-200 rounded-xl p-4 text-center col-span-2 md:col-span-1" data-subject="Urdu">
                        <i data-lucide="pen-tool" class="w-8 h-8 mx-auto mb-2 text-pink-600"></i>
                        <div class="font-semibold text-sm">Urdu</div>
                        <div class="text-xs text-gray-500 mt-1">اردو</div>
                    </div>
                </div>
            </div>

            <!-- Paper Version Selection -->
            <div class="mb-6">
                <label class="block text-sm font-semibold text-gray-700 mb-3 uppercase tracking-wide">Paper Version</label>
                <div class="flex gap-2 flex-wrap">
                    <button onclick="selectVersion('A')" id="version-A" class="version-btn px-4 py-2 rounded-lg border-2 border-indigo-500 bg-indigo-50 text-indigo-700 font-semibold text-sm">Set A</button>
                    <button onclick="selectVersion('B')" id="version-B" class="version-btn px-4 py-2 rounded-lg border-2 border-gray-200 text-gray-600 font-semibold text-sm hover:border-indigo-300">Set B</button>
                    <button onclick="selectVersion('C')" id="version-C" class="version-btn px-4 py-2 rounded-lg border-2 border-gray-200 text-gray-600 font-semibold text-sm hover:border-indigo-300">Set C</button>
                </div>
            </div>

            <!-- Options -->
            <div class="mb-6 flex flex-wrap gap-4 items-center">
                <label class="flex items-center gap-2 cursor-pointer">
                    <input type="checkbox" id="include-answer-key" class="w-5 h-5 text-indigo-600 rounded focus:ring-indigo-500" onchange="toggleAnswerKey()">
                    <span class="text-sm font-medium text-gray-700">Include Answer Key</span>
                </label>
                <label class="flex items-center gap-2 cursor-pointer">
                    <input type="checkbox" id="exam-timer" class="w-5 h-5 text-indigo-600 rounded focus:ring-indigo-500">
                    <span class="text-sm font-medium text-gray-700">Enable Exam Timer (2:30h)</span>
                </label>
            </div>

            <!-- Student Info -->
            <div class="mb-6 bg-gray-50 rounded-xl p-4 border-2 border-gray-200">
                <label class="block text-sm font-semibold text-gray-700 mb-3 uppercase tracking-wide">Student Information (Optional)</label>
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                    <input type="text" id="student-name" placeholder="Student Name" class="w-full px-4 py-2 rounded-lg border-2 border-gray-300 focus:border-indigo-500 focus:outline-none text-sm">
                    <input type="text" id="roll-number" placeholder="Roll Number" class="w-full px-4 py-2 rounded-lg border-2 border-gray-300 focus:border-indigo-500 focus:outline-none text-sm">
                    <input type="date" id="exam-date" class="w-full px-4 py-2 rounded-lg border-2 border-gray-300 focus:border-indigo-500 focus:outline-none text-sm">
                </div>
            </div>

            <!-- Action Buttons -->
            <div class="flex gap-3 flex-wrap">
                <button onclick="generatePaper()" class="flex-1 bg-gradient-to-r from-indigo-600 to-purple-600 text-white py-3 px-6 rounded-xl font-semibold hover:shadow-lg transform hover:scale-105 transition-all flex items-center justify-center gap-2">
                    <i data-lucide="file-plus"></i>
                    Generate Paper
                </button>
                <button onclick="downloadPDF()" class="flex-1 bg-red-600 text-white py-3 px-6 rounded-xl font-semibold hover:bg-red-700 transition-all flex items-center justify-center gap-2">
                    <i data-lucide="file-down"></i>
                    Download PDF
                </button>
                <button onclick="printPaper()" class="px-6 py-3 bg-gray-800 text-white rounded-xl font-semibold hover:bg-gray-900 transition-all flex items-center justify-center gap-2">
                    <i data-lucide="printer"></i>
                </button>
                <button onclick="savePaper()" class="px-6 py-3 bg-green-600 text-white rounded-xl font-semibold hover:bg-green-700 transition-all flex items-center justify-center gap-2" title="Save to Local Storage">
                    <i data-lucide="save"></i>
                </button>
                <button onclick="resetForm()" class="px-6 py-3 border-2 border-gray-300 rounded-xl font-semibold text-gray-600 hover:border-gray-400 transition-all">
                    <i data-lucide="rotate-ccw"></i>
                </button>
            </div>

            <!-- Saved Papers Section -->
            <div id="saved-papers-section" class="mt-6 pt-6 border-t-2 border-gray-200 hidden">
                <div class="flex justify-between items-center mb-3">
                    <label class="block text-sm font-semibold text-gray-700 uppercase tracking-wide">Saved Papers</label>
                    <button onclick="clearAllSaved()" class="text-xs text-red-600 hover:text-red-800 underline">Clear All</button>
                </div>
                <div id="saved-papers-list" class="grid grid-cols-1 md:grid-cols-2 gap-3 max-h-40 overflow-y-auto"></div>
            </div>
        </div>

        <!-- Timer Display (Exam Mode) -->
        <div id="timer-display" class="hidden no-print fixed top-4 right-4 bg-black text-white px-6 py-3 rounded-xl shadow-2xl z-40 border-2 border-indigo-500">
            <div class="text-xs uppercase tracking-widest mb-1 text-gray-400">Time Remaining</div>
            <div class="text-2xl font-mono font-bold" id="timer-count">02:30:00</div>
            <button onclick="stopTimer()" class="mt-2 text-xs bg-red-600 hover:bg-red-700 px-3 py-1 rounded transition-colors">Stop Timer</button>
        </div>

            <!-- Paper Display Area -->
        <div id="paper-container" class="hidden">
            <!-- Student Info Display (on paper) -->
            <div class="paper-sheet rounded-lg p-8 md:p-12 mb-8 text-gray-900" id="main-paper">
                <!-- Paper Header -->
                <div class="text-center border-b-4 border-double border-gray-800 pb-6 mb-6">
                    <div class="text-xs uppercase tracking-widest mb-1 text-gray-600">Set <span id="paper-version-display">A</span></div>
                    <div class="text-sm font-bold uppercase tracking-widest mb-2">Board of Intermediate & Secondary Education Gujranwala</div>
                    <div class="text-2xl font-bold mb-2 gradient-text">Punjab Board Examination Paper</div>
                    
                    <!-- Student Info on Paper -->
                    <div class="grid grid-cols-3 gap-4 mt-4 mb-4 p-3 bg-gray-50 rounded-lg border-2 border-gray-300 text-left">
                        <div><span class="font-bold text-gray-600">Student Name:</span> <span id="display-student-name" class="font-semibold border-b-2 border-gray-400 px-2 min-w-[100px] inline-block">_________________</span></div>
                        <div><span class="font-bold text-gray-600">Roll No:</span> <span id="display-roll-number" class="font-semibold border-b-2 border-gray-400 px-2 min-w-[80px] inline-block">__________</span></div>
                        <div><span class="font-bold text-gray-600">Date:</span> <span id="display-exam-date" class="font-semibold border-b-2 border-gray-400 px-2 min-w-[100px] inline-block">__________</span></div>
                    </div>

                    <div class="grid grid-cols-3 gap-4 mt-2 text-left border-t pt-4">
                        <div><span class="font-bold">Class:</span> <span id="paper-grade" class="font-semibold text-indigo-700"></span></div>
                        <div><span class="font-bold">Subject:</span> <span id="paper-subject" class="font-semibold text-indigo-700"></span></div>
                        <div><span class="font-bold">Total Marks:</span> 75</div>
                    </div>
                    <div class="grid grid-cols-2 gap-4 mt-2 text-left border-b pb-4">
                        <div><span class="font-bold">Time:</span> 2 Hours 30 Minutes</div>
                        <div class="text-right"><span class="font-bold">Session:</span> Annual Examination 2024</div>
                    </div>
                </div>

                <!-- Paper Content -->
                <div id="paper-content" class="prose max-w-none"></div>

                <!-- Footer -->
                <div class="mt-12 pt-6 border-t-2 border-gray-300 text-center text-sm text-gray-500 italic">
                    <p>End of Question Paper | تمام سوالات حل کریں</p>
                    <p class="mt-1 text-xs">Good Luck! | کامیابی کیلئے نیک تمنائیں</p>
                </div>
            </div>

            <!-- Answer Key Section (Hidden by default) -->
            <div id="answer-key-section" class="paper-sheet rounded-lg p-8 md:p-12 mb-8 text-gray-900 hidden" style="background: #fef3c7;">
                <div class="text-center border-b-4 border-double border-green-700 pb-6 mb-6">
                    <div class="text-2xl font-bold mb-2 text-green-800">ANSWER KEY / حل نامہ</div>
                    <div class="text-sm font-bold uppercase tracking-widest mb-2 text-green-700">Confidential - For Teachers Only</div>
                    <div class="grid grid-cols-3 gap-4 mt-4 text-left border-t pt-4">
                        <div><span class="font-bold">Class:</span> <span id="answer-grade" class="font-semibold text-green-700"></span></div>
                        <div><span class="font-bold">Subject:</span> <span id="answer-subject" class="font-semibold text-green-700"></span></div>
                        <div><span class="font-bold">Set:</span> <span id="answer-version" class="font-bold text-green-700">A</span></div>
                    </div>
                </div>
                <div id="answer-content" class="prose max-w-none"></div>
                <div class="mt-8 pt-6 border-t-2 border-green-200 text-center text-xs text-green-700">
                    <p>Note: This answer key is generated automatically and should be reviewed by subject teachers before finalization.</p>
                </div>
            </div>
        </div>

        <!-- Empty State -->
        <div id="empty-state" class="no-print text-center text-white py-20">
            <i data-lucide="clipboard-list" class="w-24 h-24 mx-auto mb-4 opacity-50"></i>
            <p class="text-xl opacity-80">Select Grade and Subject to Generate Paper</p>
            <p class="text-sm opacity-60 mt-2">گریڈ اور مضمون منتخب کریں</p>
        </div>

    </div>

    <!-- Edit Modal -->
    <div id="edit-modal" class="hidden fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4">
        <div class="bg-white rounded-2xl max-w-lg w-full p-6 transform scale-100 transition-transform">
            <h3 class="text-xl font-bold mb-4 flex items-center gap-2">
                <i data-lucide="edit-3" class="text-indigo-600"></i>
                Customize Question
            </h3>
            <div class="mb-4">
                <label class="block text-sm font-bold text-gray-700 mb-2">Original Question:</label>
                <div id="original-question" class="bg-gray-100 p-3 rounded-lg text-gray-600 text-sm italic"></div>
            </div>
            <div class="mb-6">
                <label class="block text-sm font-bold text-gray-700 mb-2">Updated Question:</label>
                <textarea id="updated-question" rows="3" class="w-full border-2 border-gray-200 rounded-lg p-3 focus:border-indigo-500 focus:outline-none resize-none"></textarea>
            </div>
            <div class="flex gap-3 justify-end">
                <button onclick="closeEditModal()" class="px-4 py-2 text-gray-600 hover:text-gray-800 font-semibold">Cancel</button>
                <button onclick="saveQuestionEdit()" class="px-6 py-2 bg-indigo-600 text-white rounded-lg font-semibold hover:bg-indigo-700 transition-colors">Save Changes</button>
            </div>
        </div>
    </div>

    <script>
        // Initialize Lucide icons
        lucide.createIcons();

        // State Management
        let currentGrade = null;
        let currentSubject = null;
        let currentEditTarget = null;
        let currentVersion = 'A';
        let timerInterval = null;
        let answerKeyMode = false;

        // Question Bank Database
        const questionBank = {
            "Mathematics": {
                mcqs: [
                    { q: "What is the value of π (pi) approximately?", options: ["3.14", "3.41", "3.12", "3.24"], answer: "A" },
                    { q: "The solution of equation x² - 5x + 6 = 0 is:", options: ["2, 3", "3, 4", "1, 6", "2, 4"], answer: "A" },
                    { q: "If log₂x = 3, then x = ?", options: ["6", "8", "9", "12"], answer: "B" },
                    { q: "The distance between points (0,0) and (3,4) is:", options: ["5", "7", "12", "25"], answer: "A" },
                    { q: "sin²θ + cos²θ = ?", options: ["0", "1", "2", "sinθ"], answer: "B" }
                ],
                shortQuestions: [
                    "Define rational number and give two examples.",
                    "Find the HCF of 12 and 18.",
                    "Solve: 2x + 5 = 15",
                    "What is the formula for area of circle?",
                    "Define Pythagoras theorem.",
                    "Convert 45° to radians.",
                    "Find the slope of line passing through (2,3) and (4,7).",
                    "What is the quadratic formula?",
                    "Define arithmetic progression."
                ],
                longQuestions: [
                    { q: "Prove that √2 is irrational.", marks: 8 },
                    { q: "Solve the system of equations: 2x + 3y = 7 and x - y = 1", marks: 8 },
                    { q: "Prove Pythagoras theorem with diagram.", marks: 8 },
                    { q: "Find the roots of equation: x² - 7x + 12 = 0 using quadratic formula.", marks: 8 }
                ]
            },
            "Physics": {
                mcqs: [
                    { q: "SI unit of force is:", options: ["Newton", "Joule", "Watt", "Pascal"], answer: "A" },
                    { q: "Acceleration due to gravity on Earth is approximately:", options: ["10 m/s²", "9.8 m/s²", "8.9 m/s²", "12 m/s²"], answer: "B" },
                    { q: "Velocity is:", options: ["Scalar", "Vector", "Constant", "None"], answer: "B" }
                ],
                shortQuestions: [
                    "Define velocity and speed. Differentiate between them.",
                    "State Newton's first law of motion.",
                    "What is the law of conservation of energy?",
                    "Define Ohm's law.",
                    "What is meant by 1 Watt power?"
                ],
                longQuestions: [
                    { q: "Derive equations of motion for uniformly accelerated motion.", marks: 8 },
                    { q: "Explain Newton's three laws of motion with examples.", marks: 8 }
                ]
            }
        };

        // Punjab Board Class Implementation
        class PunjabGujranwalaBoard {
            constructor() {
                this.generalSubjects = [
                    "Mathematics", "Physics", "Chemistry", "Biology", 
                    "Computer Science", "Islamiyat", "Pakistan Studies"
                ];
                this.languageSubjects = ["English", "Urdu"];
            }

            generatePaper({ grade, subject }) {
                if (subject === "English") {
                    return this.getEnglishStructure(grade);
                }
                if (subject === "Urdu") {
                    return this.getUrduStructure(grade);
                }
                if (this.generalSubjects.includes(subject)) {
                    return this.getGeneralStructure(grade, subject);
                }
                return "Subject not recognized.";
            }

            getEnglishStructure(grade) {
                return {
                    header: {
                        board: "Board of Intermediate & Secondary Education Gujranwala",
                        class: grade,
                        subject: "English",
                        marks: 75,
                        time: "2:30 Hours"
                    },
                    sections: [
                        {
                            title: "SECTION A – MCQs",
                            marks: 12,
                            content: [
                                "12 Objective Questions from:",
                                "• Grammar & Vocabulary",
                                "• Comprehension Passage",
                                "• Synonyms/Antonyms",
                                "Choose the correct option (A/B/C/D)"
                            ]
                        },
                        {
                            title: "SECTION B – Short Questions",
                            portions: [
                                { name: "Portion I", desc: "9 Short Questions from Text Book (Attempt any 6)", marks: "2 marks each" },
                                { name: "Portion II", desc: "9 Short Questions from Grammar Section (Attempt any 6)", marks: "2 marks each" },
                                { name: "Portion III", desc: "9 Short Questions from Translation/Paragraph (Attempt any 6)", marks: "2 marks each" }
                            ],
                            note: "Attempt any TWO portions completely"
                        },
                        {
                            title: "SECTION C – Long Questions",
                            questions: [
                                "1. Essay Writing (Choose 1 out of 3 topics) – [10 Marks]",
                                "2. Letter/Application Writing (Formal/Informal) – [8 Marks]",
                                "3. Comprehension Passage with long questions – [10 Marks]",
                                "4. Translation (Urdu to English or English to Urdu) – [8 Marks]"
                            ]
                        }
                    ],
                    instructions: [
                        "Use black/blue ink only.",
                        "Section B is compulsory to attempt any two portions.",
                        "Write neat and clean.",
                        "Mobile phones are strictly prohibited."
                    ]
                };
            }

            getUrduStructure(grade) {
                return {
                    header: {
                        board: "بورڈ آف انٹرمیڈیٹ اینڈ سیکنڈری ایجوکیشن گوجرانوالہ",
                        class: grade,
                        subject: "اردو",
                        marks: 75,
                        time: "2:30 گھنٹے"
                    },
                    sections: [
                        {
                            title: "حصہ اول – معروضی سوالات",
                            marks: 12,
                            content: [
                                "12 معروضی سوالات",
                                "• گرامر سے متعلق",
                                "• تشریح سے متعلق",
                                "• الفاظ معانی/متضادات"
                            ]
                        },
                        {
                            title: "حصہ دوم – مختصر سوالات",
                            portions: [
                                { name: "حصہ نمبر ۱", desc: "نصابی کتاب سے 9 سوالات (کوئی 6 حل کریں)", marks: "2 نمبر" },
                                { name: "حصہ نمبر ۲", desc: "گرامر سے 9 سوالات (کوئی 6 حل کریں)", marks: "2 نمبر" },
                                { name: "حصہ نمبر ۳", desc: "تشریح/ترجمہ سے 9 سوالات (کوئی 6 حل کریں)", marks: "2 نمبر" }
                            ],
                            note: "کسی بھی دو حصے مکمل حل کریں"
                        },
                        {
                            title: "حصہ سوم – طویل سوالات",
                            questions: [
                                "۱. مضمون نویسی (۳ میں سے ۱) – [۱۰ نمبر]",
                                "۲. خط/درخواست نویسی – [۸ نمبر]",
                                "۳. تشریح (آنے والے اقتباسات میں سے) – [۱۰ نمبر]",
                                "۴. ترجمہ – [۸ نمبر]"
                            ]
                        }
                    ],
                    instructions: [
                        "نیلے یا سیاہ ink کا استعمال کریں۔",
                        "دو حصوں کا حل کرنا لازمی ہے۔",
                        "صاف ستھرا لکھیں۔",
                        "موبائل فون ممنوع ہے۔"
                    ]
                };
            }

            getGeneralStructure(grade, subject) {
                // Shuffle chapters based on version for variety
                const versionOffset = currentVersion.charCodeAt(0) - 65; // 0 for A, 1 for B, 2 for C
                const chapters1 = `Chapters ${1 + versionOffset}-${6 + versionOffset}`;
                const chapters2 = `Chapters ${7 + versionOffset}-${12 + versionOffset}`;
                
                return {
                    header: {
                        board: "Board of Intermediate & Secondary Education Gujranwala",
                        class: grade,
                        subject: subject,
                        marks: 75,
                        time: "2:30 Hours"
                    },
                    sections: [
                        {
                            title: "SECTION A – Objective Type",
                            marks: 12,
                            content: [
                                "12 Multiple Choice Questions (MCQs)",
                                "Each question carries 1 mark",
                                "Covering full syllabus content",
                                "No negative marking",
                                `Version Set: ${currentVersion} (Questions may vary from other sets)`
                            ]
                        },
                        {
                            title: "SECTION B – Short Questions",
                            portions: [
                                { name: "Portion I", desc: `9 Short Questions from ${chapters1} (Attempt any 6)`, marks: "2 marks each" },
                                { name: "Portion II", desc: `9 Short Questions from ${chapters2} (Attempt any 6)`, marks: "2 marks each" },
                                { name: "Portion III", desc: "9 Short Questions from Practical/Theory Mix (Attempt any 6)", marks: "2 marks each" }
                            ],
                            note: `Attempt any TWO portions completely. Total marks: 24 | Set ${currentVersion}`
                        },
                        {
                            title: "SECTION C – Detailed Questions",
                            questions: [
                                `1. Long Question from Core Theory (Set ${currentVersion}) - [8 Marks]`,
                                `2. Numerical Problem (if applicable) - [8 Marks]`,
                                `3. Diagram/Explanation Question - [8 Marks]`,
                                `4. Practical/Application Based - [8 Marks]`
                            ],
                            note: "Attempt any TWO questions. Each carries 8 marks."
                        }
                    ],
                    instructions: [
                        "Attempt all questions according to instructions.",
                        "Write your Roll Number clearly on the top of this page.",
                        "Use of scientific calculator allowed (except programming subjects).",
                        "For numericals, show complete working.",
                        "Follow Punjab Board marking scheme.",
                        `This is Set ${currentVersion}. Do not mix with other sets.`
                    ],
                    subjectSpecific: this.getSubjectNotes(subject)
                };
            }

            getSubjectNotes(subject) {
                const notes = {
                    "Mathematics": "• Theorems must be proved with proper statements\n• Diagrams should be neat and labeled",
                    "Physics": "• Units must be written in numericals\n• Derivation steps carry marks",
                    "Chemistry": "• Chemical equations must be balanced\n• Structures should be clear",
                    "Biology": "• Label diagrams properly\n• Technical terms must be accurate",
                    "Computer Science": "• Write programs with comments\n• Flow charts carry separate marks"
                };
                return notes[subject] || "";
            }

            customizeQuestion(original, updated) {
                return {
                    success: true,
                    original,
                    updated,
                    timestamp: new Date().toISOString()
                };
            }
        }

        // Version Selection
        function selectVersion(version) {
            currentVersion = version;
            document.querySelectorAll('.version-btn').forEach(btn => {
                btn.classList.remove('border-indigo-500', 'bg-indigo-50', 'text-indigo-700');
                btn.classList.add('border-gray-200', 'text-gray-600');
            });
            document.getElementById(`version-${version}`).classList.add('border-indigo-500', 'bg-indigo-50', 'text-indigo-700');
            document.getElementById(`version-${version}`).classList.remove('border-gray-200', 'text-gray-600');
        }

        // Toggle Answer Key
        function toggleAnswerKey() {
            answerKeyMode = document.getElementById('include-answer-key').checked;
            const answerSection = document.getElementById('answer-key-section');
            if (answerSection) {
                if (answerKeyMode && !answerSection.classList.contains('hidden')) {
                    // Already visible
                } else if (!answerKeyMode) {
                    answerSection.classList.add('hidden');
                }
            }
        }

        // Timer Functions
        function startTimer() {
            if (timerInterval) clearInterval(timerInterval);
            let hours = 2, minutes = 30, seconds = 0;
            const display = document.getElementById('timer-count');
            const timerDisplay = document.getElementById('timer-display');
            
            timerDisplay.classList.remove('hidden');
            
            timerInterval = setInterval(() => {
                if (seconds === 0) {
                    if (minutes === 0) {
                        if (hours === 0) {
                            clearInterval(timerInterval);
                            alert("Time's up! Exam finished.");
                            return;
                        }
                        hours--;
                        minutes = 59;
                    } else {
                        minutes--;
                    }
                    seconds = 59;
                } else {
                    seconds--;
                }
                
                display.textContent = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
                
                // Warning colors
                if (hours === 0 && minutes < 15) {
                    display.classList.add('text-red-500');
                    display.parentElement.classList.add('border-red-500');
                }
            }, 1000);
        }

        function stopTimer() {
            if (timerInterval) {
                clearInterval(timerInterval);
                timerInterval = null;
            }
            document.getElementById('timer-display').classList.add('hidden');
        }

        // Save Paper to LocalStorage
        function savePaper() {
            if (!currentGrade || !currentSubject) {
                alert('Please generate a paper first!');
                return;
            }
            
            const paperData = {
                grade: currentGrade,
                subject: currentSubject,
                version: currentVersion,
                date: new Date().toISOString(),
                content: document.getElementById('paper-content').innerHTML,
                studentInfo: {
                    name: document.getElementById('student-name').value,
                    rollNo: document.getElementById('roll-number').value,
                    examDate: document.getElementById('exam-date').value
                }
            };
            
            let saved = JSON.parse(localStorage.getItem('punjabBoardPapers') || '[]');
            saved.unshift(paperData);
            if (saved.length > 10) saved = saved.slice(0, 10); // Keep only last 10
            localStorage.setItem('punjabBoardPapers', JSON.stringify(saved));
            
            loadSavedPapers();
            alert('Paper saved successfully!');
        }

        function loadSavedPapers() {
            const saved = JSON.parse(localStorage.getItem('punjabBoardPapers') || '[]');
            const container = document.getElementById('saved-papers-section');
            const list = document.getElementById('saved-papers-list');
            
            if (saved.length === 0) {
                container.classList.add('hidden');
                return;
            }
            
            container.classList.remove('hidden');
            list.innerHTML = saved.map((paper, index) => `
                <div class="bg-white border-2 border-gray-200 rounded-lg p-3 flex justify-between items-center hover:border-indigo-300 transition-colors">
                    <div class="overflow-hidden">
                        <div class="font-semibold text-sm truncate">${paper.subject} - ${paper.grade}</div>
                        <div class="text-xs text-gray-500">Set ${paper.version} • ${new Date(paper.date).toLocaleDateString()}</div>
                    </div>
                    <button onclick="loadPaper(${index})" class="ml-2 px-3 py-1 bg-indigo-100 text-indigo-700 rounded-lg text-xs font-semibold hover:bg-indigo-200">
                        Load
                    </button>
                </div>
            `).join('');
        }

        function loadPaper(index) {
            const saved = JSON.parse(localStorage.getItem('punjabBoardPapers') || '[]');
            if (saved[index]) {
                const paper = saved[index];
                selectGrade(paper.grade);
                selectSubject(paper.subject);
                selectVersion(paper.version);
                
                document.getElementById('student-name').value = paper.studentInfo?.name || '';
                document.getElementById('roll-number').value = paper.studentInfo?.rollNo || '';
                document.getElementById('exam-date').value = paper.studentInfo?.examDate || '';
                
                document.getElementById('paper-content').innerHTML = paper.content;
                document.getElementById('paper-container').classList.remove('hidden');
                document.getElementById('empty-state').classList.add('hidden');
                
                // Update display
                document.getElementById('paper-grade').textContent = paper.grade;
                document.getElementById('paper-subject').textContent = paper.subject;
                document.getElementById('paper-version-display').textContent = paper.version;
                
                lucide.createIcons();
            }
        }

        function clearAllSaved() {
            if (confirm('Clear all saved papers?')) {
                localStorage.removeItem('punjabBoardPapers');
                document.getElementById('saved-papers-section').classList.add('hidden');
            }
        }

        // PDF Download using html2canvas + jsPDF
        async function downloadPDF() {
            const paperContainer = document.getElementById('main-paper');
            if (!paperContainer || paperContainer.classList.contains('hidden')) {
                alert('Please generate a paper first!');
                return;
            }
            
            const { jsPDF } = window.jspdf;
            const pdf = new jsPDF('p', 'mm', 'a4');
            
            try {
                const canvas = await html2canvas(paperContainer, {
                    scale: 2,
                    useCORS: true,
                    allowTaint: true,
                    backgroundColor: '#ffffff'
                });
                
                const imgData = canvas.toDataURL('image/png');
                const imgWidth = 210; // A4 width in mm
                const pageHeight = 297; // A4 height in mm
                const imgHeight = (canvas.height * imgWidth) / canvas.width;
                
                let heightLeft = imgHeight;
                let position = 0;
                
                pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
                heightLeft -= pageHeight;
                
                // Add new pages if content overflows
                while (heightLeft > 0) {
                    position = heightLeft - imgHeight;
                    pdf.addPage();
                    pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
                    heightLeft -= pageHeight;
                }
                
                // Add answer key if enabled
                if (answerKeyMode && !document.getElementById('answer-key-section').classList.contains('hidden')) {
                    pdf.addPage();
                    const answerCanvas = await html2canvas(document.getElementById('answer-key-section'), {
                        scale: 2,
                        backgroundColor: '#fef3c7'
                    });
                    const answerImg = answerCanvas.toDataURL('image/png');
                    const ansHeight = (answerCanvas.height * imgWidth) / answerCanvas.width;
                    pdf.addImage(answerImg, 'PNG', 0, 0, imgWidth, ansHeight);
                }
                
                const fileName = `Punjab_Board_${currentSubject}_Class${currentGrade}_Set${currentVersion}.pdf`;
                pdf.save(fileName);
                
            } catch (error) {
                console.error('PDF generation failed:', error);
                alert('Failed to generate PDF. Please try printing instead.');
            }
        }

        // UI Functions
        function selectGrade(grade) {
            currentGrade = grade;
            document.querySelectorAll('.grade-btn').forEach(btn => {
                btn.classList.remove('border-indigo-500', 'text-indigo-600', 'bg-indigo-50');
                btn.classList.add('border-gray-200');
            });
<script src="https://deepsite.hf.co/deepsite-badge.js"></script>