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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, viewport-fit=cover">
    <title>K1RL QUASAR — Quantitative Intelligence Observatory</title>
    <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@200;300;400;500;600;700&family=Space+Mono:wght@400;700&display=swap" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
    <!-- ✅ MIGRATED: Ably removed — now using Redis-backed HTTP polling via HF Spaces API -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js"></script>
    <style>

        /* ============ RESET & VARIABLES ============ */

        * {

            margin: 0;

            padding: 0;

            box-sizing: border-box;

            -webkit-tap-highlight-color: transparent;

        }



        :root {

            /* Base font - DESKTOP FIRST */

            font-size: 16px;

            

            /* ===== TYPOGRAPHY SCALE ===== */

            --text-xs: 0.75rem;

            --text-sm: 0.875rem;

            --text-base: 1rem;

            --text-md: 1.25rem;

            --text-lg: 1.5rem;

            --text-xl: 2rem;

            --text-2xl: 2.5rem;

            --text-3xl: 3.5rem;

            --text-4xl: 5rem;

            --text-hero: 6rem;

            

            /* Font weights */

            --weight-light: 200;

            --weight-regular: 400;

            --weight-medium: 500;

            --weight-semibold: 600;

            --weight-bold: 700;

            

            /* Letter spacing */

            --tracking-tight: -0.02em;

            --tracking-normal: 0;

            --tracking-wide: 0.05em;

            --tracking-wider: 0.1em;

            --tracking-widest: 0.2em;

            --tracking-ultra: 0.4em;

            

            /* Line heights */

            --leading-none: 1;

            --leading-tight: 1.1;

            --leading-snug: 1.2;

            --leading-normal: 1.4;

            --leading-relaxed: 1.6;

            

            /* Colors */

            --bg-deep: #000810;

            --bg-space: #001020;

            --accent-cyan: #00d4ff;

            --accent-cyan-dim: rgba(0, 212, 255, 0.3);

            --accent-cyan-glow: rgba(0, 212, 255, 0.15);

            --success: #00ff88;

            --danger: #ff4466;

            --warning: #ffaa00;

            --text-primary: #ffffff;

            --text-secondary: rgba(255, 255, 255, 0.7);

            --text-muted: rgba(255, 255, 255, 0.5);

            --text-dim: rgba(255, 255, 255, 0.35);

            --glass-bg: rgba(0, 20, 40, 0.4);

            --glass-border: rgba(0, 212, 255, 0.2);

        }



        body {

            font-family: 'Outfit', sans-serif;

            background: var(--bg-deep);

            color: var(--text-primary);

            line-height: var(--leading-normal);

            -webkit-font-smoothing: antialiased;

            -moz-osx-font-smoothing: grayscale;

            width: 100%;

            max-width: 100vw;

            overflow-x: hidden;

        }



        /* ============ TYPOGRAPHY UTILITIES ============ */

        .font-mono { font-family: 'Space Mono', monospace; }

        .tracking-tight { letter-spacing: var(--tracking-tight); }

        .tracking-normal { letter-spacing: var(--tracking-normal); }

        .tracking-wide { letter-spacing: var(--tracking-wide); }

        .tracking-wider { letter-spacing: var(--tracking-wider); }

        .tracking-widest { letter-spacing: var(--tracking-widest); }

        .tracking-ultra { letter-spacing: var(--tracking-ultra); }

        

        .text-xs { font-size: var(--text-xs); }

        .text-sm { font-size: var(--text-sm); }

        .text-base { font-size: var(--text-base); }

        .text-md { font-size: var(--text-md); }

        .text-lg { font-size: var(--text-lg); }

        .text-xl { font-size: var(--text-xl); }

        .text-2xl { font-size: var(--text-2xl); }

        .text-3xl { font-size: var(--text-3xl); }

        .text-4xl { font-size: var(--text-4xl); }

        .text-hero { font-size: var(--text-hero); }

        

        .weight-light { font-weight: var(--weight-light); }

        .weight-regular { font-weight: var(--weight-regular); }

        .weight-medium { font-weight: var(--weight-medium); }

        .weight-semibold { font-weight: var(--weight-semibold); }

        .weight-bold { font-weight: var(--weight-bold); }



        /* ============ THREE.JS BACKGROUND ============ */

        #canvas-container {

            position: fixed;

            top: 0;

            left: 0;

            width: 100%;

            height: 100%;

            z-index: 0;

            pointer-events: none;

        }



        .gradient-overlay {

            position: fixed;

            top: 0;

            left: 0;

            width: 100%;

            height: 100%;

            background: radial-gradient(ellipse at 50% 100%, transparent 0%, rgba(0,8,16,0.7) 50%, rgba(0,8,16,0.95) 100%);

            z-index: 1;

            pointer-events: none;

        }



        /* ============ LAYOUT - DESKTOP FIRST ============ */

        .main-content {

            position: relative;

            z-index: 10;

            max-width: 1400px;

            margin: 0 auto;

            padding: 100px 40px 40px;

            width: 100%;

        }



        /* ============ NAVIGATION ============ */

        .nav-bar {

            position: fixed;

            top: 0;

            left: 0;

            right: 0;

            z-index: 100;

            display: flex;

            justify-content: space-between;

            align-items: center;

            padding: 20px 40px;

            background: rgba(0,8,16,0.85);

            backdrop-filter: blur(12px);

            border-bottom: 1px solid rgba(0,212,255,0.1);

        }



        .nav-logo {

            font-size: var(--text-lg);

            font-weight: var(--weight-light);

            letter-spacing: var(--tracking-widest);

            color: var(--text-primary);

        }



        .nav-logo span {

            color: var(--accent-cyan);

            font-weight: var(--weight-semibold);

        }



        .nav-links {

            display: flex;

            gap: 40px;

            list-style: none;

        }



        .nav-links a {

            color: var(--text-secondary);

            text-decoration: none;

            font-size: var(--text-sm);

            font-weight: var(--weight-medium);

            letter-spacing: var(--tracking-wider);

            transition: color 0.2s;

        }



        .nav-links a:hover {

            color: var(--accent-cyan);

        }



        /* ============ LIVE INDICATOR ============ */

        .live-indicator {

            position: fixed;

            top: 20px;

            right: 40px;

            z-index: 101;

            display: flex;

            align-items: center;

            gap: 10px;

            padding: 10px 20px;

            background: rgba(0, 255, 136, 0.08);

            border: 1px solid rgba(0, 255, 136, 0.2);

            border-radius: 100px;

            backdrop-filter: blur(8px);

        }



        .live-dot {

            width: 8px;

            height: 8px;

            background: var(--success);

            border-radius: 50%;

            animation: pulse 1.5s infinite;

        }



        .live-text {

            font-size: var(--text-xs);

            font-weight: var(--weight-semibold);

            letter-spacing: var(--tracking-wider);

            color: var(--success);

            font-family: 'Space Mono', monospace;

        }



        /* ============ HEADER ============ */

        .header {

            text-align: center;

            margin-bottom: 32px;

        }



        .logo-container {

            display: flex;

            align-items: center;

            justify-content: center;

            gap: 20px;

            margin-bottom: 16px;

        }



        .logo-icon {

            width: 56px;

            height: 56px;

            position: relative;

        }



        .logo-icon::before {

            content: '';

            position: absolute;

            inset: 0;

            border: 2px solid var(--accent-cyan);

            border-radius: 50%;

            animation: pulse-ring 2s infinite;

        }



        .logo-icon::after {

            content: '';

            position: absolute;

            inset: 14px;

            background: var(--accent-cyan);

            border-radius: 50%;

            box-shadow: 0 0 30px var(--accent-cyan);

        }



        .logo-text {

            font-size: var(--text-hero);

            font-weight: var(--weight-light);

            letter-spacing: var(--tracking-ultra);

            color: var(--text-primary);

            text-shadow: 0 0 40px var(--accent-cyan-dim);

            line-height: var(--leading-none);

        }



        .logo-text span {

            font-weight: var(--weight-bold);

            color: var(--accent-cyan);

        }



        .subtitle {

            font-size: var(--text-sm);

            font-weight: var(--weight-light);

            letter-spacing: var(--tracking-widest);

            text-transform: uppercase;

            color: var(--text-muted);

            margin-bottom: 8px;

        }



        .timestamp {

            font-family: 'Space Mono', monospace;

            font-size: var(--text-xs);

            color: var(--text-dim);

            letter-spacing: var(--tracking-wide);

        }



        .inst-bar {

            text-align: center;

            font-family: 'Space Mono', monospace;

            font-size: var(--text-xs);

            letter-spacing: var(--tracking-wider);

            color: rgba(255,255,255,0.3);

            margin: 20px 0 32px;

        }



        /* ============ GLASS CARDS ============ */

        .glass-card {

            background: var(--glass-bg);

            backdrop-filter: blur(16px);

            border: 1px solid var(--glass-border);

            border-radius: 24px;

            padding: 28px;

            transition: all 0.3s ease;

            display: flex;

            flex-direction: column;

        }



        .glass-card:hover {

            border-color: var(--accent-cyan-dim);

            box-shadow: 0 20px 40px rgba(0, 212, 255, 0.1);

        }



        .card-title {

            font-family: 'Outfit', sans-serif;

            font-size: var(--text-xs);

            font-weight: var(--weight-semibold);

            letter-spacing: var(--tracking-wider);

            text-transform: uppercase;

            color: var(--text-muted);

            margin-bottom: 20px;

            display: flex;

            align-items: center;

            gap: 10px;

        }



        .card-title::before {

            content: '';

            width: 4px;

            height: 4px;

            background: var(--accent-cyan);

            border-radius: 50%;

            box-shadow: 0 0 10px var(--accent-cyan);

        }



        .card-content {

            flex: 1;

            display: flex;

            flex-direction: column;

        }



        /* ============ SIGNAL PANEL ============ */

        .signal-panel {

            text-align: center;

            padding: 40px;

            margin-bottom: 32px;

        }



        .signal-label {

            font-family: 'Outfit', sans-serif;

            font-size: var(--text-sm);

            font-weight: var(--weight-medium);

            letter-spacing: var(--tracking-widest);

            text-transform: uppercase;

            color: var(--text-muted);

            margin-bottom: 16px;

        }



        .signal-value {

            font-size: var(--text-4xl);

            font-weight: var(--weight-bold);

            letter-spacing: var(--tracking-wider);

            margin-bottom: 20px;

            line-height: var(--leading-tight);

        }



        .signal-buy {

            color: var(--success);

            text-shadow: 0 0 40px var(--success), 0 0 80px rgba(0, 255, 136, 0.2);

        }



        .signal-sell {

            color: var(--danger);

            text-shadow: 0 0 40px var(--danger), 0 0 80px rgba(255, 68, 102, 0.2);

        }



        .signal-neutral {

            color: var(--warning);

            text-shadow: 0 0 40px var(--warning), 0 0 80px rgba(255, 170, 0, 0.2);

        }



        .signal-stats {

            font-family: 'Space Mono', monospace;

            font-size: var(--text-sm);

            color: var(--text-secondary);

            letter-spacing: var(--tracking-wide);

            display: flex;

            flex-wrap: wrap;

            justify-content: center;

            gap: 16px;

            margin-bottom: 20px;

        }



        /* ============ FORCE BALANCE - COMPLETE REDESIGN ============ */

        .force-balance {

            margin-top: 32px;

            width: 100%;

            max-width: 600px;

            margin-left: auto;

            margin-right: auto;

            padding: 0 20px;

        }



        /* Pressure Labels Row */

        .pressure-labels {

            display: grid;

            grid-template-columns: 1fr 1fr;

            gap: 40px;

            margin-bottom: 16px;

        }



        .pressure-item {

            display: flex;

            flex-direction: column;

        }



        .pressure-item.buy {

            align-items: flex-start;

        }



        .pressure-item.sell {

            align-items: flex-end;

            text-align: right;

        }



        .pressure-label {

            font-family: 'Outfit', sans-serif;

            font-size: var(--text-xs);

            font-weight: var(--weight-semibold);

            letter-spacing: var(--tracking-wider);

            text-transform: uppercase;

            color: var(--text-muted);

            margin-bottom: 6px;

        }



        .pressure-value {

            font-family: 'Space Mono', monospace;

            font-size: var(--text-xl);

            font-weight: var(--weight-bold);

            letter-spacing: var(--tracking-wide);

        }



        .pressure-value.buy-value {

            color: #4fc3f7;

            text-shadow: 0 0 20px rgba(79, 195, 247, 0.3);

        }



        .pressure-value.sell-value {

            color: #ef5350;

            text-shadow: 0 0 20px rgba(239, 83, 80, 0.3);

        }



        /* Pressure Gauge Track */

        .pressure-gauge {

            position: relative;

            margin: 24px 0;

        }



        .gauge-track {

            position: relative;

            height: 32px;

            background: linear-gradient(90deg, 

                rgba(21, 101, 192, 0.15) 0%, 

                rgba(0, 0, 0, 0.4) 50%, 

                rgba(198, 40, 40, 0.15) 100%);

            border-radius: 8px;

            border: 1px solid rgba(255, 255, 255, 0.08);

            overflow: visible;

        }



        .gauge-fill-buy {

            position: absolute;

            top: 2px;

            bottom: 2px;

            left: 2px;

            right: 50%;

            background: linear-gradient(90deg, #1565C0, #42A5F5);

            border-radius: 6px 0 0 6px;

            transform-origin: right center;

            transform: scaleX(0);

            transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);

        }



        .gauge-fill-sell {

            position: absolute;

            top: 2px;

            bottom: 2px;

            left: 50%;

            right: 2px;

            background: linear-gradient(90deg, #ef5350, #c62828);

            border-radius: 0 6px 6px 0;

            transform-origin: left center;

            transform: scaleX(0);

            transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);

        }



        /* Center Line */

        .gauge-center {

            position: absolute;

            left: 50%;

            top: -6px;

            bottom: -6px;

            width: 2px;

            background: rgba(255, 255, 255, 0.3);

            transform: translateX(-50%);

            z-index: 5;

        }



        .gauge-center::before {

            content: '';

            position: absolute;

            top: 0;

            left: 50%;

            transform: translateX(-50%);

            width: 8px;

            height: 8px;

            background: rgba(255, 255, 255, 0.4);

            border-radius: 50%;

        }



        .gauge-center::after {

            content: '';

            position: absolute;

            bottom: 0;

            left: 50%;

            transform: translateX(-50%);

            width: 8px;

            height: 8px;

            background: rgba(255, 255, 255, 0.4);

            border-radius: 50%;

        }



        /* Position Marker */

        .gauge-marker {

            position: absolute;

            top: 50%;

            left: 50%;

            transform: translate(-50%, -50%);

            width: 20px;

            height: 20px;

            background: white;

            border: 3px solid rgba(0, 0, 0, 0.8);

            border-radius: 50%;

            z-index: 10;

            box-shadow: 

                0 0 20px rgba(255, 255, 255, 0.5),

                0 2px 8px rgba(0, 0, 0, 0.4);

            transition: left 0.5s cubic-bezier(0.4, 0, 0.2, 1);

        }



        .gauge-marker.buy-dominant {

            background: #4fc3f7;

            border-color: #1565C0;

        }



        .gauge-marker.sell-dominant {

            background: #ef5350;

            border-color: #c62828;

        }



        /* Scale Labels */

        .gauge-scale {

            display: flex;

            justify-content: space-between;

            margin-top: 10px;

            padding: 0 4px;

        }



        .gauge-scale span {

            font-family: 'Space Mono', monospace;

            font-size: 0.65rem;

            color: rgba(255, 255, 255, 0.25);

            letter-spacing: 0.05em;

        }



        .gauge-scale span:nth-child(3) {

            color: rgba(255, 255, 255, 0.4);

            font-weight: 700;

        }



        /* Net Position */

        .net-position {

            display: flex;

            align-items: center;

            justify-content: center;

            gap: 12px;

            margin-top: 24px;

            padding-top: 20px;

            border-top: 1px solid rgba(255, 255, 255, 0.06);

        }



        .net-position-label {

            font-family: 'Outfit', sans-serif;

            font-size: var(--text-xs);

            font-weight: var(--weight-semibold);

            letter-spacing: var(--tracking-wider);

            text-transform: uppercase;

            color: var(--text-dim);

        }



        .net-position-value {

            font-family: 'Space Mono', monospace;

            font-size: var(--text-xl);

            font-weight: var(--weight-bold);

            letter-spacing: var(--tracking-wide);

            min-width: 80px;

            text-align: center;

        }



        .net-position-value.positive {

            color: #4fc3f7;

            text-shadow: 0 0 15px rgba(79, 195, 247, 0.3);

        }



        .net-position-value.negative {

            color: #ef5350;

            text-shadow: 0 0 15px rgba(239, 83, 80, 0.3);

        }



        .net-position-value.neutral {

            color: var(--text-secondary);

        }



        /* ============ GRID LAYOUTS - IMPROVED ============ */

        .grid-3 {

            display: grid;

            grid-template-columns: repeat(3, 1fr);

            gap: 28px;

            margin-bottom: 28px;

        }



        /* ============ METRIC ROWS - FILL SPACE ============ */

        .metric-row {

            display: flex;

            justify-content: space-between;

            align-items: baseline;

            padding: 16px 0;

            border-bottom: 1px solid rgba(255,255,255,0.03);

        }



        .metric-row:last-child {

            border-bottom: none;

            padding-bottom: 0;

        }



        .metric-row:first-child {

            padding-top: 0;

        }



        .metric-label {

            font-family: 'Outfit', sans-serif;

            font-size: var(--text-sm);

            font-weight: var(--weight-regular);

            color: var(--text-secondary);

            letter-spacing: var(--tracking-wide);

        }



        .metric-value {

            font-family: 'Space Mono', monospace;

            font-size: var(--text-base);

            font-weight: var(--weight-semibold);

            color: var(--text-primary);

            letter-spacing: var(--tracking-normal);

        }



        .metric-value.positive { color: var(--success); }

        .metric-value.warning { color: var(--warning); }

        .metric-value.negative { color: var(--danger); }



        /* ============ BIG NUMBERS ============ */

        .big-number {

            font-family: 'Space Mono', monospace;

            font-size: var(--text-2xl);

            font-weight: var(--weight-bold);

            text-align: center;

            color: var(--accent-cyan);

            text-shadow: 0 0 30px var(--accent-cyan-dim);

            margin: 20px 0;

            line-height: var(--leading-tight);

            letter-spacing: var(--tracking-wide);

        }



        /* ============ PROCESS STATUS - FILL SPACE ============ */

        .process-status {

            text-align: center;

            padding: 24px;

            margin-top: auto;

            border-radius: 16px;

        }



        .process-ok {

            background: rgba(0,255,136,0.08);

            border: 1px solid rgba(0,255,136,0.15);

        }



        .process-warning {

            background: rgba(255,68,102,0.08);

            border: 1px solid rgba(255,68,102,0.15);

        }



        .process-label {

            font-family: 'Outfit', sans-serif;

            font-size: var(--text-xs);

            font-weight: var(--weight-medium);

            letter-spacing: var(--tracking-wider);

            text-transform: uppercase;

            color: var(--text-muted);

            margin-bottom: 10px;

        }



        .process-value {

            font-family: 'Space Mono', monospace;

            font-size: var(--text-2xl);

            font-weight: var(--weight-bold);

            line-height: var(--leading-tight);

        }



        .process-ok .process-value { color: var(--success); }

        .process-warning .process-value { color: var(--danger); }



        /* ============ STATUS BADGES ============ */

        .status-badge {

            display: inline-flex;

            align-items: center;

            gap: 8px;

            padding: 6px 14px;

            border-radius: 100px;

            font-family: 'Outfit', sans-serif;

            font-size: var(--text-xs);

            font-weight: var(--weight-semibold);

            text-transform: uppercase;

            letter-spacing: var(--tracking-wider);

        }



        .status-active {

            background: rgba(0,255,136,0.1);

            color: var(--success);

            border: 1px solid rgba(0,255,136,0.2);

        }

        .status-unknown {

            background: rgba(255,170,0,0.1);

            color: #ffaa00;

            border: 1px solid rgba(255,170,0,0.3);

        }



        .status-inactive {

            background: rgba(255,68,102,0.1);

            color: var(--danger);

            border: 1px solid rgba(255,68,102,0.2);

        }



        .status-badge::before {

            content: '';

            width: 6px;

            height: 6px;

            border-radius: 50%;

            background: currentColor;

        }



        /* ============ PROGRESS BAR ============ */

        .progress-container {

            margin-top: 16px;

        }



        .progress-bar {

            width: 100%;

            height: 8px;

            background: rgba(255,255,255,0.06);

            border-radius: 4px;

            overflow: hidden;

        }



        .progress-fill {

            height: 100%;

            background: linear-gradient(90deg, var(--accent-cyan), var(--success));

            border-radius: 4px;

            transition: width 0.4s ease;

        }



        /* ============ LOG CONTAINER ============ */

        .log-container {

            background: rgba(0,0,0,0.25);

            border-radius: 16px;

            padding: 20px;

            height: 240px;

            overflow-y: auto;

            font-family: 'Space Mono', monospace;

            font-size: var(--text-xs);

            line-height: var(--leading-relaxed);

            border: 1px solid rgba(255,255,255,0.03);

        }



        .log-line {

            padding: 5px 0;

            word-break: break-all;

            color: var(--text-secondary);

        }



        .log-error { color: var(--danger); }

        .log-warning { color: var(--warning); }

        .log-info { color: var(--success); }



        /* ============ ACCURACY CHART ============ */

        .accuracy-header {

            display: flex;

            justify-content: space-between;

            align-items: flex-start;

            flex-wrap: wrap;

            gap: 20px;

            margin-bottom: 24px;

        }



        .accuracy-metrics {

            display: flex;

            gap: 32px;

            flex-wrap: wrap;

        }



        .accuracy-stat {

            text-align: center;

        }



        .accuracy-stat-label {

            font-family: 'Outfit', sans-serif;

            font-size: var(--text-xs);

            font-weight: var(--weight-medium);

            letter-spacing: var(--tracking-wider);

            text-transform: uppercase;

            color: var(--text-muted);

            margin-bottom: 6px;

        }



        .accuracy-stat-value {

            font-family: 'Space Mono', monospace;

            font-size: var(--text-xl);

            font-weight: var(--weight-bold);

        }



        .accuracy-legend {

            display: flex;

            gap: 20px;

            align-items: center;

        }



        .legend-item {

            display: flex;

            align-items: center;

            gap: 8px;

            font-family: 'Outfit', sans-serif;

            font-size: var(--text-xs);

            color: var(--text-secondary);

        }



        .legend-dot {

            width: 8px;

            height: 8px;

            border-radius: 50%;

        }



        .legend-dot.current { background: var(--success); }

        .legend-dot.average { background: var(--accent-cyan); }

        .legend-dot.trend { background: var(--warning); }



        .accuracy-trend-badge {

            display: inline-flex;

            align-items: center;

            gap: 8px;

            padding: 8px 16px;

            border-radius: 100px;

            font-family: 'Outfit', sans-serif;

            font-size: var(--text-xs);

            font-weight: var(--weight-semibold);

            letter-spacing: var(--tracking-wider);

            text-transform: uppercase;

        }



        .accuracy-trend-badge.rising {

            background: rgba(0, 255, 136, 0.1);

            border: 1px solid rgba(0, 255, 136, 0.2);

            color: var(--success);

        }



        .accuracy-trend-badge.stable {

            background: rgba(0, 212, 255, 0.1);

            border: 1px solid rgba(0, 212, 255, 0.2);

            color: var(--accent-cyan);

        }



        .accuracy-trend-badge.declining {

            background: rgba(255, 68, 102, 0.1);

            border: 1px solid rgba(255, 68, 102, 0.2);

            color: var(--danger);

        }



        .trend-arrow {

            font-weight: var(--weight-bold);

            font-size: var(--text-sm);

        }



        .chart-container {

            height: 200px;

            width: 100%;

            margin-top: 16px;

        }



        /* ============ VISITOR BADGE ============ */

        .visitor-badge {

            position: fixed;

            bottom: 20px;

            left: 24px;

            background: rgba(0,20,30,0.9);

            border: 1px solid rgba(0,212,170,0.2);

            border-radius: 12px;

            padding: 12px 20px;

            display: flex;

            align-items: center;

            gap: 14px;

            z-index: 200;

            backdrop-filter: blur(12px);

        }



        .visitor-dot {

            width: 10px;

            height: 10px;

            background: #00d4aa;

            border-radius: 50%;

            animation: pulse 2s infinite;

        }



        .visitor-count {

            color: #00d4aa;

            font-size: var(--text-base);

            font-weight: var(--weight-bold);

            font-family: 'Space Mono', monospace;

        }



        .visitor-label {

            font-family: 'Outfit', sans-serif;

            color: rgba(255,255,255,0.5);

            font-size: var(--text-xs);

            text-transform: uppercase;

            letter-spacing: var(--tracking-wider);

        }



        .visitor-total {

            color: rgba(255,255,255,0.3);

            font-size: 0.7rem;

            display: block;

            font-family: 'Space Mono', monospace;

        }



        /* ============ CONNECTION STATUS ============ */

        .connection-status {

            position: fixed;

            bottom: 20px;

            right: 24px;

            padding: 10px 20px;

            border-radius: 100px;

            font-size: var(--text-xs);

            font-family: 'Space Mono', monospace;

            backdrop-filter: blur(12px);

            z-index: 200;

            letter-spacing: var(--tracking-wide);

        }



        .connection-ok {

            background: rgba(0,255,136,0.1);

            border: 1px solid rgba(0,255,136,0.2);

            color: var(--success);

        }



        .connection-error {

            background: rgba(255,68,102,0.1);

            border: 1px solid rgba(255,68,102,0.2);

            color: var(--danger);

        }



        /* ============ LOADING OVERLAY ============ */

        .loading-overlay {

            position: fixed;

            bottom: 90px;

            left: 24px;

            background: rgba(0,20,30,0.95);

            border: 1px solid rgba(0,212,255,0.2);

            border-radius: 12px;

            padding: 14px 24px;

            display: flex;

            align-items: center;

            gap: 14px;

            z-index: 300;

            backdrop-filter: blur(12px);

            font-size: var(--text-sm);

        }



        .loading-spinner {

            width: 18px;

            height: 18px;

            border: 2px solid rgba(0,212,255,0.2);

            border-top-color: var(--accent-cyan);

            border-radius: 50%;

            animation: spin 0.8s linear infinite;

        }



        .hidden {

            display: none !important;

        }



        /* ============ FOOTER ============ */

        .footer {

            text-align: center;

            padding: 50px 24px 24px;

            color: var(--text-dim);

            font-size: var(--text-xs);

            letter-spacing: var(--tracking-wider);

        }



        .footer p {

            margin-bottom: 6px;

        }



        /* ============ ANIMATIONS ============ */

        @keyframes pulse {

            0%, 100% { opacity: 1; transform: scale(1); }

            50% { opacity: 0.5; transform: scale(0.8); }

        }



        @keyframes pulse-ring {

            0% { transform: scale(1); opacity: 1; }

            100% { transform: scale(1.5); opacity: 0; }

        }



        @keyframes spin {

            to { transform: rotate(360deg); }

        }



        @keyframes fadeInUp {

            from {

                opacity: 0;

                transform: translateY(20px);

            }

            to {

                opacity: 1;

                transform: translateY(0);

            }

        }



        .glass-card {

            animation: fadeInUp 0.5s ease forwards;

        }



        .grid-3 .glass-card:nth-child(1) { animation-delay: 0.1s; }

        .grid-3 .glass-card:nth-child(2) { animation-delay: 0.15s; }

        .grid-3 .glass-card:nth-child(3) { animation-delay: 0.2s; }



        /* ============ TABLET STYLES (1024px and below) ============ */

        @media (max-width: 1024px) {

            .grid-3 {

                grid-template-columns: repeat(2, 1fr);

                gap: 24px;

            }

        }



        /* ============ MOBILE STYLES (768px and below) ============ */

        @media (max-width: 768px) {

            :root {

                font-size: 14px;

            }



            .main-content {

                padding: 80px 16px 20px;

            }



            .nav-bar {

                padding: 14px 16px;

            }



            .nav-links {

                display: none;

            }



            .nav-logo {

                font-size: var(--text-base);

                letter-spacing: var(--tracking-wider);

            }



            .live-indicator {

                top: 14px;

                right: 16px;

                padding: 8px 14px;

            }



            .logo-icon {

                width: 40px;

                height: 40px;

            }



            .logo-icon::after {

                inset: 10px;

            }



            .logo-text {

                font-size: 3rem;

                letter-spacing: 0.25em;

            }



            .subtitle {

                font-size: 0.7rem;

                letter-spacing: 0.2em;

            }



            .grid-3 {

                grid-template-columns: 1fr;

                gap: 16px;

            }



            .glass-card {

                padding: 20px;

                border-radius: 20px;

            }



            .signal-panel {

                padding: 24px 16px;

            }



            .signal-value {

                font-size: var(--text-2xl);

            }



            .signal-stats {

                font-size: var(--text-xs);

                gap: 12px;

            }



            /* Force Balance Mobile */

            .force-balance {

                padding: 0 10px;

            }



            .pressure-labels {

                gap: 20px;

            }



            .pressure-value {

                font-size: var(--text-lg);

            }



            .gauge-track {

                height: 28px;

            }



            .gauge-marker {

                width: 16px;

                height: 16px;

            }



            .net-position-value {

                font-size: var(--text-lg);

            }



            .accuracy-header {

                flex-direction: column;

                align-items: flex-start;

            }



            .accuracy-metrics {

                gap: 24px;

            }



            .accuracy-stat-value {

                font-size: var(--text-lg);

            }



            .big-number {

                font-size: var(--text-xl);

            }



            .visitor-badge {

                left: 16px;

                bottom: 16px;

                padding: 10px 16px;

            }



            .connection-status {

                right: 16px;

                bottom: 16px;

                padding: 8px 16px;

            }

        }



        /* ============ SMALL MOBILE (480px and below) ============ */

        @media (max-width: 480px) {

            :root {

                font-size: 12px;

            }



            .logo-icon {

                width: 32px;

                height: 32px;

            }



            .logo-icon::after {

                inset: 8px;

            }



            .logo-text {

                font-size: 2.2rem;

                letter-spacing: 0.15em;

            }



            .subtitle {

                font-size: 0.6rem;

                letter-spacing: 0.15em;

            }



            .force-balance {

                margin-top: 20px;

                padding: 0 5px;

            }



            .pressure-labels {

                gap: 10px;

            }



            .pressure-label {

                font-size: 0.65rem;

            }



            .pressure-value {

                font-size: var(--text-md);

            }



            .gauge-track {

                height: 24px;

            }



            .gauge-scale span {

                font-size: 0.55rem;

            }



            .net-position {

                flex-direction: column;

                gap: 8px;

            }



            .accuracy-metrics {

                gap: 16px;

            }



            .accuracy-legend {

                flex-wrap: wrap;

                gap: 12px;

            }

        }



        /* ============ VERY SMALL MOBILE (360px and below) ============ */

        @media (max-width: 360px) {

            :root {

                font-size: 11px;

            }

        }



        /* ============ HOVER STATES - DESKTOP ONLY ============ */

        @media (hover: hover) and (pointer: fine) {

            .glass-card:hover {

                transform: translateY(-2px);

                box-shadow: 0 24px 48px rgba(0, 212, 255, 0.12);

            }



            .nav-links a:hover {

                color: var(--accent-cyan);

            }

        }



        /* Disable hover effects on touch devices */

        @media (hover: none) {

            .glass-card:hover {

                transform: none;

                box-shadow: none;

            }

        }

    </style>
