-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathfunc.py
More file actions
3823 lines (3337 loc) · 138 KB
/
func.py
File metadata and controls
3823 lines (3337 loc) · 138 KB
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
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
╔══════════════════════════════════════════════════════════════════════════╗
║ QUIZBOT — Core Utilities ║
║ ║
║ Shared helpers: quiz rendering, HTML generation, image processing, ║
║ premium checks, text cleaning, and MongoDB abstractions. ║
║ ║
║ Sponsored by : Qzio — qzio.in ║
║ Developed by : devgagan — devgagan.in ║
║ License : MIT ║
╚══════════════════════════════════════════════════════════════════════════╝
"""
import asyncio
import concurrent.futures
import json
import logging
import os
import random
import re
import time
import uuid
from datetime import datetime, timedelta
from bs4 import BeautifulSoup
from config import MONGO_URI, DB_NAME
from motor.motor_asyncio import AsyncIOMotorClient
from PIL import Image, ImageDraw, ImageFont, ImageFilter
from pymongo.errors import DuplicateKeyError
from unidecode import unidecode
import aiohttp
from config import FREE_BOT
from config import MONGO_URI, DB_NAME
from motor.motor_asyncio import AsyncIOMotorClient
from PIL import Image, ImageDraw, ImageFont, ImageFilter
from pymongo.errors import DuplicateKeyError
from unidecode import unidecode
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
PUBLIC_LINK_PATTERN = re.compile(r'(https?://)?(t\.me|telegram\.me)/([^/]+)(/(\d+))?')
PRIVATE_LINK_PATTERN = re.compile(r'(https?://)?(t\.me|telegram\.me)/c/(\d+)(/(\d+))?')
# Initialize MongoDB client
async def is_premium_user(user_id: int) -> bool:
try:
if FREE_BOT:
return True
r = await api_request(f'/premium/{user_id}')
return bool(r and r.get('success') and r.get('is_premium'))
except Exception as e:
print(f"[is_premium_user] API error for {user_id}: {e}")
return False
async def add_premium_user(user_id, duration_value, duration_unit):
"""Add a user as premium member with expiration time"""
try:
# Calculate expiration time based on duration
now = datetime.utcnow()
expiry_date = None
if duration_unit == "min":
expiry_date = now + timedelta(minutes=duration_value)
elif duration_unit == "hours":
expiry_date = now + timedelta(hours=duration_value)
elif duration_unit == "days":
expiry_date = now + timedelta(days=duration_value)
elif duration_unit == "weeks":
expiry_date = now + timedelta(weeks=duration_value)
elif duration_unit == "month":
expiry_date = now + timedelta(days=30 * duration_value)
elif duration_unit == "year":
expiry_date = now + timedelta(days=365 * duration_value)
elif duration_unit == "decades":
expiry_date = now + timedelta(days=3650 * duration_value)
else:
return False, "Invalid duration unit"
# Add user to premium collection
result = await premium_users_collection.update_one(
{"user_id": user_id},
{"$set": {
"user_id": user_id,
"subscription_start": now,
"subscription_end": expiry_date
}},
upsert=True
)
print(f"Added premium user {user_id}, expires at {expiry_date}")
return True, expiry_date
except Exception as e:
print(f"Error adding premium user {user_id}: {e}")
return False, str(e)
async def get_premium_details(user_id):
"""Get premium subscription details for a user"""
try:
user = await premium_users_collection.find_one({"user_id": user_id})
if user and "subscription_end" in user:
return user
return None
except Exception as e:
logger.error(f"Error getting premium details for {user_id}: {e}")
return None
def clean_html(text):
if not text or not isinstance(text, str):
return ""
try:
# Fix incomplete image URLs
text = re.sub(r'//storage\.googleapis\.com', 'https://storage.googleapis.com', text)
# --- Step 1: LaTeX Math Handling ---
def latex_to_text(latex):
try:
# Store original LaTeX to revert if processing fails
original_latex = latex
# Common LaTeX replacements with proper math symbols
replacements = {
# Basic operations
r'\\times': '×',
r'\\div': '÷',
r'\\cdot': '·',
r'\\pm': '±',
r'\\mp': '∓',
# Comparison operators
r'\\neq': '≠',
r'\\approx': '≈',
r'\\equiv': '≡',
r'\\leq': '≤',
r'\\geq': '≥',
r'\\ll': '≪',
r'\\gg': '≫',
r'\\sim': '∼',
r'\\cong': '≅',
# Arrows
r'\\to': '→',
r'\\rightarrow': '→',
r'\\leftarrow': '←',
r'\\uparrow': '↑',
r'\\downarrow': '↓',
r'\\Rightarrow': '⇒',
r'\\Leftarrow': '⇐',
r'\\leftrightarrow': '↔',
r'\\Leftrightarrow': '⇔',
# Set theory
r'\\in': '∈',
r'\\notin': '∉',
r'\\subset': '⊂',
r'\\supset': '⊃',
r'\\subseteq': '⊆',
r'\\supseteq': '⊇',
r'\\emptyset': '∅',
r'\\cap': '∩',
r'\\cup': '∪',
r'\\setminus': '∖',
# Logic
r'\\forall': '∀',
r'\\exists': '∃',
r'\\neg': '¬',
r'\\lor': '∨',
r'\\land': '∧',
r'\\implies': '⇒',
r'\\iff': '⇔',
# Calculus
r'\\int': '∫',
r'\\iint': '∬',
r'\\iiint': '∭',
r'\\oint': '∮',
r'\\nabla': '∇',
r'\\partial': '∂',
r'\\sum': '∑',
r'\\prod': '∏',
r'\\infty': '∞',
r'\\lim': 'lim',
# Roots
r'\\sqrt\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}': r'√(\1)',
r'\\sqrt\[([^]]*)\]\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}': r'∛(\2)', # Not perfect for all nth roots
# Parentheses and brackets
r'\\left\(': '(',
r'\\right\)': ')',
r'\\left\[': '[',
r'\\right\]': ']',
r'\\left\{': '{',
r'\\right\}': '}',
r'\\left\|': '|',
r'\\right\|': '|',
r'\\langle': '⟨',
r'\\rangle': '⟩',
r'\\lfloor': '⌊',
r'\\rfloor': '⌋',
r'\\lceil': '⌈',
r'\\rceil': '⌉',
# Greek letters (lowercase)
r'\\alpha': 'α',
r'\\beta': 'β',
r'\\gamma': 'γ',
r'\\delta': 'δ',
r'\\epsilon': 'ε',
r'\\varepsilon': 'ε',
r'\\zeta': 'ζ',
r'\\eta': 'η',
r'\\theta': 'θ',
r'\\vartheta': 'ϑ',
r'\\iota': 'ι',
r'\\kappa': 'κ',
r'\\lambda': 'λ',
r'\\mu': 'μ',
r'\\nu': 'ν',
r'\\xi': 'ξ',
r'\\pi': 'π',
r'\\varpi': 'ϖ',
r'\\rho': 'ρ',
r'\\varrho': 'ϱ',
r'\\sigma': 'σ',
r'\\varsigma': 'ς',
r'\\tau': 'τ',
r'\\upsilon': 'υ',
r'\\phi': 'φ',
r'\\varphi': 'φ',
r'\\chi': 'χ',
r'\\psi': 'ψ',
r'\\omega': 'ω',
# Greek letters (uppercase)
r'\\Gamma': 'Γ',
r'\\Delta': 'Δ',
r'\\Theta': 'Θ',
r'\\Lambda': 'Λ',
r'\\Xi': 'Ξ',
r'\\Pi': 'Π',
r'\\Sigma': 'Σ',
r'\\Upsilon': 'Υ',
r'\\Phi': 'Φ',
r'\\Psi': 'Ψ',
r'\\Omega': 'Ω',
# Other symbols
r'\\hbar': 'ℏ',
r'\\ell': 'ℓ',
r'\\Re': 'ℜ',
r'\\Im': 'ℑ',
r'\\wp': '℘',
r'\\prime': '′',
r'\\backprime': '‵',
r'\\degree': '°',
r'\\circ': '∘',
r'\\bullet': '•',
r'\\star': '★',
r'\\ast': '∗',
r'\\oplus': '⊕',
r'\\ominus': '⊖',
r'\\otimes': '⊗',
r'\\oslash': '⊘',
}
# Process delimited expressions (e.g., \frac{}{}, \binom{}{}, etc.)
# Handle fractions first
def process_frac(match):
num = match.group(1)
denom = match.group(2)
return f"({num}/{denom})"
latex = re.sub(r'\\frac\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}',
process_frac, latex)
# Process binomials
def process_binom(match):
n = match.group(1)
k = match.group(2)
return f"C({n},{k})"
latex = re.sub(r'\\binom\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}',
process_binom, latex)
# Apply all symbol replacements
for pattern, replacement in replacements.items():
latex = re.sub(pattern, replacement, latex)
# Handle subscripts and superscripts
# Simple case: single character or digit
latex = re.sub(r'([a-zA-Z0-9])\_\{([^{}]+)\}', r'\1_\2', latex)
latex = re.sub(r'([a-zA-Z0-9])\^\{([^{}]+)\}', r'\1^\2', latex)
# Simple case without braces
latex = re.sub(r'([a-zA-Z0-9])\_([a-zA-Z0-9])', r'\1_\2', latex)
latex = re.sub(r'([a-zA-Z0-9])\^([a-zA-Z0-9])', r'\1^\2', latex)
# Handle limits for integrals, sums, etc.
def process_limits(match):
operator = match.group(1)
lower = match.group(2)
upper = match.group(3)
return f"{operator} from {lower} to {upper}"
latex = re.sub(r'(∫|∑|∏|lim)\_\{([^{}]+)\}\^\{([^{}]+)\}', process_limits, latex)
# Clean up any leftover LaTeX commands we missed
latex = re.sub(r'\\[a-zA-Z]+(\s|$)', '', latex)
# If something went wrong and we made it worse, revert
if '\\' in latex and len(latex) > len(original_latex):
return original_latex
return latex
except Exception as e:
print(f"LaTeX processing error: {e}")
return latex # Return original if processing fails
# Process LaTeX in environments
# Find \begin{equation}...\end{equation} and other math environments
env_patterns = [
(r'\\begin\{equation\}(.*?)\\end\{equation\}', r'\1'),
(r'\\begin\{align\}(.*?)\\end\{align\}', r'\1'),
(r'\\begin\{aligned\}(.*?)\\end\{aligned\}', r'\1'),
(r'\\begin\{gather\}(.*?)\\end\{gather\}', r'\1'),
(r'\\begin\{math\}(.*?)\\end\{math\}', r'\1')
]
for pattern, replacement in env_patterns:
text = re.sub(pattern, lambda m: latex_to_text(m.group(1)), text, flags=re.DOTALL)
# Process LaTeX in \(...\) and \[...\]
text = re.sub(
r'\\\((.*?)\\\)|\\\[(.*?)\\\]',
lambda m: latex_to_text(m.group(1) if m.group(1) else m.group(2)),
text,
flags=re.DOTALL
)
# Process dollar sign delimited LaTeX
text = re.sub(
r'\$(.*?)\$|\$\$(.*?)\$\$',
lambda m: latex_to_text(m.group(1) if m.group(1) else m.group(2)),
text,
flags=re.DOTALL
)
# Process standalone LaTeX expressions
# Handle standalone fractions
while re.search(r'\\frac\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}', text):
text = re.sub(
r'\\frac\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}',
lambda m: f"({m.group(1)}/{m.group(2)})",
text
)
# Handle other standalone LaTeX symbols
tex_symbols = {
r'\\times': '×',
r'\\div': '÷',
r'\\cdot': '·',
r'\\pm': '±',
r'\\sqrt\{([^{}]*)\}': r'√(\1)',
r'\\neq': '≠',
r'\\leq': '≤',
r'\\geq': '≥',
r'\\alpha': 'α',
r'\\beta': 'β',
r'\\gamma': 'γ',
r'\\delta': 'δ',
r'\\pi': 'π',
r'\\theta': 'θ',
r'\\sigma': 'σ',
r'\\omega': 'ω',
r'\\infty': '∞',
r'\\sum': '∑',
r'\\prod': '∏',
r'\\int': '∫',
r'\\partial': '∂',
}
for pattern, replacement in tex_symbols.items():
text = re.sub(pattern, replacement, text)
# --- Step 2: HTML Cleaning (Original Logic) ---
soup = BeautifulSoup(text, 'html.parser')
# Replace <br> with newlines
for br in soup.find_all("br"):
br.replace_with("\n")
# Convert list items to bullets
for li in soup.find_all("li"):
li.insert_before("\n• ")
li.unwrap()
# Handle tables
for table in soup.find_all("table"):
table_text = ""
for row in table.find_all("tr"):
cols = row.find_all(["td", "th"])
row_text = " • ".join([col.get_text(strip=True) for col in cols])
table_text += f"{row_text}\n"
table.replace_with(table_text)
# Add line breaks after <p>
for p in soup.find_all("p"):
p.insert_after("\n")
p.unwrap()
# Remove unwanted tags
for tag in soup(["style", "script", "a", "iframe", "img"]):
tag.decompose()
clean_text = soup.get_text(separator="\n")
clean_text = re.sub(r'\n\s*\n+', '\n\n', clean_text) # Reduce blank lines
clean_text = re.sub(r'[ \t]+', ' ', clean_text) # Fix spacing
return clean_text.strip()
except Exception as e:
print(f"HTML cleaning error: {e}")
return text
async def generate_quiz_html(quiz, chat_id, context, ParseMode, type):
def js_escape(text):
if not text:
return ""
# Convert to string if not already
text = str(text)
# Escape special characters
text = text.replace('\\', '\\\\') # must be first
text = text.replace('"', '\\"')
text = text.replace("'", "\\'")
text = text.replace('\n', '\\n')
text = text.replace('\r', '\\r')
text = text.replace('\t', '\\t')
return text
# Prepare quiz filename
quiz_name = re.sub(r"[^a-zA-Z0-9_-]", "", unidecode(quiz["quiz_name"]).replace(" ", "_"))[:100] + ".html"
max_marks = len(quiz["questions"])
negative_mark = quiz.get("negative_marking", 0)
total_time = 0
if quiz.get("sections"):
for section in quiz["sections"]:
start, end = section.get("question_range", (0, -1))
num_questions = end - start + 1
section_timer = section.get("timer", 0)
total_time += section_timer * num_questions
else:
total_time = (quiz.get("timer") or 60) * len(quiz["questions"])
# Create question data for JavaScript
questions_js = []
for idx, q in enumerate(quiz["questions"]):
options = q["options"].copy()
correct_option = options[q["correct_option_id"]]
random.shuffle(options)
questions_js.append(f"""{{
id: {idx},
text: "{js_escape(q["question"])}",
reference: "{js_escape(q.get("reply_text", ""))}",
options: {json.dumps(options)}, // Using json.dumps for proper escaping
correctIndex: {options.index(correct_option)},
explanation: "{js_escape(q.get("explanation", "No explanation provided"))}"
}}""")
# Build the optimized HTML content with sound effects
html_content = f"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{quiz['quiz_name']}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap" rel="stylesheet">
<style>
:root {{
--primary-color: #4361ee;
--secondary-color: #3a56d4;
--success-color: #28a745;
--danger-color: #dc3545;
--warning-color: #ffc107;
--light-bg: #ffffff;
--dark-bg: #1a1a2e;
--light-text: #333333;
--dark-text: #f8f9fa;
--card-bg: #ffffff;
--card-shadow: 0 15px 40px rgba(0,0,0,0.12);
--option-btn-bg: #ffffff;
--option-btn-border: #e6e6e6;
--explanation-bg: #f8f9fa;
--analysis-bg: #f8f9fa;
--text-color: #333333;
--border-color: #e6e6e6;
}}
[data-theme="dark"] {{
--primary-color: #7e96ff;
--secondary-color: #6a7fd4;
--light-bg: #1a1a2e;
--dark-bg: #16213e;
--light-text: #f8f9fa;
--dark-text: #e2e2e2;
--card-bg: #16213e;
--card-shadow: 0 15px 40px rgba(0,0,0,0.3);
--option-btn-bg: #1f2a4e;
--option-btn-border: #2a3a6e;
--explanation-bg: #1f2a4e;
--analysis-bg: #1f2a4e;
--text-color: #f8f9fa;
--border-color: #2a3a6e;
}}
body {{
font-family: 'Poppins', sans-serif;
background: var(--light-bg);
color: var(--text-color);
min-height: 100vh;
padding-bottom: 50px;
transition: background 0.3s ease, color 0.3s ease;
}}
.dark-mode body {{
background: var(--dark-bg);
color: var(--dark-text);
}}
.mcard-title {{
font-size: 1.25rem;
font-weight: 600;
color: var(--text-color); /* Will auto-switch in dark mode */
margin-bottom: 1rem; /* mb-3 equivalent */
}}
.quiz-container {{
max-width: 800px;
margin: 20px auto;
background: var(--card-bg);
border-radius: 15px;
box-shadow: var(--card-shadow);
overflow: hidden;
animation: fadeIn 0.5s;
touch-action: pan-y;
transition: background 0.3s ease, box-shadow 0.3s ease;
}}
.question-text {{
font-size: 18px;
line-height: 1.6;
color: var(--text-color);
margin-bottom: 20px;
padding: 10px 0;
font-weight: 500;
}}
.dark-mode .question-text {{
color: var(--dark-text);
}}
@keyframes fadeIn {{
from {{ opacity: 0; transform: translateY(20px) }}
to {{ opacity: 1; transform: translateY(0) }}
}}
@keyframes slideIn {{
from {{ transform: translateX(20px); opacity: 0 }}
to {{ transform: translateX(0); opacity: 1 }}
}}
.quiz-header {{
position: sticky;
top: 0;
z-index: 1000;
background: var(--card-bg);
padding: 15px 20px;
border-bottom: 1px solid var(--border-color);
transition: background 0.3s ease, border-color 0.3s ease;
}}
.timer {{
font-size: 22px;
font-weight: 600;
color: var(--primary-color);
}}
.question-card {{
border: none;
box-shadow: 0 5px 20px rgba(0,0,0,0.06);
margin-bottom: 25px;
border-radius: 15px;
overflow: hidden;
transition: all 0.4s ease;
animation: slideIn 0.4s;
background: var(--card-bg);
}}
.dark-mode .question-card {{
box-shadow: 0 5px 20px rgba(0,0,0,0.2);
}}
.question-reference {{
background-color: rgba(67, 97, 238, 0.1);
border-left: 5px solid var(--primary-color);
padding: 15px;
margin-bottom: 15px;
border-radius: 5px;
color: var(--text-color);
}}
.option-btn {{
text-align: left;
padding: 16px 20px;
margin-bottom: 12px;
border-radius: 12px;
transition: all 0.3s ease;
position: relative;
overflow: hidden;
border: 1px solid var(--option-btn-border);
background-color: var(--option-btn-bg);
color: var(--text-color);
width: 100%;
}}
.option-btn:hover {{
background-color: rgba(67, 97, 238, 0.1);
transform: translateX(5px);
box-shadow: 0 3px 10px rgba(0,0,0,0.05);
}}
.option-btn.selected {{
background-color: rgba(67, 97, 238, 0.2);
border-color: var(--primary-color);
font-weight: 500;
box-shadow: 0 5px 15px rgba(67,97,238,0.15);
}}
.option-btn.correct {{
background-color: rgba(40, 167, 69, 0.2);
border-color: var(--success-color);
}}
.option-btn.incorrect {{
background-color: rgba(220, 53, 69, 0.2);
border-color: var(--danger-color);
}}
.progress {{
height: 8px;
border-radius: 4px;
overflow: hidden;
background-color: rgba(0,0,0,0.1);
}}
.dark-mode .progress {{
background-color: rgba(255,255,255,0.1);
}}
.progress-bar {{
transition: width 1s linear;
}}
.result-card {{
display: none;
animation: fadeIn 0.5s;
color: var(--text-color);
}}
.score-highlight {{
font-size: 48px;
font-weight: 700;
color: var(--primary-color);
text-align: center;
margin: 20px 0;
}}
.explanation {{
background-color: var(--explanation-bg);
padding: 15px;
border-radius: 8px;
margin-top: 15px;
border-left: 3px solid var(--primary-color);
transition: background 0.3s ease;
color: var(--text-color);
}}
.analysis-panel {{
background-color: var(--analysis-bg);
border-radius: 10px;
padding: 15px;
margin-top: 20px;
box-shadow: 0 3px 10px rgba(0,0,0,0.05);
border: 1px solid var(--border-color);
transition: background 0.3s ease;
color: var(--text-color);
}}
.analysis-item {{
display: flex;
align-items: center;
margin-bottom: 10px;
color: var(--text-color);
}}
.analysis-icon {{
width: 24px;
height: 24px;
margin-right: 10px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
color: white;
}}
.btn-primary {{
background-color: var(--primary-color);
border-color: var(--primary-color);
border-radius: 30px;
padding: 10px 25px;
transition: all 0.3s ease;
}}
.btn-primary:hover {{
background-color: var(--secondary-color);
border-color: var(--secondary-color);
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(67,97,238,0.2);
}}
.confetti {{
position: fixed;
width: 10px;
height: 10px;
background-color: #f00;
position: absolute;
top: 0;
z-index: 9999;
}}
.chart-container {{
height: 220px;
}}
.time-bar {{
height: 8px;
background: rgba(0,0,0,0.1);
border-radius: 4px;
overflow: hidden;
margin-top: 5px;
}}
.dark-mode .time-bar {{
background: rgba(255,255,255,0.1);
}}
.time-fill {{
height: 100%;
background: linear-gradient(90deg, var(--primary-color) 0%, var(--secondary-color) 100%);
border-radius: 4px;
transition: width 0.5s;
}}
.badge-avg {{
background-color: rgba(67, 97, 238, 0.2);
color: var(--primary-color);
font-weight: 500;
padding: 5px 10px;
border-radius: 20px;
}}
.badge-fast {{
background-color: rgba(40, 167, 69, 0.2);
color: var(--success-color);
font-weight: 500;
padding: 5px 10px;
border-radius: 20px;
}}
.badge-slow {{
background-color: rgba(220, 53, 69, 0.2);
color: var(--danger-color);
font-weight: 500;
padding: 5px 10px;
border-radius: 20px;
}}
/* Mobile-first styles */
@media (max-width: 768px) {{
.quiz-container {{
margin: 10px;
border-radius: 10px;
}}
.quiz-header {{
padding: 12px 15px;
}}
.timer {{
font-size: 18px;
}}
.question-card {{
margin-bottom: 15px;
border-radius: 10px;
}}
.option-btn {{
padding: 12px 15px;
margin-bottom: 8px;
border-radius: 8px;
}}
.score-highlight {{
font-size: 36px;
}}
}}
/* Hamburger menu styles */
.menu-toggle {{
display: none;
background: none;
border: none;
font-size: 24px;
color: var(--primary-color);
cursor: pointer;
padding: 5px;
margin-right: 10px;
}}
.question-list-container {{
position: fixed;
top: 0;
left: -300px;
width: 280px;
height: 100vh;
background: var(--card-bg);
box-shadow: 2px 0 10px rgba(0,0,0,0.1);
z-index: 1100;
transition: left 0.3s ease;
overflow-y: auto;
padding: 20px;
}}
.dark-mode .question-list-container {{
box-shadow: 2px 0 10px rgba(0,0,0,0.3);
}}
.question-list-container.show {{
left: 0;
}}
.question-list-header {{
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 1px solid var(--border-color);
}}
.question-list-title {{
font-weight: 600;
font-size: 18px;
color: var(--primary-color);
}}
.close-menu-btn {{
background: none;
border: none;
font-size: 20px;
color: var(--text-color);
cursor: pointer;
}}
.question-list {{
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}}
.question-list-item {{
padding: 10px;
text-align: center;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s ease;
background: rgba(0,0,0,0.05);
border: 1px solid var(--border-color);
font-weight: 600;
color: var(--text-color);
}}
.dark-mode .question-list-item {{
background: rgba(255,255,255,0.05);
}}
.question-list-item:hover {{
background: rgba(67, 97, 238, 0.1);
transform: scale(1.05);
}}
.question-list-item.active {{
background: var(--primary-color);
color: white;
border-color: var(--primary-color);
}}
.question-list-item.correct {{
background: var(--success-color);
color: white;
border-color: var(--success-color);
}}
.question-list-item.incorrect {{
background: var(--danger-color);
color: white;
border-color: var(--danger-color);
}}
.overlay {{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.5);
z-index: 1050;
opacity: 0;
visibility: hidden;
transition: opacity 0.3s ease, visibility 0.3s ease;
}}
.overlay.show {{
opacity: 1;
visibility: visible;
}}
/* Theme toggle button */
.theme-toggle {{
position: fixed;
bottom: 20px;
right: 20px;
width: 50px;
height: 50px;
border-radius: 50%;
background: var(--primary-color);
color: white;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
z-index: 1000;
border: none;
font-size: 20px;
}}
@media (max-width: 768px) {{
.menu-toggle {{
display: block;
}}
.question-list {{
grid-template-columns: repeat(2, 1fr);
}}
}}
@media (max-width: 480px) {{
.question-list {{
grid-template-columns: 1fr;
}}
}}
/* Remove the bottom question navigation */
.quiz-pagination {{
display: none !important;
}}
</style>
</head>
<body>
<!-- Hidden audio elements for sound effects -->
<audio id="clickSound" src="https://assets.mixkit.co/active_storage/sfx/269/269.wav" preload="auto"></audio>
<audio id="swipeSound" src="https://assets.mixkit.co/active_storage/sfx/1897/1897.wav" preload="auto"></audio>
<audio id="correctSound" src="https://assets.mixkit.co/active_storage/sfx/2870/2870.wav" preload="auto"></audio>