FunWith commited on
Commit
4e3ac7f
·
verified ·
1 Parent(s): e0d903a

Upload folder using huggingface_hub

Browse files
Files changed (10) hide show
  1. .gitignore +9 -0
  2. Dockerfile +15 -0
  3. README.md +13 -10
  4. data/curriculum.json +731 -0
  5. main.py +261 -0
  6. rag.py +210 -0
  7. requirements.txt +4 -0
  8. static/app.js +385 -0
  9. static/index.html +122 -0
  10. static/styles.css +570 -0
.gitignore ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ .env
2
+ __pycache__/
3
+ *.pyc
4
+ debug_err.txt
5
+ curl_err.txt
6
+ curl_out.txt
7
+ proxy_info.txt
8
+ test_async.py
9
+ debug.txt
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY main.py .
9
+ COPY rag.py .
10
+ COPY data/ data/
11
+ COPY static/ static/
12
+
13
+ EXPOSE 7860
14
+
15
+ CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,10 +1,13 @@
1
- ---
2
- title: Irish Maths Ai
3
- emoji: 🏢
4
- colorFrom: gray
5
- colorTo: indigo
6
- sdk: docker
7
- pinned: false
8
- ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
1
+ ---
2
+ title: Mathaí - Irish Maths AI
3
+ emoji: 🧮
4
+ colorFrom: green
5
+ colorTo: blue
6
+ sdk: docker
7
+ app_port: 7860
8
+ pinned: false
9
+ ---
10
+
11
+ # Mathaí — Irish Maths AI Tutor
12
+
13
+ A friendly AI maths tutor aligned to the Irish curriculum (Primary, Junior Cycle, Senior Cycle). Powered by Groq + Llama 3.3 70B.
data/curriculum.json ADDED
@@ -0,0 +1,731 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "primary": {
3
+ "label": "Primary School (Junior Infants – 6th Class)",
4
+ "stages": {
5
+ "stage_1": {
6
+ "label": "Stage 1 (Junior & Senior Infants)",
7
+ "classes": ["Junior Infants", "Senior Infants"],
8
+ "age_range": "4-6"
9
+ },
10
+ "stage_2": {
11
+ "label": "Stage 2 (1st & 2nd Class)",
12
+ "classes": ["1st Class", "2nd Class"],
13
+ "age_range": "6-8"
14
+ },
15
+ "stage_3": {
16
+ "label": "Stage 3 (3rd & 4th Class)",
17
+ "classes": ["3rd Class", "4th Class"],
18
+ "age_range": "8-10"
19
+ },
20
+ "stage_4": {
21
+ "label": "Stage 4 (5th & 6th Class)",
22
+ "classes": ["5th Class", "6th Class"],
23
+ "age_range": "10-12"
24
+ }
25
+ },
26
+ "strands": {
27
+ "algebra": {
28
+ "label": "Algebra",
29
+ "topics": {
30
+ "patterns": {
31
+ "label": "Patterns and Relationships",
32
+ "outcomes_by_stage": {
33
+ "stage_1": [
34
+ "Identify, copy and extend patterns in colour, shape, size and number",
35
+ "Recognise patterns in the environment",
36
+ "Create simple patterns using objects and drawings"
37
+ ],
38
+ "stage_2": [
39
+ "Explore and use patterns in addition and subtraction",
40
+ "Identify and record rules for simple number patterns",
41
+ "Complete number sentences involving +, – and ="
42
+ ],
43
+ "stage_3": [
44
+ "Identify and explain rules for number sequences",
45
+ "Use variables to represent unknown quantities",
46
+ "Explore and apply properties of arithmetic operations"
47
+ ],
48
+ "stage_4": [
49
+ "Identify and express rules for patterns in words and symbols",
50
+ "Use variables to express simple formulas",
51
+ "Solve simple equations involving one variable",
52
+ "Represent and interpret relationships using tables and graphs"
53
+ ]
54
+ }
55
+ },
56
+ "expressions_equations": {
57
+ "label": "Expressions and Equations",
58
+ "outcomes_by_stage": {
59
+ "stage_1": [
60
+ "Use objects and pictures to represent addition and subtraction situations"
61
+ ],
62
+ "stage_2": [
63
+ "Write and solve number sentences using +, –, =",
64
+ "Find missing numbers in number sentences"
65
+ ],
66
+ "stage_3": [
67
+ "Write expressions using variables for unknown quantities",
68
+ "Solve simple one-step equations"
69
+ ],
70
+ "stage_4": [
71
+ "Construct and solve equations from word problems",
72
+ "Understand and use order of operations",
73
+ "Simplify simple algebraic expressions"
74
+ ]
75
+ }
76
+ }
77
+ }
78
+ },
79
+ "data_and_chance": {
80
+ "label": "Data and Chance",
81
+ "topics": {
82
+ "data_collection": {
83
+ "label": "Collecting, Recording and Interpreting Data",
84
+ "outcomes_by_stage": {
85
+ "stage_1": [
86
+ "Sort, classify and compare objects by one attribute",
87
+ "Represent data using real objects and simple pictograms"
88
+ ],
89
+ "stage_2": [
90
+ "Collect and organise data using simple surveys",
91
+ "Represent data in block graphs and pictograms",
92
+ "Read and interpret simple charts and graphs"
93
+ ],
94
+ "stage_3": [
95
+ "Collect, organise and represent data using bar charts and tables",
96
+ "Use scales on axes to read and interpret data",
97
+ "Calculate the mean of a set of data"
98
+ ],
99
+ "stage_4": [
100
+ "Plan and carry out investigations to collect data",
101
+ "Represent data using bar charts, line plots, pie charts",
102
+ "Calculate mean, mode, median and range",
103
+ "Analyse and draw conclusions from data representations"
104
+ ]
105
+ }
106
+ },
107
+ "chance": {
108
+ "label": "Chance and Probability",
109
+ "outcomes_by_stage": {
110
+ "stage_1": [
111
+ "Use language of chance: will, won't, might",
112
+ "Identify events that are certain, possible, impossible"
113
+ ],
114
+ "stage_2": [
115
+ "List possible outcomes of simple random events",
116
+ "Order events from least to most likely"
117
+ ],
118
+ "stage_3": [
119
+ "Identify all possible outcomes of simple experiments",
120
+ "Estimate likelihood using words and simple fractions"
121
+ ],
122
+ "stage_4": [
123
+ "Conduct simple probability experiments",
124
+ "Express probability as fractions and percentages",
125
+ "Compare predicted and actual results"
126
+ ]
127
+ }
128
+ }
129
+ }
130
+ },
131
+ "measures": {
132
+ "label": "Measures",
133
+ "topics": {
134
+ "length": {
135
+ "label": "Length",
136
+ "outcomes_by_stage": {
137
+ "stage_1": [
138
+ "Compare and order objects by length using direct comparison",
139
+ "Use non-standard units to measure length"
140
+ ],
141
+ "stage_2": [
142
+ "Estimate and measure length using standard units (cm, m)",
143
+ "Select appropriate instruments for measuring length"
144
+ ],
145
+ "stage_3": [
146
+ "Estimate, measure and record length in m, cm, mm",
147
+ "Convert between units of length",
148
+ "Calculate perimeter of regular and irregular shapes"
149
+ ],
150
+ "stage_4": [
151
+ "Estimate, measure and calculate length in km, m, cm, mm",
152
+ "Convert fluently between metric units of length",
153
+ "Solve multi-step problems involving length and perimeter"
154
+ ]
155
+ }
156
+ },
157
+ "area": {
158
+ "label": "Area",
159
+ "outcomes_by_stage": {
160
+ "stage_2": [
161
+ "Compare areas by direct comparison and using non-standard units"
162
+ ],
163
+ "stage_3": [
164
+ "Estimate and measure area using square centimetres",
165
+ "Calculate area of rectangles using formula"
166
+ ],
167
+ "stage_4": [
168
+ "Calculate area of rectangles, triangles and compound shapes",
169
+ "Solve problems involving area in real-world contexts",
170
+ "Convert between sq cm and sq m"
171
+ ]
172
+ }
173
+ },
174
+ "weight": {
175
+ "label": "Weight (Mass)",
176
+ "outcomes_by_stage": {
177
+ "stage_1": [
178
+ "Compare and order objects by weight using direct comparison",
179
+ "Use non-standard units to measure weight"
180
+ ],
181
+ "stage_2": [
182
+ "Estimate and measure weight using kg and g",
183
+ "Read scales on weighing instruments"
184
+ ],
185
+ "stage_3": [
186
+ "Estimate, measure and record in kg and g",
187
+ "Convert between kg and g"
188
+ ],
189
+ "stage_4": [
190
+ "Solve multi-step problems involving weight",
191
+ "Convert fluently between metric units of mass"
192
+ ]
193
+ }
194
+ },
195
+ "capacity": {
196
+ "label": "Capacity",
197
+ "outcomes_by_stage": {
198
+ "stage_1": [
199
+ "Compare and order containers by capacity",
200
+ "Use non-standard units to measure capacity"
201
+ ],
202
+ "stage_2": [
203
+ "Estimate and measure capacity using litres and millilitres"
204
+ ],
205
+ "stage_3": [
206
+ "Estimate, measure and record in litres and ml",
207
+ "Convert between litres and ml"
208
+ ],
209
+ "stage_4": [
210
+ "Solve multi-step problems involving capacity",
211
+ "Relate capacity to volume"
212
+ ]
213
+ }
214
+ },
215
+ "time": {
216
+ "label": "Time",
217
+ "outcomes_by_stage": {
218
+ "stage_1": [
219
+ "Sequence daily events and use language of time",
220
+ "Read time in hours on analogue clocks"
221
+ ],
222
+ "stage_2": [
223
+ "Read time in hours, half-hours and quarter-hours",
224
+ "Read digital time",
225
+ "Know days, weeks, months, seasons"
226
+ ],
227
+ "stage_3": [
228
+ "Read time to the nearest minute (analogue and digital)",
229
+ "Use 24-hour clock",
230
+ "Calculate elapsed time"
231
+ ],
232
+ "stage_4": [
233
+ "Read and interpret timetables and schedules",
234
+ "Calculate duration involving different units of time",
235
+ "Solve multi-step problems involving time"
236
+ ]
237
+ }
238
+ },
239
+ "money": {
240
+ "label": "Money",
241
+ "outcomes_by_stage": {
242
+ "stage_1": [
243
+ "Recognise and name coins and notes",
244
+ "Exchange coins of equivalent value"
245
+ ],
246
+ "stage_2": [
247
+ "Add and subtract money amounts",
248
+ "Calculate change"
249
+ ],
250
+ "stage_3": [
251
+ "Solve problems using the four operations with money",
252
+ "Use decimal notation for euro and cent"
253
+ ],
254
+ "stage_4": [
255
+ "Solve multi-step money problems",
256
+ "Calculate percentages in money contexts (discounts, VAT)"
257
+ ]
258
+ }
259
+ }
260
+ }
261
+ },
262
+ "number": {
263
+ "label": "Number",
264
+ "topics": {
265
+ "counting_numeration": {
266
+ "label": "Counting and Numeration",
267
+ "outcomes_by_stage": {
268
+ "stage_1": [
269
+ "Count objects to 20 and beyond with understanding",
270
+ "Read, write and order numbers to 20",
271
+ "Understand ordinal numbers (1st to 10th)",
272
+ "Explore zero as representing nothing"
273
+ ],
274
+ "stage_2": [
275
+ "Read, write and order numbers up to 199",
276
+ "Understand place value (tens and units)",
277
+ "Round numbers to the nearest ten",
278
+ "Count in 2s, 5s and 10s"
279
+ ],
280
+ "stage_3": [
281
+ "Read, write and order numbers up to 9,999",
282
+ "Understand place value to thousands",
283
+ "Round to nearest ten, hundred, thousand",
284
+ "Explore negative numbers in context"
285
+ ],
286
+ "stage_4": [
287
+ "Read, write and order numbers to millions",
288
+ "Understand place value to millions",
289
+ "Round whole numbers and decimals",
290
+ "Work with negative numbers"
291
+ ]
292
+ }
293
+ },
294
+ "operations": {
295
+ "label": "Operations (+, –, ×, ÷)",
296
+ "outcomes_by_stage": {
297
+ "stage_1": [
298
+ "Add and subtract within 20 using concrete materials",
299
+ "Understand addition as combining and subtraction as taking away",
300
+ "Develop number bonds to 10"
301
+ ],
302
+ "stage_2": [
303
+ "Add and subtract numbers up to 199 with and without renaming",
304
+ "Understand multiplication as repeated addition",
305
+ "Learn multiplication facts for 2, 5, 10",
306
+ "Understand division as sharing equally"
307
+ ],
308
+ "stage_3": [
309
+ "Add and subtract numbers up to 9,999",
310
+ "Multiply by single-digit and two-digit numbers",
311
+ "Learn multiplication tables to 10×10",
312
+ "Divide with and without remainders"
313
+ ],
314
+ "stage_4": [
315
+ "Add, subtract, multiply and divide whole numbers fluently",
316
+ "Multi-digit multiplication and long division",
317
+ "Use estimation to check reasonableness",
318
+ "Solve multi-step word problems using all four operations"
319
+ ]
320
+ }
321
+ },
322
+ "fractions": {
323
+ "label": "Fractions, Decimals and Percentages",
324
+ "outcomes_by_stage": {
325
+ "stage_1": [
326
+ "Explore halves and quarters of shapes and sets"
327
+ ],
328
+ "stage_2": [
329
+ "Identify and name fractions: ½, ¼, ⅓",
330
+ "Find fractions of sets and shapes",
331
+ "Compare and order simple fractions"
332
+ ],
333
+ "stage_3": [
334
+ "Identify equivalent fractions",
335
+ "Add and subtract simple fractions with same denominator",
336
+ "Understand tenths and hundredths as decimals",
337
+ "Express fractions as decimals"
338
+ ],
339
+ "stage_4": [
340
+ "Add and subtract fractions with different denominators",
341
+ "Multiply and divide simple fractions",
342
+ "Convert between fractions, decimals and percentages",
343
+ "Calculate percentages of quantities",
344
+ "Solve problems involving fractions, decimals and percentages"
345
+ ]
346
+ }
347
+ }
348
+ }
349
+ },
350
+ "shape_and_space": {
351
+ "label": "Shape and Space",
352
+ "topics": {
353
+ "2d_shapes": {
354
+ "label": "2D Shapes",
355
+ "outcomes_by_stage": {
356
+ "stage_1": [
357
+ "Identify, name and describe 2D shapes (circle, square, triangle, rectangle)",
358
+ "Sort and compare shapes by properties"
359
+ ],
360
+ "stage_2": [
361
+ "Identify and describe properties of 2D shapes (sides, corners)",
362
+ "Combine and partition 2D shapes",
363
+ "Identify lines of symmetry"
364
+ ],
365
+ "stage_3": [
366
+ "Classify triangles and quadrilaterals by properties",
367
+ "Identify and draw lines of symmetry",
368
+ "Explore tessellation"
369
+ ],
370
+ "stage_4": [
371
+ "Construct 2D shapes from descriptions of properties",
372
+ "Classify shapes using angle and side properties",
373
+ "Use angle measurement (degrees) and protractor"
374
+ ]
375
+ }
376
+ },
377
+ "3d_shapes": {
378
+ "label": "3D Shapes",
379
+ "outcomes_by_stage": {
380
+ "stage_1": [
381
+ "Identify and name 3D shapes (cube, cuboid, sphere, cylinder, cone)",
382
+ "Explore 3D shapes in the environment"
383
+ ],
384
+ "stage_2": [
385
+ "Describe 3D shapes by their properties (faces, edges, vertices)",
386
+ "Relate 3D shapes to 2D shapes"
387
+ ],
388
+ "stage_3": [
389
+ "Classify 3D shapes and explore their nets",
390
+ "Identify 3D shapes from different viewpoints"
391
+ ],
392
+ "stage_4": [
393
+ "Construct 3D shapes from nets",
394
+ "Identify and describe prisms and pyramids",
395
+ "Calculate surface area of cuboids"
396
+ ]
397
+ }
398
+ },
399
+ "spatial_awareness": {
400
+ "label": "Spatial Awareness and Location",
401
+ "outcomes_by_stage": {
402
+ "stage_1": [
403
+ "Describe position using language: above, below, beside, between",
404
+ "Give and follow directions"
405
+ ],
406
+ "stage_2": [
407
+ "Describe and record paths and routes",
408
+ "Use simple coordinates on a grid"
409
+ ],
410
+ "stage_3": [
411
+ "Use coordinates to describe position on a grid",
412
+ "Explore translations, reflections and rotations"
413
+ ],
414
+ "stage_4": [
415
+ "Plot and read coordinates in four quadrants",
416
+ "Perform and describe transformations on a coordinate grid"
417
+ ]
418
+ }
419
+ },
420
+ "angles": {
421
+ "label": "Angles",
422
+ "outcomes_by_stage": {
423
+ "stage_2": [
424
+ "Recognise and describe angles as turns"
425
+ ],
426
+ "stage_3": [
427
+ "Classify angles as right, acute, obtuse",
428
+ "Identify angles in the environment and in shapes"
429
+ ],
430
+ "stage_4": [
431
+ "Measure and construct angles using a protractor",
432
+ "Calculate unknown angles using angle properties",
433
+ "Explore angles in triangles and quadrilaterals"
434
+ ]
435
+ }
436
+ }
437
+ }
438
+ }
439
+ }
440
+ },
441
+ "junior_cycle": {
442
+ "label": "Junior Cycle (1st – 3rd Year)",
443
+ "age_range": "12-15",
444
+ "levels": ["Ordinary Level", "Higher Level"],
445
+ "strands": {
446
+ "statistics_and_probability": {
447
+ "label": "Statistics and Probability",
448
+ "topics": {
449
+ "statistics": {
450
+ "label": "Statistics",
451
+ "outcomes": [
452
+ "Collect, classify and tabulate data",
453
+ "Represent data graphically: bar charts, histograms, line plots, pie charts, stem-and-leaf plots",
454
+ "Calculate mean, median, mode and range",
455
+ "Use appropriate measures of central tendency and spread",
456
+ "Interpret and analyse data from various representations",
457
+ "Evaluate reliability and bias in data collection"
458
+ ]
459
+ },
460
+ "probability": {
461
+ "label": "Probability",
462
+ "outcomes": [
463
+ "List all possible outcomes of an experiment",
464
+ "Calculate relative frequency from experiments",
465
+ "Express probability as a fraction, decimal and percentage",
466
+ "Use the probability scale (0 to 1)",
467
+ "Calculate expected frequency",
468
+ "Understand independent and dependent events (HL)"
469
+ ]
470
+ }
471
+ }
472
+ },
473
+ "geometry_and_trigonometry": {
474
+ "label": "Geometry and Trigonometry",
475
+ "topics": {
476
+ "synthetic_geometry": {
477
+ "label": "Synthetic Geometry",
478
+ "outcomes": [
479
+ "Understand and apply axioms, theorems and corollaries",
480
+ "Perform constructions with compass and straightedge",
481
+ "Apply properties of triangles and quadrilaterals",
482
+ "Prove theorems involving angles, triangles and parallel lines",
483
+ "Apply the theorem of Pythagoras"
484
+ ]
485
+ },
486
+ "coordinate_geometry": {
487
+ "label": "Coordinate Geometry",
488
+ "outcomes": [
489
+ "Find the midpoint, distance and slope of a line segment",
490
+ "Write the equation of a line in various forms",
491
+ "Identify parallel and perpendicular lines from equations",
492
+ "Solve problems involving lines on the coordinate plane"
493
+ ]
494
+ },
495
+ "trigonometry": {
496
+ "label": "Trigonometry",
497
+ "outcomes": [
498
+ "Use trigonometric ratios (sin, cos, tan) to solve right-angled triangle problems",
499
+ "Apply trigonometry to real-world contexts"
500
+ ]
501
+ },
502
+ "transformation_geometry": {
503
+ "label": "Transformation Geometry",
504
+ "outcomes": [
505
+ "Perform translations, reflections, rotations",
506
+ "Identify axes of symmetry and centres of rotation",
507
+ "Explore enlargements and scale factor"
508
+ ]
509
+ }
510
+ }
511
+ },
512
+ "number": {
513
+ "label": "Number",
514
+ "topics": {
515
+ "number_systems": {
516
+ "label": "Number Systems",
517
+ "outcomes": [
518
+ "Understand natural numbers, integers, rationals and irrationals",
519
+ "Perform operations with integers and rational numbers",
520
+ "Work with surds (HL)",
521
+ "Apply scientific notation",
522
+ "Use index notation and laws of indices"
523
+ ]
524
+ },
525
+ "applied_arithmetic": {
526
+ "label": "Applied Arithmetic",
527
+ "outcomes": [
528
+ "Solve problems involving percentages, profit, loss, discount, VAT",
529
+ "Calculate simple and compound interest",
530
+ "Work with ratio and proportion",
531
+ "Convert between currencies",
532
+ "Solve problems involving rates (speed, density etc.)"
533
+ ]
534
+ }
535
+ }
536
+ },
537
+ "algebra": {
538
+ "label": "Algebra",
539
+ "topics": {
540
+ "expressions": {
541
+ "label": "Expressions and Formulae",
542
+ "outcomes": [
543
+ "Simplify algebraic expressions",
544
+ "Expand brackets and factorise expressions",
545
+ "Substitute into expressions and formulae",
546
+ "Use index laws with algebraic expressions"
547
+ ]
548
+ },
549
+ "equations_inequalities": {
550
+ "label": "Equations and Inequalities",
551
+ "outcomes": [
552
+ "Solve linear equations in one variable",
553
+ "Solve simultaneous linear equations in two variables",
554
+ "Solve quadratic equations (by factoring, formula) (HL)",
555
+ "Solve linear inequalities and represent on number line"
556
+ ]
557
+ }
558
+ }
559
+ },
560
+ "functions": {
561
+ "label": "Functions",
562
+ "topics": {
563
+ "functions_intro": {
564
+ "label": "Functions and Graphs",
565
+ "outcomes": [
566
+ "Understand the concept of a function (input → output)",
567
+ "Represent functions as mappings, tables, graphs and formulae",
568
+ "Graph linear functions and identify slope and intercept",
569
+ "Graph quadratic functions and identify key features (HL)",
570
+ "Interpret real-world graphs (distance-time, growth etc.)"
571
+ ]
572
+ }
573
+ }
574
+ }
575
+ }
576
+ },
577
+ "senior_cycle": {
578
+ "label": "Senior Cycle (5th & 6th Year – Leaving Certificate)",
579
+ "age_range": "15-18",
580
+ "levels": ["Foundation Level", "Ordinary Level", "Higher Level"],
581
+ "strands": {
582
+ "statistics_and_probability": {
583
+ "label": "Statistics and Probability",
584
+ "topics": {
585
+ "counting": {
586
+ "label": "Counting Principles",
587
+ "outcomes": [
588
+ "Apply fundamental principle of counting",
589
+ "Use permutations and combinations (HL)"
590
+ ]
591
+ },
592
+ "probability": {
593
+ "label": "Probability",
594
+ "outcomes": [
595
+ "Calculate probability of compound events",
596
+ "Use tree diagrams and two-way tables",
597
+ "Apply Bernoulli trials (HL)",
598
+ "Understand and apply the normal distribution (HL)",
599
+ "Use expected value"
600
+ ]
601
+ },
602
+ "statistics": {
603
+ "label": "Statistics",
604
+ "outcomes": [
605
+ "Design experiments and surveys",
606
+ "Construct and interpret histograms, scatter plots, box-and-whisker plots",
607
+ "Calculate and interpret standard deviation",
608
+ "Use the empirical rule and z-scores (HL)",
609
+ "Interpret correlation and distinguish from causation",
610
+ "Use hypothesis testing concepts (HL)"
611
+ ]
612
+ }
613
+ }
614
+ },
615
+ "geometry_and_trigonometry": {
616
+ "label": "Geometry and Trigonometry",
617
+ "topics": {
618
+ "synthetic_geometry": {
619
+ "label": "Synthetic Geometry",
620
+ "outcomes": [
621
+ "Apply and prove circle theorems (HL)",
622
+ "Apply all Junior Cycle theorems and extensions"
623
+ ]
624
+ },
625
+ "coordinate_geometry": {
626
+ "label": "Coordinate Geometry",
627
+ "outcomes": [
628
+ "Solve problems involving the line and circle",
629
+ "Find distance from a point to a line",
630
+ "Divide a line in a given ratio",
631
+ "Apply transformations on the coordinate plane"
632
+ ]
633
+ },
634
+ "trigonometry": {
635
+ "label": "Trigonometry",
636
+ "outcomes": [
637
+ "Work with the unit circle and radian measure",
638
+ "Graph trigonometric functions (sin, cos, tan)",
639
+ "Use sine rule and cosine rule",
640
+ "Solve trigonometric equations (HL)",
641
+ "Prove and apply trigonometric identities (HL)",
642
+ "Solve 3D trigonometry problems"
643
+ ]
644
+ }
645
+ }
646
+ },
647
+ "number": {
648
+ "label": "Number",
649
+ "topics": {
650
+ "number_theory": {
651
+ "label": "Number Theory",
652
+ "outcomes": [
653
+ "Revisit and extend number systems (reals, complex numbers HL)",
654
+ "Apply logarithms",
655
+ "Manipulate surds and indices",
656
+ "Work with complex numbers: addition, multiplication, Argand diagram (HL)"
657
+ ]
658
+ },
659
+ "financial_maths": {
660
+ "label": "Financial Maths",
661
+ "outcomes": [
662
+ "Solve compound interest problems (accumulated value, present value)",
663
+ "Solve problems involving depreciation",
664
+ "Understand and calculate APR",
665
+ "Solve mortgage and investment problems using amortisation (HL)"
666
+ ]
667
+ }
668
+ }
669
+ },
670
+ "algebra": {
671
+ "label": "Algebra",
672
+ "topics": {
673
+ "expressions_formulae": {
674
+ "label": "Expressions and Formulae",
675
+ "outcomes": [
676
+ "Factorise quadratic and cubic expressions",
677
+ "Manipulate algebraic fractions",
678
+ "Apply the binomial theorem (HL)",
679
+ "Use proof by induction (HL)"
680
+ ]
681
+ },
682
+ "equations": {
683
+ "label": "Equations",
684
+ "outcomes": [
685
+ "Solve quadratic equations (factoring, formula, completing the square)",
686
+ "Solve simultaneous equations (one linear, one quadratic)",
687
+ "Solve inequalities (linear, quadratic HL)",
688
+ "Solve exponential and logarithmic equations (HL)"
689
+ ]
690
+ },
691
+ "sequences_series": {
692
+ "label": "Sequences and Series",
693
+ "outcomes": [
694
+ "Identify and work with arithmetic sequences and series",
695
+ "Identify and work with geometric sequences and series",
696
+ "Find sum to n terms and sum to infinity (HL)",
697
+ "Apply sequences to real-world problems"
698
+ ]
699
+ }
700
+ }
701
+ },
702
+ "functions": {
703
+ "label": "Functions",
704
+ "topics": {
705
+ "functions_graphs": {
706
+ "label": "Functions and Graphs",
707
+ "outcomes": [
708
+ "Understand domain, range, injective, surjective, bijective (HL)",
709
+ "Graph polynomial, exponential and logarithmic functions",
710
+ "Perform transformations on functions (shift, stretch, reflect)",
711
+ "Compose and invert functions (HL)"
712
+ ]
713
+ },
714
+ "calculus": {
715
+ "label": "Calculus",
716
+ "outcomes": [
717
+ "Understand limits and continuity (HL)",
718
+ "Differentiate from first principles (HL)",
719
+ "Differentiate polynomial, trigonometric, exponential and log functions (HL)",
720
+ "Apply differentiation to find slopes, tangents, normals, rates of change",
721
+ "Find local maxima, minima and points of inflection",
722
+ "Integrate polynomial and simple trigonometric functions (HL)",
723
+ "Calculate area under a curve (HL)",
724
+ "Apply the trapezoidal rule"
725
+ ]
726
+ }
727
+ }
728
+ }
729
+ }
730
+ }
731
+ }
main.py ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Irish Maths AI — FastAPI backend.
3
+ Serves the chat API and static frontend.
4
+ """
5
+
6
+ import os
7
+ import json
8
+ import httpx
9
+ from dotenv import load_dotenv
10
+ from fastapi import FastAPI, Request
11
+ from fastapi.staticfiles import StaticFiles
12
+ from fastapi.responses import FileResponse, JSONResponse
13
+ from pydantic import BaseModel
14
+
15
+ from rag import search_curriculum, build_index
16
+
17
+ load_dotenv()
18
+
19
+ app = FastAPI(title="Irish Maths AI")
20
+
21
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY", "")
22
+ DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
23
+
24
+ # Load curriculum for topic browser
25
+ with open(os.path.join(DATA_DIR, "curriculum.json"), "r", encoding="utf-8") as f:
26
+ CURRICULUM = json.load(f)
27
+
28
+ # Build RAG index on startup
29
+ try:
30
+ build_index()
31
+ except Exception as e:
32
+ print(f"Warning: RAG index build failed ({e}). Will retry on first query.")
33
+
34
+
35
+ # ── Models ────────────────────────────────────────────────────────────────
36
+
37
+ class ChatRequest(BaseModel):
38
+ message: str
39
+ level: str = "" # "primary", "junior_cycle", "senior_cycle" or ""
40
+ class_group: str = "" # e.g. "5th Class", "Higher Level"
41
+ role: str = "student" # "student" or "teacher"
42
+ history: list = [] # prior messages [{role, content}]
43
+
44
+
45
+ SYSTEM_PROMPT_STUDENT = """You are **Mathaí** (pronounced "Mah-hee"), a friendly, encouraging Irish maths tutor.
46
+
47
+ RULES:
48
+ - You teach maths aligned to the Irish curriculum (Primary, Junior Cycle, Senior Cycle).
49
+ - Adapt your language to the student's class level. Use simple words for younger students.
50
+ - Always show step-by-step working. Use LaTeX notation wrapped in $...$ for inline maths and $$...$$ for display maths.
51
+ - After explaining, offer a practice question so the student can try.
52
+ - Be warm, positive and patient. Use emoji sparingly (🎯 ✅ 💡).
53
+ - If curriculum context is provided, reference the exact strand and topic.
54
+ - If you don't know, say so honestly. Never invent wrong maths.
55
+ - Keep answers concise — students lose focus on long walls of text.
56
+ - For primary students (Junior Infants to 6th Class), use very simple English and visual examples.
57
+ - For secondary students, be more rigorous but still clear.
58
+
59
+ You are speaking to a STUDENT."""
60
+
61
+ SYSTEM_PROMPT_TEACHER = """You are **Mathaí** (pronounced "Mah-hee"), an expert assistant for Irish maths teachers.
62
+
63
+ RULES:
64
+ - Provide curriculum-aligned resources, lesson plan ideas and assessment suggestions.
65
+ - Reference specific strands, topics and learning outcomes from the Irish curriculum.
66
+ - Use LaTeX notation wrapped in $...$ for inline maths and $$...$$ for display maths.
67
+ - Suggest differentiation strategies for mixed-ability classes.
68
+ - Be professional but approachable.
69
+ - If curriculum context is provided, cite exact strand, stage and learning outcomes.
70
+
71
+ You are speaking to a TEACHER."""
72
+
73
+
74
+ def _build_messages(req: ChatRequest, curriculum_context: str):
75
+ system = SYSTEM_PROMPT_TEACHER if req.role == "teacher" else SYSTEM_PROMPT_STUDENT
76
+
77
+ level_hint = ""
78
+ if req.class_group:
79
+ level_hint = f"\nThe user is in: {req.class_group}."
80
+ elif req.level:
81
+ labels = {"primary": "Primary School", "junior_cycle": "Junior Cycle", "senior_cycle": "Senior Cycle"}
82
+ level_hint = f"\nThe user's level: {labels.get(req.level, req.level)}."
83
+
84
+ if curriculum_context:
85
+ system += f"\n\n--- CURRICULUM CONTEXT (use this to ground your answer) ---\n{curriculum_context}"
86
+
87
+ if level_hint:
88
+ system += level_hint
89
+
90
+ messages = [{"role": "system", "content": system}]
91
+
92
+ # Add conversation history (last 10 turns max)
93
+ for msg in req.history[-10:]:
94
+ if msg.get("role") in ("user", "assistant"):
95
+ messages.append({"role": msg["role"], "content": msg["content"]})
96
+
97
+ messages.append({"role": "user", "content": req.message})
98
+ return messages
99
+
100
+
101
+ def _fallback_reply(question, rag_results, api_error=""):
102
+ """Generate a helpful curriculum-based reply when OpenAI API is unreachable."""
103
+ parts = []
104
+ parts.append("**I'm currently in offline mode** (can't reach the AI service), but here's what I found from the Irish curriculum:\n")
105
+
106
+ if rag_results:
107
+ for i, r in enumerate(rag_results[:3], 1):
108
+ m = r["metadata"]
109
+ label = m.get("topic_label", "Topic")
110
+ stage = m.get("stage_label", "") or m.get("level_label", "")
111
+ classes = m.get("classes", "")
112
+ strand = m.get("strand_label", "")
113
+
114
+ parts.append(f"**{i}. {label}** ({stage})")
115
+ if classes:
116
+ parts.append(f" Classes: {classes}")
117
+ parts.append(f" Strand: {strand}")
118
+
119
+ # Show the learning outcomes from the chunk text
120
+ lines = r["text"].split("\n")
121
+ outcomes = [l.strip() for l in lines if l.strip().startswith("- ")]
122
+ for o in outcomes[:4]:
123
+ parts.append(f" {o}")
124
+ parts.append("")
125
+
126
+ parts.append("💡 **Tip:** Try these search terms to explore further, or check [curriculumonline.ie](https://www.curriculumonline.ie/primary/curriculum-areas/mathematics/) for the full curriculum.")
127
+ else:
128
+ parts.append("I couldn't find a specific curriculum match for your question.")
129
+ parts.append("\n💡 Try asking about a specific topic like *fractions*, *algebra*, *Pythagoras*, or *area and perimeter*.")
130
+
131
+ if api_error and "timeout" not in api_error.lower():
132
+ parts.append(f"\n*(Connection issue: {api_error[:100]})*")
133
+
134
+ return "\n".join(parts)
135
+
136
+
137
+ # ── Endpoints ─────────────────────────────────────────────────────────────
138
+
139
+ @app.post("/api/chat")
140
+ async def chat(req: ChatRequest):
141
+ if not GROQ_API_KEY:
142
+ return JSONResponse(
143
+ {"reply": "⚠️ Groq API key not configured. Add GROQ_API_KEY to your .env file. Get a free key at console.groq.com", "sources": []},
144
+ status_code=200,
145
+ )
146
+
147
+ # RAG: find relevant curriculum chunks
148
+ rag_results = search_curriculum(req.message, level=req.level, n_results=4)
149
+ curriculum_context = "\n\n".join(r["text"] for r in rag_results)
150
+
151
+ sources = []
152
+ for r in rag_results:
153
+ m = r["metadata"]
154
+ sources.append({
155
+ "strand": m.get("strand_label", ""),
156
+ "topic": m.get("topic_label", ""),
157
+ "level": m.get("level_label", ""),
158
+ "stage": m.get("stage_label", ""),
159
+ "classes": m.get("classes", ""),
160
+ })
161
+
162
+ messages = _build_messages(req, curriculum_context)
163
+
164
+ try:
165
+ async with httpx.AsyncClient(timeout=60, verify=True) as client:
166
+ resp = await client.post(
167
+ "https://api.groq.com/openai/v1/chat/completions",
168
+ headers={
169
+ "Authorization": f"Bearer {GROQ_API_KEY}",
170
+ "Content-Type": "application/json",
171
+ },
172
+ json={
173
+ "model": "llama-3.3-70b-versatile",
174
+ "messages": messages,
175
+ "temperature": 0.4,
176
+ "max_tokens": 1500,
177
+ },
178
+ )
179
+ data = resp.json()
180
+ if "error" in data:
181
+ reply = _fallback_reply(req.message, rag_results, api_error=data["error"].get("message", ""))
182
+ else:
183
+ reply = data["choices"][0]["message"]["content"]
184
+ except Exception as e:
185
+ # Network blocked / timeout — use curriculum-based fallback
186
+ reply = _fallback_reply(req.message, rag_results, api_error=str(e))
187
+
188
+ return {"reply": reply, "sources": sources}
189
+
190
+
191
+ @app.get("/api/curriculum")
192
+ async def get_curriculum():
193
+ """Return the full curriculum tree for the topic browser."""
194
+ return CURRICULUM
195
+
196
+
197
+ @app.get("/api/curriculum/{level}")
198
+ async def get_curriculum_level(level: str):
199
+ """Return curriculum for a specific level."""
200
+ if level in CURRICULUM:
201
+ return CURRICULUM[level]
202
+ return JSONResponse({"error": "Level not found"}, status_code=404)
203
+
204
+
205
+ @app.get("/api/quick-topics")
206
+ async def quick_topics():
207
+ """Return popular quick-start topics for the home screen."""
208
+ return {
209
+ "student": {
210
+ "primary": [
211
+ {"label": "Adding & Subtracting", "query": "Help me with addition and subtraction", "icon": "➕"},
212
+ {"label": "Times Tables", "query": "Practice my times tables", "icon": "✖️"},
213
+ {"label": "Fractions", "query": "Explain fractions to me", "icon": "🍕"},
214
+ {"label": "Telling Time", "query": "Help me tell the time", "icon": "🕐"},
215
+ {"label": "Shapes", "query": "Teach me about shapes", "icon": "🔷"},
216
+ {"label": "Money", "query": "Help me with euros and cent", "icon": "💶"},
217
+ ],
218
+ "junior_cycle": [
219
+ {"label": "Algebra", "query": "Explain solving equations", "icon": "🔤"},
220
+ {"label": "Pythagoras", "query": "Explain the theorem of Pythagoras with examples", "icon": "📐"},
221
+ {"label": "Statistics", "query": "How do I calculate mean, median and mode?", "icon": "📊"},
222
+ {"label": "Trigonometry", "query": "Explain sin, cos and tan", "icon": "📏"},
223
+ {"label": "Coordinate Geometry", "query": "How do I find the slope of a line?", "icon": "📈"},
224
+ {"label": "Percentages", "query": "Help me with percentage problems", "icon": "💯"},
225
+ ],
226
+ "senior_cycle": [
227
+ {"label": "Differentiation", "query": "Explain differentiation from first principles", "icon": "📉"},
228
+ {"label": "Integration", "query": "How do I integrate functions?", "icon": "∫"},
229
+ {"label": "Sequences & Series", "query": "Explain arithmetic and geometric sequences", "icon": "🔢"},
230
+ {"label": "Probability", "query": "Help with Bernoulli trials", "icon": "🎲"},
231
+ {"label": "Complex Numbers", "query": "Explain complex numbers and the Argand diagram", "icon": "💠"},
232
+ {"label": "Financial Maths", "query": "How do I solve compound interest problems?", "icon": "🏦"},
233
+ ],
234
+ },
235
+ "teacher": [
236
+ {"label": "Lesson Plan Ideas", "query": "Suggest a lesson plan for teaching fractions to 4th class", "icon": "📋"},
237
+ {"label": "Differentiation Strategies", "query": "How can I differentiate maths for mixed-ability classes?", "icon": "🎯"},
238
+ {"label": "Assessment Ideas", "query": "Suggest assessment activities for Junior Cycle algebra", "icon": "✅"},
239
+ {"label": "Real-World Maths", "query": "Give me real-world examples to make maths engaging for 2nd years", "icon": "🌍"},
240
+ {"label": "Worksheet Generator", "query": "Create 10 practice questions on area and perimeter for 5th class", "icon": "📝"},
241
+ {"label": "Exam Prep", "query": "What are the key Leaving Cert Higher Level topics to revise?", "icon": "🎓"},
242
+ ],
243
+ }
244
+
245
+
246
+ # ── Static files ──────────────────────────────────────────────────────────
247
+
248
+ app.mount("/static", StaticFiles(directory=os.path.join(os.path.dirname(__file__), "static")), name="static")
249
+
250
+
251
+ @app.get("/")
252
+ async def root():
253
+ return FileResponse(os.path.join(os.path.dirname(__file__), "static", "index.html"))
254
+
255
+
256
+ if __name__ == "__main__":
257
+ import uvicorn
258
+ port = int(os.getenv("PORT", "8700"))
259
+ print("\n 🧮 Irish Maths AI — Mathaí")
260
+ print(f" http://localhost:{port}\n")
261
+ uvicorn.run(app, host="0.0.0.0", port=port)
rag.py ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ RAG pipeline — lightweight in-memory TF-IDF search over curriculum chunks.
3
+ No heavy dependencies (works on Python 3.14+).
4
+ """
5
+
6
+ import json
7
+ import math
8
+ import os
9
+ import re
10
+ from collections import Counter
11
+
12
+ DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
13
+
14
+ _index = None # lazy singleton
15
+
16
+
17
+ class CurriculumIndex:
18
+ """Simple TF-IDF based search over curriculum chunks."""
19
+
20
+ def __init__(self):
21
+ self.chunks = [] # list of {id, text, metadata}
22
+ self.idf = {} # word -> idf score
23
+ self.tfidf_vecs = [] # list of {word: tfidf_score} dicts
24
+
25
+ def _tokenize(self, text):
26
+ return re.findall(r"[a-z0-9]+", text.lower())
27
+
28
+ def add_chunks(self, chunks):
29
+ self.chunks = chunks
30
+ doc_count = len(chunks)
31
+
32
+ # Build document frequency
33
+ df = Counter()
34
+ tokenized = []
35
+ for c in chunks:
36
+ tokens = self._tokenize(c["text"])
37
+ unique = set(tokens)
38
+ for w in unique:
39
+ df[w] += 1
40
+ tokenized.append(tokens)
41
+
42
+ # IDF
43
+ self.idf = {}
44
+ for w, count in df.items():
45
+ self.idf[w] = math.log((doc_count + 1) / (count + 1)) + 1
46
+
47
+ # TF-IDF vectors per chunk
48
+ self.tfidf_vecs = []
49
+ for tokens in tokenized:
50
+ tf = Counter(tokens)
51
+ total = len(tokens) if tokens else 1
52
+ vec = {}
53
+ for w, count in tf.items():
54
+ vec[w] = (count / total) * self.idf.get(w, 1.0)
55
+ self.tfidf_vecs.append(vec)
56
+
57
+ def search(self, query, level="", n_results=4):
58
+ query_tokens = self._tokenize(query)
59
+ if not query_tokens:
60
+ return []
61
+
62
+ # Query TF-IDF
63
+ qtf = Counter(query_tokens)
64
+ qtotal = len(query_tokens)
65
+ qvec = {}
66
+ for w, count in qtf.items():
67
+ qvec[w] = (count / qtotal) * self.idf.get(w, 1.0)
68
+
69
+ # Cosine similarity
70
+ scores = []
71
+ for i, dvec in enumerate(self.tfidf_vecs):
72
+ # Optional level filter
73
+ if level and self.chunks[i]["metadata"].get("level") != level:
74
+ continue
75
+
76
+ dot = sum(qvec.get(w, 0) * dvec.get(w, 0) for w in qvec)
77
+ mag_q = math.sqrt(sum(v ** 2 for v in qvec.values()))
78
+ mag_d = math.sqrt(sum(v ** 2 for v in dvec.values()))
79
+ if mag_q == 0 or mag_d == 0:
80
+ sim = 0
81
+ else:
82
+ sim = dot / (mag_q * mag_d)
83
+ scores.append((sim, i))
84
+
85
+ scores.sort(reverse=True)
86
+ results = []
87
+ for sim, idx in scores[:n_results]:
88
+ if sim > 0:
89
+ c = self.chunks[idx]
90
+ results.append({
91
+ "text": c["text"],
92
+ "metadata": c["metadata"],
93
+ "score": round(sim, 4),
94
+ })
95
+ return results
96
+
97
+
98
+ def _flatten_curriculum(data):
99
+ """Walk curriculum JSON and produce flat list of searchable chunks."""
100
+ chunks = []
101
+
102
+ for level_key, level_data in data.items():
103
+ level_label = level_data.get("label", level_key)
104
+ strands = level_data.get("strands", {})
105
+
106
+ for strand_key, strand_data in strands.items():
107
+ strand_label = strand_data.get("label", strand_key)
108
+ topics = strand_data.get("topics", {})
109
+
110
+ for topic_key, topic_data in topics.items():
111
+ topic_label = topic_data.get("label", topic_key)
112
+
113
+ # Primary: outcomes_by_stage
114
+ outcomes_by_stage = topic_data.get("outcomes_by_stage", {})
115
+ for stage, outcomes in outcomes_by_stage.items():
116
+ stage_info = data[level_key].get("stages", {}).get(stage, {})
117
+ stage_label = stage_info.get("label", stage)
118
+ classes = ", ".join(stage_info.get("classes", []))
119
+
120
+ text = (
121
+ f"Level: {level_label}\n"
122
+ f"Stage: {stage_label} ({classes})\n"
123
+ f"Strand: {strand_label}\n"
124
+ f"Topic: {topic_label}\n"
125
+ f"Learning Outcomes:\n"
126
+ )
127
+ for o in outcomes:
128
+ text += f" - {o}\n"
129
+
130
+ chunks.append({
131
+ "id": f"{level_key}_{strand_key}_{topic_key}_{stage}",
132
+ "text": text,
133
+ "metadata": {
134
+ "level": level_key,
135
+ "level_label": level_label,
136
+ "strand": strand_key,
137
+ "strand_label": strand_label,
138
+ "topic": topic_key,
139
+ "topic_label": topic_label,
140
+ "stage": stage,
141
+ "stage_label": stage_label,
142
+ "classes": classes,
143
+ },
144
+ })
145
+
146
+ # Secondary: flat outcomes
147
+ outcomes = topic_data.get("outcomes", [])
148
+ if outcomes:
149
+ levels_list = data[level_key].get("levels", [])
150
+ text = (
151
+ f"Level: {level_label}\n"
152
+ f"Available at: {', '.join(levels_list)}\n"
153
+ f"Strand: {strand_label}\n"
154
+ f"Topic: {topic_label}\n"
155
+ f"Learning Outcomes:\n"
156
+ )
157
+ for o in outcomes:
158
+ text += f" - {o}\n"
159
+
160
+ chunks.append({
161
+ "id": f"{level_key}_{strand_key}_{topic_key}",
162
+ "text": text,
163
+ "metadata": {
164
+ "level": level_key,
165
+ "level_label": level_label,
166
+ "strand": strand_key,
167
+ "strand_label": strand_label,
168
+ "topic": topic_key,
169
+ "topic_label": topic_label,
170
+ "stage": "",
171
+ "stage_label": "",
172
+ "classes": ", ".join(levels_list),
173
+ },
174
+ })
175
+
176
+ return chunks
177
+
178
+
179
+ def build_index():
180
+ """Load curriculum.json and build the search index."""
181
+ global _index
182
+ curriculum_path = os.path.join(DATA_DIR, "curriculum.json")
183
+ with open(curriculum_path, "r", encoding="utf-8") as f:
184
+ data = json.load(f)
185
+
186
+ chunks = _flatten_curriculum(data)
187
+ _index = CurriculumIndex()
188
+ _index.add_chunks(chunks)
189
+ return len(chunks)
190
+
191
+
192
+ def search_curriculum(query, level="", n_results=4):
193
+ """Search the curriculum index."""
194
+ global _index
195
+ if _index is None:
196
+ build_index()
197
+ return _index.search(query, level=level, n_results=n_results)
198
+
199
+
200
+ if __name__ == "__main__":
201
+ n = build_index()
202
+ print(f"Indexed {n} curriculum chunks")
203
+ print()
204
+
205
+ results = search_curriculum("fractions for 4th class")
206
+ for r in results:
207
+ m = r["metadata"]
208
+ print(f"[{r['score']}] {m['topic_label']} -- {m['stage_label'] or m['level_label']}")
209
+ print(r["text"][:150])
210
+ print()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ httpx
4
+ python-dotenv
static/app.js ADDED
@@ -0,0 +1,385 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ── Irish Maths AI — Mathaí Frontend ──────────────────────────────── */
2
+
3
+ let state = {
4
+ role: "", // "student" | "teacher"
5
+ level: "", // "primary" | "junior_cycle" | "senior_cycle"
6
+ classGroup: "", // "5th Class", "Higher Level" etc.
7
+ history: [], // [{role, content}]
8
+ sending: false,
9
+ };
10
+
11
+ // Elements
12
+ const welcomeScreen = document.getElementById("welcomeScreen");
13
+ const chatScreen = document.getElementById("chatScreen");
14
+ const levelPicker = document.getElementById("levelPicker");
15
+ const classPicker = document.getElementById("classPicker");
16
+ const classGrid = document.getElementById("classGrid");
17
+ const chatMain = document.getElementById("chatMain");
18
+ const messages = document.getElementById("messages");
19
+ const quickTopics = document.getElementById("quickTopics");
20
+ const chatInput = document.getElementById("chatInput");
21
+ const sendBtn = document.getElementById("sendBtn");
22
+ const headerLevel = document.getElementById("headerLevel");
23
+ const topicsSidebar = document.getElementById("topicsSidebar");
24
+ const sidebarContent = document.getElementById("sidebarContent");
25
+
26
+ // ── Welcome Flow ─────────────────────────────────────────────────────
27
+
28
+ document.getElementById("pickStudent").addEventListener("click", () => {
29
+ state.role = "student";
30
+ document.querySelectorAll(".role-card").forEach(c => c.classList.remove("selected"));
31
+ document.getElementById("pickStudent").classList.add("selected");
32
+ levelPicker.style.display = "block";
33
+ classPicker.style.display = "none";
34
+ levelPicker.scrollIntoView({ behavior: "smooth" });
35
+ });
36
+
37
+ document.getElementById("pickTeacher").addEventListener("click", () => {
38
+ state.role = "teacher";
39
+ state.level = "";
40
+ state.classGroup = "Teacher";
41
+ startChat();
42
+ });
43
+
44
+ document.querySelectorAll(".level-card").forEach(card => {
45
+ card.addEventListener("click", () => {
46
+ state.level = card.dataset.level;
47
+
48
+ if (state.level === "primary") {
49
+ showClassPicker([
50
+ "Junior Infants", "Senior Infants",
51
+ "1st Class", "2nd Class",
52
+ "3rd Class", "4th Class",
53
+ "5th Class", "6th Class"
54
+ ]);
55
+ } else if (state.level === "junior_cycle") {
56
+ showClassPicker(["1st Year", "2nd Year", "3rd Year", "Ordinary Level", "Higher Level"]);
57
+ } else if (state.level === "senior_cycle") {
58
+ showClassPicker(["5th Year", "6th Year", "Foundation Level", "Ordinary Level", "Higher Level"]);
59
+ }
60
+ });
61
+ });
62
+
63
+ function showClassPicker(classes) {
64
+ classPicker.style.display = "block";
65
+ classGrid.innerHTML = "";
66
+ classes.forEach(c => {
67
+ const btn = document.createElement("button");
68
+ btn.className = "class-btn";
69
+ btn.textContent = c;
70
+ btn.addEventListener("click", () => {
71
+ state.classGroup = c;
72
+ startChat();
73
+ });
74
+ classGrid.appendChild(btn);
75
+ });
76
+ classPicker.scrollIntoView({ behavior: "smooth" });
77
+ }
78
+
79
+ // ── Start Chat ───────────────────────────────────────────────────────
80
+
81
+ function startChat() {
82
+ welcomeScreen.style.display = "none";
83
+ chatScreen.style.display = "flex";
84
+
85
+ // Set header level text
86
+ if (state.role === "teacher") {
87
+ headerLevel.textContent = "Teacher Mode";
88
+ } else {
89
+ const levelLabels = {
90
+ primary: "Primary",
91
+ junior_cycle: "Junior Cycle",
92
+ senior_cycle: "Senior Cycle"
93
+ };
94
+ headerLevel.textContent = `${levelLabels[state.level] || ""} · ${state.classGroup}`;
95
+ }
96
+
97
+ state.history = [];
98
+ messages.innerHTML = "";
99
+
100
+ // Show welcome message from Mathaí
101
+ const greeting = state.role === "teacher"
102
+ ? "Hello! 👋 I'm **Mathaí**, your Irish maths teaching assistant. I can help with lesson plans, worksheet ideas, curriculum references and more. What can I help with?"
103
+ : `Hello! 👋 I'm **Mathaí**, your maths buddy! I'm here to help you with any maths questions. Just ask me anything — no question is too simple. What would you like to learn today?`;
104
+
105
+ addMessage("ai", greeting);
106
+ loadQuickTopics();
107
+ loadTopicsSidebar();
108
+ chatInput.focus();
109
+ }
110
+
111
+ // ── Quick Topics ─────────────────────────────────────────────────────
112
+
113
+ async function loadQuickTopics() {
114
+ try {
115
+ const resp = await fetch("/api/quick-topics");
116
+ const data = await resp.json();
117
+ let topics;
118
+
119
+ if (state.role === "teacher") {
120
+ topics = data.teacher || [];
121
+ } else {
122
+ topics = (data.student && data.student[state.level]) || [];
123
+ }
124
+
125
+ quickTopics.innerHTML = "";
126
+ topics.forEach(t => {
127
+ const btn = document.createElement("button");
128
+ btn.className = "quick-topic-btn";
129
+ btn.innerHTML = `<span class="qt-icon">${t.icon || "📌"}</span> ${escapeHtml(t.label)}`;
130
+ btn.addEventListener("click", () => {
131
+ chatInput.value = t.query;
132
+ sendMessage();
133
+ quickTopics.style.display = "none";
134
+ });
135
+ quickTopics.appendChild(btn);
136
+ });
137
+ } catch (e) {
138
+ quickTopics.innerHTML = "";
139
+ }
140
+ }
141
+
142
+ // ── Topics Sidebar ───────────────────────────────────────────────────
143
+
144
+ document.getElementById("topicsBtn").addEventListener("click", () => {
145
+ topicsSidebar.classList.toggle("open");
146
+ });
147
+ document.getElementById("sidebarClose").addEventListener("click", () => {
148
+ topicsSidebar.classList.remove("open");
149
+ });
150
+
151
+ async function loadTopicsSidebar() {
152
+ const level = state.level || "primary";
153
+ try {
154
+ const resp = await fetch(`/api/curriculum/${level}`);
155
+ const data = await resp.json();
156
+ const strands = data.strands || {};
157
+
158
+ sidebarContent.innerHTML = "";
159
+ for (const [key, strand] of Object.entries(strands)) {
160
+ const div = document.createElement("div");
161
+ div.className = "sidebar-strand";
162
+
163
+ const header = document.createElement("div");
164
+ header.className = "strand-header";
165
+ header.textContent = strand.label || key;
166
+ div.appendChild(header);
167
+
168
+ const topics = strand.topics || {};
169
+ for (const [tKey, topic] of Object.entries(topics)) {
170
+ const btn = document.createElement("button");
171
+ btn.className = "topic-btn";
172
+ btn.textContent = topic.label || tKey;
173
+ btn.addEventListener("click", () => {
174
+ chatInput.value = `Explain ${topic.label} for ${state.classGroup || "me"}`;
175
+ topicsSidebar.classList.remove("open");
176
+ sendMessage();
177
+ });
178
+ div.appendChild(btn);
179
+ }
180
+ sidebarContent.appendChild(div);
181
+ }
182
+ } catch (e) {
183
+ sidebarContent.innerHTML = `<p style="padding:1rem;color:var(--text-muted)">Could not load topics.</p>`;
184
+ }
185
+ }
186
+
187
+ // ── Chat ─────────────────────────────────────────────────────────────
188
+
189
+ chatInput.addEventListener("keydown", (e) => {
190
+ if (e.key === "Enter" && !e.shiftKey) {
191
+ e.preventDefault();
192
+ sendMessage();
193
+ }
194
+ });
195
+
196
+ chatInput.addEventListener("input", () => {
197
+ chatInput.style.height = "auto";
198
+ chatInput.style.height = Math.min(chatInput.scrollHeight, 120) + "px";
199
+ });
200
+
201
+ sendBtn.addEventListener("click", sendMessage);
202
+
203
+ async function sendMessage() {
204
+ const text = chatInput.value.trim();
205
+ if (!text || state.sending) return;
206
+
207
+ state.sending = true;
208
+ sendBtn.disabled = true;
209
+ chatInput.value = "";
210
+ chatInput.style.height = "auto";
211
+
212
+ // Hide quick topics after first message
213
+ quickTopics.style.display = "none";
214
+
215
+ // Add user message
216
+ addMessage("user", text);
217
+ state.history.push({ role: "user", content: text });
218
+
219
+ // Show typing indicator
220
+ const typingEl = addTyping();
221
+
222
+ try {
223
+ const resp = await fetch("/api/chat", {
224
+ method: "POST",
225
+ headers: { "Content-Type": "application/json" },
226
+ body: JSON.stringify({
227
+ message: text,
228
+ level: state.level,
229
+ class_group: state.classGroup,
230
+ role: state.role,
231
+ history: state.history.slice(-10),
232
+ }),
233
+ });
234
+ const data = await resp.json();
235
+
236
+ typingEl.remove();
237
+
238
+ addMessage("ai", data.reply, data.sources || []);
239
+ state.history.push({ role: "assistant", content: data.reply });
240
+ } catch (e) {
241
+ typingEl.remove();
242
+ addMessage("ai", "Sorry, I couldn't connect. Please check your internet and try again.");
243
+ }
244
+
245
+ state.sending = false;
246
+ sendBtn.disabled = false;
247
+ chatInput.focus();
248
+ }
249
+
250
+ // ── Message Rendering ────────────────────────────────────────────────
251
+
252
+ function addMessage(type, content, sources = []) {
253
+ const div = document.createElement("div");
254
+ div.className = `msg msg-${type}`;
255
+
256
+ const avatar = document.createElement("div");
257
+ avatar.className = "msg-avatar";
258
+ avatar.textContent = type === "user" ? "🙋" : "🧮";
259
+
260
+ const bubble = document.createElement("div");
261
+ bubble.className = "msg-bubble";
262
+
263
+ if (type === "ai") {
264
+ bubble.innerHTML = renderMarkdown(content);
265
+ // Render KaTeX
266
+ if (window.renderMathInElement) {
267
+ renderMathInElement(bubble, {
268
+ delimiters: [
269
+ { left: "$$", right: "$$", display: true },
270
+ { left: "$", right: "$", display: false },
271
+ { left: "\\(", right: "\\)", display: false },
272
+ { left: "\\[", right: "\\]", display: true },
273
+ ],
274
+ throwOnError: false,
275
+ });
276
+ }
277
+
278
+ // Add source tags
279
+ if (sources.length > 0) {
280
+ const sourcesDiv = document.createElement("div");
281
+ sourcesDiv.className = "msg-sources";
282
+ const seen = new Set();
283
+ sources.forEach(s => {
284
+ const key = `${s.strand} · ${s.topic}`;
285
+ if (seen.has(key)) return;
286
+ seen.add(key);
287
+ const tag = document.createElement("span");
288
+ tag.className = "source-tag";
289
+ tag.textContent = key;
290
+ sourcesDiv.appendChild(tag);
291
+ });
292
+ bubble.appendChild(sourcesDiv);
293
+ }
294
+ } else {
295
+ bubble.textContent = content;
296
+ }
297
+
298
+ div.appendChild(avatar);
299
+ div.appendChild(bubble);
300
+ messages.appendChild(div);
301
+ scrollToBottom();
302
+ }
303
+
304
+ function addTyping() {
305
+ const div = document.createElement("div");
306
+ div.className = "msg msg-ai";
307
+ div.id = "typing-indicator";
308
+
309
+ const avatar = document.createElement("div");
310
+ avatar.className = "msg-avatar";
311
+ avatar.textContent = "🧮";
312
+
313
+ const bubble = document.createElement("div");
314
+ bubble.className = "msg-bubble";
315
+ bubble.innerHTML = `<div class="typing-dots"><span></span><span></span><span></span></div>`;
316
+
317
+ div.appendChild(avatar);
318
+ div.appendChild(bubble);
319
+ messages.appendChild(div);
320
+ scrollToBottom();
321
+ return div;
322
+ }
323
+
324
+ function scrollToBottom() {
325
+ chatMain.scrollTop = chatMain.scrollHeight;
326
+ }
327
+
328
+ // ── Simple Markdown → HTML ───────────────────────────────────────────
329
+
330
+ function renderMarkdown(text) {
331
+ if (!text) return "";
332
+ let html = escapeHtml(text);
333
+
334
+ // Bold: **text**
335
+ html = html.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>");
336
+ // Italic: *text*
337
+ html = html.replace(/\*(.+?)\*/g, "<em>$1</em>");
338
+ // Inline code: `text`
339
+ html = html.replace(/`(.+?)`/g, "<code>$1</code>");
340
+ // Unordered list items: - text or • text
341
+ html = html.replace(/^[\-•]\s+(.+)$/gm, "<li>$1</li>");
342
+ // Ordered list items: 1. text
343
+ html = html.replace(/^\d+\.\s+(.+)$/gm, "<li>$1</li>");
344
+ // Wrap consecutive <li> in <ul>
345
+ html = html.replace(/((?:<li>.*<\/li>\n?)+)/g, "<ul>$1</ul>");
346
+ // Headings: ### text
347
+ html = html.replace(/^###\s+(.+)$/gm, "<strong>$1</strong>");
348
+ // Paragraphs (double newline)
349
+ html = html.replace(/\n\n/g, "</p><p>");
350
+ // Single newlines
351
+ html = html.replace(/\n/g, "<br>");
352
+
353
+ return `<p>${html}</p>`;
354
+ }
355
+
356
+ function escapeHtml(str) {
357
+ const div = document.createElement("div");
358
+ div.textContent = str;
359
+ return div.innerHTML;
360
+ }
361
+
362
+ // ── Header Buttons ───────────────────────────────────────────────────
363
+
364
+ document.getElementById("backBtn").addEventListener("click", () => {
365
+ chatScreen.style.display = "none";
366
+ welcomeScreen.style.display = "flex";
367
+ state.history = [];
368
+ // Reset selections
369
+ document.querySelectorAll(".role-card").forEach(c => c.classList.remove("selected"));
370
+ levelPicker.style.display = "none";
371
+ classPicker.style.display = "none";
372
+ });
373
+
374
+ document.getElementById("newChatBtn").addEventListener("click", () => {
375
+ state.history = [];
376
+ messages.innerHTML = "";
377
+ quickTopics.style.display = "flex";
378
+ loadQuickTopics();
379
+
380
+ const greeting = state.role === "teacher"
381
+ ? "Fresh start! What would you like help with?"
382
+ : "Let's start fresh! 🎯 What maths topic can I help you with?";
383
+ addMessage("ai", greeting);
384
+ chatInput.focus();
385
+ });
static/index.html ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Mathaí — Irish Maths AI Tutor</title>
7
+ <link rel="stylesheet" href="/static/styles.css">
8
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
9
+ <!-- KaTeX for maths rendering -->
10
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">
11
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
12
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js"></script>
13
+ </head>
14
+ <body>
15
+ <!-- ── Welcome Screen ─────────────────────────────────────────── -->
16
+ <div id="welcomeScreen" class="welcome-screen">
17
+ <div class="welcome-content">
18
+ <div class="welcome-hero">
19
+ <div class="hero-icon">🧮</div>
20
+ <h1>Mathaí</h1>
21
+ <p class="hero-sub">Your Irish Maths AI Tutor</p>
22
+ <p class="hero-desc">Get help with any maths topic from the Irish curriculum.<br>Primary, Junior Cycle &amp; Leaving Cert.</p>
23
+ </div>
24
+
25
+ <div class="role-picker">
26
+ <h3>I am a...</h3>
27
+ <div class="role-cards">
28
+ <button class="role-card" data-role="student" id="pickStudent">
29
+ <span class="role-icon">🎒</span>
30
+ <span class="role-label">Student</span>
31
+ <span class="role-hint">Get help with homework &amp; study</span>
32
+ </button>
33
+ <button class="role-card" data-role="teacher" id="pickTeacher">
34
+ <span class="role-icon">👩‍🏫</span>
35
+ <span class="role-label">Teacher</span>
36
+ <span class="role-hint">Lesson plans, worksheets &amp; ideas</span>
37
+ </button>
38
+ </div>
39
+ </div>
40
+
41
+ <!-- Level picker (shown after student is picked) -->
42
+ <div class="level-picker" id="levelPicker" style="display:none;">
43
+ <h3>What level are you?</h3>
44
+ <div class="level-cards">
45
+ <button class="level-card" data-level="primary">
46
+ <span class="level-emoji">🏫</span>
47
+ <span class="level-name">Primary</span>
48
+ <span class="level-detail">Junior Infants – 6th Class</span>
49
+ </button>
50
+ <button class="level-card" data-level="junior_cycle">
51
+ <span class="level-emoji">📚</span>
52
+ <span class="level-name">Junior Cycle</span>
53
+ <span class="level-detail">1st – 3rd Year</span>
54
+ </button>
55
+ <button class="level-card" data-level="senior_cycle">
56
+ <span class="level-emoji">🎓</span>
57
+ <span class="level-name">Senior Cycle</span>
58
+ <span class="level-detail">5th & 6th Year / Leaving Cert</span>
59
+ </button>
60
+ </div>
61
+ </div>
62
+
63
+ <!-- Class picker for primary (shown after primary is picked) -->
64
+ <div class="class-picker" id="classPicker" style="display:none;">
65
+ <h3>What class are you in?</h3>
66
+ <div class="class-grid" id="classGrid"></div>
67
+ </div>
68
+ </div>
69
+ </div>
70
+
71
+ <!-- ── Chat Screen ────────────────────────────────────────────── -->
72
+ <div id="chatScreen" class="chat-screen" style="display:none;">
73
+ <header class="chat-header">
74
+ <div class="header-left">
75
+ <button class="btn-back" id="backBtn" title="Back to start">←</button>
76
+ <div class="header-brand">
77
+ <span class="brand-icon">🧮</span>
78
+ <div>
79
+ <span class="brand-name">Mathaí</span>
80
+ <span class="brand-level" id="headerLevel"></span>
81
+ </div>
82
+ </div>
83
+ </div>
84
+ <div class="header-right">
85
+ <button class="btn-topics" id="topicsBtn" title="Browse topics">📖 Topics</button>
86
+ <button class="btn-new-chat" id="newChatBtn" title="New conversation">+ New Chat</button>
87
+ </div>
88
+ </header>
89
+
90
+ <main class="chat-main" id="chatMain">
91
+ <!-- Quick topic buttons -->
92
+ <div class="quick-topics" id="quickTopics"></div>
93
+
94
+ <!-- Messages appear here -->
95
+ <div class="messages" id="messages"></div>
96
+ </main>
97
+
98
+ <div class="chat-input-area">
99
+ <div class="input-row">
100
+ <textarea id="chatInput" placeholder="Ask me anything about maths..." rows="1"></textarea>
101
+ <button class="btn-send" id="sendBtn" title="Send">
102
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>
103
+ </button>
104
+ </div>
105
+ <div class="input-hint">
106
+ Mathaí follows the Irish curriculum. Answers may not always be perfect — always check with your teacher!
107
+ </div>
108
+ </div>
109
+
110
+ <!-- Topics sidebar -->
111
+ <div class="topics-sidebar" id="topicsSidebar">
112
+ <div class="sidebar-header">
113
+ <h3>📖 Browse Topics</h3>
114
+ <button class="sidebar-close" id="sidebarClose">&times;</button>
115
+ </div>
116
+ <div class="sidebar-content" id="sidebarContent"></div>
117
+ </div>
118
+ </div>
119
+
120
+ <script src="/static/app.js"></script>
121
+ </body>
122
+ </html>
static/styles.css ADDED
@@ -0,0 +1,570 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ── Irish Maths AI — Mathaí Styles ─────────────────────────────────── */
2
+
3
+ :root {
4
+ --bg: #fafbfc;
5
+ --bg-white: #ffffff;
6
+ --accent: #4f46e5;
7
+ --accent-light: #eef2ff;
8
+ --accent-hover: #4338ca;
9
+ --green: #059669;
10
+ --green-light: #ecfdf5;
11
+ --orange: #d97706;
12
+ --orange-light: #fffbeb;
13
+ --text: #1e293b;
14
+ --text-muted: #64748b;
15
+ --text-light: #94a3b8;
16
+ --border: #e2e8f0;
17
+ --border-light: #f1f5f9;
18
+ --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
19
+ --shadow: 0 4px 16px rgba(0,0,0,0.08);
20
+ --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
21
+ --radius: 12px;
22
+ --radius-sm: 8px;
23
+ --radius-lg: 20px;
24
+ }
25
+
26
+ * { margin: 0; padding: 0; box-sizing: border-box; }
27
+
28
+ body {
29
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
30
+ background: var(--bg);
31
+ color: var(--text);
32
+ min-height: 100vh;
33
+ overflow: hidden;
34
+ }
35
+
36
+ /* ── Welcome Screen ───────────────────────────────────────────────── */
37
+ .welcome-screen {
38
+ min-height: 100vh;
39
+ display: flex;
40
+ align-items: center;
41
+ justify-content: center;
42
+ padding: 2rem;
43
+ overflow-y: auto;
44
+ background: linear-gradient(135deg, #eef2ff 0%, #fafbfc 50%, #ecfdf5 100%);
45
+ }
46
+
47
+ .welcome-content {
48
+ max-width: 560px;
49
+ width: 100%;
50
+ text-align: center;
51
+ }
52
+
53
+ .welcome-hero {
54
+ margin-bottom: 2rem;
55
+ }
56
+
57
+ .hero-icon {
58
+ font-size: 4rem;
59
+ margin-bottom: 0.5rem;
60
+ animation: bounce 2s ease-in-out infinite;
61
+ }
62
+
63
+ @keyframes bounce {
64
+ 0%, 100% { transform: translateY(0); }
65
+ 50% { transform: translateY(-8px); }
66
+ }
67
+
68
+ .welcome-hero h1 {
69
+ font-size: 2.8rem;
70
+ font-weight: 800;
71
+ background: linear-gradient(135deg, var(--accent), var(--green));
72
+ -webkit-background-clip: text;
73
+ -webkit-text-fill-color: transparent;
74
+ background-clip: text;
75
+ margin-bottom: 0.25rem;
76
+ }
77
+
78
+ .hero-sub {
79
+ font-size: 1.1rem;
80
+ font-weight: 500;
81
+ color: var(--text-muted);
82
+ margin-bottom: 0.5rem;
83
+ }
84
+
85
+ .hero-desc {
86
+ font-size: 0.9rem;
87
+ color: var(--text-light);
88
+ line-height: 1.6;
89
+ }
90
+
91
+ /* Role picker */
92
+ .role-picker h3, .level-picker h3, .class-picker h3 {
93
+ font-size: 1rem;
94
+ font-weight: 600;
95
+ color: var(--text-muted);
96
+ margin-bottom: 1rem;
97
+ }
98
+
99
+ .role-cards {
100
+ display: flex;
101
+ gap: 1rem;
102
+ justify-content: center;
103
+ }
104
+
105
+ .role-card {
106
+ background: var(--bg-white);
107
+ border: 2px solid var(--border);
108
+ border-radius: var(--radius-lg);
109
+ padding: 1.5rem 2rem;
110
+ cursor: pointer;
111
+ transition: all 0.2s;
112
+ display: flex;
113
+ flex-direction: column;
114
+ align-items: center;
115
+ gap: 0.4rem;
116
+ min-width: 160px;
117
+ }
118
+
119
+ .role-card:hover {
120
+ border-color: var(--accent);
121
+ transform: translateY(-3px);
122
+ box-shadow: var(--shadow);
123
+ }
124
+
125
+ .role-card.selected {
126
+ border-color: var(--accent);
127
+ background: var(--accent-light);
128
+ }
129
+
130
+ .role-icon { font-size: 2rem; }
131
+ .role-label { font-size: 1.05rem; font-weight: 600; color: var(--text); }
132
+ .role-hint { font-size: 0.75rem; color: var(--text-muted); }
133
+
134
+ /* Level picker */
135
+ .level-picker {
136
+ margin-top: 1.5rem;
137
+ animation: fadeUp 0.3s ease;
138
+ }
139
+
140
+ .level-cards {
141
+ display: flex;
142
+ gap: 0.75rem;
143
+ justify-content: center;
144
+ flex-wrap: wrap;
145
+ }
146
+
147
+ .level-card {
148
+ background: var(--bg-white);
149
+ border: 2px solid var(--border);
150
+ border-radius: var(--radius);
151
+ padding: 1rem 1.25rem;
152
+ cursor: pointer;
153
+ transition: all 0.2s;
154
+ text-align: center;
155
+ min-width: 140px;
156
+ display: flex;
157
+ flex-direction: column;
158
+ gap: 0.2rem;
159
+ }
160
+
161
+ .level-card:hover {
162
+ border-color: var(--green);
163
+ transform: translateY(-2px);
164
+ box-shadow: var(--shadow-sm);
165
+ }
166
+
167
+ .level-emoji { font-size: 1.5rem; }
168
+ .level-name { font-size: 0.95rem; font-weight: 600; color: var(--text); }
169
+ .level-detail { font-size: 0.72rem; color: var(--text-muted); }
170
+
171
+ /* Class picker */
172
+ .class-picker {
173
+ margin-top: 1.5rem;
174
+ animation: fadeUp 0.3s ease;
175
+ }
176
+
177
+ .class-grid {
178
+ display: grid;
179
+ grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
180
+ gap: 0.6rem;
181
+ max-width: 400px;
182
+ margin: 0 auto;
183
+ }
184
+
185
+ .class-btn {
186
+ background: var(--bg-white);
187
+ border: 2px solid var(--border);
188
+ border-radius: var(--radius-sm);
189
+ padding: 0.7rem 0.5rem;
190
+ cursor: pointer;
191
+ font-size: 0.85rem;
192
+ font-weight: 500;
193
+ transition: all 0.15s;
194
+ color: var(--text);
195
+ }
196
+
197
+ .class-btn:hover {
198
+ border-color: var(--accent);
199
+ background: var(--accent-light);
200
+ }
201
+
202
+ @keyframes fadeUp {
203
+ from { opacity: 0; transform: translateY(12px); }
204
+ to { opacity: 1; transform: translateY(0); }
205
+ }
206
+
207
+ /* ── Chat Screen ──────────────────────────────────────────────────── */
208
+ .chat-screen {
209
+ height: 100vh;
210
+ display: flex;
211
+ flex-direction: column;
212
+ }
213
+
214
+ .chat-header {
215
+ display: flex;
216
+ justify-content: space-between;
217
+ align-items: center;
218
+ padding: 0.6rem 1rem;
219
+ background: var(--bg-white);
220
+ border-bottom: 1px solid var(--border);
221
+ z-index: 10;
222
+ }
223
+
224
+ .header-left {
225
+ display: flex;
226
+ align-items: center;
227
+ gap: 0.75rem;
228
+ }
229
+
230
+ .btn-back {
231
+ background: none;
232
+ border: 1px solid var(--border);
233
+ border-radius: var(--radius-sm);
234
+ padding: 0.4rem 0.6rem;
235
+ cursor: pointer;
236
+ font-size: 1rem;
237
+ color: var(--text-muted);
238
+ transition: all 0.15s;
239
+ }
240
+ .btn-back:hover { background: var(--bg); color: var(--text); }
241
+
242
+ .header-brand {
243
+ display: flex;
244
+ align-items: center;
245
+ gap: 0.5rem;
246
+ }
247
+ .brand-icon { font-size: 1.3rem; }
248
+ .brand-name { font-weight: 700; font-size: 1rem; color: var(--text); }
249
+ .brand-level {
250
+ display: block;
251
+ font-size: 0.7rem;
252
+ color: var(--text-muted);
253
+ font-weight: 400;
254
+ }
255
+
256
+ .header-right {
257
+ display: flex;
258
+ align-items: center;
259
+ gap: 0.6rem;
260
+ }
261
+
262
+ .btn-topics, .btn-new-chat {
263
+ padding: 0.4rem 0.8rem;
264
+ border: 1px solid var(--border);
265
+ border-radius: var(--radius-sm);
266
+ background: var(--bg-white);
267
+ font-size: 0.8rem;
268
+ font-weight: 500;
269
+ cursor: pointer;
270
+ color: var(--text);
271
+ transition: all 0.15s;
272
+ }
273
+ .btn-topics:hover, .btn-new-chat:hover {
274
+ background: var(--bg);
275
+ border-color: var(--text-muted);
276
+ }
277
+
278
+ /* Chat main area */
279
+ .chat-main {
280
+ flex: 1;
281
+ overflow-y: auto;
282
+ padding: 1rem 1rem 0.5rem;
283
+ display: flex;
284
+ flex-direction: column;
285
+ }
286
+
287
+ /* Quick topics buttons */
288
+ .quick-topics {
289
+ display: flex;
290
+ flex-wrap: wrap;
291
+ gap: 0.5rem;
292
+ justify-content: center;
293
+ padding: 0.5rem 0 1rem;
294
+ max-width: 640px;
295
+ margin: 0 auto;
296
+ }
297
+
298
+ .quick-topic-btn {
299
+ padding: 0.5rem 0.9rem;
300
+ border: 1px solid var(--border);
301
+ border-radius: 20px;
302
+ background: var(--bg-white);
303
+ font-size: 0.82rem;
304
+ cursor: pointer;
305
+ transition: all 0.15s;
306
+ color: var(--text);
307
+ display: flex;
308
+ align-items: center;
309
+ gap: 0.35rem;
310
+ }
311
+ .quick-topic-btn:hover {
312
+ border-color: var(--accent);
313
+ background: var(--accent-light);
314
+ transform: translateY(-1px);
315
+ }
316
+ .quick-topic-btn .qt-icon { font-size: 0.9rem; }
317
+
318
+ /* Messages */
319
+ .messages {
320
+ flex: 1;
321
+ max-width: 720px;
322
+ width: 100%;
323
+ margin: 0 auto;
324
+ display: flex;
325
+ flex-direction: column;
326
+ gap: 0.75rem;
327
+ }
328
+
329
+ .msg {
330
+ display: flex;
331
+ gap: 0.6rem;
332
+ animation: fadeUp 0.25s ease;
333
+ }
334
+
335
+ .msg-user {
336
+ flex-direction: row-reverse;
337
+ }
338
+
339
+ .msg-avatar {
340
+ width: 32px;
341
+ height: 32px;
342
+ border-radius: 50%;
343
+ display: flex;
344
+ align-items: center;
345
+ justify-content: center;
346
+ font-size: 0.9rem;
347
+ flex-shrink: 0;
348
+ margin-top: 4px;
349
+ }
350
+
351
+ .msg-user .msg-avatar {
352
+ background: var(--accent-light);
353
+ }
354
+ .msg-ai .msg-avatar {
355
+ background: var(--green-light);
356
+ }
357
+
358
+ .msg-bubble {
359
+ max-width: 85%;
360
+ padding: 0.75rem 1rem;
361
+ border-radius: var(--radius);
362
+ line-height: 1.65;
363
+ font-size: 0.92rem;
364
+ word-wrap: break-word;
365
+ }
366
+
367
+ .msg-user .msg-bubble {
368
+ background: var(--accent);
369
+ color: white;
370
+ border-bottom-right-radius: 4px;
371
+ }
372
+
373
+ .msg-ai .msg-bubble {
374
+ background: var(--bg-white);
375
+ border: 1px solid var(--border);
376
+ border-bottom-left-radius: 4px;
377
+ color: var(--text);
378
+ }
379
+
380
+ .msg-ai .msg-bubble p { margin-bottom: 0.6rem; }
381
+ .msg-ai .msg-bubble p:last-child { margin-bottom: 0; }
382
+
383
+ .msg-ai .msg-bubble ul, .msg-ai .msg-bubble ol {
384
+ margin: 0.4rem 0 0.6rem 1.2rem;
385
+ }
386
+ .msg-ai .msg-bubble li { margin-bottom: 0.25rem; }
387
+
388
+ .msg-ai .msg-bubble strong { font-weight: 600; }
389
+
390
+ .msg-ai .msg-bubble code {
391
+ background: var(--border-light);
392
+ padding: 0.15rem 0.35rem;
393
+ border-radius: 4px;
394
+ font-size: 0.85em;
395
+ }
396
+
397
+ /* Curriculum source tags below AI message */
398
+ .msg-sources {
399
+ display: flex;
400
+ flex-wrap: wrap;
401
+ gap: 0.35rem;
402
+ margin-top: 0.5rem;
403
+ }
404
+
405
+ .source-tag {
406
+ padding: 0.2rem 0.5rem;
407
+ border-radius: 4px;
408
+ font-size: 0.68rem;
409
+ font-weight: 500;
410
+ background: var(--accent-light);
411
+ color: var(--accent);
412
+ }
413
+
414
+ /* Typing indicator */
415
+ .typing-dots {
416
+ display: flex;
417
+ gap: 4px;
418
+ padding: 0.75rem 1rem;
419
+ }
420
+ .typing-dots span {
421
+ width: 8px; height: 8px;
422
+ background: var(--text-light);
423
+ border-radius: 50%;
424
+ animation: blink 1.4s infinite;
425
+ }
426
+ .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
427
+ .typing-dots span:nth-child(3) { animation-delay: 0.4s; }
428
+
429
+ @keyframes blink {
430
+ 0%, 80%, 100% { opacity: 0.3; }
431
+ 40% { opacity: 1; }
432
+ }
433
+
434
+ /* Chat input area */
435
+ .chat-input-area {
436
+ padding: 0.6rem 1rem 0.75rem;
437
+ background: var(--bg-white);
438
+ border-top: 1px solid var(--border);
439
+ }
440
+
441
+ .input-row {
442
+ display: flex;
443
+ align-items: flex-end;
444
+ gap: 0.5rem;
445
+ max-width: 720px;
446
+ margin: 0 auto;
447
+ }
448
+
449
+ #chatInput {
450
+ flex: 1;
451
+ border: 1.5px solid var(--border);
452
+ border-radius: var(--radius);
453
+ padding: 0.7rem 1rem;
454
+ font-family: inherit;
455
+ font-size: 0.92rem;
456
+ line-height: 1.5;
457
+ resize: none;
458
+ color: var(--text);
459
+ background: var(--bg);
460
+ transition: border-color 0.15s;
461
+ max-height: 120px;
462
+ overflow-y: auto;
463
+ }
464
+ #chatInput:focus { outline: none; border-color: var(--accent); }
465
+ #chatInput::placeholder { color: var(--text-light); }
466
+
467
+ .btn-send {
468
+ padding: 0.65rem;
469
+ background: var(--accent);
470
+ color: white;
471
+ border: none;
472
+ border-radius: var(--radius);
473
+ cursor: pointer;
474
+ transition: all 0.15s;
475
+ display: flex;
476
+ align-items: center;
477
+ justify-content: center;
478
+ }
479
+ .btn-send:hover { background: var(--accent-hover); transform: translateY(-1px); }
480
+ .btn-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
481
+
482
+ .input-hint {
483
+ text-align: center;
484
+ font-size: 0.7rem;
485
+ color: var(--text-light);
486
+ margin-top: 0.4rem;
487
+ }
488
+
489
+ /* ── Topics Sidebar ───────────────────────────────────────────────── */
490
+ .topics-sidebar {
491
+ position: fixed;
492
+ top: 0; right: -380px;
493
+ width: 360px;
494
+ max-width: 90vw;
495
+ height: 100vh;
496
+ background: var(--bg-white);
497
+ border-left: 1px solid var(--border);
498
+ z-index: 100;
499
+ transition: right 0.3s ease;
500
+ box-shadow: var(--shadow-lg);
501
+ display: flex;
502
+ flex-direction: column;
503
+ }
504
+
505
+ .topics-sidebar.open { right: 0; }
506
+
507
+ .sidebar-header {
508
+ display: flex;
509
+ justify-content: space-between;
510
+ align-items: center;
511
+ padding: 1rem;
512
+ border-bottom: 1px solid var(--border);
513
+ }
514
+
515
+ .sidebar-header h3 { font-size: 1rem; font-weight: 600; }
516
+
517
+ .sidebar-close {
518
+ background: none; border: none; font-size: 1.4rem;
519
+ cursor: pointer; color: var(--text-muted);
520
+ padding: 0.2rem 0.5rem; border-radius: 4px;
521
+ }
522
+ .sidebar-close:hover { background: var(--bg); }
523
+
524
+ .sidebar-content {
525
+ flex: 1;
526
+ overflow-y: auto;
527
+ padding: 0.75rem;
528
+ }
529
+
530
+ .sidebar-strand {
531
+ margin-bottom: 0.75rem;
532
+ }
533
+
534
+ .strand-header {
535
+ font-size: 0.82rem;
536
+ font-weight: 600;
537
+ color: var(--text-muted);
538
+ padding: 0.4rem 0.5rem;
539
+ text-transform: uppercase;
540
+ letter-spacing: 0.03em;
541
+ }
542
+
543
+ .topic-btn {
544
+ display: block;
545
+ width: 100%;
546
+ text-align: left;
547
+ padding: 0.55rem 0.75rem;
548
+ border: none;
549
+ background: none;
550
+ border-radius: var(--radius-sm);
551
+ cursor: pointer;
552
+ font-size: 0.85rem;
553
+ color: var(--text);
554
+ transition: background 0.1s;
555
+ }
556
+ .topic-btn:hover { background: var(--accent-light); }
557
+
558
+ /* ── Responsive ───────────────────────────────────────────────────── */
559
+ @media (max-width: 640px) {
560
+ .welcome-hero h1 { font-size: 2rem; }
561
+ .role-cards { flex-direction: column; align-items: center; }
562
+ .role-card { min-width: 200px; width: 100%; }
563
+ .level-cards { flex-direction: column; align-items: center; }
564
+ .level-card { width: 100%; }
565
+
566
+ .chat-header { padding: 0.5rem 0.6rem; }
567
+ .btn-topics span { display: none; }
568
+ .msg-bubble { max-width: 92%; font-size: 0.88rem; }
569
+ .header-right { gap: 0.3rem; }
570
+ }