</head>
<body>
    <!-- Three.js Canvas -->
    <div id="canvas-container">
        <canvas id="three-canvas"></canvas>
    </div>
    <div class="gradient-overlay"></div>

    <!-- Loading Overlay -->
    <div class="loading-overlay" id="loadingOverlay">
        <div class="loading-spinner"></div>
        <span id="loadingText">Initializing Observatory...</span>
    </div>

    <!-- Connection Status -->
    <div class="connection-status connection-ok" id="connectionStatus">● Connected</div>

    <!-- Visitor Counter -->
    <div class="visitor-badge">
        <div class="visitor-dot"></div>
        <div>
            <span class="visitor-count" id="activeVisitors">—</span>
            <span class="visitor-label">Online</span>
            <span class="visitor-total" id="totalVisitors">— total</span>
        </div>
    </div>

    <!-- Navigation -->
    <nav class="nav-bar">
        <div class="nav-logo">K1RL <span>QUASAR</span></div>
        <ul class="nav-links">
            <li><a href="#dashboard">Dashboard</a></li>
            <li><a href="#metrics">Metrics</a></li>
            <li><a href="#system">System</a></li>
        </ul>
    </nav>

    <!-- Live Indicator -->
    <div class="live-indicator">
        <div class="live-dot"></div>
        <span class="live-text">LIVE</span>
    </div>

    <!-- Main Content -->
    <div class="main-content">
        <!-- Header -->
        <header class="header" id="dashboard">
            <div class="logo-container">
                <div class="logo-icon"></div>
                <h1 class="logo-text">QU<span>A</span>SAR</h1>
            </div>
            <p class="subtitle">Quantitative Intelligence Observatory</p>
            <p class="timestamp" id="lastUpdate">Last Observation: Initializing...</p>
            <div class="inst-bar" id="instBar">VOLATILITY 75 INDEX │ DERIV</div>
        </header>

        <!-- SIGNAL PANEL -->
        <div class="glass-card signal-panel">
            <div class="card-title">Market Directive — 10M Agent — Last 5 Minutes</div>
            <div class="signal-label">Dominant Signal</div>
            <div class="signal-value signal-neutral" id="dominantSignal">NEUTRAL</div>
            <div class="signal-stats" id="signalStats">
                <span>BUY: 0 (0%)</span> • <span>SELL: 0 (0%)</span> • <span>TOTAL: 0</span>
            </div>
            
            <!-- FORCE BALANCE -->
            <div class="force-balance">
                <!-- Pressure Labels -->
                <div class="pressure-labels">
                    <div class="pressure-item buy">
                        <span class="pressure-label">Buy Pressure</span>
                        <span class="pressure-value buy-value" id="forceBuyValue">0.0%</span>
                    </div>
                    <div class="pressure-item sell">
                        <span class="pressure-label">Sell Pressure</span>
                        <span class="pressure-value sell-value" id="forceSellValue">0.0%</span>
                    </div>
                </div>

                <!-- Pressure Gauge -->
                <div class="pressure-gauge">
                    <div class="gauge-track">
                        <div class="gauge-fill-buy" id="gaugeFillBuy"></div>
                        <div class="gauge-fill-sell" id="gaugeFillSell"></div>
                        <div class="gauge-center"></div>
                        <div class="gauge-marker" id="gaugeMarker"></div>
                    </div>
                    <div class="gauge-scale">
                        <span>100</span>
                        <span>50</span>
                        <span>0</span>
                        <span>50</span>
                        <span>100</span>
                    </div>
                </div>

                <!-- Net Position -->
                <div class="net-position">
                    <span class="net-position-label">Net Position</span>
                    <span class="net-position-value neutral" id="netPositionValue">0.0</span>
                </div>
            </div>
        </div>

        <!-- TRAINING & REWARDS -->
        <div class="grid-3" id="metrics">
            <!-- Training Progression -->
            <div class="glass-card">
                <div class="card-title">Training Progression</div>
                <div class="card-content">
                    <div class="metric-row">
                        <span class="metric-label">Iterations Completed</span>
                        <span class="metric-value" id="trainingSteps" style="color: #00ff88;">—</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">Actor Loss</span>
                        <span class="metric-value" id="actorLoss" style="color: #00ff88;">—</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">Critic Loss</span>
                        <span class="metric-value" id="criticLoss">—</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">AVN Loss</span>
                        <span class="metric-value" id="avnLoss">—</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">AVN Accuracy</span>
                        <span class="metric-value" id="avnAccuracy" style="color: #00d4aa;">—</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">Buffer Capacity</span>
                        <span class="metric-value" id="bufferSize">—</span>
                    </div>
                </div>
            </div>

            <!-- Reward Mechanisms -->
            <div class="glass-card">
                <div class="card-title">Reward Mechanisms</div>
                <div class="card-content">
                    <div class="metric-row">
                        <span class="metric-label">Matched Signals</span>
                        <span class="metric-value positive" id="matchedRewards">—</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">Unmatched Signals</span>
                        <span class="metric-value warning" id="unmatchedRewards">—</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">Duplicate Entries</span>
                        <span class="metric-value" id="duplicates">—</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">Match Efficacy</span>
                        <span class="metric-value" id="matchRate">—</span>
                    </div>
                </div>
            </div>

            <!-- Service Registry -->
            <div class="glass-card" id="system">
                <div class="card-title">Service Registry</div>
                <div class="card-content">
                    <div class="metric-row">
                        <span class="metric-label">Quasar Engine</span>
                        <span class="status-badge status-active" id="statusQuasar">Active</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">Feature Pipeline</span>
                        <span class="status-badge status-active" id="statusFeatures">Active</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">Reward System</span>
                        <span class="status-badge status-active" id="statusRewards">Active</span>
                    </div>
                    <div class="process-status process-ok" id="processCount">
                        <div class="process-label">Quasar Processes</div>
                        <div class="process-value" id="processCountValue">1</div>
                    </div>
                </div>
            </div>
        </div>

        <!-- SYSTEM RESOURCES -->
        <div class="grid-3">
            <!-- Computational Load -->
            <div class="glass-card">
                <div class="card-title">Computational Load</div>
                <div class="card-content">
                    <div class="big-number" id="cpuPercent">—%</div>
                    <div class="progress-container">
                        <div class="progress-bar">
                            <div class="progress-fill" id="cpuBar" style="width:0%"></div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Memory Allocation -->
            <div class="glass-card">
                <div class="card-title">Memory Allocation</div>
                <div class="card-content">
                    <div class="big-number" id="memoryPercent">—%</div>
                    <div class="metric-row">
                        <span class="metric-label">Used</span>
                        <span class="metric-value" id="memoryUsed">—/— GB</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">Quasar</span>
                        <span class="metric-value positive" id="quasarMemory">— GB</span>
                    </div>
                </div>
            </div>

            <!-- Latest Checkpoint -->
            <div class="glass-card">
                <div class="card-title">Latest Checkpoint</div>
                <div class="card-content">
                    <div class="metric-row">
                        <span class="metric-label">Filename</span>
                        <span class="metric-value" id="checkpointFile" style="font-size:0.7rem;">—</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">Training Step</span>
                        <span class="metric-value" id="checkpointStep">—</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">Size</span>
                        <span class="metric-value" id="checkpointSize">—</span>
                    </div>
                    <div class="metric-row">
                        <span class="metric-label">Modified</span>
                        <span class="metric-value" id="checkpointModified" style="font-size:0.75rem;">—</span>
                    </div>
                </div>
            </div>
        </div>

        <!-- ACCURACY TRENDS -->
        <div class="glass-card">
            <div class="card-title">Signal Precision Analytics</div>
            <div class="accuracy-header">
                <div class="accuracy-metrics">
                    <div class="accuracy-stat">
                        <div class="accuracy-stat-label">Current</div>
                        <div class="accuracy-stat-value" id="accuracy-current" style="color: var(--success);">—</div>
                    </div>
                    <div class="accuracy-stat">
                        <div class="accuracy-stat-label">Average</div>
                        <div class="accuracy-stat-value" id="accuracy-avg" style="color: var(--accent-cyan);">—</div>
                    </div>
                    <div class="accuracy-stat">
                        <div class="accuracy-stat-label">Last 10</div>
                        <div class="accuracy-stat-value" id="accuracy-last10" style="color: var(--warning);">—</div>
                    </div>
                </div>
                <div class="accuracy-trend-badge stable" id="accuracy-trend">
                    <span class="trend-arrow">―</span>
                    <span>STABLE</span>
                </div>
            </div>
            <div class="chart-container">
                <canvas id="accuracyChart"></canvas>
            </div>
        </div>

        <!-- SYSTEM LOGS -->
        <div class="glass-card">
            <div class="card-title">Quasar Intelligence Stream</div>
            <div class="log-container" id="logContainer">
                <div class="log-line">Awaiting signal intelligence...</div>
            </div>
        </div>

        <!-- HuggingFace Spaces Platform Badge -->
        <div style="position:fixed;bottom:20px;right:20px;z-index:101;padding:8px 16px;background:rgba(255,136,0,0.1);border:1px solid rgba(255,136,0,0.3);border-radius:20px;backdrop-filter:blur(8px);font-size:0.75rem;font-weight:500;color:#ffaa00;letter-spacing:0.05em;">🤗 HuggingFace Spaces</div>

        <!-- Footer -->
        <footer class="footer">
            <p>K1RL QUASAR Observatory v10.0 — HF Spaces Edition</p>
            <p>Reinforcement Learning • Quantitative Intelligence • VOLATILITY 75 Index • Redis-Backed</p>
        </footer>
    </div>

    <script>

        // ==================== THREE.JS WITH REALISTIC EARTH ====================

        (function() {

            const canvas = document.getElementById('three-canvas');

            const isMobile = window.innerWidth <= 768;

            

            const renderer = new THREE.WebGLRenderer({ 

                canvas, 

                antialias: !isMobile,

                alpha: true,

                powerPreference: 'high-performance'

            });

            renderer.setSize(window.innerWidth, window.innerHeight);

            renderer.setPixelRatio(Math.min(window.devicePixelRatio, isMobile ? 1.5 : 2));

            renderer.setClearColor(0x000810, 1);

            

            const scene = new THREE.Scene();

            scene.fog = new THREE.FogExp2(0x000810, 0.0006);

            

            const camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 3000);

            camera.position.set(0, 50, 500);

            camera.lookAt(0, -50, 0);

            

            const textureLoader = new THREE.TextureLoader();

            

            // ===== STARFIELD =====

            const starCount = isMobile ? 800 : 2000;

            const starGeo = new THREE.BufferGeometry();

            const starPos = new Float32Array(starCount * 3);

            for (let i = 0; i < starCount * 3; i += 3) {

                starPos[i] = (Math.random() - 0.5) * 2000;

                starPos[i+1] = (Math.random() - 0.5) * 2000;

                starPos[i+2] = (Math.random() - 0.5) * 2000;

            }

            starGeo.setAttribute('position', new THREE.BufferAttribute(starPos, 3));

            const stars = new THREE.Points(starGeo, new THREE.PointsMaterial({ 

                color: 0xffffff, 

                size: 1.2, 

                transparent: true, 

                opacity: 0.8, 

                sizeAttenuation: true 

            }));

            scene.add(stars);



            // ==================== NEURAL NETWORK WITH PHYSICS ====================

            const nodeCount = isMobile ? 60 : 100;

            const nodes = [];

            

            // Physics constants

            const PHYSICS = {

                // Core forces

                centralGravity: 0.00008,      // Pull towards center

                repulsion: 800,               // Node-to-node repulsion strength

                repulsionDistance: 120,       // Max distance for repulsion

                springStrength: 0.0003,       // Connection spring force

                springRestLength: 100,        // Ideal connection length

                

                // Boundaries

                minRadius: 200,

                maxRadius: 550,

                

                // Damping & limits

                damping: 0.985,               // Velocity decay

                maxVelocity: 2.5,

                

                // Mouse interaction

                mouseRadius: 200,

                mouseForce: 0.15,

                mouseAttract: false,          // false = repel, true = attract

                

                // Connection

                connectionDistance: 140,

                maxConnections: 6

            };

            

            // Mouse tracking

            const mouse = { x: 0, y: 0, z: 0, active: false };

            const mouseVector = new THREE.Vector3();

            const raycaster = new THREE.Raycaster();

            const mouse2D = new THREE.Vector2();

            

            // Create nodes with physics properties

            const nodeGeometry = new THREE.BufferGeometry();

            const nodePositions = new Float32Array(nodeCount * 3);

            const nodeSizes = new Float32Array(nodeCount);

            const nodeColors = new Float32Array(nodeCount * 3);

            

            for (let i = 0; i < nodeCount; i++) {

                const i3 = i * 3;

                const theta = Math.random() * Math.PI * 2;

                const phi = Math.acos(2 * Math.random() - 1);

                const radius = PHYSICS.minRadius + Math.random() * (PHYSICS.maxRadius - PHYSICS.minRadius);

                

                const x = radius * Math.sin(phi) * Math.cos(theta);

                const y = radius * Math.sin(phi) * Math.sin(theta);

                const z = radius * Math.cos(phi);

                

                nodePositions[i3] = x;

                nodePositions[i3 + 1] = y;

                nodePositions[i3 + 2] = z;

                

                // Random mass affects node size and physics response

                const mass = 0.5 + Math.random() * 1.5;

                nodeSizes[i] = isMobile ? mass * 3 : mass * 4;

                

                // Color gradient: cyan to blue based on distance from center

                const colorFactor = Math.random();

                nodeColors[i3] = 0.0 + colorFactor * 0.2;      // R

                nodeColors[i3 + 1] = 0.7 + colorFactor * 0.3;  // G  

                nodeColors[i3 + 2] = 1.0;                       // B

                

                nodes.push({

                    x, y, z,

                    vx: (Math.random() - 0.5) * 0.5,

                    vy: (Math.random() - 0.5) * 0.5,

                    vz: (Math.random() - 0.5) * 0.5,

                    mass: mass,

                    connections: [],

                    energy: 0.5 + Math.random() * 0.5  // For pulse effects

                });

            }

            

            nodeGeometry.setAttribute('position', new THREE.BufferAttribute(nodePositions, 3));

            nodeGeometry.setAttribute('size', new THREE.BufferAttribute(nodeSizes, 1));

            nodeGeometry.setAttribute('color', new THREE.BufferAttribute(nodeColors, 3));

            

            // Custom shader for variable-size glowing nodes

            const nodeShaderMaterial = new THREE.ShaderMaterial({

                uniforms: {

                    time: { value: 0 },

                    pixelRatio: { value: renderer.getPixelRatio() }

                },

                vertexShader: `

                    attribute float size;

                    attribute vec3 color;

                    varying vec3 vColor;

                    varying float vSize;

                    uniform float time;

                    uniform float pixelRatio;

                    

                    void main() {

                        vColor = color;

                        vSize = size;

                        

                        vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);

                        

                        // Subtle pulse based on position

                        float pulse = 1.0 + 0.15 * sin(time * 2.0 + position.x * 0.01 + position.y * 0.01);

                        

                        gl_PointSize = size * pulse * pixelRatio * (300.0 / -mvPosition.z);

                        gl_Position = projectionMatrix * mvPosition;

                    }

                `,

                fragmentShader: `

                    varying vec3 vColor;

                    varying float vSize;

                    

                    void main() {

                        vec2 center = gl_PointCoord - vec2(0.5);

                        float dist = length(center);

                        

                        if (dist > 0.5) discard;

                        

                        // Soft glow falloff

                        float alpha = 1.0 - smoothstep(0.0, 0.5, dist);

                        float glow = exp(-dist * 3.0);

                        

                        vec3 finalColor = vColor + vec3(0.3, 0.5, 0.8) * glow * 0.5;

                        gl_FragColor = vec4(finalColor, alpha * 0.9);

                    }

                `,

                transparent: true,

                depthWrite: false,

                blending: THREE.AdditiveBlending

            });

            

            const nodePoints = new THREE.Points(nodeGeometry, nodeShaderMaterial);

            scene.add(nodePoints);

            

            // Connection lines with varying opacity

            const maxLines = nodeCount * PHYSICS.maxConnections;

            const linePositions = new Float32Array(maxLines * 6);

            const lineColors = new Float32Array(maxLines * 6);

            

            const linesGeometry = new THREE.BufferGeometry();

            linesGeometry.setAttribute('position', new THREE.BufferAttribute(linePositions, 3));

            linesGeometry.setAttribute('color', new THREE.BufferAttribute(lineColors, 3));

            

            const linesMaterial = new THREE.LineBasicMaterial({

                vertexColors: true,

                transparent: true,

                opacity: 0.6,

                blending: THREE.AdditiveBlending

            });

            

            const lines = new THREE.LineSegments(linesGeometry, linesMaterial);

            scene.add(lines);

            

            // Build spatial hash for efficient neighbor lookup

            function buildSpatialHash() {

                const cellSize = PHYSICS.repulsionDistance;

                const hash = {};

                

                for (let i = 0; i < nodeCount; i++) {

                    const node = nodes[i];

                    const cellX = Math.floor(node.x / cellSize);

                    const cellY = Math.floor(node.y / cellSize);

                    const cellZ = Math.floor(node.z / cellSize);

                    const key = `${cellX},${cellY},${cellZ}`;

                    

                    if (!hash[key]) hash[key] = [];

                    hash[key].push(i);

                }

                

                return hash;

            }

            

            // Get neighbors from spatial hash

            function getNeighborCells(x, y, z, cellSize) {

                const cellX = Math.floor(x / cellSize);

                const cellY = Math.floor(y / cellSize);

                const cellZ = Math.floor(z / cellSize);

                const neighbors = [];

                

                for (let dx = -1; dx <= 1; dx++) {

                    for (let dy = -1; dy <= 1; dy++) {

                        for (let dz = -1; dz <= 1; dz++) {

                            neighbors.push(`${cellX + dx},${cellY + dy},${cellZ + dz}`);

                        }

                    }

                }

                

                return neighbors;

            }

            

            // Physics simulation step

            function simulatePhysics(deltaTime) {

                const dt = Math.min(deltaTime, 0.033); // Cap at ~30fps worth

                const spatialHash = buildSpatialHash();

                

                // Reset connections

                for (let i = 0; i < nodeCount; i++) {

                    nodes[i].connections = [];

                }

                

                // Calculate forces for each node

                for (let i = 0; i < nodeCount; i++) {

                    const node = nodes[i];

                    let fx = 0, fy = 0, fz = 0;

                    

                    // 1. Central gravity - pull towards origin

                    const distFromCenter = Math.sqrt(node.x * node.x + node.y * node.y + node.z * node.z);

                    if (distFromCenter > 0.01) {

                        const gravityStrength = PHYSICS.centralGravity * node.mass;

                        fx -= (node.x / distFromCenter) * gravityStrength * distFromCenter;

                        fy -= (node.y / distFromCenter) * gravityStrength * distFromCenter;

                        fz -= (node.z / distFromCenter) * gravityStrength * distFromCenter;

                    }

                    

                    // 2. Boundary force - soft repulsion at edges

                    if (distFromCenter > PHYSICS.maxRadius) {

                        const overflow = distFromCenter - PHYSICS.maxRadius;

                        const boundaryForce = overflow * 0.01;

                        fx -= (node.x / distFromCenter) * boundaryForce;

                        fy -= (node.y / distFromCenter) * boundaryForce;

                        fz -= (node.z / distFromCenter) * boundaryForce;

                    } else if (distFromCenter < PHYSICS.minRadius) {

                        const underflow = PHYSICS.minRadius - distFromCenter;

                        const boundaryForce = underflow * 0.01;

                        fx += (node.x / distFromCenter) * boundaryForce;

                        fy += (node.y / distFromCenter) * boundaryForce;

                        fz += (node.z / distFromCenter) * boundaryForce;

                    }

                    

                    // 3. Node-to-node repulsion (using spatial hash for efficiency)

                    const neighborCells = getNeighborCells(node.x, node.y, node.z, PHYSICS.repulsionDistance);

                    

                    for (const cellKey of neighborCells) {

                        const cellNodes = spatialHash[cellKey];

                        if (!cellNodes) continue;

                        

                        for (const j of cellNodes) {

                            if (i === j) continue;

                            

                            const other = nodes[j];

                            const dx = node.x - other.x;

                            const dy = node.y - other.y;

                            const dz = node.z - other.z;

                            const distSq = dx * dx + dy * dy + dz * dz;

                            const dist = Math.sqrt(distSq);

                            

                            if (dist < PHYSICS.repulsionDistance && dist > 0.1) {

                                // Inverse square repulsion

                                const force = PHYSICS.repulsion / (distSq + 100);

                                fx += (dx / dist) * force / node.mass;

                                fy += (dy / dist) * force / node.mass;

                                fz += (dz / dist) * force / node.mass;

                                

                                // Track connections for springs and rendering

                                if (dist < PHYSICS.connectionDistance && node.connections.length < PHYSICS.maxConnections) {

                                    if (!node.connections.includes(j)) {

                                        node.connections.push(j);

                                    }

                                }

                            }

                        }

                    }

                    

                    // 4. Spring forces along connections

                    for (const j of node.connections) {

                        const other = nodes[j];

                        const dx = other.x - node.x;

                        const dy = other.y - node.y;

                        const dz = other.z - node.z;

                        const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);

                        

                        if (dist > 0.1) {

                            const displacement = dist - PHYSICS.springRestLength;

                            const springForce = displacement * PHYSICS.springStrength;

                            fx += (dx / dist) * springForce;

                            fy += (dy / dist) * springForce;

                            fz += (dz / dist) * springForce;

                        }

                    }

                    

                    // 5. Mouse interaction

                    if (mouse.active) {

                        const mdx = node.x - mouse.x;

                        const mdy = node.y - mouse.y;

                        const mdz = node.z - mouse.z;

                        const mouseDist = Math.sqrt(mdx * mdx + mdy * mdy + mdz * mdz);

                        

                        if (mouseDist < PHYSICS.mouseRadius && mouseDist > 1) {

                            const mouseStrength = (1 - mouseDist / PHYSICS.mouseRadius) * PHYSICS.mouseForce;

                            const direction = PHYSICS.mouseAttract ? -1 : 1;

                            fx += direction * (mdx / mouseDist) * mouseStrength;

                            fy += direction * (mdy / mouseDist) * mouseStrength;

                            fz += direction * (mdz / mouseDist) * mouseStrength;

                        }

                    }

                    

                    // Apply forces to velocity

                    node.vx += fx * dt;

                    node.vy += fy * dt;

                    node.vz += fz * dt;

                    

                    // Damping

                    node.vx *= PHYSICS.damping;

                    node.vy *= PHYSICS.damping;

                    node.vz *= PHYSICS.damping;

                    

                    // Velocity limit

                    const speed = Math.sqrt(node.vx * node.vx + node.vy * node.vy + node.vz * node.vz);

                    if (speed > PHYSICS.maxVelocity) {

                        const scale = PHYSICS.maxVelocity / speed;

                        node.vx *= scale;

                        node.vy *= scale;

                        node.vz *= scale;

                    }

                }

                

                // Update positions

                const positions = nodeGeometry.attributes.position.array;

                const sizes = nodeGeometry.attributes.size.array;

                

                for (let i = 0; i < nodeCount; i++) {

                    const node = nodes[i];

                    const i3 = i * 3;

                    

                    node.x += node.vx;

                    node.y += node.vy;

                    node.z += node.vz;

                    

                    positions[i3] = node.x;

                    positions[i3 + 1] = node.y;

                    positions[i3 + 2] = node.z;

                    

                    // Size varies with connections (more connected = larger)

                    const connectionBonus = node.connections.length * 0.3;

                    sizes[i] = (isMobile ? 3 : 4) * node.mass + connectionBonus;

                }

                

                nodeGeometry.attributes.position.needsUpdate = true;

                nodeGeometry.attributes.size.needsUpdate = true;

            }

            

            // Update connection lines

            function updateConnections() {

                const linePos = linesGeometry.attributes.position.array;

                const lineCol = linesGeometry.attributes.color.array;

                let lineIndex = 0;

                

                for (let i = 0; i < nodeCount; i++) {

                    const node = nodes[i];

                    

                    for (const j of node.connections) {

                        if (j > i) continue; // Avoid duplicates

                        

                        const other = nodes[j];

                        const dx = other.x - node.x;

                        const dy = other.y - node.y;

                        const dz = other.z - node.z;

                        const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);

                        

                        // Line positions

                        const idx = lineIndex * 6;

                        linePos[idx] = node.x;

                        linePos[idx + 1] = node.y;

                        linePos[idx + 2] = node.z;

                        linePos[idx + 3] = other.x;

                        linePos[idx + 4] = other.y;

                        linePos[idx + 5] = other.z;

                        

                        // Color based on distance (closer = brighter)

                        const intensity = 1 - (dist / PHYSICS.connectionDistance);

                        const r = 0.0 * intensity;

                        const g = 0.83 * intensity;

                        const b = 1.0 * intensity;

                        

                        lineCol[idx] = r;

                        lineCol[idx + 1] = g;

                        lineCol[idx + 2] = b;

                        lineCol[idx + 3] = r;

                        lineCol[idx + 4] = g;

                        lineCol[idx + 5] = b;

                        

                        lineIndex++;

                    }

                }

                

                // Clear unused line segments

                for (let i = lineIndex * 6; i < linePos.length; i++) {

                    linePos[i] = 0;

                    lineCol[i] = 0;

                }

                

                linesGeometry.attributes.position.needsUpdate = true;

                linesGeometry.attributes.color.needsUpdate = true;

                linesGeometry.setDrawRange(0, lineIndex * 2);

            }

            

            // Mouse event handlers

            function onMouseMove(event) {

                mouse2D.x = (event.clientX / window.innerWidth) * 2 - 1;

                mouse2D.y = -(event.clientY / window.innerHeight) * 2 + 1;

                

                raycaster.setFromCamera(mouse2D, camera);

                

                // Project mouse into 3D space at network depth

                const planeZ = -100;

                const planeNormal = new THREE.Vector3(0, 0, 1);

                const planePoint = new THREE.Vector3(0, 0, planeZ);

                const plane = new THREE.Plane().setFromNormalAndCoplanarPoint(planeNormal, planePoint);

                

                const intersectPoint = new THREE.Vector3();

                raycaster.ray.intersectPlane(plane, intersectPoint);

                

                if (intersectPoint) {

                    mouse.x = intersectPoint.x;

                    mouse.y = intersectPoint.y;

                    mouse.z = intersectPoint.z;

                    mouse.active = true;

                }

            }

            

            function onMouseLeave() {

                mouse.active = false;

            }

            

            // Touch support

            function onTouchMove(event) {

                if (event.touches.length > 0) {

                    const touch = event.touches[0];

                    onMouseMove({ clientX: touch.clientX, clientY: touch.clientY });

                }

            }

            

            function onTouchEnd() {

                mouse.active = false;

            }

            

            // Add event listeners

            document.addEventListener('mousemove', onMouseMove);

            document.addEventListener('mouseleave', onMouseLeave);

            document.addEventListener('touchmove', onTouchMove, { passive: true });

            document.addEventListener('touchend', onTouchEnd);



            // ==================== REALISTIC EARTH ====================

            const earthRadius = isMobile ? 160 : 180;

            const earthGroup = new THREE.Group();

            earthGroup.position.set(0, isMobile ? -350 : -380, -100);

            scene.add(earthGroup);



            // Earth texture URLs (from three-globe)

            const textureURLs = {

                dayMap: 'https://unpkg.com/three-globe@2.24.13/example/img/earth-day.jpg',

                nightMap: 'https://unpkg.com/three-globe@2.24.13/example/img/earth-night.jpg',

                bumpMap: 'https://unpkg.com/three-globe@2.24.13/example/img/earth-topology.png',

                cloudsMap: 'https://unpkg.com/three-globe@2.24.13/example/img/earth-clouds.png'

            };



            // Load textures

            const earthDayTexture = textureLoader.load(textureURLs.dayMap);

            const earthNightTexture = textureLoader.load(textureURLs.nightMap);

            const earthBumpTexture = textureLoader.load(textureURLs.bumpMap);

            const earthCloudsTexture = textureLoader.load(textureURLs.cloudsMap);



            // Earth geometry

            const earthGeometry = new THREE.SphereGeometry(earthRadius, isMobile ? 48 : 64, isMobile ? 48 : 64);



            // Custom shader for day/night cycle

            const earthMaterial = new THREE.ShaderMaterial({

                uniforms: {

                    dayTexture: { value: earthDayTexture },

                    nightTexture: { value: earthNightTexture },

                    sunDirection: { value: new THREE.Vector3(1, 0.5, 1).normalize() }

                },

                vertexShader: `

                    varying vec2 vUv;

                    varying vec3 vNormal;

                    varying vec3 vPosition;

                    

                    void main() {

                        vUv = uv;

                        vNormal = normalize(normalMatrix * normal);

                        vPosition = (modelMatrix * vec4(position, 1.0)).xyz;

                        gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);

                    }

                `,

                fragmentShader: `

                    uniform sampler2D dayTexture;

                    uniform sampler2D nightTexture;

                    uniform vec3 sunDirection;

                    

                    varying vec2 vUv;

                    varying vec3 vNormal;

                    varying vec3 vPosition;

                    

                    void main() {

                        vec3 dayColor = texture2D(dayTexture, vUv).rgb;

                        vec3 nightColor = texture2D(nightTexture, vUv).rgb;

                        

                        float sunIntensity = dot(vNormal, sunDirection);

                        float dayFactor = smoothstep(-0.2, 0.4, sunIntensity);

                        

                        nightColor *= 1.5;

                        vec3 color = mix(nightColor, dayColor, dayFactor);

                        color += vec3(0.02, 0.03, 0.05);

                        

                        float fresnel = pow(1.0 - abs(dot(vNormal, vec3(0.0, 0.0, 1.0))), 3.0);

                        vec3 atmosphereColor = vec3(0.3, 0.6, 1.0);

                        color = mix(color, atmosphereColor, fresnel * 0.3);

                        

                        gl_FragColor = vec4(color, 1.0);

                    }

                `

            });



            const earth = new THREE.Mesh(earthGeometry, earthMaterial);

            earthGroup.add(earth);



            // Cloud layer

            const cloudGeometry = new THREE.SphereGeometry(earthRadius * 1.02, isMobile ? 48 : 64, isMobile ? 48 : 64);

            const cloudMaterial = new THREE.MeshPhongMaterial({

                map: earthCloudsTexture,

                transparent: true,

                opacity: 0.4,

                depthWrite: false,

                side: THREE.DoubleSide

            });

            

            const clouds = new THREE.Mesh(cloudGeometry, cloudMaterial);

            earthGroup.add(clouds);



            // Atmosphere glow

            const atmosphereGeometry = new THREE.SphereGeometry(earthRadius * 1.15, isMobile ? 48 : 64, isMobile ? 48 : 64);

            const atmosphereMaterial = new THREE.ShaderMaterial({

                uniforms: {

                    glowColor: { value: new THREE.Color(0x3388ff) },

                    viewVector: { value: camera.position }

                },

                vertexShader: `

                    uniform vec3 viewVector;

                    varying float intensity;

                    

                    void main() {

                        vec3 vNormal = normalize(normalMatrix * normal);

                        vec3 vNormel = normalize(normalMatrix * viewVector);

                        intensity = pow(0.7 - dot(vNormal, vNormel), 2.0);

                        gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);

                    }

                `,

                fragmentShader: `

                    uniform vec3 glowColor;

                    varying float intensity;

                    

                    void main() {

                        vec3 glow = glowColor * intensity;

                        gl_FragColor = vec4(glow, intensity * 0.6);

                    }

                `,

                side: THREE.BackSide,

                blending: THREE.AdditiveBlending,

                transparent: true

            });

            

            const atmosphereOuter = new THREE.Mesh(atmosphereGeometry, atmosphereMaterial);

            earthGroup.add(atmosphereOuter);



            // ===== LIGHTING =====

            const ambientLight = new THREE.AmbientLight(isMobile ? 0x555555 : 0x333333);

            scene.add(ambientLight);



            const sunLight = new THREE.DirectionalLight(0xffffff, 1.5);

            sunLight.position.set(5, 3, 5);

            scene.add(sunLight);



            // ==================== AMBIENT ASTRONAUT — DETAILED EVA SUIT ====================

            let updateAstronaut = null;

            const astronautEnabled = !window.matchMedia('(prefers-reduced-motion: reduce)').matches;

            

            if (astronautEnabled) {

                const astronautGroup = new THREE.Group(); // Keep name for compatibility

                

                // ═══════════════════════════════════════════════════════════════

                // ██  UFO SPACESHIP CONSTRUCTION  ██

                // ═══════════════════════════════════════════════════════════════

                

                // ──────────── MATERIALS LIBRARY ────────────

                const mobileEmissiveBoost = isMobile ? 1.8 : 1.0; // Brighter on mobile

                

                const mat = {

                    // Main hull - lighter metallic with self-illumination

                    hull: new THREE.MeshStandardMaterial({

                        color: 0x5a7a9a, roughness: 0.3, metalness: 0.7,

                        emissive: 0x2a4a6a, emissiveIntensity: 0.4 * mobileEmissiveBoost

                    }),

                    // Hull accent - lighter

                    hullAccent: new THREE.MeshStandardMaterial({

                        color: 0x6a8aaa, roughness: 0.4, metalness: 0.6,

                        emissive: 0x3a5a7a, emissiveIntensity: 0.35 * mobileEmissiveBoost

                    }),

                    // Chrome trim - brighter

                    chrome: new THREE.MeshStandardMaterial({

                        color: 0xddddee, roughness: 0.1, metalness: 1.0,

                        emissive: 0x556677, emissiveIntensity: 0.4 * mobileEmissiveBoost

                    }),

                    // Dome glass - brighter tint

                    domeGlass: new THREE.MeshStandardMaterial({

                        color: 0x55bbdd, roughness: 0.05, metalness: 0.3,

                        transparent: true, opacity: 0.6,

                        emissive: 0x338899, emissiveIntensity: 0.7 * mobileEmissiveBoost

                    }),

                    // Inner dome glow - brighter

                    domeInner: new THREE.MeshStandardMaterial({

                        color: 0x00ffcc, emissive: 0x00ffaa, emissiveIntensity: 1.5 * mobileEmissiveBoost,

                        transparent: true, opacity: 0.7

                    }),

                    // Cyan lights (primary) - brighter

                    lightCyan: new THREE.MeshStandardMaterial({

                        color: 0x00ffff, emissive: 0x00ffff, emissiveIntensity: 4.0 * mobileEmissiveBoost,

                        transparent: true, opacity: 1.0

                    }),

                    // Green lights (accent) - brighter

                    lightGreen: new THREE.MeshStandardMaterial({

                        color: 0x00ff88, emissive: 0x00ff88, emissiveIntensity: 3.5 * mobileEmissiveBoost

                    }),

                    // Blue thrust core - brighter

                    thrustCore: new THREE.MeshStandardMaterial({

                        color: 0x00ccff, emissive: 0x00aaff, emissiveIntensity: 5.0 * mobileEmissiveBoost,

                        transparent: true, opacity: 0.95

                    }),

                    // Thrust mid layer

                    thrustMid: new THREE.MeshStandardMaterial({

                        color: 0x00aaff, emissive: 0x0088ee, emissiveIntensity: 2.5 * mobileEmissiveBoost,

                        transparent: true, opacity: 0.55, side: THREE.DoubleSide

                    }),

                    // Thrust outer glow

                    thrustOuter: new THREE.MeshStandardMaterial({

                        color: 0x0088dd, emissive: 0x0066bb, emissiveIntensity: 1.2 * mobileEmissiveBoost,

                        transparent: true, opacity: 0.3, side: THREE.DoubleSide

                    }),

                    // Dark panels - lighter

                    panel: new THREE.MeshStandardMaterial({

                        color: 0x3a5a7a, roughness: 0.7, metalness: 0.4,

                        emissive: 0x2a3a4a, emissiveIntensity: 0.3 * mobileEmissiveBoost

                    })

                };

                

                // ──────────── MAIN SAUCER BODY ────────────

                

                // Upper dome housing (flattened sphere)

                const upperDome = new THREE.Mesh(

                    new THREE.SphereGeometry(8, 32, 16, 0, Math.PI * 2, 0, Math.PI * 0.5),

                    mat.hull

                );

                upperDome.scale.set(1, 0.5, 1);

                upperDome.position.y = 2;

                astronautGroup.add(upperDome);

                

                // Glass cockpit dome

                const glassDome = new THREE.Mesh(

                    new THREE.SphereGeometry(5, 32, 16, 0, Math.PI * 2, 0, Math.PI * 0.55),

                    mat.domeGlass

                );

                glassDome.scale.set(1, 0.7, 1);

                glassDome.position.y = 3.5;

                astronautGroup.add(glassDome);

                

                // Inner dome glow

                const innerGlow = new THREE.Mesh(

                    new THREE.SphereGeometry(4.5, 24, 12, 0, Math.PI * 2, 0, Math.PI * 0.5),

                    mat.domeInner

                );

                innerGlow.scale.set(1, 0.6, 1);

                innerGlow.position.y = 3.5;

                astronautGroup.add(innerGlow);

                

                // Main disc body (torus-like shape using lathe)

                const discProfile = [];

                for (let i = 0; i <= 20; i++) {

                    const t = i / 20;

                    const angle = t * Math.PI;

                    const r = 8 + Math.sin(angle) * 7;

                    const y = Math.cos(angle) * 2.5;

                    discProfile.push(new THREE.Vector2(r, y));

                }

                const discGeo = new THREE.LatheGeometry(discProfile, 48);

                const mainDisc = new THREE.Mesh(discGeo, mat.hull);

                mainDisc.position.y = 0;

                astronautGroup.add(mainDisc);

                

                // Chrome ring (equator trim)

                const chromeRing = new THREE.Mesh(

                    new THREE.TorusGeometry(15, 0.4, 16, 64),

                    mat.chrome

                );

                chromeRing.rotation.x = Math.PI / 2;

                chromeRing.position.y = 0;

                astronautGroup.add(chromeRing);

                

                // Upper chrome ring

                const upperRing = new THREE.Mesh(

                    new THREE.TorusGeometry(8, 0.25, 12, 48),

                    mat.chrome

                );

                upperRing.rotation.x = Math.PI / 2;

                upperRing.position.y = 2;

                astronautGroup.add(upperRing);

                

                // ──────────── BOTTOM STRUCTURE ────────────

                

                // Bottom dome (inverted, flatter)

                const bottomDome = new THREE.Mesh(

                    new THREE.SphereGeometry(10, 32, 16, 0, Math.PI * 2, Math.PI * 0.5, Math.PI * 0.5),

                    mat.hullAccent

                );

                bottomDome.scale.set(1, 0.35, 1);

                bottomDome.position.y = -2.5;

                astronautGroup.add(bottomDome);

                

                // Central thrust housing

                const thrustHousing = new THREE.Mesh(

                    new THREE.CylinderGeometry(4, 5, 2, 24),

                    mat.hull

                );

                thrustHousing.position.y = -4;

                astronautGroup.add(thrustHousing);

                

                // Thrust emitter ring

                const thrustEmitterRing = new THREE.Mesh(

                    new THREE.TorusGeometry(4.5, 0.3, 12, 32),

                    mat.chrome

                );

                thrustEmitterRing.rotation.x = Math.PI / 2;

                thrustEmitterRing.position.y = -5;

                astronautGroup.add(thrustEmitterRing);

                

                // ──────────── RIM LIGHTS (8 around edge) ────────────

                const rimLightCount = 8;

                const rimLights = [];

                const rimLightMats = [];

                for (let i = 0; i < rimLightCount; i++) {

                    const angle = (i / rimLightCount) * Math.PI * 2;

                    const lightGroup = new THREE.Group();

                    

                    // Light housing

                    const housing = new THREE.Mesh(

                        new THREE.SphereGeometry(1.2, 16, 12),

                        mat.hullAccent

                    );

                    housing.scale.set(1, 0.6, 1);

                    lightGroup.add(housing);

                    

                    // Light dome (glowing) - unique material per light for animation

                    const lightMat = new THREE.MeshStandardMaterial({

                        color: 0x00ffff, emissive: 0x00ffff, emissiveIntensity: 3.5 * mobileEmissiveBoost,

                        transparent: true, opacity: 1.0

                    });

                    const lightDome = new THREE.Mesh(

                        new THREE.SphereGeometry(1, 16, 12, 0, Math.PI * 2, 0, Math.PI * 0.6),

                        lightMat

                    );

                    lightDome.position.y = 0.3;

                    lightGroup.add(lightDome);

                    

                    lightGroup.position.set(

                        Math.cos(angle) * 14,

                        0.5,

                        Math.sin(angle) * 14

                    );

                    

                    astronautGroup.add(lightGroup);

                    rimLights.push(lightDome);

                    rimLightMats.push(lightMat);

                }

                

                // ──────────── TOP DOME LIGHTS (4 around dome) ────────────

                const domeLightCount = 4;

                const domeLights = [];

                const domeLightMats = [];

                for (let i = 0; i < domeLightCount; i++) {

                    const angle = (i / domeLightCount) * Math.PI * 2 + Math.PI / 4;

                    

                    const lightMat = new THREE.MeshStandardMaterial({

                        color: 0x00ff88, emissive: 0x00ff88, emissiveIntensity: 3.0 * mobileEmissiveBoost

                    });

                    const domeLight = new THREE.Mesh(

                        new THREE.SphereGeometry(0.6, 12, 8),

                        lightMat

                    );

                    domeLight.position.set(

                        Math.cos(angle) * 6,

                        4,

                        Math.sin(angle) * 6

                    );

                    astronautGroup.add(domeLight);

                    domeLights.push(domeLight);

                    domeLightMats.push(lightMat);

                }

                

                // ──────────── PANEL DETAILS ────────────

                for (let i = 0; i < 12; i++) {

                    const angle = (i / 12) * Math.PI * 2;

                    const panelLine = new THREE.Mesh(

                        new THREE.BoxGeometry(0.1, 0.3, 5),

                        mat.panel

                    );

                    panelLine.position.set(

                        Math.cos(angle) * 11,

                        1,

                        Math.sin(angle) * 11

                    );

                    panelLine.rotation.y = -angle;

                    astronautGroup.add(panelLine);

                }

                

                // ══════════════════════════════════════════════════════════════

                // ██  BLUE/RED THRUST BEAM SYSTEM (Signal Reactive)  ██

                // ══════════════════════════════════════════════════════════════

                

                const mobileLightBoost = isMobile ? 2.0 : 1.0; // Extra brightness on mobile

                

                const thrustGroup = new THREE.Group();

                thrustGroup.position.y = -5;

                astronautGroup.add(thrustGroup);

                

                // Core beam (bright center) - LONGER & WIDER

                const beamCoreGeo = new THREE.CylinderGeometry(1, 5, 30, 24, 1, true);

                const beamCore = new THREE.Mesh(beamCoreGeo, mat.thrustCore);

                beamCore.position.y = -15;

                thrustGroup.add(beamCore);

                

                // Mid beam layer - LONGER & WIDER

                const beamMidGeo = new THREE.CylinderGeometry(2.5, 8, 35, 24, 1, true);

                const beamMid = new THREE.Mesh(beamMidGeo, mat.thrustMid);

                beamMid.position.y = -17;

                thrustGroup.add(beamMid);

                

                // Outer glow cone - LONGER & WIDER

                const beamOuterGeo = new THREE.CylinderGeometry(5, 14, 40, 24, 1, true);

                const beamOuter = new THREE.Mesh(beamOuterGeo, mat.thrustOuter);

                beamOuter.position.y = -20;

                thrustGroup.add(beamOuter);

                

                // Thrust particles - wider spread, longer travel (reduced on mobile)

                const thrustParticleCount = isMobile ? 80 : 200;

                const thrustParticleGeo = new THREE.BufferGeometry();

                const thrustParticlePos = new Float32Array(thrustParticleCount * 3);

                const thrustParticleSpeeds = [];

                

                for (let i = 0; i < thrustParticleCount; i++) {

                    const angle = Math.random() * Math.PI * 2;

                    const radius = Math.random() * 5;

                    thrustParticlePos[i * 3] = Math.cos(angle) * radius;

                    thrustParticlePos[i * 3 + 1] = -Math.random() * 35;

                    thrustParticlePos[i * 3 + 2] = Math.sin(angle) * radius;

                    thrustParticleSpeeds.push(0.6 + Math.random() * 1.8);

                }

                thrustParticleGeo.setAttribute('position', new THREE.BufferAttribute(thrustParticlePos, 3));

                

                const thrustParticleMat = new THREE.PointsMaterial({

                    color: 0x00eeff, size: isMobile ? 1.0 : 0.7, transparent: true, opacity: 1.0,

                    blending: THREE.AdditiveBlending

                });

                const thrustParticles = new THREE.Points(thrustParticleGeo, thrustParticleMat);

                thrustGroup.add(thrustParticles);

                

                // Point light for thrust illumination - stronger

                const thrustLight = new THREE.PointLight(0x00aaff, 5 * mobileLightBoost, 100);

                thrustLight.position.y = -15;

                thrustGroup.add(thrustLight);

                

                // ──────────── POINT LIGHTS (brighter for visibility) ────────────

                const ufoMainLight = new THREE.PointLight(0x00d4ff, 1.5 * mobileLightBoost, 150);

                ufoMainLight.position.set(0, 8, 0);

                astronautGroup.add(ufoMainLight);

                

                const ufoRimLight = new THREE.PointLight(0x00ffaa, 1.0 * mobileLightBoost, 120);

                ufoRimLight.position.set(0, -5, 0);

                astronautGroup.add(ufoRimLight);

                

                // Additional lights for hull illumination

                const ufoTopLight = new THREE.PointLight(0x88aacc, 0.8 * mobileLightBoost, 80);

                ufoTopLight.position.set(0, 15, 0);

                astronautGroup.add(ufoTopLight);

                

                const ufoFrontLight = new THREE.PointLight(0x00ccff, 0.6 * mobileLightBoost, 60);

                ufoFrontLight.position.set(0, 0, 20);

                astronautGroup.add(ufoFrontLight);

                

                // Extra bottom light for mobile visibility

                if (isMobile) {

                    const ufoBottomLight = new THREE.PointLight(0x00aaff, 1.5, 100);

                    ufoBottomLight.position.set(0, -15, 0);

                    astronautGroup.add(ufoBottomLight);

                }

                

                // ──────────── FINAL SETUP ────────────

                const ufoScale = isMobile ? 0.7 : 0.8; // Slightly smaller on mobile

                astronautGroup.scale.setScalar(ufoScale);

                scene.add(astronautGroup);

                

                // ════════════════════════════════════════════════════════════════════

                // ██  SUPERMAN FLIGHT SYSTEM — Spline-Driven Heroic Motion  ██

                // ════════════════════════════════════════════════════════════════════

                

                // ──────────── MATH UTILITIES ────────────

                

                function smoothstep(edge0, edge1, x) {

                    const t = Math.max(0, Math.min(1, (x - edge0) / (edge1 - edge0)));

                    return t * t * (3 - 2 * t);

                }

                

                function smootherstep(edge0, edge1, x) {

                    const t = Math.max(0, Math.min(1, (x - edge0) / (edge1 - edge0)));

                    return t * t * t * (t * (t * 6 - 15) + 10);

                }

                

                function catmullRom(p0, p1, p2, p3, t) {

                    const t2 = t * t;

                    const t3 = t2 * t;

                    return new THREE.Vector3(

                        0.5 * ((2 * p1.x) + (-p0.x + p2.x) * t + (2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t2 + (-p0.x + 3 * p1.x - 3 * p2.x + p3.x) * t3),

                        0.5 * ((2 * p1.y) + (-p0.y + p2.y) * t + (2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t2 + (-p0.y + 3 * p1.y - 3 * p2.y + p3.y) * t3),

                        0.5 * ((2 * p1.z) + (-p0.z + p2.z) * t + (2 * p0.z - 5 * p1.z + 4 * p2.z - p3.z) * t2 + (-p0.z + 3 * p1.z - 3 * p2.z + p3.z) * t3)

                    );

                }

                

                function catmullRomTangent(p0, p1, p2, p3, t) {

                    const t2 = t * t;

                    return new THREE.Vector3(

                        0.5 * ((-p0.x + p2.x) + 2 * (2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t + 3 * (-p0.x + 3 * p1.x - 3 * p2.x + p3.x) * t2),

                        0.5 * ((-p0.y + p2.y) + 2 * (2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t + 3 * (-p0.y + 3 * p1.y - 3 * p2.y + p3.y) * t2),

                        0.5 * ((-p0.z + p2.z) + 2 * (2 * p0.z - 5 * p1.z + 4 * p2.z - p3.z) * t + 3 * (-p0.z + 3 * p1.z - 3 * p2.z + p3.z) * t2)

                    ).normalize();

                }

                

                function quaternionFromDirection(direction, up) {

                    up = up || new THREE.Vector3(0, 1, 0);

                    const matrix = new THREE.Matrix4();

                    matrix.lookAt(new THREE.Vector3(0, 0, 0), direction, up);

                    const quat = new THREE.Quaternion();

                    quat.setFromRotationMatrix(matrix);

                    return quat;

                }

                

                // ──────────── FLIGHT BOUNDS ────────────

                const flightBounds = {

                    xMin: -180, xMax: 180,

                    yMin: 60,   yMax: 220,

                    zMin: -120, zMax: 80

                };

                

                // ──────────── WAYPOINT GENERATOR ────────────

                function generateWaypoint(currentPos, currentDirection) {

                    const minDist = 100;

                    const maxDist = 200;

                    const dist = minDist + Math.random() * (maxDist - minDist);

                    const forwardBias = 0.6;

                    

                    let newDir = new THREE.Vector3(

                        currentDirection.x * forwardBias + (Math.random() - 0.5) * (1 - forwardBias) * 2,

                        currentDirection.y * forwardBias + (Math.random() - 0.5) * (1 - forwardBias) * 1.5,

                        currentDirection.z * forwardBias + (Math.random() - 0.5) * (1 - forwardBias) * 2

                    ).normalize();

                    

                    let target = new THREE.Vector3(

                        currentPos.x + newDir.x * dist,

                        currentPos.y + newDir.y * dist,

                        currentPos.z + newDir.z * dist

                    );

                    

                    const margin = 30;

                    if (target.x < flightBounds.xMin + margin) target.x = flightBounds.xMin + margin + Math.random() * 40;

                    if (target.x > flightBounds.xMax - margin) target.x = flightBounds.xMax - margin - Math.random() * 40;

                    if (target.y < flightBounds.yMin + margin) target.y = flightBounds.yMin + margin + Math.random() * 30;

                    if (target.y > flightBounds.yMax - margin) target.y = flightBounds.yMax - margin - Math.random() * 30;

                    if (target.z < flightBounds.zMin + margin) target.z = flightBounds.zMin + margin + Math.random() * 40;

                    if (target.z > flightBounds.zMax - 50) target.z = flightBounds.zMax - 50 - Math.random() * 30;

                    

                    return target;

                }

                

                // ──────────── BEHAVIORAL STATE ────────────

                const ec = earthGroup.position;

                const startPos = new THREE.Vector3(ec.x + 50, ec.y + 130, ec.z - 30);

                

                const st = {

                    waypoints: [

                        startPos.clone().add(new THREE.Vector3(-100, 20, -50)),

                        startPos.clone(),

                        startPos.clone().add(new THREE.Vector3(80, -10, 30)),

                        startPos.clone().add(new THREE.Vector3(160, 30, -20))

                    ],

                    t: 0,

                    segmentDuration: 4,

                    cruiseSpeed: 1.2,

                    currentSpeed: 0,

                    currentQuat: new THREE.Quaternion(),

                    targetQuat: new THREE.Quaternion(),

                    bankAngle: 0,

                    targetBankAngle: 0,

                    verticalWavePhase: Math.random() * Math.PI * 2,

                    verticalWaveAmp: 1.5,

                    verticalWaveFreq: 0.08,

                    prevVelocity: new THREE.Vector3(1, 0, 0),

                    totalTime: 0,

                    thrusterIntensity: 1.0,

                    opacity: 1.0,

                    targetOp: 1.0,

                    // Teleport state

                    teleportCooldown: 15 + Math.random() * 20, // Time until next teleport

                    teleportTimer: 0,

                    isTeleporting: false,

                    teleportPhase: 0,

                    teleportDuration: 3.5, // How long to stay at Market Directive

                    teleportFlashIntensity: 0,

                    preTeleportPos: null,

                    preTeleportQuat: null

                };

                

                const initialDir = new THREE.Vector3().subVectors(st.waypoints[2], st.waypoints[1]).normalize();

                st.currentQuat = quaternionFromDirection(initialDir);

                st.targetQuat = st.currentQuat.clone();

                astronautGroup.quaternion.copy(st.currentQuat);

                astronautGroup.position.copy(st.waypoints[1]);

                

                function advanceWaypoint() {

                    st.waypoints[0] = st.waypoints[1].clone();

                    st.waypoints[1] = st.waypoints[2].clone();

                    st.waypoints[2] = st.waypoints[3].clone();

                    const currentDir = new THREE.Vector3().subVectors(st.waypoints[2], st.waypoints[1]).normalize();

                    st.waypoints[3] = generateWaypoint(st.waypoints[2], currentDir);

                    st.t = 0;

                    st.segmentDuration = 3 + Math.random() * 3;

                    st.cruiseSpeed = 1.0 + Math.random() * 0.5;

                }

                

                // ──────────── UPDATE FUNCTION (UFO Flight) ────────────

                updateAstronaut = function(time, deltaTime) {

                    const dt = Math.min(deltaTime || 0.016, 0.05);

                    st.totalTime += dt;

                    

                    // ════════════════════════════════════════════════════════

                    // █  SUPERMAN TRAJECTORY — Spline + Velocity Profile  █

                    // ════════════════════════════════════════════════════════

                    

                    const accelZone = 0.15;

                    const decelZone = 0.85;

                    

                    let speedMultiplier;

                    if (st.t < accelZone) {

                        speedMultiplier = smootherstep(0, accelZone, st.t);

                    } else if (st.t > decelZone) {

                        speedMultiplier = smootherstep(1, decelZone, st.t);

                    } else {

                        speedMultiplier = 1.0;

                    }

                    

                    st.currentSpeed = speedMultiplier * st.cruiseSpeed;

                    

                    const baseProgress = dt / st.segmentDuration;

                    st.t += baseProgress * (0.5 + st.currentSpeed * 1.2);

                    

                    if (st.t >= 1.0) {

                        st.t = 0;

                        advanceWaypoint();

                    }

                    

                    const splinePos = catmullRom(

                        st.waypoints[0], st.waypoints[1],

                        st.waypoints[2], st.waypoints[3],

                        st.t

                    );

                    

                    st.verticalWavePhase += dt * st.verticalWaveFreq * Math.PI * 2;

                    const verticalOffset = Math.sin(st.verticalWavePhase) * st.verticalWaveAmp;

                    splinePos.y += verticalOffset;

                    

                    // ════════════════════════════════════════════════════════

                    // █  TELEPORT TO MARKET DIRECTIVE  █

                    // ════════════════════════════════════════════════════════

                    

                    st.teleportTimer += dt;

                    

                    // Check if it's time to teleport

                    if (!st.isTeleporting && st.teleportTimer >= st.teleportCooldown) {

                        // Start teleport sequence

                        st.isTeleporting = true;

                        st.teleportPhase = 0;

                        st.teleportFlashIntensity = 1.0;

                        st.preTeleportPos = astronautGroup.position.clone();

                        st.preTeleportQuat = astronautGroup.quaternion.clone();

                        

                        // Get Market Directive element position

                        const directiveEl = document.querySelector('.signal-panel');

                        if (directiveEl) {

                            const rect = directiveEl.getBoundingClientRect();

                            // Convert screen position to normalized device coordinates

                            const screenX = (rect.left + rect.width / 2) / window.innerWidth * 2 - 1;

                            const screenY = -((rect.top + rect.height / 2) / window.innerHeight * 2 - 1);

                            

                            // Project to 3D space (in front of camera)

                            const teleportZ = 150; // Close to camera

                            const fov = camera.fov * Math.PI / 180;

                            const height = 2 * Math.tan(fov / 2) * teleportZ;

                            const width = height * camera.aspect;

                            

                            st.teleportTarget = new THREE.Vector3(

                                screenX * width / 2,

                                screenY * height / 2 + 20, // Slightly above center

                                camera.position.z - teleportZ

                            );

                        }

                    }

                    

                    // Handle teleport animation

                    if (st.isTeleporting) {

                        st.teleportPhase += dt;

                        

                        // Flash effect fades

                        st.teleportFlashIntensity = Math.max(0, st.teleportFlashIntensity - dt * 2);

                        

                        if (st.teleportPhase < st.teleportDuration) {

                            // At Market Directive - hover with gentle movement

                            if (st.teleportTarget) {

                                const hoverOffset = new THREE.Vector3(

                                    Math.sin(st.teleportPhase * 2) * 8,

                                    Math.sin(st.teleportPhase * 1.5) * 5,

                                    Math.sin(st.teleportPhase * 1.8) * 4

                                );

                                astronautGroup.position.copy(st.teleportTarget).add(hoverOffset);

                                

                                // Face the camera (slightly tilted)

                                const lookDir = new THREE.Vector3(0, 0, 1);

                                const tiltAngle = Math.sin(st.teleportPhase * 2) * 0.15;

                                st.targetQuat = quaternionFromDirection(lookDir);

                                const tiltQuat = new THREE.Quaternion().setFromAxisAngle(

                                    new THREE.Vector3(1, 0, 0), tiltAngle

                                );

                                st.targetQuat.multiply(tiltQuat);

                                st.currentQuat.slerp(st.targetQuat, 0.1);

                                astronautGroup.quaternion.copy(st.currentQuat);

                            }

                        } else {

                            // Teleport back - flash and return

                            if (st.teleportPhase < st.teleportDuration + 0.5) {

                                st.teleportFlashIntensity = 1.0 - (st.teleportPhase - st.teleportDuration) * 2;

                            } else {

                                // End teleport

                                st.isTeleporting = false;

                                st.teleportTimer = 0;

                                st.teleportCooldown = 20 + Math.random() * 25; // Next teleport in 20-45 seconds

                                st.teleportFlashIntensity = 0;

                                

                                // Reset waypoints from current spline position

                                st.waypoints[1] = splinePos.clone();

                                const dir = st.prevVelocity.clone().normalize();

                                st.waypoints[0] = splinePos.clone().sub(dir.clone().multiplyScalar(50));

                                st.waypoints[2] = generateWaypoint(splinePos, dir);

                                st.waypoints[3] = generateWaypoint(st.waypoints[2], dir);

                                st.t = 0;

                            }

                        }

                    } else {

                        // Normal flight - apply spline position

                        astronautGroup.position.copy(splinePos);

                    }

                    

                    // ════════════════════════════════════════════════════════

                    // █  ORIENTATION — Face Velocity + Banking  █

                    // ════════════════════════════════════════════════════════

                    

                    // Only do normal orientation when not teleporting

                    if (!st.isTeleporting) {

                        const velocity = catmullRomTangent(

                            st.waypoints[0], st.waypoints[1],

                            st.waypoints[2], st.waypoints[3],

                            st.t

                        );

                        

                        const turnAxis = new THREE.Vector3().crossVectors(st.prevVelocity, velocity);

                        const turnAmount = turnAxis.y;

                        

                        st.targetBankAngle = -turnAmount * 35 * (Math.PI / 180);

                        st.bankAngle += (st.targetBankAngle - st.bankAngle) * 0.08;

                        st.prevVelocity.copy(velocity);

                        

                        st.targetQuat = quaternionFromDirection(velocity);

                        const bankQuat = new THREE.Quaternion();

                        bankQuat.setFromAxisAngle(velocity, st.bankAngle);

                        st.targetQuat.multiply(bankQuat);

                        

                        st.currentQuat.slerp(st.targetQuat, 0.12);

                        astronautGroup.quaternion.copy(st.currentQuat);

                    }

                    

                    // ════════════════════════════════════════════════════════

                    // █  UFO LIGHT ANIMATIONS  █

                    // ════════════════════════════════════════════════════════

                    

                    // Rim lights pulse in sequence (brighter)

                    for (let i = 0; i < rimLightCount; i++) {

                        const phase = time * 2 + (i / rimLightCount) * Math.PI * 2;

                        rimLightMats[i].emissiveIntensity = 2.5 + Math.sin(phase) * 1.0;

                        rimLightMats[i].opacity = 0.85 + Math.sin(phase) * 0.15;

                    }

                    

                    // Dome lights alternate (brighter)

                    for (let i = 0; i < domeLightCount; i++) {

                        const phase = time * 3 + (i / domeLightCount) * Math.PI * 2;

                        domeLightMats[i].emissiveIntensity = 2.0 + Math.sin(phase) * 1.0;

                    }

                    

                    // Inner dome pulse (brighter)

                    mat.domeInner.emissiveIntensity = 0.8 + Math.sin(time * 1.5) * 0.4;

                    mat.domeInner.opacity = 0.5 + Math.sin(time * 1.5) * 0.15;

                    

                    // ════════════════════════════════════════════════════════

                    // █  THRUST BEAM ANIMATIONS (Signal-Reactive Color)  █

                    // ════════════════════════════════════════════════════════

                    

                    // Check dominant signal for beam color

                    const signalEl = document.getElementById('dominantSignal');

                    const dominantSignal = signalEl ? signalEl.textContent.trim().toUpperCase() : 'NEUTRAL';

                    const isSellSignal = dominantSignal === 'SELL';

                    const isBuySignal = dominantSignal === 'BUY';

                    const isNeutral = !isSellSignal && !isBuySignal;

                    

                    // Color targets based on signal

                    // SELL = Red, BUY = Blue, NEUTRAL = Golden

                    let targetCoreColor, targetCoreEmissive, targetMidColor, targetMidEmissive;

                    let targetOuterColor, targetOuterEmissive, targetParticleColor, targetLightColor;

                    

                    if (isSellSignal) {

                        // RED for SELL

                        targetCoreColor = new THREE.Color(0xff4444);

                        targetCoreEmissive = new THREE.Color(0xff2222);

                        targetMidColor = new THREE.Color(0xff6644);

                        targetMidEmissive = new THREE.Color(0xee4422);

                        targetOuterColor = new THREE.Color(0xcc4422);

                        targetOuterEmissive = new THREE.Color(0xaa3311);

                        targetParticleColor = new THREE.Color(0xff6655);

                        targetLightColor = 0xff4433;

                    } else if (isBuySignal) {

                        // BLUE for BUY

                        targetCoreColor = new THREE.Color(0x00ccff);

                        targetCoreEmissive = new THREE.Color(0x00aaff);

                        targetMidColor = new THREE.Color(0x00aaff);

                        targetMidEmissive = new THREE.Color(0x0088ee);

                        targetOuterColor = new THREE.Color(0x0088dd);

                        targetOuterEmissive = new THREE.Color(0x0066bb);

                        targetParticleColor = new THREE.Color(0x00eeff);

                        targetLightColor = 0x00aaff;

                    } else {

                        // GOLDEN for NEUTRAL

                        targetCoreColor = new THREE.Color(0xffcc44);

                        targetCoreEmissive = new THREE.Color(0xffaa22);

                        targetMidColor = new THREE.Color(0xddaa33);

                        targetMidEmissive = new THREE.Color(0xcc9922);

                        targetOuterColor = new THREE.Color(0xbb8822);

                        targetOuterEmissive = new THREE.Color(0x996611);

                        targetParticleColor = new THREE.Color(0xffdd66);

                        targetLightColor = 0xffaa33;

                    }

                    

                    // Smoothly lerp colors

                    mat.thrustCore.color.lerp(targetCoreColor, 0.08);

                    mat.thrustCore.emissive.lerp(targetCoreEmissive, 0.08);

                    mat.thrustMid.color.lerp(targetMidColor, 0.08);

                    mat.thrustMid.emissive.lerp(targetMidEmissive, 0.08);

                    mat.thrustOuter.color.lerp(targetOuterColor, 0.08);

                    mat.thrustOuter.emissive.lerp(targetOuterEmissive, 0.08);

                    thrustParticleMat.color.lerp(targetParticleColor, 0.08);

                    

                    // Lerp light color

                    const currentLightColor = new THREE.Color(thrustLight.color);

                    currentLightColor.lerp(new THREE.Color(targetLightColor), 0.08);

                    thrustLight.color.copy(currentLightColor);

                    

                    // Thrust intensity based on speed (boost during teleport)

                    const isAccelerating = st.t < accelZone && st.currentSpeed > 0.3;

                    const isTurning = Math.abs(st.targetBankAngle) > 0.05;

                    const thrustActive = isAccelerating || isTurning || st.currentSpeed > 0.5 || st.isTeleporting;

                    

                    if (thrustActive) {

                        st.thrusterIntensity = Math.min(st.thrusterIntensity + dt * 3, st.isTeleporting ? 1.2 : 1);

                    } else {

                        st.thrusterIntensity = Math.max(st.thrusterIntensity - dt * 2, 0.3);

                    }

                    

                    // Core beam intensity fluctuation (brighter)

                    mat.thrustCore.emissiveIntensity = (3.5 + Math.sin(time * 8) * 0.8) * st.thrusterIntensity;

                    mat.thrustCore.opacity = (0.9 + Math.sin(time * 6) * 0.1) * st.thrusterIntensity;

                    

                    // Beam layers subtle rotation

                    beamCore.rotation.y = time * 0.5;

                    beamMid.rotation.y = -time * 0.3;

                    beamOuter.rotation.y = time * 0.2;

                    

                    // Beam scale based on thrust intensity

                    const thrustScale = 0.5 + st.thrusterIntensity * 0.5;

                    thrustGroup.scale.set(thrustScale, thrustScale, thrustScale);

                    

                    // Thrust light flicker (brighter)

                    thrustLight.intensity = (4.0 + Math.sin(time * 10) * 1.0 + Math.sin(time * 17) * 0.5) * st.thrusterIntensity;

                    

                    // Animate thrust particles - longer travel distance

                    const positions = thrustParticleGeo.attributes.position.array;

                    for (let i = 0; i < thrustParticleCount; i++) {

                        positions[i * 3 + 1] -= thrustParticleSpeeds[i] * 0.6 * st.thrusterIntensity;

                        

                        if (positions[i * 3 + 1] < -38) {

                            const angle = Math.random() * Math.PI * 2;

                            const radius = Math.random() * 5;

                            positions[i * 3] = Math.cos(angle) * radius;

                            positions[i * 3 + 1] = 0;

                            positions[i * 3 + 2] = Math.sin(angle) * radius;

                        }

                        

                        positions[i * 3] *= 1.003;

                        positions[i * 3 + 2] *= 1.003;

                    }

                    thrustParticleGeo.attributes.position.needsUpdate = true;

                    thrustParticleMat.opacity = 0.85 * st.thrusterIntensity;

                    

                    // Main UFO light pulse (brighter)

                    ufoMainLight.intensity = 1.2 + Math.sin(time * 1.5) * 0.4 + st.teleportFlashIntensity * 3;

                    ufoRimLight.intensity = 0.8 + st.thrusterIntensity * 0.5 + st.teleportFlashIntensity * 2;

                    

                    // Teleport flash on all rim lights

                    if (st.teleportFlashIntensity > 0) {

                        for (let i = 0; i < rimLightCount; i++) {

                            rimLightMats[i].emissiveIntensity += st.teleportFlashIntensity * 5;

                        }

                        for (let i = 0; i < domeLightCount; i++) {

                            domeLightMats[i].emissiveIntensity += st.teleportFlashIntensity * 4;

                        }

                        mat.domeInner.emissiveIntensity += st.teleportFlashIntensity * 3;

                    }

                    

                    // ════════════════════════════════════════════════════════

                    // █  DEPTH OPACITY  █

                    // ════════════════════════════════════════════════════════

                    

                    // Make UFO fully visible during teleport or on mobile

                    if (st.isTeleporting || isMobile) {

                        st.targetOp = 1.0;

                        st.opacity = 1.0;

                    } else {

                        const distCam = astronautGroup.position.distanceTo(camera.position);

                        st.targetOp = distCam < 250 ? 0.4 : distCam < 450 ? 0.7 : 1.0;

                        st.opacity += (st.targetOp - st.opacity) * 0.015;

                    }

                };

            }



            // ===== ANIMATION =====

            let time = 0;

            let lastTime = performance.now();

            

            function animate() {

                requestAnimationFrame(animate);

                

                const currentTime = performance.now();

                const deltaTime = (currentTime - lastTime) / 1000;

                lastTime = currentTime;

                

                time += 0.016; // Consistent time for visual effects

                

                // Stars rotation

                stars.rotation.y += 0.0001;

                stars.rotation.x += 0.00005;

                

                // ===== PHYSICS SIMULATION =====

                simulatePhysics(deltaTime);

                updateConnections();

                

                // Update node shader time uniform

                nodeShaderMaterial.uniforms.time.value = time;

                

                // Gentle rotation of entire network

                nodePoints.rotation.y += 0.0002;

                lines.rotation.y += 0.0002;

                

                // Earth rotation

                earth.rotation.y += 0.0005;

                clouds.rotation.y += 0.0006;

                clouds.rotation.x += 0.0001;

                

                // Sun position for day/night cycle

                const sunAngle = time * 0.05;

                const sunDir = new THREE.Vector3(

                    Math.cos(sunAngle),

                    0.3,

                    Math.sin(sunAngle)

                ).normalize();

                earthMaterial.uniforms.sunDirection.value = sunDir;

                sunLight.position.set(sunDir.x * 5, sunDir.y * 5, sunDir.z * 5);

                

                // Update atmosphere view vector

                atmosphereMaterial.uniforms.viewVector.value = new THREE.Vector3().subVectors(

                    camera.position,

                    earthGroup.position

                );

                

                // ===== ASTRONAUT UPDATE =====

                if (updateAstronaut) updateAstronaut(time, deltaTime);

                

                renderer.render(scene, camera);

            }

            

            // ===== RESIZE HANDLER =====

            window.addEventListener('resize', () => {

                camera.aspect = window.innerWidth / window.innerHeight;

                camera.updateProjectionMatrix();

                renderer.setSize(window.innerWidth, window.innerHeight);

            });

            

            // Initialize connections and start animation

            updateConnections();

            animate();

            

            // Hide loading after init

            setTimeout(() => {

                document.getElementById('loadingOverlay')?.classList.add('hidden');

            }, 1500);

        })();



        // ==================== DASHBOARD LOGIC ====================

        const signalHistory = [];

        const SIGNAL_WINDOW = 5 * 60 * 1000;

        const TARGET_AGENT = '10m';

        let consecutiveErrors = 0;



        // ==================== REDIS-BACKED SIGNAL TRACKING ====================

        // ✅ MIGRATED: Signals now extracted from log polling instead of Ably WebSocket

        // This is compatible with HuggingFace Spaces + Redis architecture

        

        function extractAgentName(signalKey) {

            if (!signalKey) return 'unknown';

            signalKey = signalKey.toString().trim().toLowerCase();

            if (signalKey.includes('_')) {

                return signalKey.split('_')[0];

            }

            const match = signalKey.match(/\d+[mhdw]/);

            return match ? match[0] : 'unknown';

        }



        // Force Balance - Updated for new gauge design

        function updateForceBalance(buyPercent, sellPercent, dominant) {

            const buyFill = document.getElementById('gaugeFillBuy');

            const sellFill = document.getElementById('gaugeFillSell');

            const marker = document.getElementById('gaugeMarker');

            const buyVal = document.getElementById('forceBuyValue');

            const sellVal = document.getElementById('forceSellValue');

            const netVal = document.getElementById('netPositionValue');

            

            // Clamp values

            buyPercent = Math.min(100, Math.max(0, buyPercent || 0));

            sellPercent = Math.min(100, Math.max(0, sellPercent || 0));

            

            // Update fill bars using scaleX transform (0 to 1 range)

            if (buyFill) {

                buyFill.style.transform = `scaleX(${buyPercent / 100})`;

            }

            if (sellFill) {

                sellFill.style.transform = `scaleX(${sellPercent / 100})`;

            }

            

            // Update percentage values

            if (buyVal) buyVal.textContent = buyPercent.toFixed(1) + '%';

            if (sellVal) sellVal.textContent = sellPercent.toFixed(1) + '%';

            

            // Calculate and display net position

            const net = buyPercent - sellPercent;

            if (netVal) {

                netVal.textContent = (net >= 0 ? '+' : '') + net.toFixed(1);

                netVal.classList.remove('positive', 'negative', 'neutral');

                if (net > 0) {

                    netVal.classList.add('positive');

                } else if (net < 0) {

                    netVal.classList.add('negative');

                } else {

                    netVal.classList.add('neutral');

                }

            }

            

            // Position marker: 50% = center

            // Buy pushes left (towards 0%), Sell pushes right (towards 100%)

            const markerPos = 50 + ((sellPercent - buyPercent) / 2);

            if (marker) {

                marker.style.left = markerPos + '%';

                marker.classList.remove('buy-dominant', 'sell-dominant');

                if (dominant === 'BUY') {

                    marker.classList.add('buy-dominant');

                } else if (dominant === 'SELL') {

                    marker.classList.add('sell-dominant');

                }

            }

        }



        function updateDominantSignal() {

            const now = Date.now();

            const recentSignals = signalHistory.filter(s => now - s.timestamp < SIGNAL_WINDOW);

            

            const buyCount = recentSignals.filter(s => s.action === 'BUY').length;

            const sellCount = recentSignals.filter(s => s.action === 'SELL').length;

            const total = buyCount + sellCount;

            

            const el = document.getElementById('dominantSignal');

            const statsEl = document.getElementById('signalStats');

            

            let dominant = 'NEUTRAL';

            if (total > 0) {

                if (buyCount > sellCount) dominant = 'BUY';

                else if (sellCount > buyCount) dominant = 'SELL';

            }

            

            if (el) {

                el.textContent = dominant;

                el.className = 'signal-value signal-' + dominant.toLowerCase();

            }

            

            if (statsEl && total > 0) {

                const buyPct = ((buyCount / total) * 100).toFixed(0);

                const sellPct = ((sellCount / total) * 100).toFixed(0);

                statsEl.innerHTML = `<span>BUY: ${buyCount} (${buyPct}%)</span> • <span>SELL: ${sellCount} (${sellPct}%)</span> • <span>TOTAL: ${total}</span>`;

                

                updateForceBalance(parseFloat(buyPct), parseFloat(sellPct), dominant);

            }

        }



        // ==================== HELPER FUNCTIONS ====================

        

        // ✅ Safe text setter — guards against null, undefined, NaN, and "undefined" strings

        function setText(id, text) {

            const el = document.getElementById(id);

            if (el) {

                if (text === null || text === undefined || String(text).includes('undefined') || String(text).includes('NaN')) {

                    el.textContent = '—';

                } else {

                    el.textContent = text;

                }

            }

        }

        

        // ✅ Number formatter — compact display for large numbers

        function formatNumber(num) {

            if (num === undefined || num === null || isNaN(Number(num))) return '—';

            num = Number(num);

            if (num >= 1000000) return (num / 1000000).toFixed(1) + 'M';

            if (num >= 1000) return (num / 1000).toFixed(1) + 'K';

            return num.toLocaleString();

        }

        

        // ✅ Safe number formatter with decimal control

        function safeNum(val, decimals = 1) {

            if (val === undefined || val === null || val === '' || isNaN(Number(val))) return null;

            return Number(val).toFixed(decimals);

        }

        

        // ✅ Safe format with decimal control (returns string or dash)

        function formatNum(val, decimals) {

            if (val === undefined || val === null || val === '' || isNaN(Number(val))) return '—';

            return Number(val).toFixed(decimals);

        }



        function updateConnectionStatus(connected) {

            const el = document.getElementById('connectionStatus');

            if (el) {

                el.textContent = connected ? '● Connected' : '● Disconnected';

                el.className = 'connection-status ' + (connected ? 'connection-ok' : 'connection-error');

            }

        }



        // ✅ MIGRATED: HF Spaces compatible metrics fetch with fallback patterns

        function updateMetrics() {

            fetch('/api/metrics')

                .then(r => r.json())

                .then(data => {

                    consecutiveErrors = 0;

                    updateConnectionStatus(true);

                    

                    const now = new Date();

                    setText('lastUpdate', 'Last Observation: ' + now.toLocaleTimeString('en-US', { 

                        hour: '2-digit', 

                        minute: '2-digit', 

                        second: '2-digit',

                        hour12: false 

                    }));

                    

                    // V75: Update instrument bar from API asset field

                    if (data.asset) {

                        const instBar = document.getElementById('instBar');

                        if (instBar) instBar.textContent = data.asset;

                    }

                    

                    // Training metrics - use data.metrics path

                    if (data.metrics) {

                        setText('trainingSteps', formatNumber(data.metrics.training_steps));

                        setText('actorLoss', formatNum(data.metrics.actor_loss, 2));

                        setText('criticLoss', formatNum(data.metrics.critic_loss, 4));

                        setText('avnLoss', formatNum(data.metrics.avn_loss, 4));

                        

                        // AVN Accuracy with color coding

                        const accEl = document.getElementById('avnAccuracy');

                        if (accEl) {

                            const accRaw = data.metrics.avn_accuracy;

                            const accValid = accRaw !== undefined && accRaw !== null && !isNaN(Number(accRaw));

                            if (accValid) {

                                const accVal = Number(accRaw).toFixed(1);

                                accEl.textContent = accVal + '%';

                                accEl.style.color = parseFloat(accVal) >= 55 ? '#00d4aa' : '#ffa500';

                            } else {

                                accEl.textContent = '—';

                            }

                        }

                        

                        setText('bufferSize', formatNumber(data.metrics.buffer_size));

                        

                        // Reward metrics with match efficiency calculation

                        const matched = data.metrics.matched_rewards || 0;

                        const unmatched = data.metrics.unmatched_rewards || 0;

                        const total = matched + unmatched;

                        const matchRate = total > 0 ? (matched / total * 100).toFixed(1) + '%' : '—';

                        

                        setText('matchedRewards', matched > 0 ? formatNumber(matched) : '—');

                        setText('unmatchedRewards', unmatched > 0 ? formatNumber(unmatched) : '—');

                        setText('duplicates', formatNumber(data.metrics.duplicates));

                        setText('matchRate', matchRate);

                    }

                    

                    // ✅ Service status — handles different name formats from HF Spaces

                    if (data.services) {

                        updateServiceStatus('statusQuasar', data.services['quasar_engine'] || data.services['quasar'] || 'unknown');

                        updateServiceStatus('statusFeatures', data.services['features'] || data.services['feature_pipeline'] || 'active');

                        updateServiceStatus('statusRewards', data.services['rewards'] || data.services['reward_system'] || 'active');

                    }

                    

                    // Process count — handles HF Spaces format

                    const processCount = data.process_count || data.resources?.process_count || 1;

                    const procEl = document.getElementById('processCount');

                    const procVal = document.getElementById('processCountValue');

                    

                    if (procVal) procVal.textContent = processCount;

                    if (procEl) {

                        procEl.classList.remove('process-ok', 'process-warning');

                        procEl.classList.add(processCount >= 1 ? 'process-ok' : 'process-warning');

                    }

                    

                    // ✅ System resources — handles HF Spaces data shapes

                    if (data.resources) {

                        const cpuVal = safeNum(data.resources.cpu_percent);

                        setText('cpuPercent', cpuVal !== null ? cpuVal + '%' : '—');

                        const cpuBar = document.getElementById('cpuBar');

                        if (cpuBar) {

                            cpuBar.style.width = (cpuVal !== null ? Math.min(parseFloat(cpuVal), 100) : 0) + '%';

                            cpuBar.className = 'progress-fill' + (parseFloat(cpuVal) > 80 ? ' warning' : '');

                        }

                        

                        const memPct = safeNum(data.resources.memory_percent);

                        setText('memoryPercent', memPct !== null ? memPct + '%' : '—');

                        

                        const memUsed = data.resources.memory_used_gb;

                        const memTotal = data.resources.memory_total_gb;

                        const memUsedValid = memUsed !== undefined && memUsed !== null && memUsed !== '';

                        const memTotalValid = memTotal !== undefined && memTotal !== null && memTotal !== '';

                        setText('memoryUsed', (memUsedValid && memTotalValid) 

                            ? memUsed + ' / ' + memTotal + ' GB' 

                            : '—');

                        

                        const quasarMem = data.resources.quasar_memory_gb;

                        const quasarValid = quasarMem !== undefined && quasarMem !== null && quasarMem !== '';

                        setText('quasarMemory', quasarValid ? quasarMem + ' GB' : '—');

                    } else {

                        setText('cpuPercent', '—');

                        setText('memoryPercent', '—');

                        setText('memoryUsed', '—');

                        setText('quasarMemory', '—');

                    }

                    

                    // Checkpoint data

                    if (data.checkpoint) {

                        setText('checkpointFile', data.checkpoint.filename ?? '—');

                        setText('checkpointStep', data.checkpoint.step?.toLocaleString() ?? '—');

                        setText('checkpointSize', data.checkpoint.size_mb !== undefined ? data.checkpoint.size_mb + ' MB' : '—');

                        setText('checkpointModified', data.checkpoint.modified ?? '—');

                    }

                })

                .catch(error => {

                    console.error('Error fetching metrics:', error);

                    consecutiveErrors++;

                    if (consecutiveErrors >= 3) updateConnectionStatus(false);

                });

        }

        

        function updateServiceStatus(elementId, status) {

            const elem = document.getElementById(elementId);

            if (!elem) return;

            elem.textContent = (status || 'unknown').toUpperCase();

            

            if (status === 'active') {

                elem.className = 'status-badge status-active';

            } else if (status === 'unknown' || status === undefined || status === null) {

                // Unknown = booting/pending, not necessarily failed — show amber

                elem.className = 'status-badge status-unknown';

                elem.textContent = 'PENDING';

            } else {

                elem.className = 'status-badge status-inactive';

            }

        }



        // ✅ MIGRATED: HF Spaces compatible logs fetch

        // Strategy: Try /logs/quasar_engine (text) → fallback /api/logs/quasar (JSON)

        function updateLogs() {

            fetch('/logs/quasar_engine')

                .then(response => {

                    if (!response.ok) {

                        // Fallback to alternative endpoint

                        return fetch('/api/logs/quasar');

                    }

                    return response;

                })

                .then(response => {

                    const contentType = response.headers.get('content-type') || '';

                    if (contentType.includes('application/json')) {

                        return response.json().then(data => (data.lines || []).join('\n'));

                    }

                    return response.text();

                })

                .then(logText => {

                    const cont = document.getElementById('logContainer');

                    if (!cont) return;

                    

                    cont.innerHTML = '';

                    

                    const lines = logText.split('\n').filter(line => line.trim());

                    const recentLines = lines.slice(-50);

                    

                    recentLines.forEach(line => {

                        if (!line.trim()) return;

                        

                        const div = document.createElement('div');

                        div.className = 'log-line';

                        

                        // Style log lines based on content

                        if (line.includes('ERROR') || line.includes('error') || line.includes('Error') || line.includes('❌')) {

                            div.classList.add('log-error');

                        } else if (line.includes('WARNING') || line.includes('warning') || line.includes('Warning') || line.includes('⚠️')) {

                            div.classList.add('log-warning');

                        } else if (line.includes('INFO') || line.includes('✅') || line.includes('SUCCESS')) {

                            div.classList.add('log-info');

                        }

                        

                        // Extract signals for dominant signal tracker - filter by target agent

                        let agent = null;

                        const agentMatch1 = line.match(/(\d+[mhdw])_\d+/i);

                        if (agentMatch1) agent = agentMatch1[1].toLowerCase();

                        if (!agent) {

                            const agentMatch2 = line.match(/[\[\(](\d+[mhdw])[\]\)]/i);

                            if (agentMatch2) agent = agentMatch2[1].toLowerCase();

                        }

                        if (!agent) {

                            const agentMatch3 = line.match(/AVN[\s\-_]?(\d+[mhdw])[:\s]/i);

                            if (agentMatch3) agent = agentMatch3[1].toLowerCase();

                        }

                        

                        // Skip signals from other agents

                        if (agent && agent !== TARGET_AGENT) {

                            return;

                        }

                        

                        if (line.includes('AVN') && (line.includes('BUY') || line.includes('SELL'))) {

                            const buyMatch = line.match(/BUY.*conf[idence]*[=:]\s*([\d.]+)/i);

                            const sellMatch = line.match(/SELL.*conf[idence]*[=:]\s*([\d.]+)/i);

                            

                            if (buyMatch || sellMatch) {

                                const signal = {

                                    action: buyMatch ? 'BUY' : 'SELL',

                                    confidence: buyMatch ? parseFloat(buyMatch[1]) : parseFloat(sellMatch[1]),

                                    timestamp: Date.now()

                                };

                                signalHistory.push(signal);

                                

                                if (signalHistory.length > 100) {

                                    signalHistory.shift();

                                }

                            }

                        }

                        

                        div.textContent = line;

                        cont.appendChild(div);

                    });

                    

                    cont.scrollTop = cont.scrollHeight;

                    updateDominantSignal();

                })

                .catch(error => {

                    console.error('Error fetching logs:', error);

                });

        }



        // Visitors

        function updateVisitors() {

            fetch('/api/visitors')

                .then(r => r.json())

                .then(v => {

                    setText('activeVisitors', v.active_now || 0);

                    const tel = document.getElementById('totalVisitors');

                    if (tel) tel.textContent = (v.all_time_unique || 0) + ' total';

                })

                .catch(() => {});

        }



        // Accuracy Chart

        let accuracyChart;

        

        function initChart() {

            const ctx = document.getElementById('accuracyChart')?.getContext('2d');

            if (!ctx) return;

            

            // Chart.js gradient with earth tones

            const gradient = ctx.createLinearGradient(0, 0, 0, 200);

            gradient.addColorStop(0, 'rgba(0, 255, 136, 0.25)');

            gradient.addColorStop(0.5, 'rgba(64, 192, 160, 0.1)');

            gradient.addColorStop(1, 'rgba(0, 255, 136, 0)');

            

            accuracyChart = new Chart(ctx, {

                type: 'line',

                data: { 

                    labels: [], 

                    datasets: [{

                        label: 'AVN Accuracy',

                        borderColor: '#00ff88',

                        backgroundColor: gradient,

                        borderWidth: 2.5,

                        fill: true,

                        tension: 0.4,

                        pointRadius: 0,

                        pointHoverRadius: 6,

                        pointHoverBackgroundColor: '#00ff88',

                        pointHoverBorderColor: '#fff',

                        pointHoverBorderWidth: 2,

                        data: []

                    }]

                },

                options: {

                    responsive: true,

                    maintainAspectRatio: false,

                    interaction: {

                        intersect: false,

                        mode: 'index'

                    },

                    plugins: { 

                        legend: { display: false },

                        tooltip: { 

                            backgroundColor: 'rgba(0, 20, 40, 0.95)',

                            titleColor: '#fff',

                            titleFont: { size: 12, weight: '600', family: 'Outfit' },

                            bodyColor: '#00ff88',

                            bodyFont: { size: 14, weight: '700', family: 'Space Mono' },

                            borderColor: 'rgba(0, 255, 136, 0.3)',

                            borderWidth: 1,

                            padding: 12,

                            cornerRadius: 8,

                            displayColors: false,

                            callbacks: {

                                title: (items) => `Iteration ${items[0].label}`,

                                label: (item) => `Accuracy: ${item.raw.toFixed(1)}%`

                            }

                        }

                    },

                    scales: {

                        y: { 

                            min: 0, 

                            max: 100, 

                            grid: { 

                                color: 'rgba(255, 255, 255, 0.04)',

                                drawBorder: false

                            }, 

                            border: { display: false },

                            ticks: { 

                                color: 'rgba(255, 255, 255, 0.4)', 

                                callback: v => v + '%',

                                font: { size: 11, family: 'Space Mono' },

                                padding: 10,

                                stepSize: 20

                            } 

                        },

                        x: { 

                            grid: { display: false }, 

                            border: { display: false },

                            ticks: { 

                                color: 'rgba(255, 255, 255, 0.4)', 

                                maxTicksLimit: window.innerWidth <= 768 ? 5 : 8,

                                font: { size: 10, family: 'Space Mono' },

                                padding: 8

                            } 

                        }

                    }

                }

            });

        }



        // ✅ MIGRATED: Resilient accuracy fetch with fallbacks for HF Spaces

        async function updateAccuracy() {

            try {

                // Try dedicated accuracy endpoints first

                let stats = null;

                let history = [];

                

                try {

                    stats = await fetch('/api/accuracy/stats').then(r => r.json());

                } catch (e) {

                    // Fallback: extract from main metrics

                    try {

                        const metricsData = await fetch('/api/metrics').then(r => r.json());

                        if (metricsData.metrics && metricsData.metrics.avn_accuracy !== undefined) {

                            stats = {

                                current: metricsData.metrics.avn_accuracy,

                                average: metricsData.metrics.avn_accuracy,

                                last_10_avg: metricsData.metrics.avn_accuracy,

                                trend: 'stable'

                            };

                        }

                    } catch (e2) {

                        console.warn('Accuracy fallback also failed:', e2);

                    }

                }

                

                if (stats) {

                    setText('accuracy-current', (stats.current?.toFixed(1) || '—') + (stats.current !== undefined ? '%' : ''));

                    setText('accuracy-avg', (stats.average?.toFixed(1) || '—') + (stats.average !== undefined ? '%' : ''));

                    setText('accuracy-last10', (stats.last_10_avg?.toFixed(1) || '—') + (stats.last_10_avg !== undefined ? '%' : ''));

                    

                    const trend = document.getElementById('accuracy-trend');

                    if (trend && stats.trend) {

                        trend.classList.remove('rising', 'stable', 'declining');

                        

                        if (stats.trend === 'up') {

                            trend.classList.add('rising');

                            trend.innerHTML = '<span class="trend-arrow">▲</span><span>RISING</span>';

                        } else if (stats.trend === 'down') {

                            trend.classList.add('declining');

                            trend.innerHTML = '<span class="trend-arrow">▼</span><span>DECLINING</span>';

                        } else {

                            trend.classList.add('stable');

                            trend.innerHTML = '<span class="trend-arrow">―</span><span>STABLE</span>';

                        }

                    }

                }

                

                // Try to get accuracy history — real data only

                try {

                    history = await fetch('/api/accuracy/history').then(r => r.json());

                } catch (e) {

                    console.warn('Accuracy history endpoint unavailable');

                }

                

                // Update chart

                if (history.length > 0 && accuracyChart) {

                    const recent = history.slice(-(window.innerWidth <= 768 ? 30 : 50));

                    accuracyChart.data.labels = recent.map((_, i) => i + 1);

                    accuracyChart.data.datasets[0].data = recent.map(d => d.accuracy);

                    accuracyChart.update('none');

                }

            } catch(e) {

                console.warn('Accuracy fetch failed:', e);

            }

        }



        // ✅ INITIALIZATION — Tuned for HuggingFace Spaces + Redis

        updateMetrics();

        updateLogs();

        updateVisitors();

        initChart();

        setTimeout(updateAccuracy, 500);

        

        // Intervals — gentler on HF Spaces (slightly slower than local dev)

        setInterval(updateMetrics, 5000);   // Every 5 seconds

        setInterval(updateLogs, 8000);      // Every 8 seconds  

        setInterval(updateVisitors, 30000); // Every 30 seconds

        setInterval(updateAccuracy, 15000); // Every 15 seconds



        // ✅ Debug info for HF Spaces

        console.log('🌌 K1RL QUASAR Full-Featured Dashboard initialized');

        console.log('Platform: HuggingFace Spaces (Redis-backed)');

        console.log('Signal Tracking: Log-based extraction (replaced Ably WebSocket)');

        console.log('Target Agent:', TARGET_AGENT);

        console.log('API Endpoints: /api/metrics, /logs/quasar_engine, /api/visitors, /api/accuracy/*');

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