Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
2469 lines (2403 loc) · 169 KB
/
Copy pathindex.html
File metadata and controls
2469 lines (2403 loc) · 169 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, viewport-fit=cover">
<meta name="description" content="TheTerminal: a live 3D container terminal operations game for the fictional Port Mumbai.">
<style>
:root{color-scheme:light;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}
body{margin:0;font:14px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif}
img{max-width:100%}
[hidden]{display:none!important}
</style>
<title>TheTerminal</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap">
<style>
/* Layout: full-bleed isometric terminal; top app bar, KPI cards top-left, terminal card right, vessel tracking bottom-left, berths/anchorage card bottom-right. Light = daylight ops board, dark = night shift. */
:root{
--bg:#EDF1F7; --surface:#FFFFFF; --surface-2:#F3F6FB; --glass:rgba(255,255,255,.95);
--line:#E3E8F0; --line-strong:#CDD6E3;
--text:#0F172A; --muted:#5B6B82; --dim:#94A3B8;
--primary:#2F5BEA; --primary-strong:#2449C7; --primary-soft:#E9EEFD; --on-primary:#FFFFFF;
--success:#15803D; --success-soft:#DCFCE7;
--warn:#B45309; --warn-soft:#FEF3C7;
--danger:#DC2626; --danger-soft:#FEE2E2;
--shadow:0 10px 30px rgba(15,23,42,.08),0 1px 3px rgba(15,23,42,.06);
--shadow-sm:0 1px 2px rgba(15,23,42,.08);
--f:'Inter',system-ui,-apple-system,'Segoe UI',Roboto,sans-serif;
--r:14px;
}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){
--bg:#09111E; --surface:#0F1A2C; --surface-2:#16233A; --glass:rgba(13,23,40,.93);
--line:#1F2E47; --line-strong:#2D4062;
--text:#E8EEF6; --muted:#97A7BF; --dim:#61738F;
--primary:#5B82FF; --primary-strong:#86A3FF; --primary-soft:rgba(91,130,255,.16); --on-primary:#FFFFFF;
--success:#4ADE80; --success-soft:rgba(74,222,128,.13);
--warn:#FBBF24; --warn-soft:rgba(251,191,36,.14);
--danger:#F87171; --danger-soft:rgba(248,113,113,.15);
--shadow:0 12px 34px rgba(0,0,0,.45),0 1px 2px rgba(0,0,0,.3);
--shadow-sm:0 1px 2px rgba(0,0,0,.4);
color-scheme:dark;
}}
:root[data-theme="dark"]{
--bg:#09111E; --surface:#0F1A2C; --surface-2:#16233A; --glass:rgba(13,23,40,.93);
--line:#1F2E47; --line-strong:#2D4062;
--text:#E8EEF6; --muted:#97A7BF; --dim:#61738F;
--primary:#5B82FF; --primary-strong:#86A3FF; --primary-soft:rgba(91,130,255,.16); --on-primary:#FFFFFF;
--success:#4ADE80; --success-soft:rgba(74,222,128,.13);
--warn:#FBBF24; --warn-soft:rgba(251,191,36,.14);
--danger:#F87171; --danger-soft:rgba(248,113,113,.15);
--shadow:0 12px 34px rgba(0,0,0,.45),0 1px 2px rgba(0,0,0,.3);
--shadow-sm:0 1px 2px rgba(0,0,0,.4);
color-scheme:dark;
}
html,body{height:100%}
body{background:var(--bg);color:var(--text);font-family:var(--f);font-size:14px;overflow:hidden;-webkit-font-smoothing:antialiased;font-feature-settings:"cv11","ss01"}
[hidden]{display:none!important}
.num{font-variant-numeric:tabular-nums}
button{font:inherit;color:inherit}
:focus-visible{outline:2px solid var(--primary);outline-offset:2px}
.ic{width:18px;height:18px;flex:none;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
.muted{color:var(--muted)}
#scene{position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none;cursor:grab;outline:none}
#scene.dragging{cursor:grabbing}
#scene.hovering{cursor:pointer}
#boot{position:fixed;inset:0;display:grid;place-items:center;font-weight:600;color:var(--muted);background:var(--bg);z-index:50;transition:opacity .5s}
#boot.gone{opacity:0;pointer-events:none}
/* ---------- shared pieces ---------- */
.card{pointer-events:auto;background:var(--glass);border:1px solid var(--line);border-radius:var(--r);box-shadow:var(--shadow)}
.tile{width:36px;height:36px;border-radius:10px;background:var(--primary);color:var(--on-primary);display:grid;place-items:center;flex:none}
.tile .ic{width:19px;height:19px}
.tile.sm{width:30px;height:30px;border-radius:8px}
.tile.sm .ic{width:16px;height:16px}
.tile.soft{background:var(--primary-soft);color:var(--primary)}
.tile.ok{background:var(--success-soft);color:var(--success)}
.tile.warn{background:var(--warn-soft);color:var(--warn)}
.tile.crit{background:var(--danger-soft);color:var(--danger)}
h3{margin:0;font-size:13px;font-weight:700;letter-spacing:-.005em;display:flex;align-items:center;gap:8px}
h3 .ic{color:var(--primary)}
.pill{display:inline-flex;align-items:center;gap:5px;font-size:11.5px;font-weight:600;line-height:1;padding:5px 9px;border-radius:999px;background:var(--surface-2);color:var(--muted);white-space:nowrap}
.pill.ok{background:var(--success-soft);color:var(--success)}
.pill.warn{background:var(--warn-soft);color:var(--warn)}
.pill.crit{background:var(--danger-soft);color:var(--danger)}
.pill.info{background:var(--primary-soft);color:var(--primary)}
.delta{font-size:11.5px;font-weight:600;padding:3px 7px;border-radius:7px;white-space:nowrap;font-variant-numeric:tabular-nums}
.delta.up{background:var(--success-soft);color:var(--success)}
.delta.down{background:var(--danger-soft);color:var(--danger)}
.delta.flat{background:var(--surface-2);color:var(--muted)}
.btn{display:inline-flex;align-items:center;gap:6px;background:var(--surface);border:1px solid var(--line-strong);border-radius:9px;padding:7px 12px;cursor:pointer;font-size:12.5px;font-weight:600;color:var(--text);white-space:nowrap}
.btn:hover:not(:disabled){border-color:var(--primary);color:var(--primary)}
.btn.primary{background:var(--primary);border-color:var(--primary);color:var(--on-primary)}
.btn.primary:hover:not(:disabled){background:var(--primary-strong);border-color:var(--primary-strong);color:var(--on-primary)}
.btn.soft{background:var(--primary-soft);border-color:transparent;color:var(--primary)}
.btn.sm{padding:5px 9px;font-size:11.5px;border-radius:8px}
.btn:disabled{opacity:.45;cursor:not-allowed}
.iconbtn{width:36px;height:36px;display:grid;place-items:center;border-radius:10px;border:1px solid var(--line);background:var(--surface);cursor:pointer;color:var(--muted);flex:none}
.iconbtn:hover{color:var(--primary);border-color:var(--line-strong)}
.iconbtn.sm{width:28px;height:28px;border-radius:8px}
.iconbtn.sm .ic{width:15px;height:15px}
.tabs{display:flex;gap:3px;background:var(--surface-2);padding:3px;border-radius:10px;border:1px solid var(--line)}
.tabs button{flex:1;display:inline-flex;align-items:center;justify-content:center;gap:6px;background:transparent;border:0;border-radius:8px;padding:7px 10px;cursor:pointer;font-size:12.5px;font-weight:600;color:var(--muted);white-space:nowrap}
.tabs button b{font-weight:600;color:var(--dim);font-variant-numeric:tabular-nums}
.tabs button.on{background:var(--surface);color:var(--text);box-shadow:var(--shadow-sm)}
.tabs button.on b{color:var(--primary)}
.bar{height:6px;border-radius:4px;background:var(--surface-2);overflow:hidden;box-shadow:inset 0 0 0 1px var(--line)}
.bar i{display:block;height:100%;width:0;background:var(--primary);border-radius:4px;transition:width .5s,background .3s}
.bar i.warn{background:var(--warn)}
.bar i.crit{background:var(--danger)}
.empty{font-size:12.5px;color:var(--muted);padding:10px 2px;line-height:1.45}
.ldot{display:inline-block;width:9px;height:9px;border-radius:50%;box-shadow:inset 0 0 0 1px rgba(15,23,42,.25);flex:none}
/* ---------- top app bar ---------- */
.topbar{position:fixed;top:0;left:0;right:0;z-index:15;display:flex;align-items:center;gap:14px;
padding-block:calc(env(safe-area-inset-top,0px) + 10px) 10px;
padding-left:max(16px,env(safe-area-inset-left,0px));padding-right:max(16px,env(safe-area-inset-right,0px));
background:var(--glass);border-bottom:1px solid var(--line);box-shadow:var(--shadow-sm);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px)}
.brand{display:flex;align-items:center;gap:10px;flex:none}
.brand .tile{width:34px;height:34px}
.wordmark{font-size:19px;font-weight:800;letter-spacing:-.02em}
.search{position:relative;flex:1;max-width:440px;min-width:0}
.search .ic{position:absolute;left:11px;top:50%;transform:translateY(-50%);color:var(--dim);pointer-events:none}
.search input{width:100%;height:40px;border-radius:11px;border:1px solid var(--line);background:var(--surface-2);padding:0 40px 0 36px;font:inherit;font-size:13.5px;color:var(--text);outline:none}
.search input::placeholder{color:var(--dim)}
.search input:focus{border-color:var(--primary);background:var(--surface);box-shadow:0 0 0 3px var(--primary-soft)}
.search kbd{position:absolute;right:10px;top:50%;transform:translateY(-50%);font:600 11px var(--f);color:var(--dim);border:1px solid var(--line-strong);border-radius:6px;padding:2px 6px}
.qres{position:absolute;top:46px;left:0;right:0;padding:6px;display:flex;flex-direction:column;gap:2px;z-index:30}
.qres button{display:grid;grid-template-columns:30px minmax(0,1fr) auto;gap:10px;align-items:center;text-align:left;background:transparent;border:0;border-radius:9px;padding:6px 8px;cursor:pointer}
.qres button:hover,.qres button.on{background:var(--surface-2)}
.qres .t{font-weight:600;font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.qres .s{font-size:11.5px;color:var(--muted)}
.site{display:flex;align-items:center;gap:10px;padding:5px 12px 5px 5px;border:1px solid var(--line);border-radius:12px;background:var(--surface);cursor:pointer;text-align:left;min-width:0}
.site:hover{border-color:var(--line-strong)}
.site .t{font-weight:700;font-size:13px;white-space:nowrap}
.site .s{font-size:11.5px;color:var(--muted);white-space:nowrap}
.site .chev{color:var(--dim)}
.tb-right{display:flex;align-items:center;gap:10px;margin-left:auto}
.livechip{display:flex;align-items:center;gap:8px;padding:8px 12px;border-radius:999px;background:var(--success-soft);color:var(--success);font-weight:600;font-size:12.5px;white-space:nowrap;font-variant-numeric:tabular-nums}
.livechip i{width:7px;height:7px;border-radius:50%;background:currentColor;animation:ping 1.8s infinite}
@keyframes ping{0%{box-shadow:0 0 0 0 color-mix(in srgb,currentColor 55%,transparent)}70%{box-shadow:0 0 0 7px transparent}100%{box-shadow:0 0 0 0 transparent}}
.speed{display:flex;border:1px solid var(--line);border-radius:10px;overflow:hidden;background:var(--surface)}
.speed button{background:transparent;border:0;padding:0 10px;height:34px;font-size:12.5px;font-weight:600;cursor:pointer;color:var(--muted);min-width:36px;font-variant-numeric:tabular-nums}
.speed button+button{border-left:1px solid var(--line)}
.speed button:hover{color:var(--primary)}
.speed button.on{background:var(--primary);color:var(--on-primary)}
.who{display:flex;align-items:center;gap:10px;padding-left:12px;border-left:1px solid var(--line)}
.avatar{width:34px;height:34px;border-radius:50%;background:var(--primary-soft);color:var(--primary);display:grid;place-items:center;font-weight:700;font-size:12.5px}
.who .t{font-weight:700;font-size:13px;white-space:nowrap}
.who .s{font-size:11.5px;color:var(--muted);white-space:nowrap}
/* ---------- HUD grid ---------- */
#hud{position:fixed;left:0;right:0;bottom:0;top:var(--hh,64px);pointer-events:none;display:grid;
grid-template-columns:minmax(0,1fr) 372px;grid-template-rows:auto minmax(0,1fr) auto;gap:14px;
padding-block:14px calc(env(safe-area-inset-bottom,0px) + 14px);
padding-left:max(16px,env(safe-area-inset-left,0px));padding-right:max(16px,env(safe-area-inset-right,0px))}
.kpis{grid-column:1;grid-row:1;display:flex;gap:12px;flex-wrap:wrap;align-items:stretch;justify-self:start;min-width:0}
.kpi{pointer-events:auto;width:212px;padding:12px 14px;display:grid;grid-template-columns:auto minmax(0,1fr);gap:6px 10px;align-items:center}
.kpi .lb{grid-column:1/-1;font-size:12px;font-weight:600;color:var(--muted)}
.kpi .vv{display:flex;align-items:baseline;gap:7px;flex-wrap:wrap;min-width:0}
.kpi .v{font-size:23px;font-weight:800;letter-spacing:-.02em;line-height:1.05;font-variant-numeric:tabular-nums;white-space:nowrap}
.kpi .v small{font-size:13px;font-weight:600;color:var(--muted);letter-spacing:0}
.kpi .v.crit{color:var(--danger)}
.kpi .sb{grid-column:1/-1;font-size:11.5px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.kpi .sb.warn{color:var(--warn)}
.kpi .sb.crit{color:var(--danger)}
.stage{grid-column:1;grid-row:2;display:flex;justify-content:space-between;align-items:flex-start;gap:12px;min-height:0}
.float{display:flex;flex-direction:column;gap:10px;width:min(380px,100%);min-width:0}
.mapctl{pointer-events:auto;display:flex;flex-direction:column;padding:4px;gap:2px;margin-left:auto}
.mapctl button{width:36px;height:36px;display:grid;place-items:center;border:0;background:transparent;border-radius:9px;cursor:pointer;color:var(--muted)}
.mapctl button:hover{background:var(--surface-2);color:var(--primary)}
.mapctl hr{border:0;border-top:1px solid var(--line);margin:2px 4px}
.bottom{grid-column:1/-1;grid-row:3;display:flex;gap:14px;align-items:flex-end;justify-content:space-between;min-width:0}
/* ---------- terminal panel ---------- */
#panel{grid-column:2;grid-row:1/3;display:flex;flex-direction:column;min-height:0;overflow:hidden}
.ph{padding:14px 14px 12px;display:flex;flex-direction:column;gap:12px;border-bottom:1px solid var(--line)}
.phead{display:flex;gap:12px;align-items:center}
.eyebrow{font-size:11px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:var(--primary)}
.ptitle{font-size:17px;font-weight:800;letter-spacing:-.015em;line-height:1.2}
.psub{font-size:12px;color:var(--muted)}
.pstat{display:flex;align-items:center;gap:10px;flex-wrap:wrap;font-size:12px}
.scroll{overflow-y:auto;min-height:0;padding:14px;display:flex;flex-direction:column;gap:16px;scrollbar-width:thin;scrollbar-color:var(--line-strong) transparent}
.mgrid{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.metric{border:1px solid var(--line);background:var(--surface);border-radius:11px;padding:10px 11px;display:flex;flex-direction:column;gap:5px;min-width:0}
.metric .k{font-size:11.5px;color:var(--muted);font-weight:500}
.metric .v{font-size:18px;font-weight:700;font-variant-numeric:tabular-nums;letter-spacing:-.01em}
.metric .s{font-size:11px;color:var(--dim)}
.sect{display:flex;flex-direction:column;gap:9px}
.sh{display:flex;justify-content:space-between;align-items:center;gap:8px;font-size:11.5px}
.rows{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}
.row{display:grid;grid-template-columns:30px minmax(0,1fr) auto;gap:10px;align-items:center;padding:7px 8px;border-radius:10px;border:1px solid var(--line);background:var(--surface);font-size:12.5px;line-height:1.35}
.row.click{cursor:pointer}
.row.click:hover{border-color:var(--line-strong)}
.row .t{font-weight:600}
.row .n{font-weight:700;font-variant-numeric:tabular-nums;text-align:right;display:flex;gap:10px;align-items:center}
#spark{width:100%;height:58px;display:block}
.sparkax{display:flex;justify-content:space-between;font-size:11px;color:var(--dim);font-variant-numeric:tabular-nums}
.item{border:1px solid var(--line);background:var(--surface);border-radius:12px;padding:12px;display:grid;grid-template-columns:36px minmax(0,1fr);gap:4px 12px}
.item .top{display:flex;justify-content:space-between;align-items:baseline;gap:8px}
.item .t{font-weight:700;font-size:13.5px}
.item .own{font-size:11.5px;color:var(--muted);white-space:nowrap}
.item p{grid-column:2;margin:0;font-size:12.5px;color:var(--muted);line-height:1.45}
.item .act{grid-column:2;display:flex;justify-content:space-between;align-items:center;margin-top:6px}
.item .price{font-weight:700;font-variant-numeric:tabular-nums}
/* ---------- bottom cards ---------- */
.card-h{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:12px 14px 0}
.tnav{display:flex;align-items:center;gap:6px;font-size:12px}
#track{flex:1 1 auto;max-width:680px;min-width:0;display:flex;flex-direction:column}
.trk{display:grid;grid-template-columns:minmax(0,1fr) 260px;gap:14px;padding:12px 14px 14px;align-items:center}
.steps{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:repeat(6,minmax(0,1fr))}
.steps li{position:relative;display:flex;flex-direction:column;align-items:center;gap:5px;text-align:center;min-width:0}
.steps li:not(:first-child)::before{content:"";position:absolute;top:15px;right:50%;width:100%;height:2px;background:var(--line-strong)}
.steps li.done::before,.steps li.cur::before{background:var(--primary)}
.steps .dot{position:relative;z-index:1;width:32px;height:32px;border-radius:50%;display:grid;place-items:center;background:var(--surface);border:2px solid var(--line-strong);color:var(--dim)}
.steps .dot .ic{width:15px;height:15px}
.steps li.done .dot{background:var(--primary);border-color:var(--primary);color:var(--on-primary)}
.steps li.cur .dot{border-color:var(--primary);color:var(--primary);box-shadow:0 0 0 4px var(--primary-soft)}
.steps .lb{font-size:12px;font-weight:600;white-space:nowrap}
.steps li.todo .lb{color:var(--muted)}
.steps .tm{font-size:11px;color:var(--muted);font-variant-numeric:tabular-nums;white-space:nowrap}
.steps li.cur .tm{color:var(--primary);font-weight:600}
.vcard{border:1px solid var(--line);background:var(--surface);border-radius:12px;padding:11px;display:grid;grid-template-columns:auto minmax(0,1fr);gap:11px;cursor:pointer}
.vcard:hover{border-color:var(--line-strong)}
.vinfo{display:flex;flex-direction:column;gap:4px;min-width:0}
.vid{font-size:11.5px;font-weight:700;color:var(--primary);display:flex;gap:6px;align-items:center}
.vname{font-weight:700;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.vsub{display:flex;align-items:center;gap:6px;font-size:11.5px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.vrow{display:flex;align-items:center;gap:8px;font-size:11.5px;flex-wrap:wrap}
.acts{display:flex;gap:6px;flex-wrap:wrap;margin-top:4px}
.insp{padding:12px 14px 14px;display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:8px}
.insp .metric .v{font-size:14px}
.insp-acts{padding:0 14px 14px;display:flex;gap:8px;flex-wrap:wrap;align-items:center;font-size:12.5px;color:var(--muted)}
#docks{flex:none;width:440px;max-height:300px;display:flex;flex-direction:column;overflow:hidden}
.dh{display:flex;align-items:center;gap:10px;padding:12px 14px 10px}
.dh .tabs{flex:1}
.dbody{overflow-y:auto;min-height:0;padding:0 14px 14px;display:flex;flex-direction:column;gap:6px;scrollbar-width:thin;scrollbar-color:var(--line-strong) transparent}
.drow{display:grid;grid-template-columns:58px minmax(0,1fr) auto 70px auto;gap:10px;align-items:center;padding:8px 9px;border-radius:10px;border:1px solid var(--line);background:var(--surface);cursor:pointer;font-size:12.5px}
.drow:hover{border-color:var(--line-strong)}
.drow.locked{border-style:dashed;cursor:default}
.drow .dl{display:flex;flex-direction:column;line-height:1.25}
.drow .dl b{font-weight:700;font-variant-numeric:tabular-nums;white-space:nowrap}
.drow .dl span,.drow .msub{font-size:11px;color:var(--muted)}
.drow .dm{display:flex;flex-direction:column;gap:2px;min-width:0}
.vchip{display:flex;align-items:center;gap:6px;font-weight:600;min-width:0}
.vchip span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.vchip .ic{width:15px;height:15px;color:var(--primary)}
.drow .dp{display:flex;flex-direction:column;gap:4px;font-size:11px;color:var(--muted);font-variant-numeric:tabular-nums;text-align:right}
.chev{color:var(--dim);display:grid;place-items:center}
.switch{display:flex;align-items:center;gap:8px;cursor:pointer;font-size:12px;font-weight:600;color:var(--muted);justify-content:space-between;padding:2px 2px 4px}
.switch input{position:absolute;opacity:0;width:1px;height:1px}
.switch .sw{position:relative;width:32px;height:18px;border-radius:10px;background:var(--line-strong);transition:background .2s;flex:none}
.switch .sw::after{content:"";position:absolute;left:2px;top:2px;width:14px;height:14px;border-radius:50%;background:#fff;box-shadow:var(--shadow-sm);transition:transform .2s}
.switch input:checked+.sw{background:var(--primary)}
.switch input:checked+.sw::after{transform:translateX(14px)}
.switch input:focus-visible+.sw{outline:2px solid var(--primary);outline-offset:2px}
.log{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:2px}
.log li{display:grid;grid-template-columns:42px minmax(0,1fr);gap:10px;font-size:12.5px;line-height:1.4;padding:5px 2px;border-bottom:1px solid var(--line)}
.log li .t{color:var(--dim);font-variant-numeric:tabular-nums;font-size:11.5px;padding-top:1px}
.log li.good span{color:var(--success)}
.log li.warn span{color:var(--warn)}
.log li.crit span{color:var(--danger)}
/* ---------- floating cards & toasts ---------- */
.fcard{padding:13px 14px;display:flex;flex-direction:column;gap:9px;animation:rise .35s ease-out}
@keyframes rise{from{transform:translateY(8px);opacity:.3}to{transform:none;opacity:1}}
.fcard .hd{display:flex;justify-content:space-between;gap:10px;align-items:flex-start}
.fcard .hl{display:flex;gap:11px;align-items:center}
.fcard .ttl{font-weight:700;font-size:14.5px;line-height:1.25}
.fcard .st{font-size:12px;color:var(--muted)}
.fcard p{margin:0;font-size:12.5px;line-height:1.5;color:var(--muted)}
.fcard kbd{font:600 11px var(--f);border:1px solid var(--line-strong);border-radius:5px;padding:1px 5px;color:var(--text);background:var(--surface-2)}
.fcard.contract{border-color:color-mix(in srgb,var(--warn) 45%,var(--line))}
.x{background:transparent;border:0;color:var(--dim);cursor:pointer;padding:2px;border-radius:6px;display:grid;place-items:center}
.x:hover{color:var(--text);background:var(--surface-2)}
#toasts{position:fixed;left:50%;top:calc(var(--hh,64px) + 12px);transform:translateX(-50%);display:flex;flex-direction:column;gap:6px;align-items:center;pointer-events:none;z-index:20;width:min(460px,calc(100% - 32px))}
.toast{display:flex;align-items:center;gap:10px;background:var(--surface);border:1px solid var(--line);border-radius:12px;padding:9px 12px;font-size:12.5px;animation:rise .3s ease-out;box-shadow:var(--shadow)}
.toast .ic{color:var(--primary)}
.toast.good .ic{color:var(--success)}
.toast.warn .ic{color:var(--warn)}
.toast b{color:var(--success);font-variant-numeric:tabular-nums}
.tabbar{display:none}
.dock{display:none}
.seg button{font-size:12px;padding:6px 6px}
.tabs.mini{padding:2px;flex:none}
.tabs.mini button{padding:4px 9px;font-size:11.5px}
.note{margin:0;font-size:12px;line-height:1.5;color:var(--muted)}
.brow{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:12px;align-items:center;padding:9px 10px;border:1px solid var(--line);border-radius:10px;background:var(--surface);cursor:pointer}
.brow:hover{border-color:var(--line-strong)}
.bl{display:flex;flex-direction:column;gap:5px;min-width:0}
.bl .t{font-weight:700;font-size:13px}
.bl .muted{font-size:11.5px;font-variant-numeric:tabular-nums}
.cbar{display:flex;height:6px;border-radius:4px;background:var(--surface-2);overflow:hidden;box-shadow:inset 0 0 0 1px var(--line)}
.cbar i{display:block;height:100%}
.cbar .ci{background:var(--primary)}
.cbar .ce{background:var(--warn)}
.legend{display:flex;gap:12px;font-size:11.5px;color:var(--muted);align-items:center}
.legend i{display:inline-block;width:8px;height:8px;border-radius:2px;margin-right:5px;vertical-align:0}
.drow.static{cursor:default}
.dh .tabs button{padding:7px 6px}
.steps .lb{font-size:11.5px}
/* desktop panel dock: toggles the overview, tracking and berths panels */
@media (min-width:901px){
.dock{display:flex;flex-direction:column;gap:2px;padding:4px;position:fixed;z-index:6;left:max(10px,env(safe-area-inset-left,0px));top:50%;transform:translateY(-50%)}
.dock button{width:36px;height:36px;display:grid;place-items:center;border:0;background:transparent;border-radius:9px;cursor:pointer;color:var(--dim)}
.dock button:hover{background:var(--surface-2);color:var(--text)}
.dock button[aria-pressed="true"]{background:var(--primary-soft);color:var(--primary)}
.dock button:focus-visible{outline:2px solid var(--primary);outline-offset:1px}
.float{margin-left:48px;width:min(380px,calc(100% - 48px))}
#hud.hide-panel #panel,#hud.hide-track #track,#hud.hide-docks #docks{display:none}
#hud.hide-panel{grid-template-columns:minmax(0,1fr) 0;column-gap:0}
#docks{margin-left:auto}
}
@media (max-width:1240px){
#hud{grid-template-columns:minmax(0,1fr) 336px}
.kpi{width:188px}
.who{display:none}
.trk{grid-template-columns:minmax(0,1fr)}
#docks{width:400px}
}
@media (max-width:1020px){ .site{display:none} }
@media (max-width:900px){
.topbar{gap:8px}
.search,.livechip .lbl{display:none}
.wordmark{font-size:17px}
.speed button{min-width:32px;padding:0 7px}
#hud{grid-template-columns:minmax(0,1fr);gap:10px;padding-block:10px calc(env(safe-area-inset-bottom,0px) + 80px)}
.kpis{flex-wrap:nowrap;overflow-x:auto;width:100%;scrollbar-width:none;pointer-events:auto;padding-bottom:2px}
.kpis::-webkit-scrollbar{display:none}
.kpi{flex:none;width:184px}
.float{width:min(340px,calc(100% - 56px))}
#panel,#track,#docks{display:none;position:fixed;z-index:6;left:max(16px,env(safe-area-inset-left,0px));right:max(16px,env(safe-area-inset-right,0px));bottom:calc(env(safe-area-inset-bottom,0px) + 76px);max-height:min(60vh,560px);width:auto;max-width:none}
#panel.open,#track.open,#docks.open{display:flex}
#track.open{overflow-y:auto}
.steps .lb{font-size:11px}
.tabbar{display:flex;pointer-events:auto;position:fixed;z-index:7;left:max(16px,env(safe-area-inset-left,0px));right:max(16px,env(safe-area-inset-right,0px));bottom:calc(env(safe-area-inset-bottom,0px) + 12px);padding:5px;gap:4px}
.tabbar button{flex:1;display:flex;flex-direction:column;align-items:center;gap:3px;background:transparent;border:0;border-radius:10px;padding:7px 4px;font-size:11px;font-weight:600;color:var(--muted);cursor:pointer}
.tabbar button.on{background:var(--primary-soft);color:var(--primary)}
#toasts{top:calc(var(--hh,64px) + 110px)}
}
@media (max-width:520px){
.speed button[data-id="2"]{display:none}
.wordmark{display:none}
.tb-right{gap:8px}
.drow{grid-template-columns:52px minmax(0,1fr) auto auto}
.drow .dp{display:none}
}
@media (prefers-reduced-motion:reduce){ .fcard,.toast,.livechip i{animation:none} }
</style>
</head>
<body>
<svg width="0" height="0" style="position:absolute" aria-hidden="true">
<symbol id="i-ship" viewBox="0 0 24 24"><path d="M3 14h18l-2.6 5H5.6z"/><path d="M6 14v-4h5v4M11 11h4v3M14 7h3v4"/></symbol>
<symbol id="i-crane" viewBox="0 0 24 24"><path d="M6 21V4h13M6 4 3 8M10 4v3M17 4v6M15 10h4v3h-4zM3 21h7"/></symbol>
<symbol id="i-truck" viewBox="0 0 24 24"><path d="M3 7h11v9H3zM14 10h4l3 3v3h-7z"/><circle cx="7" cy="17.5" r="1.8"/><circle cx="17" cy="17.5" r="1.8"/></symbol>
<symbol id="i-stack" viewBox="0 0 24 24"><rect x="3" y="13" width="8" height="6" rx="1.2"/><rect x="13" y="13" width="8" height="6" rx="1.2"/><rect x="8" y="5.5" width="8" height="6" rx="1.2"/></symbol>
<symbol id="i-gate" viewBox="0 0 24 24"><path d="M4 20V7l8-3 8 3v13M4 11h16M9 20v-5h6v5"/></symbol>
<symbol id="i-coin" viewBox="0 0 24 24"><circle cx="12" cy="12" r="8.5"/><path d="M14.6 9.6c-.5-1-1.5-1.6-2.6-1.6-1.5 0-2.6.8-2.6 2s1 1.7 2.6 2 2.6.8 2.6 2-1.1 2-2.6 2c-1.1 0-2.1-.6-2.6-1.6M12 6.4V8M12 16v1.6"/></symbol>
<symbol id="i-shield" viewBox="0 0 24 24"><path d="M12 3l7 3v5c0 5-3 8-7 10-4-2-7-5-7-10V6z"/><path d="M9 12l2 2 4-4"/></symbol>
<symbol id="i-wave" viewBox="0 0 24 24"><path d="M3 9c2-2 4-2 6 0s4 2 6 0 4-2 6 0M3 15c2-2 4-2 6 0s4 2 6 0 4-2 6 0"/></symbol>
<symbol id="i-pulse" viewBox="0 0 24 24"><path d="M3 12h4l3-7 4 14 3-7h4"/></symbol>
<symbol id="i-alert" viewBox="0 0 24 24"><path d="M12 3.5 21.5 20h-19z"/><path d="M12 10v4.2M12 17.2v.1"/></symbol>
<symbol id="i-check" viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></symbol>
<symbol id="i-anchor" viewBox="0 0 24 24"><circle cx="12" cy="5" r="2"/><path d="M12 7v14M5 13a7 7 0 0 0 14 0M8.5 10.5h7"/></symbol>
<symbol id="i-berth" viewBox="0 0 24 24"><path d="M3 19h18M5 19v-8h14v8M9 11V7h6v4"/></symbol>
<symbol id="i-search" viewBox="0 0 24 24"><circle cx="11" cy="11" r="6.5"/><path d="M16 16l4.5 4.5"/></symbol>
<symbol id="i-sun" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2.5v2M12 19.5v2M2.5 12h2M19.5 12h2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4"/></symbol>
<symbol id="i-moon" viewBox="0 0 24 24"><path d="M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z"/></symbol>
<symbol id="i-plus" viewBox="0 0 24 24"><path d="M12 5v14M5 12h14"/></symbol>
<symbol id="i-minus" viewBox="0 0 24 24"><path d="M5 12h14"/></symbol>
<symbol id="i-rotate" viewBox="0 0 24 24"><path d="M20 12a8 8 0 1 1-2.4-5.7M20 4v5h-5"/></symbol>
<symbol id="i-home" viewBox="0 0 24 24"><path d="M4 11l8-7 8 7v9h-5v-6H9v6H4z"/></symbol>
<symbol id="i-chev-r" viewBox="0 0 24 24"><path d="M9 6l6 6-6 6"/></symbol>
<symbol id="i-chev-l" viewBox="0 0 24 24"><path d="M15 6l-6 6 6 6"/></symbol>
<symbol id="i-chev-d" viewBox="0 0 24 24"><path d="M6 9l6 6 6-6"/></symbol>
<symbol id="i-bolt" viewBox="0 0 24 24"><path d="M13 3 5 13h6l-1 8 8-10h-6z"/></symbol>
<symbol id="i-storm" viewBox="0 0 24 24"><path d="M7 17a4 4 0 0 1-.5-8A5.5 5.5 0 0 1 17 8a3.5 3.5 0 0 1 .5 7"/><path d="M13 12l-2 4h3l-2 4"/></symbol>
<symbol id="i-wind" viewBox="0 0 24 24"><path d="M3 8h11a3 3 0 1 0-3-3M3 12h16a3 3 0 1 1-3 3M3 16h8"/></symbol>
<symbol id="i-list" viewBox="0 0 24 24"><path d="M9 6h11M9 12h11M9 18h11M4.5 6h.01M4.5 12h.01M4.5 18h.01"/></symbol>
<symbol id="i-grid" viewBox="0 0 24 24"><rect x="4" y="4" width="7" height="7" rx="1.5"/><rect x="13" y="4" width="7" height="7" rx="1.5"/><rect x="4" y="13" width="7" height="7" rx="1.5"/><rect x="13" y="13" width="7" height="7" rx="1.5"/></symbol>
<symbol id="i-close" viewBox="0 0 24 24"><path d="M6 6l12 12M18 6 6 18"/></symbol>
<symbol id="i-wrench" viewBox="0 0 24 24"><path d="M14.7 6.3a4 4 0 0 0 5 5L21 12.6 12.6 21 9.5 18l8.4-8.4-1.3-1.3a4 4 0 0 1-5-5l2.6 2.6 2-2z"/></symbol>
<symbol id="i-map" viewBox="0 0 24 24"><path d="M12 21s-6.5-6-6.5-11a6.5 6.5 0 0 1 13 0c0 5-6.5 11-6.5 11z"/><circle cx="12" cy="10" r="2.3"/></symbol>
</svg>
<canvas id="scene" tabindex="0" aria-label="Live 3D view of the Port Mumbai container terminal"></canvas>
<div id="boot">Raising the cranes…</div>
<header class="topbar" id="topbar">
<div class="brand">
<span class="tile"><svg class="ic" aria-hidden="true"><use href="#i-wave"/></svg></span>
<span class="wordmark">TheTerminal</span>
</div>
<div class="search">
<svg class="ic" aria-hidden="true"><use href="#i-search"/></svg>
<input id="q" type="search" autocomplete="off" placeholder="Search vessels, cranes, blocks, tractors…" aria-label="Search the terminal">
<kbd>/</kbd>
<div class="qres card" id="qres" hidden></div>
</div>
<button class="site" data-act="home" title="Reset the view to the whole terminal">
<span class="tile sm"><svg class="ic" aria-hidden="true"><use href="#i-crane"/></svg></span>
<span><span class="t" style="display:block">Port Mumbai · T2</span><span class="s" id="siteSub">—</span></span>
<svg class="ic chev" aria-hidden="true"><use href="#i-chev-d"/></svg>
</button>
<div class="tb-right">
<span class="livechip"><i></i><span class="lbl">Live</span><span id="clock">Day 1 · 07:20</span></span>
<div class="speed" role="group" aria-label="Simulation speed">
<button data-act="speed" data-id="0" title="Pause (Space)" aria-label="Pause">II</button>
<button data-act="speed" data-id="1" class="on" title="Normal speed (1)">1×</button>
<button data-act="speed" data-id="2" title="Double speed (2)">2×</button>
<button data-act="speed" data-id="4" title="Fast forward (3)">4×</button>
</div>
<button class="iconbtn" id="themeBtn" data-act="theme" aria-label="Switch theme"></button>
<div class="who">
<span class="avatar">HM</span>
<span><span class="t" style="display:block">You</span><span class="s">Harbourmaster</span></span>
</div>
</div>
</header>
<div id="toasts" aria-live="polite"></div>
<div id="hud">
<section class="kpis" aria-label="Key figures">
<div class="card kpi"><span class="lb">Treasury</span><span class="tile"><svg class="ic"><use href="#i-coin"/></svg></span><span class="vv"><span class="v" id="kCash">—</span><span class="delta flat" id="dCash">—</span></span><span class="sb" id="sCash">—</span></div>
<div class="card kpi"><span class="lb">Quay throughput</span><span class="tile"><svg class="ic"><use href="#i-pulse"/></svg></span><span class="vv"><span class="v" id="kLph">—</span><span class="delta flat" id="dLph">—</span></span><span class="sb" id="sLph">—</span></div>
<div class="card kpi"><span class="lb">Carrier trust</span><span class="tile"><svg class="ic"><use href="#i-shield"/></svg></span><span class="vv"><span class="v" id="kRep">—</span><span class="delta flat" id="dRep">—</span></span><span class="sb" id="sRep">—</span></div>
<div class="card kpi"><span class="lb">Tide & wind</span><span class="tile"><svg class="ic"><use href="#i-wave"/></svg></span><span class="vv"><span class="v" id="kTide">—</span><span class="delta flat" id="dTide">—</span></span><span class="sb" id="sTide">—</span></div>
</section>
<div class="stage">
<div class="float" id="float"></div>
<div class="card mapctl" role="group" aria-label="Map controls">
<button data-act="zin" aria-label="Zoom in" title="Zoom in"><svg class="ic"><use href="#i-plus"/></svg></button>
<button data-act="zout" aria-label="Zoom out" title="Zoom out"><svg class="ic"><use href="#i-minus"/></svg></button>
<hr>
<button data-act="rot" aria-label="Rotate view" title="Rotate 45°"><svg class="ic"><use href="#i-rotate"/></svg></button>
<button data-act="home" aria-label="Reset view" title="Reset view"><svg class="ic"><use href="#i-home"/></svg></button>
</div>
</div>
<aside class="card" id="panel" aria-label="Terminal overview">
<div class="ph">
<div class="phead">
<span class="tile"><svg class="ic"><use href="#i-crane"/></svg></span>
<div style="min-width:0"><div class="eyebrow">Terminal · T2</div><div class="ptitle">Mumbai Container Terminal</div><div class="psub">Quay 2, Port Mumbai harbour</div></div>
</div>
<div class="pstat"><span class="pill ok" id="opPill">Operational</span><span class="muted" id="opLine">—</span></div>
<div class="tabs" role="tablist">
<button data-act="ptab" data-id="overview" class="on" role="tab">Overview</button>
<button data-act="ptab" data-id="yard" role="tab">Yard plan</button>
<button data-act="ptab" data-id="build" role="tab">Build</button>
</div>
</div>
<div class="scroll" id="pOverview">
<div class="mgrid">
<div class="metric"><span class="k">Berth use</span><span class="v" id="kBerth">—</span><div class="bar"><i id="mBerth"></i></div></div>
<div class="metric"><span class="k">Yard fill</span><span class="v" id="kYard">—</span><div class="cbar"><i class="ci" id="mYardI"></i><i class="ce" id="mYardE"></i></div><span class="s" id="kYardS">—</span></div>
<div class="metric"><span class="k">Avg anchor wait</span><span class="v" id="kWait">—</span><span class="s" id="kQueue">—</span></div>
<div class="metric"><span class="k">Gate moves</span><span class="v" id="kGate">—</span><span class="s" id="kGateS">—</span></div>
<div class="metric"><span class="k">Import dwell</span><span class="v" id="kDwI">—</span><span class="s" id="kDwIS">—</span></div>
<div class="metric"><span class="k">Export dwell</span><span class="v" id="kDwE">—</span><span class="s" id="kDwES">—</span></div>
</div>
<div class="sect">
<div class="sh"><h3>Quay throughput</h3><span class="muted">lifts / hr · last 6 h</span></div>
<svg id="spark" viewBox="0 0 300 58" preserveAspectRatio="none" aria-hidden="true"></svg>
<div class="sparkax"><span id="spMin">—</span><span id="spMax">—</span></div>
</div>
<div class="sect"><div class="sh"><h3>Watch list</h3></div><ul class="rows" id="alerts"></ul></div>
<div class="sect"><div class="sh"><h3>Yard blocks</h3><span class="muted">boxes stacked</span></div><ul class="rows" id="blocks"></ul></div>
<div class="sect"><div class="sh"><h3>Tractor fleet</h3><span class="muted" id="fleetTxt">—</span></div><div class="bar"><i id="mFleet"></i></div><span class="muted" style="font-size:12px" id="fleetSub">—</span></div>
</div>
<div class="scroll" id="pYard" hidden></div>
<div class="scroll" id="pBuild" hidden><div class="rows" id="build"></div></div>
</aside>
<footer class="bottom">
<section class="card" id="track" aria-label="Vessel tracking"></section>
<section class="card" id="docks" aria-label="Berths and anchorage">
<div class="dh">
<div class="tabs" role="tablist">
<button data-act="dtab" data-id="berths" class="on">Berths <b id="cB">—</b></button>
<button data-act="dtab" data-id="sched">Schedule <b id="cS">—</b></button>
<button data-act="dtab" data-id="anch">Anchorage <b id="cA">—</b></button>
<button data-act="dtab" data-id="log">Log</button>
</div>
</div>
<div class="dbody" id="dBerths"></div>
<div class="dbody" id="dAnch" hidden>
<label class="switch"><span>Auto-berth in priority, then arrival order</span><input type="checkbox" id="auto" checked><span class="sw"></span></label>
<div id="queue" style="display:flex;flex-direction:column;gap:6px"></div>
</div>
<div class="dbody" id="dSched" hidden></div>
<div class="dbody" id="dLog" hidden><ol class="log" id="log"></ol></div>
</section>
</footer>
<nav class="card dock" aria-label="Show or hide panels">
<button data-act="dock" data-id="panel" aria-pressed="true" aria-label="Terminal overview" title="Terminal overview"><svg class="ic"><use href="#i-grid"/></svg></button>
<button data-act="dock" data-id="track" aria-pressed="true" aria-label="Vessel tracking" title="Vessel tracking"><svg class="ic"><use href="#i-ship"/></svg></button>
<button data-act="dock" data-id="docks" aria-pressed="true" aria-label="Berths and anchorage" title="Berths and anchorage"><svg class="ic"><use href="#i-berth"/></svg></button>
</nav>
<nav class="card tabbar" aria-label="Panels">
<button data-act="mtab" data-id="panel"><svg class="ic"><use href="#i-grid"/></svg>Overview</button>
<button data-act="mtab" data-id="docks"><svg class="ic"><use href="#i-berth"/></svg>Berths</button>
<button data-act="mtab" data-id="track"><svg class="ic"><use href="#i-map"/></svg>Track</button>
<button data-act="mtab" data-id="build"><svg class="ic"><use href="#i-crane"/></svg>Build</button>
</nav>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
(() => {
'use strict';
const $ = s => document.querySelector(s);
if (!window.THREE) { $('#boot').textContent = 'The 3D engine did not load. Check your connection and reload.'; return; }
/* ====================================================================
Helpers
==================================================================== */
const TAU = Math.PI * 2;
const rand = (a, b) => a + Math.random() * (b - a);
const randi = (a, b) => Math.floor(rand(a, b + 1));
const pick = a => a[Math.floor(Math.random() * a.length)];
const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
const lerp = (a, b, t) => a + (b - a) * t;
const smooth = (e0, e1, x) => { const t = clamp((x - e0) / (e1 - e0), 0, 1); return t * t * (3 - 2 * t); };
const approach = (v, t, s) => v < t ? Math.min(t, v + s) : Math.max(t, v - s);
const angDiff = (a, b) => { let d = (b - a) % TAU; if (d > Math.PI) d -= TAU; if (d < -Math.PI) d += TAU; return d; };
const hexCss = h => '#' + h.toString(16).padStart(6, '0');
const shuffle = a => { for (let i = a.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [a[i], a[j]] = [a[j], a[i]]; } return a; };
const money = n => { const s = n < 0 ? '−' : ''; n = Math.abs(n); return s + '$' + (n >= 1e6 ? (n / 1e6).toFixed(2) + 'M' : n >= 1e3 ? Math.round(n / 1e3) + 'k' : Math.round(n)); };
const esc = s => String(s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
const V3 = (x, y, z) => new THREE.Vector3(x, y, z);
/* ====================================================================
Themes: one palette for the UI tokens, one for the 3D scene
==================================================================== */
const THEMES = {
light: {
night: 0, skyTop: 0xb9cfeb, skyHor: 0xe9eff6, stormTop: 0x8a98a9, stormHor: 0xc5cdd7, fogD: 0.0016,
waterDeep: 0x4f8fd0, waterShallow: 0x9ccaee, grid: 0x2f5bea, gridAmt: 0.22, waterLight: 1.0, foam: 0xffffff,
hemiSky: 0xffffff, hemiGround: 0xc4cfdc, hemi: 0.95, sun: 1.15, sunColor: 0xfffaf0,
slab: 0xd0d8e3, quayFace: 0xb4c0cf, hinter: 0xdbe2ea, road: 0x3a4451, shed: 0x2f5bea, crane: 0x2f5bea, craneDark: 0x24324d,
house: 0xffffff, rtg: 0xf2b43a, deck: 0x56606e, truckCab: 0x2f5bea, extCab: 0xffffff, chassis: 0x2c3544,
leaf: 0x5cc46e, trunk: 0x8a6a4a, pole: 0x9aa8b8, rain: 0x5f7d9c, fender: 0x262c35, gateOff: 0xc3ccd8, gateOn: 0x22c55e,
ground: { base: '#e3e9f0', apron: '#edf1f6', road: '#2e3844', speck: '60,80,110', speckA: 0.05, coping: '#f2b63c', copingDark: '#c9d2dd', rail: '#a9b5c4',
line: 'rgba(255,255,255,.85)', lineStrong: 'rgba(255,255,255,.95)', amber: 'rgba(217,119,6,.7)', aisle: 'rgba(255,255,255,.45)',
blockFill: 'rgba(47,91,234,.07)', blockStroke: 'rgba(47,91,234,.5)', blockGrid: 'rgba(47,91,234,.12)', text: 'rgba(30,45,70,.5)',
amberText: 'rgba(180,83,9,.65)', gateFill: 'rgba(245,158,11,.12)' },
label: { bg: 'rgba(255,255,255,.97)', border: 'rgba(47,91,234,.55)', pri: 'rgba(217,119,6,.95)', text: '#0F172A', sub: '#5B6B82' },
pin: '#2F5BEA', danger: '#DC2626',
},
dark: {
night: 1, skyTop: 0x030a14, skyHor: 0x0a1b2c, stormTop: 0x0a1118, stormHor: 0x1a2632, fogD: 0.0023,
waterDeep: 0x03172a, waterShallow: 0x0e3c5c, grid: 0x5b82ff, gridAmt: 0.3, waterLight: 0.78, foam: 0x9cc0d8,
hemiSky: 0x9cc6ff, hemiGround: 0x0b1a26, hemi: 0.55, sun: 0.5, sunColor: 0xa9c2ff,
slab: 0x18293a, quayFace: 0x223445, hinter: 0x0b1622, road: 0x2c3743, shed: 0x1b2f66, crane: 0x3f68e6, craneDark: 0x172235,
house: 0xc9d3de, rtg: 0xd8a038, deck: 0x2a333d, truckCab: 0x3f68e6, extCab: 0xcfd6de, chassis: 0x1b232c,
leaf: 0x1d5a3c, trunk: 0x3a2c20, pole: 0x3a4a58, rain: 0xa8d4f0, fender: 0x0a0e13, gateOff: 0x31404e, gateOn: 0x4ade80,
ground: { base: '#0f1c29', apron: '#142638', road: '#2c3743', speck: '150,175,200', speckA: 0.045, coping: '#b28a3c', copingDark: '#2b3c4c', rail: '#4a6278',
line: 'rgba(232,238,244,.35)', lineStrong: 'rgba(232,238,244,.5)', amber: 'rgba(251,191,36,.55)', aisle: 'rgba(232,238,244,.12)',
blockFill: 'rgba(91,130,255,.06)', blockStroke: 'rgba(140,165,255,.42)', blockGrid: 'rgba(232,238,244,.07)', text: 'rgba(232,238,244,.38)',
amberText: 'rgba(251,191,36,.45)', gateFill: 'rgba(251,191,36,.07)' },
label: { bg: 'rgba(13,23,40,.92)', border: 'rgba(91,130,255,.75)', pri: 'rgba(251,191,36,.9)', text: '#E8EEF6', sub: '#97A7BF' },
pin: '#5B82FF', danger: '#F87171',
},
};
const rootEl = document.documentElement;
const darkMQ = window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null;
try { const saved = localStorage.getItem('tidegrid-theme'); if (saved === 'light' || saved === 'dark') rootEl.setAttribute('data-theme', saved); } catch (e) {}
function currentTheme() { const a = rootEl.getAttribute('data-theme'); if (a === 'light' || a === 'dark') return a; return darkMQ && darkMQ.matches ? 'dark' : 'light'; }
let curTheme = currentTheme();
let TH = THEMES[curTheme];
/* ====================================================================
World constants
==================================================================== */
const G = 0.35; // game minutes per simulated second
const QUAY_LANE = -4, SPINE = -14, BERTH_Z = 7.2, TRAVEL_Y = 12;
const LIFT_RATE = 1400; // $ earned per container lift
const WIND_BASE = 38, WIND_RATED = 46;
const PRICE = { truck: 45000, block: 160000, gate: 90000, berth: 480000, crane: 260000, autopilot: 300000, storm: 220000, repair: 30000 };
const OPEX = { crane: 6000, truck: 1500, block: 2500, berth: 4000, gate: 1500 }; // per game hour
const LINES = [
{ name: 'Meridian Lines', hull: 0x1c3a5a, accent: 0xd9a441 },
{ name: 'Kestrel Ocean', hull: 0x5b2124, accent: 0xe8eef4 },
{ name: 'Halvard Maritime', hull: 0x22343f, accent: 0x3ee6a8 },
{ name: 'Sable Coast', hull: 0x26262e, accent: 0xff7a45 },
{ name: 'Orrin Freight', hull: 0x14434b, accent: 0x7fc8ff },
];
const SHIP_NAMES = ['Calder Reach','Halcyon Drift','Northmark','Saltvane','Brisa Mumbai','Ostra Bay','Tessaline','Corvid Star','Lumen Tide','Varga Point','Peregrine Sea','Isola Grey','Marrow Sound','Quillon','Asteria Bight','Kelpie Run','Solent Ash','Ardent Fathom','Morrow Gate','Cinder Cove','Ilse Marron','Faro Vento','Gannet Rise','Severn Lark'];
const BOX_COLORS = [0xb8432f, 0x2f6f9f, 0xd29a3a, 0x3f8a6b, 0x7d848f, 0xd5dde6, 0x5b4a8a, 0x9c5a2c, 0x2b5f73, 0xa83a3a];
const BERTHS = [
{ id: 'A', x: -62, open: true, ship: null, cranes: [] },
{ id: 'B', x: 0, open: true, ship: null, cranes: [] },
{ id: 'C', x: 62, open: false, ship: null, cranes: [] },
];
const COL_ID = { '-72': 'A', '-36': 'B', '0': 'C', '36': 'D', '72': 'E' };
const BLOCK_ORDER = [[-36, -26], [0, -26], [36, -26], [0, -44], [-72, -26], [72, -26], [-36, -44], [36, -44], [-72, -44], [72, -44]];
const BLK = { cols: 8, rows: 6, tiers: 4, cap: 192 };
const ANCH = [[-110, 104], [-52, 114], [6, 106], [62, 116], [118, 104], [-82, 158], [-22, 164], [36, 160], [96, 166], [150, 150]];
/* ====================================================================
Game state
==================================================================== */
const S = {
credits: 900000, rep: 58, minutes: 7 * 60 + 20, speed: 1,
liftTimes: [], gateTimes: [], spark: [], sparkAcc: 0,
liftsToday: 0, revToday: 0, dayStamp: 1,
waits: [], gateLanes: 2, gateAcc: 0, autopilot: false, stormRated: false,
wind: 11, windTarget: 11, windTimer: 0,
storm: null, customs: null, flash: 0,
nextContract: 150, nextStorm: rand(420, 640), nextCustoms: rand(700, 1000), nextFault: rand(260, 420),
contract: null, selected: null, autoBerth: true,
ships: [], trucks: [], ext: [], tweens: [], blocks: [], cranes: [],
shipSeq: 0, truckSeq: 0, craneSeq: 0, usedNames: new Set(),
flags: {},
calls: [], callSeq: 0, window: 2, hold: 60, pickups: 0, gateTurn: false,
rehandles: 0, rehandlesToday: 0, rehandleTimes: [], gateInTimes: [], dwell: { imp: [], exp: [] }, shortShipped: 0, started: false,
};
const REHANDLE_COST = 300;
/* ====================================================================
Renderer / scene
==================================================================== */
const canvas = $('#scene');
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, powerPreference: 'high-performance' });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.75));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
const fogColor = new THREE.Color(0x0b2236);
scene.fog = new THREE.FogExp2(fogColor, 0.0024);
scene.background = fogColor;
const camera = new THREE.PerspectiveCamera(42, 1, 0.5, 3200);
const hemi = new THREE.HemisphereLight(0x9cc6ff, 0x0b1a26, 0.6);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffffff, 0.9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
Object.assign(sun.shadow.camera, { left: -160, right: 160, top: 160, bottom: -160, near: 10, far: 600 });
sun.shadow.bias = -0.0006;
scene.add(sun, sun.target);
/* ---- sky dome ---- */
const skyU = {
uTop: { value: new THREE.Color(0x030a14) }, uHorizon: { value: fogColor.clone() },
uGlow: { value: new THREE.Color(0xff8a4a) }, uSunDir: { value: V3(0, 1, 0) }, uGlowAmt: { value: 0 },
};
const sky = new THREE.Mesh(new THREE.SphereGeometry(1500, 32, 16), new THREE.ShaderMaterial({
uniforms: skyU, side: THREE.BackSide, depthWrite: false, fog: false,
vertexShader: `varying vec3 vDir; void main(){ vDir = normalize(position); gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0); }`,
fragmentShader: `uniform vec3 uTop,uHorizon,uGlow,uSunDir; uniform float uGlowAmt; varying vec3 vDir;
void main(){ float h = clamp(vDir.y,0.0,1.0); vec3 c = mix(uHorizon,uTop,pow(h,0.5));
float s = pow(max(dot(normalize(vDir),normalize(uSunDir)),0.0),6.0);
c += uGlow * s * uGlowAmt * (1.0-h);
gl_FragColor = vec4(c,1.0); }`
}));
sky.renderOrder = -1;
scene.add(sky);
/* ---- stars ---- */
const starGeo = new THREE.BufferGeometry();
{ const p = []; for (let i = 0; i < 900; i++) { const th = rand(0, TAU), ph = rand(0.08, 1.45); p.push(Math.cos(th) * Math.cos(ph) * 1400, Math.sin(ph) * 1400, Math.sin(th) * Math.cos(ph) * 1400); }
starGeo.setAttribute('position', new THREE.Float32BufferAttribute(p, 3)); }
const starMat = new THREE.PointsMaterial({ color: 0xcfe6ff, size: 2.2, sizeAttenuation: false, transparent: true, opacity: 0.8, fog: false, depthWrite: false });
const stars = new THREE.Points(starGeo, starMat);
scene.add(stars);
/* ---- water: "tidal grid" shader ---- */
const waterU = {
uTime: { value: 0 }, uAmp: { value: 1 }, uLight: { value: 1 },
uDeep: { value: new THREE.Color(0x03172a) }, uShallow: { value: new THREE.Color(0x0e3c5c) },
uGrid: { value: new THREE.Color(0x00bfff) }, uGridAmt: { value: 0.3 }, uFoam: { value: new THREE.Color(0xffffff) }, uFog: { value: fogColor }, uFogD: { value: 0.0024 },
uSun: { value: V3(0.4, 0.8, 0.3) },
};
const water = new THREE.Mesh(new THREE.PlaneGeometry(2600, 2600, 220, 220), new THREE.ShaderMaterial({
uniforms: waterU, extensions: { derivatives: true },
vertexShader: `uniform float uTime; uniform float uAmp; varying vec3 vW; varying float vH;
void main(){ vec4 wp = modelMatrix * vec4(position,1.0);
float h = sin(wp.x*0.045 + uTime*0.9)*0.32 + sin(wp.z*0.06 - uTime*1.15)*0.24 + sin((wp.x+wp.z)*0.12 + uTime*1.8)*0.1;
h *= uAmp * smoothstep(0.0, 14.0, wp.z + 4.0); wp.y += h; vH = h; vW = wp.xyz;
gl_Position = projectionMatrix * viewMatrix * wp; }`,
fragmentShader: `uniform vec3 uDeep,uShallow,uGrid,uFog,uSun,uFoam; uniform float uFogD,uTime,uLight,uGridAmt;
varying vec3 vW; varying float vH;
void main(){
float d = length(cameraPosition - vW);
vec3 n = normalize(cross(dFdx(vW), dFdy(vW))); if (n.y < 0.0) n = -n;
vec3 v = normalize(cameraPosition - vW);
float fres = pow(1.0 - max(dot(n, v), 0.0), 3.0);
vec3 col = mix(uDeep, uShallow, clamp(vH*0.9 + 0.45, 0.0, 1.0) * 0.55 + fres * 0.35) * uLight;
vec3 hdir = normalize(normalize(uSun) + v);
col += vec3(1.0,0.92,0.8) * pow(max(dot(n,hdir),0.0), 90.0) * 0.6 * uLight;
vec2 gp = vW.xz / 12.0;
vec2 g = abs(fract(gp - 0.5) - 0.5) / fwidth(gp);
float line = 1.0 - min(min(g.x, g.y), 1.0);
float pulse = 0.5 + 0.5 * sin(uTime*0.7 - length(vW.xz - vec2(0.0,-20.0))*0.035);
col = mix(col, uGrid, clamp(line * uGridAmt * (0.45 + 0.55*pulse) * exp(-d*0.0035), 0.0, 1.0));
float foam = smoothstep(5.0, 0.0, vW.z) * step(abs(vW.x), 120.0);
col = mix(col, uFoam, clamp(foam * (0.22 + 0.12*sin(vW.x*0.9 + uTime*3.0)), 0.0, 1.0));
float f = 1.0 - exp(-pow(uFogD * d, 2.0));
gl_FragColor = vec4(mix(col, uFog, f), 1.0);
}`
}));
water.rotation.x = -Math.PI / 2;
scene.add(water);
/* ====================================================================
Materials
==================================================================== */
const std = (color, rough = 0.6, metal = 0.2, extra = {}) => new THREE.MeshStandardMaterial(Object.assign({ color, roughness: rough, metalness: metal }, extra));
const M = {
container: std(0xffffff, 0.62, 0.25),
crane: std(0x2b87bd, 0.5, 0.4), craneDark: std(0x173247, 0.7, 0.3), house: std(0xdfe7ee, 0.6, 0.1),
warn: std(0xffb547, 0.5, 0.2), rtg: std(0xd8a038, 0.5, 0.35), concrete: std(0x18293a, 0.95, 0.05),
quayFace: std(0x223445, 0.95, 0.05), fender: std(0x0a0e13, 0.9, 0), deck: std(0x2a333d, 0.8, 0.2),
hinter: std(0x0b1622, 1, 0), road: std(0x3a4451, 0.95, 0), shed: std(0x1d2c3b, 0.9, 0.1), tree: std(0x0d2420, 1, 0),
window: std(0x101f2b, 0.5, 0.1, { emissive: new THREE.Color(0xffd28a), emissiveIntensity: 0.2 }),
lampHead: std(0x2a2418, 0.6, 0.3, { emissive: new THREE.Color(0xffb547), emissiveIntensity: 1 }),
pole: std(0x3a4a58, 0.6, 0.5), truckCab: std(0xe3a33a, 0.5, 0.3), extCab: std(0xcfd6de, 0.5, 0.3),
chassis: std(0x1b232c, 0.8, 0.4), tire: std(0x0b0d10, 0.9, 0), leaf: std(0x5cc46e, 0.9, 0), trunk: std(0x8a6a4a, 0.9, 0),
red: new THREE.MeshBasicMaterial({ color: 0xff3b30 }), flood: new THREE.MeshBasicMaterial({ color: 0xfff1d0 }),
gateOn: new THREE.MeshBasicMaterial({ color: 0x3ee6a8 }), gateOff: new THREE.MeshBasicMaterial({ color: 0x31404e }),
lighthouse: new THREE.MeshBasicMaterial({ color: 0xfff3c4, transparent: true, opacity: 1 }),
};
const boxMatCache = {};
const boxMat = hex => boxMatCache[hex] || (boxMatCache[hex] = std(hex, 0.62, 0.25));
const hullMatCache = {};
const hullMat = hex => hullMatCache[hex] || (hullMatCache[hex] = std(hex, 0.55, 0.35));
const boxGeo = new THREE.BoxGeometry(2.4, 1.0, 1.0);
const unit = new THREE.BoxGeometry(1, 1, 1);
const ZERO = new THREE.Matrix4().makeScale(0, 0, 0);
function mesh(geo, mat, x, y, z, shadow = true) {
const m = new THREE.Mesh(geo, mat); m.position.set(x, y, z);
if (shadow) { m.castShadow = true; m.receiveShadow = true; }
return m;
}
function box(w, h, d, mat, x, y, z, shadow = true) { const m = mesh(unit, mat, x, y, z, shadow); m.scale.set(w, h, d); return m; }
function beam(a, b, t, mat) {
const m = new THREE.Mesh(unit, mat); m.position.copy(a).add(b).multiplyScalar(0.5);
m.scale.set(t, t, a.distanceTo(b)); m.lookAt(b); m.castShadow = true; return m;
}
/* ====================================================================
Terrain: terminal slab, quay, hinterland, breakwater
==================================================================== */
const groundCanvas = document.createElement('canvas');
groundCanvas.width = 2400; groundCanvas.height = 1100;
const groundTex = new THREE.CanvasTexture(groundCanvas);
groundTex.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
function drawGround() {
const g = groundCanvas.getContext('2d'), W = 2400, H = 1100, C = TH.ground;
const P = (x, z) => [(x + 120) * 10, (z + 110) * 10];
g.setLineDash([]);
g.fillStyle = C.base; g.fillRect(0, 0, W, H);
let seed = 7; const rnd = () => (seed = (seed * 16807) % 2147483647) / 2147483647;
for (let i = 0; i < 7000; i++) { g.fillStyle = `rgba(${C.speck},${rnd() * C.speckA})`; g.fillRect(rnd() * W, rnd() * H, 2 + rnd() * 5, 2 + rnd() * 5); }
const ya = P(0, -12)[1]; g.fillStyle = C.apron; g.fillRect(0, ya, W, H - ya);
g.fillStyle = C.coping; g.fillRect(0, H - 7, W, 7);
g.fillStyle = C.copingDark; g.fillRect(0, H - 14, W, 7);
g.strokeStyle = C.rail; g.lineWidth = 4;
[-0.8, -7.2].forEach(z => { const y = P(0, z)[1]; g.beginPath(); g.moveTo(0, y); g.lineTo(W, y); g.stroke(); });
const dashed = (x1, z1, x2, z2, col, w, dash) => {
const [a, b] = P(x1, z1), [c, d] = P(x2, z2); g.strokeStyle = col; g.lineWidth = w; g.setLineDash(dash || []);
g.beginPath(); g.moveTo(a, b); g.lineTo(c, d); g.stroke(); g.setLineDash([]);
};
// asphalt under every lane trucks drive on
g.fillStyle = C.road;
const band = (x0, z0, x1, z1) => { const [a, b] = P(x0, z0), [c, d] = P(x1, z1); g.fillRect(a, b, c - a, d - b); };
[[QUAY_LANE, 1.5], [SPINE, 1.8], [-20.7, 1.2], [-38.7, 1.2], [-96, 1.8]].forEach(([z, hw]) => band(-120, z - hw, 120, z + hw));
[-90, -54, -18, 18, 54, 90, 104].forEach(x => band(x - 1.8, -98, x + 1.8, SPINE - 1.8));
band(-12, -110, 12, -96);
dashed(-120, QUAY_LANE + 1.5, 120, QUAY_LANE + 1.5, C.line, 3, [30, 22]);
dashed(-120, QUAY_LANE - 1.5, 120, QUAY_LANE - 1.5, C.line, 3, [30, 22]);
dashed(-120, SPINE + 1.8, 120, SPINE + 1.8, C.lineStrong, 3);
dashed(-120, SPINE - 1.8, 120, SPINE - 1.8, C.lineStrong, 3);
dashed(-120, SPINE, 120, SPINE, C.amber, 3, [40, 30]);
[-90, -54, -18, 18, 54, 90, 104].forEach(x => dashed(x, SPINE - 1.8, x, -98, C.aisle, 2, [20, 20]));
dashed(-120, -96 + 1.8, 120, -96 + 1.8, C.line, 3);
dashed(-120, -96 - 1.8, 120, -96 - 1.8, C.line, 3);
g.font = '700 44px Inter, system-ui, sans-serif'; g.textAlign = 'left'; g.textBaseline = 'alphabetic';
BLOCK_ORDER.forEach(([bx, bz]) => {
const [x0, y0] = P(bx - 11, bz - 3.6), [x1, y1] = P(bx + 11, bz + 3.6);
const blk = S.blocks.find(q => q.x === bx && q.z === bz), ex = !!(blk && blk.open && blk.role === 'export');
g.fillStyle = ex ? C.gateFill : C.blockFill; g.fillRect(x0, y0, x1 - x0, y1 - y0);
g.strokeStyle = ex ? C.amber : C.blockStroke; g.lineWidth = 3; g.strokeRect(x0, y0, x1 - x0, y1 - y0);
g.strokeStyle = C.blockGrid; g.lineWidth = 2;
for (let c = 1; c < BLK.cols; c++) { const xx = P(bx - 10.4 + c * 2.6, 0)[0]; g.beginPath(); g.moveTo(xx, y0); g.lineTo(xx, y1); g.stroke(); }
dashed(bx - 11, bz + 5.3, bx + 11, bz + 5.3, C.amber, 2, [14, 12]);
const id = COL_ID[String(bx)] + (bz === -26 ? '1' : '2');
g.fillStyle = ex ? C.amberText : C.text; const [tx, ty] = P(bx - 10.6, bz - 4.2);
g.fillText(blk && blk.open ? id + (ex ? ' · EXPORT' : ' · IMPORT') : id, tx, ty);
});
g.font = '800 66px Inter, system-ui, sans-serif'; g.textAlign = 'center';
BERTHS.forEach(b => { const [x, y] = P(b.x, -9.6); g.fillStyle = C.text; g.fillText('BERTH ' + b.id, x, y); });
g.font = '700 32px Inter, system-ui, sans-serif';
{ const [x, y] = P(104, -42); g.fillStyle = C.amberText; g.save(); g.translate(x, y); g.rotate(-Math.PI / 2); g.fillText('TRACTOR DEPOT', 0, 14); g.restore(); }
{ const [x0, y0] = P(-14, -110), [x1, y1] = P(14, -98); g.fillStyle = C.gateFill; g.fillRect(x0, y0, x1 - x0, y1 - y0);
g.fillStyle = C.text; g.font = '800 42px Inter, system-ui, sans-serif'; g.fillText('GATE 2', P(0, 0)[0], P(0, -100.5)[1]); }
groundTex.needsUpdate = true;
}
drawGround();
if (document.fonts && document.fonts.ready) document.fonts.ready.then(() => { drawGround(); S.ships.forEach(drawShipLabel); });
{ // terminal slab
const top = new THREE.MeshStandardMaterial({ map: groundTex, roughness: 0.95, metalness: 0.02 });
const slab = new THREE.Mesh(new THREE.BoxGeometry(240, 10, 110), [M.concrete, M.concrete, top, M.concrete, M.quayFace, M.concrete]);
slab.position.set(0, -5, -55); slab.receiveShadow = true; scene.add(slab);
const hinter = new THREE.Mesh(new THREE.BoxGeometry(1400, 10, 900), M.hinter);
hinter.position.set(0, -5.05, -560); hinter.receiveShadow = true; scene.add(hinter);
// fenders & bollards
for (let x = -116; x <= 116; x += 7.5) {
scene.add(box(1.4, 3.2, 0.7, M.fender, x, -1.6, 0.35, false));
scene.add(mesh(new THREE.CylinderGeometry(0.3, 0.38, 0.7, 8), M.craneDark, x + 3.7, 0.35, -0.5));
}
// gate approach road (gate lanes run x -9..9 from the gate out to z -175)
const gateRoad = new THREE.Mesh(new THREE.PlaneGeometry(24, 72), M.road);
gateRoad.rotation.x = -Math.PI / 2; gateRoad.position.set(0, 0.02, -146); gateRoad.receiveShadow = true; scene.add(gateRoad);
// warehouses + a scatter of hinterland sheds (keep clear of the gate road, |x| < 14)
const sheds = [[-80, -128, 40, 9, 16], [-38, -132, 40, 11, 20], [40, -126, 30, 8, 14], [95, -134, 44, 10, 18], [-150, -170, 60, 12, 24], [150, -180, 50, 9, 20], [70, -230, 60, 10, 22]];
sheds.forEach(([x, z, w, h, d]) => {
scene.add(box(w, h, d, M.shed, x, h / 2, z));
for (let i = 0; i < Math.floor(w / 6); i++) scene.add(box(1.6, 0.6, 0.1, M.window, x - w / 2 + 3 + i * 6, h * 0.55, z + d / 2 + 0.06, false));
});
// reefer stacks at the back (decor), gate canopy built later
// breakwater + lighthouse
scene.add(box(200, 4, 7, M.quayFace, 326, -1, 196));
for (let i = 0; i < 40; i++) scene.add(mesh(new THREE.DodecahedronGeometry(rand(1.2, 2.6)), M.concrete, rand(228, 424), rand(-1, 0.6), 196 + pick([-4.5, 4.5]) + rand(-1, 1), false));
scene.add(mesh(new THREE.CylinderGeometry(1.4, 2.2, 16, 12), M.house, 232, 8, 196));
scene.add(mesh(new THREE.CylinderGeometry(1.6, 1.6, 1.6, 12), M.red, 232, 4, 196, false));
}
const lighthouseLamp = new THREE.Mesh(new THREE.SphereGeometry(1.4, 12, 8), M.lighthouse);
lighthouseLamp.position.set(232, 17, 196); scene.add(lighthouseLamp);
const glowTex = (() => {
const c = document.createElement('canvas'); c.width = c.height = 128; const g = c.getContext('2d');
const gr = g.createRadialGradient(64, 64, 0, 64, 64, 64);
gr.addColorStop(0, 'rgba(255,255,255,1)'); gr.addColorStop(0.25, 'rgba(255,255,255,.55)'); gr.addColorStop(1, 'rgba(255,255,255,0)');
g.fillStyle = gr; g.fillRect(0, 0, 128, 128); return new THREE.CanvasTexture(c);
})();
const lhGlow = new THREE.Sprite(new THREE.SpriteMaterial({ map: glowTex, color: 0xffe3a0, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false }));
lhGlow.scale.set(18, 18, 1); lhGlow.position.copy(lighthouseLamp.position); scene.add(lhGlow);
/* ---- trees (landscape buffer around the terminal) ---- */
{
const crown = new THREE.IcosahedronGeometry(2.4, 1), trunkG = new THREE.CylinderGeometry(0.3, 0.42, 2.4, 6);
const spots = [];
for (let x = -112; x <= 112; x += 13) if (Math.abs(x) > 20) spots.push([x + rand(-2, 2), -113 + rand(-1.5, 1.5)]);
for (let z = -100; z <= -22; z += 13) { spots.push([-117 + rand(-1, 1), z]); }
for (let i = 0; i < 26; i++) { const x = rand(-200, 200); if (Math.abs(x) > 16) spots.push([x, rand(-150, -260)]); }
spots.forEach(([x, z]) => {
const s = rand(0.85, 1.3);
const t = mesh(trunkG, M.trunk, x, 1.2 * s, z); t.scale.setScalar(s); scene.add(t);
const c = mesh(crown, M.leaf, x, (2.4 + 2.2) * s, z); c.scale.setScalar(s); scene.add(c);
});
}
/* ---- distant ridge + city lights ---- */
for (let i = 0; i < 9; i++) {
const r = rand(80, 180), h = rand(40, 110);
const cone = new THREE.Mesh(new THREE.ConeGeometry(r, h, 6), M.hinter);
cone.position.set(-700 + i * 175 + rand(-40, 40), h / 2 - 6, -980 + rand(-60, 60)); scene.add(cone);
}
const cityGeo = new THREE.BufferGeometry();
{ const p = []; for (let i = 0; i < 700; i++) p.push(rand(-700, 700), rand(0.5, 8), rand(-860, -300)); cityGeo.setAttribute('position', new THREE.Float32BufferAttribute(p, 3)); }
const cityMat = new THREE.PointsMaterial({ color: 0xffc77a, size: 2.4, sizeAttenuation: false, transparent: true, opacity: 0.7, depthWrite: false });
scene.add(new THREE.Points(cityGeo, cityMat));
/* ---- lamp poles + light pools ---- */
const pools = [];
const poolMat = new THREE.MeshBasicMaterial({ map: glowTex, color: 0xffb547, transparent: true, opacity: 0.3, blending: THREE.AdditiveBlending, depthWrite: false });
[[-90, SPINE], [-54, SPINE], [-18, SPINE], [18, SPINE], [54, SPINE], [90, SPINE], [-90, -35], [-54, -35], [-18, -35], [18, -35], [54, -35], [90, -35], [-54, -60], [0, -60], [54, -60], [-110, -6], [110, -6]].forEach(([x, z]) => {
scene.add(mesh(new THREE.CylinderGeometry(0.22, 0.32, 24, 6), M.pole, x, 12, z));
scene.add(box(2.6, 0.5, 2.6, M.lampHead, x, 24.2, z, false));
const p = new THREE.Mesh(new THREE.PlaneGeometry(34, 34), poolMat); p.rotation.x = -Math.PI / 2; p.position.set(x, 0.06, z); p.renderOrder = 2; scene.add(p); pools.push(p);
});
/* ---- gate canopy ---- */
const gateBooths = [];
{
scene.add(box(34, 0.8, 9, M.house, 0, 7.5, -101));
[-16, 16].forEach(x => scene.add(box(0.8, 7.5, 0.8, M.pole, x, 3.75, -101)));
for (let i = 0; i < 4; i++) {
const x = -9 + i * 6;
scene.add(box(1.4, 2.4, 2.2, M.craneDark, x - 2.6, 1.2, -101));
const lamp = box(4.4, 0.25, 0.3, M.gateOff, x, 7.0, -96.6, false); scene.add(lamp); gateBooths.push(lamp);
}
}
const gateLaneX = i => -9 + (i % 4) * 6;
/* ---- rain ---- */
const rainGeo = new THREE.BufferGeometry();
const RAIN_N = 2600;
const rainPos = new Float32Array(RAIN_N * 3);
for (let i = 0; i < RAIN_N; i++) { rainPos[i * 3] = rand(-160, 160); rainPos[i * 3 + 1] = rand(0, 90); rainPos[i * 3 + 2] = rand(-160, 160); }
rainGeo.setAttribute('position', new THREE.BufferAttribute(rainPos, 3));
const rainMat = new THREE.PointsMaterial({ color: 0xa8d4f0, size: 0.55, transparent: true, opacity: 0, depthWrite: false });
const rain = new THREE.Points(rainGeo, rainMat); rain.frustumCulled = false; scene.add(rain);
/* ====================================================================
Yard blocks + RTGs
==================================================================== */
const yardMesh = new THREE.InstancedMesh(boxGeo, M.container, BLOCK_ORDER.length * BLK.cap);
yardMesh.castShadow = true; yardMesh.receiveShadow = true; yardMesh.frustumCulled = false;
yardMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
const tmpM = new THREE.Matrix4(), tmpC = new THREE.Color(), tmpV = V3(0, 0, 0);
for (let i = 0; i < BLOCK_ORDER.length * BLK.cap; i++) { yardMesh.setMatrixAt(i, ZERO); yardMesh.setColorAt(i, tmpC.setHex(pick(BOX_COLORS))); }
scene.add(yardMesh);
function slotPos(b, s) {
const tier = Math.floor(s / 48), w = s % 48, col = w % BLK.cols, row = Math.floor(w / BLK.cols);
return V3(b.x + (col - 3.5) * 2.6, 0.5 + tier * 1.02, b.z + (row - 2.5) * 1.12);
}
function setYardSlot(b, s, on, color) {
const idx = b.base + s;
if (on) { yardMesh.setMatrixAt(idx, tmpM.makeTranslation(...slotPos(b, s).toArray())); if (color != null) { yardMesh.setColorAt(idx, tmpC.setHex(color)); yardMesh.instanceColor.needsUpdate = true; } }
else yardMesh.setMatrixAt(idx, ZERO);
yardMesh.instanceMatrix.needsUpdate = true;
}
const hitMat = new THREE.MeshBasicMaterial({ transparent: true, opacity: 0, depthWrite: false });
const lockedEdgeMat = new THREE.LineBasicMaterial({ color: 0x00bfff, transparent: true, opacity: 0.22 });
BLOCK_ORDER.forEach(([x, z], i) => {
const b = { i, id: COL_ID[String(x)] + (z === -26 ? '1' : '2'), x, z, lane: z + 5.3, aisle: x + 18, base: i * BLK.cap, open: false, role: 'import', count: 0, imp: 0, impT: [], exp: {}, expT: {}, expRes: {}, reserved: 0, outbound: 0, landing: 0, order: [], rtg: null };
for (let t = 0; t < BLK.tiers; t++) b.order.push(...shuffle(Array.from({ length: 48 }, (_, k) => t * 48 + k)));
const hit = new THREE.Mesh(unit, hitMat); hit.scale.set(22, 5, 8); hit.position.set(x, 2.5, z); hit.userData.pick = { type: 'block', ref: b }; scene.add(hit);
const edges = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(21.6, 4.2, 7.2)), lockedEdgeMat);
edges.position.set(x, 2.1, z); scene.add(edges); b.edges = edges;
S.blocks.push(b);
});
function makeRTG(b) {
const g = new THREE.Group();
[-1.6, 1.6].forEach(sx => [-4.6, 6.4].forEach(sz => g.add(box(0.55, 6.6, 0.55, M.rtg, sx, 3.3, sz))));
[-1.6, 1.6].forEach(sx => g.add(box(0.6, 0.8, 11.6, M.rtg, sx, 6.9, 0.9)));
[-4.6, 6.4].forEach(sz => g.add(box(3.8, 0.6, 0.6, M.rtg, 0, 6.6, sz)));
[-4.6, 6.4].forEach(sz => g.add(box(3.8, 0.7, 1.0, M.craneDark, 0, 0.4, sz)));
const trolley = box(2.6, 0.7, 1.6, M.craneDark, 0, 7.5, 0); g.add(trolley);
g.add(box(1.0, 1.0, 1.2, M.house, 1.2, 5.6, 6.4));
g.position.set(b.x - 9, 0, b.z);
g.traverse(o => { if (o.isMesh) o.userData.pick = { type: 'block', ref: b }; });
scene.add(g);
b.rtg = { group: g, trolley, tx: b.x - 9, tz: 0 };
}
function openBlock(b, fill = 0, role = 'import') {
b.open = true; b.role = role; b.edges.visible = false; makeRTG(b);
for (let k = 0; k < fill; k++) { setYardSlot(b, b.order[k], true, pick(BOX_COLORS)); b.impT.push(S.minutes - rand(30, 420)); }
b.count = fill; b.imp = fill; b.impT.sort((x, y) => x - y);
if (S.started) drawGround();
}
/* ====================================================================
STS cranes
==================================================================== */
function buildCraneMesh() {
const g = new THREE.Group();
[-4.2, 4.2].forEach(sx => [-7.2, -0.8].forEach(sz => {
g.add(box(0.85, 19, 0.85, M.crane, sx, 9.5, sz));
g.add(box(2.4, 1.1, 1.4, M.craneDark, sx, 0.55, sz));
}));
[-7.2, -0.8].forEach(sz => g.add(box(9.3, 1.0, 1.0, M.crane, 0, 18.6, sz)));
[-4.2, 4.2].forEach(sx => g.add(box(0.6, 0.6, 6.4, M.crane, sx, 11, -4)));
[-1.3, 1.3].forEach(sx => g.add(box(0.7, 1.3, 34, M.crane, sx, 20.6, 2)));
g.add(box(3.3, 0.25, 34, M.craneDark, 0, 21.35, 2));
[-1, 1].forEach(s => {
const ap = V3(s * 1.3, 31, -4);
g.add(beam(V3(s * 4.2, 19, -7.2), ap, 0.7, M.crane));
g.add(beam(V3(s * 4.2, 19, -0.8), ap, 0.7, M.crane));
g.add(beam(ap, V3(s * 1.3, 21.3, 18.6), 0.22, M.craneDark));
g.add(beam(ap, V3(s * 1.3, 21.3, -14.6), 0.22, M.craneDark));
});
g.add(box(3.4, 0.9, 0.9, M.crane, 0, 31, -4));
g.add(box(4.4, 2.8, 4.2, M.house, 0, 23.1, -11.6));
g.add(box(3.6, 1.5, 0.7, M.warn, 0, 20.6, 19.1));
const beacon = new THREE.Mesh(new THREE.SphereGeometry(0.42, 10, 8), M.red); beacon.position.set(0, 31.8, -4); g.add(beacon);
const floods = [];
[6, 13].forEach(z => { const f = box(1.8, 0.2, 0.6, M.flood, 0, 19.85, z, false); g.add(f); floods.push(f); });
const trolley = new THREE.Group();
trolley.add(box(3.2, 1.1, 2.6, M.craneDark, 0, 0, 0));
trolley.add(box(1.4, 1.2, 1.4, M.house, 0, -1.15, 1.0));
trolley.add(box(1.2, 0.45, 0.05, M.window, 0, -1.0, 1.72, false));
trolley.position.set(0, 19.7, -9); g.add(trolley);
const spreader = new THREE.Group();
spreader.add(box(2.8, 0.34, 1.15, M.warn, 0, 0, 0));
spreader.position.set(0, TRAVEL_Y, -9); g.add(spreader);
const cables = [-0.9, 0.9].map(x => { const c = box(0.07, 1, 0.07, M.craneDark, x, 0, 0, false); g.add(c); return c; });
return { g, trolley, spreader, cables, beacon, floods };
}
function addCrane(berth, animate = true) {
const parts = buildCraneMesh();
const c = { id: ++S.craneSeq, berth, ...parts, x: berth.x, home: berth.x, tz: -9, sy: TRAVEL_Y, phase: 'idle', t: 0, slot: null, carry: null, carryColor: 0, truck: null, lifts: 0, fault: false, faultUntil: 0, scaleIn: animate ? 0 : 1, waitingTruck: false };
parts.g.traverse(o => { if (o.isMesh) o.userData.pick = { type: 'crane', ref: c }; });
berth.cranes.push(c); S.cranes.push(c);
layoutCranes(berth);
c.x = c.home; parts.g.position.set(c.x, 0, 0);