File size: 242,687 Bytes
1f3051b
 
 
 
 
0e14b1c
1f3051b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
    <title>3D Periodic Table for Students</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
            color: #fff;
            overflow: hidden;
            position: fixed;
            width: 100%;
            height: 100%;
            -webkit-overflow-scrolling: touch;
            touch-action: none;
        }
        canvas {
            touch-action: none;
        }
        #loading {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0, 0, 0, 0.9); display: flex; flex-direction: column;
            justify-content: center; align-items: center; z-index: 1000;
        }
        .spinner {
            width: 50px; height: 50px; border: 5px solid rgba(255, 255, 255, 0.3);
            border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite;
        }
        @keyframes spin { to { transform: rotate(360deg); } }
        #loading p { margin-top: 20px; font-size: 18px; }
        #app-container { width: 100vw; height: 100vh; position: relative; display: none; }
        #canvas-container { width: 100%; height: 100%; }
        #info-panel-wrapper {
            position: absolute; top: 0; right: 0; height: 100vh;
            transition: transform 0.3s ease;
        }
        #info-panel-wrapper.hidden { 
            display: none;
        }
        #info-panel-wrapper.collapsed {
            transform: translateX(100%);
        }
        #info-panel {
            background: rgba(0, 0, 0, 0.8);
            padding: 20px; max-width: 450px; height: 100%;
            overflow-y: auto; backdrop-filter: blur(10px); border-left: 1px solid rgba(255, 255, 255, 0.2);
        }
        #info-panel-toggle {
            position: absolute;
            left: -40px;
            top: 50%;
            transform: translateY(-50%);
            width: 40px;
            height: 80px;
            background: rgba(0, 0, 0, 0.8);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-right: none;
            border-radius: 10px 0 0 10px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            color: #4fc3f7;
            transition: background 0.3s;
            user-select: none;
            z-index: 10;
        }
        #info-panel-toggle:hover {
            background: rgba(0, 0, 0, 0.9);
        }
        #info-panel h2 { margin-bottom: 10px; color: #4fc3f7; }
        #element-details { margin-bottom: 15px; font-size: 14px; color: #ccc; }
        .origin-badge {
            display: inline-block; padding: 4px 8px; margin: 2px; border-radius: 4px;
            font-size: 11px; font-weight: bold;
        }
        .astronomy-info {
            background: rgba(79, 195, 247, 0.1); border-left: 3px solid #4fc3f7;
            padding: 10px; margin: 10px 0; border-radius: 4px; font-size: 13px; line-height: 1.5;
        }
        .astronomy-info h4 { color: #4fc3f7; margin-bottom: 5px; font-size: 14px; }
        .chemistry-info {
            background: rgba(126, 211, 33, 0.1); border-left: 3px solid #7ED321;
            padding: 10px; margin: 10px 0; border-radius: 4px; font-size: 13px; line-height: 1.5;
        }
        .chemistry-info h4 { color: #7ED321; margin-bottom: 5px; font-size: 14px; }
        .physics-info {
            background: rgba(189, 16, 224, 0.1); border-left: 3px solid #BD10E0;
            padding: 10px; margin: 10px 0; border-radius: 4px; font-size: 13px; line-height: 1.5;
        }
        .physics-info h4 { color: #BD10E0; margin-bottom: 5px; font-size: 14px; }
        .collapsible-header {
            cursor: pointer;
            user-select: none;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .collapsible-header:hover {
            opacity: 0.8;
        }
        .collapse-icon {
            font-size: 12px;
            transition: transform 0.3s;
        }
        .collapse-icon.collapsed {
            transform: rotate(-90deg);
        }
        .collapsible-content {
            max-height: 1000px;
            overflow: hidden;
            transition: max-height 0.3s ease-out;
        }
        .collapsible-content.collapsed {
            max-height: 0;
        }
        #controls-info {
            position: absolute; bottom: 60px; left: 50%; transform: translateX(-50%);
            background: rgba(0, 0, 0, 0.7); padding: 10px 20px; border-radius: 5px;
            font-size: 14px; text-align: center;
        }
        footer { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); font-size: 12px; }
        footer a { color: #4fc3f7; text-decoration: none; }
        
        #title-3d {
            position: absolute;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            font-size: 48px;
            font-weight: bold;
            color: #fff;
            text-shadow: 
                0 1px 0 #ccc,
                0 2px 0 #c9c9c9,
                0 3px 0 #bbb,
                0 4px 0 #b9b9b9,
                0 5px 0 #aaa,
                0 6px 1px rgba(0,0,0,.1),
                0 0 5px rgba(0,0,0,.1),
                0 1px 3px rgba(0,0,0,.3),
                0 3px 5px rgba(0,0,0,.2),
                0 5px 10px rgba(0,0,0,.25),
                0 10px 10px rgba(0,0,0,.2),
                0 20px 20px rgba(0,0,0,.15);
            letter-spacing: 3px;
            z-index: 100;
            pointer-events: none;
            background: linear-gradient(to bottom, #ffffff 0%, #4fc3f7 50%, #2a5298 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        #legend-panel {
            position: absolute;
            top: 20px;
            left: 20px;
            background: rgba(0, 0, 0, 0.8);
            padding: 15px;
            border-radius: 10px;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            z-index: 100;
            transition: all 0.3s ease;
        }
        
        #legend-panel.collapsed {
            padding: 10px;
        }
        
        #legend-panel h3 {
            margin: 0 0 10px 0;
            font-size: 16px;
            color: #4fc3f7;
            text-align: center;
            cursor: pointer;
            user-select: none;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }
        
        #legend-panel h3:hover {
            opacity: 0.8;
        }
        
        #legend-toggle-icon {
            font-size: 12px;
            transition: transform 0.3s;
        }
        
        #legend-toggle-icon.collapsed {
            transform: rotate(-90deg);
        }
        
        #legend-items {
            max-height: 500px;
            overflow: hidden;
            transition: max-height 0.3s ease-out;
        }
        
        #legend-items.collapsed {
            max-height: 0;
        }
        
        .legend-item {
            display: flex;
            align-items: center;
            margin: 5px 0;
            font-size: 12px;
        }
        
        .legend-color {
            width: 20px;
            height: 20px;
            border-radius: 3px;
            margin-right: 8px;
            border: 1px solid rgba(255, 255, 255, 0.3);
        }
        
        #spectrum-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.95);
            z-index: 2000;
            overflow-y: auto;
        }
        
        #spectrum-modal.active {
            display: block;
        }
        
        #spectrum-modal-content {
            max-width: 1400px;
            margin: 40px auto;
            padding: 30px;
            position: relative;
        }
        
        #spectrum-modal-close {
            position: absolute;
            top: 20px;
            right: 30px;
            font-size: 40px;
            color: #fff;
            cursor: pointer;
            z-index: 2001;
            background: rgba(0, 0, 0, 0.5);
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            line-height: 1;
        }
        
        #spectrum-modal-close:hover {
            background: rgba(255, 255, 255, 0.1);
        }
        
        .spectrum-clickable {
            cursor: pointer;
            transition: opacity 0.2s;
        }
        
        .spectrum-clickable:hover {
            opacity: 0.8;
        }
        
        /* Mobile-specific styles */
        @media (max-width: 768px) {
            #title-3d {
                font-size: 24px;
                top: 10px;
                letter-spacing: 1px;
            }
            
            #legend-panel {
                top: 50px;
                left: 10px;
                padding: 10px;
                max-height: 40vh;
                overflow-y: auto;
                font-size: 10px;
            }
            
            #legend-panel h3 {
                font-size: 14px;
                margin-bottom: 8px;
            }
            
            .legend-item {
                margin: 3px 0;
                font-size: 10px;
            }
            
            .legend-color {
                width: 15px;
                height: 15px;
                margin-right: 5px;
            }
            
            #info-panel-wrapper {
                width: 100%;
                height: 60vh;
                top: auto;
                bottom: 0;
                right: 0;
            }
            
            #info-panel-wrapper.collapsed {
                transform: translateY(100%);
            }
            
            #info-panel {
                max-width: 100%;
                width: 100%;
                height: 100%;
                border-left: none;
                border-top: 1px solid rgba(255, 255, 255, 0.2);
            }
            
            #info-panel-toggle {
                left: 50%;
                top: -40px;
                transform: translateX(-50%);
                width: 80px;
                height: 40px;
                border-radius: 10px 10px 0 0;
                border-right: 1px solid rgba(255, 255, 255, 0.2);
                font-size: 20px;
            }
            
            #controls-info {
                bottom: 10px;
                font-size: 10px;
                padding: 5px 10px;
                max-width: 90%;
            }
            
            #controls-info p {
                font-size: 10px;
            }
            
            footer {
                bottom: 5px;
                font-size: 10px;
            }
            
            #spectrum-modal-content {
                margin: 20px 10px;
                padding: 15px;
            }
            
            #spectrum-modal-close {
                top: 10px;
                right: 10px;
                width: 40px;
                height: 40px;
                font-size: 30px;
            }
        }
        
        /* Tablet styles */
        @media (min-width: 769px) and (max-width: 1024px) {
            #title-3d {
                font-size: 36px;
            }
            
            #legend-panel {
                padding: 12px;
            }
            
            #info-panel {
                max-width: 350px;
            }
        }
        
        /* Touch device optimizations */
        @media (hover: none) and (pointer: coarse) {
            #info-panel-toggle:hover {
                background: rgba(0, 0, 0, 0.8);
            }
            
            .spectrum-clickable:hover {
                opacity: 1;
            }
            
            .collapsible-header:hover {
                opacity: 1;
            }
        }

        /* ===== Student edition additions ===== */
        body { touch-action: manipulation; }
        #subtitle { position: absolute; top: 84px; left: 50%; transform: translateX(-50%); font-size: 15px; color: #cfe9ff; letter-spacing: 2px; z-index: 100; pointer-events: none; text-align: center; white-space: nowrap; }
        #filter-status { position: absolute; top: 114px; left: 50%; transform: translateX(-50%); max-width: 560px; background: rgba(0,0,0,0.75); border: 1px solid #4fc3f7; border-radius: 10px; padding: 8px 14px; font-size: 13px; line-height: 1.4; z-index: 100; text-align: center; }
        #filter-status.hidden { display: none; }
        #filter-status button { margin-left: 8px; background: #4fc3f7; color: #00212e; border: none; border-radius: 6px; padding: 3px 9px; cursor: pointer; font-weight: bold; }
        .legend-item { cursor: pointer; padding: 3px 6px; border-radius: 6px; transition: background 0.2s, opacity 0.2s; }
        .legend-item:hover { background: rgba(255,255,255,0.14); }
        .legend-item.active { background: rgba(79,195,247,0.28); outline: 1px solid #4fc3f7; }
        .legend-item.dim { opacity: 0.45; }
        .legend-item.legend-all { justify-content: center; margin-top: 8px; border: 1px dashed rgba(255,255,255,0.35); }
        .legend-hint { font-size: 11px; color: #9fd8f5; margin-bottom: 6px; text-align: center; }
        #legend-panel, #info-panel { touch-action: pan-y; }
        .collapsible-content { max-height: 4000px; }
        #student-badge { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.65); border: 1px solid rgba(255,255,255,0.25); border-radius: 20px; padding: 5px 14px; font-size: 13px; text-align: center; z-index: 100; white-space: nowrap; }
        footer { position: static; transform: none; }
        .el-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
        .el-tile { width: 74px; height: 74px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 30px; font-weight: bold; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.6); flex-shrink: 0; }
        .el-tile small { font-size: 12px; font-weight: normal; }
        .chip { display: inline-block; padding: 3px 9px; margin: 2px 3px 2px 0; border-radius: 12px; font-size: 12px; background: rgba(255,255,255,0.13); }
        .chip.rad { background: rgba(255,193,7,0.25); border: 1px solid #ffc107; }
        .chip.ok { background: rgba(126,211,33,0.2); border: 1px solid #7ED321; }
        .fam-desc { font-size: 12px; color: #cfd8e3; margin-bottom: 8px; line-height: 1.45; }
        .stu-card { padding: 10px; margin: 10px 0; border-radius: 6px; font-size: 13px; line-height: 1.5; background: rgba(255,255,255,0.05); border-left: 3px solid #4fc3f7; }
        .stu-card h4 { font-size: 14px; margin: 0; }
        .stu-card.c-green { border-left-color: #7ED321; background: rgba(126,211,33,0.08); } .stu-card.c-green h4 { color: #7ED321; }
        .stu-card.c-blue { border-left-color: #4fc3f7; background: rgba(79,195,247,0.08); } .stu-card.c-blue h4 { color: #4fc3f7; }
        .stu-card.c-purple { border-left-color: #BD10E0; background: rgba(189,16,224,0.08); } .stu-card.c-purple h4 { color: #e57bf5; }
        .stu-card.c-orange { border-left-color: #ffa726; background: rgba(255,167,38,0.08); } .stu-card.c-orange h4 { color: #ffa726; }
        .stu-card.c-pink { border-left-color: #FF69B4; background: rgba(255,105,180,0.08); } .stu-card.c-pink h4 { color: #ff8fc8; }
        .stu-card.c-yellow { border-left-color: #ffd54f; background: rgba(255,213,79,0.08); } .stu-card.c-yellow h4 { color: #ffd54f; }
        .stu-card .collapsible-content { padding-top: 6px; }
        .stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 6px 0; }
        .stat { background: rgba(255,255,255,0.07); border-radius: 6px; padding: 6px 8px; font-size: 13px; }
        .stat span { display: block; font-size: 11px; color: #9fb4c8; }
        .stat strong { font-size: 15px; }
        .note { font-size: 12px; color: #cfd8e3; margin: 6px 0; line-height: 1.5; }
        .bond-svg { width: 100%; height: auto; background: rgba(0,0,0,0.35); border-radius: 8px; margin: 4px 0; display: block; }
        .bohr-svg { max-width: 220px; margin: 4px auto; }
        .bond-chip { display: inline-block; background: #ffd54f; color: #222; font-weight: bold; font-size: 12px; padding: 3px 10px; border-radius: 12px; margin: 6px 0; }
        .bond-ex { font-size: 14px; margin: 4px 0; }
        .bond-type { margin: 10px 0; padding-top: 6px; border-top: 1px solid rgba(255,255,255,0.12); }
        .bond-type h5 { font-size: 13px; color: #ffd54f; margin-bottom: 4px; }
        @media (max-width: 768px) {
            #subtitle { top: 42px; font-size: 11px; letter-spacing: 1px; }
            #filter-status { top: auto; bottom: 40px; max-width: 92%; font-size: 11px; }
            #student-badge { bottom: 6px; font-size: 11px; padding: 3px 10px; }
        }
        /* ===== Layout fixes: legend as a top bar, never covering the table ===== */
        #title-3d { white-space: nowrap; }
        #info-panel-wrapper { z-index: 200; }
        #legend-panel { top: 118px; left: 50%; right: auto; transform: translateX(-50%); width: min(920px, 94vw); padding: 8px 12px; }
        #legend-panel h3 { margin: 0 0 6px 0; font-size: 14px; }
        #legend-panel.collapsed h3 { margin-bottom: 0; }
        #legend-items { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 6px; }
        .legend-hint { width: 100%; margin: 0 0 2px 0; }
        .legend-item { margin: 0; font-size: 12px; }
        .legend-item.legend-all { margin-top: 0; }
        .legend-color { width: 16px; height: 16px; }
        #filter-status { top: auto; bottom: 48px; }
        @media (max-width: 768px) {
            #title-3d { font-size: 20px; top: 8px; }
            #subtitle { top: 36px; }
            #legend-panel { top: 56px; left: 50%; max-height: 45vh; overflow-y: auto; }
            .legend-item { font-size: 11px; }
            #filter-status { bottom: 38px; }
        }
        @media (min-width: 769px) {
            body.panel-open #legend-panel { left: calc((100vw - 450px) / 2); width: min(920px, calc(100vw - 480px)); }
            body.panel-open #title-3d, body.panel-open #subtitle, body.panel-open #filter-status { left: calc((100vw - 450px) / 2); }
        }
    </style>
</head>
<body>
    <div id="loading">
        <div class="spinner"></div>
        <p>Loading Periodic Table...</p>
    </div>
    <div id="app-container">
        <div id="title-3d">PERIODIC TABLE</div>
        <div id="legend-panel">
            <h3 onclick="const panel = document.getElementById('legend-panel'); const items = document.getElementById('legend-items'); const icon = document.getElementById('legend-toggle-icon'); panel.classList.toggle('collapsed'); items.classList.toggle('collapsed'); icon.classList.toggle('collapsed');">
                <span>Element Categories</span>
                <span id="legend-toggle-icon">▼</span>
            </h3>
            <div id="legend-items">
                <div class="legend-hint">👆 Click a colour to see only that family</div>
                <div class="legend-item" data-cat="alkali-metal"><div class="legend-color" style="background-color: #FF6B6B;"></div><span>Alkali Metal</span></div>
                <div class="legend-item" data-cat="alkaline-earth"><div class="legend-color" style="background-color: #FFA07A;"></div><span>Alkaline Earth Metal</span></div>
                <div class="legend-item" data-cat="transition-metal"><div class="legend-color" style="background-color: #87CEEB;"></div><span>Transition Metal</span></div>
                <div class="legend-item" data-cat="metal"><div class="legend-color" style="background-color: #4A90E2;"></div><span>Post-Transition Metal</span></div>
                <div class="legend-item" data-cat="metalloid"><div class="legend-color" style="background-color: #F5A623;"></div><span>Metalloid</span></div>
                <div class="legend-item" data-cat="nonmetal"><div class="legend-color" style="background-color: #7ED321;"></div><span>Nonmetal</span></div>
                <div class="legend-item" data-cat="halogen"><div class="legend-color" style="background-color: #50E3C2;"></div><span>Halogen</span></div>
                <div class="legend-item" data-cat="noble-gas"><div class="legend-color" style="background-color: #BD10E0;"></div><span>Noble Gas</span></div>
                <div class="legend-item" data-cat="lanthanide"><div class="legend-color" style="background-color: #FFD700;"></div><span>Lanthanide</span></div>
                <div class="legend-item" data-cat="actinide"><div class="legend-color" style="background-color: #FF69B4;"></div><span>Actinide</span></div>
                <div class="legend-item legend-all" data-cat="all"><span>🔄 Show all elements</span></div>
            </div>
        </div>
        <div id="subtitle">LEARN THE ELEMENTS • GRADES 6–10</div>
        <div id="filter-status" class="hidden"></div>

        <div id="canvas-container"></div>
        <div id="info-panel-wrapper" class="hidden">
            <div id="info-panel-toggle" onclick="const wrapper = document.getElementById('info-panel-wrapper'); wrapper.classList.toggle('collapsed'); const isMobile = window.innerWidth <= 768; this.textContent = wrapper.classList.contains('collapsed') ? (isMobile ? '▲' : '◀') : (isMobile ? '▼' : '▶');">▶</div>
            <div id="info-panel">
                <h2 id="element-name"></h2>
                <div id="element-details"></div>
                <div id="spectrum-container"></div>
            </div>
        </div>
        <div id="student-badge">🎓 Created by <strong>Nithyasri K</strong>, Student<span id="school-name"></span></div>
        <footer style="display:none"><p>Based on the Periodic Table Spectrum Viewer by Andy Kong (MIT License) | Data from <a href="https://www.nist.gov/pml/atomic-spectra-database" target="_blank">NIST</a></p></footer>
    </div>
    <div id="spectrum-modal">
        <div id="spectrum-modal-close" onclick="document.getElementById('spectrum-modal').classList.remove('active');">&times;</div>
        <div id="spectrum-modal-content"></div>
    </div>
    <script type="importmap">
    { "imports": {
        "three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",
        "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/"
    }}
    </script>
    <script type="module">
        import * as THREE from 'three';
        import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
        import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';

        const SPECTRAL_DATA = { elements: [
            { symbol: "H", name: "Hydrogen", atomicNumber: 1, category: "nonmetal",
              cosmicOrigin: "Big Bang", originColor: "#FFD700",
              astronomyInfo: "The most abundant element in the universe, created during the Big Bang 13.8 billion years ago. Hydrogen makes up about 75% of all normal matter and is the fuel that powers stars through nuclear fusion.",
              chemistryInfo: "The simplest element with one proton and one electron. Forms covalent bonds in H₂ molecules. Essential for water (H₂O), acids, and all organic compounds. Has three isotopes: protium, deuterium, and tritium.",
              physicsInfo: "Electron configuration: 1s¹. Isotopes: ¹H (99.985%), ²H/Deuterium (0.015%), ³H/Tritium (trace, radioactive). Atomic mass: 1.008 u. Ionization energy: 13.6 eV.",
              spectralLines: [
                { wavelength: 410.2, intensity: 0.5, transition: "n=6→n=2 (Hδ, Balmer)" },
                { wavelength: 434.0, intensity: 0.7, transition: "n=5→n=2 (Hγ, Balmer)" },
                { wavelength: 486.1, intensity: 0.9, transition: "n=4→n=2 (Hβ, Balmer)" },
                { wavelength: 656.3, intensity: 1.0, transition: "n=3→n=2 (Hα, Balmer, red)" }
            ]},
            { symbol: "He", name: "Helium", atomicNumber: 2, category: "noble-gas",
              cosmicOrigin: "Big Bang", originColor: "#FFD700",
              astronomyInfo: "The second most abundant element in the universe, primarily created during the Big Bang. Also produced by nuclear fusion in stars. Helium was first discovered in the Sun's spectrum before being found on Earth.",
              chemistryInfo: "Noble gas with complete electron shell, chemically inert. Does not form compounds under normal conditions. Lowest boiling point (-269°C). Used in balloons, diving, and cryogenics.",
              physicsInfo: "Electron configuration: 1s². Isotopes: ⁴He (99.999863%), ³He (0.000137%). Atomic mass: 4.003 u. Ionization energy: 24.6 eV (highest of all elements).",
              spectralLines: [
                { wavelength: 447.1, intensity: 0.5, transition: "4d→2p (blue)" },
                { wavelength: 471.3, intensity: 0.6, transition: "4s→2p (blue)" },
                { wavelength: 492.2, intensity: 0.4, transition: "4d→2p (cyan)" },
                { wavelength: 501.6, intensity: 0.7, transition: "3s→2p (green)" },
                { wavelength: 587.6, intensity: 1.0, transition: "3s→2p (D-line, yellow)" },
                { wavelength: 667.8, intensity: 0.8, transition: "3d→2p (red)" },
                { wavelength: 706.5, intensity: 0.6, transition: "3s→2p (deep red)" }
            ]},
            { symbol: "Li", name: "Lithium", atomicNumber: 3, category: "alkali-metal",
              cosmicOrigin: "Cosmic Ray & Dying Stars", originColor: "#9370DB",
              astronomyInfo: "Created through multiple processes: some from the Big Bang, most from dying low-mass stars, and some isotopes from cosmic ray collisions. Lithium is one of only three elements created in the Big Bang that still exist today.",
              chemistryInfo: "Highly reactive alkali metal, stored in oil. Forms ionic compounds with halogens. Lightest metal and least dense solid. Used in rechargeable batteries and psychiatric medication.",
              physicsInfo: "Electron configuration: [He] 2s¹. Isotopes: ⁷Li (92.5%), ⁶Li (7.5%). Atomic mass: 6.94 u. Shells: 2, 1.",
              spectralLines: [
                { wavelength: 610.4, intensity: 0.5, transition: "3d→2p (orange)" },
                { wavelength: 670.8, intensity: 1.0, transition: "2p→2s (D-line, crimson red)" }
            ]},
            { symbol: "C", name: "Carbon", atomicNumber: 6, category: "nonmetal",
              cosmicOrigin: "Dying Low Mass Stars", originColor: "#FF6B9D",
              astronomyInfo: "The basis of all known life, carbon is forged in the cores of dying low-mass stars through the triple-alpha process. As Carl Sagan said, 'We are made of star stuff' - and carbon is a prime example.",
              chemistryInfo: "Basis of organic chemistry, forms 4 covalent bonds. Exists as diamond, graphite, graphene, and fullerenes. Essential for all known life. Forms millions of compounds.",
              physicsInfo: "Electron configuration: [He] 2s² 2p². Isotopes: ¹²C (98.93%), ¹³C (1.07%), ¹⁴C (trace, radioactive). Atomic mass: 12.011 u. Shells: 2, 4.",
              spectralLines: [
                { wavelength: 247.9, intensity: 1.0, transition: "2p→2s (UV)" },
                { wavelength: 426.7, intensity: 0.5, transition: "3d→2p (blue)" },
                { wavelength: 538.0, intensity: 0.4, transition: "3p→2s (green)" },
                { wavelength: 658.8, intensity: 0.3, transition: "3d→2p (red)" }
            ]},
            { symbol: "N", name: "Nitrogen", atomicNumber: 7, category: "nonmetal",
              cosmicOrigin: "Dying Low Mass Stars", originColor: "#FF6B9D",
              astronomyInfo: "Essential for DNA and proteins, nitrogen is created in dying low-mass stars through the CNO cycle. The nitrogen in our DNA was literally forged in the hearts of ancient stars billions of years ago.",
              chemistryInfo: "Diatomic gas (N₂) with triple bond, very stable. Essential for proteins and DNA. Forms nitrates and ammonia. Makes up 78% of Earth's atmosphere.",
              physicsInfo: "Electron configuration: [He] 2s² 2p³. Isotopes: ¹⁴N (99.636%), ¹⁵N (0.364%). Atomic mass: 14.007 u. Shells: 2, 5.",
              spectralLines: [
                { wavelength: 399.5, intensity: 0.8, transition: "3p→3s (violet)" },
                { wavelength: 500.5, intensity: 0.6, transition: "3d→3p (cyan)" },
                { wavelength: 567.6, intensity: 0.5, transition: "4s→3p (yellow-green)" },
                { wavelength: 648.2, intensity: 0.4, transition: "3d→3p (red)" }
            ]},
            { symbol: "O", name: "Oxygen", atomicNumber: 8, category: "nonmetal",
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in massive stars and scattered across the universe when these stars explode as supernovae. Oxygen is the third most abundant element in the universe and essential for life as we know it.",
              chemistryInfo: "Highly reactive, forms oxides with most elements. Essential for respiration. Exists as O₂ and O₃ (ozone). Second most electronegative element after fluorine.",
              physicsInfo: "Electron configuration: [He] 2s² 2p⁴. Isotopes: ¹⁶O (99.757%), ¹⁸O (0.205%), ¹⁷O (0.038%). Atomic mass: 15.999 u. Shells: 2, 6.",
              spectralLines: [
                { wavelength: 615.8, intensity: 0.5, transition: "4s→3p (orange)" },
                { wavelength: 777.4, intensity: 1.0, transition: "3p→3s (near-IR, red)" },
                { wavelength: 844.6, intensity: 0.8, transition: "3d→3p (near-IR)" }
            ]},
            { symbol: "Na", name: "Sodium", atomicNumber: 11, category: "alkali-metal",
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in massive stars and released during supernova explosions. Sodium's distinctive yellow spectral lines make it easy to identify in astronomical observations of distant stars and galaxies.",
              chemistryInfo: "Highly reactive alkali metal, reacts violently with water producing H₂ gas. Forms Na⁺ ions. Essential for nerve function and fluid balance. Found in table salt (NaCl).",
              physicsInfo: "Electron configuration: [Ne] 3s¹. Isotope: ²³Na (100%). Atomic mass: 22.990 u. Shells: 2, 8, 1.",
              spectralLines: [
                { wavelength: 589.0, intensity: 1.0, transition: "3p→3s (D1-line)" },
                { wavelength: 589.6, intensity: 0.9, transition: "3p→3s (D2-line)" },
                { wavelength: 568.3, intensity: 0.2, transition: "4d→3p" }
            ]},
            { symbol: "Fe", name: "Iron", atomicNumber: 26, category: "transition-metal",
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "The iron in your blood was created in the core of a dying massive star. Iron is the final element that can be produced by fusion in stellar cores before the star collapses and explodes as a supernova.",
              chemistryInfo: "Transition metal, forms Fe²⁺ and Fe³⁺ ions. Essential for hemoglobin in blood. Most common element on Earth by mass. Rusts in presence of oxygen and water.",
              physicsInfo: "Electron configuration: [Ar] 3d⁶ 4s². Isotopes: ⁵⁶Fe (91.754%), ⁵⁴Fe (5.845%), ⁵⁷Fe (2.119%), ⁵⁸Fe (0.282%). Atomic mass: 55.845 u. Shells: 2, 8, 14, 2.",
              spectralLines: [
                { wavelength: 385.9, intensity: 0.7, transition: "3d→4s (violet)" },
                { wavelength: 404.6, intensity: 0.8, transition: "3d→4s (violet)" },
                { wavelength: 438.4, intensity: 1.0, transition: "3d→4s (blue)" },
                { wavelength: 440.5, intensity: 0.9, transition: "3d→4s (blue)" },
                { wavelength: 495.8, intensity: 0.7, transition: "4s→3d (cyan)" },
                { wavelength: 526.9, intensity: 0.8, transition: "3d→4s (green)" },
                { wavelength: 532.8, intensity: 0.6, transition: "3d→4s (green)" }
            ]},
            { symbol: "Cu", name: "Copper", atomicNumber: 29, category: "transition-metal",
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created during supernova explosions when massive stars die. Elements heavier than iron like copper require the enormous energy of a supernova to form through rapid neutron capture.",
              chemistryInfo: "Excellent electrical and thermal conductor. Forms Cu⁺ and Cu²⁺ ions. Used in wiring, plumbing, and coins. Antimicrobial properties. Forms green patina (copper carbonate) when exposed to air.",
              physicsInfo: "Electron configuration: [Ar] 3d¹⁰ 4s¹. Isotopes: ⁶³Cu (69.15%), ⁶⁵Cu (30.85%). Atomic mass: 63.546 u. Shells: 2, 8, 18, 1.",
              spectralLines: [
                { wavelength: 324.8, intensity: 1.0, transition: "4p→4s (UV)" },
                { wavelength: 327.4, intensity: 0.9, transition: "4p→4s (UV)" },
                { wavelength: 465.1, intensity: 0.6, transition: "4d→4p (blue)" },
                { wavelength: 510.6, intensity: 0.8, transition: "4d→4p (cyan-green)" },
                { wavelength: 515.3, intensity: 0.7, transition: "4d→4p (cyan-green)" },
                { wavelength: 521.8, intensity: 0.9, transition: "4d→4p (green)" },
                { wavelength: 578.2, intensity: 0.5, transition: "4d→4p (yellow)" }
            ]},
            { symbol: "Au", name: "Gold", atomicNumber: 79, category: "transition-metal",
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Gold is so heavy that it requires extreme conditions to form - likely created when neutron stars collide. Every gold atom on Earth was forged in the violent collision of dead stars, making it truly precious from a cosmic perspective.",
              chemistryInfo: "Noble metal, highly unreactive. Does not tarnish or corrode. Forms Au⁺ and Au³⁺ ions. Used in jewelry, electronics, and medicine. Excellent conductor and highly malleable.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d¹⁰ 6s¹. Isotope: ¹⁹⁷Au (100%). Atomic mass: 196.967 u. Shells: 2, 8, 18, 32, 18, 1.",
              spectralLines: [
                { wavelength: 267.6, intensity: 0.8, transition: "6p→6s (UV)" },
                { wavelength: 312.3, intensity: 0.6, transition: "6p→6s (UV)" },
                { wavelength: 479.3, intensity: 0.7, transition: "6d→6p" },
                { wavelength: 523.0, intensity: 0.8, transition: "6p→6s (emerald green)" },
                { wavelength: 584.0, intensity: 1.0, transition: "6p→6s (bright yellow)" },
                { wavelength: 628.0, intensity: 0.9, transition: "6p→6s (red)" }
            ]},
            // Period 2 continued
            { symbol: "Be", name: "Beryllium", atomicNumber: 4, category: "alkaline-earth", row: 2, col: 2,
              cosmicOrigin: "Cosmic Ray Fission", originColor: "#9370DB",
              astronomyInfo: "Created by cosmic ray spallation when high-energy particles collide with heavier elements.",
              chemistryInfo: "Alkaline earth metal, forms strong covalent bonds. Toxic and carcinogenic. Used in aerospace alloys and X-ray windows. Forms Be²⁺ ions.",
              physicsInfo: "Electron configuration: [He] 2s². Isotope: ⁹Be (100%). Atomic mass: 9.012 u. Shells: 2, 2.",
              spectralLines: [
                { wavelength: 234.9, intensity: 1.0, transition: "2p→2s (UV)" },
                { wavelength: 313.0, intensity: 0.5, transition: "3s→2p (UV)" },
                { wavelength: 332.1, intensity: 0.4, transition: "3p→2s (UV)" },
                { wavelength: 457.3, intensity: 0.3, transition: "3d→2p (blue)" }
            ]},
            { symbol: "B", name: "Boron", atomicNumber: 5, category: "metalloid", row: 2, col: 13,
              cosmicOrigin: "Cosmic Ray Fission", originColor: "#9370DB",
              astronomyInfo: "Produced by cosmic ray spallation, making it one of the rarest elements in the universe.",
              chemistryInfo: "Metalloid with unique chemistry. Forms electron-deficient compounds. Essential for plant growth. Used in fiberglass and semiconductors.",
              physicsInfo: "Electron configuration: [He] 2s² 2p¹. Isotopes: ¹¹B (80.1%), ¹⁰B (19.9%). Atomic mass: 10.81 u. Shells: 2, 3.",
              spectralLines: [
                { wavelength: 249.7, intensity: 1.0, transition: "2p→2s (UV)" },
                { wavelength: 345.1, intensity: 0.4, transition: "3s→2p (UV)" },
                { wavelength: 412.2, intensity: 0.3, transition: "3p→3s (violet)" },
                { wavelength: 518.0, intensity: 0.3, transition: "3d→2p (green)" }
            ]},
            { symbol: "F", name: "Fluorine", atomicNumber: 9, category: "halogen", row: 2, col: 17,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in dying stars and supernovae explosions.",
              chemistryInfo: "Most electronegative and reactive element. Forms fluorides with all elements except He, Ne, Ar. Used in toothpaste (fluoride) and Teflon. Highly toxic as F₂ gas.",
              physicsInfo: "Electron configuration: [He] 2s² 2p⁵. Isotope: ¹⁹F (100%). Atomic mass: 18.998 u. Shells: 2, 7.",
              spectralLines: [
                { wavelength: 624.0, intensity: 0.6, transition: "3p→3s (red)" },
                { wavelength: 685.6, intensity: 0.9, transition: "3p→3s (red)" },
                { wavelength: 690.2, intensity: 0.7, transition: "3d→3p (red)" },
                { wavelength: 739.9, intensity: 0.8, transition: "3p→3s (red)" }
            ]},
            { symbol: "Ne", name: "Neon", atomicNumber: 10, category: "noble-gas", row: 2, col: 18,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in massive stars through carbon burning, released in supernovae.",
              chemistryInfo: "Noble gas, chemically inert. No known stable compounds. Used in neon signs (red-orange glow), lasers, and cryogenic refrigeration.",
              physicsInfo: "Electron configuration: [He] 2s² 2p⁶. Isotopes: ²⁰Ne (90.48%), ²²Ne (9.25%), ²¹Ne (0.27%). Atomic mass: 20.180 u. Shells: 2, 8.",
              spectralLines: [
                { wavelength: 585.2, intensity: 0.8, transition: "3s→2p (yellow)" },
                { wavelength: 614.3, intensity: 0.9, transition: "3p→3s (orange)" },
                { wavelength: 640.2, intensity: 1.0, transition: "3p→3s (red-orange)" },
                { wavelength: 703.2, intensity: 0.7, transition: "3p→3s (deep red)" }
            ]},
            // Period 3
            { symbol: "Mg", name: "Magnesium", atomicNumber: 12, category: "alkaline-earth", row: 3, col: 2,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in massive stars and scattered by supernovae. Essential for chlorophyll in plants.",
              chemistryInfo: "Alkaline earth metal, burns with brilliant white light. Forms Mg²⁺ ions. Essential for chlorophyll and over 300 enzymes. Reacts with acids. Used in alloys, fireworks, and as a dietary supplement.",
              physicsInfo: "Electron configuration: [Ne] 3s². Isotopes: ²⁴Mg (78.99%), ²⁶Mg (11.01%), ²⁵Mg (10.00%). Atomic mass: 24.305 u. Shells: 2, 8, 2.",
              spectralLines: [
                { wavelength: 383.8, intensity: 0.6, transition: "4s→3p (violet)" },
                { wavelength: 516.7, intensity: 0.8, transition: "3p→3s (green)" },
                { wavelength: 517.3, intensity: 0.7, transition: "3p→3s (green)" },
                { wavelength: 518.4, intensity: 1.0, transition: "3p→3s (green)" }
            ]},
            { symbol: "Al", name: "Aluminum", atomicNumber: 13, category: "metal", row: 3, col: 13,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, aluminum is the most abundant metal in Earth's crust.",
              chemistryInfo: "Post-transition metal, lightweight and corrosion-resistant. Forms Al³⁺ ions. Amphoteric (reacts with both acids and bases). Used in aircraft, cans, foil, and construction. Third most abundant element in Earth's crust.",
              physicsInfo: "Electron configuration: [Ne] 3s² 3p¹. Isotope: ²⁷Al (100%). Atomic mass: 26.982 u. Shells: 2, 8, 3.",
              spectralLines: [
                { wavelength: 308.2, intensity: 0.8, transition: "3p→3s (UV)" },
                { wavelength: 309.3, intensity: 0.7, transition: "3p→3s (UV)" },
                { wavelength: 394.4, intensity: 1.0, transition: "4s→3p (violet)" },
                { wavelength: 396.2, intensity: 0.9, transition: "3p→3s (violet)" }
            ]},
            { symbol: "Si", name: "Silicon", atomicNumber: 14, category: "metalloid", row: 3, col: 14,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in massive stars, silicon is the basis of rocks and computer chips.",
              chemistryInfo: "Metalloid, forms covalent bonds. Basis of silicate minerals and glass. Essential for semiconductors and computer chips. Forms SiO₂ (quartz, sand). Second most abundant element in Earth's crust after oxygen.",
              physicsInfo: "Electron configuration: [Ne] 3s² 3p². Isotopes: ²⁸Si (92.23%), ²⁹Si (4.67%), ³⁰Si (3.10%). Atomic mass: 28.085 u. Shells: 2, 8, 4.",
              spectralLines: [
                { wavelength: 288.2, intensity: 0.7, transition: "4s→3p (UV)" },
                { wavelength: 390.6, intensity: 1.0, transition: "3p→3s (violet)" },
                { wavelength: 505.6, intensity: 0.5, transition: "4p→4s (cyan)" },
                { wavelength: 634.7, intensity: 0.4, transition: "4p→4s (red)" }
            ]},
            { symbol: "P", name: "Phosphorus", atomicNumber: 15, category: "nonmetal", row: 3, col: 15,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Essential for DNA and ATP, created in supernovae explosions.",
              chemistryInfo: "Highly reactive nonmetal, exists as white, red, and black allotropes. Essential for DNA, RNA, and ATP. Forms phosphates. Used in fertilizers, matches, and detergents. Never found free in nature.",
              physicsInfo: "Electron configuration: [Ne] 3s² 3p³. Isotope: ³¹P (100%). Atomic mass: 30.974 u. Shells: 2, 8, 5.",
              spectralLines: [
                { wavelength: 253.6, intensity: 1.0, transition: "3p→3s (UV)" },
                { wavelength: 255.3, intensity: 0.9, transition: "4s→3p (UV)" },
                { wavelength: 435.5, intensity: 0.5, transition: "4p→4s (blue)" },
                { wavelength: 542.4, intensity: 0.4, transition: "4p→4s (green)" }
            ]},
            { symbol: "S", name: "Sulfur", atomicNumber: 16, category: "nonmetal", row: 3, col: 16,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in massive stars and released in supernova explosions.",
              chemistryInfo: "Nonmetal, forms S²⁻ ions and many compounds. Essential for proteins (cysteine, methionine). Forms sulfuric acid (H₂SO₄), the most produced industrial chemical. Gives rotten eggs their smell (H₂S). Used in vulcanizing rubber.",
              physicsInfo: "Electron configuration: [Ne] 3s² 3p⁴. Isotopes: ³²S (94.99%), ³⁴S (4.25%), ³³S (0.75%), ³⁶S (0.01%). Atomic mass: 32.06 u. Shells: 2, 8, 6.",
              spectralLines: [
                { wavelength: 469.4, intensity: 0.9, transition: "3p→3s (blue)" },
                { wavelength: 545.4, intensity: 0.8, transition: "4s→3p (green)" },
                { wavelength: 564.0, intensity: 0.7, transition: "4s→3p (yellow-green)" },
                { wavelength: 921.3, intensity: 0.6, transition: "4p→4s (near-IR)" }
            ]},
            { symbol: "Cl", name: "Chlorine", atomicNumber: 17, category: "halogen", row: 3, col: 17,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, essential for life and common in Earth's oceans.",
              chemistryInfo: "Highly reactive halogen, toxic yellow-green gas as Cl₂. Forms Cl⁻ ions (chloride). Essential for stomach acid (HCl) and nerve function. Used in water purification, bleach, and PVC plastic. Found in table salt (NaCl).",
              physicsInfo: "Electron configuration: [Ne] 3s² 3p⁵. Isotopes: ³⁵Cl (75.76%), ³⁷Cl (24.24%). Atomic mass: 35.45 u. Shells: 2, 8, 7.",
              spectralLines: [
                { wavelength: 479.5, intensity: 0.8, transition: "3p→3s (blue)" },
                { wavelength: 542.3, intensity: 0.7, transition: "4s→3p (green)" },
                { wavelength: 725.7, intensity: 0.7, transition: "4s→3p (red)" },
                { wavelength: 837.6, intensity: 0.6, transition: "4p→4s (near-IR)" }
            ]},
            { symbol: "Ar", name: "Argon", atomicNumber: 18, category: "noble-gas", row: 3, col: 18,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, argon makes up about 1% of Earth's atmosphere.",
              chemistryInfo: "Noble gas, chemically inert with complete electron shell. No stable compounds. Third most abundant gas in Earth's atmosphere (0.93%). Used in welding, light bulbs, and as protective atmosphere for reactive materials.",
              physicsInfo: "Electron configuration: [Ne] 3s² 3p⁶. Isotopes: ⁴⁰Ar (99.60%), ³⁶Ar (0.34%), ³⁸Ar (0.06%). Atomic mass: 39.948 u. Shells: 2, 8, 8.",
              spectralLines: [
                { wavelength: 415.9, intensity: 0.7, transition: "4p→4s (violet)" },
                { wavelength: 420.1, intensity: 0.6, transition: "4p→4s (violet)" },
                { wavelength: 696.5, intensity: 1.0, transition: "4p→4s (red)" },
                { wavelength: 706.7, intensity: 0.9, transition: "4p→4s (red)" },
                { wavelength: 738.4, intensity: 0.8, transition: "4p→4s (red)" },
                { wavelength: 763.5, intensity: 0.7, transition: "4p→4s (red)" }
            ]},
            // Period 4
            { symbol: "K", name: "Potassium", atomicNumber: 19, category: "alkali-metal", row: 4, col: 1,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, essential for nerve function in living organisms.",
              chemistryInfo: "Highly reactive alkali metal, soft enough to cut with a knife. Forms K⁺ ions. Essential for nerve impulses, muscle contraction, and heart function. Reacts violently with water. Found in bananas and used in fertilizers.",
              physicsInfo: "Electron configuration: [Ar] 4s¹. Isotopes: ³⁹K (93.26%), ⁴¹K (6.73%), ⁴⁰K (0.01%, radioactive). Atomic mass: 39.098 u. Shells: 2, 8, 8, 1.",
              spectralLines: [
                { wavelength: 404.4, intensity: 0.5, transition: "5p→4s (violet)" },
                { wavelength: 766.5, intensity: 1.0, transition: "4p→4s (red)" },
                { wavelength: 769.9, intensity: 0.9, transition: "4p→4s (red)" }
            ]},
            { symbol: "Ca", name: "Calcium", atomicNumber: 20, category: "alkaline-earth", row: 4, col: 2,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "The calcium in your bones was created in exploding stars billions of years ago.",
              chemistryInfo: "Alkaline earth metal, forms Ca²⁺ ions. Essential for bones, teeth, and muscle contraction. Fifth most abundant element in Earth's crust. Reacts with water. Found in limestone (CaCO₃), chalk, and marble.",
              physicsInfo: "Electron configuration: [Ar] 4s². Isotopes: ⁴⁰Ca (96.94%), ⁴⁴Ca (2.09%), ⁴²Ca (0.65%), ⁴⁸Ca (0.19%), ⁴³Ca (0.14%), ⁴⁶Ca (0.004%). Atomic mass: 40.078 u. Shells: 2, 8, 8, 2.",
              spectralLines: [
                { wavelength: 393.4, intensity: 0.8, transition: "5s→4p (violet)" },
                { wavelength: 396.8, intensity: 0.7, transition: "4p→4s (violet)" },
                { wavelength: 422.7, intensity: 1.0, transition: "4p→4s (blue-violet)" },
                { wavelength: 445.5, intensity: 0.6, transition: "4p→4s (blue)" },
                { wavelength: 558.9, intensity: 0.5, transition: "4p→4s (green)" },
                { wavelength: 643.9, intensity: 0.7, transition: "4p→4s (red)" }
            ]},
            { symbol: "Sc", name: "Scandium", atomicNumber: 21, category: "transition-metal", row: 4, col: 3,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Rare element created in supernovae explosions.",
              chemistryInfo: "Transition metal, forms Sc³⁺ ions. Lightweight and strong. Used in aerospace alloys, baseball bats, and bicycle frames. Rare in Earth's crust. Tarnishes in air.",
              physicsInfo: "Electron configuration: [Ar] 3d¹ 4s². Isotope: ⁴⁵Sc (100%). Atomic mass: 44.956 u. Shells: 2, 8, 9, 2.",
              spectralLines: [
                { wavelength: 390.7, intensity: 0.7, transition: "4p→4s (violet)" },
                { wavelength: 402.4, intensity: 0.9, transition: "3d→4s (violet)" },
                { wavelength: 402.0, intensity: 0.8, transition: "3d→4s (violet)" },
                { wavelength: 424.7, intensity: 1.0, transition: "3d→4s (blue-violet)" },
                { wavelength: 431.4, intensity: 0.6, transition: "3d→4s (blue)" }
            ]},
            { symbol: "Ti", name: "Titanium", atomicNumber: 22, category: "transition-metal", row: 4, col: 4,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, titanium is strong, light, and corrosion-resistant.",
              chemistryInfo: "Transition metal, forms Ti²⁺, Ti³⁺, and Ti⁴⁺ ions. Strong as steel but 45% lighter. Highly corrosion-resistant. Used in aircraft, spacecraft, medical implants, and white paint (TiO₂).",
              physicsInfo: "Electron configuration: [Ar] 3d² 4s². Isotopes: ⁴⁸Ti (73.72%), ⁴⁶Ti (8.25%), ⁴⁷Ti (7.44%), ⁴⁹Ti (5.41%), ⁵⁰Ti (5.18%). Atomic mass: 47.867 u. Shells: 2, 8, 10, 2.",
              spectralLines: [
                { wavelength: 399.9, intensity: 0.7, transition: "3d→4s (violet)" },
                { wavelength: 453.3, intensity: 0.8, transition: "4p→3d (blue)" },
                { wavelength: 498.2, intensity: 1.0, transition: "3d→4s (cyan)" },
                { wavelength: 499.1, intensity: 0.9, transition: "3d→4s (cyan)" },
                { wavelength: 521.0, intensity: 0.6, transition: "3d→4s (green)" }
            ]},
            { symbol: "V", name: "Vanadium", atomicNumber: 23, category: "transition-metal", row: 4, col: 5,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, used in steel alloys for strength.",
              chemistryInfo: "Transition metal, forms V²⁺, V³⁺, V⁴⁺, and V⁵⁺ ions. Adds strength and toughness to steel. Used in tools, springs, and jet engines. Named after Vanadis, Norse goddess of beauty, for its colorful compounds.",
              physicsInfo: "Electron configuration: [Ar] 3d³ 4s². Isotopes: ⁵¹V (99.75%), ⁵⁰V (0.25%, radioactive). Atomic mass: 50.942 u. Shells: 2, 8, 11, 2.",
              spectralLines: [
                { wavelength: 411.2, intensity: 0.7, transition: "4p→3d (violet)" },
                { wavelength: 437.9, intensity: 1.0, transition: "3d→4s (blue)" },
                { wavelength: 438.5, intensity: 0.9, transition: "3d→4s (blue)" },
                { wavelength: 440.8, intensity: 0.8, transition: "3d→4s (blue)" },
                { wavelength: 506.6, intensity: 0.6, transition: "3d→4s (cyan)" }
            ]},
            { symbol: "Cr", name: "Chromium", atomicNumber: 24, category: "transition-metal", row: 4, col: 6,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, gives rubies their red color.",
              chemistryInfo: "Transition metal, forms Cr²⁺, Cr³⁺, and Cr⁶⁺ ions. Extremely hard and corrosion-resistant. Used in stainless steel and chrome plating. Gives emeralds and rubies their colors. Essential trace element for glucose metabolism.",
              physicsInfo: "Electron configuration: [Ar] 3d⁵ 4s¹. Isotopes: ⁵²Cr (83.79%), ⁵³Cr (9.50%), ⁵⁰Cr (4.35%), ⁵⁴Cr (2.36%). Atomic mass: 51.996 u. Shells: 2, 8, 13, 1.",
              spectralLines: [
                { wavelength: 357.9, intensity: 0.8, transition: "3d→4s (UV)" },
                { wavelength: 425.4, intensity: 1.0, transition: "3d→4s (blue-violet)" },
                { wavelength: 427.5, intensity: 0.9, transition: "4p→3d (blue-violet)" },
                { wavelength: 520.5, intensity: 0.6, transition: "4p→3d (green)" },
                { wavelength: 520.8, intensity: 0.6, transition: "4p→3d (green)" }
            ]},
            { symbol: "Mn", name: "Manganese", atomicNumber: 25, category: "transition-metal", row: 4, col: 7,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, essential for photosynthesis in plants.",
              chemistryInfo: "Transition metal, forms Mn²⁺, Mn³⁺, Mn⁴⁺, and Mn⁷⁺ ions. Essential for photosynthesis and bone formation. Used in steel production and batteries. Permanganate (MnO₄⁻) is a strong oxidizer used in water treatment.",
              physicsInfo: "Electron configuration: [Ar] 3d⁵ 4s². Isotope: ⁵⁵Mn (100%). Atomic mass: 54.938 u. Shells: 2, 8, 13, 2.",
              spectralLines: [
                { wavelength: 403.1, intensity: 1.0, transition: "3d→4s (violet)" },
                { wavelength: 403.3, intensity: 0.9, transition: "4p→3d (violet)" },
                { wavelength: 403.4, intensity: 0.9, transition: "3d→4s (violet)" },
                { wavelength: 420.4, intensity: 0.7, transition: "3d→4s (violet)" },
                { wavelength: 475.4, intensity: 0.6, transition: "3d→4s (blue)" }
            ]},
            { symbol: "Co", name: "Cobalt", atomicNumber: 27, category: "transition-metal", row: 4, col: 9,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, essential for vitamin B12.",
              chemistryInfo: "Transition metal, forms Co²⁺ and Co³⁺ ions. Essential component of vitamin B12. Used in rechargeable batteries, magnets, and blue pigments. Ferromagnetic like iron and nickel.",
              physicsInfo: "Electron configuration: [Ar] 3d⁷ 4s². Isotope: ⁵⁹Co (100%). Atomic mass: 58.933 u. Shells: 2, 8, 15, 2.",
              spectralLines: [
                { wavelength: 340.5, intensity: 0.9, transition: "4p→3d (UV)" },
                { wavelength: 345.4, intensity: 1.0, transition: "3d→4s (UV)" },
                { wavelength: 350.2, intensity: 0.8, transition: "3d→4s (UV)" },
                { wavelength: 412.1, intensity: 0.6, transition: "3d→4s (violet)" },
                { wavelength: 535.4, intensity: 0.5, transition: "3d→4s (green)" }
            ]},
            { symbol: "Ni", name: "Nickel", atomicNumber: 28, category: "transition-metal", row: 4, col: 10,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, abundant in Earth's core and meteorites.",
              chemistryInfo: "Transition metal, forms Ni²⁺ and Ni³⁺ ions. Corrosion-resistant and ferromagnetic. Used in stainless steel, coins, rechargeable batteries, and catalysts. Major component of Earth's core. Can cause allergic reactions.",
              physicsInfo: "Electron configuration: [Ar] 3d⁸ 4s². Isotopes: ⁵⁸Ni (68.08%), ⁶⁰Ni (26.22%), ⁶²Ni (3.63%), ⁶¹Ni (1.14%), ⁶⁴Ni (0.93%). Atomic mass: 58.693 u. Shells: 2, 8, 16, 2.",
              spectralLines: [
                { wavelength: 341.5, intensity: 0.9, transition: "4p→3d (UV)" },
                { wavelength: 344.6, intensity: 0.8, transition: "4p→3d (UV)" },
                { wavelength: 349.3, intensity: 0.7, transition: "4p→3d (UV)" },
                { wavelength: 352.5, intensity: 1.0, transition: "3d→4s (UV)" },
                { wavelength: 508.5, intensity: 0.5, transition: "4d→4p (cyan)" }
            ]},
            { symbol: "Zn", name: "Zinc", atomicNumber: 30, category: "transition-metal", row: 4, col: 12,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, essential for immune function and wound healing.",
              chemistryInfo: "Transition metal, forms Zn²⁺ ions. Essential for immune system, wound healing, and DNA synthesis. Used in galvanizing steel, brass alloys, and batteries. Found in oysters, meat, and beans.",
              physicsInfo: "Electron configuration: [Ar] 3d¹⁰ 4s². Isotopes: ⁶⁴Zn (49.17%), ⁶⁶Zn (27.73%), ⁶⁸Zn (18.45%), ⁶⁷Zn (4.04%), ⁷⁰Zn (0.61%). Atomic mass: 65.38 u. Shells: 2, 8, 18, 2.",
              spectralLines: [
                { wavelength: 213.9, intensity: 1.0, transition: "4p→4s (UV)" },
                { wavelength: 330.3, intensity: 0.7, transition: "5s→4p (UV)" },
                { wavelength: 468.0, intensity: 0.5, transition: "5p→5s (blue)" },
                { wavelength: 472.2, intensity: 0.5, transition: "5p→5s (blue)" },
                { wavelength: 481.1, intensity: 0.6, transition: "5s→4p (blue)" },
                { wavelength: 636.2, intensity: 0.4, transition: "5p→5s (red)" }
            ]},
            { symbol: "Ga", name: "Gallium", atomicNumber: 31, category: "metal", row: 4, col: 13,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, melts in your hand at 30°C.",
              chemistryInfo: "Post-transition metal, forms Ga³⁺ ions. Melts at 29.76°C (can melt in your hand). Used in semiconductors, LEDs, and solar panels. Liquid over a wide temperature range. Non-toxic.",
              physicsInfo: "Electron configuration: [Ar] 3d¹⁰ 4s² 4p¹. Isotopes: ⁶⁹Ga (60.11%), ⁷¹Ga (39.89%). Atomic mass: 69.723 u. Shells: 2, 8, 18, 3.",
              spectralLines: [
                { wavelength: 294.4, intensity: 0.8, transition: "4p→4s (UV)" },
                { wavelength: 403.3, intensity: 0.9, transition: "5s→4p (violet)" },
                { wavelength: 417.2, intensity: 1.0, transition: "4p→4s (violet)" },
                { wavelength: 641.3, intensity: 0.6, transition: "5p→5s (red)" }
            ]},
            { symbol: "Ge", name: "Germanium", atomicNumber: 32, category: "metalloid", row: 4, col: 14,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, used in semiconductors and fiber optics.",
              chemistryInfo: "Metalloid, forms Ge²⁺ and Ge⁴⁺ ions. Important semiconductor used in transistors and fiber optics. Predicted by Mendeleev before its discovery. Brittle and silvery-white.",
              physicsInfo: "Electron configuration: [Ar] 3d¹⁰ 4s² 4p². Isotopes: ⁷⁴Ge (36.73%), ⁷²Ge (27.31%), ⁷⁰Ge (20.52%), ⁷³Ge (7.76%), ⁷⁶Ge (7.67%). Atomic mass: 72.630 u. Shells: 2, 8, 18, 4.",
              spectralLines: [
                { wavelength: 265.2, intensity: 0.8, transition: "5s→4p (UV)" },
                { wavelength: 275.5, intensity: 0.7, transition: "5s→4p (UV)" },
                { wavelength: 303.9, intensity: 1.0, transition: "4p→4s (UV)" },
                { wavelength: 422.7, intensity: 0.5, transition: "5p→5s (blue-violet)" },
                { wavelength: 468.6, intensity: 0.4, transition: "5p→5s (blue)" }
            ]},
            { symbol: "As", name: "Arsenic", atomicNumber: 33, category: "metalloid", row: 4, col: 15,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, infamous as a poison but essential in trace amounts.",
              chemistryInfo: "Metalloid, forms As³⁻, As³⁺, and As⁵⁺ ions. Infamous poison but essential in trace amounts. Used in semiconductors, wood preservatives, and pesticides. Forms toxic arsine gas (AsH₃).",
              physicsInfo: "Electron configuration: [Ar] 3d¹⁰ 4s² 4p³. Isotope: ⁷⁵As (100%). Atomic mass: 74.922 u. Shells: 2, 8, 18, 5.",
              spectralLines: [
                { wavelength: 228.8, intensity: 1.0, transition: "4p→4s (UV)" },
                { wavelength: 234.9, intensity: 0.9, transition: "5s→4p (UV)" },
                { wavelength: 278.0, intensity: 0.7, transition: "5s→4p (UV)" },
                { wavelength: 286.0, intensity: 0.6, transition: "5s→4p (UV)" }
            ]},
            { symbol: "Se", name: "Selenium", atomicNumber: 34, category: "nonmetal", row: 4, col: 16,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, essential for thyroid function.",
              chemistryInfo: "Nonmetal, forms Se²⁻ ions. Essential for thyroid function and antioxidant enzymes. Photoconductor used in photocopiers. Found in Brazil nuts, seafood, and meat. Toxic in large amounts.",
              physicsInfo: "Electron configuration: [Ar] 3d¹⁰ 4s² 4p⁴. Isotopes: ⁸⁰Se (49.61%), ⁷⁸Se (23.77%), ⁷⁶Se (9.37%), ⁸²Se (8.73%), ⁷⁷Se (7.63%), ⁷⁴Se (0.89%). Atomic mass: 78.971 u. Shells: 2, 8, 18, 6.",
              spectralLines: [
                { wavelength: 196.0, intensity: 1.0, transition: "4p→4s (UV)" },
                { wavelength: 203.9, intensity: 0.9, transition: "5s→4p (UV)" },
                { wavelength: 206.3, intensity: 0.8, transition: "5s→4p (UV)" },
                { wavelength: 473.1, intensity: 0.5, transition: "5p→5s (blue)" }
            ]},
            { symbol: "Br", name: "Bromine", atomicNumber: 35, category: "halogen", row: 4, col: 17,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, one of only two liquid elements at room temperature.",
              chemistryInfo: "Halogen, forms Br⁻ ions. One of only two elements liquid at room temperature (with mercury). Reddish-brown and volatile. Used in flame retardants, fumigants, and photography. Toxic and corrosive.",
              physicsInfo: "Electron configuration: [Ar] 3d¹⁰ 4s² 4p⁵. Isotopes: ⁷⁹Br (50.69%), ⁸¹Br (49.31%). Atomic mass: 79.904 u. Shells: 2, 8, 18, 7.",
              spectralLines: [
                { wavelength: 470.5, intensity: 0.9, transition: "4p→4s (blue)" },
                { wavelength: 478.6, intensity: 0.8, transition: "5s→4p (blue)" },
                { wavelength: 481.7, intensity: 0.7, transition: "5s→4p (blue)" },
                { wavelength: 827.2, intensity: 0.8, transition: "5p→5s (near-IR)" },
                { wavelength: 889.0, intensity: 0.7, transition: "5p→5s (near-IR)" }
            ]},
            { symbol: "Kr", name: "Krypton", atomicNumber: 36, category: "noble-gas", row: 4, col: 18,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, used in high-performance lighting.",
              chemistryInfo: "Noble gas, chemically inert. Forms very few compounds. Used in high-performance light bulbs, lasers, and flash lamps for high-speed photography. Produces bright white light when electrified.",
              physicsInfo: "Electron configuration: [Ar] 3d¹⁰ 4s² 4p⁶. Isotopes: ⁸⁴Kr (56.99%), ⁸⁶Kr (17.28%), ⁸²Kr (11.59%), ⁸³Kr (11.50%), ⁸⁰Kr (2.29%), ⁷⁸Kr (0.35%). Atomic mass: 83.798 u. Shells: 2, 8, 18, 8.",
              spectralLines: [
                { wavelength: 427.4, intensity: 0.7, transition: "5p→5s (blue)" },
                { wavelength: 431.9, intensity: 0.6, transition: "5p→5s (blue)" },
                { wavelength: 557.0, intensity: 1.0, transition: "5p→5s (green)" },
                { wavelength: 587.1, intensity: 0.9, transition: "5p→5s (yellow)" },
                { wavelength: 760.2, intensity: 0.8, transition: "5p→5s (red)" },
                { wavelength: 810.4, intensity: 0.7, transition: "5p→5s (near-IR)" }
            ]},
            // Period 5
            { symbol: "Rb", name: "Rubidium", atomicNumber: 37, category: "alkali-metal", row: 5, col: 1,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, used in atomic clocks.",
              chemistryInfo: "Highly reactive alkali metal, forms Rb⁺ ions. Ignites spontaneously in air. Used in atomic clocks, photocells, and research. Second most electropositive element after cesium.",
              physicsInfo: "Electron configuration: [Kr] 5s¹. Isotopes: ⁸⁵Rb (72.17%), ⁸⁷Rb (27.83%, radioactive). Atomic mass: 85.468 u. Shells: 2, 8, 18, 8, 1.",
              spectralLines: [
                { wavelength: 420.2, intensity: 0.7, transition: "6p→5s (violet)" },
                { wavelength: 421.6, intensity: 0.6, transition: "6p→5s (violet)" },
                { wavelength: 780.0, intensity: 1.0, transition: "5p→5s (red)" },
                { wavelength: 794.8, intensity: 0.9, transition: "5p→5s (red)" }
            ]},
            { symbol: "Sr", name: "Strontium", atomicNumber: 38, category: "alkaline-earth", row: 5, col: 2,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, gives fireworks their brilliant red color.",
              chemistryInfo: "Alkaline earth metal, forms Sr²⁺ ions. Gives fireworks their brilliant red color. Chemically similar to calcium. Radioactive ⁹⁰Sr is a dangerous nuclear fallout product. Used in magnets and zinc refining.",
              physicsInfo: "Electron configuration: [Kr] 5s². Isotopes: ⁸⁸Sr (82.58%), ⁸⁶Sr (9.86%), ⁸⁷Sr (7.00%), ⁸⁴Sr (0.56%). Atomic mass: 87.62 u. Shells: 2, 8, 18, 8, 2.",
              spectralLines: [
                { wavelength: 407.8, intensity: 0.8, transition: "6s→5p (violet)" },
                { wavelength: 421.6, intensity: 0.7, transition: "5p→5s (blue-violet)" },
                { wavelength: 460.7, intensity: 1.0, transition: "5p→5s (blue)" },
                { wavelength: 483.2, intensity: 0.6, transition: "5p→5s (blue)" },
                { wavelength: 605.0, intensity: 0.7, transition: "5p→5s (orange)" },
                { wavelength: 640.8, intensity: 0.8, transition: "5p→5s (red)" },
                { wavelength: 687.8, intensity: 0.9, transition: "5p→5s (deep red)" }
            ]},
            { symbol: "Y", name: "Yttrium", atomicNumber: 39, category: "transition-metal", row: 5, col: 3,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, used in LEDs and superconductors.",
              chemistryInfo: "Transition metal, forms Y³⁺ ions. Used in LEDs, superconductors, and cancer treatment. Named after Ytterby, Sweden. Often found with lanthanides. Silvery-metallic and relatively stable in air.",
              physicsInfo: "Electron configuration: [Kr] 4d¹ 5s². Isotope: ⁸⁹Y (100%). Atomic mass: 88.906 u. Shells: 2, 8, 18, 9, 2.",
              spectralLines: [
                { wavelength: 371.0, intensity: 0.8, transition: "5p→5s (UV)" },
                { wavelength: 407.7, intensity: 1.0, transition: "4d→5s (violet)" },
                { wavelength: 412.8, intensity: 0.7, transition: "4d→5s (violet)" },
                { wavelength: 437.5, intensity: 0.6, transition: "4d→5s (blue)" }
            ]},
            { symbol: "Zr", name: "Zirconium", atomicNumber: 40, category: "transition-metal", row: 5, col: 4,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, extremely corrosion-resistant.",
              chemistryInfo: "Transition metal, forms Zr⁴⁺ ions. Extremely corrosion-resistant. Used in nuclear reactors, surgical instruments, and gemstones (cubic zirconia). Does not absorb neutrons, making it ideal for nuclear applications.",
              physicsInfo: "Electron configuration: [Kr] 4d² 5s². Isotopes: ⁹⁰Zr (51.45%), ⁹⁴Zr (17.38%), ⁹²Zr (17.15%), ⁹¹Zr (11.22%), ⁹⁶Zr (2.80%). Atomic mass: 91.224 u. Shells: 2, 8, 18, 10, 2.",
              spectralLines: [
                { wavelength: 349.6, intensity: 0.8, transition: "5p→4d (UV)" },
                { wavelength: 360.1, intensity: 1.0, transition: "4d→5s (UV)" },
                { wavelength: 468.8, intensity: 0.6, transition: "5p→4d (blue)" },
                { wavelength: 614.7, intensity: 0.5, transition: "5p→4d (orange)" }
            ]},
            { symbol: "Nb", name: "Niobium", atomicNumber: 41, category: "transition-metal", row: 5, col: 5,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, used in superconducting magnets.",
              chemistryInfo: "Transition metal, forms Nb³⁺ and Nb⁵⁺ ions. Used in superconducting magnets, steel alloys, and jewelry. Highly resistant to corrosion. Named after Niobe from Greek mythology.",
              physicsInfo: "Electron configuration: [Kr] 4d⁴ 5s¹. Isotope: ⁹³Nb (100%). Atomic mass: 92.906 u. Shells: 2, 8, 18, 12, 1.",
              spectralLines: [
                { wavelength: 405.9, intensity: 0.9, transition: "4d→5s (violet)" },
                { wavelength: 412.4, intensity: 1.0, transition: "5p→4d (violet)" },
                { wavelength: 417.9, intensity: 0.8, transition: "4d→5s (violet)" },
                { wavelength: 468.4, intensity: 0.7, transition: "5p→4d (blue)" }
            ]},
            { symbol: "Mo", name: "Molybdenum", atomicNumber: 42, category: "transition-metal", row: 5, col: 6,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, essential for nitrogen-fixing enzymes.",
              chemistryInfo: "Transition metal, forms Mo³⁺, Mo⁴⁺, Mo⁵⁺, and Mo⁶⁺ ions. Essential for nitrogen-fixing enzymes in bacteria. Used in steel alloys, catalysts, and lubricants. Has one of the highest melting points.",
              physicsInfo: "Electron configuration: [Kr] 4d⁵ 5s¹. Isotopes: ⁹⁸Mo (24.39%), ⁹⁶Mo (16.67%), ⁹⁵Mo (15.84%), ⁹²Mo (14.53%), ¹⁰⁰Mo (9.82%), ⁹⁷Mo (9.60%), ⁹⁴Mo (9.15%). Atomic mass: 95.95 u. Shells: 2, 8, 18, 13, 1.",
              spectralLines: [
                { wavelength: 379.8, intensity: 0.9, transition: "4d→5s (UV)" },
                { wavelength: 386.4, intensity: 1.0, transition: "4d→5s (violet)" },
                { wavelength: 390.3, intensity: 0.9, transition: "5p→4d (violet)" },
                { wavelength: 550.6, intensity: 0.7, transition: "5p→4d (green)" }
            ]},
            { symbol: "Tc", name: "Technetium", atomicNumber: 43, category: "transition-metal", row: 5, col: 7,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "First artificially produced element, but also created in supernovae. All isotopes are radioactive.",
              chemistryInfo: "Transition metal, forms Tc⁴⁺, Tc⁶⁺, and Tc⁷⁺ ions. First element artificially produced. All isotopes radioactive. Used in medical imaging (⁹⁹ᵐTc). Prevents corrosion of steel.",
              physicsInfo: "Electron configuration: [Kr] 4d⁵ 5s². No stable isotopes. Most common: ⁹⁹Tc (half-life 211,000 years). Atomic mass: 98 u. Shells: 2, 8, 18, 13, 2.",
              spectralLines: [
                { wavelength: 403.2, intensity: 0.8, transition: "4d→5s (violet)" },
                { wavelength: 426.2, intensity: 1.0, transition: "5p→4d (blue-violet)" },
                { wavelength: 429.7, intensity: 0.9, transition: "4d→5s (blue)" },
                { wavelength: 485.4, intensity: 0.7, transition: "5p→4d (blue)" }
            ]},
            { symbol: "Ru", name: "Ruthenium", atomicNumber: 44, category: "transition-metal", row: 5, col: 8,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, used in electronics and catalysts.",
              chemistryInfo: "Transition metal, forms Ru²⁺, Ru³⁺, and Ru⁴⁺ ions. Platinum group metal. Used in electrical contacts, chip resistors, and catalysts. Hardens platinum and palladium alloys.",
              physicsInfo: "Electron configuration: [Kr] 4d⁷ 5s¹. Isotopes: ¹⁰²Ru (31.55%), ¹⁰⁴Ru (18.62%), ¹⁰¹Ru (17.06%), ⁹⁹Ru (12.76%), ¹⁰⁰Ru (12.60%), ⁹⁶Ru (5.54%), ⁹⁸Ru (1.87%). Atomic mass: 101.07 u. Shells: 2, 8, 18, 15, 1.",
              spectralLines: [
                { wavelength: 349.9, intensity: 0.8, transition: "5p→4d (UV)" },
                { wavelength: 372.8, intensity: 1.0, transition: "4d→5s (UV)" },
                { wavelength: 379.9, intensity: 0.9, transition: "4d→5s (UV)" },
                { wavelength: 455.5, intensity: 0.6, transition: "5p→4d (blue)" },
                { wavelength: 469.4, intensity: 0.7, transition: "5p→4d (blue)" }
            ]},
            { symbol: "Rh", name: "Rhodium", atomicNumber: 45, category: "transition-metal", row: 5, col: 9,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, one of the rarest and most valuable metals.",
              chemistryInfo: "Transition metal, forms Rh³⁺ and Rh⁴⁺ ions. Platinum group metal. Extremely rare and valuable. Used in catalytic converters, jewelry plating, and industrial catalysts. Highly reflective.",
              physicsInfo: "Electron configuration: [Kr] 4d⁸ 5s¹. Isotope: ¹⁰³Rh (100%). Atomic mass: 102.91 u. Shells: 2, 8, 18, 16, 1.",
              spectralLines: [
                { wavelength: 343.5, intensity: 0.9, transition: "5p→4d (UV)" },
                { wavelength: 369.2, intensity: 1.0, transition: "4d→5s (UV)" },
                { wavelength: 372.8, intensity: 0.8, transition: "4d→5s (UV)" },
                { wavelength: 437.5, intensity: 0.6, transition: "5p→4d (blue)" }
            ]},
            { symbol: "Pd", name: "Palladium", atomicNumber: 46, category: "transition-metal", row: 5, col: 10,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, used in catalytic converters.",
              chemistryInfo: "Transition metal, forms Pd²⁺ and Pd⁴⁺ ions. Platinum group metal. Used in catalytic converters, electronics, dentistry, and jewelry. Can absorb up to 900 times its volume in hydrogen.",
              physicsInfo: "Electron configuration: [Kr] 4d¹⁰. Isotopes: ¹⁰⁶Pd (27.33%), ¹⁰⁸Pd (26.46%), ¹⁰⁵Pd (22.33%), ¹¹⁰Pd (11.72%), ¹⁰⁴Pd (11.14%), ¹⁰²Pd (1.02%). Atomic mass: 106.42 u. Shells: 2, 8, 18, 18.",
              spectralLines: [
                { wavelength: 324.3, intensity: 0.8, transition: "5p→5s (UV)" },
                { wavelength: 340.5, intensity: 1.0, transition: "5p→5s (UV)" },
                { wavelength: 363.5, intensity: 0.9, transition: "5p→5s (UV)" },
                { wavelength: 422.5, intensity: 0.6, transition: "5d→5p (blue-violet)" }
            ]},
            { symbol: "Ag", name: "Silver", atomicNumber: 47, category: "transition-metal", row: 5, col: 11,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, the best conductor of electricity.",
              chemistryInfo: "Transition metal, forms Ag⁺ ions. Best electrical and thermal conductor of all elements. Used in jewelry, coins, electronics, and photography. Antibacterial properties. Tarnishes in air forming Ag₂S.",
              physicsInfo: "Electron configuration: [Kr] 4d¹⁰ 5s¹. Isotopes: ¹⁰⁷Ag (51.84%), ¹⁰⁹Ag (48.16%). Atomic mass: 107.87 u. Shells: 2, 8, 18, 18, 1.",
              spectralLines: [
                { wavelength: 328.1, intensity: 1.0, transition: "5p→5s (UV)" },
                { wavelength: 338.3, intensity: 0.9, transition: "5p→5s (UV)" },
                { wavelength: 405.5, intensity: 0.6, transition: "5d→5p (violet)" },
                { wavelength: 421.2, intensity: 0.5, transition: "5d→5p (violet)" },
                { wavelength: 520.9, intensity: 0.7, transition: "5d→5p (green)" },
                { wavelength: 546.5, intensity: 0.6, transition: "5d→5p (green)" }
            ]},
            { symbol: "Cd", name: "Cadmium", atomicNumber: 48, category: "transition-metal", row: 5, col: 12,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, used in batteries and pigments.",
              chemistryInfo: "Transition metal, forms Cd²⁺ ions. Soft, bluish-white metal. Used in rechargeable batteries, pigments, and coatings. Toxic to humans. Absorbs neutrons, used in nuclear reactor control rods.",
              physicsInfo: "Electron configuration: [Kr] 4d¹⁰ 5s². Isotopes: ¹¹⁴Cd (28.73%), ¹¹²Cd (24.13%), ¹¹¹Cd (12.80%), ¹¹⁰Cd (12.51%), ¹¹³Cd (12.22%), ¹¹⁶Cd (7.49%), ¹⁰⁶Cd (1.25%), ¹⁰⁸Cd (0.89%). Atomic mass: 112.41 u. Shells: 2, 8, 18, 18, 2.",
              spectralLines: [
                { wavelength: 228.8, intensity: 1.0, transition: "5p→5s (UV)" },
                { wavelength: 326.1, intensity: 0.8, transition: "6s→5p (UV)" },
                { wavelength: 361.1, intensity: 0.7, transition: "6s→5p (UV)" },
                { wavelength: 467.8, intensity: 0.6, transition: "6p→6s (blue)" },
                { wavelength: 508.6, intensity: 0.7, transition: "6p→6s (cyan)" },
                { wavelength: 643.8, intensity: 0.8, transition: "6p→6s (red)" }
            ]},
            { symbol: "In", name: "Indium", atomicNumber: 49, category: "metal", row: 5, col: 13,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, used in touchscreens and solar panels.",
              chemistryInfo: "Post-transition metal, forms In⁺ and In³⁺ ions. Soft and malleable. Used in touchscreens (ITO), solar panels, and LEDs. Named for its indigo spectral line. Very rare in Earth's crust.",
              physicsInfo: "Electron configuration: [Kr] 4d¹⁰ 5s² 5p¹. Isotopes: ¹¹⁵In (95.71%, radioactive), ¹¹³In (4.29%). Atomic mass: 114.82 u. Shells: 2, 8, 18, 18, 3.",
              spectralLines: [
                { wavelength: 303.9, intensity: 0.7, transition: "5p→5s (UV)" },
                { wavelength: 325.6, intensity: 0.6, transition: "5p→5s (UV)" },
                { wavelength: 410.2, intensity: 0.9, transition: "6s→5p (violet)" },
                { wavelength: 451.1, intensity: 1.0, transition: "5p→5s (indigo blue)" },
                { wavelength: 465.0, intensity: 0.8, transition: "6s→5p (blue)" }
            ]},
            { symbol: "Sn", name: "Tin", atomicNumber: 50, category: "metal", row: 5, col: 14,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, used since ancient times for bronze.",
              chemistryInfo: "Post-transition metal, forms Sn²⁺ and Sn⁴⁺ ions. Used since ancient times in bronze (Cu+Sn). Used in solder, tin cans, and pewter. Malleable and corrosion-resistant. Has two allotropes (white and gray tin).",
              physicsInfo: "Electron configuration: [Kr] 4d¹⁰ 5s² 5p². Isotopes: ¹²⁰Sn (32.58%), ¹¹⁸Sn (24.22%), ¹¹⁶Sn (14.54%), ¹¹⁹Sn (8.59%), ¹¹⁷Sn (7.68%), ¹²⁴Sn (5.79%), ¹²²Sn (4.63%), ¹¹²Sn (0.97%), ¹¹⁴Sn (0.66%), ¹¹⁵Sn (0.34%). Atomic mass: 118.71 u. Shells: 2, 8, 18, 18, 4.",
              spectralLines: [
                { wavelength: 284.0, intensity: 1.0, transition: "5p→5s (UV)" },
                { wavelength: 317.5, intensity: 0.9, transition: "6s→5p (UV)" },
                { wavelength: 452.5, intensity: 0.6, transition: "6p→6s (blue)" },
                { wavelength: 533.5, intensity: 0.7, transition: "6p→6s (green)" }
            ]},
            { symbol: "Sb", name: "Antimony", atomicNumber: 51, category: "metalloid", row: 5, col: 15,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, used in flame retardants and semiconductors.",
              chemistryInfo: "Metalloid, forms Sb³⁺ and Sb⁵⁺ ions. Used in flame retardants, batteries, and semiconductors. Brittle and silvery. Known since ancient times. Toxic in large amounts.",
              physicsInfo: "Electron configuration: [Kr] 4d¹⁰ 5s² 5p³. Isotopes: ¹²¹Sb (57.21%), ¹²³Sb (42.79%). Atomic mass: 121.76 u. Shells: 2, 8, 18, 18, 5.",
              spectralLines: [
                { wavelength: 252.9, intensity: 0.8, transition: "6s→5p (UV)" },
                { wavelength: 259.8, intensity: 1.0, transition: "5p→5s (UV)" },
                { wavelength: 287.8, intensity: 0.7, transition: "6s→5p (UV)" },
                { wavelength: 326.8, intensity: 0.6, transition: "6p→6s (UV)" }
            ]},
            { symbol: "Te", name: "Tellurium", atomicNumber: 52, category: "metalloid", row: 5, col: 16,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, used in solar panels and thermoelectrics.",
              chemistryInfo: "Metalloid, forms Te²⁻, Te⁴⁺, and Te⁶⁺ ions. Used in solar panels, thermoelectric devices, and DVDs. Brittle and silvery-white. Gives garlic-like odor to breath when ingested.",
              physicsInfo: "Electron configuration: [Kr] 4d¹⁰ 5s² 5p⁴. Isotopes: ¹³⁰Te (34.08%), ¹²⁸Te (31.74%), ¹²⁶Te (18.84%), ¹²⁵Te (7.07%), ¹²⁴Te (4.74%), ¹²²Te (2.55%), ¹²³Te (0.89%), ¹²⁰Te (0.09%). Atomic mass: 127.60 u. Shells: 2, 8, 18, 18, 6.",
              spectralLines: [
                { wavelength: 214.3, intensity: 1.0, transition: "5p→5s (UV)" },
                { wavelength: 238.6, intensity: 0.9, transition: "6s→5p (UV)" },
                { wavelength: 452.5, intensity: 0.5, transition: "6p→6s (blue)" },
                { wavelength: 486.0, intensity: 0.4, transition: "6p→6s (blue)" }
            ]},
            { symbol: "I", name: "Iodine", atomicNumber: 53, category: "halogen", row: 5, col: 17,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, essential for thyroid hormones.",
              chemistryInfo: "Halogen, forms I⁻ ions. Essential for thyroid hormones. Violet vapor when heated. Used in disinfectants, dyes, and photography. Found in seaweed and iodized salt. Deficiency causes goiter.",
              physicsInfo: "Electron configuration: [Kr] 4d¹⁰ 5s² 5p⁵. Isotope: ¹²⁷I (100%). Atomic mass: 126.90 u. Shells: 2, 8, 18, 18, 7.",
              spectralLines: [
                { wavelength: 516.1, intensity: 0.7, transition: "6s→5p (green)" },
                { wavelength: 546.5, intensity: 0.9, transition: "5p→5s (green)" },
                { wavelength: 804.4, intensity: 0.8, transition: "6p→6s (near-IR)" },
                { wavelength: 905.8, intensity: 1.0, transition: "6p→6s (near-IR)" }
            ]},
            { symbol: "Xe", name: "Xenon", atomicNumber: 54, category: "noble-gas", row: 5, col: 18,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, used in high-intensity lamps and anesthesia.",
              chemistryInfo: "Noble gas, can form compounds (unlike lighter noble gases). Used in flash lamps, arc lamps, anesthesia, and ion propulsion. Produces brilliant white light. Extremely rare in Earth's atmosphere.",
              physicsInfo: "Electron configuration: [Kr] 4d¹⁰ 5s² 5p⁶. Isotopes: ¹³²Xe (26.89%), ¹²⁹Xe (26.40%), ¹³¹Xe (21.23%), ¹³⁴Xe (10.44%), ¹³⁶Xe (8.86%), ¹³⁰Xe (4.07%), ¹²⁸Xe (1.91%), ¹²⁴Xe (0.10%), ¹²⁶Xe (0.09%). Atomic mass: 131.29 u. Shells: 2, 8, 18, 18, 8.",
              spectralLines: [
                { wavelength: 450.1, intensity: 0.8, transition: "6p→6s (blue)" },
                { wavelength: 462.4, intensity: 1.0, transition: "6p→6s (blue)" },
                { wavelength: 467.1, intensity: 0.9, transition: "6p→6s (blue)" },
                { wavelength: 480.7, intensity: 0.7, transition: "6p→6s (blue)" },
                { wavelength: 823.2, intensity: 0.8, transition: "6p→6s (near-IR)" },
                { wavelength: 828.0, intensity: 0.7, transition: "6p→6s (near-IR)" }
            ]},
            // Period 6
            { symbol: "Cs", name: "Cesium", atomicNumber: 55, category: "alkali-metal", row: 6, col: 1,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, defines the second in atomic clocks.",
              chemistryInfo: "Highly reactive alkali metal, forms Cs⁺ ions. Most electropositive element. Ignites spontaneously in air. Used in atomic clocks (defines the second), photoelectric cells, and drilling fluids. Soft and golden.",
              physicsInfo: "Electron configuration: [Xe] 6s¹. Isotope: ¹³³Cs (100%). Atomic mass: 132.91 u. Shells: 2, 8, 18, 18, 8, 1.",
              spectralLines: [
                { wavelength: 455.5, intensity: 0.7, transition: "6p→6s (blue)" },
                { wavelength: 459.3, intensity: 0.6, transition: "6p→6s (blue)" },
                { wavelength: 672.3, intensity: 0.8, transition: "6p→6s (red)" },
                { wavelength: 852.1, intensity: 1.0, transition: "6p→6s (near-IR)" },
                { wavelength: 894.3, intensity: 0.9, transition: "6p→6s (near-IR)" }
            ]},
            { symbol: "Ba", name: "Barium", atomicNumber: 56, category: "alkaline-earth", row: 6, col: 2,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, gives fireworks their green color.",
              chemistryInfo: "Alkaline earth metal, forms Ba²⁺ ions. Gives fireworks their green color. Used in medical imaging (barium meals), drilling fluids, and glass. Reactive with water. Compounds are toxic except BaSO₄.",
              physicsInfo: "Electron configuration: [Xe] 6s². Isotopes: ¹³⁸Ba (71.70%), ¹³⁷Ba (11.23%), ¹³⁶Ba (7.85%), ¹³⁵Ba (6.59%), ¹³⁴Ba (2.42%), ¹³⁰Ba (0.11%), ¹³²Ba (0.10%). Atomic mass: 137.33 u. Shells: 2, 8, 18, 18, 8, 2.",
              spectralLines: [
                { wavelength: 455.4, intensity: 0.9, transition: "7s→6p (blue)" },
                { wavelength: 493.4, intensity: 0.8, transition: "6p→6s (cyan)" },
                { wavelength: 513.7, intensity: 1.0, transition: "6p→6s (green)" },
                { wavelength: 553.5, intensity: 1.0, transition: "6p→6s (green)" },
                { wavelength: 577.8, intensity: 0.7, transition: "6p→6s (yellow)" },
                { wavelength: 614.2, intensity: 0.6, transition: "6p→6s (orange)" }
            ]},
            { symbol: "Hf", name: "Hafnium", atomicNumber: 72, category: "transition-metal", row: 6, col: 4,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, used in nuclear reactors and microchips.",
              chemistryInfo: "Transition metal, forms Hf⁴⁺ ions. Excellent neutron absorber used in nuclear reactor control rods. Used in microchips and superalloys. Chemically similar to zirconium. Very corrosion-resistant.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d² 6s². Isotopes: ¹⁸⁰Hf (35.08%), ¹⁷⁸Hf (27.28%), ¹⁷⁷Hf (18.60%), ¹⁷⁹Hf (13.62%), ¹⁷⁶Hf (5.26%), ¹⁷⁴Hf (0.16%). Atomic mass: 178.49 u. Shells: 2, 8, 18, 32, 10, 2.",
              spectralLines: [
                { wavelength: 339.9, intensity: 0.7, transition: "6p→5d (UV)" },
                { wavelength: 368.2, intensity: 0.9, transition: "5d→6s (UV)" },
                { wavelength: 407.5, intensity: 1.0, transition: "5d→6s (violet)" },
                { wavelength: 495.2, intensity: 0.6, transition: "6p→5d (cyan)" }
            ]},
            { symbol: "Ta", name: "Tantalum", atomicNumber: 73, category: "transition-metal", row: 6, col: 5,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, extremely corrosion-resistant.",
              chemistryInfo: "Transition metal, forms Ta⁵⁺ ions. Extremely corrosion-resistant, immune to most acids. Used in capacitors, surgical implants, and jet engines. Named after Tantalus from Greek mythology.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d³ 6s². Isotopes: ¹⁸¹Ta (99.988%), ¹⁸⁰Ta (0.012%, radioactive). Atomic mass: 180.95 u. Shells: 2, 8, 18, 32, 11, 2.",
              spectralLines: [
                { wavelength: 263.6, intensity: 0.8, transition: "6p→5d (UV)" },
                { wavelength: 271.5, intensity: 1.0, transition: "5d→6s (UV)" },
                { wavelength: 301.3, intensity: 0.7, transition: "5d→6s (UV)" },
                { wavelength: 411.9, intensity: 0.6, transition: "6p→5d (violet)" }
            ]},
            { symbol: "W", name: "Tungsten", atomicNumber: 74, category: "transition-metal", row: 6, col: 6,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, has the highest melting point of all elements.",
              chemistryInfo: "Transition metal, forms W⁴⁺ and W⁶⁺ ions. Highest melting point (3422°C) of all elements. Used in light bulb filaments, X-ray tubes, and armor-piercing ammunition. Extremely dense and hard.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d⁴ 6s². Isotopes: ¹⁸⁴W (30.64%), ¹⁸⁶W (28.43%), ¹⁸²W (26.50%), ¹⁸³W (14.31%), ¹⁸⁰W (0.12%). Atomic mass: 183.84 u. Shells: 2, 8, 18, 32, 12, 2.",
              spectralLines: [
                { wavelength: 400.9, intensity: 1.0, transition: "5d→6s (violet)" },
                { wavelength: 407.4, intensity: 0.9, transition: "5d→6s (violet)" },
                { wavelength: 429.5, intensity: 0.9, transition: "6p→5d (blue)" },
                { wavelength: 468.0, intensity: 0.7, transition: "6p→5d (blue)" },
                { wavelength: 505.3, intensity: 0.6, transition: "6p→5d (cyan)" }
            ]},
            { symbol: "Re", name: "Rhenium", atomicNumber: 75, category: "transition-metal", row: 6, col: 7,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, one of the rarest elements in Earth's crust.",
              chemistryInfo: "Transition metal, forms Re⁴⁺, Re⁶⁺, and Re⁷⁺ ions. One of the rarest elements in Earth's crust. Third highest melting point. Used in jet engine parts and catalysts. Named after the Rhine river.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d⁵ 6s². Isotopes: ¹⁸⁷Re (62.60%, radioactive), ¹⁸⁵Re (37.40%). Atomic mass: 186.21 u. Shells: 2, 8, 18, 32, 13, 2.",
              spectralLines: [
                { wavelength: 345.2, intensity: 0.9, transition: "6p→5d (UV)" },
                { wavelength: 346.0, intensity: 1.0, transition: "5d→6s (UV)" },
                { wavelength: 488.0, intensity: 0.6, transition: "6p→5d (blue)" },
                { wavelength: 489.2, intensity: 0.7, transition: "6p→5d (blue)" }
            ]},
            { symbol: "Os", name: "Osmium", atomicNumber: 76, category: "transition-metal", row: 6, col: 8,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Created in neutron star collisions, the densest naturally occurring element.",
              chemistryInfo: "Transition metal, forms Os⁴⁺ and Os⁸⁺ ions. Densest naturally occurring element (22.59 g/cm³). Platinum group metal. Used in fountain pen tips and electrical contacts. OsO₄ is highly toxic.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d⁶ 6s². Isotopes: ¹⁹²Os (40.78%), ¹⁹⁰Os (26.26%), ¹⁸⁹Os (16.15%), ¹⁸⁸Os (13.24%), ¹⁸⁷Os (1.96%), ¹⁸⁶Os (1.59%), ¹⁸⁴Os (0.02%). Atomic mass: 190.23 u. Shells: 2, 8, 18, 32, 14, 2.",
              spectralLines: [
                { wavelength: 305.9, intensity: 0.8, transition: "6p→5d (UV)" },
                { wavelength: 330.2, intensity: 1.0, transition: "5d→6s (UV)" },
                { wavelength: 442.0, intensity: 0.6, transition: "6p→5d (blue)" },
                { wavelength: 426.1, intensity: 0.7, transition: "6p→5d (blue)" }
            ]},
            { symbol: "Ir", name: "Iridium", atomicNumber: 77, category: "transition-metal", row: 6, col: 9,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Forged in neutron star collisions, found in the asteroid impact layer that killed the dinosaurs.",
              chemistryInfo: "Transition metal, forms Ir³⁺ and Ir⁴⁺ ions. Second densest element. Most corrosion-resistant metal. Platinum group metal. Found in the K-T boundary layer from the dinosaur-killing asteroid impact.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d⁷ 6s². Isotopes: ¹⁹³Ir (62.7%), ¹⁹¹Ir (37.3%). Atomic mass: 192.22 u. Shells: 2, 8, 18, 32, 15, 2.",
              spectralLines: [
                { wavelength: 322.1, intensity: 0.8, transition: "6p→5d (UV)" },
                { wavelength: 380.0, intensity: 1.0, transition: "5d→6s (UV)" },
                { wavelength: 424.9, intensity: 0.7, transition: "6p→5d (blue-violet)" },
                { wavelength: 449.8, intensity: 0.6, transition: "6p→5d (blue)" }
            ]},
            { symbol: "Pt", name: "Platinum", atomicNumber: 78, category: "transition-metal", row: 6, col: 10,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Created in neutron star collisions, extremely rare and valuable.",
              chemistryInfo: "Transition metal, forms Pt²⁺ and Pt⁴⁺ ions. Platinum group metal. Extremely rare and valuable. Used in catalytic converters, jewelry, laboratory equipment, and cancer drugs (cisplatin). Highly unreactive.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d⁹ 6s¹. Isotopes: ¹⁹⁵Pt (33.83%), ¹⁹⁴Pt (32.97%), ¹⁹⁶Pt (25.24%), ¹⁹⁸Pt (7.16%), ¹⁹²Pt (0.78%), ¹⁹⁰Pt (0.01%). Atomic mass: 195.08 u. Shells: 2, 8, 18, 32, 17, 1.",
              spectralLines: [
                { wavelength: 265.9, intensity: 1.0, transition: "6p→6s (UV)" },
                { wavelength: 299.8, intensity: 0.9, transition: "6p→6s (UV)" },
                { wavelength: 306.5, intensity: 0.8, transition: "6p→6s (UV)" },
                { wavelength: 390.5, intensity: 0.6, transition: "6d→6p (violet)" }
            ]},
            { symbol: "Hg", name: "Mercury", atomicNumber: 80, category: "transition-metal", row: 6, col: 12,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Produced in neutron star collisions, the only metal that's liquid at room temperature.",
              chemistryInfo: "Transition metal, forms Hg⁺ and Hg²⁺ ions. Only metal liquid at room temperature. Used in thermometers, barometers, fluorescent lights, and dental amalgams. Highly toxic, especially as vapor and methylmercury.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d¹⁰ 6s². Isotopes: ²⁰²Hg (29.86%), ²⁰⁰Hg (23.10%), ¹⁹⁹Hg (16.87%), ²⁰¹Hg (13.18%), ¹⁹⁸Hg (9.97%), ²⁰⁴Hg (6.87%), ¹⁹⁶Hg (0.15%). Atomic mass: 200.59 u. Shells: 2, 8, 18, 32, 18, 2.",
              spectralLines: [
                { wavelength: 253.7, intensity: 1.0, transition: "6p→6s (UV)" },
                { wavelength: 365.0, intensity: 0.7, transition: "7s→6p (UV)" },
                { wavelength: 404.7, intensity: 0.9, transition: "7s→6p (violet)" },
                { wavelength: 435.8, intensity: 1.0, transition: "7s→6p (blue)" },
                { wavelength: 546.1, intensity: 0.8, transition: "7s→6p (green)" },
                { wavelength: 577.0, intensity: 0.6, transition: "7s→6p (yellow)" },
                { wavelength: 579.1, intensity: 0.6, transition: "7s→6p (yellow)" }
            ]},
            { symbol: "Tl", name: "Thallium", atomicNumber: 81, category: "metal", row: 6, col: 13,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Forged in neutron star collisions, highly toxic but used in medical imaging.",
              chemistryInfo: "Post-transition metal, forms Tl⁺ and Tl³⁺ ions. Soft and malleable. Highly toxic (used as rat poison). Used in medical imaging, electronics, and infrared detectors. Named for its bright green spectral line (thallos = green twig).",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d¹⁰ 6s² 6p¹. Isotopes: ²⁰⁵Tl (70.48%), ²⁰³Tl (29.52%). Atomic mass: 204.38 u. Shells: 2, 8, 18, 32, 18, 3.",
              spectralLines: [
                { wavelength: 377.6, intensity: 0.9, transition: "7s→6p (UV)" },
                { wavelength: 535.0, intensity: 1.0, transition: "6p→6s (green)" },
                { wavelength: 291.8, intensity: 0.7, transition: "7s→6p (UV)" }
            ]},
            { symbol: "Pb", name: "Lead", atomicNumber: 82, category: "metal", row: 6, col: 14,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Created in neutron star collisions, the final stable element in the periodic table.",
              spectralLines: [{ wavelength: 405.8, intensity: 1.0 }, { wavelength: 368.3, intensity: 0.8 }]},
            { symbol: "Bi", name: "Bismuth", atomicNumber: 83, category: "metal", row: 6, col: 15,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Produced in neutron star collisions, the most diamagnetic element.",
              spectralLines: [{ wavelength: 306.8, intensity: 0.9 }, { wavelength: 289.8, intensity: 0.7 }]},
            { symbol: "Pb", name: "Lead", atomicNumber: 82, category: "metal", row: 6, col: 14,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Created in neutron star collisions, the final stable element in the periodic table.",
              chemistryInfo: "Post-transition metal, forms Pb²⁺ and Pb⁴⁺ ions. Heaviest stable element. Soft, malleable, and dense. Used in batteries, radiation shielding, and historically in pipes and paint. Toxic, especially to children.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d¹⁰ 6s² 6p². Isotopes: ²⁰⁸Pb (52.4%), ²⁰⁶Pb (24.1%), ²⁰⁷Pb (22.1%), ²⁰⁴Pb (1.4%). Atomic mass: 207.2 u. Shells: 2, 8, 18, 32, 18, 4.",
              spectralLines: [{ wavelength: 405.8, intensity: 1.0, transition: "6p→6s" }, { wavelength: 368.3, intensity: 0.8, transition: "7s→6p" }]},
            { symbol: "Bi", name: "Bismuth", atomicNumber: 83, category: "metal", row: 6, col: 15,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Produced in neutron star collisions, forms beautiful iridescent oxide crystals.",
              chemistryInfo: "Post-transition metal, forms Bi³⁺ and Bi⁵⁺ ions. Brittle with iridescent oxide layer. Used in cosmetics, medicines (Pepto-Bismol), and low-melting alloys. Least toxic of heavy metals. Diamagnetic.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d¹⁰ 6s² 6p³. Isotope: ²⁰⁹Bi (100%, very slightly radioactive). Atomic mass: 208.98 u. Shells: 2, 8, 18, 32, 18, 5.",
              spectralLines: [{ wavelength: 306.8, intensity: 0.9, transition: "6p→6s" }, { wavelength: 289.8, intensity: 0.7, transition: "7s→6p" }]},
            { symbol: "Po", name: "Polonium", atomicNumber: 84, category: "metalloid", row: 6, col: 16,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Forged in neutron star collisions, discovered by Marie Curie, highly radioactive.",
              chemistryInfo: "Metalloid, forms Po²⁺ and Po⁴⁺ ions. Highly radioactive and toxic. Discovered by Marie Curie, named after Poland. Used in antistatic devices and as heat source in space probes. All isotopes radioactive.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d¹⁰ 6s² 6p⁴. No stable isotopes. Most common: ²⁰⁹Po (half-life 102 years). Atomic mass: 209 u. Shells: 2, 8, 18, 32, 18, 6.",
              spectralLines: [{ wavelength: 300.3, intensity: 0.7, transition: "6p→6s" }, { wavelength: 255.8, intensity: 0.5, transition: "7s→6p" }]},
            { symbol: "At", name: "Astatine", atomicNumber: 85, category: "halogen", row: 6, col: 17,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Created in neutron star collisions, the rarest naturally occurring element on Earth.",
              chemistryInfo: "Halogen, forms At⁻ ions. Rarest naturally occurring element on Earth (less than 1 gram in Earth's crust). All isotopes radioactive. Properties similar to iodine. Used in cancer treatment research.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d¹⁰ 6s² 6p⁵. No stable isotopes. Most stable: ²¹⁰At (half-life 8.1 hours). Atomic mass: 210 u. Shells: 2, 8, 18, 32, 18, 7.",
              spectralLines: [{ wavelength: 224.4, intensity: 0.6, transition: "6p→6s" }, { wavelength: 216.2, intensity: 0.5, transition: "7s→6p" }]},
            { symbol: "Rn", name: "Radon", atomicNumber: 86, category: "noble-gas", row: 6, col: 18,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Produced in neutron star collisions, radioactive noble gas found in basements.",
              chemistryInfo: "Noble gas, can form compounds. Radioactive decay product of radium. Colorless, odorless, and tasteless. Accumulates in basements, second leading cause of lung cancer. All isotopes radioactive.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d¹⁰ 6s² 6p⁶. No stable isotopes. Most stable: ²²²Rn (half-life 3.8 days). Atomic mass: 222 u. Shells: 2, 8, 18, 32, 18, 8.",
              spectralLines: [{ wavelength: 435.0, intensity: 0.7, transition: "7p→7s" }, { wavelength: 745.0, intensity: 0.6, transition: "7p→7s" }]},
            // Period 7
            { symbol: "Fr", name: "Francium", atomicNumber: 87, category: "alkali-metal", row: 7, col: 1,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Forged in neutron star collisions, extremely rare and radioactive.",
              chemistryInfo: "Highly reactive alkali metal, forms Fr⁺ ions. Most unstable of first 101 elements. Extremely rare (less than 30 grams in Earth's crust at any time). All isotopes radioactive. Would be liquid at room temperature.",
              physicsInfo: "Electron configuration: [Rn] 7s¹. No stable isotopes. Most stable: ²²³Fr (half-life 22 minutes). Atomic mass: 223 u. Shells: 2, 8, 18, 32, 18, 8, 1.",
              spectralLines: [{ wavelength: 718.0, intensity: 0.5, transition: "7p→7s" }, { wavelength: 817.0, intensity: 0.4, transition: "7p→7s" }]},
            { symbol: "Ra", name: "Radium", atomicNumber: 88, category: "alkaline-earth", row: 7, col: 2,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Created in neutron star collisions, discovered by Marie Curie, glows in the dark.",
              chemistryInfo: "Alkaline earth metal, forms Ra²⁺ ions. Discovered by Marie and Pierre Curie. Glows in the dark due to radioactivity. Used in early luminous paints (now banned). Highly radioactive and toxic. Decay product of uranium.",
              physicsInfo: "Electron configuration: [Rn] 7s². No stable isotopes. Most stable: ²²⁶Ra (half-life 1600 years). Atomic mass: 226 u. Shells: 2, 8, 18, 32, 18, 8, 2.",
              spectralLines: [{ wavelength: 381.4, intensity: 0.7, transition: "7p→7s" }, { wavelength: 468.2, intensity: 0.6, transition: "8s→7p" }]},
            { symbol: "Rf", name: "Rutherfordium", atomicNumber: 104, category: "transition-metal", row: 7, col: 4,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element created in laboratories, does not occur naturally.",
              chemistryInfo: "Synthetic transition metal. Created by bombarding californium with carbon ions. Extremely radioactive. Only a few atoms produced at a time. Properties predicted to be similar to hafnium.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d² 7s². No stable isotopes. Most stable: ²⁶⁷Rf (half-life 1.3 hours). Atomic mass: 267 u.",
              spectralLines: [{ wavelength: 350.0, intensity: 0.3, transition: "6d→7s" }]},
            { symbol: "Db", name: "Dubnium", atomicNumber: 105, category: "transition-metal", row: 7, col: 5,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Dubna, Russia.",
              chemistryInfo: "Synthetic transition metal. Named after Dubna, Russia where it was discovered. Extremely radioactive. Properties predicted to be similar to tantalum. Only produced in particle accelerators.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d³ 7s². No stable isotopes. Most stable: ²⁶⁸Db (half-life 28 hours). Atomic mass: 268 u.",
              spectralLines: [{ wavelength: 360.0, intensity: 0.3, transition: "6d→7s" }]},
            { symbol: "Sg", name: "Seaborgium", atomicNumber: 106, category: "transition-metal", row: 7, col: 6,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Glenn Seaborg.",
              chemistryInfo: "Synthetic transition metal. Named after Glenn Seaborg, Nobel laureate. Extremely radioactive. Properties predicted to be similar to tungsten. Only a few atoms ever produced.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d⁴ 7s². No stable isotopes. Most stable: ²⁶⁹Sg (half-life 14 minutes). Atomic mass: 269 u.",
              spectralLines: [{ wavelength: 370.0, intensity: 0.3, transition: "6d→7s" }]},
            { symbol: "Bh", name: "Bohrium", atomicNumber: 107, category: "transition-metal", row: 7, col: 7,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Niels Bohr.",
              chemistryInfo: "Synthetic transition metal. Named after Niels Bohr, pioneer of atomic theory. Extremely radioactive. Properties predicted to be similar to rhenium. Produced one atom at a time.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d⁵ 7s². No stable isotopes. Most stable: ²⁷⁰Bh (half-life 61 seconds). Atomic mass: 270 u.",
              spectralLines: [{ wavelength: 380.0, intensity: 0.3, transition: "6d→7s" }]},
            { symbol: "Hs", name: "Hassium", atomicNumber: 108, category: "transition-metal", row: 7, col: 8,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after the German state of Hesse.",
              chemistryInfo: "Synthetic transition metal. Named after Hesse, Germany. Extremely radioactive. Properties predicted to be similar to osmium. Very few atoms ever produced.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d⁶ 7s². No stable isotopes. Most stable: ²⁷⁰Hs (half-life 10 seconds). Atomic mass: 270 u.",
              spectralLines: [{ wavelength: 390.0, intensity: 0.3, transition: "6d→7s" }]},
            { symbol: "Mt", name: "Meitnerium", atomicNumber: 109, category: "transition-metal", row: 7, col: 9,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Lise Meitner.",
              chemistryInfo: "Synthetic transition metal. Named after Lise Meitner, physicist who discovered nuclear fission. Extremely radioactive. Properties predicted to be similar to iridium.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d⁷ 7s². No stable isotopes. Most stable: ²⁷⁸Mt (half-life 8 seconds). Atomic mass: 278 u.",
              spectralLines: [{ wavelength: 400.0, intensity: 0.3, transition: "6d→7s" }]},
            { symbol: "Ds", name: "Darmstadtium", atomicNumber: 110, category: "transition-metal", row: 7, col: 10,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Darmstadt, Germany.",
              chemistryInfo: "Synthetic transition metal. Named after Darmstadt, Germany. Extremely radioactive. Properties predicted to be similar to platinum. Only a few atoms ever created.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d⁸ 7s². No stable isotopes. Most stable: ²⁸¹Ds (half-life 11 seconds). Atomic mass: 281 u.",
              spectralLines: [{ wavelength: 410.0, intensity: 0.3, transition: "6d→7s" }]},
            { symbol: "Rg", name: "Roentgenium", atomicNumber: 111, category: "transition-metal", row: 7, col: 11,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Wilhelm Röntgen.",
              chemistryInfo: "Synthetic transition metal. Named after Wilhelm Röntgen, discoverer of X-rays. Extremely radioactive. Properties predicted to be similar to gold. Produced in particle accelerators.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d⁹ 7s². No stable isotopes. Most stable: ²⁸²Rg (half-life 2 minutes). Atomic mass: 282 u.",
              spectralLines: [{ wavelength: 420.0, intensity: 0.3, transition: "6d→7s" }]},
            { symbol: "Cn", name: "Copernicium", atomicNumber: 112, category: "transition-metal", row: 7, col: 12,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Nicolaus Copernicus.",
              chemistryInfo: "Synthetic transition metal. Named after Nicolaus Copernicus, astronomer. Extremely radioactive. Properties predicted to be similar to mercury, possibly liquid or gas at room temperature.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d¹⁰ 7s². No stable isotopes. Most stable: ²⁸⁵Cn (half-life 29 seconds). Atomic mass: 285 u.",
              spectralLines: [{ wavelength: 430.0, intensity: 0.3, transition: "7p→7s" }]},
            { symbol: "Nh", name: "Nihonium", atomicNumber: 113, category: "metal", row: 7, col: 13,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Japan (Nihon).",
              chemistryInfo: "Synthetic post-transition metal. Named after Japan (Nihon). Extremely radioactive. Properties predicted to be similar to thallium. First element synthesized in Asia.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d¹⁰ 7s² 7p¹. No stable isotopes. Most stable: ²⁸⁶Nh (half-life 10 seconds). Atomic mass: 286 u.",
              spectralLines: [{ wavelength: 440.0, intensity: 0.3, transition: "7p→7s" }]},
            { symbol: "Fl", name: "Flerovium", atomicNumber: 114, category: "metal", row: 7, col: 14,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Georgy Flyorov.",
              chemistryInfo: "Synthetic post-transition metal. Named after Georgy Flyorov, physicist. Extremely radioactive. Properties predicted to be similar to lead. May be volatile like a noble gas.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d¹⁰ 7s² 7p². No stable isotopes. Most stable: ²⁸⁹Fl (half-life 2.6 seconds). Atomic mass: 289 u.",
              spectralLines: [{ wavelength: 450.0, intensity: 0.3, transition: "7p→7s" }]},
            { symbol: "Mc", name: "Moscovium", atomicNumber: 115, category: "metal", row: 7, col: 15,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Moscow, Russia.",
              chemistryInfo: "Synthetic post-transition metal. Named after Moscow, Russia. Extremely radioactive. Properties predicted to be similar to bismuth. Produced by bombarding americium with calcium.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d¹⁰ 7s² 7p³. No stable isotopes. Most stable: ²⁹⁰Mc (half-life 0.65 seconds). Atomic mass: 290 u.",
              spectralLines: [{ wavelength: 460.0, intensity: 0.3, transition: "7p→7s" }]},
            { symbol: "Lv", name: "Livermorium", atomicNumber: 116, category: "metal", row: 7, col: 16,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Livermore, California.",
              chemistryInfo: "Synthetic post-transition metal. Named after Lawrence Livermore National Laboratory. Extremely radioactive. Properties predicted to be similar to polonium. Very short-lived.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d¹⁰ 7s² 7p⁴. No stable isotopes. Most stable: ²⁹³Lv (half-life 61 milliseconds). Atomic mass: 293 u.",
              spectralLines: [{ wavelength: 470.0, intensity: 0.3, transition: "7p→7s" }]},
            { symbol: "Ts", name: "Tennessine", atomicNumber: 117, category: "halogen", row: 7, col: 17,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Tennessee, USA.",
              chemistryInfo: "Synthetic halogen. Named after Tennessee, USA. Extremely radioactive. Properties predicted to be similar to astatine. Second-heaviest known element. May be metallic rather than halogen-like.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d¹⁰ 7s² 7p⁵. No stable isotopes. Most stable: ²⁹⁴Ts (half-life 51 milliseconds). Atomic mass: 294 u.",
              spectralLines: [{ wavelength: 480.0, intensity: 0.3, transition: "7p→7s" }]},
            { symbol: "Og", name: "Oganesson", atomicNumber: 118, category: "noble-gas", row: 7, col: 18,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Yuri Oganessian, completes the 7th period.",
              chemistryInfo: "Synthetic noble gas. Named after Yuri Oganessian, nuclear physicist. Heaviest known element. Extremely radioactive. May be solid at room temperature due to relativistic effects, unlike other noble gases.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 6d¹⁰ 7s² 7p⁶. No stable isotopes. Most stable: ²⁹⁴Og (half-life 0.7 milliseconds). Atomic mass: 294 u.",
              spectralLines: [{ wavelength: 490.0, intensity: 0.3, transition: "7p→7s" }]},
            // Lanthanides
            { symbol: "La", name: "Lanthanum", atomicNumber: 57, category: "lanthanide", row: 8, col: 3,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, used in camera lenses and lighting.",
              chemistryInfo: "Lanthanide, forms La³⁺ ions. Soft and malleable. Used in camera lenses, studio lighting, and hydrogen storage. Tarnishes rapidly in air. First of the lanthanide series.",
              physicsInfo: "Electron configuration: [Xe] 5d¹ 6s². Isotopes: ¹³⁹La (99.91%), ¹³⁸La (0.09%, radioactive). Atomic mass: 138.91 u. Shells: 2, 8, 18, 18, 9, 2.",
              spectralLines: [{ wavelength: 550.1, intensity: 0.9, transition: "5d→6s" }, { wavelength: 394.9, intensity: 0.7, transition: "6p→5d" }]},
            { symbol: "Ce", name: "Cerium", atomicNumber: 58, category: "lanthanide", row: 8, col: 4,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, most abundant rare earth element.",
              chemistryInfo: "Lanthanide, forms Ce³⁺ and Ce⁴⁺ ions. Most abundant rare earth element. Used in catalytic converters, self-cleaning ovens, and glass polishing. Ignites when scratched.",
              physicsInfo: "Electron configuration: [Xe] 4f¹ 5d¹ 6s². Isotopes: ¹⁴⁰Ce (88.45%), ¹⁴²Ce (11.11%), ¹³⁸Ce (0.25%), ¹³⁶Ce (0.19%). Atomic mass: 140.12 u. Shells: 2, 8, 18, 19, 9, 2.",
              spectralLines: [{ wavelength: 569.9, intensity: 0.8, transition: "4f→5d" }, { wavelength: 413.4, intensity: 0.6, transition: "6p→5d" }]},
            { symbol: "Pr", name: "Praseodymium", atomicNumber: 59, category: "lanthanide", row: 8, col: 5,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, gives protective goggles their color.",
              chemistryInfo: "Lanthanide, forms Pr³⁺ and Pr⁴⁺ ions. Used in welders' goggles, magnets, and lighter flints. Forms green salts. Tarnishes slowly in air.",
              physicsInfo: "Electron configuration: [Xe] 4f³ 6s². Isotope: ¹⁴¹Pr (100%). Atomic mass: 140.91 u. Shells: 2, 8, 18, 21, 8, 2.",
              spectralLines: [{ wavelength: 495.1, intensity: 0.8, transition: "4f→6s" }, { wavelength: 513.3, intensity: 0.7, transition: "6p→4f" }]},
            { symbol: "Nd", name: "Neodymium", atomicNumber: 60, category: "lanthanide", row: 8, col: 6,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Created in supernovae, makes the strongest permanent magnets.",
              chemistryInfo: "Lanthanide, forms Nd³⁺ ions. Makes the strongest permanent magnets (Nd₂Fe₁₄B). Used in hard drives, headphones, and electric motors. Colors glass purple.",
              physicsInfo: "Electron configuration: [Xe] 4f⁴ 6s². Isotopes: ¹⁴²Nd (27.2%), ¹⁴⁴Nd (23.8%), ¹⁴⁶Nd (17.2%), ¹⁴³Nd (12.2%), ¹⁴⁵Nd (8.3%), ¹⁴⁸Nd (5.7%), ¹⁵⁰Nd (5.6%). Atomic mass: 144.24 u. Shells: 2, 8, 18, 22, 8, 2.",
              spectralLines: [{ wavelength: 492.5, intensity: 0.9, transition: "4f→6s" }, { wavelength: 463.4, intensity: 0.7, transition: "6p→4f" }]},
            { symbol: "Pm", name: "Promethium", atomicNumber: 61, category: "lanthanide", row: 8, col: 7,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Produced in supernovae, all isotopes are radioactive.",
              chemistryInfo: "Lanthanide, forms Pm³⁺ ions. Only radioactive rare earth element. Used in luminous paint and atomic batteries. All isotopes radioactive. Named after Prometheus.",
              physicsInfo: "Electron configuration: [Xe] 4f⁵ 6s². No stable isotopes. Most stable: ¹⁴⁵Pm (half-life 17.7 years). Atomic mass: 145 u. Shells: 2, 8, 18, 23, 8, 2.",
              spectralLines: [{ wavelength: 468.0, intensity: 0.6, transition: "4f→6s" }, { wavelength: 441.0, intensity: 0.5, transition: "6p→4f" }]},
            { symbol: "Sm", name: "Samarium", atomicNumber: 62, category: "lanthanide", row: 8, col: 8,
              cosmicOrigin: "Exploding Massive Stars", originColor: "#00CED1",
              astronomyInfo: "Forged in supernovae, used in powerful magnets and cancer treatment.",
              chemistryInfo: "Lanthanide, forms Sm²⁺ and Sm³⁺ ions. Used in powerful magnets, cancer treatment, and nuclear reactors. Ignites at 150°C. Named after mineral samarskite.",
              physicsInfo: "Electron configuration: [Xe] 4f⁶ 6s². Isotopes: ¹⁵²Sm (26.75%), ¹⁵⁴Sm (22.75%), ¹⁴⁷Sm (14.99%), ¹⁴⁹Sm (13.82%), ¹⁴⁸Sm (11.24%), ¹⁵⁰Sm (7.38%), ¹⁴⁴Sm (3.07%). Atomic mass: 150.36 u. Shells: 2, 8, 18, 24, 8, 2.",
              spectralLines: [{ wavelength: 476.0, intensity: 0.8, transition: "4f→6s" }, { wavelength: 428.1, intensity: 0.6, transition: "6p→4f" }]},
            { symbol: "Eu", name: "Europium", atomicNumber: 63, category: "lanthanide", row: 8, col: 9,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Created in neutron star collisions, used in euro banknote anti-counterfeiting.",
              chemistryInfo: "Lanthanide, forms Eu²⁺ and Eu³⁺ ions. Most reactive rare earth element. Used in euro banknotes (anti-counterfeiting), TV screens, and LEDs. Named after Europe.",
              physicsInfo: "Electron configuration: [Xe] 4f⁷ 6s². Isotopes: ¹⁵³Eu (52.19%), ¹⁵¹Eu (47.81%). Atomic mass: 151.96 u. Shells: 2, 8, 18, 25, 8, 2.",
              spectralLines: [{ wavelength: 459.4, intensity: 1.0, transition: "4f→6s" }, { wavelength: 466.2, intensity: 0.8, transition: "6p→4f" }]},
            { symbol: "Gd", name: "Gadolinium", atomicNumber: 64, category: "lanthanide", row: 8, col: 10,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Produced in neutron star collisions, used in MRI contrast agents.",
              chemistryInfo: "Lanthanide, forms Gd³⁺ ions. Used in MRI contrast agents, neutron radiography, and magnets. Ferromagnetic below 20°C. Named after Johan Gadolin.",
              physicsInfo: "Electron configuration: [Xe] 4f⁷ 5d¹ 6s². Isotopes: ¹⁵⁸Gd (24.84%), ¹⁶⁰Gd (21.86%), ¹⁵⁶Gd (20.47%), ¹⁵⁷Gd (15.65%), ¹⁵⁵Gd (14.80%), ¹⁵⁴Gd (2.18%), ¹⁵²Gd (0.20%). Atomic mass: 157.25 u. Shells: 2, 8, 18, 25, 9, 2.",
              spectralLines: [{ wavelength: 440.2, intensity: 0.8, transition: "4f→6s" }, { wavelength: 407.9, intensity: 0.7, transition: "6p→4f" }]},
            { symbol: "Tb", name: "Terbium", atomicNumber: 65, category: "lanthanide", row: 8, col: 11,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Forged in neutron star collisions, used in green phosphors.",
              chemistryInfo: "Lanthanide, forms Tb³⁺ and Tb⁴⁺ ions. Used in green phosphors for fluorescent lamps and TV tubes. Magnetostrictive (changes shape in magnetic fields). Named after Ytterby, Sweden.",
              physicsInfo: "Electron configuration: [Xe] 4f⁹ 6s². Isotope: ¹⁵⁹Tb (100%). Atomic mass: 158.93 u. Shells: 2, 8, 18, 27, 8, 2.",
              spectralLines: [{ wavelength: 432.6, intensity: 0.9, transition: "4f→6s" }, { wavelength: 350.9, intensity: 0.7, transition: "6p→4f" }]},
            { symbol: "Dy", name: "Dysprosium", atomicNumber: 66, category: "lanthanide", row: 8, col: 12,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Created in neutron star collisions, used in high-performance magnets.",
              chemistryInfo: "Lanthanide, forms Dy³⁺ ions. Used in high-performance magnets, lasers, and nuclear reactors. Soft and silvery. Name means 'hard to get' in Greek.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁰ 6s². Isotopes: ¹⁶⁴Dy (28.18%), ¹⁶²Dy (25.51%), ¹⁶³Dy (24.90%), ¹⁶¹Dy (18.91%), ¹⁶⁰Dy (2.33%), ¹⁵⁸Dy (0.10%), ¹⁵⁶Dy (0.06%). Atomic mass: 162.50 u. Shells: 2, 8, 18, 28, 8, 2.",
              spectralLines: [{ wavelength: 421.2, intensity: 0.8, transition: "4f→6s" }, { wavelength: 404.6, intensity: 0.7, transition: "6p→4f" }]},
            { symbol: "Ho", name: "Holmium", atomicNumber: 67, category: "lanthanide", row: 8, col: 13,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Produced in neutron star collisions, has the highest magnetic strength.",
              chemistryInfo: "Lanthanide, forms Ho³⁺ ions. Has the highest magnetic strength of any element. Used in lasers, magnets, and nuclear reactors. Named after Stockholm (Holmia in Latin).",
              physicsInfo: "Electron configuration: [Xe] 4f¹¹ 6s². Isotope: ¹⁶⁵Ho (100%). Atomic mass: 164.93 u. Shells: 2, 8, 18, 29, 8, 2.",
              spectralLines: [{ wavelength: 410.4, intensity: 0.8, transition: "4f→6s" }, { wavelength: 389.1, intensity: 0.6, transition: "6p→4f" }]},
            { symbol: "Er", name: "Erbium", atomicNumber: 68, category: "lanthanide", row: 8, col: 14,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Forged in neutron star collisions, used in fiber optic amplifiers.",
              chemistryInfo: "Lanthanide, forms Er³⁺ ions. Used in fiber optic amplifiers, lasers, and nuclear technology. Colors glass pink. Named after Ytterby, Sweden.",
              physicsInfo: "Electron configuration: [Xe] 4f¹² 6s². Isotopes: ¹⁶⁶Er (33.50%), ¹⁶⁸Er (26.98%), ¹⁶⁷Er (22.87%), ¹⁷⁰Er (14.88%), ¹⁶⁴Er (1.56%), ¹⁶²Er (0.14%). Atomic mass: 167.26 u. Shells: 2, 8, 18, 30, 8, 2.",
              spectralLines: [{ wavelength: 400.8, intensity: 0.9, transition: "4f→6s" }, { wavelength: 415.1, intensity: 0.7, transition: "6p→4f" }]},
            { symbol: "Tm", name: "Thulium", atomicNumber: 69, category: "lanthanide", row: 8, col: 15,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Created in neutron star collisions, used in portable X-ray devices.",
              chemistryInfo: "Lanthanide, forms Tm²⁺ and Tm³⁺ ions. Least abundant rare earth element. Used in portable X-ray devices, lasers, and arc lighting. Named after Thule (ancient name for Scandinavia).",
              physicsInfo: "Electron configuration: [Xe] 4f¹³ 6s². Isotope: ¹⁶⁹Tm (100%). Atomic mass: 168.93 u. Shells: 2, 8, 18, 31, 8, 2.",
              spectralLines: [{ wavelength: 371.8, intensity: 0.8, transition: "4f→6s" }, { wavelength: 409.4, intensity: 0.6, transition: "6p→4f" }]},
            { symbol: "Yb", name: "Ytterbium", atomicNumber: 70, category: "lanthanide", row: 8, col: 16,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Produced in neutron star collisions, used in atomic clocks.",
              chemistryInfo: "Lanthanide, forms Yb²⁺ and Yb³⁺ ions. Used in atomic clocks, lasers, and steel alloys. Soft and malleable. Named after Ytterby, Sweden.",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 6s². Isotopes: ¹⁷⁴Yb (31.83%), ¹⁷²Yb (21.83%), ¹⁷³Yb (16.13%), ¹⁷¹Yb (14.28%), ¹⁷⁶Yb (12.76%), ¹⁷⁰Yb (3.04%), ¹⁶⁸Yb (0.13%). Atomic mass: 173.05 u. Shells: 2, 8, 18, 32, 8, 2.",
              spectralLines: [{ wavelength: 398.8, intensity: 1.0, transition: "6p→6s" }, { wavelength: 555.6, intensity: 0.7, transition: "6p→6s" }]},
            { symbol: "Lu", name: "Lutetium", atomicNumber: 71, category: "lanthanide", row: 8, col: 17,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Forged in neutron star collisions, the last lanthanide element.",
              chemistryInfo: "Lanthanide, forms Lu³⁺ ions. Hardest and densest rare earth element. Used in catalysts, phosphors, and cancer treatment. Named after Lutetia (ancient name for Paris).",
              physicsInfo: "Electron configuration: [Xe] 4f¹⁴ 5d¹ 6s². Isotopes: ¹⁷⁵Lu (97.41%), ¹⁷⁶Lu (2.59%, radioactive). Atomic mass: 174.97 u. Shells: 2, 8, 18, 32, 9, 2.",
              spectralLines: [{ wavelength: 451.9, intensity: 0.8, transition: "5d→6s" }, { wavelength: 337.7, intensity: 0.6, transition: "6p→5d" }]},
            // Actinides
            { symbol: "Ac", name: "Actinium", atomicNumber: 89, category: "actinide", row: 9, col: 3,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Created in neutron star collisions, radioactive and glows blue in the dark.",
              chemistryInfo: "Actinide, forms Ac³⁺ ions. Radioactive, glows blue in the dark. Used in radiation therapy. Extremely rare. Named from Greek 'aktinos' meaning ray.",
              physicsInfo: "Electron configuration: [Rn] 6d¹ 7s². No stable isotopes. Most stable: ²²⁷Ac (half-life 21.8 years). Atomic mass: 227 u. Shells: 2, 8, 18, 32, 18, 9, 2.",
              spectralLines: [{ wavelength: 417.0, intensity: 0.6, transition: "6d→7s" }, { wavelength: 438.0, intensity: 0.5, transition: "7p→6d" }]},
            { symbol: "Th", name: "Thorium", atomicNumber: 90, category: "actinide", row: 9, col: 4,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Produced in neutron star collisions, potential future nuclear fuel.",
              chemistryInfo: "Actinide, forms Th⁴⁺ ions. Radioactive but more abundant than uranium. Potential future nuclear fuel. Used in gas mantles and welding electrodes. Named after Thor.",
              physicsInfo: "Electron configuration: [Rn] 6d² 7s². Isotope: ²³²Th (100%, radioactive, half-life 14 billion years). Atomic mass: 232.04 u. Shells: 2, 8, 18, 32, 18, 10, 2.",
              spectralLines: [{ wavelength: 401.9, intensity: 0.8, transition: "6d→7s" }, { wavelength: 283.7, intensity: 0.6, transition: "7p→6d" }]},
            { symbol: "Pa", name: "Protactinium", atomicNumber: 91, category: "actinide", row: 9, col: 5,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Forged in neutron star collisions, highly radioactive and rare.",
              chemistryInfo: "Actinide, forms Pa⁴⁺ and Pa⁵⁺ ions. Highly radioactive and toxic. Extremely rare. No practical applications. Name means 'before actinium' (parent of actinium).",
              physicsInfo: "Electron configuration: [Rn] 5f² 6d¹ 7s². Isotope: ²³¹Pa (100%, radioactive, half-life 32,760 years). Atomic mass: 231.04 u. Shells: 2, 8, 18, 32, 20, 9, 2.",
              spectralLines: [{ wavelength: 392.0, intensity: 0.6, transition: "5f→7s" }, { wavelength: 405.0, intensity: 0.5, transition: "7p→5f" }]},
            { symbol: "U", name: "Uranium", atomicNumber: 92, category: "actinide", row: 9, col: 6,
              cosmicOrigin: "Merging Neutron Stars", originColor: "#FF4500",
              astronomyInfo: "Created in neutron star collisions, powers nuclear reactors and was formed before Earth.",
              chemistryInfo: "Actinide, forms U³⁺, U⁴⁺, U⁵⁺, and U⁶⁺ ions. Powers nuclear reactors and weapons. Naturally radioactive. Used in dating rocks. Depleted uranium used in armor and ammunition. Named after Uranus.",
              physicsInfo: "Electron configuration: [Rn] 5f³ 6d¹ 7s². Isotopes: ²³⁸U (99.27%, half-life 4.5 billion years), ²³⁵U (0.72%, half-life 704 million years), ²³⁴U (0.01%). Atomic mass: 238.03 u. Shells: 2, 8, 18, 32, 21, 9, 2.",
              spectralLines: [{ wavelength: 591.5, intensity: 0.8, transition: "5f→7s" }, { wavelength: 424.4, intensity: 0.7, transition: "7p→5f" }]},
            { symbol: "Np", name: "Neptunium", atomicNumber: 93, category: "actinide", row: 9, col: 7,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "First synthetic transuranium element, named after Neptune.",
              chemistryInfo: "Synthetic actinide, forms Np³⁺, Np⁴⁺, Np⁵⁺, and Np⁶⁺ ions. First transuranium element discovered. Radioactive. Used in neutron detection. Named after Neptune.",
              physicsInfo: "Electron configuration: [Rn] 5f⁴ 6d¹ 7s². No stable isotopes. Most stable: ²³⁷Np (half-life 2.1 million years). Atomic mass: 237 u. Shells: 2, 8, 18, 32, 22, 9, 2.",
              spectralLines: [{ wavelength: 500.0, intensity: 0.4, transition: "5f→7s" }]},
            { symbol: "Pu", name: "Plutonium", atomicNumber: 94, category: "actinide", row: 9, col: 8,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, used in nuclear weapons and spacecraft power.",
              chemistryInfo: "Synthetic actinide, forms Pu³⁺, Pu⁴⁺, Pu⁵⁺, and Pu⁶⁺ ions. Used in nuclear weapons and spacecraft power (RTGs). Extremely toxic. Warm to touch due to radioactivity. Named after Pluto.",
              physicsInfo: "Electron configuration: [Rn] 5f⁶ 7s². No stable isotopes. Most common: ²³⁹Pu (half-life 24,110 years). Atomic mass: 244 u. Shells: 2, 8, 18, 32, 24, 8, 2.",
              spectralLines: [{ wavelength: 510.0, intensity: 0.4, transition: "5f→7s" }]},
            { symbol: "Am", name: "Americium", atomicNumber: 95, category: "actinide", row: 9, col: 9,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, used in smoke detectors.",
              chemistryInfo: "Synthetic actinide, forms Am³⁺ and Am⁴⁺ ions. Used in smoke detectors (²⁴¹Am). Radioactive. Glows in the dark. Named after the Americas.",
              physicsInfo: "Electron configuration: [Rn] 5f⁷ 7s². No stable isotopes. Most stable: ²⁴³Am (half-life 7,370 years). Atomic mass: 243 u. Shells: 2, 8, 18, 32, 25, 8, 2.",
              spectralLines: [{ wavelength: 520.0, intensity: 0.4, transition: "5f→7s" }]},
            { symbol: "Cm", name: "Curium", atomicNumber: 96, category: "actinide", row: 9, col: 10,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Marie and Pierre Curie.",
              chemistryInfo: "Synthetic actinide, forms Cm³⁺ and Cm⁴⁺ ions. Named after Marie and Pierre Curie. Radioactive. Glows purple in the dark. Used in space missions as heat source.",
              physicsInfo: "Electron configuration: [Rn] 5f⁷ 6d¹ 7s². No stable isotopes. Most stable: ²⁴⁷Cm (half-life 15.6 million years). Atomic mass: 247 u. Shells: 2, 8, 18, 32, 25, 9, 2.",
              spectralLines: [{ wavelength: 530.0, intensity: 0.4, transition: "5f→7s" }]},
            { symbol: "Bk", name: "Berkelium", atomicNumber: 97, category: "actinide", row: 9, col: 11,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Berkeley, California.",
              chemistryInfo: "Synthetic actinide, forms Bk³⁺ and Bk⁴⁺ ions. Named after Berkeley, California. Radioactive. No practical applications. Produced in nuclear reactors.",
              physicsInfo: "Electron configuration: [Rn] 5f⁹ 7s². No stable isotopes. Most stable: ²⁴⁷Bk (half-life 1,380 years). Atomic mass: 247 u. Shells: 2, 8, 18, 32, 27, 8, 2.",
              spectralLines: [{ wavelength: 540.0, intensity: 0.3, transition: "5f→7s" }]},
            { symbol: "Cf", name: "Californium", atomicNumber: 98, category: "actinide", row: 9, col: 12,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after California.",
              chemistryInfo: "Synthetic actinide, forms Cf³⁺ and Cf⁴⁺ ions. Named after California. Powerful neutron emitter used in cancer treatment and oil well logging. Extremely expensive.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁰ 7s². No stable isotopes. Most stable: ²⁵¹Cf (half-life 898 years). Atomic mass: 251 u. Shells: 2, 8, 18, 32, 28, 8, 2.",
              spectralLines: [{ wavelength: 550.0, intensity: 0.3, transition: "5f→7s" }]},
            { symbol: "Es", name: "Einsteinium", atomicNumber: 99, category: "actinide", row: 9, col: 13,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Albert Einstein.",
              chemistryInfo: "Synthetic actinide, forms Es³⁺ ions. Named after Albert Einstein. Radioactive. Discovered in debris from first hydrogen bomb test. No practical applications.",
              physicsInfo: "Electron configuration: [Rn] 5f¹¹ 7s². No stable isotopes. Most stable: ²⁵²Es (half-life 471.7 days). Atomic mass: 252 u. Shells: 2, 8, 18, 32, 29, 8, 2.",
              spectralLines: [{ wavelength: 560.0, intensity: 0.3, transition: "5f→7s" }]},
            { symbol: "Fm", name: "Fermium", atomicNumber: 100, category: "actinide", row: 9, col: 14,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Enrico Fermi.",
              chemistryInfo: "Synthetic actinide, forms Fm³⁺ ions. Named after Enrico Fermi. Radioactive. Discovered in debris from first hydrogen bomb test. No practical applications.",
              physicsInfo: "Electron configuration: [Rn] 5f¹² 7s². No stable isotopes. Most stable: ²⁵⁷Fm (half-life 100.5 days). Atomic mass: 257 u. Shells: 2, 8, 18, 32, 30, 8, 2.",
              spectralLines: [{ wavelength: 570.0, intensity: 0.3, transition: "5f→7s" }]},
            { symbol: "Md", name: "Mendelevium", atomicNumber: 101, category: "actinide", row: 9, col: 15,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Dmitri Mendeleev.",
              chemistryInfo: "Synthetic actinide, forms Md²⁺ and Md³⁺ ions. Named after Dmitri Mendeleev, creator of the periodic table. Radioactive. No practical applications.",
              physicsInfo: "Electron configuration: [Rn] 5f¹³ 7s². No stable isotopes. Most stable: ²⁵⁸Md (half-life 51.5 days). Atomic mass: 258 u. Shells: 2, 8, 18, 32, 31, 8, 2.",
              spectralLines: [{ wavelength: 580.0, intensity: 0.3, transition: "5f→7s" }]},
            { symbol: "No", name: "Nobelium", atomicNumber: 102, category: "actinide", row: 9, col: 16,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Alfred Nobel.",
              chemistryInfo: "Synthetic actinide, forms No²⁺ and No³⁺ ions. Named after Alfred Nobel. Radioactive. No practical applications. Only produced a few atoms at a time.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 7s². No stable isotopes. Most stable: ²⁵⁹No (half-life 58 minutes). Atomic mass: 259 u. Shells: 2, 8, 18, 32, 32, 8, 2.",
              spectralLines: [{ wavelength: 590.0, intensity: 0.3, transition: "7p→7s" }]},
            { symbol: "Lr", name: "Lawrencium", atomicNumber: 103, category: "actinide", row: 9, col: 17,
              cosmicOrigin: "Synthetic", originColor: "#808080",
              astronomyInfo: "Synthetic element, named after Ernest Lawrence.",
              chemistryInfo: "Synthetic actinide, forms Lr³⁺ ions. Named after Ernest Lawrence, inventor of the cyclotron. Radioactive. Last actinide. No practical applications.",
              physicsInfo: "Electron configuration: [Rn] 5f¹⁴ 7s² 7p¹. No stable isotopes. Most stable: ²⁶²Lr (half-life 3.6 hours). Atomic mass: 262 u. Shells: 2, 8, 18, 32, 32, 8, 3.",
              spectralLines: [{ wavelength: 600.0, intensity: 0.3, transition: "7p→7s" }]}
        ]};

        const ELEMENT_LAYOUT = {
            "H": { row: 1, column: 1 }, "He": { row: 1, column: 18 },
            "Li": { row: 2, column: 1 }, "Be": { row: 2, column: 2 }, "B": { row: 2, column: 13 }, "C": { row: 2, column: 14 },
            "N": { row: 2, column: 15 }, "O": { row: 2, column: 16 }, "F": { row: 2, column: 17 }, "Ne": { row: 2, column: 18 },
            "Na": { row: 3, column: 1 }, "Mg": { row: 3, column: 2 }, "Al": { row: 3, column: 13 }, "Si": { row: 3, column: 14 },
            "P": { row: 3, column: 15 }, "S": { row: 3, column: 16 }, "Cl": { row: 3, column: 17 }, "Ar": { row: 3, column: 18 },
            "K": { row: 4, column: 1 }, "Ca": { row: 4, column: 2 }, "Sc": { row: 4, column: 3 }, "Ti": { row: 4, column: 4 },
            "V": { row: 4, column: 5 }, "Cr": { row: 4, column: 6 }, "Mn": { row: 4, column: 7 }, "Fe": { row: 4, column: 8 },
            "Co": { row: 4, column: 9 }, "Ni": { row: 4, column: 10 }, "Cu": { row: 4, column: 11 }, "Zn": { row: 4, column: 12 },
            "Ga": { row: 4, column: 13 }, "Ge": { row: 4, column: 14 }, "As": { row: 4, column: 15 }, "Se": { row: 4, column: 16 },
            "Br": { row: 4, column: 17 }, "Kr": { row: 4, column: 18 },
            "Rb": { row: 5, column: 1 }, "Sr": { row: 5, column: 2 }, "Y": { row: 5, column: 3 }, "Zr": { row: 5, column: 4 },
            "Nb": { row: 5, column: 5 }, "Mo": { row: 5, column: 6 }, "Tc": { row: 5, column: 7 }, "Ru": { row: 5, column: 8 },
            "Rh": { row: 5, column: 9 }, "Pd": { row: 5, column: 10 }, "Ag": { row: 5, column: 11 }, "Cd": { row: 5, column: 12 },
            "In": { row: 5, column: 13 }, "Sn": { row: 5, column: 14 }, "Sb": { row: 5, column: 15 }, "Te": { row: 5, column: 16 },
            "I": { row: 5, column: 17 }, "Xe": { row: 5, column: 18 },
            "Cs": { row: 6, column: 1 }, "Ba": { row: 6, column: 2 }, "La": { row: 8, column: 3 }, "Hf": { row: 6, column: 4 },
            "Ta": { row: 6, column: 5 }, "W": { row: 6, column: 6 }, "Re": { row: 6, column: 7 }, "Os": { row: 6, column: 8 },
            "Ir": { row: 6, column: 9 }, "Pt": { row: 6, column: 10 }, "Au": { row: 6, column: 11 }, "Hg": { row: 6, column: 12 },
            "Tl": { row: 6, column: 13 }, "Pb": { row: 6, column: 14 }, "Bi": { row: 6, column: 15 }, "Po": { row: 6, column: 16 },
            "At": { row: 6, column: 17 }, "Rn": { row: 6, column: 18 },
            "Fr": { row: 7, column: 1 }, "Ra": { row: 7, column: 2 }, "Ac": { row: 9, column: 3 }, "Rf": { row: 7, column: 4 },
            "Db": { row: 7, column: 5 }, "Sg": { row: 7, column: 6 }, "Bh": { row: 7, column: 7 }, "Hs": { row: 7, column: 8 },
            "Mt": { row: 7, column: 9 }, "Ds": { row: 7, column: 10 }, "Rg": { row: 7, column: 11 }, "Cn": { row: 7, column: 12 },
            "Nh": { row: 7, column: 13 }, "Fl": { row: 7, column: 14 }, "Mc": { row: 7, column: 15 }, "Lv": { row: 7, column: 16 },
            "Ts": { row: 7, column: 17 }, "Og": { row: 7, column: 18 },
            // Lanthanides
            "Ce": { row: 8, column: 4 }, "Pr": { row: 8, column: 5 }, "Nd": { row: 8, column: 6 }, "Pm": { row: 8, column: 7 },
            "Sm": { row: 8, column: 8 }, "Eu": { row: 8, column: 9 }, "Gd": { row: 8, column: 10 }, "Tb": { row: 8, column: 11 },
            "Dy": { row: 8, column: 12 }, "Ho": { row: 8, column: 13 }, "Er": { row: 8, column: 14 }, "Tm": { row: 8, column: 15 },
            "Yb": { row: 8, column: 16 }, "Lu": { row: 8, column: 17 },
            // Actinides
            "Th": { row: 9, column: 4 }, "Pa": { row: 9, column: 5 }, "U": { row: 9, column: 6 }, "Np": { row: 9, column: 7 },
            "Pu": { row: 9, column: 8 }, "Am": { row: 9, column: 9 }, "Cm": { row: 9, column: 10 }, "Bk": { row: 9, column: 11 },
            "Cf": { row: 9, column: 12 }, "Es": { row: 9, column: 13 }, "Fm": { row: 9, column: 14 }, "Md": { row: 9, column: 15 },
            "No": { row: 9, column: 16 }, "Lr": { row: 9, column: 17 }
        };

        const ELEMENT_COLORS = {
            "metal": 0x4A90E2, "nonmetal": 0x7ED321, "metalloid": 0xF5A623,
            "noble-gas": 0xBD10E0, "alkali-metal": 0xFF6B6B, "alkaline-earth": 0xFFA07A,
            "transition-metal": 0x87CEEB, "lanthanide": 0xFFD700, "actinide": 0xFF69B4,
            "halogen": 0x50E3C2, "unknown": 0xCCCCCC
        };

        // ================= STUDENT EDITION DATA & HELPERS =================
        // Edit the school name below to show it in the footer (leave '' to hide)
        const STUDENT_INFO = { name: 'Nithyasri K', role: 'Student', school: '' };

        const CATEGORY_INFO = {
            "alkali-metal": { label: "Alkali Metals", desc: "Soft, shiny, very reactive metals with 1 outer electron. They fizz or explode in water (Li, Na, K...)." },
            "alkaline-earth": { label: "Alkaline Earth Metals", desc: "Group 2 metals with 2 outer electrons. Harder and less reactive than alkali metals. Calcium is in your bones, magnesium in sparklers." },
            "transition-metal": { label: "Transition Metals", desc: "Strong, shiny metals in the middle block. Good conductors, they form coloured compounds and ions with different charges (iron, copper, gold)." },
            "metal": { label: "Post-Transition Metals", desc: "Softer metals with lower melting points, like aluminium, tin and lead. They sit to the right of the transition metals." },
            "metalloid": { label: "Metalloids", desc: "Between metals and non-metals. Silicon, a metalloid, is the heart of computer chips (a semiconductor)." },
            "nonmetal": { label: "Non-metals", desc: "Mostly gases or brittle solids that do not conduct electricity. Hydrogen, carbon, nitrogen, oxygen... the building blocks of life." },
            "halogen": { label: "Halogens", desc: "Group 17: very reactive non-metals with 7 outer electrons. They make salts with metals (like NaCl)." },
            "noble-gas": { label: "Noble Gases", desc: "Group 18: gases with a full outer shell. They are very unreactive and glow in lamps and signs." },
            "lanthanide": { label: "Lanthanides", desc: "'Rare earth' metals from the bottom block. Used in strong magnets, lasers and phone screens." },
            "actinide": { label: "Actinides", desc: "Radioactive metals in the bottom row, including uranium and plutonium." }
        };

        const MASS_NUMBERS = [null,1,4,7,9,11,12,14,16,19,20,23,24,27,28,31,32,35,40,39,40,45,48,51,52,55,56,59,58,63,64,69,74,75,80,79,84,85,88,89,90,93,98,99,102,103,106,107,114,115,120,121,130,127,132,133,138,139,140,141,142,145,152,153,158,159,164,165,166,169,174,175,180,181,184,187,192,193,195,197,202,205,208,209,209,210,222,223,226,227,232,231,238,237,244,243,247,247,251,252,257,258,259,262,267,268,269,270,270,278,281,282,285,286,289,290,293,294,294];

        const ATOMIC_MASS = [null,1.008,4.003,6.94,9.012,10.81,12.011,14.007,15.999,18.998,20.180,22.990,24.305,26.982,28.085,30.974,32.06,35.45,39.948,39.098,40.078,44.956,47.867,50.942,51.996,54.938,55.845,58.933,58.693,63.546,65.38,69.723,72.630,74.922,78.971,79.904,83.798,85.468,87.62,88.906,91.224,92.906,95.95,98,101.07,102.91,106.42,107.87,112.41,114.82,118.71,121.76,127.60,126.90,131.29,132.91,137.33,138.91,140.12,140.91,144.24,145,150.36,151.96,157.25,158.93,162.50,164.93,167.26,168.93,173.05,174.97,178.49,180.95,183.84,186.21,190.23,192.22,195.08,196.97,200.59,204.38,207.2,208.98,209,210,222,223,226,227,232.04,231.04,238.03,237,244,243,247,247,251,252,257,258,259,262,267,268,269,270,270,278,281,282,285,286,289,290,293,294,294];

        // Electron shells: fill by the Madelung rule, with the well-known exceptions listed explicitly
        function computeShells(z) {
            const exc = {
                24: [2,8,13,1], 29: [2,8,18,1], 41: [2,8,18,12,1], 42: [2,8,18,13,1], 44: [2,8,18,15,1],
                45: [2,8,18,16,1], 46: [2,8,18,18], 47: [2,8,18,18,1], 57: [2,8,18,18,9,2], 58: [2,8,18,19,9,2],
                64: [2,8,18,25,9,2], 78: [2,8,18,32,17,1], 79: [2,8,18,32,18,1], 89: [2,8,18,32,18,9,2],
                90: [2,8,18,32,18,10,2], 91: [2,8,18,32,20,9,2], 92: [2,8,18,32,21,9,2], 93: [2,8,18,32,22,9,2],
                96: [2,8,18,32,25,9,2], 103: [2,8,18,32,32,8,3]
            };
            if (exc[z]) return exc[z];
            const order = [[1,0],[2,0],[2,1],[3,0],[3,1],[4,0],[3,2],[4,1],[5,0],[4,2],[5,1],[6,0],[4,3],[5,2],[6,1],[7,0],[5,3],[6,2],[7,1]];
            let rem = z; const sh = [];
            for (const [n, l] of order) {
                if (rem <= 0) break;
                const e = Math.min(rem, 2 * (2 * l + 1));
                sh[n - 1] = (sh[n - 1] || 0) + e;
                rem -= e;
            }
            return sh;
        }

        // Bond example builders: I = ionic, C = covalent, D = coordinate (dative) covalent
        const I = (f, nm, c, cc, a, ac, nc, na) => ['i', f, nm, [c, cc, a, ac, nc, na]];
        const C = (f, nm, ce, p, n, o) => ['c', f, nm, [ce, p, n, o]];
        const D = (f, nm, d, a, r) => ['d', f, nm, [d, a, r]];
        const NO = ['n'];
        const UN = ['x'];
        const SYN = "Only a few atoms have ever been made in a laboratory, so it is used only for scientific research.";

        // mp / bp in °C (null = unknown), f = interesting fact, u = uses, c = common chemicals, b = bond example, n = note
        const STUDENT_DATA = {
            H: { mp: -259, bp: -253, f: "Hydrogen is the lightest element and fuels the Sun. Its atom is just one proton and one electron!", u: "Rocket fuel, making ammonia for fertilizers, fuel cells.", c: "H₂O (water), HCl (hydrochloric acid), CH₄ (methane)", b: C("H₂O", "Water", "O", "H", 2, 1) },
            He: { mp: -272, bp: -269, n: "Helium only freezes under very high pressure.", f: "Helium makes your voice squeaky and is lighter than air, but it never catches fire.", u: "Party balloons, cooling MRI scanners, airships, deep-sea diving mixes.", c: "None – helium does not form compounds", b: NO },
            Li: { mp: 181, bp: 1342, f: "Lithium is so light it floats on water (and fizzes!).", u: "Rechargeable batteries in phones and laptops, some medicines.", c: "Li₂CO₃ (lithium carbonate), LiCl", b: I("LiCl", "Lithium chloride", "Li", 1, "Cl", 1, 1, 1) },
            Be: { mp: 1287, bp: 2470, f: "Gemstones like emerald and aquamarine owe their form to beryllium.", u: "Aircraft and spacecraft parts, X-ray windows.", c: "BeO (beryllium oxide), BeCl₂", b: I("BeO", "Beryllium oxide", "Be", 2, "O", 2, 1, 1) },
            B: { mp: 2076, bp: 3927, f: "Boron compounds give green colour to fireworks and make strong heat-proof glass.", u: "Pyrex glass, detergents (borax), plant fertilizer.", c: "Na₂B₄O₇ (borax), H₃BO₃ (boric acid)", b: C("BF₃", "Boron trifluoride", "B", "F", 3, 1) },
            C: { mp: 3550, bp: 4027, f: "All living things contain carbon. Diamond and pencil 'lead' (graphite) are both pure carbon!", u: "Fuel (coal, charcoal), steel making, pencils, diamonds, fizzy drinks.", c: "CO₂ (carbon dioxide), CH₄ (methane), C₆H₁₂O₆ (glucose), CaCO₃ (chalk)", b: C("CO₂", "Carbon dioxide", "C", "O", 2, 2) },
            N: { mp: -210, bp: -196, f: "78% of the air you breathe is nitrogen. Liquid nitrogen is so cold it freezes a flower so it shatters!", u: "Fertilizers, food packaging, freezing food, filling tyres.", c: "NH₃ (ammonia), HNO₃ (nitric acid), KNO₃ (saltpetre)", b: D("NH₄⁺", "Ammonium ion", "NH₃", "H⁺", "NH₄⁺") },
            O: { mp: -219, bp: -183, f: "Oxygen makes up about half of the Earth's crust and is needed for burning and breathing.", u: "Breathing, hospitals, welding, steel making.", c: "H₂O (water), CO₂, O₃ (ozone), Fe₂O₃ (rust)", b: C("H₂O", "Water", "O", "H", 2, 1) },
            F: { mp: -220, bp: -188, f: "Fluorine is the most reactive element of all. A tiny amount in toothpaste protects your teeth.", u: "Toothpaste (fluoride), non-stick Teflon pans.", c: "NaF (sodium fluoride), CaF₂, HF", b: I("NaF", "Sodium fluoride", "Na", 1, "F", 1, 1, 1) },
            Ne: { mp: -249, bp: -246, f: "Neon lights glow bright red-orange when electricity passes through the gas.", u: "Advertising signs, lasers.", c: "None – neon does not form compounds", b: NO },
            Na: { mp: 98, bp: 883, f: "Sodium is a soft metal you can cut with a knife and it explodes in water, yet it is half of table salt!", u: "Table salt, street lamps, baking soda, soap.", c: "NaCl (table salt), NaHCO₃ (baking soda), NaOH (caustic soda)", b: I("NaCl", "Sodium chloride (table salt)", "Na", 1, "Cl", 1, 1, 1) },
            Mg: { mp: 650, bp: 1090, f: "Burning magnesium makes a dazzling white light – used in sparklers and old camera flashes.", u: "Light alloys, fireworks, medicine for acidity (milk of magnesia).", c: "MgO, Mg(OH)₂ (milk of magnesia), MgSO₄ (Epsom salt)", b: I("MgO", "Magnesium oxide", "Mg", 2, "O", 2, 1, 1) },
            Al: { mp: 660, bp: 2519, f: "Aluminium is the most common metal in Earth's crust and can be recycled again and again.", u: "Drink cans, foil, aeroplanes, utensils, window frames.", c: "Al₂O₃ (alumina), alum (used to clean water), AlCl₃", b: I("Al₂O₃", "Aluminium oxide", "Al", 3, "O", 2, 2, 3) },
            Si: { mp: 1414, bp: 3265, f: "Sand is mostly silicon dioxide, and silicon chips run every computer and phone.", u: "Computer chips, glass, solar cells, cement.", c: "SiO₂ (sand, quartz), silicones", b: C("SiCl₄", "Silicon tetrachloride", "Si", "Cl", 4, 1) },
            P: { mp: 44, bp: 277, n: "Values are for white phosphorus.", f: "Phosphorus on matchsticks helps them light. Your DNA and bones contain phosphorus.", u: "Matches, fertilizers, detergents, cola drinks (phosphoric acid).", c: "H₃PO₄ (phosphoric acid), Ca₃(PO₄)₂ (in bones)", b: C("PCl₃", "Phosphorus trichloride", "P", "Cl", 3, 1) },
            S: { mp: 115, bp: 445, f: "Sulfur gives rotten eggs their smell, and volcanoes have bright yellow sulfur crystals.", u: "Making sulfuric acid, gunpowder, hardening rubber, matches.", c: "H₂SO₄ (sulfuric acid), SO₂, H₂S", b: C("H₂S", "Hydrogen sulfide", "S", "H", 2, 1) },
            Cl: { mp: -102, bp: -34, f: "Chlorine kills germs in swimming pools and drinking water.", u: "Water purification, bleach, PVC pipes.", c: "NaCl (table salt), HCl, NaOCl (bleach)", b: C("Cl₂", "Chlorine gas", "Cl", "Cl", 1, 1) },
            Ar: { mp: -189, bp: -186, f: "Argon fills light bulbs so the hot filament does not burn up.", u: "Light bulbs, welding.", c: "None – argon does not form compounds", b: NO },
            K: { mp: 63, bp: 759, f: "Potassium is in bananas and helps your nerves and muscles work.", u: "Fertilizers, soap, salt substitute.", c: "KCl, KNO₃ (saltpetre), KOH", b: I("KCl", "Potassium chloride", "K", 1, "Cl", 1, 1, 1) },
            Ca: { mp: 842, bp: 1484, f: "Calcium builds your bones and teeth. Seashells and chalk are calcium carbonate.", u: "Bones and teeth, cement, chalk, antacids.", c: "CaCO₃ (limestone, chalk), CaO (quicklime), CaSO₄ (plaster of Paris)", b: I("CaCl₂", "Calcium chloride", "Ca", 2, "Cl", 1, 1, 2) },
            Sc: { mp: 1541, bp: 2836, f: "Scandium is rare, but a pinch makes aluminium much stronger.", u: "Sports equipment, stadium lights.", c: "Sc₂O₃", b: I("Sc₂O₃", "Scandium oxide", "Sc", 3, "O", 2, 2, 3) },
            Ti: { mp: 1668, bp: 3287, f: "Titanium is as strong as steel but much lighter and never rusts. Hip replacements use it.", u: "Aeroplanes, spectacle frames, joint implants.", c: "TiO₂ (white paint, sunscreen)", b: I("TiO₂", "Titanium dioxide", "Ti", 4, "O", 2, 1, 2) },
            V: { mp: 1910, bp: 3407, f: "Vanadium makes steel tough – good for spanners and springs.", u: "Tools, springs, steel alloys.", c: "V₂O₅ (catalyst for making sulfuric acid)", b: I("V₂O₅", "Vanadium pentoxide", "V", 5, "O", 2, 2, 5) },
            Cr: { mp: 1907, bp: 2671, f: "Chromium makes the shiny 'chrome' on bikes and is added to make stainless steel.", u: "Stainless steel, chrome plating, leather tanning.", c: "Cr₂O₃ (green pigment), K₂Cr₂O₇", b: I("Cr₂O₃", "Chromium(III) oxide", "Cr", 3, "O", 2, 2, 3) },
            Mn: { mp: 1246, bp: 2061, f: "Manganese makes steel hard and is inside many dry-cell batteries.", u: "Steel, batteries.", c: "MnO₂ (in batteries), KMnO₄ (purple disinfectant)", b: I("MnO₂", "Manganese dioxide", "Mn", 4, "O", 2, 1, 2) },
            Fe: { mp: 1538, bp: 2861, f: "Iron is in your blood, where it carries oxygen. Rust is iron + oxygen + water.", u: "Buildings, bridges, cars, tools, utensils.", c: "Fe₂O₃ (rust), Fe₃O₄, FeSO₄ (iron tablets)", b: I("Fe₂O₃", "Iron(III) oxide (rust)", "Fe", 3, "O", 2, 2, 3) },
            Co: { mp: 1495, bp: 2927, f: "Cobalt gives the deep blue colour to glass and pottery.", u: "Batteries, blue pigments, strong magnets.", c: "CoCl₂ (changes colour with moisture)", b: I("CoCl₂", "Cobalt chloride", "Co", 2, "Cl", 1, 1, 2) },
            Ni: { mp: 1455, bp: 2913, f: "Nickel is used in coins. Some people are allergic to it in cheap jewellery.", u: "Coins, stainless steel, batteries.", c: "NiO, NiSO₄", b: I("NiO", "Nickel oxide", "Ni", 2, "O", 2, 1, 1) },
            Cu: { mp: 1085, bp: 2562, f: "Copper is a great conductor, so it is used in electric wires. The green Statue of Liberty is copper that has 'rusted'.", u: "Electric wires, utensils, coins, water pipes.", c: "CuSO₄ (blue vitriol / 'neela thotha'), CuO, Cu₂O", b: D("[Cu(NH₃)₄]²⁺", "Deep-blue copper complex ion", "NH₃", "Cu²⁺", "[Cu(NH₃)₄]²⁺") },
            Zn: { mp: 420, bp: 907, f: "Zinc coats iron sheets to stop rust (galvanising) and helps your wounds heal.", u: "Galvanised roofs, batteries, sunscreen, medicines.", c: "ZnO (calamine lotion), ZnSO₄", b: I("ZnO", "Zinc oxide", "Zn", 2, "O", 2, 1, 1) },
            Ga: { mp: 30, bp: 2204, f: "Gallium melts in your hand – it is a metal that turns liquid at about 30 °C!", u: "LEDs, mobile phone chips.", c: "GaAs (gallium arsenide), Ga₂O₃", b: I("Ga₂O₃", "Gallium oxide", "Ga", 3, "O", 2, 2, 3) },
            Ge: { mp: 938, bp: 2833, f: "Mendeleev predicted germanium before it was discovered.", u: "Early transistors, fibre optics, infrared lenses.", c: "GeO₂", b: C("GeO₂", "Germanium dioxide", "Ge", "O", 2, 2) },
            As: { mp: 817, bp: 614, n: "Arsenic turns straight from solid to gas (sublimes) at 614 °C and melts only under pressure.", f: "Arsenic is a famous poison, yet tiny amounts are used in electronics.", u: "Semiconductors, wood preservatives.", c: "As₂O₃, AsH₃ (arsine, poisonous gas)", b: C("AsH₃", "Arsine", "As", "H", 3, 1) },
            Se: { mp: 221, bp: 685, f: "Selenium is needed in tiny amounts by your body. Brazil nuts are rich in it.", u: "Photocopiers, glass making, dandruff shampoo.", c: "SeO₂, H₂Se", b: C("H₂Se", "Hydrogen selenide", "Se", "H", 2, 1) },
            Br: { mp: -7, bp: 59, f: "Bromine is one of only two elements that are liquid at room temperature (the other is mercury).", u: "Fire retardants, photography, medicines.", c: "NaBr, HBr, AgBr (in old photo film)", b: C("Br₂", "Bromine", "Br", "Br", 1, 1) },
            Kr: { mp: -157, bp: -153, f: "Krypton is the name of Superman's home planet!", u: "Camera flash lamps, lasers.", c: "None – krypton hardly forms compounds", b: NO },
            Rb: { mp: 39, bp: 688, f: "Rubidium is named from the Latin 'rubidus' = deep red, after its red spectrum lines.", u: "Atomic clocks, research.", c: "RbCl, Rb₂CO₃", b: I("RbCl", "Rubidium chloride", "Rb", 1, "Cl", 1, 1, 1) },
            Sr: { mp: 777, bp: 1377, f: "Strontium makes fireworks glow bright crimson red.", u: "Red fireworks and signal flares.", c: "SrCO₃, Sr(NO₃)₂", b: I("SrCl₂", "Strontium chloride", "Sr", 2, "Cl", 1, 1, 2) },
            Y: { mp: 1526, bp: 2931, f: "Yttrium is named after the village of Ytterby in Sweden, which also gave names to three other elements.", u: "LED lights, TV and screen colours.", c: "Y₂O₃", b: I("Y₂O₃", "Yttrium oxide", "Y", 3, "O", 2, 2, 3) },
            Zr: { mp: 1855, bp: 4409, f: "Cubic zirconia, the diamond lookalike, is made from zirconium oxide.", u: "Nuclear reactor tubes, artificial gems, ceramics.", c: "ZrO₂ (cubic zirconia)", b: I("ZrO₂", "Zirconium dioxide", "Zr", 4, "O", 2, 1, 2) },
            Nb: { mp: 2477, bp: 4744, f: "Niobium is used in the super-strong magnets inside MRI machines.", u: "MRI magnets, jet engines, steel.", c: "Nb₂O₅", b: I("Nb₂O₅", "Niobium pentoxide", "Nb", 5, "O", 2, 2, 5) },
            Mo: { mp: 2623, bp: 4639, f: "Molybdenum helps bacteria turn nitrogen from air into plant food.", u: "Strong steel alloys, lubricants.", c: "MoS₂ (slippery lubricant)", b: C("MoS₂", "Molybdenum disulfide", "Mo", "S", 2, 2) },
            Tc: { mp: 2157, bp: 4265, f: "Technetium was the first element ever made artificially by humans (1937).", u: "Hospital scans of organs (as a tiny radioactive tracer).", c: "Technetium-99m compounds used in medicine", b: UN },
            Ru: { mp: 2334, bp: 4150, f: "Ruthenium is named after Russia (Latin: Ruthenia).", u: "Hard electrical contacts, chemical catalysts.", c: "RuO₂", b: I("RuO₂", "Ruthenium dioxide", "Ru", 4, "O", 2, 1, 2) },
            Rh: { mp: 1964, bp: 3695, f: "Rhodium is one of the most expensive metals on Earth.", u: "Car exhaust cleaners (catalytic converters), shiny jewellery plating.", c: "RhCl₃", b: I("RhCl₃", "Rhodium chloride", "Rh", 3, "Cl", 1, 1, 3) },
            Pd: { mp: 1555, bp: 2963, f: "Palladium can soak up about 900 times its own volume of hydrogen gas.", u: "Car exhaust cleaners, electronics, jewellery.", c: "PdCl₂", b: I("PdCl₂", "Palladium chloride", "Pd", 2, "Cl", 1, 1, 2) },
            Ag: { mp: 962, bp: 2162, f: "Silver conducts electricity better than any other metal and kills germs.", u: "Jewellery, coins, mirrors, photography, electronics.", c: "AgNO₃ (silver nitrate), AgCl, Ag₂S (black tarnish)", b: I("AgCl", "Silver chloride", "Ag", 1, "Cl", 1, 1, 1) },
            Cd: { mp: 321, bp: 767, f: "Cadmium is toxic; old rechargeable Ni-Cd batteries used it.", u: "Batteries, yellow paint pigment.", c: "CdS (yellow pigment)", b: I("CdS", "Cadmium sulfide", "Cd", 2, "S", 2, 1, 1) },
            In: { mp: 157, bp: 2072, f: "Indium is named after its bright indigo spectrum line.", u: "Touchscreens, solar cells.", c: "In₂O₃ (in touchscreen coating)", b: I("In₂O₃", "Indium oxide", "In", 3, "O", 2, 2, 3) },
            Sn: { mp: 232, bp: 2602, f: "Tin mixed with copper makes bronze – used since ancient times.", u: "Tin cans, solder, bronze.", c: "SnO₂, SnCl₂", b: I("SnO₂", "Tin dioxide", "Sn", 4, "O", 2, 1, 2) },
            Sb: { mp: 631, bp: 1587, f: "Ancient Egyptians used antimony compounds as eye make-up (kohl).", u: "Flame-proofing, batteries, alloys.", c: "Sb₂O₃, SbCl₃", b: C("SbCl₃", "Antimony trichloride", "Sb", "Cl", 3, 1) },
            Te: { mp: 450, bp: 988, f: "Tellurium is named after the Earth (Latin: tellus).", u: "Solar panels, rewritable discs.", c: "TeO₂, H₂Te", b: C("H₂Te", "Hydrogen telluride", "Te", "H", 2, 1) },
            I: { mp: 114, bp: 184, f: "Iodine prevents goitre, which is why salt is 'iodised'. Its vapour is violet.", u: "Iodised salt, antiseptic (tincture iodine), medicines.", c: "KI, NaI, I₂ in antiseptic", b: C("I₂", "Iodine", "I", "I", 1, 1) },
            Xe: { mp: -112, bp: -108, f: "Xenon makes very bright car headlights (xenon lamps).", u: "Headlamps, flash lamps, ion engines, anaesthetic.", c: "XeF₄ – one of the few noble-gas compounds", b: C("XeF₄", "Xenon tetrafluoride", "Xe", "F", 4, 1) },
            Cs: { mp: 28, bp: 671, f: "Caesium atomic clocks define the length of one second.", u: "Atomic clocks, drilling fluids.", c: "CsCl, CsOH", b: I("CsCl", "Caesium chloride", "Cs", 1, "Cl", 1, 1, 1) },
            Ba: { mp: 727, bp: 1845, f: "Barium makes green fireworks. A 'barium meal' helps doctors see your stomach in X-rays.", u: "X-ray 'barium meal', green fireworks, glass.", c: "BaSO₄ (barium meal), BaCl₂", b: I("BaCl₂", "Barium chloride", "Ba", 2, "Cl", 1, 1, 2) },
            La: { mp: 920, bp: 3464, f: "Lanthanum is used in hybrid-car batteries and camera lenses.", u: "Camera lenses, hybrid-car batteries.", c: "La₂O₃", b: I("La₂O₃", "Lanthanum oxide", "La", 3, "O", 2, 2, 3) },
            Ce: { mp: 798, bp: 3443, f: "Cerium is the most common 'rare earth' and makes sparks when scratched – found in lighter flints.", u: "Lighter flints, self-cleaning ovens, glass polishing.", c: "CeO₂", b: I("CeO₂", "Cerium dioxide", "Ce", 4, "O", 2, 1, 2) },
            Pr: { mp: 931, bp: 3520, f: "Praseodymium makes glass yellow-green and is used in welders' goggles.", u: "Welding goggles, strong magnets.", c: "Pr₂O₃", b: I("Pr₂O₃", "Praseodymium oxide", "Pr", 3, "O", 2, 2, 3) },
            Nd: { mp: 1021, bp: 3074, f: "Neodymium makes the strongest permanent magnets – inside earphones and headphones.", u: "Magnets in headphones, electric-car motors, wind turbines.", c: "Nd₂O₃", b: I("Nd₂O₃", "Neodymium oxide", "Nd", 3, "O", 2, 2, 3) },
            Pm: { mp: 1100, bp: 3000, n: "Approximate values.", f: "Promethium is named after Prometheus, who stole fire from the gods. It has no stable form.", u: "Glow-in-the-dark paint (old), tiny nuclear batteries.", c: "Pm₂O₃", b: I("Pm₂O₃", "Promethium oxide", "Pm", 3, "O", 2, 2, 3) },
            Sm: { mp: 1072, bp: 1794, f: "Samarium is used in strong magnets and a cancer-pain medicine.", u: "Magnets, cancer treatment.", c: "Sm₂O₃", b: I("Sm₂O₃", "Samarium oxide", "Sm", 3, "O", 2, 2, 3) },
            Eu: { mp: 822, bp: 1596, f: "Europium glows under UV light and helps stop fake euro banknotes.", u: "Banknote security ink, red colour in TV screens.", c: "Eu₂O₃", b: I("Eu₂O₃", "Europium oxide", "Eu", 3, "O", 2, 2, 3) },
            Gd: { mp: 1313, bp: 3273, f: "Gadolinium helps doctors get clear MRI scans.", u: "MRI contrast agent, nuclear reactors.", c: "Gd₂O₃", b: I("Gd₂O₃", "Gadolinium oxide", "Gd", 3, "O", 2, 2, 3) },
            Tb: { mp: 1356, bp: 3230, f: "Terbium makes the green colour in old TV screens and energy-saving lamps.", u: "Green phosphors, lamps.", c: "Tb₂O₃", b: I("Tb₂O₃", "Terbium oxide", "Tb", 3, "O", 2, 2, 3) },
            Dy: { mp: 1412, bp: 2567, f: "Dysprosium's name comes from the Greek for 'hard to get'.", u: "Strong magnets, wind turbines.", c: "Dy₂O₃", b: I("Dy₂O₃", "Dysprosium oxide", "Dy", 3, "O", 2, 2, 3) },
            Ho: { mp: 1474, bp: 2700, f: "Holmium has the strongest magnetic strength of any element.", u: "Surgical lasers, magnets.", c: "Ho₂O₃", b: I("Ho₂O₃", "Holmium oxide", "Ho", 3, "O", 2, 2, 3) },
            Er: { mp: 1529, bp: 2868, f: "Erbium helps internet signals travel through fibre-optic cables.", u: "Fibre-optic amplifiers, pink glass.", c: "Er₂O₃", b: I("Er₂O₃", "Erbium oxide", "Er", 3, "O", 2, 2, 3) },
            Tm: { mp: 1545, bp: 1950, f: "Thulium is one of the rarest of the rare-earth metals.", u: "Portable X-ray machines, lasers.", c: "Tm₂O₃", b: I("Tm₂O₃", "Thulium oxide", "Tm", 3, "O", 2, 2, 3) },
            Yb: { mp: 824, bp: 1196, f: "Ytterbium is used in some of the most accurate atomic clocks.", u: "Atomic clocks, lasers.", c: "Yb₂O₃", b: I("Yb₂O₃", "Ytterbium oxide", "Yb", 3, "O", 2, 2, 3) },
            Lu: { mp: 1663, bp: 3402, f: "Lutetium is the hardest and densest of the rare-earth metals.", u: "PET scanners, cancer treatment.", c: "Lu₂O₃", b: I("Lu₂O₃", "Lutetium oxide", "Lu", 3, "O", 2, 2, 3) },
            Hf: { mp: 2233, bp: 4603, f: "Hafnium is used in computer chips and nuclear reactor control rods.", u: "Computer chips, nuclear reactor control rods.", c: "HfO₂", b: I("HfO₂", "Hafnium dioxide", "Hf", 4, "O", 2, 1, 2) },
            Ta: { mp: 3017, bp: 5458, f: "Tantalum does not react with body fluids and is found inside mobile phones.", u: "Mobile-phone capacitors, surgical implants.", c: "Ta₂O₅", b: I("Ta₂O₅", "Tantalum pentoxide", "Ta", 5, "O", 2, 2, 5) },
            W: { mp: 3422, bp: 5555, f: "Tungsten has the highest melting point of any metal – perfect for bulb filaments.", u: "Old bulb filaments, drill bits, X-ray tubes.", c: "WO₃", b: I("WO₃", "Tungsten trioxide", "W", 6, "O", 2, 1, 3) },
            Re: { mp: 3186, bp: 5596, f: "Rhenium was the last stable element to be discovered in nature (1925).", u: "Jet-engine parts, catalysts.", c: "ReO₂", b: I("ReO₂", "Rhenium dioxide", "Re", 4, "O", 2, 1, 2) },
            Os: { mp: 3033, bp: 5012, f: "Osmium is the densest natural element – a small block feels surprisingly heavy.", u: "Fountain pen tips, electrical contacts.", c: "OsO₄ (very toxic)", b: C("OsO₄", "Osmium tetroxide", "Os", "O", 4, 2) },
            Ir: { mp: 2446, bp: 4428, f: "A thin layer of iridium in rocks is evidence that an asteroid ended the age of dinosaurs.", u: "Spark plugs, pen tips, corrosion-proof parts.", c: "IrO₂", b: I("IrO₂", "Iridium dioxide", "Ir", 4, "O", 2, 1, 2) },
            Pt: { mp: 1768, bp: 3825, f: "Platinum is rarer and more valuable than gold. A platinum compound called cisplatin treats cancer.", u: "Jewellery, car exhaust cleaners, cancer drugs.", c: "Pt(NH₃)₂Cl₂ (cisplatin)", b: D("Pt(NH₃)₂Cl₂", "Cisplatin (cancer drug)", "NH₃", "Pt²⁺", "Pt(NH₃)₂Cl₂") },
            Au: { mp: 1064, bp: 2856, f: "Gold never rusts or tarnishes, so ancient gold looks as shiny as new.", u: "Jewellery, coins, electronics, dentistry.", c: "AuCl₃", b: I("AuCl₃", "Gold(III) chloride", "Au", 3, "Cl", 1, 1, 3) },
            Hg: { mp: -39, bp: 357, f: "Mercury is the only metal that is liquid at room temperature. It is poisonous.", u: "Thermometers (older), fluorescent tubes, dental fillings (older).", c: "HgS (cinnabar ore), HgCl₂", b: I("HgS", "Mercury sulfide", "Hg", 2, "S", 2, 1, 1) },
            Tl: { mp: 304, bp: 1473, f: "Thallium is named after the Greek word for a green shoot, for its bright green spectrum line.", u: "Special glass, infrared detectors, heart scans.", c: "Tl₂SO₄ (very poisonous)", b: I("TlCl", "Thallium chloride", "Tl", 1, "Cl", 1, 1, 1) },
            Pb: { mp: 327, bp: 1749, f: "Pencil 'lead' is really graphite. True lead is poisonous and was removed from petrol and paint.", u: "Car batteries, radiation shields.", c: "PbO, PbSO₄ (car battery), Pb(NO₃)₂", b: I("PbO", "Lead(II) oxide", "Pb", 2, "O", 2, 1, 1) },
            Bi: { mp: 271, bp: 1564, f: "Bismuth forms beautiful rainbow-coloured crystals. Stomach medicines contain it.", u: "Stomach medicines, cosmetics, low-melting alloys.", c: "Bi₂O₃, bismuth subsalicylate", b: I("Bi₂O₃", "Bismuth oxide", "Bi", 3, "O", 2, 2, 3) },
            Po: { mp: 254, bp: 962, f: "Marie Curie discovered polonium and named it after her home country, Poland.", u: "Static-removing brushes, heat source in space probes.", c: "PoO₂ (rare)", b: UN },
            At: { mp: 302, bp: 337, n: "Estimated values – too rare to measure.", f: "Astatine is the rarest naturally occurring element – less than 1 gram exists in Earth's crust at any time.", u: "Being studied for cancer treatment.", c: "None commonly known", b: UN },
            Rn: { mp: -71, bp: -62, f: "Radon is a radioactive gas that can seep up into basements from the ground.", u: "Mostly a hazard; small uses in research.", c: "None commonly known", b: NO },
            Fr: { mp: 27, bp: 677, n: "Estimated values – too rare to measure.", f: "Francium is named after France. It is so unstable that it lasts only about 22 minutes.", u: "Only used in research.", c: "None commonly known", b: UN },
            Ra: { mp: 700, bp: 1737, f: "Radium glowed in the dark and was once used on watch dials – now banned because it is dangerous.", u: "Once used in luminous paint; small medical use.", c: "RaCl₂, RaBr₂", b: I("RaCl₂", "Radium chloride", "Ra", 2, "Cl", 1, 1, 2) },
            Ac: { mp: 1050, bp: 3200, f: "Actinium glows blue in the dark because of its radioactivity.", u: "Research, cancer therapy studies.", c: "Ac₂O₃", b: I("Ac₂O₃", "Actinium oxide", "Ac", 3, "O", 2, 2, 3) },
            Th: { mp: 1750, bp: 4788, f: "Thorium is found in sand and rocks and could be a safer future nuclear fuel.", u: "Gas lantern mantles, welding rods.", c: "ThO₂", b: I("ThO₂", "Thorium dioxide", "Th", 4, "O", 2, 1, 2) },
            Pa: { mp: 1568, bp: null, f: "Protactinium is so rare that only small amounts are used in research.", u: "Scientific research only.", c: "None commonly known", b: UN },
            U: { mp: 1132, bp: 4131, f: "Uranium is the fuel of nuclear power stations. One small pellet can give as much energy as about a tonne of coal.", u: "Nuclear power, dating ancient rocks.", c: "UO₂ (reactor fuel), UF₆", b: I("UO₂", "Uranium dioxide", "U", 4, "O", 2, 1, 2) },
            Np: { mp: 644, bp: 3902, f: "Neptunium was the first element heavier than uranium to be made in a laboratory.", u: "Research, detecting neutrons.", c: "NpO₂", b: UN },
            Pu: { mp: 640, bp: 3228, f: "Plutonium produces heat that powers space probes and Mars rovers.", u: "Spacecraft power sources, nuclear reactors.", c: "PuO₂", b: I("PuO₂", "Plutonium dioxide", "Pu", 4, "O", 2, 1, 2) },
            Am: { mp: 1176, bp: 2607, f: "Americium is inside most household smoke detectors.", u: "Smoke alarms.", c: "AmO₂", b: I("AmO₂", "Americium dioxide", "Am", 4, "O", 2, 1, 2) },
            Cm: { mp: 1340, bp: 3110, f: "Curium is named after Marie and Pierre Curie.", u: "Power for space probes, research.", c: "Cm₂O₃", b: I("Cm₂O₃", "Curium oxide", "Cm", 3, "O", 2, 2, 3) },
            Bk: { mp: 986, bp: null, f: "Berkelium is named after Berkeley, California, where it was first made.", u: "Used to make even heavier elements in research.", c: "None commonly known", b: UN },
            Cf: { mp: 900, bp: null, n: "Estimated values.", f: "Californium is a powerful neutron source.", u: "Starting nuclear reactors, finding oil and gold in rocks.", c: "None commonly known", b: UN },
            Es: { mp: 860, bp: null, n: "Estimated value.", f: "Einsteinium was first found in the ashes of the first hydrogen-bomb test (1952).", u: "Scientific research only.", c: "None commonly known", b: UN },
            Fm: { mp: 1527, bp: null, n: "Estimated value.", f: "Fermium is named after the physicist Enrico Fermi.", u: "Scientific research only.", c: "None commonly known", b: UN },
            Md: { mp: 827, bp: null, n: "Estimated value.", f: "Mendelevium is named after Dmitri Mendeleev, who created the periodic table.", u: "Scientific research only.", c: "None commonly known", b: UN },
            No: { mp: 827, bp: null, n: "Estimated value.", f: "Nobelium is named after Alfred Nobel, who started the Nobel Prizes.", u: "Scientific research only.", c: "None commonly known", b: UN },
            Lr: { mp: 1627, bp: null, n: "Estimated value.", f: "Lawrencium is named after Ernest Lawrence, who invented the cyclotron.", u: "Scientific research only.", c: "None commonly known", b: UN },
            Rf: { mp: null, bp: null, f: "Rutherfordium is named after Ernest Rutherford, the father of the nucleus.", u: SYN, c: "None", b: UN },
            Db: { mp: null, bp: null, f: "Dubnium is named after Dubna, the Russian town where it was made.", u: SYN, c: "None", b: UN },
            Sg: { mp: null, bp: null, f: "Seaborgium honours Glenn Seaborg, who had an element named after him while still alive.", u: SYN, c: "None", b: UN },
            Bh: { mp: null, bp: null, f: "Bohrium is named after Niels Bohr, who explained electron shells in the atom.", u: SYN, c: "None", b: UN },
            Hs: { mp: null, bp: null, f: "Hassium is named after Hesse, a state in Germany.", u: SYN, c: "None", b: UN },
            Mt: { mp: null, bp: null, f: "Meitnerium honours Lise Meitner, who helped discover nuclear fission.", u: SYN, c: "None", b: UN },
            Ds: { mp: null, bp: null, f: "Darmstadtium is named after Darmstadt in Germany.", u: SYN, c: "None", b: UN },
            Rg: { mp: null, bp: null, f: "Roentgenium is named after Wilhelm Röntgen, who discovered X-rays.", u: SYN, c: "None", b: UN },
            Cn: { mp: null, bp: null, f: "Copernicium is named after Nicolaus Copernicus, who said the Earth goes around the Sun.", u: SYN, c: "None", b: UN },
            Nh: { mp: null, bp: null, f: "Nihonium is named after Japan (Nihon) – the first element discovered in Asia.", u: SYN, c: "None", b: UN },
            Fl: { mp: null, bp: null, f: "Flerovium is named after the Flerov Laboratory in Russia.", u: SYN, c: "None", b: UN },
            Mc: { mp: null, bp: null, f: "Moscovium is named after Moscow, Russia.", u: SYN, c: "None", b: UN },
            Lv: { mp: null, bp: null, f: "Livermorium is named after the Lawrence Livermore laboratory in California.", u: SYN, c: "None", b: UN },
            Ts: { mp: null, bp: null, f: "Tennessine is named after Tennessee, USA.", u: SYN, c: "None", b: UN },
            Og: { mp: null, bp: null, f: "Oganesson is named after Yuri Oganessian – one of only two people to have an element named for them while alive.", u: SYN, c: "None", b: UN }
        };

        // ---- small SVG diagram generators (simple, student-friendly) ----
        let _svgId = 0;
        function sup(c, sign) { const d = { 1: '', 2: '²', 3: '³', 4: '⁴', 5: '⁵', 6: '⁶', 7: '⁷' }; return (d[c] !== undefined ? d[c] : c) + sign; }

        function stateOf(d) {
            if (!d || d.mp == null) return 'Unknown';
            if (d.mp > 25) return 'Solid';
            if (d.bp != null && d.bp > 25) return 'Liquid';
            return 'Gas';
        }

        function bohrSVG(shells, sym, z) {
            const n = shells.length;
            let s = `<svg viewBox="0 0 200 200" class="bond-svg bohr-svg" role="img" aria-label="Electron shell diagram of ${sym}">`;
            const radii = shells.map((_, i) => n === 1 ? 46 : 30 + i * (64 / (n - 1)));
            radii.forEach(r => { s += `<circle cx="100" cy="100" r="${r}" fill="none" stroke="#5c6b8a" stroke-width="1"/>`; });
            s += `<circle cx="100" cy="100" r="17" fill="#e8a33d"/><text x="100" y="104" text-anchor="middle" font-size="10" font-weight="bold" fill="#222">+${z}</text>`;
            shells.forEach((e, i) => {
                const r = radii[i]; const last = i === n - 1;
                const dr = e > 20 ? 2.1 : 2.8;
                for (let j = 0; j < e; j++) {
                    const a = (2 * Math.PI * j) / e - Math.PI / 2;
                    s += `<circle cx="${(100 + r * Math.cos(a)).toFixed(1)}" cy="${(100 + r * Math.sin(a)).toFixed(1)}" r="${dr}" fill="${last ? '#ffd54f' : '#7ec8ff'}"/>`;
                }
            });
            return s + `</svg>`;
        }

        function ionicSVG([cat, cc, an, ac, nc, na]) {
            const id = 'ar' + (_svgId++);
            const n = Math.max(nc, na), H = Math.max(140, n * 58 + 30), W = 340, midY = H / 2;
            const col = (count, x, label, fill, stroke) => {
                let out = ''; const gap = H / (count + 1);
                for (let i = 1; i <= count; i++) {
                    const y = gap * i;
                    out += `<circle cx="${x}" cy="${y}" r="25" fill="${fill}" stroke="${stroke}" stroke-width="2"/><text x="${x}" y="${y + 5}" text-anchor="middle" font-size="14" font-weight="bold" fill="#fff">${label}</text>`;
                }
                return out;
            };
            return `<svg viewBox="0 0 ${W} ${H}" class="bond-svg" role="img" aria-label="Ionic bond diagram">
                <defs><marker id="${id}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0L10 5L0 10z" fill="#ffd54f"/></marker></defs>
                ${col(nc, 70, cat + sup(cc, '⁺'), '#2e6fd8', '#8ab4ff')}
                ${col(na, 270, an + sup(ac, '⁻'), '#d8402e', '#ff9a8a')}
                <line x1="110" y1="${midY}" x2="228" y2="${midY}" stroke="#ffd54f" stroke-width="2.5" marker-end="url(#${id})"/>
                <text x="170" y="${midY - 10}" text-anchor="middle" font-size="12" fill="#ffd54f">${cc * nc} e⁻ transferred</text>
                <text x="170" y="${midY + 22}" text-anchor="middle" font-size="11" fill="#ddd">+ and − attract</text>
            </svg>`;
        }

        function covalentSVG([ce, p, n, order]) {
            const W = 320, H = 190, cx = n === 1 ? 105 : 160, cy = 95;
            let angles, R;
            if (n === 1) { angles = [0]; R = 110; }
            else if (n === 2) { if (order === 1) { angles = [-145, -35]; R = 80; } else { angles = [180, 0]; R = 95; } }
            else if (n === 3) { angles = [90, -30, 210]; R = 72; }
            else { angles = [90, 0, 180, -90]; R = 72; }
            const rc = 26, rp = 22;
            let out = '';
            angles.forEach(a => {
                const rad = a * Math.PI / 180, dx = Math.cos(rad), dy = -Math.sin(rad);
                const px = cx + R * dx, py = cy + R * dy, mid = (rc + R - rp) / 2, mx = cx + mid * dx, my = cy + mid * dy;
                const deg = Math.atan2(dy, dx) * 180 / Math.PI;
                out += `<ellipse cx="${mx.toFixed(1)}" cy="${my.toFixed(1)}" rx="16" ry="${order * 6 + 6}" transform="rotate(${deg.toFixed(1)} ${mx.toFixed(1)} ${my.toFixed(1)})" fill="#ffd54f" opacity="0.15"/>`;
                out += `<circle cx="${px.toFixed(1)}" cy="${py.toFixed(1)}" r="${rp}" fill="#2f9e5c" stroke="#8be0ae" stroke-width="2"/><text x="${px.toFixed(1)}" y="${(py + 5).toFixed(1)}" text-anchor="middle" font-size="14" font-weight="bold" fill="#fff">${p}</text>`;
                for (let k = 0; k < order; k++) {
                    const off = (k - (order - 1) / 2) * 10;
                    [-4, 4].forEach(sft => {
                        out += `<circle cx="${(mx + dx * sft - dy * off).toFixed(1)}" cy="${(my + dy * sft + dx * off).toFixed(1)}" r="2.8" fill="#ffd54f"/>`;
                    });
                }
            });
            out += `<circle cx="${cx}" cy="${cy}" r="${rc}" fill="#2e6fd8" stroke="#8ab4ff" stroke-width="2"/><text x="${cx}" y="${cy + 6}" text-anchor="middle" font-size="16" font-weight="bold" fill="#fff">${ce}</text>`;
            return `<svg viewBox="0 0 ${W} ${H}" class="bond-svg" role="img" aria-label="Covalent bond diagram">${out}</svg>`;
        }

        function coordSVG([donor, acc, res]) {
            const id = 'ar' + (_svgId++);
            const fs = t => t.length > 4 ? 12 : 16;
            return `<svg viewBox="0 0 340 160" class="bond-svg" role="img" aria-label="Coordinate bond diagram">
                <defs><marker id="${id}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0L10 5L0 10z" fill="#ffd54f"/></marker></defs>
                <circle cx="70" cy="70" r="40" fill="#2e6fd8" stroke="#8ab4ff" stroke-width="2"/>
                <text x="70" y="${70 + fs(donor) / 3}" text-anchor="middle" font-size="${fs(donor)}" font-weight="bold" fill="#fff">${donor}</text>
                <circle cx="116" cy="63" r="3" fill="#ffd54f"/><circle cx="116" cy="77" r="3" fill="#ffd54f"/>
                <line x1="128" y1="70" x2="208" y2="70" stroke="#ffd54f" stroke-width="2.5" marker-end="url(#${id})"/>
                <text x="168" y="54" text-anchor="middle" font-size="11" fill="#ffd54f">lone pair given</text>
                <circle cx="268" cy="70" r="38" fill="#7a3fb5" stroke="#c9a0f0" stroke-width="2" stroke-dasharray="5 4"/>
                <text x="268" y="${70 + fs(acc) / 3}" text-anchor="middle" font-size="${fs(acc)}" font-weight="bold" fill="#fff">${acc}</text>
                <text x="268" y="120" text-anchor="middle" font-size="10" fill="#ccc">empty space</text>
                <text x="170" y="148" text-anchor="middle" font-size="14" font-weight="bold" fill="#8be0ae">→ ${res}</text>
            </svg>`;
        }

        function bondTendency(el, shells) {
            const outer = shells[shells.length - 1], full = shells.length === 1 ? 2 : 8, need = full - outer, cat = el.category;
            if (cat === 'noble-gas') return `Its outer shell is already full (${outer} electrons), so it is very stable and almost never forms bonds.`;
            if (el.symbol === 'H') return `Hydrogen has 1 electron and needs 1 more to fill its shell. It usually shares it (covalent bond, as in H₂O) or loses it to become H⁺ in acids.`;
            if (cat === 'alkali-metal') return `Has 1 outer electron. It easily loses it to form a +1 ion, making ionic bonds with non-metals like chlorine or oxygen.`;
            if (cat === 'alkaline-earth') return `Has 2 outer electrons. It loses both to form a +2 ion, making ionic bonds with non-metals.`;
            if (cat === 'transition-metal') return `Transition metals can lose different numbers of electrons, so they form ions with different charges (like Fe²⁺ and Fe³⁺). They make ionic bonds and also coordinate bonds in coloured complex ions. In the solid metal, atoms are held by metallic bonding (a "sea" of free electrons).`;
            if (cat === 'lanthanide' || cat === 'actinide') return `Usually loses 3 electrons to form a +3 ion (ionic bonds). In the solid metal, atoms are held together by metallic bonding.`;
            if (cat === 'metal') return `A metal: it tends to lose its outer electrons to make positive ions (ionic bonds). In the solid metal, atoms are held by metallic bonding.`;
            if (cat === 'metalloid') return `Sits between metals and non-metals. With ${outer} outer electrons it mostly shares electrons to make covalent bonds.`;
            if (cat === 'halogen') return `Has 7 outer electrons and needs just 1 more. It gains 1 electron to become a −1 ion (ionic bond with metals) or shares 1 electron (covalent bond with non-metals).`;
            return `Has ${outer} outer electrons and needs ${need} more to fill its shell. It shares electrons with other non-metals (covalent bonds) or gains ${need} electron${need > 1 ? 's' : ''} from metals (ionic bonds).`;
        }

        function bondExampleHTML(b) {
            const [t, f, nm, a] = b;
            if (t === 'n') return `<p class="note">Noble gases have a full outer shell, so they are stable and do not form bonds under normal conditions. No bond diagram needed!</p>`;
            if (t === 'x') return `<p class="note">Its compounds are not well known because the element is very rare or radioactive. Scientists predict it would bond like the other elements in its group.</p>`;
            let label, diagram, text;
            const s = n => n > 1 ? 's' : '';
            if (t === 'i') {
                const [c, cc, an, ac, nc, na] = a; label = 'Ionic bond'; diagram = ionicSVG(a);
                text = `Each ${c} atom gives away ${cc} electron${s(cc)} and becomes ${c}${sup(cc, '⁺')}. Each ${an} atom takes ${ac} electron${s(ac)} and becomes ${an}${sup(ac, '⁻')}. The oppositely charged ions attract and stick together: ${nc} ${c} : ${na} ${an} → ${f}.`;
            } else if (t === 'c') {
                const [ce, p, n, o] = a; label = 'Covalent bond'; diagram = covalentSVG(a);
                const kind = o === 1 ? 'single' : (o === 2 ? 'double' : 'triple');
                text = `${ce} shares ${o} pair${s(o)} of electrons (${o * 2} electrons, shown as yellow dots) with each of ${n} ${p} atom${s(n)} – a ${kind} bond. Shared electrons belong to both atoms. This makes ${f}. (Shapes are simplified.)`;
            } else {
                const [d, ac, r] = a; label = 'Coordinate (dative) covalent bond'; diagram = coordSVG(a);
                text = `${d} has a lone pair of electrons. It gives BOTH electrons of the shared pair to ${ac}, which has an empty space. Result: ${r}.`;
            }
            return `<div class="bond-chip">${label}</div><p class="bond-ex"><strong>${f}</strong> — ${nm}</p>${diagram}<p class="note">${text}</p>`;
        }

        function bondTypesHTML() {
            return `<div class="bond-type"><h5>1. Ionic bond = TRANSFER</h5>${ionicSVG(['Na', 1, 'Cl', 1, 1, 1])}<p class="note">A metal gives electrons to a non-metal. Charged ions attract each other. Example: NaCl (table salt).</p></div>
                <div class="bond-type"><h5>2. Covalent bond = SHARE</h5>${covalentSVG(['O', 'H', 2, 1])}<p class="note">Two non-metals share pairs of electrons. Example: H₂O (water). A shared pair = 1 single bond.</p></div>
                <div class="bond-type"><h5>3. Coordinate covalent bond = ONE ATOM DONATES BOTH</h5>${coordSVG(['NH₃', 'H⁺', 'NH₄⁺'])}<p class="note">Like a covalent bond, but both shared electrons come from the same atom (the donor). Example: ammonium ion NH₄⁺, and H₃O⁺.</p></div>`;
        }
        // ================= END STUDENT EDITION DATA =================

        function wavelengthToRGB(wavelength) {
            let r, g, b;
            if (wavelength >= 380 && wavelength < 440) {
                r = -(wavelength - 440) / (440 - 380); g = 0.0; b = 1.0;
            } else if (wavelength >= 440 && wavelength < 490) {
                r = 0.0; g = (wavelength - 440) / (490 - 440); b = 1.0;
            } else if (wavelength >= 490 && wavelength < 510) {
                r = 0.0; g = 1.0; b = -(wavelength - 510) / (510 - 490);
            } else if (wavelength >= 510 && wavelength < 580) {
                r = (wavelength - 510) / (580 - 510); g = 1.0; b = 0.0;
            } else if (wavelength >= 580 && wavelength < 645) {
                r = 1.0; g = -(wavelength - 645) / (645 - 580); b = 0.0;
            } else if (wavelength >= 645 && wavelength <= 750) {
                r = 1.0; g = 0.0; b = 0.0;
            } else { r = 0.0; g = 0.0; b = 0.0; }
            
            let factor;
            if (wavelength >= 380 && wavelength < 420) {
                factor = 0.3 + 0.7 * (wavelength - 380) / (420 - 380);
            } else if (wavelength >= 420 && wavelength <= 700) {
                factor = 1.0;
            } else if (wavelength > 700 && wavelength <= 750) {
                factor = 0.3 + 0.7 * (750 - wavelength) / (750 - 700);
            } else { factor = 0.0; }
            
            const gamma = 0.80;
            return new THREE.Color(Math.pow(r * factor, gamma), Math.pow(g * factor, gamma), Math.pow(b * factor, gamma));
        }

        function getSpectrumColor(wavelength) {
            if (wavelength < 380) return { color: new THREE.Color(0x9400D3), opacity: 0.5 };
            else if (wavelength > 750) return { color: new THREE.Color(0x8B0000), opacity: 0.5 };
            else return { color: wavelengthToRGB(wavelength), opacity: 1.0 };
        }

        class PeriodicTableApp {
            constructor() {
                this.scene = null; this.camera = null; this.renderer = null; this.controls = null;
                this.elementMeshes = new Map(); this.elementSprites = new Map(); this.elementsData = new Map();
                this.selectedElement = null; this.highlightedElement = null;
                this.activeFilter = null; this.scalingActive = false;
            }

            async init() {
                try {
                    // Check WebGL support
                    const canvas = document.createElement('canvas');
                    const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
                    if (!gl) {
                        throw new Error('WebGL is not supported on this device. Please use a modern browser with WebGL support.');
                    }
                    
                    SPECTRAL_DATA.elements.forEach(element => {
                        this.elementsData.set(element.symbol, element);
                    });

                    // Detect mobile device
                    const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.innerWidth <= 768;
                    
                    // Show app container first so we can get proper dimensions
                    document.getElementById('app-container').style.display = 'block';
                    
                    const container = document.getElementById('canvas-container');
                    this.scene = new THREE.Scene();
                    this.scene.background = new THREE.Color(0x1a1a2e);

                    const aspect = window.innerWidth / window.innerHeight;
                    this.camera = new THREE.PerspectiveCamera(75, aspect, 0.1, 1000);
                    
                    // Adjust camera position for mobile
                    // Fit the whole table on screen for any screen shape (portrait phones need to be further away)
                    const tanHalf = Math.tan(37.5 * Math.PI / 180);
                    const fitDist = Math.max(5.7 / tanHalf, 10.4 / (tanHalf * aspect)) * 1.04;
                    this.fitDist = isMobile ? fitDist : Math.max(12, fitDist);
                    this.targetY = isMobile ? -1.65 : 0;
                    this.camera.position.set(0, this.targetY, this.fitDist);

                    this.renderer = new THREE.WebGLRenderer({ antialias: true });
                    this.renderer.setSize(window.innerWidth, window.innerHeight);
                    this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); // Limit pixel ratio for performance
                    container.appendChild(this.renderer.domElement);

                    const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
                    this.scene.add(ambientLight);
                    const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
                    directionalLight.position.set(10, 10, 10);
                    this.scene.add(directionalLight);

                    this.createPeriodicTable();

                    this.controls = new OrbitControls(this.camera, this.renderer.domElement);
                    this.controls.enableDamping = true;
                    this.controls.dampingFactor = 0.05;
                    this.controls.target.set(0, this.targetY, 0);
                    this.controls.update();
                    
                    // Adjust controls for mobile
                    if (isMobile) {
                        this.controls.minDistance = 15;
                        this.controls.maxDistance = Math.max(100, this.fitDist * 2);
                        this.controls.rotateSpeed = 0.5;
                        this.controls.zoomSpeed = 0.8;
                        // Enable touch controls
                        this.controls.touches = {
                            ONE: THREE.TOUCH.ROTATE,
                            TWO: THREE.TOUCH.DOLLY_PAN
                        };
                    } else {
                        this.controls.minDistance = 10;
                        this.controls.maxDistance = 80;
                    }

                    // Add touch event listeners for mobile
                    if (isMobile) {
                        this.renderer.domElement.addEventListener('touchstart', (e) => this.onTouchStart(e));
                        this.renderer.domElement.addEventListener('touchend', (e) => this.onTouchEnd(e));
                    } else {
                        this.renderer.domElement.addEventListener('mousemove', (e) => this.onMouseMove(e));
                        this.renderer.domElement.addEventListener('click', (e) => this.onClick(e));
                    }
                    
                    document.addEventListener('keydown', (e) => { if (e.key === 'Escape') this.deselectElement(); });
                    window.addEventListener('resize', () => this.onWindowResize());

                    this.animate();
                    this.setupLegend();
                    if (STUDENT_INFO.school) document.getElementById("school-name").textContent = " · " + STUDENT_INFO.school;
                    
                    // Hide loading after everything is set up
                    document.getElementById('loading').style.display = 'none';
                } catch (error) {
                    console.error('Init error:', error);
                    document.getElementById('loading').innerHTML = '<div style="color: #ff6b6b;"><h2>Failed to Load</h2><p>' + error.message + '</p></div>';
                }
            }

            createPeriodicTable() {
                this.elementsData.forEach((elementData, symbol) => {
                    const pos = ELEMENT_LAYOUT[symbol];
                    if (!pos) return;

                    const unit = 1.1;
                    const x = (pos.column - 9.5) * unit;
                    const y = -(pos.row - 3.5) * unit;

                    const geometry = new RoundedBoxGeometry(0.9, 0.9, 0.4, 4, 0.08);
                    const color = ELEMENT_COLORS[elementData.category] || ELEMENT_COLORS.unknown;
                    const material = new THREE.MeshStandardMaterial({
                        color: color, emissive: 0x000000, metalness: 0.3, roughness: 0.7
                    });

                    const mesh = new THREE.Mesh(geometry, material);
                    mesh.position.set(x, y, 0);
                    mesh.userData = { symbol, elementData, originalZ: 0, active: true, scale: 1 };
                    this.scene.add(mesh);
                    this.elementMeshes.set(symbol, mesh);

                    const canvas = document.createElement('canvas');
                    const context = canvas.getContext('2d');
                    canvas.width = 128; canvas.height = 128;
                    context.fillStyle = 'rgba(255, 255, 255, 0.7)';
                    context.font = 'bold 24px Arial';
                    context.textAlign = 'center';
                    context.textBaseline = 'top';
                    context.fillText(elementData.atomicNumber, 64, 10);
                    context.fillStyle = 'white';
                    context.font = 'bold 60px Arial';
                    context.textBaseline = 'middle';
                    context.fillText(symbol, 64, 75);

                    const texture = new THREE.CanvasTexture(canvas);
                    const spriteMaterial = new THREE.SpriteMaterial({ map: texture });
                    const sprite = new THREE.Sprite(spriteMaterial);
                    sprite.scale.set(0.6, 0.6, 1);
                    sprite.position.set(x, y, 0.5);
                    sprite.userData = { symbol, originalZ: 0.5 };
                    this.scene.add(sprite);
                    this.elementSprites.set(symbol, sprite);
                });
            }

            onMouseMove(event) {
                const rect = this.renderer.domElement.getBoundingClientRect();
                const x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
                const y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
                const element = this.getElementAtPosition(x, y);
                if (element) {
                    this.renderer.domElement.style.cursor = 'pointer';
                    this.highlightElement(element);
                } else {
                    this.renderer.domElement.style.cursor = 'default';
                    this.highlightElement(null);
                }
            }

            onClick(event) {
                const rect = this.renderer.domElement.getBoundingClientRect();
                const x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
                const y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
                const element = this.getElementAtPosition(x, y);
                if (element) this.selectElement(element);
                else this.deselectElement();
            }
            
            onTouchStart(event) {
                if (event.touches.length === 1) {
                    this.touchStartTime = Date.now();
                    this.touchStartPos = {
                        x: event.touches[0].clientX,
                        y: event.touches[0].clientY
                    };
                }
            }
            
            onTouchEnd(event) {
                if (event.changedTouches.length === 1 && this.touchStartTime) {
                    const touchDuration = Date.now() - this.touchStartTime;
                    const touch = event.changedTouches[0];
                    const deltaX = Math.abs(touch.clientX - this.touchStartPos.x);
                    const deltaY = Math.abs(touch.clientY - this.touchStartPos.y);
                    
                    // If it's a quick tap (not a drag), treat it as a click
                    if (touchDuration < 300 && deltaX < 10 && deltaY < 10) {
                        const rect = this.renderer.domElement.getBoundingClientRect();
                        const x = ((touch.clientX - rect.left) / rect.width) * 2 - 1;
                        const y = -((touch.clientY - rect.top) / rect.height) * 2 + 1;
                        const element = this.getElementAtPosition(x, y);
                        if (element) this.selectElement(element);
                        else this.deselectElement();
                    }
                }
                this.touchStartTime = null;
                this.touchStartPos = null;
            }

            getElementAtPosition(x, y) {
                const raycaster = new THREE.Raycaster();
                const mouse = new THREE.Vector2(x, y);
                raycaster.setFromCamera(mouse, this.camera);
                const meshes = Array.from(this.elementMeshes.values()).filter(m => m.userData.active);
                const intersects = raycaster.intersectObjects(meshes);
                return intersects.length > 0 ? intersects[0].object.userData.symbol : null;
            }

            highlightElement(symbol) {
                if (this.highlightedElement && this.highlightedElement !== this.selectedElement) {
                    const mesh = this.elementMeshes.get(this.highlightedElement);
                    const sprite = this.elementSprites.get(this.highlightedElement);
                    if (mesh) {
                        mesh.material.emissive.setHex(0x000000);
                        mesh.position.z = mesh.userData.originalZ;
                    }
                    if (sprite) {
                        sprite.position.z = sprite.userData.originalZ;
                    }
                }
                if (symbol && symbol !== this.selectedElement) {
                    const mesh = this.elementMeshes.get(symbol);
                    const sprite = this.elementSprites.get(symbol);
                    if (mesh) {
                        mesh.material.emissive.setHex(0x444444);
                        mesh.position.z = mesh.userData.originalZ + 0.2;
                    }
                    if (sprite) {
                        sprite.position.z = sprite.userData.originalZ + 0.2;
                    }
                }
                this.highlightedElement = symbol;
            }

            selectElement(symbol) {
                if (this.selectedElement) {
                    const mesh = this.elementMeshes.get(this.selectedElement);
                    const sprite = this.elementSprites.get(this.selectedElement);
                    if (mesh) {
                        mesh.material.emissive.setHex(0x000000);
                        mesh.position.z = mesh.userData.originalZ;
                    }
                    if (sprite) {
                        sprite.position.z = sprite.userData.originalZ;
                    }
                }
                if (symbol) {
                    const mesh = this.elementMeshes.get(symbol);
                    const sprite = this.elementSprites.get(symbol);
                    if (mesh) {
                        mesh.material.emissive.setHex(0x00ff00);
                        mesh.position.z = mesh.userData.originalZ;
                    }
                    if (sprite) {
                        sprite.position.z = sprite.userData.originalZ;
                    }
                    this.showSpectrum(symbol);
                }
                this.selectedElement = symbol;
            }

            deselectElement() {
                this.selectElement(null);
                document.getElementById('info-panel-wrapper').classList.add('hidden');
            }

            setupLegend() {
                const counts = {};
                this.elementsData.forEach(e => { counts[e.category] = (counts[e.category] || 0) + 1; });
                document.querySelectorAll('#legend-items .legend-item').forEach(item => {
                    const cat = item.dataset.cat;
                    if (cat !== 'all' && counts[cat]) {
                        const span = item.querySelector('span');
                        if (span && !span.dataset.counted) { span.textContent += ' (' + counts[cat] + ')'; span.dataset.counted = '1'; }
                    }
                    item.addEventListener('click', () => this.filterCategory(cat === 'all' ? null : cat));
                });
                const wrap = document.getElementById('info-panel-wrapper');
                const syncPanel = () => document.body.classList.toggle('panel-open', !wrap.classList.contains('hidden') && !wrap.classList.contains('collapsed'));
                new MutationObserver(syncPanel).observe(wrap, { attributes: true, attributeFilter: ['class'] });
                document.getElementById('filter-status').addEventListener('click', (e) => {
                    if (e.target.tagName === 'BUTTON') this.filterCategory(null);
                });
                if (window.innerWidth <= 768) {
                    ['legend-panel', 'legend-items', 'legend-toggle-icon'].forEach(id => document.getElementById(id).classList.add('collapsed'));
                }
            }

            filterCategory(cat) {
                if (cat && this.activeFilter === cat) cat = null;
                this.activeFilter = cat;
                let shown = 0;
                this.elementMeshes.forEach(mesh => {
                    mesh.userData.active = !cat || mesh.userData.elementData.category === cat;
                    if (mesh.userData.active) shown++;
                });
                this.scalingActive = true;
                this.highlightElement(null);
                document.querySelectorAll('#legend-items .legend-item').forEach(item => {
                    const c = item.dataset.cat;
                    item.classList.toggle('active', !!cat && c === cat);
                    item.classList.toggle('dim', !!cat && c !== cat && c !== 'all');
                });
                const status = document.getElementById('filter-status');
                if (cat) {
                    const info = CATEGORY_INFO[cat] || { label: cat, desc: '' };
                    status.innerHTML = '<strong>' + info.label + '</strong> (' + shown + ' elements)<br>' + info.desc + '<button>Show all</button>';
                    status.classList.remove('hidden');
                    if (this.selectedElement) {
                        const sel = this.elementsData.get(this.selectedElement);
                        if (!sel || sel.category !== cat) this.deselectElement();
                    }
                } else {
                    status.classList.add('hidden');
                }
            }

            updateScales() {
                if (!this.scalingActive) return;
                let moving = false;
                this.elementMeshes.forEach((mesh, sym) => {
                    const u = mesh.userData, t = u.active ? 1 : 0;
                    if (Math.abs(t - u.scale) > 0.002) { u.scale += (t - u.scale) * 0.15; moving = true; } else { u.scale = t; }
                    mesh.scale.setScalar(Math.max(u.scale, 0.0001));
                    mesh.visible = u.scale > 0.02;
                    const sp = this.elementSprites.get(sym);
                    if (sp) { sp.scale.set(0.6 * u.scale, 0.6 * u.scale, 1); sp.visible = u.scale > 0.02; }
                });
                this.scalingActive = moving;
            }

            miniSpectrum(symbol, elementData) {
                const lines = elementData.spectralLines || [];
                const sortedLines = [...lines].sort((a, b) => (b.intensity || 0) - (a.intensity || 0)).slice(0, 20);
                const canvas = document.createElement('canvas');
                canvas.width = 360; canvas.height = 200;
                canvas.style.width = '100%';
                canvas.style.border = '1px solid rgba(255, 255, 255, 0.2)';
                canvas.style.borderRadius = '5px';
                canvas.className = 'spectrum-clickable';
                canvas.title = 'Click to view detailed spectrum';
                canvas.onclick = () => this.showDetailedSpectrum(symbol, elementData);
                const ctx = canvas.getContext('2d');
                ctx.fillStyle = '#000';
                ctx.fillRect(0, 0, canvas.width, canvas.height);
                const wl = sortedLines.map(l => l.wavelength);
                const minWave = Math.min(...wl, 380), maxWave = Math.max(...wl, 750), range = maxWave - minWave;
                ctx.fillStyle = '#666'; ctx.font = '10px Arial'; ctx.textAlign = 'center';
                for (let w = Math.ceil(minWave / 50) * 50; w <= maxWave; w += 50) {
                    const x = ((w - minWave) / range) * (canvas.width - 40) + 20;
                    ctx.fillRect(x, canvas.height - 20, 1, 10);
                    ctx.fillText(w + 'nm', x, canvas.height - 5);
                }
                sortedLines.forEach(line => {
                    const { color, opacity } = getSpectrumColor(line.wavelength);
                    const x = ((line.wavelength - minWave) / range) * (canvas.width - 40) + 20;
                    const height = (line.intensity || 0.5) * 140;
                    ctx.fillStyle = `rgba(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)}, ${opacity})`;
                    ctx.fillRect(x - 2, canvas.height - 30 - height, 4, height);
                });
                return canvas;
            }

            showSpectrum(symbol) {
                const el = this.elementsData.get(symbol);
                if (!el) return;
                const sd = STUDENT_DATA[symbol] || {};
                const z = el.atomicNumber;
                const shells = computeShells(z);
                const massNo = MASS_NUMBERS[z], atomicMass = ATOMIC_MASS[z];
                const neutrons = massNo - z;
                const radioactive = (z === 43 || z === 61 || z >= 84);
                const state = stateOf(sd);
                const cat = CATEGORY_INFO[el.category] || { label: el.category, desc: '' };
                const hex = '#' + (ELEMENT_COLORS[el.category] || 0xcccccc).toString(16).padStart(6, '0');
                const pos = ELEMENT_LAYOUT[symbol];
                const group = pos && pos.row <= 7 ? pos.column : 'f-block (inner transition)';
                const temp = t => t == null ? 'Unknown' : `${t} °C (${t + 273} K)`;
                const stateIcon = { Solid: '🧊', Liquid: '💧', Gas: '💨', Unknown: '❓' }[state];

                document.getElementById('element-name').textContent = el.name;
                document.getElementById('element-details').innerHTML = `
                    <div class="el-head">
                        <div class="el-tile" style="background:${hex}">${symbol}<small>${z}</small></div>
                        <div>
                            <span class="chip">${cat.label}</span>
                            <span class="chip">${stateIcon} ${state} at room temp</span>
                            <span class="chip ${radioactive ? 'rad' : 'ok'}">${radioactive ? '☢️ Radioactive' : '✅ Not radioactive'}</span>
                        </div>
                    </div>
                    <div class="fam-desc"><strong>About this family:</strong> ${cat.desc}</div>`;

                const collapsible = (title, icon, color, body, open) => `
                    <div class="stu-card ${color}">
                        <div class="collapsible-header" onclick="this.nextElementSibling.classList.toggle('collapsed'); this.querySelector('.collapse-icon').classList.toggle('collapsed');">
                            <h4>${icon} ${title}</h4><span class="collapse-icon ${open ? '' : 'collapsed'}">▼</span>
                        </div>
                        <div class="collapsible-content ${open ? '' : 'collapsed'}">${body}</div>
                    </div>`;

                const atomBody = `
                    ${bohrSVG(shells, symbol, z)}
                    <p class="note" style="text-align:center">Blue dots = inner electrons, yellow dots = outer-shell electrons. The centre is the nucleus (+${z} protons).</p>
                    <div class="stat-grid">
                        <div class="stat"><span>Atomic number</span><strong>${z}</strong></div>
                        <div class="stat"><span>Mass number</span><strong>${massNo}</strong></div>
                        <div class="stat"><span>Protons</span><strong>${z}</strong></div>
                        <div class="stat"><span>Neutrons</span><strong>${neutrons}</strong></div>
                        <div class="stat"><span>Electrons</span><strong>${z}</strong></div>
                        <div class="stat"><span>Atomic mass</span><strong>${atomicMass} u</strong></div>
                        <div class="stat"><span>Electron arrangement</span><strong>${shells.join(', ')}</strong></div>
                        <div class="stat"><span>Outer-shell electrons</span><strong>${shells[shells.length - 1]}</strong></div>
                        <div class="stat"><span>Period (shells)</span><strong>${shells.length}</strong></div>
                        <div class="stat"><span>Group</span><strong>${group}</strong></div>
                    </div>
                    <p class="note">Remember: atomic number = protons = electrons (in a neutral atom). Mass number = protons + neutrons, so neutrons = ${massNo} − ${z} = ${neutrons}. (Shown for the most common isotope.)</p>`;

                const physBody = `
                    <div class="stat-grid">
                        <div class="stat"><span>State at room temp</span><strong>${stateIcon} ${state}</strong></div>
                        <div class="stat"><span>Melting point</span><strong>${temp(sd.mp)}</strong></div>
                        <div class="stat"><span>Boiling point</span><strong>${temp(sd.bp)}</strong></div>
                    </div>
                    ${sd.n ? `<p class="note">ℹ️ ${sd.n}</p>` : ''}
                    ${sd.mp == null ? '<p class="note">Too few atoms have been made to measure this.</p>' : ''}`;

                const radBody = radioactive
                    ? `<p>☢️ <strong>Yes, radioactive.</strong> ${(z === 43 || z === 61) ? 'It has no stable form at all. ' : ''}Its atoms are unstable and slowly break down (decay), giving off energy as radiation. ${(z === 90 || z === 92) ? 'It decays extremely slowly, over billions of years. ' : ''}Radioactive materials must only be handled by trained experts.</p>`
                    : `<p>✅ <strong>No.</strong> Its atoms are stable, so it does not give off dangerous radiation.</p>`;

                const bondBody = `
                    <p>${bondTendency(el, shells)}</p>
                    ${bondExampleHTML(sd.b || ['x'])}
                    <div class="stu-card c-yellow" style="margin-top:10px">
                        <div class="collapsible-header" onclick="this.nextElementSibling.classList.toggle('collapsed'); this.querySelector('.collapse-icon').classList.toggle('collapsed');">
                            <h4>📘 Learn the 3 bond types</h4><span class="collapse-icon collapsed">▼</span>
                        </div>
                        <div class="collapsible-content collapsed">${bondTypesHTML()}</div>
                    </div>`;

                const container = document.getElementById('spectrum-container');
                container.innerHTML = '';
                container.insertAdjacentHTML('beforeend',
                    collapsible('Atom at a glance', '⚛️', 'c-blue', atomBody, true) +
                    collapsible('Physical properties', '🌡️', 'c-orange', physBody, true) +
                    collapsible('Radioactive?', '☢️', 'c-pink', radBody, true) +
                    collapsible('How does it bond?', '🔗', 'c-purple', bondBody, true) +
                    collapsible('Uses', '🛠️', 'c-green', `<p>${sd.u || ''}</p>`, true) +
                    collapsible('Common chemicals', '🧪', 'c-green', `<p>${sd.c || ''}</p>`, true) +
                    collapsible('Interesting fact', '💡', 'c-yellow', `<p>${sd.f || ''}</p>`, true) +
                    collapsible('Where did it come from?', '🌟', 'c-blue', `<p><span class="origin-badge" style="background-color:${el.originColor};color:#000">${el.cosmicOrigin}</span></p><p>${el.astronomyInfo || ''}</p>`, false) +
                    collapsible('Light fingerprint (emission spectrum)', '🌈', 'c-purple', `<p class="note">Heated atoms give out light of special colours. Click the picture to see it bigger.</p><div id="mini-spectrum"></div>`, false));
                document.getElementById('mini-spectrum').appendChild(this.miniSpectrum(symbol, el));

                document.getElementById('info-panel-wrapper').classList.remove('hidden');
                document.getElementById('info-panel').scrollTop = 0;
                const isMobile = window.innerWidth <= 768;
                const toggle = document.getElementById('info-panel-toggle');
                if (toggle) toggle.textContent = isMobile ? '▼' : '▶';
            }

            showDetailedSpectrum(symbol, elementData) {
                const modal = document.getElementById('spectrum-modal');
                const modalContent = document.getElementById('spectrum-modal-content');
                
                modalContent.innerHTML = '';
                
                const title = document.createElement('h2');
                title.textContent = `${elementData.name} (${symbol}) - Emission Spectrum`;
                title.style.color = '#4fc3f7';
                title.style.textAlign = 'center';
                title.style.marginBottom = '10px';
                title.style.fontSize = '28px';
                modalContent.appendChild(title);
                
                // Add element properties section
                const propsSection = document.createElement('div');
                propsSection.style.background = 'rgba(79, 195, 247, 0.1)';
                propsSection.style.border = '1px solid rgba(79, 195, 247, 0.3)';
                propsSection.style.borderRadius = '8px';
                propsSection.style.padding = '15px';
                propsSection.style.marginBottom = '20px';
                propsSection.style.display = 'grid';
                propsSection.style.gridTemplateColumns = 'repeat(auto-fit, minmax(200px, 1fr))';
                propsSection.style.gap = '15px';
                propsSection.style.fontSize = '14px';
                
                const atomicNumber = `<div><strong>Atomic Number:</strong> ${elementData.atomicNumber}</div>`;
                const category = `<div><strong>Category:</strong> ${elementData.category.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase())}</div>`;
                const cosmicOrigin = `<div><strong>Cosmic Origin:</strong> <span style="color: ${elementData.originColor}">${elementData.cosmicOrigin}</span></div>`;
                const spectralLinesCount = `<div><strong>Spectral Lines:</strong> ${elementData.spectralLines.length} lines</div>`;
                
                propsSection.innerHTML = atomicNumber + category + cosmicOrigin + spectralLinesCount;
                modalContent.appendChild(propsSection);
                
                // Check wavelength range of spectral lines
                const lines = elementData.spectralLines || [];
                const wavelengths = lines.map(l => l.wavelength);
                const minLineWave = Math.min(...wavelengths);
                const maxLineWave = Math.max(...wavelengths);
                
                // Determine if we need extended range
                const hasUV = minLineWave < 380;
                const hasIR = maxLineWave > 750;
                const showExtended = hasUV || hasIR;
                
                let minWave, maxWave, rangeLabel;
                if (showExtended) {
                    minWave = 200;
                    maxWave = 1000;
                    rangeLabel = 'Extended Spectrum (200-1000 nm) - Including UV and IR';
                } else {
                    minWave = 380;
                    maxWave = 750;
                    rangeLabel = 'Visible Spectrum (380-750 nm)';
                }
                
                const subtitle = document.createElement('p');
                subtitle.textContent = rangeLabel;
                subtitle.style.color = '#aaa';
                subtitle.style.textAlign = 'center';
                subtitle.style.marginBottom = '30px';
                subtitle.style.fontSize = '16px';
                modalContent.appendChild(subtitle);
                
                const canvas = document.createElement('canvas');
                canvas.width = 1400;
                canvas.height = 300;
                canvas.style.width = '100%';
                canvas.style.border = '2px solid rgba(255, 255, 255, 0.3)';
                canvas.style.borderRadius = '10px';
                canvas.style.background = '#000';
                
                const ctx = canvas.getContext('2d');
                ctx.fillStyle = '#000';
                ctx.fillRect(0, 0, canvas.width, canvas.height);
                
                const range = maxWave - minWave;
                
                if (showExtended) {
                    // Draw spectrum regions for extended view
                    const regions = [
                        { start: 200, end: 380, label: 'UV', color: 'rgba(138, 43, 226, 0.15)' },
                        { start: 380, end: 750, label: 'Visible', color: 'rgba(255, 255, 255, 0.05)' },
                        { start: 750, end: 1000, label: 'IR', color: 'rgba(255, 0, 0, 0.15)' }
                    ];
                    
                    regions.forEach(region => {
                        const x1 = ((region.start - minWave) / range) * (canvas.width - 80) + 40;
                        const x2 = ((region.end - minWave) / range) * (canvas.width - 80) + 40;
                        ctx.fillStyle = region.color;
                        ctx.fillRect(x1, 50, x2 - x1, canvas.height - 100);
                        
                        ctx.fillStyle = '#888';
                        ctx.font = 'bold 12px Arial';
                        ctx.textAlign = 'center';
                        ctx.fillText(region.label, (x1 + x2) / 2, 35);
                    });
                }
                
                // Draw continuous visible spectrum gradient
                const visStart = Math.max(380, minWave);
                const visEnd = Math.min(750, maxWave);
                const gradientHeight = 40;
                const gradientY = canvas.height - 80;
                
                for (let w = visStart; w <= visEnd; w += 1) {
                    const x = ((w - minWave) / range) * (canvas.width - 80) + 40;
                    const color = wavelengthToRGB(w);
                    ctx.fillStyle = `rgb(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)})`;
                    ctx.fillRect(x, gradientY, 2, gradientHeight);
                }
                
                // Draw wavelength scale below gradient
                ctx.strokeStyle = '#666';
                ctx.lineWidth = 1;
                ctx.fillStyle = '#aaa';
                ctx.font = '12px Arial';
                ctx.textAlign = 'center';
                
                // Major tick marks
                const tickInterval = showExtended ? 100 : 50;
                const startTick = Math.ceil(minWave / tickInterval) * tickInterval;
                for (let w = startTick; w <= maxWave; w += tickInterval) {
                    const x = ((w - minWave) / range) * (canvas.width - 80) + 40;
                    ctx.beginPath();
                    ctx.moveTo(x, gradientY + gradientHeight);
                    ctx.lineTo(x, gradientY + gradientHeight + 10);
                    ctx.stroke();
                    ctx.fillText(w, x, gradientY + gradientHeight + 25);
                }
                
                // Minor tick marks
                const minorInterval = showExtended ? 20 : 10;
                ctx.strokeStyle = '#444';
                for (let w = minWave; w <= maxWave; w += minorInterval) {
                    if (w % tickInterval !== 0) {
                        const x = ((w - minWave) / range) * (canvas.width - 80) + 40;
                        ctx.beginPath();
                        ctx.moveTo(x, gradientY + gradientHeight);
                        ctx.lineTo(x, gradientY + gradientHeight + 5);
                        ctx.stroke();
                    }
                }
                
                // Add "nm" label
                ctx.fillStyle = '#aaa';
                ctx.font = '14px Arial';
                ctx.textAlign = 'right';
                ctx.fillText('Wavelength (nm)', canvas.width - 45, gradientY + gradientHeight + 25);
                
                // Draw spectral lines
                lines.forEach(line => {
                    if (line.wavelength >= minWave && line.wavelength <= maxWave) {
                        const { color, opacity } = getSpectrumColor(line.wavelength);
                        const x = ((line.wavelength - minWave) / range) * (canvas.width - 80) + 40;
                        const intensity = line.intensity || 0.5;
                        const height = 30 + intensity * 150;
                        
                        // Draw line with glow effect
                        const gradient = ctx.createLinearGradient(x, gradientY - height, x, gradientY);
                        gradient.addColorStop(0, `rgba(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)}, ${opacity})`);
                        gradient.addColorStop(1, `rgba(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)}, ${opacity * 0.3})`);
                        
                        ctx.fillStyle = gradient;
                        ctx.fillRect(x - 2, gradientY - height, 4, height);
                        
                        // Add glow
                        ctx.shadowBlur = 10;
                        ctx.shadowColor = `rgba(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)}, ${opacity})`;
                        ctx.fillRect(x - 2, gradientY - height, 4, height);
                        ctx.shadowBlur = 0;
                        
                        // Label prominent lines
                        if (intensity > 0.6) {
                            ctx.fillStyle = '#fff';
                            ctx.font = 'bold 11px Arial';
                            ctx.textAlign = 'center';
                            ctx.fillText(line.wavelength.toFixed(1), x, gradientY - height - 10);
                            
                            // Draw transition info if available
                            if (line.transition) {
                                ctx.font = '9px Arial';
                                ctx.fillStyle = '#4fc3f7';
                                ctx.fillText(line.transition, x, gradientY - height - 22);
                            }
                        }
                    }
                });
                
                
                modalContent.appendChild(canvas);
                
                // Add Absorption Spectrum
                const absorptionTitle = document.createElement('h3');
                absorptionTitle.textContent = 'Absorption Spectrum';
                absorptionTitle.style.color = '#4fc3f7';
                absorptionTitle.style.marginTop = '30px';
                absorptionTitle.style.marginBottom = '10px';
                absorptionTitle.style.fontSize = '20px';
                absorptionTitle.style.textAlign = 'center';
                modalContent.appendChild(absorptionTitle);
                
                const absorptionSubtitle = document.createElement('p');
                absorptionSubtitle.textContent = 'Dark lines show wavelengths absorbed by the element';
                absorptionSubtitle.style.color = '#aaa';
                absorptionSubtitle.style.textAlign = 'center';
                absorptionSubtitle.style.marginBottom = '15px';
                absorptionSubtitle.style.fontSize = '14px';
                modalContent.appendChild(absorptionSubtitle);
                
                const absCanvas = document.createElement('canvas');
                absCanvas.width = 1400;
                absCanvas.height = 200;
                absCanvas.style.width = '100%';
                absCanvas.style.border = '2px solid rgba(255, 255, 255, 0.3)';
                absCanvas.style.borderRadius = '10px';
                absCanvas.style.background = '#000';
                
                const absCtx = absCanvas.getContext('2d');
                absCtx.fillStyle = '#000';
                absCtx.fillRect(0, 0, absCanvas.width, absCanvas.height);
                
                // Draw continuous spectrum background (bright)
                const absGradientHeight = 80;
                const absGradientY = 60;
                
                if (showExtended) {
                    // For extended view, show regions
                    const regions = [
                        { start: 200, end: 380, color: '#8A2BE2' },
                        { start: 750, end: 1000, color: '#ff0000' }
                    ];
                    
                    // UV region
                    const uvX1 = ((200 - minWave) / range) * (absCanvas.width - 80) + 40;
                    const uvX2 = ((380 - minWave) / range) * (absCanvas.width - 80) + 40;
                    const uvGradient = absCtx.createLinearGradient(uvX1, 0, uvX2, 0);
                    uvGradient.addColorStop(0, 'rgba(138, 43, 226, 0.3)');
                    uvGradient.addColorStop(1, 'rgba(138, 43, 226, 0.6)');
                    absCtx.fillStyle = uvGradient;
                    absCtx.fillRect(uvX1, absGradientY, uvX2 - uvX1, absGradientHeight);
                    
                    // Visible spectrum
                    for (let w = 380; w <= 750; w += 1) {
                        const x = ((w - minWave) / range) * (absCanvas.width - 80) + 40;
                        const color = wavelengthToRGB(w);
                        absCtx.fillStyle = `rgb(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)})`;
                        absCtx.fillRect(x, absGradientY, 2, absGradientHeight);
                    }
                    
                    // IR region
                    const irX1 = ((750 - minWave) / range) * (absCanvas.width - 80) + 40;
                    const irX2 = ((1000 - minWave) / range) * (absCanvas.width - 80) + 40;
                    const irGradient = absCtx.createLinearGradient(irX1, 0, irX2, 0);
                    irGradient.addColorStop(0, 'rgba(255, 0, 0, 0.6)');
                    irGradient.addColorStop(1, 'rgba(255, 0, 0, 0.3)');
                    absCtx.fillStyle = irGradient;
                    absCtx.fillRect(irX1, absGradientY, irX2 - irX1, absGradientHeight);
                } else {
                    // Visible spectrum only
                    for (let w = visStart; w <= visEnd; w += 1) {
                        const x = ((w - minWave) / range) * (absCanvas.width - 80) + 40;
                        const color = wavelengthToRGB(w);
                        absCtx.fillStyle = `rgb(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)})`;
                        absCtx.fillRect(x, absGradientY, 2, absGradientHeight);
                    }
                }
                
                // Draw absorption lines (dark lines on bright background)
                lines.forEach(line => {
                    if (line.wavelength >= minWave && line.wavelength <= maxWave) {
                        const x = ((line.wavelength - minWave) / range) * (absCanvas.width - 80) + 40;
                        const intensity = line.intensity || 0.5;
                        const lineWidth = 2 + intensity * 3;
                        
                        // Draw dark line
                        absCtx.fillStyle = 'rgba(0, 0, 0, 0.9)';
                        absCtx.fillRect(x - lineWidth/2, absGradientY, lineWidth, absGradientHeight);
                        
                        // Add subtle shadow for depth
                        absCtx.shadowBlur = 3;
                        absCtx.shadowColor = 'rgba(0, 0, 0, 0.8)';
                        absCtx.fillRect(x - lineWidth/2, absGradientY, lineWidth, absGradientHeight);
                        absCtx.shadowBlur = 0;
                    }
                });
                
                // Draw wavelength scale
                absCtx.strokeStyle = '#666';
                absCtx.lineWidth = 1;
                absCtx.fillStyle = '#aaa';
                absCtx.font = '12px Arial';
                absCtx.textAlign = 'center';
                
                const absScaleY = absGradientY + absGradientHeight;
                for (let w = startTick; w <= maxWave; w += tickInterval) {
                    const x = ((w - minWave) / range) * (absCanvas.width - 80) + 40;
                    absCtx.beginPath();
                    absCtx.moveTo(x, absScaleY);
                    absCtx.lineTo(x, absScaleY + 10);
                    absCtx.stroke();
                    absCtx.fillText(w, x, absScaleY + 25);
                }
                
                // Add label
                absCtx.fillStyle = '#aaa';
                absCtx.font = '14px Arial';
                absCtx.textAlign = 'right';
                absCtx.fillText('Wavelength (nm)', absCanvas.width - 45, absScaleY + 25);
                
                modalContent.appendChild(absCanvas);
                
                // Add line details table
                const detailsTitle = document.createElement('h3');
                detailsTitle.textContent = 'Spectral Line Details';
                detailsTitle.style.color = '#4fc3f7';
                detailsTitle.style.marginTop = '30px';
                detailsTitle.style.marginBottom = '15px';
                detailsTitle.style.fontSize = '20px';
                modalContent.appendChild(detailsTitle);
                
                const table = document.createElement('div');
                table.style.display = 'grid';
                table.style.gridTemplateColumns = '1fr 1fr 1fr';
                table.style.gap = '10px';
                table.style.color = '#ccc';
                table.style.fontSize = '13px';
                
                lines.sort((a, b) => b.intensity - a.intensity).forEach(line => {
                    const lineItem = document.createElement('div');
                    lineItem.style.padding = '10px';
                    lineItem.style.background = 'rgba(255, 255, 255, 0.05)';
                    lineItem.style.borderRadius = '5px';
                    lineItem.style.borderLeft = '3px solid';
                    const { color } = getSpectrumColor(line.wavelength);
                    lineItem.style.borderColor = `rgb(${Math.floor(color.r * 255)}, ${Math.floor(color.g * 255)}, ${Math.floor(color.b * 255)})`;
                    
                    let regionLabel = '';
                    if (line.wavelength < 380) {
                        regionLabel = '<span style="color: #8A2BE2; font-size: 11px;"> (UV)</span>';
                    } else if (line.wavelength > 750) {
                        regionLabel = '<span style="color: #ff0000; font-size: 11px;"> (IR)</span>';
                    }
                    
                    let transitionText = '';
                    if (line.transition) {
                        transitionText = `<br><span style="color: #4fc3f7; font-size: 11px;">${line.transition}</span>`;
                    }
                    
                    lineItem.innerHTML = `
                        <strong>${line.wavelength.toFixed(1)} nm${regionLabel}</strong><br>
                        Intensity: ${(line.intensity || 0).toFixed(2)}${transitionText}
                    `;
                    table.appendChild(lineItem);
                });
                
                modalContent.appendChild(table);
                
                // Add note
                const note = document.createElement('p');
                note.style.marginTop = '30px';
                note.style.textAlign = 'center';
                note.style.color = '#888';
                note.style.fontSize = '13px';
                if (showExtended) {
                    note.innerHTML = 'Line heights represent relative intensities. UV (ultraviolet) and IR (infrared) lines are shown in shaded regions.<br>Press ESC or click outside to close.';
                } else {
                    note.innerHTML = 'Line heights represent relative intensities. Colors match actual wavelengths in the visible spectrum.<br>Press ESC or click outside to close.';
                }
                modalContent.appendChild(note);
                
                // Add data source reference
                const reference = document.createElement('p');
                reference.style.marginTop = '20px';
                reference.style.textAlign = 'center';
                reference.style.color = '#666';
                reference.style.fontSize = '12px';
                const elementNameLower = elementData.name.toLowerCase();
                reference.innerHTML = `Data source: <a href="https://www.nist.gov/pml/atomic-spectra-database" target="_blank" style="color: #4fc3f7; text-decoration: none;">NIST Atomic Spectra Database</a> | <a href="https://www.physics.nist.gov/PhysRefData/Handbook/Tables/${elementNameLower}table2.htm" target="_blank" style="color: #4fc3f7; text-decoration: none;">View full ${elementData.name} data at NIST</a>`;
                modalContent.appendChild(reference);
                
                modal.classList.add('active');
                
                // Close on ESC key
                const escHandler = (e) => {
                    if (e.key === 'Escape') {
                        modal.classList.remove('active');
                        document.removeEventListener('keydown', escHandler);
                    }
                };
                document.addEventListener('keydown', escHandler);
                
                // Close on click outside
                modal.onclick = (e) => {
                    if (e.target === modal) {
                        modal.classList.remove('active');
                    }
                };
            }

            onWindowResize() {
                this.camera.aspect = window.innerWidth / window.innerHeight;
                this.camera.updateProjectionMatrix();
                this.renderer.setSize(window.innerWidth, window.innerHeight);
            }

            animate() {
                requestAnimationFrame(() => this.animate());
                this.updateScales();
                this.controls.update();
                this.renderer.render(this.scene, this.camera);
            }
        }

        const app = new PeriodicTableApp();
        app.init();
    </script>
</body>
</html>