-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAI-SP500--MarketSimulator.html
More file actions
1607 lines (1530 loc) · 89.7 KB
/
Copy pathAI-SP500--MarketSimulator.html
File metadata and controls
1607 lines (1530 loc) · 89.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MARKET STORM // S&P 500 Bet Simulator</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Major+Mono+Display&family=Space+Grotesk:wght@400;500;700&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
<style>
:root{
--bg:#070a10; --panel:#0d1119; --panel2:#11161f; --line:#1c2530;
--ink:#e8edf4; --dim:#7c8aa0; --faint:#46556a;
--up:#16e0a3; --down:#ff4d6d; --gold:#ffc857; --cyan:#3fd0ff; --violet:#9b7bff;
--glow-up:0 0 16px rgba(22,224,163,.55);
--glow-down:0 0 16px rgba(255,77,109,.55);
}
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%}
body{
background:var(--bg); color:var(--ink);
font-family:'Space Grotesk',sans-serif;
overflow:hidden; -webkit-font-smoothing:antialiased;
}
#app{display:flex;flex-direction:column;height:100vh;width:100vw}
/* ---- top bar ---- */
header{
display:flex;align-items:center;gap:18px;
padding:10px 18px;border-bottom:1px solid var(--line);
background:linear-gradient(180deg,#0c1019,#080b11);
flex:0 0 auto;z-index:30;
}
.logo{font-family:'Major Mono Display',monospace;font-size:19px;letter-spacing:1px;white-space:nowrap}
.logo b{color:var(--cyan)}
.logo i{color:var(--gold);font-style:normal}
.idx{display:flex;align-items:baseline;gap:8px;font-family:'JetBrains Mono',monospace}
.idx .lbl{color:var(--faint);font-size:10px;letter-spacing:1px}
.idx .val{font-size:17px;font-weight:700}
.idx .chg{font-size:12px;font-weight:700}
.spark{height:30px;width:130px}
.clock{font-family:'JetBrains Mono',monospace;font-size:11px;color:var(--dim)}
.regime{
font-family:'JetBrains Mono',monospace;font-size:10px;letter-spacing:1px;
padding:4px 9px;border:1px solid var(--line);border-radius:4px;
}
.wallet{
margin-left:auto;display:flex;align-items:center;gap:14px;
font-family:'JetBrains Mono',monospace;
}
.wallet .cash{font-size:18px;font-weight:700;color:var(--gold)}
.wallet .sub{font-size:10px;color:var(--faint);letter-spacing:1px}
.themebtns{display:flex;gap:5px}
.themebtns button{
background:var(--panel2);border:1px solid var(--line);color:var(--dim);
font-size:9px;letter-spacing:.5px;padding:5px 7px;border-radius:4px;cursor:pointer;
font-family:'JetBrains Mono',monospace;text-transform:uppercase;
}
.themebtns button.on{border-color:var(--cyan);color:var(--cyan);box-shadow:0 0 8px rgba(63,208,255,.3)}
/* ---- main grid ---- */
main{flex:1;display:grid;grid-template-columns:288px 1fr 320px;min-height:0}
.col{display:flex;flex-direction:column;min-height:0;min-width:0}
.col.left{border-right:1px solid var(--line);background:var(--panel)}
.col.right{border-left:1px solid var(--line);background:var(--panel)}
.col.center{position:relative;background:#05070b}
.panelhead{
padding:9px 12px;font-family:'JetBrains Mono',monospace;font-size:10px;
letter-spacing:1.5px;color:var(--faint);text-transform:uppercase;
border-bottom:1px solid var(--line);display:flex;align-items:center;gap:8px;
flex:0 0 auto;
}
.panelhead .count{margin-left:auto;color:var(--cyan)}
/* ---- search / filter ---- */
.controls{padding:9px 10px;border-bottom:1px solid var(--line);flex:0 0 auto}
.search{
width:100%;background:var(--bg);border:1px solid var(--line);
color:var(--ink);padding:7px 9px;border-radius:5px;font-size:12px;
font-family:'JetBrains Mono',monospace;
}
.search:focus{outline:none;border-color:var(--cyan)}
.filters{display:flex;flex-wrap:wrap;gap:4px;margin-top:7px}
.chip{
font-size:9px;padding:3px 6px;border:1px solid var(--line);border-radius:10px;
color:var(--dim);cursor:pointer;font-family:'JetBrains Mono',monospace;
white-space:nowrap;background:var(--panel2);
}
.chip.on{background:var(--cyan);color:#04121a;border-color:var(--cyan);font-weight:700}
.sortrow{display:flex;gap:4px;margin-top:7px}
.sortrow button{
flex:1;font-size:9px;padding:4px;background:var(--panel2);border:1px solid var(--line);
color:var(--dim);border-radius:4px;cursor:pointer;font-family:'JetBrains Mono',monospace;
}
.sortrow button.on{color:var(--gold);border-color:var(--gold)}
/* ---- stock list ---- */
.list{overflow-y:auto;flex:1;min-height:0}
.list::-webkit-scrollbar{width:8px}
.list::-webkit-scrollbar-thumb{background:var(--line);border-radius:4px}
.row{
display:grid;grid-template-columns:46px 1fr auto auto;gap:7px;align-items:center;
padding:6px 11px;border-bottom:1px solid #131922;cursor:pointer;
}
.row:hover{background:var(--panel2)}
.row.sel{background:#141d2a;box-shadow:inset 3px 0 0 var(--cyan)}
.row .tk{font-family:'JetBrains Mono',monospace;font-weight:700;font-size:12px}
.row .nm{font-size:10px;color:var(--dim);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.row .px{font-family:'JetBrains Mono',monospace;font-size:11px;text-align:right}
.row .pc{font-family:'JetBrains Mono',monospace;font-size:10px;text-align:right;font-weight:700}
.row .star{font-size:11px;color:var(--faint);width:14px;text-align:center}
.row .star.on{color:var(--gold)}
.up{color:var(--up)} .down{color:var(--down)}
/* ---- center / 3d ---- */
#gl{position:absolute;inset:0;width:100%;height:100%;display:block}
.centerhud{
position:absolute;left:0;right:0;top:0;padding:10px 14px;
display:flex;gap:10px;align-items:flex-start;pointer-events:none;z-index:10;
}
.selcard{
background:rgba(10,14,20,.86);border:1px solid var(--line);border-radius:8px;
padding:11px 14px;backdrop-filter:blur(8px);pointer-events:auto;min-width:230px;
}
.selcard .t{display:flex;align-items:baseline;gap:9px}
.selcard .tk{font-family:'JetBrains Mono',monospace;font-size:21px;font-weight:700}
.selcard .sct{font-size:9px;color:var(--faint);letter-spacing:1px;text-transform:uppercase}
.selcard .nm{font-size:11px;color:var(--dim);margin-top:2px}
.selcard .pxbig{font-family:'JetBrains Mono',monospace;font-size:30px;font-weight:700;margin-top:7px}
.selcard .pxchg{font-family:'JetBrains Mono',monospace;font-size:13px;font-weight:700}
.statgrid{display:grid;grid-template-columns:1fr 1fr;gap:5px 14px;margin-top:9px}
.statgrid div{font-family:'JetBrains Mono',monospace;font-size:10px;color:var(--dim);display:flex;justify-content:space-between}
.statgrid div b{color:var(--ink)}
.selcard .actions{display:flex;gap:6px;margin-top:10px}
.selcard .actions button{
flex:1;padding:7px;border-radius:5px;font-size:10px;font-weight:700;cursor:pointer;
font-family:'JetBrains Mono',monospace;letter-spacing:.5px;border:1px solid;
}
.btnwatch{background:var(--panel2);border-color:var(--line)!important;color:var(--gold)}
.btnbet{background:rgba(63,208,255,.12);border-color:var(--cyan)!important;color:var(--cyan)}
.chartwrap{
position:absolute;left:14px;right:14px;bottom:14px;height:168px;
background:rgba(8,11,17,.82);border:1px solid var(--line);border-radius:8px;
backdrop-filter:blur(6px);z-index:10;padding:8px 10px 4px;
}
#chart{width:100%;height:100%;display:block}
.chartlbl{
position:absolute;top:8px;left:12px;font-family:'JetBrains Mono',monospace;
font-size:9px;color:var(--faint);letter-spacing:1px;
}
.speedctl{
position:absolute;right:14px;top:90px;display:flex;flex-direction:column;gap:5px;
z-index:10;pointer-events:auto;
}
.speedctl button{
width:38px;height:30px;background:rgba(10,14,20,.86);border:1px solid var(--line);
color:var(--dim);border-radius:5px;cursor:pointer;font-family:'JetBrains Mono',monospace;
font-size:10px;font-weight:700;
}
.speedctl button.on{border-color:var(--gold);color:var(--gold)}
/* ---- right column ---- */
.right .seg{display:flex;border-bottom:1px solid var(--line);flex:0 0 auto}
.right .seg button{
flex:1;padding:9px;background:transparent;border:none;color:var(--faint);
font-family:'JetBrains Mono',monospace;font-size:10px;letter-spacing:1px;cursor:pointer;
border-bottom:2px solid transparent;
}
.right .seg button.on{color:var(--cyan);border-bottom-color:var(--cyan)}
.tabwrap{flex:1;overflow-y:auto;min-height:0}
.tabwrap::-webkit-scrollbar{width:8px}
.tabwrap::-webkit-scrollbar-thumb{background:var(--line);border-radius:4px}
.empty{padding:34px 18px;text-align:center;color:var(--faint);font-size:11px;line-height:1.6}
.wrow{
padding:9px 12px;border-bottom:1px solid #131922;cursor:pointer;
display:grid;grid-template-columns:1fr auto;gap:3px;
}
.wrow:hover{background:var(--panel2)}
.wrow .tk{font-family:'JetBrains Mono',monospace;font-weight:700;font-size:12px}
.wrow .nm{font-size:9px;color:var(--faint)}
.wrow .px{font-family:'JetBrains Mono',monospace;font-size:12px;text-align:right}
.wrow .pc{font-family:'JetBrains Mono',monospace;font-size:10px;text-align:right;font-weight:700}
/* ---- bet builder ---- */
.betpanel{padding:13px}
.betpanel h4{
font-family:'JetBrains Mono',monospace;font-size:10px;color:var(--faint);
letter-spacing:1.5px;margin-bottom:9px;text-transform:uppercase;
}
.betpanel .tgt{
font-family:'JetBrains Mono',monospace;font-size:14px;font-weight:700;
margin-bottom:11px;display:flex;justify-content:space-between;align-items:center;
}
.betmode{display:flex;gap:5px;margin-bottom:11px}
.betmode button{
flex:1;padding:7px 4px;background:var(--panel2);border:1px solid var(--line);
color:var(--dim);font-family:'JetBrains Mono',monospace;font-size:9px;
border-radius:5px;cursor:pointer;letter-spacing:.3px;
}
.betmode button.on{border-color:var(--cyan);color:var(--cyan);background:rgba(63,208,255,.08)}
.field{margin-bottom:11px}
.field label{font-family:'JetBrains Mono',monospace;font-size:9px;color:var(--faint);letter-spacing:1px;display:block;margin-bottom:5px}
.dirbtns{display:flex;gap:6px}
.dirbtns button{
flex:1;padding:11px;border-radius:6px;font-family:'JetBrains Mono',monospace;
font-weight:700;font-size:12px;cursor:pointer;border:1px solid;
}
.dirbtns .bup{background:rgba(22,224,163,.1);border-color:var(--up)!important;color:var(--up)}
.dirbtns .bdn{background:rgba(255,77,109,.1);border-color:var(--down)!important;color:var(--down)}
.dirbtns button.on{box-shadow:0 0 0 2px currentColor inset}
.dirbtns button.dim{opacity:.32}
input[type=range]{width:100%;accent-color:var(--cyan)}
.numin{
width:100%;background:var(--bg);border:1px solid var(--line);color:var(--ink);
padding:7px 9px;border-radius:5px;font-family:'JetBrains Mono',monospace;font-size:13px;
}
.numin:focus{outline:none;border-color:var(--cyan)}
.stakeq{display:flex;gap:5px;margin-top:6px}
.stakeq button{
flex:1;padding:5px;background:var(--panel2);border:1px solid var(--line);
color:var(--dim);font-size:9px;border-radius:4px;cursor:pointer;
font-family:'JetBrains Mono',monospace;
}
.payout{
background:var(--panel2);border:1px solid var(--line);border-radius:6px;
padding:9px 11px;margin-bottom:11px;
}
.payout div{display:flex;justify-content:space-between;font-family:'JetBrains Mono',monospace;font-size:11px;margin:3px 0}
.payout .big{font-size:14px;font-weight:700}
.payout .odds{color:var(--gold)}
.placebet{
width:100%;padding:13px;border-radius:7px;border:1px solid var(--cyan);
background:linear-gradient(180deg,rgba(63,208,255,.22),rgba(63,208,255,.07));
color:var(--cyan);font-family:'JetBrains Mono',monospace;font-weight:700;
font-size:13px;letter-spacing:1px;cursor:pointer;
}
.placebet:disabled{opacity:.35;cursor:not-allowed}
.placebet:not(:disabled):hover{box-shadow:0 0 18px rgba(63,208,255,.4)}
/* ---- active positions ---- */
.pos{
padding:10px 12px;border-bottom:1px solid #131922;
}
.pos .ph{display:flex;justify-content:space-between;align-items:baseline}
.pos .tk{font-family:'JetBrains Mono',monospace;font-weight:700;font-size:13px}
.pos .typ{font-size:9px;font-family:'JetBrains Mono',monospace;padding:2px 6px;border-radius:3px;border:1px solid var(--line)}
.pos .detail{font-family:'JetBrains Mono',monospace;font-size:10px;color:var(--dim);margin-top:5px;line-height:1.6}
.pbar{height:5px;background:var(--bg);border-radius:3px;margin-top:7px;overflow:hidden;border:1px solid var(--line)}
.pbar i{display:block;height:100%;background:linear-gradient(90deg,var(--cyan),var(--violet))}
.pos .live{font-family:'JetBrains Mono',monospace;font-size:11px;font-weight:700;margin-top:5px;display:flex;justify-content:space-between}
/* ---- history / log ---- */
.logitem{
padding:8px 12px;border-bottom:1px solid #131922;font-family:'JetBrains Mono',monospace;
font-size:10px;display:flex;justify-content:space-between;gap:8px;
}
.logitem .l{color:var(--dim)}
.logitem .r{font-weight:700;white-space:nowrap}
/* ---- toast / outcome ---- */
#toasts{position:absolute;bottom:18px;left:50%;transform:translateX(-50%);z-index:60;display:flex;flex-direction:column;gap:8px;align-items:center}
.toast{
padding:9px 16px;border-radius:7px;font-family:'JetBrains Mono',monospace;
font-size:11px;font-weight:700;border:1px solid;background:rgba(8,11,17,.95);
animation:tin .35s ease, tout .4s ease 3.6s forwards;
}
@keyframes tin{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:none}}
@keyframes tout{to{opacity:0;transform:translateY(-10px)}}
#outcome{
position:absolute;inset:0;z-index:80;display:none;align-items:center;justify-content:center;
background:radial-gradient(circle at 50% 45%,rgba(0,0,0,.55),rgba(3,5,8,.93));
backdrop-filter:blur(3px);
}
#outcome.show{display:flex;animation:fade .3s ease}
@keyframes fade{from{opacity:0}to{opacity:1}}
.ocard{
text-align:center;padding:34px 48px;border-radius:14px;border:1px solid;
background:rgba(10,13,19,.94);max-width:430px;
}
.ocard .verdict{font-family:'Major Mono Display',monospace;font-size:42px;letter-spacing:2px}
.ocard .sub{font-family:'JetBrains Mono',monospace;font-size:12px;color:var(--dim);margin-top:8px}
.ocard .amt{font-family:'JetBrains Mono',monospace;font-size:32px;font-weight:700;margin:14px 0}
.ocard .ln{font-family:'JetBrains Mono',monospace;font-size:11px;color:var(--dim);margin:3px 0}
.ocard button{
margin-top:18px;padding:10px 26px;border-radius:7px;cursor:pointer;
font-family:'JetBrains Mono',monospace;font-weight:700;font-size:12px;
background:var(--panel2);border:1px solid var(--line);color:var(--ink);
}
/* ---- data feed modal ---- */
#feed{
position:absolute;inset:0;z-index:70;display:none;align-items:center;justify-content:center;
background:rgba(3,5,8,.9);backdrop-filter:blur(3px);
}
#feed.show{display:flex}
.feedcard{
width:520px;max-width:92vw;background:var(--panel);border:1px solid var(--line);
border-radius:12px;padding:20px;
}
.feedcard h3{font-family:'JetBrains Mono',monospace;font-size:13px;letter-spacing:1px;margin-bottom:6px}
.feedcard p{font-size:11px;color:var(--dim);line-height:1.6;margin-bottom:11px}
.feedcard textarea{
width:100%;height:130px;background:var(--bg);border:1px solid var(--line);
color:var(--ink);border-radius:6px;padding:9px;font-family:'JetBrains Mono',monospace;
font-size:11px;resize:vertical;
}
.feedcard .frow{display:flex;gap:8px;margin-top:12px}
.feedcard button{
flex:1;padding:9px;border-radius:6px;cursor:pointer;font-family:'JetBrains Mono',monospace;
font-size:11px;font-weight:700;
}
.feedcard .apply{background:rgba(63,208,255,.15);border:1px solid var(--cyan);color:var(--cyan)}
.feedcard .cancel{background:var(--panel2);border:1px solid var(--line);color:var(--dim)}
.miniftr{
flex:0 0 auto;padding:7px 12px;border-top:1px solid var(--line);
display:flex;gap:8px;align-items:center;
font-family:'JetBrains Mono',monospace;font-size:9px;color:var(--faint);
}
.miniftr button{
background:var(--panel2);border:1px solid var(--line);color:var(--dim);
font-size:9px;padding:4px 8px;border-radius:4px;cursor:pointer;
font-family:'JetBrains Mono',monospace;
}
.miniftr .stat{margin-left:auto}
@media(max-width:1100px){
main{grid-template-columns:230px 1fr 280px}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="logo"><b>MARKET</b> <i>STORM</i></div>
<div class="idx">
<span class="lbl">S&P 500</span>
<span class="val" id="idxVal">--</span>
<span class="chg" id="idxChg">--</span>
</div>
<canvas class="spark" id="idxSpark"></canvas>
<div class="regime" id="regime">CALM</div>
<div class="clock" id="clock">DAY 1 · 09:30</div>
<div class="wallet">
<div class="themebtns" id="themeBtns">
<button data-th="floor">FLOOR</button>
<button data-th="storm" class="on">STORM</button>
<button data-th="neon">NEON</button>
</div>
<div style="text-align:right">
<div class="cash" id="cash">$10,000</div>
<div class="sub" id="pnl">SESSION P/L $0</div>
</div>
</div>
</header>
<main>
<!-- LEFT: universe -->
<div class="col left">
<div class="panelhead">S&P 500 Universe <span class="count" id="uniCount">455</span></div>
<div class="controls">
<input class="search" id="search" placeholder="search ticker / name…" autocomplete="off">
<div class="filters" id="sectorChips"></div>
<div class="sortrow">
<button data-sort="weight" class="on">▼ WEIGHT</button>
<button data-sort="change">▼ %CHG</button>
<button data-sort="ticker">A–Z</button>
</div>
</div>
<div class="list" id="stockList"></div>
<div class="miniftr">
<button id="dataBtn">⛁ DATA FEED</button>
<span class="stat" id="feedStat">SIM</span>
</div>
</div>
<!-- CENTER: 3D + chart -->
<div class="col center">
<canvas id="gl"></canvas>
<div class="centerhud">
<div class="selcard" id="selCard"></div>
</div>
<div class="speedctl" id="speedCtl">
<button data-sp="0">⏸</button>
<button data-sp="1" class="on">1×</button>
<button data-sp="3">3×</button>
<button data-sp="8">8×</button>
</div>
<div class="chartwrap">
<div class="chartlbl" id="chartLbl">PRICE HISTORY</div>
<canvas id="chart"></canvas>
</div>
<div id="toasts"></div>
<div id="outcome"><div class="ocard" id="ocard"></div></div>
<div id="feed">
<div class="feedcard">
<h3>⛁ EXTERNAL DATA FEED</h3>
<p>This simulator runs a fully procedural market engine — no live API. To anchor it to real data, paste rows below as <b>TICKER,PRICE</b> (one per line). Matching tickers get re-seeded to your prices; the engine then simulates forward from there.</p>
<textarea id="feedText" placeholder="AAPL,212.50 MSFT,438.10 NVDA,141.20 TSLA,255.00"></textarea>
<div class="frow">
<button class="cancel" id="feedCancel">CANCEL</button>
<button class="apply" id="feedApply">RE-SEED & SIMULATE</button>
</div>
</div>
</div>
</div>
<!-- RIGHT: watchlist / bet / positions -->
<div class="col right">
<div class="seg" id="seg">
<button data-tab="watch" class="on">WATCH</button>
<button data-tab="bet">BET</button>
<button data-tab="positions">LIVE <span id="posCount"></span></button>
<button data-tab="log">LOG</button>
</div>
<div class="tabwrap" id="tabWrap"></div>
</div>
</main>
</div>
<script id="sp500data">
const SP500=[{t:'AAPL',n:'Apple Inc.',s:'Information Technology',w:7.0},{t:'MSFT',n:'Microsoft Corp.',s:'Information Technology',w:6.5},{t:'NVDA',n:'NVIDIA Corp.',s:'Information Technology',w:6.8},{t:'AMZN',n:'Amazon.com Inc.',s:'Consumer Discretionary',w:3.8},{t:'META',n:'Meta Platforms Inc.',s:'Communication Services',w:2.6},{t:'GOOGL',n:'Alphabet Inc. Class A',s:'Communication Services',w:2.0},{t:'GOOG',n:'Alphabet Inc. Class C',s:'Communication Services',w:1.7},{t:'AVGO',n:'Broadcom Inc.',s:'Information Technology',w:1.7},{t:'TSLA',n:'Tesla Inc.',s:'Consumer Discretionary',w:1.6},{t:'BRK.B',n:'Berkshire Hathaway Class B',s:'Financials',w:1.7},{t:'JPM',n:'JPMorgan Chase & Co.',s:'Financials',w:1.5},{t:'LLY',n:'Eli Lilly and Co.',s:'Health Care',w:1.4},{t:'V',n:'Visa Inc.',s:'Financials',w:1.0},{t:'XOM',n:'Exxon Mobil Corp.',s:'Energy',w:1.0},{t:'UNH',n:'UnitedHealth Group Inc.',s:'Health Care',w:1.0},{t:'MA',n:'Mastercard Inc.',s:'Financials',w:0.9},{t:'COST',n:'Costco Wholesale Corp.',s:'Consumer Staples',w:0.9},{t:'HD',n:'Home Depot Inc.',s:'Consumer Discretionary',w:0.8},{t:'PG',n:'Procter & Gamble Co.',s:'Consumer Staples',w:0.8},{t:'WMT',n:'Walmart Inc.',s:'Consumer Staples',w:0.9},{t:'JNJ',n:'Johnson & Johnson',s:'Health Care',w:0.8},{t:'NFLX',n:'Netflix Inc.',s:'Communication Services',w:0.9},{t:'ABBV',n:'AbbVie Inc.',s:'Health Care',w:0.7},{t:'BAC',n:'Bank of America Corp.',s:'Financials',w:0.7},{t:'CRM',n:'Salesforce Inc.',s:'Information Technology',w:0.6},{t:'ORCL',n:'Oracle Corp.',s:'Information Technology',w:0.7},{t:'CVX',n:'Chevron Corp.',s:'Energy',w:0.6},{t:'KO',n:'Coca-Cola Co.',s:'Consumer Staples',w:0.6},{t:'MRK',n:'Merck & Co. Inc.',s:'Health Care',w:0.6},{t:'WFC',n:'Wells Fargo & Co.',s:'Financials',w:0.6},{t:'CSCO',n:'Cisco Systems Inc.',s:'Information Technology',w:0.5},{t:'ACN',n:'Accenture plc',s:'Information Technology',w:0.5},{t:'AMD',n:'Advanced Micro Devices',s:'Information Technology',w:0.5},{t:'PEP',n:'PepsiCo Inc.',s:'Consumer Staples',w:0.5},{t:'ADBE',n:'Adobe Inc.',s:'Information Technology',w:0.4},{t:'LIN',n:'Linde plc',s:'Materials',w:0.5},{t:'MCD',n:'McDonald\'s Corp.',s:'Consumer Discretionary',w:0.5},{t:'TMO',n:'Thermo Fisher Scientific',s:'Health Care',w:0.4},{t:'ABT',n:'Abbott Laboratories',s:'Health Care',w:0.4},{t:'GE',n:'GE Aerospace',s:'Industrials',w:0.5},{t:'PM',n:'Philip Morris International',s:'Consumer Staples',w:0.5},{t:'IBM',n:'International Business Machines',s:'Information Technology',w:0.5},{t:'TXN',n:'Texas Instruments Inc.',s:'Information Technology',w:0.4},{t:'ISRG',n:'Intuitive Surgical Inc.',s:'Health Care',w:0.4},{t:'QCOM',n:'Qualcomm Inc.',s:'Information Technology',w:0.4},{t:'GS',n:'Goldman Sachs Group',s:'Financials',w:0.4},{t:'CAT',n:'Caterpillar Inc.',s:'Industrials',w:0.4},{t:'DIS',n:'Walt Disney Co.',s:'Communication Services',w:0.4},{t:'VZ',n:'Verizon Communications',s:'Communication Services',w:0.3},{t:'INTU',n:'Intuit Inc.',s:'Information Technology',w:0.4},{t:'MS',n:'Morgan Stanley',s:'Financials',w:0.3},{t:'RTX',n:'RTX Corp.',s:'Industrials',w:0.4},{t:'AMGN',n:'Amgen Inc.',s:'Health Care',w:0.3},{t:'NOW',n:'ServiceNow Inc.',s:'Information Technology',w:0.4},{t:'T',n:'AT&T Inc.',s:'Communication Services',w:0.3},{t:'SPGI',n:'S&P Global Inc.',s:'Financials',w:0.3},{t:'PFE',n:'Pfizer Inc.',s:'Health Care',w:0.3},{t:'BKNG',n:'Booking Holdings Inc.',s:'Consumer Discretionary',w:0.3},{t:'UBER',n:'Uber Technologies Inc.',s:'Industrials',w:0.3},{t:'AXP',n:'American Express Co.',s:'Financials',w:0.3},{t:'BSX',n:'Boston Scientific Corp.',s:'Health Care',w:0.3},{t:'PLTR',n:'Palantir Technologies',s:'Information Technology',w:0.4},{t:'SCHW',n:'Charles Schwab Corp.',s:'Financials',w:0.3},{t:'BLK',n:'BlackRock Inc.',s:'Financials',w:0.3},{t:'C',n:'Citigroup Inc.',s:'Financials',w:0.3},{t:'TJX',n:'TJX Companies Inc.',s:'Consumer Discretionary',w:0.3},{t:'SYK',n:'Stryker Corp.',s:'Health Care',w:0.3},{t:'LOW',n:'Lowe\'s Companies Inc.',s:'Consumer Discretionary',w:0.3},{t:'HON',n:'Honeywell International',s:'Industrials',w:0.3},{t:'ADP',n:'Automatic Data Processing',s:'Industrials',w:0.2},{t:'DHR',n:'Danaher Corp.',s:'Health Care',w:0.3},{t:'NEE',n:'NextEra Energy Inc.',s:'Utilities',w:0.3},{t:'ETN',n:'Eaton Corp. plc',s:'Industrials',w:0.3},{t:'COP',n:'ConocoPhillips',s:'Energy',w:0.2},{t:'VRTX',n:'Vertex Pharmaceuticals',s:'Health Care',w:0.2},{t:'MU',n:'Micron Technology Inc.',s:'Information Technology',w:0.3},{t:'GILD',n:'Gilead Sciences Inc.',s:'Health Care',w:0.2},{t:'PANW',n:'Palo Alto Networks',s:'Information Technology',w:0.3},{t:'ANET',n:'Arista Networks Inc.',s:'Information Technology',w:0.3},{t:'KKR',n:'KKR & Co. Inc.',s:'Financials',w:0.2},{t:'ADI',n:'Analog Devices Inc.',s:'Information Technology',w:0.2},{t:'LRCX',n:'Lam Research Corp.',s:'Information Technology',w:0.2},{t:'MDT',n:'Medtronic plc',s:'Health Care',w:0.2},{t:'CB',n:'Chubb Ltd.',s:'Financials',w:0.2},{t:'PGR',n:'Progressive Corp.',s:'Financials',w:0.2},{t:'SBUX',n:'Starbucks Corp.',s:'Consumer Discretionary',w:0.2},{t:'KLAC',n:'KLA Corp.',s:'Information Technology',w:0.2},{t:'INTC',n:'Intel Corp.',s:'Information Technology',w:0.2},{t:'APH',n:'Amphenol Corp.',s:'Information Technology',w:0.2},{t:'MMC',n:'Marsh & McLennan',s:'Financials',w:0.2},{t:'AMAT',n:'Applied Materials Inc.',s:'Information Technology',w:0.2},{t:'PLD',n:'Prologis Inc.',s:'Real Estate',w:0.2},{t:'CMG',n:'Chipotle Mexican Grill',s:'Consumer Discretionary',w:0.2},{t:'BX',n:'Blackstone Inc.',s:'Financials',w:0.2},{t:'SO',n:'Southern Co.',s:'Utilities',w:0.2},{t:'TT',n:'Trane Technologies',s:'Industrials',w:0.2},{t:'CRWD',n:'CrowdStrike Holdings',s:'Information Technology',w:0.2},{t:'WELL',n:'Welltower Inc.',s:'Real Estate',w:0.2},{t:'DE',n:'Deere & Co.',s:'Industrials',w:0.2},{t:'ICE',n:'Intercontinental Exchange',s:'Financials',w:0.2},{t:'DUK',n:'Duke Energy Corp.',s:'Utilities',w:0.2},{t:'ELV',n:'Elevance Health Inc.',s:'Health Care',w:0.2},{t:'NKE',n:'Nike Inc.',s:'Consumer Discretionary',w:0.2},{t:'LMT',n:'Lockheed Martin Corp.',s:'Industrials',w:0.2},{t:'CME',n:'CME Group Inc.',s:'Financials',w:0.2},{t:'PH',n:'Parker-Hannifin Corp.',s:'Industrials',w:0.2},{t:'MO',n:'Altria Group Inc.',s:'Consumer Staples',w:0.2},{t:'WM',n:'Waste Management Inc.',s:'Industrials',w:0.2},{t:'AON',n:'Aon plc',s:'Financials',w:0.2},{t:'MCK',n:'McKesson Corp.',s:'Health Care',w:0.2},{t:'TDG',n:'TransDigm Group Inc.',s:'Industrials',w:0.2},{t:'CTAS',n:'Cintas Corp.',s:'Industrials',w:0.2},{t:'EQIX',n:'Equinix Inc.',s:'Real Estate',w:0.2},{t:'CDNS',n:'Cadence Design Systems',s:'Information Technology',w:0.2},{t:'ABNB',n:'Airbnb Inc.',s:'Consumer Discretionary',w:0.1},{t:'APO',n:'Apollo Global Management',s:'Financials',w:0.2},{t:'MSI',n:'Motorola Solutions Inc.',s:'Information Technology',w:0.1},{t:'SNPS',n:'Synopsys Inc.',s:'Information Technology',w:0.1},{t:'USB',n:'U.S. Bancorp',s:'Financials',w:0.1},{t:'ITW',n:'Illinois Tool Works',s:'Industrials',w:0.1},{t:'ORLY',n:'O\'Reilly Automotive',s:'Consumer Discretionary',w:0.1},{t:'ZTS',n:'Zoetis Inc.',s:'Health Care',w:0.1},{t:'GD',n:'General Dynamics Corp.',s:'Industrials',w:0.1},{t:'NOC',n:'Northrop Grumman Corp.',s:'Industrials',w:0.1},{t:'COF',n:'Capital One Financial',s:'Financials',w:0.1},{t:'CL',n:'Colgate-Palmolive Co.',s:'Consumer Staples',w:0.1},{t:'WMB',n:'Williams Companies Inc.',s:'Energy',w:0.1},{t:'EOG',n:'EOG Resources Inc.',s:'Energy',w:0.1},{t:'PYPL',n:'PayPal Holdings Inc.',s:'Financials',w:0.1},{t:'MMM',n:'3M Co.',s:'Industrials',w:0.1},{t:'CSX',n:'CSX Corp.',s:'Industrials',w:0.1},{t:'BDX',n:'Becton Dickinson & Co.',s:'Health Care',w:0.1},{t:'EMR',n:'Emerson Electric Co.',s:'Industrials',w:0.1},{t:'CARR',n:'Carrier Global Corp.',s:'Industrials',w:0.1},{t:'APD',n:'Air Products & Chemicals',s:'Materials',w:0.1},{t:'HCA',n:'HCA Healthcare Inc.',s:'Health Care',w:0.1},{t:'FCX',n:'Freeport-McMoRan Inc.',s:'Materials',w:0.1},{t:'NEM',n:'Newmont Corp.',s:'Materials',w:0.1},{t:'MAR',n:'Marriott International',s:'Consumer Discretionary',w:0.1},{t:'TFC',n:'Truist Financial Corp.',s:'Financials',w:0.1},{t:'ADSK',n:'Autodesk Inc.',s:'Information Technology',w:0.1},{t:'ROP',n:'Roper Technologies Inc.',s:'Information Technology',w:0.1},{t:'OKE',n:'ONEOK Inc.',s:'Energy',w:0.1},{t:'AJG',n:'Arthur J. Gallagher & Co.',s:'Financials',w:0.1},{t:'FDX',n:'FedEx Corp.',s:'Industrials',w:0.1},{t:'SLB',n:'Schlumberger Ltd.',s:'Energy',w:0.1},{t:'PCAR',n:'PACCAR Inc.',s:'Industrials',w:0.1},{t:'NXPI',n:'NXP Semiconductors',s:'Information Technology',w:0.1},{t:'SPG',n:'Simon Property Group',s:'Real Estate',w:0.1},{t:'GM',n:'General Motors Co.',s:'Consumer Discretionary',w:0.1},{t:'TGT',n:'Target Corp.',s:'Consumer Staples',w:0.1},{t:'AFL',n:'Aflac Inc.',s:'Financials',w:0.1},{t:'AEP',n:'American Electric Power',s:'Utilities',w:0.1},{t:'PSX',n:'Phillips 66',s:'Energy',w:0.1},{t:'MET',n:'MetLife Inc.',s:'Financials',w:0.1},{t:'DLR',n:'Digital Realty Trust',s:'Real Estate',w:0.1},{t:'ECL',n:'Ecolab Inc.',s:'Materials',w:0.1},{t:'TRV',n:'Travelers Companies',s:'Financials',w:0.1},{t:'ROST',n:'Ross Stores Inc.',s:'Consumer Discretionary',w:0.1},{t:'GEV',n:'GE Vernova Inc.',s:'Industrials',w:0.1},{t:'SRE',n:'Sempra',s:'Utilities',w:0.1},{t:'O',n:'Realty Income Corp.',s:'Real Estate',w:0.1},{t:'JCI',n:'Johnson Controls Intl',s:'Industrials',w:0.1},{t:'CPRT',n:'Copart Inc.',s:'Industrials',w:0.1},{t:'AZO',n:'AutoZone Inc.',s:'Consumer Discretionary',w:0.1},{t:'URI',n:'United Rentals Inc.',s:'Industrials',w:0.1},{t:'FICO',n:'Fair Isaac Corp.',s:'Information Technology',w:0.1},{t:'PWR',n:'Quanta Services Inc.',s:'Industrials',w:0.1},{t:'DHI',n:'D.R. Horton Inc.',s:'Consumer Discretionary',w:0.1},{t:'MNST',n:'Monster Beverage Corp.',s:'Consumer Staples',w:0.1},{t:'HLT',n:'Hilton Worldwide Holdings',s:'Consumer Discretionary',w:0.1},{t:'KMI',n:'Kinder Morgan Inc.',s:'Energy',w:0.1},{t:'COR',n:'Cencora Inc.',s:'Health Care',w:0.1},{t:'TEL',n:'TE Connectivity plc',s:'Information Technology',w:0.1},{t:'BK',n:'Bank of New York Mellon',s:'Financials',w:0.1},{t:'NSC',n:'Norfolk Southern Corp.',s:'Industrials',w:0.1},{t:'AMP',n:'Ameriprise Financial',s:'Financials',w:0.1},{t:'PAYX',n:'Paychex Inc.',s:'Industrials',w:0.1},{t:'MPC',n:'Marathon Petroleum Corp.',s:'Energy',w:0.1},{t:'CMI',n:'Cummins Inc.',s:'Industrials',w:0.1},{t:'ALL',n:'Allstate Corp.',s:'Financials',w:0.1},{t:'AIG',n:'American International Group',s:'Financials',w:0.1},{t:'D',n:'Dominion Energy Inc.',s:'Utilities',w:0.1},{t:'FANG',n:'Diamondback Energy',s:'Energy',w:0.1},{t:'MSCI',n:'MSCI Inc.',s:'Financials',w:0.1},{t:'PEG',n:'Public Service Enterprise',s:'Utilities',w:0.1},{t:'FAST',n:'Fastenal Co.',s:'Industrials',w:0.1},{t:'KMB',n:'Kimberly-Clark Corp.',s:'Consumer Staples',w:0.1},{t:'DASH',n:'DoorDash Inc.',s:'Consumer Discretionary',w:0.1},{t:'CTVA',n:'Corteva Inc.',s:'Materials',w:0.1},{t:'ODFL',n:'Old Dominion Freight Line',s:'Industrials',w:0.1},{t:'VST',n:'Vistra Corp.',s:'Utilities',w:0.1},{t:'EW',n:'Edwards Lifesciences',s:'Health Care',w:0.1},{t:'HWM',n:'Howmet Aerospace Inc.',s:'Industrials',w:0.1},{t:'GWW',n:'W.W. Grainger Inc.',s:'Industrials',w:0.1},{t:'A',n:'Agilent Technologies',s:'Health Care',w:0.1},{t:'F',n:'Ford Motor Co.',s:'Consumer Discretionary',w:0.1},{t:'LHX',n:'L3Harris Technologies',s:'Industrials',w:0.1},{t:'EXC',n:'Exelon Corp.',s:'Utilities',w:0.1},{t:'KVUE',n:'Kenvue Inc.',s:'Consumer Staples',w:0.1},{t:'CCI',n:'Crown Castle Inc.',s:'Real Estate',w:0.1},{t:'VRSK',n:'Verisk Analytics Inc.',s:'Industrials',w:0.1},{t:'OTIS',n:'Otis Worldwide Corp.',s:'Industrials',w:0.1},{t:'IT',n:'Gartner Inc.',s:'Information Technology',w:0.1},{t:'PCG',n:'PG&E Corp.',s:'Utilities',w:0.1},{t:'HUM',n:'Humana Inc.',s:'Health Care',w:0.1},{t:'EA',n:'Electronic Arts Inc.',s:'Communication Services',w:0.1},{t:'GLW',n:'Corning Inc.',s:'Information Technology',w:0.1},{t:'IR',n:'Ingersoll Rand Inc.',s:'Industrials',w:0.1},{t:'YUM',n:'Yum! Brands Inc.',s:'Consumer Discretionary',w:0.1},{t:'RSG',n:'Republic Services Inc.',s:'Industrials',w:0.1},{t:'GEHC',n:'GE HealthCare Tech',s:'Health Care',w:0.1},{t:'DAL',n:'Delta Air Lines Inc.',s:'Industrials',w:0.1},{t:'ED',n:'Consolidated Edison',s:'Utilities',w:0.1},{t:'CBRE',n:'CBRE Group Inc.',s:'Real Estate',w:0.1},{t:'PRU',n:'Prudential Financial',s:'Financials',w:0.1},{t:'LULU',n:'Lululemon Athletica',s:'Consumer Discretionary',w:0.1},{t:'XEL',n:'Xcel Energy Inc.',s:'Utilities',w:0.1},{t:'DD',n:'DuPont de Nemours Inc.',s:'Materials',w:0.1},{t:'VLO',n:'Valero Energy Corp.',s:'Energy',w:0.1},{t:'ACGL',n:'Arch Capital Group',s:'Financials',w:0.1},{t:'RCL',n:'Royal Caribbean Cruises',s:'Consumer Discretionary',w:0.1},{t:'HES',n:'Hess Corp.',s:'Energy',w:0.1},{t:'CSGP',n:'CoStar Group Inc.',s:'Real Estate',w:0.1},{t:'SYY',n:'Sysco Corp.',s:'Consumer Staples',w:0.1},{t:'KDP',n:'Keurig Dr Pepper Inc.',s:'Consumer Staples',w:0.1},{t:'EXR',n:'Extra Space Storage',s:'Real Estate',w:0.1},{t:'WAB',n:'Westinghouse Air Brake',s:'Industrials',w:0.1},{t:'DXCM',n:'DexCom Inc.',s:'Health Care',w:0.1},{t:'EFX',n:'Equifax Inc.',s:'Industrials',w:0.1},{t:'TTWO',n:'Take-Two Interactive',s:'Communication Services',w:0.1},{t:'NUE',n:'Nucor Corp.',s:'Materials',w:0.1},{t:'KR',n:'Kroger Co.',s:'Consumer Staples',w:0.1},{t:'IRM',n:'Iron Mountain Inc.',s:'Real Estate',w:0.1},{t:'IQV',n:'IQVIA Holdings Inc.',s:'Health Care',w:0.1},{t:'MTB',n:'M&T Bank Corp.',s:'Financials',w:0.1},{t:'HIG',n:'Hartford Financial Services',s:'Financials',w:0.1},{t:'VICI',n:'VICI Properties Inc.',s:'Real Estate',w:0.1},{t:'WTW',n:'Willis Towers Watson',s:'Financials',w:0.1},{t:'AVB',n:'AvalonBay Communities',s:'Real Estate',w:0.1},{t:'OXY',n:'Occidental Petroleum',s:'Energy',w:0.1},{t:'EBAY',n:'eBay Inc.',s:'Consumer Discretionary',w:0.1},{t:'ROK',n:'Rockwell Automation',s:'Industrials',w:0.1},{t:'GIS',n:'General Mills Inc.',s:'Consumer Staples',w:0.1},{t:'BRO',n:'Brown & Brown Inc.',s:'Financials',w:0.1},{t:'CAH',n:'Cardinal Health Inc.',s:'Health Care',w:0.1},{t:'IDXX',n:'IDEXX Laboratories',s:'Health Care',w:0.1},{t:'FITB',n:'Fifth Third Bancorp',s:'Financials',w:0.1},{t:'ANSS',n:'Ansys Inc.',s:'Information Technology',w:0.1},{t:'WEC',n:'WEC Energy Group',s:'Utilities',w:0.1},{t:'MCHP',n:'Microchip Technology',s:'Information Technology',w:0.1},{t:'DOW',n:'Dow Inc.',s:'Materials',w:0.1},{t:'TSCO',n:'Tractor Supply Co.',s:'Consumer Discretionary',w:0.1},{t:'KEYS',n:'Keysight Technologies',s:'Information Technology',w:0.1},{t:'EQT',n:'EQT Corp.',s:'Energy',w:0.1},{t:'CPAY',n:'Corpay Inc.',s:'Financials',w:0.1},{t:'EXE',n:'Expand Energy Corp.',s:'Energy',w:0.1},{t:'HPQ',n:'HP Inc.',s:'Information Technology',w:0.1},{t:'GRMN',n:'Garmin Ltd.',s:'Consumer Discretionary',w:0.1},{t:'PPG',n:'PPG Industries Inc.',s:'Materials',w:0.1},{t:'STZ',n:'Constellation Brands',s:'Consumer Staples',w:0.1},{t:'DFS',n:'Discover Financial Services',s:'Financials',w:0.1},{t:'ON',n:'ON Semiconductor Corp.',s:'Information Technology',w:0.1},{t:'FTNT',n:'Fortinet Inc.',s:'Information Technology',w:0.1},{t:'TROW',n:'T. Rowe Price Group',s:'Financials',w:0.1},{t:'NDAQ',n:'Nasdaq Inc.',s:'Financials',w:0.1},{t:'VMC',n:'Vulcan Materials Co.',s:'Materials',w:0.1},{t:'MLM',n:'Martin Marietta Materials',s:'Materials',w:0.1},{t:'CHTR',n:'Charter Communications',s:'Communication Services',w:0.1},{t:'BR',n:'Broadridge Financial',s:'Industrials',w:0.1},{t:'DVN',n:'Devon Energy Corp.',s:'Energy',w:0.1},{t:'WST',n:'West Pharmaceutical',s:'Health Care',w:0.1},{t:'AWK',n:'American Water Works',s:'Utilities',w:0.1},{t:'ADM',n:'Archer-Daniels-Midland',s:'Consumer Staples',w:0.1},{t:'CHD',n:'Church & Dwight Co.',s:'Consumer Staples',w:0.1},{t:'EL',n:'Estee Lauder Companies',s:'Consumer Staples',w:0.1},{t:'HSY',n:'Hershey Co.',s:'Consumer Staples',w:0.1},{t:'SW',n:'Smurfit WestRock plc',s:'Materials',w:0.1},{t:'PHM',n:'PulteGroup Inc.',s:'Consumer Discretionary',w:0.1},{t:'RJF',n:'Raymond James Financial',s:'Financials',w:0.1},{t:'GDDY',n:'GoDaddy Inc.',s:'Information Technology',w:0.1},{t:'TER',n:'Teradyne Inc.',s:'Information Technology',w:0.1},{t:'HUBB',n:'Hubbell Inc.',s:'Industrials',w:0.1},{t:'TYL',n:'Tyler Technologies Inc.',s:'Information Technology',w:0.1},{t:'DTE',n:'DTE Energy Co.',s:'Utilities',w:0.1},{t:'VTR',n:'Ventas Inc.',s:'Real Estate',w:0.1},{t:'CDW',n:'CDW Corp.',s:'Information Technology',w:0.1},{t:'BIIB',n:'Biogen Inc.',s:'Health Care',w:0.1},{t:'SBAC',n:'SBA Communications',s:'Real Estate',w:0.1},{t:'AEE',n:'Ameren Corp.',s:'Utilities',w:0.1},{t:'ROL',n:'Rollins Inc.',s:'Industrials',w:0.1},{t:'ZBH',n:'Zimmer Biomet Holdings',s:'Health Care',w:0.1},{t:'PPL',n:'PPL Corp.',s:'Utilities',w:0.1},{t:'WRB',n:'W.R. Berkley Corp.',s:'Financials',w:0.1},{t:'NVR',n:'NVR Inc.',s:'Consumer Discretionary',w:0.1},{t:'ETR',n:'Entergy Corp.',s:'Utilities',w:0.1},{t:'SYF',n:'Synchrony Financial',s:'Financials',w:0.1},{t:'CMS',n:'CMS Energy Corp.',s:'Utilities',w:0.1},{t:'STE',n:'Steris plc',s:'Health Care',w:0.1},{t:'EIX',n:'Edison International',s:'Utilities',w:0.1},{t:'TPL',n:'Texas Pacific Land Corp.',s:'Energy',w:0.1},{t:'PKG',n:'Packaging Corp. of America',s:'Materials',w:0.1},{t:'MTD',n:'Mettler-Toledo Intl',s:'Health Care',w:0.1},{t:'WY',n:'Weyerhaeuser Co.',s:'Real Estate',w:0.1},{t:'HBAN',n:'Huntington Bancshares',s:'Financials',w:0.1},{t:'NRG',n:'NRG Energy Inc.',s:'Utilities',w:0.1},{t:'WBD',n:'Warner Bros. Discovery',s:'Communication Services',w:0.1},{t:'HAL',n:'Halliburton Co.',s:'Energy',w:0.1},{t:'RF',n:'Regions Financial Corp.',s:'Financials',w:0.1},{t:'LYV',n:'Live Nation Entertainment',s:'Communication Services',w:0.1},{t:'INVH',n:'Invitation Homes Inc.',s:'Real Estate',w:0.1},{t:'DRI',n:'Darden Restaurants Inc.',s:'Consumer Discretionary',w:0.1},{t:'FE',n:'FirstEnergy Corp.',s:'Utilities',w:0.1},{t:'LDOS',n:'Leidos Holdings Inc.',s:'Industrials',w:0.1},{t:'PTC',n:'PTC Inc.',s:'Information Technology',w:0.1},{t:'K',n:'Kellanova',s:'Consumer Staples',w:0.1},{t:'CNP',n:'CenterPoint Energy',s:'Utilities',w:0.1},{t:'IFF',n:'Intl Flavors & Fragrances',s:'Materials',w:0.1},{t:'ES',n:'Eversource Energy',s:'Utilities',w:0.1},{t:'STT',n:'State Street Corp.',s:'Financials',w:0.1},{t:'ATO',n:'Atmos Energy Corp.',s:'Utilities',w:0.1},{t:'PODD',n:'Insulet Corp.',s:'Health Care',w:0.1},{t:'TDY',n:'Teledyne Technologies',s:'Information Technology',w:0.1},{t:'NTAP',n:'NetApp Inc.',s:'Information Technology',w:0.1},{t:'WAT',n:'Waters Corp.',s:'Health Care',w:0.1},{t:'KEY',n:'KeyCorp',s:'Financials',w:0.1},{t:'ULTA',n:'Ulta Beauty Inc.',s:'Consumer Discretionary',w:0.1},{t:'DGX',n:'Quest Diagnostics Inc.',s:'Health Care',w:0.1},{t:'LH',n:'Labcorp Holdings Inc.',s:'Health Care',w:0.1},{t:'GPN',n:'Global Payments Inc.',s:'Financials',w:0.1},{t:'EXPE',n:'Expedia Group Inc.',s:'Consumer Discretionary',w:0.1},{t:'CINF',n:'Cincinnati Financial',s:'Financials',w:0.1},{t:'LUV',n:'Southwest Airlines Co.',s:'Industrials',w:0.1},{t:'ESS',n:'Essex Property Trust',s:'Real Estate',w:0.1},{t:'MKC',n:'McCormick & Co.',s:'Consumer Staples',w:0.1},{t:'COO',n:'Cooper Companies Inc.',s:'Health Care',w:0.1},{t:'CFG',n:'Citizens Financial Group',s:'Financials',w:0.1},{t:'CLX',n:'Clorox Co.',s:'Consumer Staples',w:0.1},{t:'TXT',n:'Textron Inc.',s:'Industrials',w:0.1},{t:'MAA',n:'Mid-America Apartment',s:'Real Estate',w:0.1},{t:'SNA',n:'Snap-on Inc.',s:'Industrials',w:0.1},{t:'DG',n:'Dollar General Corp.',s:'Consumer Staples',w:0.1},{t:'HPE',n:'Hewlett Packard Enterprise',s:'Information Technology',w:0.1},{t:'BALL',n:'Ball Corp.',s:'Materials',w:0.1},{t:'GEN',n:'Gen Digital Inc.',s:'Information Technology',w:0.1},{t:'PFG',n:'Principal Financial Group',s:'Financials',w:0.1},{t:'DOC',n:'Healthpeak Properties',s:'Real Estate',w:0.1},{t:'J',n:'Jacobs Solutions Inc.',s:'Industrials',w:0.1},{t:'ARE',n:'Alexandria Real Estate',s:'Real Estate',w:0.1},{t:'DLTR',n:'Dollar Tree Inc.',s:'Consumer Staples',w:0.1},{t:'NTRS',n:'Northern Trust Corp.',s:'Financials',w:0.1},{t:'IP',n:'International Paper Co.',s:'Materials',w:0.1},{t:'CTRA',n:'Coterra Energy Inc.',s:'Energy',w:0.1},{t:'JBL',n:'Jabil Inc.',s:'Information Technology',w:0.1},{t:'HOLX',n:'Hologic Inc.',s:'Health Care',w:0.1},{t:'FOXA',n:'Fox Corp. Class A',s:'Communication Services',w:0.1},{t:'FOX',n:'Fox Corp. Class B',s:'Communication Services',w:0.1},{t:'MOH',n:'Molina Healthcare Inc.',s:'Health Care',w:0.1},{t:'BAX',n:'Baxter International',s:'Health Care',w:0.1},{t:'EXPD',n:'Expeditors Intl',s:'Industrials',w:0.1},{t:'BBY',n:'Best Buy Co. Inc.',s:'Consumer Discretionary',w:0.1},{t:'TSN',n:'Tyson Foods Inc.',s:'Consumer Staples',w:0.1},{t:'AVY',n:'Avery Dennison Corp.',s:'Materials',w:0.1},{t:'CNC',n:'Centene Corp.',s:'Health Care',w:0.1},{t:'WDC',n:'Western Digital Corp.',s:'Information Technology',w:0.1},{t:'OMC',n:'Omnicom Group Inc.',s:'Communication Services',w:0.1},{t:'DPZ',n:'Domino\'s Pizza Inc.',s:'Consumer Discretionary',w:0.1},{t:'EG',n:'Everest Group Ltd.',s:'Financials',w:0.1},{t:'L',n:'Loews Corp.',s:'Financials',w:0.1},{t:'NWS',n:'News Corp. Class B',s:'Communication Services',w:0.1},{t:'NWSA',n:'News Corp. Class A',s:'Communication Services',w:0.1},{t:'PNR',n:'Pentair plc',s:'Industrials',w:0.1},{t:'MAS',n:'Masco Corp.',s:'Industrials',w:0.1},{t:'DOV',n:'Dover Corp.',s:'Industrials',w:0.1},{t:'APTV',n:'Aptiv plc',s:'Consumer Discretionary',w:0.1},{t:'FDS',n:'FactSet Research Systems',s:'Financials',w:0.1},{t:'TKO',n:'TKO Group Holdings',s:'Communication Services',w:0.1},{t:'LNT',n:'Alliant Energy Corp.',s:'Utilities',w:0.1},{t:'BEN',n:'Franklin Resources Inc.',s:'Financials',w:0.1},{t:'CF',n:'CF Industries Holdings',s:'Materials',w:0.1},{t:'JBHT',n:'J.B. Hunt Transport',s:'Industrials',w:0.1},{t:'JKHY',n:'Jack Henry & Associates',s:'Financials',w:0.1},{t:'ZBRA',n:'Zebra Technologies',s:'Information Technology',w:0.1},{t:'TRMB',n:'Trimble Inc.',s:'Information Technology',w:0.1},{t:'BLDR',n:'Builders FirstSource',s:'Industrials',w:0.1},{t:'SWKS',n:'Skyworks Solutions Inc.',s:'Information Technology',w:0.1},{t:'PNW',n:'Pinnacle West Capital',s:'Utilities',w:0.1},{t:'KIM',n:'Kimco Realty Corp.',s:'Real Estate',w:0.1},{t:'EVRG',n:'Evergy Inc.',s:'Utilities',w:0.1},{t:'SWK',n:'Stanley Black & Decker',s:'Industrials',w:0.1},{t:'STX',n:'Seagate Technology',s:'Information Technology',w:0.1},{t:'UAL',n:'United Airlines Holdings',s:'Industrials',w:0.1},{t:'INCY',n:'Incyte Corp.',s:'Health Care',w:0.1},{t:'NI',n:'NiSource Inc.',s:'Utilities',w:0.1},{t:'AKAM',n:'Akamai Technologies',s:'Information Technology',w:0.1},{t:'CPB',n:'Campbell\'s Co.',s:'Consumer Staples',w:0.1},{t:'POOL',n:'Pool Corp.',s:'Consumer Discretionary',w:0.1},{t:'UDR',n:'UDR Inc.',s:'Real Estate',w:0.1},{t:'REG',n:'Regency Centers Corp.',s:'Real Estate',w:0.1},{t:'TPR',n:'Tapestry Inc.',s:'Consumer Discretionary',w:0.1},{t:'CPT',n:'Camden Property Trust',s:'Real Estate',w:0.1},{t:'ALGN',n:'Align Technology Inc.',s:'Health Care',w:0.1},{t:'DVA',n:'DaVita Inc.',s:'Health Care',w:0.1},{t:'HRL',n:'Hormel Foods Corp.',s:'Consumer Staples',w:0.1},{t:'NDSN',n:'Nordson Corp.',s:'Industrials',w:0.1},{t:'TECH',n:'Bio-Techne Corp.',s:'Health Care',w:0.1},{t:'KMX',n:'CarMax Inc.',s:'Consumer Discretionary',w:0.1},{t:'MRNA',n:'Moderna Inc.',s:'Health Care',w:0.1},{t:'GL',n:'Globe Life Inc.',s:'Financials',w:0.1},{t:'EPAM',n:'EPAM Systems Inc.',s:'Information Technology',w:0.1},{t:'JNPR',n:'Juniper Networks Inc.',s:'Information Technology',w:0.1},{t:'CHRW',n:'C.H. Robinson Worldwide',s:'Industrials',w:0.1},{t:'WBA',n:'Walgreens Boots Alliance',s:'Consumer Staples',w:0.1},{t:'AES',n:'AES Corp.',s:'Utilities',w:0.1},{t:'ENPH',n:'Enphase Energy Inc.',s:'Information Technology',w:0.1},{t:'SOLV',n:'Solventum Corp.',s:'Health Care',w:0.1},{t:'LKQ',n:'LKQ Corp.',s:'Consumer Discretionary',w:0.1},{t:'CAG',n:'Conagra Brands Inc.',s:'Consumer Staples',w:0.1},{t:'SJM',n:'J.M. Smucker Co.',s:'Consumer Staples',w:0.1},{t:'ALLE',n:'Allegion plc',s:'Industrials',w:0.1},{t:'AMCR',n:'Amcor plc',s:'Materials',w:0.1},{t:'HST',n:'Host Hotels & Resorts',s:'Real Estate',w:0.1},{t:'PARA',n:'Paramount Global',s:'Communication Services',w:0.1},{t:'BG',n:'Bunge Global SA',s:'Consumer Staples',w:0.1},{t:'FFIV',n:'F5 Inc.',s:'Information Technology',w:0.1},{t:'CRL',n:'Charles River Laboratories',s:'Health Care',w:0.1},{t:'DAY',n:'Dayforce Inc.',s:'Industrials',w:0.1},{t:'TFX',n:'Teleflex Inc.',s:'Health Care',w:0.1},{t:'ERIE',n:'Erie Indemnity Co.',s:'Financials',w:0.1},{t:'IEX',n:'IDEX Corp.',s:'Industrials',w:0.1},{t:'NCLH',n:'Norwegian Cruise Line',s:'Consumer Discretionary',w:0.1},{t:'PAYC',n:'Paycom Software Inc.',s:'Industrials',w:0.1},{t:'TAP',n:'Molson Coors Beverage',s:'Consumer Staples',w:0.1},{t:'ALB',n:'Albemarle Corp.',s:'Materials',w:0.1},{t:'AOS',n:'A.O. Smith Corp.',s:'Industrials',w:0.1},{t:'EMN',n:'Eastman Chemical Co.',s:'Materials',w:0.1},{t:'MGM',n:'MGM Resorts Intl',s:'Consumer Discretionary',w:0.1},{t:'GNRC',n:'Generac Holdings Inc.',s:'Industrials',w:0.1},{t:'WYNN',n:'Wynn Resorts Ltd.',s:'Consumer Discretionary',w:0.1},{t:'MOS',n:'Mosaic Co.',s:'Materials',w:0.1},{t:'HII',n:'Huntington Ingalls',s:'Industrials',w:0.1},{t:'DECK',n:'Deckers Outdoor Corp.',s:'Consumer Discretionary',w:0.1},{t:'LW',n:'Lamb Weston Holdings',s:'Consumer Staples',w:0.1},{t:'PNC',n:'PNC Financial Services',s:'Financials',w:0.1},{t:'AIZ',n:'Assurant Inc.',s:'Financials',w:0.1},{t:'UHS',n:'Universal Health Services',s:'Health Care',w:0.1},{t:'APA',n:'APA Corp.',s:'Energy',w:0.1},{t:'FRT',n:'Federal Realty Inv Trust',s:'Real Estate',w:0.1},{t:'JBLU',n:'JetBlue Airways Corp.',s:'Industrials',w:0.05},{t:'BXP',n:'BXP Inc.',s:'Real Estate',w:0.05},{t:'MKTX',n:'MarketAxess Holdings',s:'Financials',w:0.05},{t:'HAS',n:'Hasbro Inc.',s:'Consumer Discretionary',w:0.05},{t:'IPG',n:'Interpublic Group',s:'Communication Services',w:0.05},{t:'CZR',n:'Caesars Entertainment',s:'Consumer Discretionary',w:0.05},{t:'MTCH',n:'Match Group Inc.',s:'Communication Services',w:0.05}];
window.SP500=SP500;
</script>
<script type="importmap">
{ "imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.171.0/build/three.webgpu.js",
"three/webgpu": "https://cdn.jsdelivr.net/npm/three@0.171.0/build/three.webgpu.js",
"three/tsl": "https://cdn.jsdelivr.net/npm/three@0.171.0/build/three.tsl.js"
}}
</script>
<script id="appcode" type="module">
// ===================================================================
// MARKET STORM — engine + UI + WebGPU/TSL visuals
// ===================================================================
import * as THREE from 'three';
import {
Fn, vec3, vec4, float, uniform, color, mix, sin, cos, time,
positionLocal, uv, length, smoothstep, attribute, pow, max, min,
oscSine, fract, abs, dot
} from 'three/tsl';
// ---- SECTOR PALETTE -------------------------------------------------
const SECTOR_META = {
'Information Technology': {c:'#3fd0ff', vol:1.35, beta:1.25},
'Communication Services': {c:'#9b7bff', vol:1.20, beta:1.10},
'Consumer Discretionary': {c:'#ff8f3f', vol:1.25, beta:1.15},
'Financials': {c:'#16e0a3', vol:1.05, beta:1.10},
'Health Care': {c:'#ff5fa8', vol:0.85, beta:0.85},
'Industrials': {c:'#ffc857', vol:1.00, beta:1.05},
'Consumer Staples': {c:'#7fe07f', vol:0.55, beta:0.60},
'Energy': {c:'#ff4d6d', vol:1.45, beta:1.20},
'Utilities': {c:'#5b8def', vol:0.50, beta:0.45},
'Real Estate': {c:'#c98bff', vol:0.90, beta:0.90},
'Materials': {c:'#d4a373', vol:1.10, beta:1.05},
};
const fmt$ = n => '$' + n.toLocaleString('en-US',{minimumFractionDigits:2,maximumFractionDigits:2});
const fmtBig = n => '$' + Math.round(n).toLocaleString('en-US');
const fmtPct = n => (n>=0?'+':'') + n.toFixed(2) + '%';
const clamp = (v,a,b)=>Math.max(a,Math.min(b,v));
// =====================================================================
// MARKET ENGINE — geometric brownian motion w/ sector correlation,
// volatility regimes, momentum, mean reversion.
// =====================================================================
class MarketEngine {
constructor(universe){
this.t = 0; // tick counter
this.day = 1;
this.minute = 570; // 9:30 = 570 min
this.regime = 'CALM';
this.regimeTimer = 0;
this.marketDrift = 0.00004; // baseline upward drift / tick
this.marketShock = 0; // index-wide momentum
this.stocks = universe.map(u=>{
const m = SECTOR_META[u.s] || {c:'#888',vol:1,beta:1};
// seed a plausible price from index weight (bigger weight ~ larger cap, varied px)
const base = 18 + Math.pow(u.w,0.42)*120 + this._rand()*180;
return {
...u, color:m.c, sectorVol:m.vol, beta:m.beta,
price: +(base).toFixed(2),
open: 0, prevClose: 0,
dayHigh:0, dayLow:0,
momentum:0,
anchor: base, // mean-reversion anchor
hist: [], // price history
volume: 0,
spark: [],
};
});
this.stocks.forEach(s=>{
s.open=s.price; s.prevClose=s.price; s.dayHigh=s.price; s.dayLow=s.price;
s.anchor=s.price;
for(let i=0;i<60;i++) s.hist.push(s.price);
});
this.idx = 5000;
this.idxHist = new Array(80).fill(5000);
this.byTicker = Object.fromEntries(this.stocks.map(s=>[s.t,s]));
this._recomputeIndex(true);
}
_rand(){ return Math.random(); }
_gauss(){ // Box-Muller
let u=0,v=0; while(u===0)u=Math.random(); while(v===0)v=Math.random();
return Math.sqrt(-2*Math.log(u))*Math.cos(2*Math.PI*v);
}
_recomputeIndex(init){
let totW=0, val=0;
for(const s of this.stocks){ totW+=s.w; val += s.price*s.w; }
const raw = val/totW;
if(init){ this._idxBase = raw; this.idx = 5000; }
else this.idx = 5000 * raw / this._idxBase;
}
_rollRegime(){
this.regimeTimer--;
if(this.regimeTimer>0) return;
const r = Math.random();
if(r<0.50){ this.regime='CALM'; this.regimeVol=0.7; this.marketDrift=0.00006; }
else if(r<0.74){ this.regime='BULL RUN'; this.regimeVol=1.0; this.marketDrift=0.00028; }
else if(r<0.90){ this.regime='CHOPPY'; this.regimeVol=1.6; this.marketDrift=0.00002; }
else if(r<0.98){ this.regime='SELLOFF'; this.regimeVol=2.1; this.marketDrift=-0.00045;}
else { this.regime='BLACK SWAN'; this.regimeVol=3.4; this.marketDrift=-0.0014; }
this.regimeTimer = 140 + Math.floor(Math.random()*260);
}
// advance one tick (~ a few simulated minutes)
step(){
this.t++;
this._rollRegime();
// market-wide shock factor (autocorrelated)
this.marketShock = this.marketShock*0.93 + this._gauss()*0.0016*(this.regimeVol||1);
// per-sector shock
const sectorShock = {};
for(const k in SECTOR_META)
sectorShock[k] = this._gauss()*0.0022*(SECTOR_META[k].vol);
for(const s of this.stocks){
const vol = 0.0042 * s.sectorVol * (this.regimeVol||1);
const idio = this._gauss()*vol;
const sysd = (this.marketDrift + this.marketShock)*s.beta;
const sect = sectorShock[s.s]*0.6;
// mean reversion toward slowly-drifting anchor
const rev = (s.anchor - s.price)/s.price * 0.0035;
s.momentum = s.momentum*0.86 + (idio+sysd)*0.45;
let ret = sysd + idio + sect + rev + s.momentum*0.30;
ret = clamp(ret,-0.14,0.14);
s.price = Math.max(0.5, +(s.price*(1+ret)).toFixed(2));
s.anchor *= (1 + this.marketDrift*0.7);
s.dayHigh = Math.max(s.dayHigh,s.price);
s.dayLow = Math.min(s.dayLow ,s.price);
s.volume += Math.abs(ret)*s.w*1e6 + Math.random()*500;
s.hist.push(s.price); if(s.hist.length>180) s.hist.shift();
}
this._recomputeIndex(false);
this.idxHist.push(this.idx); if(this.idxHist.length>80) this.idxHist.shift();
// clock
this.minute += 3;
if(this.minute>=960){ // 16:00 close → new day
this.minute=570; this.day++;
for(const s of this.stocks){
s.prevClose=s.price; s.open=s.price;
s.dayHigh=s.price; s.dayLow=s.price; s.volume=0;
}
}
}
reseed(map){ // map: {TICKER: price}
let n=0;
for(const tk in map){
const s=this.byTicker[tk.toUpperCase()];
if(s){ const p=+map[tk]; if(p>0){ s.price=p; s.open=p; s.prevClose=p;
s.dayHigh=p; s.dayLow=p; s.anchor=p; s.hist=new Array(60).fill(p); n++; } }
}
this._recomputeIndex(true);
return n;
}
clock(){
const h=Math.floor(this.minute/60), m=this.minute%60;
return `DAY ${this.day} · ${String(h).padStart(2,'0')}:${String(m).padStart(2,'0')}`;
}
dayChange(s){ return (s.price - s.prevClose)/s.prevClose*100; }
}
window.__ENGINE_LIB = { MarketEngine, SECTOR_META, fmt$, fmtBig, fmtPct, clamp,
THREE_NS:THREE, TSL:{Fn,vec3,vec4,float,uniform,color,mix,sin,cos,time,positionLocal,
uv,length,smoothstep,attribute,pow,max,min,oscSine,fract,abs,dot} };
// ===================================================================
// VIZ — WebGPU + TSL "Market Storm" 3D visualization
// 500 instanced shards, one per S&P company, driven by live sim.
// ===================================================================
const VIZ = (()=>{
let renderer, scene, camera, mesh, ready=false, fallback=false;
let count=0, eng=null, theme='storm';
const dummy = new THREE.Object3D();
let cmrAngle=0, focusIdx=0;
let posArr, scaleArr, glowArr, colorArr; // instanced attribute buffers
let glowAttr, scaleAttr;
const pulses=[]; // transient bet pulses {idx,up,life}
const tmpColor=new THREE.Color();
// layout: companies arranged on a spiral disc, radius ~ index weight
function layout(engine){
count=engine.stocks.length;
posArr=new Float32Array(count*3);
const GA=Math.PI*(3-Math.sqrt(5)); // golden angle
engine.stocks.forEach((s,i)=>{
const r = 3 + Math.sqrt(i/count)*26; // spread across disc
const a = i*GA;
posArr[i*3+0]=Math.cos(a)*r;
posArr[i*3+1]=(Math.random()-0.5)*2; // base height jitter
posArr[i*3+2]=Math.sin(a)*r;
s._vx=posArr[i*3+0]; s._vz=posArr[i*3+2];
});
}
function buildScene(engine){
scene=new THREE.Scene();
camera=new THREE.PerspectiveCamera(52, 1, 0.1, 400);
camera.position.set(0,22,40);
camera.lookAt(0,0,0);
// instanced shards — octahedrons = "market crystals"
const geo=new THREE.OctahedronGeometry(0.5,0);
const mat=new THREE.MeshBasicNodeMaterial({transparent:true});
// per-instance attributes
glowArr=new Float32Array(count); // -1..+1 day change driver
scaleArr=new Float32Array(count);
colorArr=new Float32Array(count*3);
engine.stocks.forEach((s,i)=>{
scaleArr[i]=0.5+Math.sqrt(s.w)*1.6;
tmpColor.set(s.color);
colorArr[i*3]=tmpColor.r;colorArr[i*3+1]=tmpColor.g;colorArr[i*3+2]=tmpColor.b;
glowArr[i]=0;
});
mesh=new THREE.InstancedMesh(geo, mat, count);
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
glowAttr=new THREE.InstancedBufferAttribute(glowArr,1);
glowAttr.setUsage(THREE.DynamicDrawUsage);
const colAttr=new THREE.InstancedBufferAttribute(colorArr,3);
mesh.geometry.setAttribute('aGlow',glowAttr);
mesh.geometry.setAttribute('aColor',colAttr);
// ---- TSL shader: color shifts up(green)/down(red), pulse glow ----
const aGlow = attribute('aGlow','float');
const aColor = attribute('aColor','vec3');
const upC = color('#16e0a3');
const dnC = color('#ff4d6d');
// base sector color blended toward up/down by performance
const perf = aGlow; // -1..1
const tint = mix(aColor, mix(dnC, upC, smoothstep(float(-1),float(1),perf)),
float(0.55));
// rim-ish brightness from local normal-ish via uv & a pulse
const pulse = sin(time.mul(3).add(aGlow.mul(6))).mul(0.5).add(0.5);
const bright = float(0.55).add(abs(perf).mul(0.6)).add(pulse.mul(abs(perf)).mul(0.4));
mat.colorNode = tint.mul(bright);
mat.opacityNode = float(0.82).add(abs(perf).mul(0.18));
// subtle vertex breathing on big movers
mat.positionNode = positionLocal.add(
positionLocal.normalize().mul(
sin(time.mul(2).add(aGlow.mul(4))).mul(abs(perf)).mul(0.12)
)
);
scene.add(mesh);
// central index core
const coreGeo=new THREE.IcosahedronGeometry(2.4,2);
const coreMat=new THREE.MeshBasicNodeMaterial({transparent:true});
const cu=uv();
const cpulse=sin(time.mul(1.5)).mul(0.5).add(0.5);
coreMat.colorNode=mix(color('#1c2738'),color('#3fd0ff'),cpulse);
coreMat.opacityNode=float(0.32);
const core=new THREE.Mesh(coreGeo,coreMat);
scene.add(core);
VIZ._core=core;
// ground glow ring (a flat disc with radial TSL gradient)
const ringGeo=new THREE.RingGeometry(2,30,64);
const ringMat=new THREE.MeshBasicNodeMaterial({transparent:true,side:THREE.DoubleSide});
const ru=uv();
const rd=length(ru.sub(0.5));
ringMat.colorNode=color('#0d2535');
ringMat.opacityNode=smoothstep(float(0.5),float(0.1),rd).mul(0.25);
const ring=new THREE.Mesh(ringGeo,ringMat);
ring.rotation.x=-Math.PI/2; ring.position.y=-1.5;
scene.add(ring);
// starfield backdrop
const starN=600;
const starPos=new Float32Array(starN*3);
for(let i=0;i<starN;i++){
const rr=60+Math.random()*120;
const th=Math.random()*Math.PI*2, ph=Math.acos(2*Math.random()-1);
starPos[i*3]=rr*Math.sin(ph)*Math.cos(th);
starPos[i*3+1]=rr*Math.cos(ph);
starPos[i*3+2]=rr*Math.sin(ph)*Math.sin(th);
}
const starGeo=new THREE.BufferGeometry();
starGeo.setAttribute('position',new THREE.BufferAttribute(starPos,3));
const starMat=new THREE.PointsNodeMaterial({transparent:true,size:0.7,sizeAttenuation:true});
starMat.colorNode=color('#2a3a52');
starMat.opacityNode=float(0.5);
const stars=new THREE.Points(starGeo,starMat);
scene.add(stars);
VIZ._stars=stars;
}
// ----- fallback: canvas-2D radial viz if WebGPU unavailable -----
function buildFallback(engine){
fallback=true;
const cv=document.getElementById('gl');
const ctx=cv.getContext('2d');
VIZ._fbCtx=ctx; VIZ._fbCv=cv;
layout(engine);
}
function drawFallback(engine,selected){
const cv=VIZ._fbCv, ctx=VIZ._fbCtx;
const dpr=Math.min(devicePixelRatio||1,2);
const w=cv.clientWidth,h=cv.clientHeight;
if(cv.width!==w*dpr){cv.width=w*dpr;cv.height=h*dpr;}
ctx.setTransform(dpr,0,0,dpr,0,0);
ctx.fillStyle='#05070b';ctx.fillRect(0,0,w,h);
const cxC=w/2,cyC=h/2+20;
cmrAngle+=0.002;
// ring
const gr=ctx.createRadialGradient(cxC,cyC,20,cxC,cyC,Math.min(w,h)*0.5);
gr.addColorStop(0,'rgba(63,208,255,.10)');gr.addColorStop(1,'rgba(0,0,0,0)');
ctx.fillStyle=gr;ctx.fillRect(0,0,w,h);
engine.stocks.forEach((s,i)=>{
const ch=engine.dayChange(s);
const ang=Math.atan2(s._vz,s._vx)+cmrAngle;
const rad=Math.hypot(s._vx,s._vz)*(Math.min(w,h)/72);
const x=cxC+Math.cos(ang)*rad, y=cyC+Math.sin(ang)*rad*0.55;
const sz=(0.5+Math.sqrt(s.w)*1.6)*2.2*(1+clamp(Math.abs(ch)/8,0,1.4));
const col=ch>=0?'22,224,163':'255,77,109';
ctx.beginPath();ctx.arc(x,y,sz,0,7);
ctx.fillStyle=`rgba(${col},${0.4+clamp(Math.abs(ch)/10,0,0.55)})`;
ctx.shadowColor=`rgba(${col},.8)`;
ctx.shadowBlur=s.t===selected?20:clamp(Math.abs(ch)*2,0,14);
ctx.fill();
if(s.t===selected){
ctx.shadowBlur=0;ctx.strokeStyle='#fff';ctx.lineWidth=2;
ctx.beginPath();ctx.arc(x,y,sz+5,0,7);ctx.stroke();
ctx.fillStyle='#fff';ctx.font='bold 11px JetBrains Mono';
ctx.fillText(s.t,x+sz+8,y+3);
}
});
ctx.shadowBlur=0;
// core
ctx.beginPath();ctx.arc(cxC,cyC,16,0,7);
ctx.fillStyle='rgba(63,208,255,.5)';ctx.fill();
}
function clamp(v,a,b){return Math.max(a,Math.min(b,v));}
return {
_core:null,_stars:null,
async init(engine,selected){
eng=engine;
const cv=document.getElementById('gl');
if(!navigator.gpu){
buildFallback(engine); ready=true;
showBadge('WebGPU unavailable — 2D fallback active','#ffc857');
return;
}
try{
renderer=new THREE.WebGPURenderer({canvas:cv,antialias:true,alpha:true});
renderer.setPixelRatio(Math.min(devicePixelRatio||1,2));
renderer.setSize(cv.clientWidth,cv.clientHeight,false);
await renderer.init();
layout(engine);
buildScene(engine);
ready=true;
showBadge('WebGPU // TSL renderer online','#3fd0ff');
}catch(err){
console.warn('WebGPU init failed, fallback:',err);
buildFallback(engine); ready=true;
showBadge('WebGPU init failed — 2D fallback','#ffc857');
}
},
setTheme(t){
theme=t;
if(fallback||!scene) return;
const bg={floor:'#0a0c0f',storm:'#05070b',neon:'#0a0514'}[t];
// (background handled by canvas alpha; tweak core color)
if(VIZ._core){
const c={floor:'#4ea8ff',storm:'#3fd0ff',neon:'#ff3fd0'}[t];
}
},
focusStock(t){
if(!eng) return;
focusIdx=eng.stocks.findIndex(s=>s.t===t);
},
spawnBetPulse(t,up){
if(!eng)return;
const i=eng.stocks.findIndex(s=>s.t===t);
if(i>=0) pulses.push({idx:i,up,life:1.0,kind:'bet'});
},
spawnOutcomeBurst(t,won){
if(!eng)return;
const i=eng.stocks.findIndex(s=>s.t===t);
if(i>=0) pulses.push({idx:i,up:won,life:1.0,kind:'burst'});
},
update(engine,selected){
if(!ready) return;
eng=engine;
if(fallback){ drawFallback(engine,selected); return; }
if(!renderer||!scene) return;
const cv=document.getElementById('gl');
if(cv.width!==cv.clientWidth*renderer.getPixelRatio()){
renderer.setSize(cv.clientWidth,cv.clientHeight,false);
camera.aspect=cv.clientWidth/cv.clientHeight;
camera.updateProjectionMatrix();
}
// slow orbit camera
cmrAngle+=0.0016;
const camR=42;
camera.position.x=Math.cos(cmrAngle)*camR;
camera.position.z=Math.sin(cmrAngle)*camR;
camera.position.y=20+Math.sin(cmrAngle*0.6)*6;
camera.lookAt(0,0,0);
const tnow=performance.now()*0.001;
// update instances
engine.stocks.forEach((s,i)=>{
const ch=clamp(engine.dayChange(s)/8,-1,1);
// smooth glow toward day change
glowArr[i]+=(ch-glowArr[i])*0.12;
// float height by performance + bob
const targetY = ch*4 + Math.sin(tnow*1.3+i)*0.4;
dummy.position.set(
posArr[i*3], posArr[i*3+1]+targetY, posArr[i*3+2]);
// spin faster when volatile
const spin=tnow*(0.3+Math.abs(ch)*1.6)+i;
dummy.rotation.set(spin*0.7,spin,spin*0.4);
let sc=scaleArr[i]*(1+Math.abs(ch)*0.5);
if(i===focusIdx) sc*=1.7;
dummy.scale.setScalar(sc);
dummy.updateMatrix();
mesh.setMatrixAt(i,dummy.matrix);
});
// pulses
for(let k=pulses.length-1;k>=0;k--){
const p=pulses[k];
p.life-=0.02;
const i=p.idx;
if(p.life<=0){ pulses.splice(k,1); continue; }
// override glow with bet flash
glowArr[i]=p.up? Math.max(glowArr[i],p.life) : Math.min(glowArr[i],-p.life);
}
glowAttr.needsUpdate=true;
mesh.instanceMatrix.needsUpdate=true;
if(VIZ._core) VIZ._core.rotation.y+=0.004;
if(VIZ._stars) VIZ._stars.rotation.y+=0.0003;
renderer.render(scene,camera);
}
};
})();
function showBadge(msg,col){
const b=document.createElement('div');
b.textContent=msg;
b.style.cssText=`position:absolute;bottom:198px;left:14px;z-index:11;
font-family:'JetBrains Mono',monospace;font-size:9px;letter-spacing:1px;
color:${col};border:1px solid ${col}55;padding:4px 9px;border-radius:4px;
background:rgba(8,11,17,.8)`;
document.querySelector('.col.center').appendChild(b);
setTimeout(()=>{b.style.transition='opacity .6s';b.style.opacity='0';
setTimeout(()=>b.remove(),700);},3600);
}
window.VIZ = VIZ;
// ===================================================================
// CONTROLLER — wires engine to UI, runs betting game + 3D viz
// ===================================================================
// ---------- STATE ----------
const ENG = new MarketEngine(window.SP500);
const ST = {
cash: 10000,
startCash: 10000,
watch: new Set(['AAPL','NVDA','TSLA','JPM','XOM']),
selected: 'NVDA',
positions: [], // active bets
history: [], // resolved bets + events
tab: 'watch',
sectorFilter: null,
sort: 'weight',
query: '',
speed: 1,
theme: 'storm',
betMode: 'direction', // direction | target | leverage
betDir: 'up',
betStake: 250,
betHorizon: 20, // ticks
betStrikePct: 3, // % move for target
betLeverage: 5,
betId: 0,
};
// ---------- DOM ----------
const $ = id => document.getElementById(id);
const stockList=$('stockList'), sectorChips=$('sectorChips'), tabWrap=$('tabWrap');
const selCard=$('selCard'), toasts=$('toasts');
// ============================================================
// LEFT PANEL — universe
// ============================================================
function buildSectorChips(){
const secs = Object.keys(SECTOR_META);
sectorChips.innerHTML='';
const all=document.createElement('span');
all.className='chip on'; all.textContent='ALL'; all.dataset.s='';
sectorChips.appendChild(all);
secs.forEach(s=>{
const c=document.createElement('span');
c.className='chip'; c.dataset.s=s;
c.textContent=s.replace('Information Technology','Info Tech')
.replace('Communication Services','Comm Svc')
.replace('Consumer Discretionary','Cons Disc')
.replace('Consumer Staples','Cons Stpl')
.replace('Health Care','Health').replace('Real Estate','REIT');
c.style.borderColor=SECTOR_META[s].c+'66';
sectorChips.appendChild(c);
});
sectorChips.onclick=e=>{
const chip=e.target.closest('.chip'); if(!chip) return;
[...sectorChips.children].forEach(x=>x.classList.remove('on'));
chip.classList.add('on');
ST.sectorFilter = chip.dataset.s || null;
renderList();
};
}
function filteredStocks(){
let arr = ENG.stocks;
if(ST.sectorFilter) arr=arr.filter(s=>s.s===ST.sectorFilter);
if(ST.query){
const q=ST.query.toUpperCase();
arr=arr.filter(s=>s.t.includes(q)||s.n.toUpperCase().includes(q));
}
arr=[...arr];
if(ST.sort==='weight') arr.sort((a,b)=>b.w-a.w);
else if(ST.sort==='change') arr.sort((a,b)=>ENG.dayChange(b)-ENG.dayChange(a));
else arr.sort((a,b)=>a.t<b.t?-1:1);
return arr;
}
function renderList(){
const arr=filteredStocks();
$('uniCount').textContent=arr.length;
const frag=document.createDocumentFragment();
arr.slice(0,140).forEach(s=>{
const ch=ENG.dayChange(s);
const row=document.createElement('div');
row.className='row'+(s.t===ST.selected?' sel':'');
row.dataset.t=s.t;
row.innerHTML=`
<span class="tk" style="color:${s.color}">${s.t}</span>
<span class="nm">${s.n}</span>
<span class="px">${fmt$(s.price)}</span>
<span class="pc ${ch>=0?'up':'down'}">${fmtPct(ch)}</span>`;
const star=document.createElement('span');
star.className='star'+(ST.watch.has(s.t)?' on':'');
star.textContent=ST.watch.has(s.t)?'★':'☆';
star.onclick=e=>{e.stopPropagation();toggleWatch(s.t);};
row.appendChild(star);
row.onclick=()=>selectStock(s.t);
frag.appendChild(row);
});
stockList.innerHTML='';
stockList.appendChild(frag);
}
// light refresh of just prices for visible rows
function refreshListPrices(){
for(const row of stockList.children){
const s=ENG.byTicker[row.dataset.t]; if(!s) continue;
const ch=ENG.dayChange(s);
row.children[2].textContent=fmt$(s.price);
const pc=row.children[3];
pc.textContent=fmtPct(ch);
pc.className='pc '+(ch>=0?'up':'down');
}
}
function toggleWatch(t){
if(ST.watch.has(t)) ST.watch.delete(t);
else { ST.watch.add(t); toast(`★ ${t} added to watchlist`, 'var(--gold)'); }
renderList(); if(ST.tab==='watch') renderTab();
}
function selectStock(t){
ST.selected=t;
renderList();