-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1028 lines (971 loc) · 74.1 KB
/
Copy pathindex.html
File metadata and controls
1028 lines (971 loc) · 74.1 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>The Gift of Life — Deceased Organ Donation Pathway</title>
<style>
/* ============================================================
THE GIFT OF LIFE — Interactive Donation Pathway (v2)
Controllable character (Dr. Arvin) in a hospital corridor.
Single self-contained file. Desktop-first.
============================================================ */
:root{
--teal:#34d6c8; --teal-glow:#34d6c8aa;
--gold:#f4c95d; --gold-glow:#f4c95daa;
--green:#3ad17a; --green-glow:#3ad17aaa;
--blue:#5aa0ff; --blue-glow:#5aa0ffaa;
--red:#ff5a6e; --red-glow:#ff5a6eaa;
--amber:#ffb547; --amber-glow:#ffb547aa;
--orange:#ff9a52;
--bg0:#070b14; --bg1:#0d1426;
--ink:#eaf2ff; --ink-dim:#9fb3d1; --ink-faint:#5d7396;
--panel:#0f1830ee; --panel-line:#26365e;
--font:'Segoe UI',system-ui,-apple-system,sans-serif;
}
*{box-sizing:border-box; margin:0; padding:0}
html,body{height:100%}
body{font-family:var(--font); color:var(--ink); overflow:hidden;
background:radial-gradient(120% 120% at 50% -10%,#16223f 0%,var(--bg1) 45%,var(--bg0) 100%); user-select:none}
.screen{position:fixed; inset:0; display:none; flex-direction:column; align-items:center; justify-content:center;
padding:24px; opacity:0; transition:opacity .6s ease; z-index:10}
.screen.active{display:flex; opacity:1}
.particles{position:fixed; inset:0; pointer-events:none; overflow:hidden; z-index:0}
.particles span{position:absolute; bottom:-20px; border-radius:50%; animation:rise linear infinite}
@keyframes rise{to{transform:translateY(-110vh); opacity:0}}
/* ---------- INTRO VIDEO ---------- */
#introScreen{position:fixed;inset:0;z-index:100;background:#000;display:flex;align-items:center;justify-content:center;flex-direction:column}
#introScreen.hidden{display:none}
#introVideo{max-width:100%;max-height:100vh;width:100%;height:100%;object-fit:contain}
#introSkip{position:absolute;bottom:28px;right:28px;background:#ffffff22;border:1px solid #ffffff44;color:#fff;
font-family:var(--font);font-size:13px;font-weight:700;padding:9px 18px;border-radius:10px;cursor:pointer;letter-spacing:.5px;
transition:background .15s}
#introSkip:hover{background:#ffffff44}
/* ---------- LOADING ---------- */
.bigtitle{font-size:clamp(34px,6vw,68px); font-weight:800; letter-spacing:1px; text-align:center;
background:linear-gradient(90deg,#fff,var(--teal),var(--gold)); -webkit-background-clip:text; background-clip:text;
color:transparent; filter:drop-shadow(0 0 22px #34d6c855)}
.subtitle{color:var(--ink-dim); margin-top:10px; text-align:center; font-size:clamp(13px,1.6vw,17px)}
.org-tag{color:var(--ink-faint); margin-top:22px; font-size:12px; letter-spacing:2px; text-transform:uppercase}
.ecg-wrap{width:min(520px,86vw); height:120px; margin:18px 0}
.ecg-line{width:100%; height:100%}
.ecg-line path{fill:none; stroke:var(--teal); stroke-width:2.5; filter:drop-shadow(0 0 6px var(--teal-glow));
stroke-dasharray:1200; stroke-dashoffset:1200; animation:trace 2.6s ease forwards}
@keyframes trace{to{stroke-dashoffset:0}}
.loadbar{width:min(420px,80vw); height:7px; border-radius:99px; background:#1a2742; overflow:hidden; margin-top:26px}
.loadbar i{display:block; height:100%; width:0; border-radius:99px; background:linear-gradient(90deg,var(--teal),var(--gold));
box-shadow:0 0 14px var(--teal-glow); animation:fill 2.6s ease forwards}
@keyframes fill{to{width:100%}}
.loadnote{color:var(--ink-faint); margin-top:12px; font-size:13px; font-style:italic}
/* ---------- buttons ---------- */
.btn{cursor:pointer; border:none; font-family:var(--font); font-weight:700; padding:14px 30px; border-radius:14px;
font-size:16px; color:#06121a; background:linear-gradient(135deg,var(--teal),#7defff);
box-shadow:0 6px 26px var(--teal-glow),inset 0 1px 0 #fff8; transition:transform .15s,box-shadow .15s; letter-spacing:.4px}
.btn:hover{transform:translateY(-2px) scale(1.02); box-shadow:0 10px 34px var(--teal-glow)}
.btn:active{transform:translateY(0) scale(.99)}
.btn.gold{background:linear-gradient(135deg,var(--gold),#ffe9a8); box-shadow:0 6px 26px var(--gold-glow),inset 0 1px 0 #fff8}
.btn.ghost{background:#16223f; color:var(--ink); box-shadow:inset 0 0 0 1px var(--panel-line)}
.btn.ghost:hover{background:#1c2c50}
.btn:disabled{opacity:.4; cursor:not-allowed; transform:none}
.btn.appear{opacity:0; animation:pop .5s ease forwards}
@keyframes pop{from{opacity:0; transform:translateY(10px) scale(.96)}to{opacity:1; transform:none}}
/* ---------- LOGIN ---------- */
.card{background:var(--panel); border:1px solid var(--panel-line); border-radius:22px; padding:36px 40px;
max-width:560px; width:100%; backdrop-filter:blur(8px); box-shadow:0 24px 70px #0009, inset 0 1px 0 #ffffff10}
.card h2{font-size:clamp(22px,3.5vw,32px); margin-bottom:8px}
.card p.lead{color:var(--ink-dim); margin-bottom:24px; line-height:1.55}
.login-row{display:flex; gap:22px; align-items:center}
.login-portrait{width:120px; flex-shrink:0; filter:drop-shadow(0 10px 18px #000a)}
.field{display:flex; flex-direction:column; gap:8px; margin-bottom:18px}
.field label{font-size:13px; color:var(--ink-dim); letter-spacing:1px; text-transform:uppercase}
.field input{padding:15px 18px; border-radius:13px; border:1px solid var(--panel-line); background:#0a1326; color:var(--ink);
font-size:18px; font-family:var(--font); outline:none; transition:border .2s,box-shadow .2s}
.field input:focus{border-color:var(--teal); box-shadow:0 0 0 3px #34d6c833}
.role-note{font-size:12.5px; color:var(--ink-faint); margin:2px 0 20px; line-height:1.5}
.guide-name{color:var(--green); font-weight:800; font-size:13px; letter-spacing:1px; text-align:center; margin-top:6px}
.guide-role{color:var(--ink-faint); font-size:11px; text-align:center}
/* ---------- HUD ---------- */
#hud{position:fixed; top:0; left:0; right:0; height:56px; display:none; align-items:center; justify-content:space-between;
padding:0 22px; z-index:40; background:linear-gradient(#0b1326ee,#0b132600); backdrop-filter:blur(4px)}
#hud.show{display:flex}
.hud-player{display:flex; align-items:center; gap:10px; font-weight:700}
.hud-badge{width:30px; height:30px; border-radius:50%; display:grid; place-items:center;
background:linear-gradient(135deg,var(--teal),#7defff); color:#06121a; font-size:14px; font-weight:800; box-shadow:0 0 12px var(--teal-glow)}
.pips{display:flex; gap:7px}
.pip{width:24px; height:6px; border-radius:99px; background:#23314f; transition:background .4s,box-shadow .4s}
.pip.done{background:var(--green); box-shadow:0 0 8px var(--green-glow)}
.pip.cur{background:var(--gold); box-shadow:0 0 10px var(--gold-glow)}
.hud-score{display:flex; align-items:center; gap:8px; font-weight:800; font-size:18px}
.hud-score .lbl{font-size:11px; color:var(--ink-faint); font-weight:600; letter-spacing:1px}
#soundBtn{cursor:pointer; border:1px solid var(--panel-line); background:#0f1830cc; color:var(--ink);
border-radius:9px; width:34px; height:34px; font-size:16px; margin-left:6px; transition:background .15s}
#soundBtn:hover{background:#1c2c50}
#soundBtn.on{background:var(--teal); color:#06121a; border-color:var(--teal)}
#scoreVal{color:var(--gold); min-width:42px; text-align:right; transition:color .3s}
#scoreVal.flash{animation:scoreflash .6s ease}
@keyframes scoreflash{0%{color:var(--red); transform:scale(1.3)}100%{color:var(--gold); transform:scale(1)}}
/* ============================================================
WORLD — hospital corridor
============================================================ */
#world{position:fixed; inset:0; display:none; overflow:hidden; z-index:5;
background:linear-gradient(#aebfd6,#7e90ac)}
#world.show{display:block}
.corridor{position:absolute; top:0; left:0; height:100%; will-change:transform}
/* ceiling */
.ceiling{position:absolute; top:0; left:0; height:16%; width:100%;
background:linear-gradient(#1c2740,#2d3c5e)}
.lightpanel{position:absolute; top:30%; width:120px; height:24px; border-radius:4px;
background:linear-gradient(#fffbe8,#ffe9a8); box-shadow:0 8px 40px 6px #ffeaa055, 0 0 0 3px #44506e}
/* wall */
.wall{position:absolute; top:16%; left:0; height:54%; width:100%;
background:linear-gradient(#eaf0f8,#cdd8e8);
border-bottom:6px solid #9fb0c8}
.wallseam{position:absolute; top:16%; width:2px; height:54%; background:#00000010}
.baseboard{position:absolute; top:68%; left:0; height:4%; width:100%; background:#8497b2}
/* doors decoration */
.door{position:absolute; bottom:30%; width:78px; height:150px; border-radius:8px 8px 0 0;
background:linear-gradient(#b9c6da,#9aa9c2); border:3px solid #8496b0; box-shadow:inset 0 0 0 4px #ffffff22}
.door::after{content:""; position:absolute; right:10px; top:50%; width:7px; height:7px; border-radius:50%; background:#5c6e8c}
.doorsign{position:absolute; bottom:calc(30% + 152px); transform:translateX(-50%); font-size:10px; letter-spacing:2px;
color:#52617c; background:#dfe7f2; padding:3px 8px; border-radius:5px; border:1px solid #aab8cd}
/* floor */
.floor{position:absolute; top:72%; left:0; height:28%; width:100%;
background:linear-gradient(#c4cfe0,#9aa7bd)}
.floortiles{position:absolute; top:72%; left:0; height:28%; width:100%; opacity:.5;
background:repeating-linear-gradient(90deg,transparent 0 78px,#6f7f99 78px 80px),
repeating-linear-gradient(#ffffff22 0 1px,transparent 1px 26px)}
.floorshine{position:absolute; top:72%; left:0; height:28%; width:100%;
background:linear-gradient(90deg,#ffffff00,#ffffff22,#ffffff00); mix-blend-mode:overlay}
/* STATIONS */
.station{position:absolute; bottom:28%; transform:translateX(-50%); width:150px; text-align:center; z-index:6}
.station .arch{height:188px; border-radius:14px 14px 0 0; border:4px solid var(--gold);
background:linear-gradient(#1b2742cc,#13203acc); position:relative; overflow:hidden;
box-shadow:0 0 0 6px #f4c95d22, 0 0 40px var(--gold-glow); transition:filter .3s,opacity .3s}
.station .archicon{font-size:54px; position:absolute; left:50%; top:54%; transform:translate(-50%,-50%); filter:drop-shadow(0 4px 8px #000a)}
.station .glowfloor{position:absolute; bottom:-14px; left:50%; transform:translateX(-50%); width:120px; height:18px;
border-radius:50%; background:var(--gold); filter:blur(8px); opacity:.5}
.station .sign{position:absolute; top:-58px; left:50%; transform:translateX(-50%); white-space:nowrap;
background:#0f1830ee; border:1px solid var(--gold); border-radius:10px; padding:6px 14px; box-shadow:0 8px 24px #0008}
.station .sign b{display:block; color:var(--gold); font-size:14px}
.station .sign small{color:var(--ink-dim); font-size:11px}
.station.locked .arch{border-color:#54627e; box-shadow:none; filter:grayscale(1) brightness(.6)}
.station.locked .sign{border-color:#54627e; opacity:.7}
.station.locked .sign b{color:#7b8aa6}
.station.locked .glowfloor{opacity:0}
.station.active .arch{animation:archpulse 1.8s ease-in-out infinite}
@keyframes archpulse{0%,100%{box-shadow:0 0 0 6px #f4c95d22,0 0 40px var(--gold-glow)}50%{box-shadow:0 0 0 12px #f4c95d18,0 0 60px var(--gold-glow)}}
.station.done .arch{border-color:var(--green); box-shadow:0 0 0 6px #3ad17a22,0 0 36px var(--green-glow)}
.station.done .sign{border-color:var(--green)} .station.done .sign b{color:var(--green)}
.station.done .glowfloor{background:var(--green)}
.station .check{position:absolute; top:8px; right:8px; font-size:22px; display:none}
.station.done .check{display:block}
/* BARRIERS */
.barrier{position:absolute; bottom:28%; transform:translateX(-50%); width:26px; height:300px; z-index:6;
background:repeating-linear-gradient(45deg,#f4c95d 0 14px,#1b1305 14px 28px);
border-radius:5px; box-shadow:0 0 26px #f4c95d66; display:flex; align-items:center; justify-content:center;
transition:opacity .5s,transform .5s}
.barrier .lock{position:absolute; top:46%; font-size:22px; background:#0f1830; border-radius:8px; padding:4px}
.barrier.open{opacity:0; transform:translateX(-50%) translateY(20px) scaleY(.6); pointer-events:none}
/* HERO (Dr. Arvin) */
#hero{position:absolute; bottom:26%; width:96px; z-index:7; transition:none; filter:drop-shadow(0 10px 10px #0006)}
#hero svg{width:100%; height:auto; display:block}
#hero.left svg{transform:scaleX(-1)}
#hero.shake{animation:heroshake .45s ease}
@keyframes heroshake{0%,100%{transform:translateX(0)}20%{transform:translateX(-7px)}40%{transform:translateX(7px)}60%{transform:translateX(-5px)}80%{transform:translateX(5px)}}
.shadowblob{position:absolute; bottom:25%; width:80px; height:16px; border-radius:50%; background:#00000033; filter:blur(5px); z-index:6; transform:translateX(-50%)}
/* limbs pivots + walk cycle */
#hero .leg,#hero .arm{transform-origin:0 0}
#hero #bob{transform-box:fill-box; transform-origin:50% 100%}
#hero.walking .leg-front{animation:lb .42s linear infinite}
#hero.walking .leg-back{animation:lf .42s linear infinite}
#hero.walking .arm-front{animation:ab .42s linear infinite}
#hero.walking .arm-back{animation:af .42s linear infinite}
#hero.walking #bob{animation:bob .21s linear infinite}
@keyframes lf{0%,100%{transform:rotate(20deg)}50%{transform:rotate(-20deg)}}
@keyframes lb{0%,100%{transform:rotate(-20deg)}50%{transform:rotate(20deg)}}
@keyframes af{0%,100%{transform:rotate(-24deg)}50%{transform:rotate(24deg)}}
@keyframes ab{0%,100%{transform:rotate(24deg)}50%{transform:rotate(-24deg)}}
@keyframes bob{0%,100%{transform:translateY(0)}50%{transform:translateY(-3px)}}
#hero:not(.walking) #bob{animation:breathe 3.2s ease-in-out infinite}
@keyframes breathe{0%,100%{transform:translateY(0)}50%{transform:translateY(-1.5px)}}
/* interaction prompt */
#prompt{position:fixed; left:50%; top:34%; transform:translateX(-50%); z-index:30; display:none;
background:#0f1830ee; border:1px solid var(--gold); border-radius:12px; padding:10px 18px; text-align:center;
box-shadow:0 10px 30px #0009; animation:floaty 1.6s ease-in-out infinite}
#prompt.show{display:block}
#prompt .key{display:inline-block; background:var(--gold); color:#06121a; font-weight:900; border-radius:6px; padding:2px 9px; margin:0 2px}
#prompt small{display:block; color:var(--ink-dim); font-size:12px; margin-top:3px}
@keyframes floaty{0%,100%{transform:translateX(-50%) translateY(0)}50%{transform:translateX(-50%) translateY(-6px)}}
/* controls + hint */
#controls{position:fixed; bottom:18px; right:22px; z-index:35; display:none; gap:10px}
#controls.show{display:flex}
#controls button{width:60px; height:60px; border-radius:16px; border:1px solid var(--panel-line); background:#0f1830cc;
color:var(--ink); font-size:22px; cursor:pointer; backdrop-filter:blur(4px); touch-action:none}
#controls button:active{background:var(--teal); color:#06121a}
#hint{position:fixed; bottom:24px; left:22px; z-index:35; display:none; color:#23324d; font-size:13px; font-weight:600;
background:#ffffffbb; padding:8px 14px; border-radius:10px}
#hint.show{display:block}
/* toast */
#toast{position:fixed; top:74px; left:50%; transform:translateX(-50%) translateY(-20px); z-index:38; opacity:0;
background:#0f1830ee; border:1px solid var(--green); color:var(--ink); padding:12px 22px; border-radius:12px;
font-weight:600; box-shadow:0 10px 30px #0009; transition:opacity .3s,transform .3s; pointer-events:none; max-width:90vw; text-align:center}
#toast.show{opacity:1; transform:translateX(-50%) translateY(0)}
/* ============================================================
DECISION OVERLAY
============================================================ */
#decisionOverlay{position:fixed; inset:0; z-index:45; display:none; align-items:flex-start; justify-content:center;
padding:74px 20px 30px; overflow:auto; background:#04070ecc; backdrop-filter:blur(3px)}
#decisionOverlay.show{display:flex}
#guide{position:fixed; left:24px; bottom:24px; z-index:46; width:140px; text-align:center; display:none}
#guide.show{display:block}
#guide svg{width:96px; filter:drop-shadow(0 8px 14px #000a)}
#guide.react svg{animation:heroshake .45s ease}
#guide .gname{color:var(--green); font-weight:800; font-size:12px; letter-spacing:1px}
#guide .grole{color:var(--ink-faint); font-size:10px}
@media(max-width:820px){#guide{display:none!important}}
.scene{width:min(820px,94vw); animation:sceneIn .5s ease}
@keyframes sceneIn{from{opacity:0; transform:translateY(16px)}to{opacity:1; transform:none}}
.phase-banner{display:inline-block; font-size:13px; font-weight:800; letter-spacing:2px; text-transform:uppercase;
padding:7px 16px; border-radius:99px; margin-bottom:14px; background:#16223f; color:var(--gold); box-shadow:inset 0 0 0 1px var(--panel-line)}
.scene-art{height:140px; border-radius:18px; margin-bottom:18px; position:relative; overflow:hidden; border:1px solid var(--panel-line);
display:grid; place-items:center; font-size:58px; text-shadow:0 6px 18px #000a}
.art-icu{background:radial-gradient(120% 140% at 50% 130%,#3a5a9c,#16233f 60%,#0c1426)}
.art-neuro{background:radial-gradient(120% 140% at 50% 130%,#3a6f9c,#16293f 60%,#0c1426)}
.art-family{background:radial-gradient(120% 140% at 50% 130%,#9c7a3a,#3f3216 60%,#1a1408)}
.art-lanes{background:radial-gradient(120% 140% at 50% 130%,#2c6f5e,#16332b 60%,#0c1a16)}
.art-or{background:radial-gradient(120% 140% at 50% 130%,#6f9cc9,#28405f 60%,#0c1426)}
.art-recipient{background:radial-gradient(120% 140% at 50% 130%,#9c3a6f,#3f1632 60%,#1a0814)}
.art-end{background:radial-gradient(120% 140% at 50% 130%,#6b6b6b,#2a2a2a 60%,#141414)}
.situation{background:var(--panel); border:1px solid var(--panel-line); border-left:4px solid var(--teal); border-radius:12px;
padding:18px 20px; line-height:1.6; color:#dce8fb; margin-bottom:18px; font-size:16px}
.signpost{display:flex; gap:12px; align-items:flex-start; background:#1a1305; border:1px solid #4a3a12; border-radius:12px;
padding:16px 18px; margin-bottom:18px}
.signpost .ico{font-size:24px}
.signpost .q{font-weight:800; color:var(--amber); font-size:17px; line-height:1.4}
.signpost .q small{display:block; color:#caa45f; font-weight:500; font-size:13px; margin-top:6px; line-height:1.5}
.choices{display:flex; flex-direction:column; gap:12px; margin-bottom:6px}
.choice{cursor:pointer; text-align:left; padding:16px 18px; border-radius:13px; font-size:16px; font-weight:600;
border:1px solid var(--panel-line); background:#101a32; color:var(--ink); display:flex; align-items:center; gap:12px;
transition:transform .12s,box-shadow .12s,background .12s; font-family:var(--font)}
.choice:hover{transform:translateX(4px); background:#16233f; box-shadow:0 6px 20px #0006}
.choice .dot{font-size:20px}
.choice.green:hover{box-shadow:0 6px 22px var(--green-glow); border-color:var(--green)}
.choice.red:hover{box-shadow:0 6px 22px var(--red-glow); border-color:var(--red)}
.choice.blue:hover{box-shadow:0 6px 22px var(--blue-glow); border-color:var(--blue)}
.aux{display:flex; gap:10px; margin-top:8px; flex-wrap:wrap}
.aux button{cursor:pointer; font-family:var(--font); font-size:13px; font-weight:700; padding:9px 16px; border-radius:10px;
border:1px solid var(--panel-line); background:#0d1730; color:var(--ink-dim); transition:background .15s,color .15s}
.aux button:hover{background:#16233f; color:var(--ink)}
.gate{background:var(--panel); border:1px solid var(--panel-line); border-radius:14px; padding:18px; margin-bottom:16px}
.gate h4{margin-bottom:12px; color:var(--amber); font-size:15px}
.checkitem{display:flex; align-items:center; gap:12px; padding:11px 12px; border-radius:10px; cursor:pointer;
border:1px solid #1d2c4a; margin-bottom:8px; transition:background .15s,border .15s; font-size:14.5px}
.checkitem:hover{background:#13203c}
.checkitem .box{width:22px; height:22px; border-radius:6px; border:2px solid #3a4f78; display:grid; place-items:center;
flex-shrink:0; transition:all .2s; font-size:14px; color:#06121a; font-weight:900}
.checkitem.on .box{background:var(--green); border-color:var(--green); box-shadow:0 0 10px var(--green-glow)}
.checkitem.on{border-color:#2a4a3a; background:#0e2018}
.gate-progress{height:6px; border-radius:99px; background:#1a2742; overflow:hidden; margin-top:6px}
.gate-progress i{display:block; height:100%; width:0; background:linear-gradient(90deg,var(--green),var(--teal));
box-shadow:0 0 10px var(--green-glow); transition:width .3s}
.lanes{display:grid; grid-template-columns:1fr 1fr 1fr; gap:12px; margin-bottom:16px}
.lane{border-radius:13px; padding:14px; border:1px solid var(--panel-line); background:#0e1830}
.lane.A{border-top:3px solid var(--blue)} .lane.B{border-top:3px solid var(--green)} .lane.C{border-top:3px solid var(--orange)}
.lane h5{font-size:13px; letter-spacing:1px; text-transform:uppercase; margin-bottom:8px}
.lane.A h5{color:var(--blue)} .lane.B h5{color:var(--green)} .lane.C h5{color:var(--orange)}
.lane p{font-size:13px; color:var(--ink-dim); line-height:1.5}
.lane ul{list-style:none; margin-top:8px; font-size:12.5px; color:var(--ink-dim)} .lane li{padding:3px 0}
@media(max-width:760px){.lanes{grid-template-columns:1fr}}
/* MODAL */
.modal{position:fixed; inset:0; z-index:60; display:none; align-items:center; justify-content:center; padding:24px;
background:#03060cdd; backdrop-filter:blur(3px)}
.modal.show{display:flex; animation:fadein .25s ease}
@keyframes fadein{from{opacity:0}to{opacity:1}}
.modal-box{background:var(--panel); border:1px solid var(--panel-line); border-radius:18px; padding:26px 28px;
max-width:620px; width:100%; max-height:82vh; overflow:auto; box-shadow:0 30px 90px #000c; animation:pop .35s ease}
.modal-box h3{margin-bottom:14px; font-size:20px; display:flex; align-items:center; gap:10px}
.modal-box.boundary{border-color:var(--red); box-shadow:0 0 50px var(--red-glow),0 30px 90px #000c}
.modal-box.boundary h3{color:var(--red)}
.dtable{width:100%; border-collapse:collapse; font-size:14px; margin:8px 0}
.dtable th,.dtable td{text-align:left; padding:9px 12px; border-bottom:1px solid #1d2c4a}
.dtable th{color:var(--teal); font-size:12px; text-transform:uppercase; letter-spacing:1px}
.dtable td:last-child{color:var(--ink-dim)}
.modal-box p{line-height:1.65; color:#dce8fb; margin-bottom:12px}
.modal-box ul{margin:8px 0 14px 20px; line-height:1.7; color:#dce8fb}
.modal-close{margin-top:14px}
.deadend .scene-art{font-size:50px}
/* ---------- PHASE TIMER ---------- */
#phaseTimer{position:fixed; top:62px; left:50%; transform:translateX(-50%); z-index:47; display:none;
align-items:center; gap:10px; background:#0f1830ee; border:1px solid var(--panel-line); border-radius:14px;
padding:8px 18px; box-shadow:0 10px 30px #0009; font-variant-numeric:tabular-nums}
#phaseTimer.show{display:flex}
#phaseTimer .tlabel{font-size:11px; color:var(--ink-faint); letter-spacing:1px; text-transform:uppercase}
#phaseTimer .tclock{font-size:24px; font-weight:900; color:var(--teal); min-width:62px; text-align:center}
#phaseTimer .tbar{width:120px; height:6px; border-radius:99px; background:#1a2742; overflow:hidden}
#phaseTimer .tbar i{display:block; height:100%; width:100%; background:linear-gradient(90deg,var(--green),var(--teal));
transition:width 1s linear, background .4s}
#phaseTimer.warn .tclock{color:var(--red); animation:tpulse .9s ease-in-out infinite}
#phaseTimer.warn .tbar i{background:var(--red); box-shadow:0 0 12px var(--red-glow)}
#phaseTimer.paused{opacity:.55; filter:grayscale(.4)}
#phaseTimer.paused .tclock::before{content:"⏸ "; font-size:16px}
@keyframes tpulse{0%,100%{transform:scale(1)}50%{transform:scale(1.12)}}
/* red blink warning vignette (last minute) */
#redAlert{position:fixed; inset:0; z-index:55; pointer-events:none; opacity:0;
box-shadow:inset 0 0 160px 40px var(--red); background:radial-gradient(120% 120% at 50% 50%,transparent 55%,#ff000022)}
#redAlert.on{animation:redblink 1s ease-in-out infinite}
@keyframes redblink{0%,100%{opacity:0}50%{opacity:.85}}
/* ---------- EXPIRED (game over) ---------- */
#expired{background:radial-gradient(120% 120% at 50% 40%,#3a0a12 0%,#1a0408 60%,#080203 100%); z-index:70}
#expired.shake{animation:bigshake .6s ease}
@keyframes bigshake{0%,100%{transform:translate(0,0)}15%{transform:translate(-10px,4px)}30%{transform:translate(9px,-5px)}
45%{transform:translate(-7px,3px)}60%{transform:translate(6px,-3px)}80%{transform:translate(-3px,2px)}}
.exp-flatline{width:min(620px,90vw); height:120px; margin:10px 0 6px}
.exp-flatline path{fill:none; stroke:var(--red); stroke-width:3; filter:drop-shadow(0 0 8px var(--red-glow));
stroke-dasharray:1400; stroke-dashoffset:1400; animation:flatdraw 1.8s ease forwards}
@keyframes flatdraw{to{stroke-dashoffset:0}}
.exp-title{font-size:clamp(32px,6vw,64px); font-weight:900; letter-spacing:2px; color:#fff; text-align:center;
text-shadow:0 0 30px var(--red-glow); animation:exppulse 1.4s ease-in-out infinite}
@keyframes exppulse{0%,100%{opacity:1; text-shadow:0 0 30px var(--red-glow)}50%{opacity:.78; text-shadow:0 0 56px var(--red)}}
.exp-sub{color:#ffb9c2; margin-top:14px; text-align:center; max-width:560px; line-height:1.6; font-size:15px}
.exp-reason{color:#ff8d9b; margin-top:8px; font-weight:700; font-size:14px}
.exp-actions{display:flex; gap:12px; margin-top:30px; flex-wrap:wrap; justify-content:center}
.btn.red{background:linear-gradient(135deg,var(--red),#ff97a3); color:#1a0205; box-shadow:0 6px 26px var(--red-glow),inset 0 1px 0 #fff8}
/* WIN */
#win{overflow:auto; justify-content:flex-start; padding-top:40px}
.win-wrap{width:min(960px,95vw)}
.win-hero{text-align:center; margin-bottom:24px}
.win-hero .trophy{font-size:60px; filter:drop-shadow(0 0 24px var(--gold-glow)); animation:wfloat 3s ease-in-out infinite}
@keyframes wfloat{0%,100%{transform:translateY(0)}50%{transform:translateY(-10px)}}
.win-hero h1{font-size:clamp(26px,4.5vw,44px); font-weight:800; margin:10px 0 4px;
background:linear-gradient(90deg,var(--gold),#fff,var(--teal)); -webkit-background-clip:text; background-clip:text; color:transparent}
.win-hero p{color:var(--ink-dim)}
.win-grid{display:grid; grid-template-columns:1.1fr 1fr; gap:18px; margin-bottom:20px}
@media(max-width:780px){.win-grid{grid-template-columns:1fr}}
.win-panel{background:var(--panel); border:1px solid var(--panel-line); border-radius:18px; padding:22px}
.win-panel h3{font-size:16px; color:var(--teal); letter-spacing:1px; text-transform:uppercase; margin-bottom:14px}
.recap-item{display:flex; align-items:center; gap:10px; padding:8px 0; font-size:14.5px; border-bottom:1px solid #16233f}
.recap-item:last-child{border-bottom:none} .recap-item .ok{color:var(--green)}
.scorebig{text-align:center; padding:8px 0 16px}
.scorebig .num{font-size:64px; font-weight:900; line-height:1; background:linear-gradient(135deg,var(--gold),#fff);
-webkit-background-clip:text; background-clip:text; color:transparent}
.scorebig .grade{font-size:20px; font-weight:800; margin-top:6px}
.deduct{display:flex; justify-content:space-between; gap:10px; padding:8px 0; font-size:13.5px; border-bottom:1px solid #16233f; color:var(--ink-dim)}
.deduct .pts{color:var(--red); font-weight:700; white-space:nowrap}
.deduct.none{color:var(--green); justify-content:center; text-align:center}
.impact{text-align:center}
.impact .organs{font-size:36px; letter-spacing:6px; margin-bottom:10px}
.impact .big{font-size:22px; font-weight:800; color:var(--gold)}
.impact p{color:var(--ink-dim); margin-top:8px; line-height:1.6}
.win-actions{display:flex; gap:12px; flex-wrap:wrap; justify-content:center; margin-top:6px}
.tnote{font-size:12.5px; color:var(--ink-faint); font-style:italic; margin-top:10px; line-height:1.5}
</style>
</head>
<body>
<div class="particles" id="particles"></div>
<!-- INTRO VIDEO -->
<div id="introScreen">
<video id="introVideo" autoplay muted playsinline>
<source src="grok-cee0ff77-4eb8-4f3e-acd5-75c98c32fe83.mp4" type="video/mp4">
</video>
<button id="introSkip">Skip ▶</button>
</div>
<!-- HUD -->
<div id="hud">
<div class="hud-player"><span class="hud-badge" id="hudBadge">?</span><span id="hudName">Player</span></div>
<div class="pips" id="pips"></div>
<div class="hud-score"><span class="lbl">SCORE</span><span id="scoreVal">100</span>
<button id="soundBtn" title="Sound off — click to enable">🔇</button></div>
</div>
<!-- LOADING -->
<section class="screen active" id="loading">
<div class="bigtitle">THE GIFT OF LIFE</div>
<div class="subtitle">Deceased Organ Donation Clinical Pathway<br>An Interactive Training Walkthrough</div>
<div class="ecg-wrap"><svg class="ecg-line" viewBox="0 0 600 120" preserveAspectRatio="none">
<path d="M0,60 L140,60 L160,60 L175,30 L190,90 L205,10 L220,100 L235,60 L300,60 L320,60 L335,40 L350,80 L365,60 L600,60"/></svg></div>
<div class="loadbar"><i></i></div>
<div class="loadnote">Loading donor journey… 1 donor can save up to 8 lives.</div>
<div class="org-tag">SHARE · Organ Transplant Services Unit · SPMC</div>
<div style="margin-top:30px"><button class="btn gold appear" id="beginBtn" style="animation-delay:2.6s">▶ Begin the Journey</button></div>
</section>
<!-- LOGIN -->
<section class="screen" id="login">
<div class="card">
<h2>Meet your guide</h2>
<p class="lead">This is <strong>Dr. Arvin</strong>, your SHARE coordinator. You'll walk him down the hospital corridor and decide what happens at each station. Enter your name to begin.</p>
<div class="login-row">
<div>
<svg class="login-portrait" id="loginPortrait" viewBox="0 0 120 210"></svg>
<div class="guide-name">DR. ARVIN</div>
<div class="guide-role">SHARE Coordinator</div>
</div>
<div style="flex:1">
<div class="field">
<label for="nameInput">Your name</label>
<input id="nameInput" type="text" placeholder="e.g., Al John Manalaysay, RN" maxlength="40" autocomplete="off" />
</div>
<p class="role-note">You begin with <strong>100 points</strong>. Choices that break clinical safety or ethical boundaries cost points — shown in full on the final screen. This is a training walkthrough, not a patient record.</p>
<button class="btn gold" id="startBtn" disabled>Enter the Corridor →</button>
</div>
</div>
</div>
</section>
<!-- WORLD -->
<div id="world">
<div class="corridor" id="corridor"></div>
</div>
<div id="prompt"></div>
<div id="controls">
<button id="btnLeft" aria-label="walk left">◀</button>
<button id="btnAct" aria-label="interact">E</button>
<button id="btnRight" aria-label="walk right">▶</button>
</div>
<div id="hint">← → or A D to walk · E / Space to enter a station</div>
<div id="toast"></div>
<!-- PHASE TIMER + RED ALERT -->
<div id="phaseTimer"><span class="tlabel">Phase</span><span class="tclock" id="tclock">3:00</span><span class="tbar"><i id="tbarfill"></i></span></div>
<div id="redAlert"></div>
<!-- DECISION OVERLAY -->
<div id="decisionOverlay"><div class="scene" id="scene"></div></div>
<div id="guide"><svg id="guideHero" viewBox="0 0 120 210"></svg><div class="gname">DR. ARVIN</div><div class="grole">guiding you</div></div>
<!-- WIN -->
<section class="screen" id="win">
<div class="win-wrap">
<div class="win-hero"><div class="trophy">🏆</div><h1>The Gift of Life Was Given</h1><p id="winName">Pathway complete.</p></div>
<div class="win-grid">
<div class="win-panel"><h3>Your Journey</h3><div id="recapList"></div><p class="tnote" id="timeNote"></p></div>
<div class="win-panel"><h3>Your Score</h3>
<div class="scorebig"><div class="num" id="finalScore">100</div><div class="grade" id="finalGrade">Flawless</div></div>
<div id="deductList"></div></div>
</div>
<div class="win-panel impact" style="margin-bottom:20px">
<div class="organs" id="impactOrgans">🫀 🫁 🫘 🫘</div>
<div class="big">1 donor → up to 8 lives changed.</div>
<p>Because you maintained the ethical wall, worked in parallel, and retrieved in time — recipients who were waiting in hope received a second chance today.</p>
</div>
<div class="win-actions">
<button class="btn gold" onclick="restart()">🔁 Play Again</button>
<button class="btn ghost" onclick="exploreBranches()">🛣️ Explore Other Paths</button>
<button class="btn ghost" onclick="downloadSummary()">📄 Download My Summary</button>
</div>
<p class="tnote" style="text-align:center; margin-top:18px">The deepest learning lives in the dead-ends. Replay and try a “No” branch — see what happens when consent isn’t given, or brain death can’t be confirmed.</p>
</div>
</section>
<!-- EXPIRED (game over) -->
<section class="screen" id="expired">
<div class="exp-title">PATIENT HAS EXPIRED</div>
<svg class="exp-flatline" viewBox="0 0 600 120" preserveAspectRatio="none"><path d="M0,60 L600,60"/></svg>
<div class="exp-sub" id="expSub">The donor deteriorated into cardiac arrest before this phase was completed. In deceased donation, time is everything — organ viability is lost when decisions stall.</div>
<div class="exp-reason" id="expReason"></div>
<div class="exp-actions">
<button class="btn red" onclick="restart()">🔁 Start Over</button>
<button class="btn ghost" onclick="downloadSummary()">📄 Download My Summary</button>
</div>
</section>
<!-- MODAL -->
<div class="modal" id="modal"><div class="modal-box" id="modalBox"></div></div>
<script>
/* ============================================================
DR. ARVIN — SVG character (built once, reused)
============================================================ */
const HERO_SVG=`
<g id="bob">
<g transform="translate(40,70)"><g class="arm arm-back"><rect x="-7" y="0" width="14" height="40" rx="6" fill="#dfe6f0"/><rect x="-6" y="34" width="12" height="13" rx="4" fill="#c98f54"/></g></g>
<g transform="translate(58,126)"><g class="leg leg-back"><rect x="-7" y="0" width="14" height="50" rx="3" fill="#1f3a6b"/><rect x="-9" y="46" width="19" height="13" rx="3" fill="#e6ecf4"/></g></g>
<g transform="translate(66,126)"><g class="leg leg-front"><rect x="-7" y="0" width="14" height="50" rx="3" fill="#27468a"/><rect x="-9" y="46" width="19" height="13" rx="3" fill="#f6f9fc"/></g></g>
<g class="torso" transform="translate(120,0) scale(-1,1)">
<rect x="35" y="64" width="50" height="68" rx="9" fill="#f3f6fa"/>
<path d="M50 64 L60 86 L70 64 Z" fill="#27468a"/>
<path d="M48 64 L60 92 L48 100 Z" fill="#e3e9f1"/>
<path d="M72 64 L60 92 L72 100 Z" fill="#e3e9f1"/>
<g transform="translate(46,94)"><rect x="-6" y="-2.5" width="12" height="5" rx="1" fill="#3ad17a"/><rect x="-2.5" y="-6" width="5" height="12" rx="1" fill="#3ad17a"/></g>
<rect x="66" y="98" width="9" height="12" rx="2" fill="#bfe8ff" stroke="#2a3a5a"/>
<path d="M52 62 C49 84 56 96 60 104" fill="none" stroke="#2b3340" stroke-width="3"/>
<path d="M68 62 C71 82 65 96 61 104" fill="none" stroke="#2b3340" stroke-width="3"/>
<circle cx="60.5" cy="107" r="5" fill="#3b4452"/>
</g>
<g transform="translate(80,70)"><g class="arm arm-front"><rect x="-7" y="0" width="14" height="40" rx="6" fill="#f6f9fc"/><rect x="-6" y="34" width="12" height="13" rx="4" fill="#e0a868"/></g></g>
<g class="head">
<rect x="44" y="20" width="32" height="34" rx="10" fill="#e8b07e"/>
<path d="M41 31 Q43 11 60 11 Q77 11 79 31 Q73 21 67 26 Q63 14 58 26 Q52 17 50 28 Q46 23 41 31 Z" fill="#15161a"/>
<rect x="46" y="32" width="12" height="9" rx="2.5" fill="#cdeffb88" stroke="#3a2e22" stroke-width="2"/>
<rect x="62" y="32" width="12" height="9" rx="2.5" fill="#cdeffb88" stroke="#3a2e22" stroke-width="2"/>
<line x1="58" y1="36" x2="62" y2="36" stroke="#3a2e22" stroke-width="2"/>
<path d="M53 47 Q60 52 67 47" fill="none" stroke="#7a4a2a" stroke-width="2" stroke-linecap="round"/>
</g>
</g>`;
/* ============================================================
STATE
============================================================ */
const S = { name:"", score:100, deductions:[], violations:0, phaseIdx:0,
timeGoals:0, timeGoalsMax:7, exploredBranch:false, done:new Set(), timeSpare:0 };
const PHASES=["Phase 1","Phase 2","Phase 3","Phase 4","Phase 5","Phase 6"];
/* ============================================================
CLINICAL DATA (📋 Details / ℹ️ Why)
============================================================ */
const DETAILS={
trigger:{title:"📋 Potential Donor Trigger Criteria",html:`<p>Recognize a <em>potential</em> donor early — broader than "GCS 7 alone":</p>
<ul><li>Mechanically ventilated patient</li><li>Devastating brain injury</li><li>GCS ≤ 7 <em>or</em> absent brainstem reflexes</li>
<li>Poor neurologic prognosis</li><li>Planned withdrawal/limitation of life-sustaining treatment</li></ul>
<p>Early recognition does <strong>not</strong> mean donation is being pursued yet.</p>`},
bdchecklist:{title:"📋 Brain Death Determination Checklist",html:`<table class="dtable"><tr><th>Requirement</th><th>Before testing</th></tr>
<tr><td>Known cause of irreversible catastrophic brain injury</td><td>Required</td></tr><tr><td>Coma established</td><td>Required</td></tr>
<tr><td>Confounders excluded (hypothermia, sedatives, paralytics, metabolic, shock)</td><td>Required</td></tr>
<tr><td>Adequate blood pressure & oxygenation</td><td>Required</td></tr><tr><td>Brainstem reflex examination completed</td><td>Required</td></tr>
<tr><td>Apnea test performed (if safe)</td><td>Required</td></tr><tr><td>Ancillary test (if apnea cannot be completed)</td><td>If needed</td></tr>
<tr><td>Time of death documented</td><td>Required</td></tr><tr><td>Family informed by treating physician</td><td>Required</td></tr></table>`},
bundle:{title:"📋 Donor Management Bundle — Targets",html:`<table class="dtable"><tr><th>Domain</th><th>Target</th></tr>
<tr><td>Blood pressure</td><td>MAP ≥ 65 mmHg (or institution target)</td></tr><tr><td>Oxygenation</td><td>Adequate PaO₂ / SpO₂</td></tr>
<tr><td>Ventilation</td><td>Lung-protective where appropriate</td></tr><tr><td>Urine output</td><td>0.5–1 mL/kg/hr; avoid severe DI</td></tr>
<tr><td>Temperature</td><td>Normothermia</td></tr><tr><td>Electrolytes</td><td>Correct Na, K, Ca, Mg, PO₄</td></tr>
<tr><td>Glucose</td><td>Avoid severe hyper-/hypoglycemia</td></tr><tr><td>Infection</td><td>Cultures; antibiotics if indicated</td></tr></table>`},
teams:{title:"📋 Organ-Specific Recipient Teams",html:`<table class="dtable"><tr><th>Organ</th><th>Recipient team</th></tr>
<tr><td>Kidney</td><td>Nephrology + transplant surgery/urology</td></tr><tr><td>Liver</td><td>GI/Hepatology + liver transplant surgery</td></tr>
<tr><td>Heart</td><td>Cardiology + cardiac surgery</td></tr><tr><td>Lung</td><td>Pulmonology + thoracic surgery</td></tr>
<tr><td>Cornea/tissue</td><td>Eye/tissue bank team if applicable</td></tr></table>`},
acceptance:{title:"📋 Organ Acceptance / Refusal Flow",html:`<ul><li>PHILNOS provides the candidate hierarchy.</li>
<li>Recipient coordinator contacts attending physician.</li><li>Team reviews donor data, suitability, infection risk, crossmatch, readiness.</li>
<li>Attending documents acceptance or refusal.</li><li>If refused, reason documented; PHILNOS/SHARE informed immediately.</li>
<li>Offer proceeds to the next eligible candidate.</li></ul>`},
};
const WHY={
trigger:"We recognize a potential donor early — but recognizing is NOT pursuing donation. The team's first duty is still to save this patient. Early recognition only means we stay aware.",
share:"SHARE may review eligibility internally, but must NOT examine the patient, talk to the family, or change care until brain death is declared. This protects the ethical wall between rescuing a life and organ donation.",
bdchecklist:"This checklist is what makes the pathway safe, defensible, and auditable. We never declare death without excluding things that mimic it — sedatives, hypothermia, metabolic problems.",
consentlead:"How donation is introduced strongly affects family trust and consent. A trained coordinator — never the retrieval team — leads this conversation, and only after the family understands the death.",
parallel:"Once consent is obtained, donor management, workup, PHILNOS coordination, recipient prep, and retrieval prep run SIMULTANEOUSLY — to preserve organ viability before the donor deteriorates toward cardiac arrest.",
retrievaltime:"Retrieval should ideally happen before the donor deteriorates into cardiac arrest. Waiting for every recipient step to finish one-by-one risks losing the organs entirely.",
};
/* ============================================================
SCENE / NODE ENGINE
============================================================ */
let NODES={};
function go(id){ NODES[id](); document.getElementById('decisionOverlay').scrollTop=0; }
function setPhase(i){ S.phaseIdx=i; renderPips(); }
function renderPips(){ const c=document.getElementById('pips'); c.innerHTML='';
PHASES.forEach((_,i)=>{ const p=document.createElement('div');
p.className='pip'+(i<S.phaseIdx?' done':'')+(i===S.phaseIdx?' cur':''); c.appendChild(p); }); }
function deduct(pts,reason,isViolation=true){ S.score=Math.max(0,S.score-pts); S.deductions.push({pts,reason}); if(isViolation) S.violations++;
const el=document.getElementById('scoreVal'); el.textContent=S.score; el.classList.remove('flash'); void el.offsetWidth; el.classList.add('flash');
if(isViolation){ const g=document.getElementById('guide'); g.classList.add('react'); setTimeout(()=>g.classList.remove('react'),500); } }
function recordPhaseTime(idx){ S.timeSpare+=Math.max(0,timeLeft);
if(timeLeft>0 && timeLeft<=WARN_AT) deduct(5,`Finished ${PHASES[idx]} in the danger zone (final minute)`,false); }
function addTimeGoal(){ S.timeGoals++; }
function scene({art,artIcon,banner,situation,signpost,choices,extraHTML='',aux=[]}){
const sc=document.getElementById('scene');
let h=`<div class="phase-banner">${banner}</div><div class="scene-art ${art}">${artIcon}</div><div class="situation">${situation}</div>`;
if(signpost){ h+=`<div class="signpost"><div class="ico">⚠️</div><div class="q">${signpost.q}${signpost.sub?`<small>${signpost.sub}</small>`:''}</div></div>`; }
h+=extraHTML;
if(choices){ h+=`<div class="choices">`+choices.map((c,i)=>`<button class="choice ${c.color||''}" data-i="${i}"><span class="dot">${c.dot||'•'}</span><span>${c.label}</span></button>`).join('')+`</div>`; }
if(aux.length){ h+=`<div class="aux">`+aux.map(a=>`<button data-aux="${a.key}">${a.label}</button>`).join('')+`</div>`; }
sc.innerHTML=h;
if(choices) sc.querySelectorAll('.choice').forEach(b=> b.onclick=()=>choices[+b.dataset.i].do());
sc.querySelectorAll('[data-aux]').forEach(b=> b.onclick=()=>{ const a=aux.find(x=>x.key===b.dataset.aux); a.act(); });
}
function openDetails(k){ const d=DETAILS[k]; showModal(`<h3>${d.title}</h3>${d.html}<button class="btn ghost modal-close" onclick="closeModal()">Close</button>`); }
function openWhy(k){ showModal(`<h3>ℹ️ Why this matters</h3><p>${WHY[k]}</p><button class="btn ghost modal-close" onclick="closeModal()">Got it</button>`); }
function boundary(msg,returnFn){ document.getElementById('guide').classList.add('react'); setTimeout(()=>document.getElementById('guide').classList.remove('react'),500);
showModal(`<h3>⚠️ Boundary Violation</h3><p>${msg}</p><p style="color:var(--red);font-weight:700">−10 points · Let's correct course.</p>
<button class="btn modal-close" onclick="closeModal(); (${returnFn})()">Return to the decision</button>`,true); }
function teaching(title,msg,nextFn,penalty){ showModal(`<h3>📌 ${title}</h3><p>${msg}</p>${penalty?`<p style="color:var(--amber);font-weight:700">−${penalty} points</p>`:''}
<button class="btn modal-close" onclick="closeModal(); (${nextFn})()">Continue</button>`); }
function showModal(html,isB){ const b=document.getElementById('modalBox'); b.className='modal-box'+(isB?' boundary':''); b.innerHTML=html;
document.getElementById('modal').classList.add('show'); }
function closeModal(){ document.getElementById('modal').classList.remove('show'); }
/* ---------------- PHASE 1 ---------------- */
NODES.p1a=()=>{ setPhase(0); scene({
banner:"Phase 1 — Save the Patient", art:"art-icu", artIcon:"🏥",
situation:"A 34-year-old man arrives in the ICU after a severe head injury. He is on a ventilator. The primary service and intensivist are fighting to save his life. His GCS is dropping and brainstem reflexes appear to be fading.",
signpost:{q:"Does this patient meet Potential Donor Trigger Criteria?", sub:"Mechanically ventilated · devastating brain injury · GCS ≤ 7 or absent brainstem reflexes · poor prognosis."},
aux:[{key:'d',label:'📋 Details',act:()=>openDetails('trigger')},{key:'w',label:'ℹ️ Why',act:()=>openWhy('trigger')}],
choices:[
{label:"YES — trigger criteria met", color:"green", dot:"🟢", do:()=>{ addTimeGoal(); go('p1b'); }},
{label:"NOT YET — keep treating, reassess later", color:"blue", dot:"🔵",
do:()=>{ deduct(5,"Delayed potential-donor recognition"); teaching("Recognize early","This patient already meets the criteria. Recognizing a potential donor early doesn't mean pursuing donation — but delaying recognition can cost viable organs.","()=>go('p1a')",5); }},
]}); };
NODES.p1b=()=>{ scene({
banner:"Phase 1 — Save the Patient", art:"art-icu", artIcon:"📞",
situation:"Trigger criteria are met. Now decide how SHARE — the organ donation service — should be involved at this stage.",
signpost:{q:"How should SHARE be involved right now?"},
aux:[{key:'w',label:'ℹ️ Why',act:()=>openWhy('share')}],
choices:[
{label:"Notify SHARE for awareness ONLY (no exam, no family contact, no change to care)", color:"green", dot:"🟢", do:()=>{ addTimeGoal(); stamp1(); }},
{label:"Have SHARE come examine the patient and assess the family now", color:"red", dot:"🔴",
do:()=>{ deduct(10,"SHARE involved before brain death (boundary)"); boundary("SHARE may not examine the patient or approach the family before brain death is declared. This protects the ethical wall between saving a life and organ donation.","()=>go('p1b')"); }},
]}); };
function stamp1(){ teaching("Phase 1 Cleared ✅","SHARE notified within 1 hour of trigger. Documented: time identified, service, clinical trigger, awareness notification. The team keeps fighting to save the patient — no family approach about donation yet.","()=>completePhase(0)"); }
/* ---------------- PHASE 2 ---------------- */
const BD_ITEMS=["Known cause of irreversible catastrophic brain injury","Coma established",
"Confounders excluded (hypothermia, sedatives, paralytics, metabolic, shock)","Adequate blood pressure & oxygenation",
"Brainstem reflex examination completed","Apnea test performed (if safe)","Ancillary test done (if apnea cannot be completed)",
"Time of death documented","Family informed by treating physician"];
NODES.p2a=()=>{ setPhase(1);
const items=BD_ITEMS.map((t,i)=>`<div class="checkitem" data-c="${i}"><span class="box"></span><span>${t}</span></div>`).join('');
scene({ banner:"Phase 2 — Brain Death Evaluation", art:"art-neuro", artIcon:"🧠",
situation:"Despite maximal treatment, the patient shows no signs of recovery. An independent Brain Death Determination Team — qualified physicians not involved in any transplant decision — is called. The road ahead is locked until every prerequisite is confirmed.",
signpost:{q:"Complete the Brain Death Determination Checklist.", sub:"Tick each requirement to unlock the gate."},
extraHTML:`<div class="gate"><h4>🔒 Brain Death Checklist Gate</h4>${items}<div class="gate-progress"><i id="gateBar"></i></div></div>
<div class="choices"><button class="choice green" id="bdConfirm" disabled><span class="dot">🟢</span><span>YES — death declared by neurologic criteria</span></button>
<button class="choice blue" id="bdNo"><span class="dot">🔵</span><span>NO — a confounder is present, cannot confirm</span></button></div>`,
aux:[{key:'d',label:'📋 Details',act:()=>openDetails('bdchecklist')},{key:'w',label:'ℹ️ Why',act:()=>openWhy('bdchecklist')}],
});
let ticked=0;
document.querySelectorAll('.checkitem').forEach(it=> it.onclick=()=>{ if(it.classList.contains('on'))return;
it.classList.add('on'); it.querySelector('.box').textContent='✓'; ticked++;
document.getElementById('gateBar').style.width=(ticked/BD_ITEMS.length*100)+'%';
if(ticked===BD_ITEMS.length) document.getElementById('bdConfirm').disabled=false; });
document.getElementById('bdConfirm').onclick=()=>{ if(document.getElementById('bdConfirm').disabled)return; addTimeGoal(); stamp2(); };
document.getElementById('bdNo').onclick=()=>go('branch_comfort_bd');
};
function stamp2(){ teaching("Phase 2 Cleared ✅","Brain death confirmed and documented: checklist, examiners, apnea/ancillary test, time of death. The treating physician now informs the family that — despite everything — their son has died. The donation conversation has NOT started yet.","()=>completePhase(1)"); }
/* ---------------- PHASE 3 ---------------- */
NODES.p3a=()=>{ setPhase(2); scene({
banner:"Phase 3 — Family Approach & Consent", art:"art-family", artIcon:"🕊️",
situation:"The family understands their loved one has died. Now — and only now — the Patient Management Team gently introduces SHARE as the trained donation coordinator.",
signpost:{q:"Who leads the donation conversation?"},
aux:[{key:'w',label:'ℹ️ Why',act:()=>openWhy('consentlead')}],
choices:[
{label:"SHARE / trained donor coordinator leads the discussion", color:"green", dot:"🟢", do:()=>{ addTimeGoal(); go('p3b'); }},
{label:"The surgeon who will retrieve the organs asks the family", color:"red", dot:"🔴",
do:()=>{ deduct(10,"Retrieval team led consent (conflict of interest)"); boundary("The retrieval/transplant team must not participate in the consent process. Mixing the people who recover organs with the people who ask for them creates a conflict of interest and erodes family trust.","()=>go('p3a')"); }},
]}); };
NODES.p3b=()=>{ scene({
banner:"Phase 3 — Family Approach & Consent", art:"art-family", artIcon:"💬",
situation:"The trained coordinator sits with the family. After they understand the gift their loved one can give, the family is asked — gently and without pressure — to consider organ donation.",
signpost:{q:"THE FAMILY'S DECISION", sub:"This is the family's one true choice in the pathway."},
choices:[
{label:"The family consents to donation", color:"green", dot:"🟢", do:()=>stamp3()},
{label:"The family respectfully declines", color:"blue", dot:"🕊️", do:()=>go('branch_noconsent')},
]}); };
function stamp3(){ teaching("Phase 3 Cleared ✅ — Parallel Workflow Unlocked 🔓","Consent given and documented: who approached, time, family decision, consent form. The road ahead now opens into parallel lanes — donor management, allocation, and recipient preparation all begin at once.","()=>completePhase(2)"); }
/* ---------------- PHASE 4 ---------------- */
NODES.p4=()=>{ setPhase(3); scene({
banner:"Phase 4–5 — Parallel Workflow", art:"art-lanes", artIcon:"🛣️",
situation:"<strong>Everything now happens in parallel, not in sequence.</strong> Once consent is obtained, these lanes run simultaneously to preserve organ viability before the donor deteriorates toward cardiac arrest.",
extraHTML:`<div class="lanes">
<div class="lane A"><h5>🟦 Lane A · Donor Management</h5><p>Goal shifts from saving the patient to <strong>saving the organs</strong>.</p>
<ul><li>✅ MAP ≥ 65 mmHg</li><li>✅ PaO₂/SpO₂ adequate</li><li>✅ Lung-protective ventilation</li><li>✅ Urine 0.5–1 mL/kg/hr</li><li>✅ Normothermia · electrolytes · glucose</li></ul></div>
<div class="lane B"><h5>🟩 Lane B · Workup & Allocation</h5><p>SHARE performs workup & immunologic testing, submits data to <strong>PHILNOS</strong>, which returns the candidate hierarchy.</p>
<ul><li>🫀 Heart 🫁 Lungs</li><li> Liver</li><li>🫘 Kidney ×2</li></ul></div>
<div class="lane C"><h5>🟧 Lane C · Recipient Prep</h5><p>At the SAME time: recipients identified, crossmatched, admitted; billing/social cleared; retrieval team on standby.</p></div></div>`,
signpost:{q:"Lane B — Are the organs assessed as suitable for donation?"},
aux:[{key:'b',label:'📋 Donor Bundle',act:()=>openDetails('bundle')},{key:'t',label:'📋 Recipient Teams',act:()=>openDetails('teams')},{key:'w',label:'ℹ️ Why parallel?',act:()=>openWhy('parallel')}],
choices:[
{label:"YES — organs assessed suitable; notify PHILNOS immediately", color:"green", dot:"🟢", do:()=>{ addTimeGoal(); go('p4b'); }},
{label:"NO — assume unsuitable without full workup", color:"blue", dot:"🔵",
do:()=>{ deduct(5,"Skipped donor workup before ruling out organs"); teaching("Don't skip the workup","Suitability is decided by completed screening, labs, and organ-specific assessment — not assumption. Some organs may be suitable even when others aren't.","()=>go('p4')",5); }},
]}); };
NODES.p4b=()=>{ scene({
banner:"Phase 4–5 — Parallel Workflow", art:"art-lanes", artIcon:"🤝",
situation:"PHILNOS returns the candidate hierarchy per national allocation rules. In Lane C, the recipient coordinator contacts the attending physician for the top-matched candidate.",
signpost:{q:"Lane C — The team reviewed donor data, suitability, infection risk, crossmatch, and readiness. Accept the organ?"},
aux:[{key:'a',label:'📋 Acceptance Flow',act:()=>openDetails('acceptance')},{key:'t',label:'📋 Recipient Teams',act:()=>openDetails('teams')}],
choices:[
{label:"Attending accepts the organ — candidate admitted & crossmatched", color:"green", dot:"🟢", do:()=>{ addTimeGoal(); stamp4(); }},
{label:"Attending refuses — document reason, offer to next candidate", color:"blue", dot:"🔵",
do:()=>teaching("Refusal handled correctly","A refusal isn't a dead end — the reason is documented, PHILNOS/SHARE are informed immediately, and the offer passes to the next eligible candidate, who accepts. No points lost; this is valid practice.","()=>{ addTimeGoal(); stamp4(); }")},
]}); };
function stamp4(){ teaching("Phase 4 Cleared ✅","All lanes advanced together. Documented: donor orders & targets, labs, allocation hierarchy, organ acceptances. PHILNOS notified immediately. Now the lanes converge at the operating theatre.","()=>completePhase(3)"); }
/* ---------------- PHASE 5 ---------------- */
NODES.p5=()=>{ setPhase(4); scene({
banner:"Phase 5 — Organ Retrieval", art:"art-or", artIcon:"🏛️",
situation:"The donor's condition is being held stable. The separate Retrieval Team is ready. The recipient is already admitted and crossmatched — because everything ran in parallel.",
signpost:{q:"Is the donor stable and the retrieval team ready to proceed NOW?"},
aux:[{key:'w',label:'ℹ️ Why timing?',act:()=>openWhy('retrievaltime')}],
choices:[
{label:"YES — proceed to retrieval now (preserves viability)", color:"green", dot:"🟢", do:()=>{ addTimeGoal(); stamp5(); }},
{label:"Delay — finish every recipient step one-by-one first", color:"red", dot:"🔴",
do:()=>{ deduct(10,"Delayed retrieval (sequential, risked cardiac arrest)"); boundary("Retrieval should ideally happen before the donor deteriorates into cardiac arrest. Waiting for every recipient step to finish sequentially defeats the parallel workflow and risks losing the organs entirely.","()=>go('p5')"); }},
]}); };
function stamp5(){ teaching("Phase 5 Cleared ✅","Retrieval performed respectfully and in time. Organs recovered: 🫀 🫁 🫘 🫘 — each placed in transport with cold-ischemia timers started. Documented: OR time, retrieval team, organs retrieved, cold ischemia start.","()=>completePhase(4)"); }
/* ---------------- PHASE 6 ---------------- */
NODES.p6=()=>{ setPhase(5); scene({
banner:"Phase 6 — Transplant & Handover", art:"art-recipient", artIcon:"🫀",
situation:"The recipients are already admitted and crossmatched. Organ-specific transplant teams are scrubbed and waiting.",
signpost:{q:"Final check — crossmatch compatible and recipient ready. Proceed to transplant?"},
choices:[{label:"YES — proceed to transplant", color:"green", dot:"🟢", do:()=>{ addTimeGoal(); win(); }}],
}); };
/* ---------------- BRANCHES ---------------- */
NODES.branch_comfort_bd=()=>{ S.exploredBranch=true; document.getElementById('scene').className='scene deadend';
scene({ banner:"Pathway Ended — Comfort Care", art:"art-end", artIcon:"🤍",
situation:"Because a confounder is present, brain death cannot yet be confirmed. Donation cannot proceed on neurologic criteria at this time. The team continues full care and re-evaluates only when confounders are corrected.",
extraHTML:`<div class="situation" style="border-left-color:var(--ink-faint)">In this training scenario, all confounders had in fact been excluded — so this branch ends the donor pathway. In real practice, you would correct the confounder and reassess.</div>`,
choices:[{label:"↩ Return to the brain death decision", color:"blue", dot:"🔵", do:()=>{ document.getElementById('scene').className='scene'; go('p2a'); }}] }); };
NODES.branch_noconsent=()=>{ S.exploredBranch=true; document.getElementById('scene').className='scene deadend';
scene({ banner:"Pathway Ended — No Consent", art:"art-end", artIcon:"🕊️",
situation:"The family has declined organ donation. Their decision is honored and documented respectfully.",
extraHTML:`<div class="situation" style="border-left-color:var(--ink-faint)">• Inform the main service and ICU team.<br>• Continue end-of-life care according to hospital policy.<br>• Offer spiritual care, social service, and bereavement support — or refer to Palliative Service.<br>• No further donation-related approach unless the family reopens the discussion.</div>`,
choices:[{label:"↩ Return to the family decision", color:"blue", dot:"🔵", do:()=>{ document.getElementById('scene').className='scene'; go('p3b'); }}] }); };
/* ============================================================
WORLD — corridor build + character control
============================================================ */
const STATIONS=[
{x:700, name:'Phase 1', sub:'Save the Patient', icon:'🏥'},
{x:1620,name:'Phase 2', sub:'Brain Death Eval', icon:'🧠'},
{x:2540,name:'Phase 3', sub:'Family & Consent', icon:'🕊️'},
{x:3460,name:'Phase 4', sub:'Parallel Workflow', icon:'🛣️'},
{x:4380,name:'Phase 5', sub:'Organ Retrieval', icon:'🏛️'},
{x:5300,name:'Phase 6', sub:'Transplant', icon:'🫀'},
];
const ENTRY=['p1a','p2a','p3a','p4','p5','p6'];
const BARRIER_OFFSET=420;
const WORLD_W=STATIONS[STATIONS.length-1].x+700;
const DOOR_LABELS=['ICU','WARD','LAB','OR','RADIOLOGY','ER','PHARMACY','RECOVERY'];
let heroX=130, facing=1, moving=false, unlockedUpTo=0, inDecision=false, rafId=null;
const keys={left:false,right:false};
const corridor=document.getElementById('corridor');
const hero=document.getElementById('hero'); // assigned after build
let heroEl, shadowEl;
function buildCorridor(){
corridor.style.width=WORLD_W+'px';
let html=`<div class="ceiling"></div><div class="wall"></div><div class="baseboard"></div>
<div class="floor"></div><div class="floortiles"></div><div class="floorshine"></div>`;
// ceiling lights
for(let x=120;x<WORLD_W;x+=300) html+=`<div class="lightpanel" style="left:${x}px"></div>`;
// wall seams
for(let x=80;x<WORLD_W;x+=80) html+=`<div class="wallseam" style="left:${x}px"></div>`;
// decorative doors (skip near stations)
let li=0;
for(let x=240;x<WORLD_W-200;x+=360){
if(STATIONS.some(s=>Math.abs(s.x-x)<140)) continue;
const lbl=DOOR_LABELS[li++%DOOR_LABELS.length];
html+=`<div class="door" style="left:${x}px"></div><div class="doorsign" style="left:${x+39}px">${lbl}</div>`;
}
// stations
STATIONS.forEach((s,i)=> html+=`<div class="station locked" id="st${i}" style="left:${s.x}px">
<div class="sign"><b>${s.name}</b><small>${s.sub}</small></div>
<div class="arch"><div class="archicon">${s.icon}</div><div class="check">✅</div></div>
<div class="glowfloor"></div></div>`);
// barriers
STATIONS.forEach((s,i)=> html+=`<div class="barrier" id="bar${i}" style="left:${s.x+BARRIER_OFFSET}px"><div class="lock">🔒</div></div>`);
// hero + shadow
html+=`<div class="shadowblob" id="shadow"></div><div id="hero"><svg viewBox="0 0 120 210">${HERO_SVG}</svg></div>`;
corridor.innerHTML=html;
heroEl=document.getElementById('hero'); shadowEl=document.getElementById('shadow');
updateWorld();
}
function maxWalkX(){ return STATIONS[Math.min(unlockedUpTo,STATIONS.length-1)].x + BARRIER_OFFSET - 30; }
function updateWorld(){
STATIONS.forEach((s,i)=>{ const el=document.getElementById('st'+i); el.className='station';
if(S.done.has(i)) el.classList.add('done'); else if(i===unlockedUpTo) el.classList.add('active'); else if(i>unlockedUpTo) el.classList.add('locked'); });
STATIONS.forEach((s,i)=>{ const b=document.getElementById('bar'+i); if(i<unlockedUpTo) b.classList.add('open'); else b.classList.remove('open'); });
}
function loop(){
if(!inDecision){
moving=false; const speed=4.2;
if(keys.left){ heroX-=speed; facing=-1; moving=true; }
if(keys.right){ heroX+=speed; facing=1; moving=true; }
heroX=Math.max(70,Math.min(maxWalkX(),heroX));
} else moving=false;
// place hero + shadow
heroEl.style.left=(heroX-48)+'px';
shadowEl.style.left=heroX+'px';
heroEl.classList.toggle('left',facing===1);
heroEl.classList.toggle('walking',moving);
// camera
const viewW=window.innerWidth;
let camX=heroX-viewW*0.4; camX=Math.max(0,Math.min(WORLD_W-viewW,camX));
corridor.style.transform=`translateX(${-camX}px)`;
// interaction prompt
const st=STATIONS[unlockedUpTo];
const near = st && !S.done.has(unlockedUpTo) && !inDecision && Math.abs(heroX-st.x)<95;
const prompt=document.getElementById('prompt');
if(near){ prompt.classList.add('show'); prompt.innerHTML=`<div><span class="key">E</span> Enter ${st.name}</div><small>${st.sub}</small>`; }
else prompt.classList.remove('show');
prompt._near=near;
rafId=requestAnimationFrame(loop);
}
function tryInteract(){ if(inDecision) return; const p=document.getElementById('prompt'); if(p._near) openPhase(unlockedUpTo); }
function enterWorld(){
document.querySelectorAll('.screen').forEach(s=>s.classList.remove('active'));
document.getElementById('world').classList.add('show');
document.getElementById('hud').classList.add('show');
document.getElementById('controls').classList.add('show');
document.getElementById('hint').classList.add('show');
if(!rafId) loop();
toast(`Welcome, ${S.name.split(/[ ,]/)[0]}. Walk Dr. Arvin right ▶ to Phase 1.`);
}
function openPhase(i){
inDecision=true; document.getElementById('prompt').classList.remove('show');
document.getElementById('decisionOverlay').classList.add('show');
document.getElementById('guide').classList.add('show');
document.getElementById('scene').className='scene';
startPhaseTimer();
go(ENTRY[i]);
}
function completePhase(idx){
S.done.add(idx); recordPhaseTime(idx); closeModal(); stopPhaseTimer();
document.getElementById('decisionOverlay').classList.remove('show');
document.getElementById('guide').classList.remove('show');
inDecision=false;
unlockedUpTo=Math.min(idx+1,STATIONS.length-1);
updateWorld();
setPhase(unlockedUpTo);
if(idx<STATIONS.length-1) toast(`Phase ${idx+1} cleared ✅ — walk right ▶ to ${STATIONS[unlockedUpTo].name}.`);
}
/* ---------------- PHASE TIMER ---------------- */
const PHASE_SECONDS=180, WARN_AT=60;
let timeLeft=PHASE_SECONDS, gameOver=false;
/* ---- audio (Web Audio, no files) ---- */
let soundOn=false, actx=null;
function audioCtx(){ if(!actx){ try{ actx=new (window.AudioContext||window.webkitAudioContext)(); }catch(e){} } return actx; }
function beep(freq,dur,type='sine',gain=0.14){ if(!soundOn) return; const c=audioCtx(); if(!c) return;
const o=c.createOscillator(), g=c.createGain(); o.type=type; o.frequency.value=freq; o.connect(g); g.connect(c.destination);
const t=c.currentTime; g.gain.setValueAtTime(gain,t); g.gain.exponentialRampToValueAtTime(0.0001,t+dur);
o.start(t); o.stop(t+dur); }
function heartbeat(gain){ beep(110,0.13,'sine',gain); setTimeout(()=>beep(72,0.17,'sine',gain*0.85),150); }
function playUrgent(){ beep(1050,0.06,'square',0.12); setTimeout(()=>beep(1050,0.06,'square',0.12),130); }
function playFlat(){ beep(150,1.3,'sawtooth',0.18); }
function modalOpen(){ return document.getElementById('modal').classList.contains('show'); }
function timerActive(){ return inDecision && !gameOver && !modalOpen() && timeLeft>0; }
function startPhaseTimer(){ timeLeft=PHASE_SECONDS; updateTimerUI();
document.getElementById('phaseTimer').classList.add('show'); }
function stopPhaseTimer(){ document.getElementById('phaseTimer').classList.remove('show','warn');
document.getElementById('redAlert').classList.remove('on'); }
function updateTimerUI(){
const m=Math.floor(timeLeft/60), s=timeLeft%60;
document.getElementById('tclock').textContent=`${m}:${String(s).padStart(2,'0')}`;
document.getElementById('tbarfill').style.width=(timeLeft/PHASE_SECONDS*100)+'%';
const pt=document.getElementById('phaseTimer');
pt.classList.toggle('warn', timeLeft<=WARN_AT);
pt.classList.toggle('paused', inDecision && modalOpen());
document.getElementById('redAlert').classList.toggle('on', timeLeft<=WARN_AT && timerActive());
}
setInterval(()=>{
if(timerActive()){ timeLeft--; updateTimerUI();
if(timeLeft<=0){ expire(); }
else {
const inWarn = timeLeft<=WARN_AT;
heartbeat(inWarn?0.12:0.055); // gentle all phase, stronger in the red minute
if(inWarn) setTimeout(()=>heartbeat(0.10),430); // doubles up → racing heart
if(timeLeft<=10) playUrgent(); // code-alarm in final seconds
}
} else updateTimerUI();
},1000);
function expire(){
gameOver=true; playFlat(); closeModal(); stopPhaseTimer();
document.getElementById('redAlert').classList.remove('on');
document.getElementById('decisionOverlay').classList.remove('show');
document.getElementById('guide').classList.remove('show');
document.getElementById('world').classList.remove('show');
document.getElementById('controls').classList.remove('show');
document.getElementById('hint').classList.remove('show');
document.getElementById('hud').classList.remove('show');
document.getElementById('prompt').classList.remove('show');
const ph=PHASES[S.phaseIdx]||"this phase";
document.getElementById('expReason').textContent=`Ran out of time during ${ph}.`;
const exp=document.getElementById('expired'); exp.classList.add('active');
// replay flatline + shake
const fl=exp.querySelector('.exp-flatline path'); fl.style.animation='none'; void fl.offsetWidth; fl.style.animation='';
exp.classList.remove('shake'); void exp.offsetWidth; exp.classList.add('shake');
}
let toastTimer=null;
function toast(msg){ const t=document.getElementById('toast'); t.textContent=msg; t.classList.add('show');
clearTimeout(toastTimer); toastTimer=setTimeout(()=>t.classList.remove('show'),3800); }
/* ============================================================
WIN
============================================================ */
const RECAP=["Phase 1 — Donor recognized · SHARE awareness only","Phase 2 — Brain death confirmed (9/9 checklist)",
"Phase 3 — Coordinator-led consent · family consented","Phase 4 — Parallel donor management, allocation & recipient prep",
"Phase 5 — Timely retrieval (no delay)","Phase 6 — Transplant complete"];
function gradeFor(s){ if(s>=100)return{g:"Flawless — Gold Standard",c:"var(--gold)"}; if(s>=90)return{g:"Excellent",c:"var(--green)"};
if(s>=75)return{g:"Good",c:"var(--teal)"}; if(s>=60)return{g:"Needs Review",c:"var(--amber)"}; return{g:"Review the Pathway",c:"var(--red)"}; }
function win(){ closeModal(); recordPhaseTime(5); stopPhaseTimer();
document.getElementById('decisionOverlay').classList.remove('show'); document.getElementById('guide').classList.remove('show');
document.getElementById('world').classList.remove('show'); document.getElementById('controls').classList.remove('show');
document.getElementById('hint').classList.remove('show'); document.getElementById('hud').classList.remove('show');
document.getElementById('win').classList.add('active'); inDecision=true;
document.getElementById('winName').textContent=`Guided by ${S.name}. Pathway complete.`;
document.getElementById('recapList').innerHTML=RECAP.map(r=>`<div class="recap-item"><span class="ok">✅</span><span>${r}</span></div>`).join('');
const sm=Math.floor(S.timeSpare/60), ss=S.timeSpare%60;
document.getElementById('timeNote').textContent=`⏱ Time goals met: ${S.timeGoals} / ${S.timeGoalsMax} · ⚠️ Boundary violations: ${S.violations} · ⚡ Finished with ${sm}:${String(ss).padStart(2,'0')} to spare`;
document.getElementById('finalScore').textContent=S.score;
const gr=gradeFor(S.score); const ge=document.getElementById('finalGrade'); ge.textContent=gr.g; ge.style.color=gr.c;
const dl=document.getElementById('deductList');
if(S.deductions.length===0) dl.innerHTML=`<div class="deduct none">🌟 Perfect run — no points lost. Every clinical and ethical boundary respected.</div>`;
else dl.innerHTML=`<div style="font-size:12px;color:var(--ink-faint);text-transform:uppercase;letter-spacing:1px;margin-bottom:8px">Where points were lost</div>`+
S.deductions.map(d=>`<div class="deduct"><span>${d.reason}</span><span class="pts">−${d.pts}</span></div>`).join('');
}
function resetState(){ Object.assign(S,{score:100,deductions:[],violations:0,phaseIdx:0,timeGoals:0,exploredBranch:false,done:new Set()});
document.getElementById('scoreVal').textContent=100; heroX=130; facing=1; unlockedUpTo=0; inDecision=false;
gameOver=false; timeLeft=PHASE_SECONDS; S.timeSpare=0; stopPhaseTimer();
document.getElementById('expired').classList.remove('active','shake');
document.getElementById('redAlert').classList.remove('on'); renderPips(); }
function restart(){ document.getElementById('win').classList.remove('active'); resetState(); buildCorridor(); enterWorld(); }
function exploreBranches(){ restart(); setTimeout(()=>toast("Tip: at Phase 2 choose “confounder present”, or at Phase 3 have the family decline, to see the other endings."),600); }
function downloadSummary(){
const lines=["THE GIFT OF LIFE — Donor Pathway Training Summary","==================================================",
`Player: ${S.name}`,`Date: ${new Date().toLocaleString()}`,"",
`FINAL SCORE: ${S.score} / 100 (${gradeFor(S.score).g})`,`Time goals met: ${S.timeGoals}/${S.timeGoalsMax}`,
`Boundary violations: ${S.violations}`,"","JOURNEY:",...RECAP.map(r=>" ✓ "+r),"","POINT DEDUCTIONS:",
...(S.deductions.length? S.deductions.map(d=>` -${d.pts} ${d.reason}`):[" None — perfect run."]),
"","Impact: 1 donor → up to 8 lives changed.","",
"(Informal training walkthrough — not a patient record. Certificate feature planned for a future version.)"].join("\n");
const blob=new Blob([lines],{type:"text/plain"}); const a=document.createElement('a');
a.href=URL.createObjectURL(blob); a.download=`donor-pathway-${S.name.replace(/[^a-z0-9]+/gi,'_')||'player'}.txt`; a.click();
}
/* ============================================================
FLOW + INPUT
============================================================ */
document.getElementById('loginPortrait').innerHTML=HERO_SVG;
document.getElementById('guideHero').innerHTML=HERO_SVG;
/* --- intro video --- */
(function(){
const intro=document.getElementById('introScreen');
const vid=document.getElementById('introVideo');
const skip=document.getElementById('introSkip');
function endIntro(){ intro.classList.add('hidden'); document.getElementById('loading').classList.add('active'); }
vid.addEventListener('ended', endIntro);
skip.addEventListener('click', endIntro);
vid.addEventListener('error', endIntro);
})();
document.getElementById('beginBtn').onclick=()=>{ document.getElementById('loading').classList.remove('active');
document.getElementById('login').classList.add('active'); setTimeout(()=>document.getElementById('nameInput').focus(),300); };
const nameInput=document.getElementById('nameInput'), startBtn=document.getElementById('startBtn');
nameInput.addEventListener('input',()=>{ startBtn.disabled=nameInput.value.trim().length<2; });
nameInput.addEventListener('keydown',e=>{ if(e.key==='Enter'&&!startBtn.disabled) startBtn.click(); });
startBtn.onclick=()=>{ S.name=nameInput.value.trim();
document.getElementById('hudName').textContent=S.name;
document.getElementById('hudBadge').textContent=S.name.charAt(0).toUpperCase();
renderPips(); buildCorridor(); enterWorld(); };
/* keyboard */
window.addEventListener('keydown',e=>{
const t=e.target;
if(t&&(t.tagName==='INPUT'||t.tagName==='TEXTAREA'||t.isContentEditable)) return; // don't hijack typing
const k=e.key.toLowerCase();
// E / Enter / Space on intro → skip video
if((k==='e'||k==='enter'||k===' ')&&!document.getElementById('introScreen').classList.contains('hidden')){
e.preventDefault(); document.getElementById('introSkip').click(); return;
}
// E / Enter / Space on loading → click Begin
if((k==='e'||k==='enter'||k===' ')&&document.getElementById('loading').classList.contains('active')){
e.preventDefault(); const b=document.getElementById('beginBtn'); if(!b.disabled) b.click(); return;
}
if(k==='arrowleft'||k==='a'){ keys.left=true; }
if(k==='arrowright'||k==='d'){ keys.right=true; }
if(k==='e'||k===' '){ if(!inDecision){ e.preventDefault(); tryInteract(); } }