-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFoodSystem2050.html
More file actions
2066 lines (1851 loc) · 96.8 KB
/
Copy pathFoodSystem2050.html
File metadata and controls
2066 lines (1851 loc) · 96.8 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 Food System Transformation Challenge</title>
<style>
*{box-sizing:border-box;margin:0;padding:0}
body{font-family:'Segoe UI',Tahoma,sans-serif;background:#0d1117;color:#c9d1d9;min-height:100vh;overflow-x:hidden}
.screen{display:none}
.screen.active{display:flex;flex-direction:column;min-height:100vh}
/* ── SCROLLBAR ── */
::-webkit-scrollbar{width:5px}::-webkit-scrollbar-track{background:#0d1117}
::-webkit-scrollbar-thumb{background:#30363d;border-radius:3px}
/* ── INTRO ── */
#screen-intro{align-items:center;justify-content:center;text-align:center;padding:40px 20px;
background:radial-gradient(ellipse at 50% 30%,#0d2b1a 0%,#0d1117 65%);min-height:100vh}
#screen-intro h1{font-size:2.8em;color:#58d68d;margin-bottom:6px;letter-spacing:-1px;
text-shadow:0 0 40px rgba(88,214,141,.35)}
.intro-subtitle{font-size:1.1em;color:#8b9e7a;margin-bottom:28px}
.intro-body{max-width:680px;line-height:1.7;color:#adbac7;margin-bottom:28px;font-size:.95em}
.intro-features{display:grid;grid-template-columns:repeat(4,1fr);gap:12px;max-width:800px;margin:0 auto 32px}
.intro-features.intro-features-5col{grid-template-columns:repeat(5,1fr)}
.feat{background:#161b22;border:1px solid #30363d;border-radius:10px;padding:14px 12px;text-align:left}
.feat-icon{font-size:1.6em;margin-bottom:6px}
.feat-title{font-size:.82em;font-weight:700;color:#c9d1d9;margin-bottom:3px}
.feat-desc{font-size:.75em;color:#8b949e;line-height:1.3}
.intro-cite{font-size:.75em;color:#8b949e;margin-top:20px;font-style:italic}
.intro-cite a{color:#ffffff;text-decoration:underline}
/* ── BUTTONS ── */
.btn-primary{background:#238636;color:#fff;border:none;padding:13px 38px;
font-size:1.05em;border-radius:8px;cursor:pointer;transition:background .2s,transform .1s;font-weight:600}
.btn-primary:hover{background:#2ea043;transform:translateY(-1px)}
.btn-secondary{background:#21262d;color:#c9d1d9;border:1px solid #30363d;padding:11px 28px;
font-size:.95em;border-radius:8px;cursor:pointer;transition:background .2s}
.btn-secondary:hover{background:#2d333b}
/* ── GAME HEADER ── */
#game-header{position:fixed;top:0;left:0;right:0;background:#161b22;
border-bottom:1px solid #30363d;padding:10px 18px;display:flex;align-items:center;
gap:20px;z-index:200;height:56px}
#game-header .title{color:#58d68d;font-weight:700;font-size:1em;flex:1;white-space:nowrap}
.hstat{text-align:center;min-width:70px}
.hstat .lbl{font-size:.68em;color:#8b949e;display:block;text-transform:uppercase;letter-spacing:.5px}
.hstat .val{font-size:1.25em;font-weight:700}
#h-year .val{color:#58a6ff}
#h-round .val{color:#bc8cff}
#h-budget .val{color:#f0b429}
.round-dots{display:flex;gap:5px;align-items:center}
.rdot{width:9px;height:9px;border-radius:50%;background:#21262d;border:2px solid #30363d;transition:all .3s}
.rdot.done{background:#388bfd;border-color:#388bfd}
.rdot.current{background:#58d68d;border-color:#58d68d;box-shadow:0 0 6px rgba(88,214,141,.5)}
/* ── GAME BODY ── */
#screen-game{flex-direction:column;height:100vh;overflow:hidden}
#game-body{display:flex;flex:1;margin-top:56px;height:calc(100vh - 56px)}
#left-panel{flex:0 0 55%;padding:16px;overflow-y:auto;border-right:1px solid #30363d}
#right-panel{flex:0 0 45%;display:flex;flex-direction:column;overflow:hidden}
#measures-scroll{flex:1;overflow-y:auto;padding:12px 12px 80px}
#end-round-bar{position:fixed;bottom:0;right:0;width:45%;padding:10px 12px;
background:#0d1117;border-top:1px solid #30363d;z-index:100}
.btn-end-round{width:100%;background:#1f6feb;color:#fff;border:none;padding:11px;
font-size:.95em;border-radius:7px;cursor:pointer;font-weight:600;transition:background .2s}
.btn-end-round:hover{background:#388bfd}
.btn-end-round:disabled{background:#21262d;color:#8b949e;cursor:not-allowed}
/* ── PANEL HEADERS ── */
.panel-head{color:#8b949e;font-size:.78em;text-transform:uppercase;letter-spacing:1px;
margin-bottom:12px;display:flex;align-items:center;gap:6px}
/* ── INDICATOR CHARTS ── */
#indicators-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:8px}
.gauge-card{background:#161b22;border:1px solid #30363d;border-radius:9px;
padding:8px 10px 6px;transition:border-color .25s,box-shadow .25s;cursor:default}
.gauge-card.hi{border-color:#58d68d;box-shadow:0 0 8px rgba(88,214,141,.18)}
.gauge-card.lo{border-color:#f85149;box-shadow:0 0 8px rgba(248,81,73,.18)}
.chart-header{display:flex;align-items:baseline;justify-content:space-between;margin-bottom:4px}
.g-name{font-size:.78em;font-weight:600;color:#c9d1d9;line-height:1.2}
.g-value{font-size:.92em;font-weight:700}
.trend-up{color:#58d68d}.trend-dn{color:#f85149}.trend-nc{color:#8b949e}
/* ── POPULARITY CHART ── */
#pop-chart-box{margin-top:12px;background:#161b22;border:1px solid #30363d;
border-radius:9px;padding:11px 14px}
#pop-chart-box h4{font-size:.75em;text-transform:uppercase;letter-spacing:.8px;
color:#8b949e;margin-bottom:8px}
/* ── MEASURE CARDS ── */
.cat-section{margin-bottom:10px}
.cat-head{display:flex;align-items:center;gap:7px;padding:8px 10px;
background:#161b22;border:1px solid #30363d;border-radius:7px 7px 0 0;
cursor:pointer;user-select:none;transition:background .15s}
.cat-head:hover{background:#1c2128}
.cat-icon{font-size:1.1em}
.cat-name{font-weight:700;font-size:.9em}
.cat-cost{margin-left:auto;font-size:.75em;color:#8b949e}
.cat-body{border:1px solid #30363d;border-top:none;border-radius:0 0 7px 7px;
display:grid;grid-template-columns:1fr 1fr;gap:1px;background:#30363d;overflow:hidden}
.cat-body.collapsed{display:none}
.mcard{padding:9px 11px;cursor:pointer;background:#0d1117;
transition:background .15s;position:relative;user-select:none}
.mcard:hover:not(.mbusy){background:#1c2128}
.mcard.msel{background:rgba(88,214,141,.08);border-left:3px solid #a5f3a5}
.mcard.mprior{border-left:3px solid #444c56}
.mcard.mbusy{opacity:.35;cursor:not-allowed}
.mhead{display:flex;align-items:flex-start;gap:7px}
.mname{font-size:.87em;font-weight:700;flex:1}
.mcost-row{display:flex;align-items:center;gap:3px;flex-shrink:0}
.mcost{background:#30363d;color:#f0b429;border-radius:4px;padding:1px 6px;
font-size:.75em;white-space:nowrap}
.mcost.sel{background:rgba(88,214,141,.2);color:#58d68d}
.sel-count{background:#388bfd;color:#fff;border-radius:4px;padding:1px 5px;
font-size:.72em;font-weight:700}
.prior-badge{background:#444c56;color:#adbac7;border-radius:4px;padding:1px 5px;
font-size:.68em;font-weight:700}
.add-purchase{background:#1f6feb;color:#fff;border-radius:4px;padding:0 6px;
font-size:.8em;font-weight:700;cursor:pointer;line-height:1.4}
.add-purchase:hover{background:#388bfd}
.vi-penalty{color:#f85149;font-size:.85em;font-weight:700}
.repeat-note{color:#8b949e;font-size:.8em}
.mdesc{font-size:.75em;color:#8b949e;margin-top:3px;line-height:1.3}
.mfx{display:flex;flex-wrap:wrap;gap:3px;margin-top:5px}
.chip{font-size:.68em;padding:1px 5px;border-radius:3px;font-weight:700;border:1px solid}
.chip-p{color:#58d68d;background:rgba(88,214,141,.12);border-color:rgba(88,214,141,.3)}
.chip-n{color:#f85149;background:rgba(248,81,73,.12);border-color:rgba(248,81,73,.3)}
/* ── WILDCARD SCREEN ── */
#screen-wildcard{align-items:center;justify-content:center;padding:40px 20px;
background:radial-gradient(ellipse at 50% 30%,#1a0d2e 0%,#0d1117 65%);min-height:100vh}
.wc-screen-box{max-width:600px;width:100%;animation:fadeUp .35s ease}
.wc-screen-eyebrow{font-size:.78em;text-transform:uppercase;letter-spacing:1.2px;
color:#bc8cff;margin-bottom:10px}
.wc-screen-title{font-size:1.45em;font-weight:700;color:#c9d1d9;margin-bottom:28px;
line-height:1.4}
.wc-event-card{background:#1a1535;border:1px solid #4a3567;border-radius:10px;
padding:16px 18px;margin-bottom:14px}
.wc-event-header{display:flex;align-items:center;gap:10px;margin-bottom:6px}
.wc-event-icon{font-size:1.5em}
.wc-event-name{font-size:1em;font-weight:700;color:#c9d1d9}
.wc-event-desc{font-size:.85em;color:#8b949e;line-height:1.5;margin-bottom:10px}
.wc-screen-box .btn-primary{margin-top:10px}
/* ── RESULT SCREEN ── */
#screen-result{align-items:center;justify-content:center;padding:30px 20px;background:#0d1117}
.result-box{max-width:680px;width:100%;animation:fadeUp .3s ease}
.result-year{font-size:1.8em;color:#58a6ff;font-weight:700;margin-bottom:4px}
.result-subtitle{color:#8b949e;margin-bottom:18px;font-size:.9em}
.narrative-box{background:#161b22;border:1px solid #30363d;border-radius:9px;
padding:14px 16px;margin-bottom:18px;line-height:1.65;color:#adbac7;font-size:.9em}
.changes-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-bottom:18px}
.chg-item{background:#161b22;border:1px solid #30363d;border-radius:8px;
padding:10px 12px;display:flex;align-items:center;gap:9px}
.chg-name{font-size:.82em;font-weight:700;flex:1}
.chg-delta{font-size:.95em;font-weight:700}
.delta-p{color:#58d68d}.delta-n{color:#f85149}.delta-0{color:#8b949e}
.measures-taken{background:#161b22;border:1px solid #30363d;border-radius:9px;
padding:12px 14px;margin-bottom:18px}
.measures-taken h4{font-size:.78em;text-transform:uppercase;color:#8b949e;
letter-spacing:.8px;margin-bottom:8px}
.taken-list{display:flex;flex-wrap:wrap;gap:5px}
.taken-pill{background:rgba(88,214,141,.1);border:1px solid rgba(88,214,141,.3);
color:#58d68d;border-radius:5px;padding:3px 9px;font-size:.78em}
.no-measures{color:#8b949e;font-size:.85em;font-style:italic}
/* ── WILDCARD EVENTS ── */
.wildcard-box{background:#161b22;border:1px solid #4a3567;border-radius:9px;
padding:12px 14px;margin-bottom:18px}
.wildcard-box h4{font-size:.78em;text-transform:uppercase;color:#bc8cff;
letter-spacing:.8px;margin-bottom:8px}
.wc-item{background:#1a1535;border:1px solid #4a3567;border-radius:7px;
padding:9px 11px;margin-bottom:6px}
.wc-item:last-child{margin-bottom:0}
.wc-name{font-size:.87em;font-weight:700;color:#c9d1d9}
.wc-desc{font-size:.75em;color:#8b949e;margin:3px 0 5px;line-height:1.3}
/* ── POPULARITY ── */
/* header widget */
.pop-header-widget{display:flex;flex-direction:column;align-items:center;min-width:120px}
.pop-header-widget .lbl{font-size:.68em;color:#8b949e;text-transform:uppercase;letter-spacing:.5px;margin-bottom:2px}
.pop-header-num-row{display:flex;align-items:center;gap:6px}
.pop-header-num{font-size:1.15em;font-weight:700}
.pop-header-mandate{font-size:.68em;font-weight:600}
.pop-mini-track{width:90px;height:5px;background:#21262d;border-radius:3px;overflow:hidden;margin-top:2px}
.pop-mini-fill{height:100%;border-radius:3px;transition:width .5s ease,background .5s ease}
/* popularity chip on measure cards */
.pop-chip{font-size:.68em;padding:1px 5px;border-radius:3px;font-weight:700;border:1px solid;white-space:nowrap}
.pop-chip-p{color:#a5f3a5;background:rgba(165,243,165,.1);border-color:rgba(165,243,165,.3)}
.pop-chip-n{color:#fca5a5;background:rgba(252,165,165,.1);border-color:rgba(252,165,165,.3)}
.pop-chip-0{color:#8b949e;background:rgba(139,148,158,.1);border-color:rgba(139,148,158,.3)}
/* end-round forecast bar */
.forecast-row{font-size:.75em;color:#8b949e;text-align:center;padding:5px 2px 0;
display:flex;align-items:center;justify-content:center;flex-wrap:wrap;gap:4px}
.forecast-pop-p{color:#58d68d;font-weight:700}.forecast-pop-n{color:#f85149;font-weight:700}
.forecast-pop-0{color:#8b949e;font-weight:700}
/* result screen popularity section */
.pop-section{background:#161b22;border:1px solid #30363d;border-radius:9px;
padding:14px 16px;margin-bottom:16px}
.pop-section-title{font-size:.78em;text-transform:uppercase;letter-spacing:.8px;
color:#8b949e;margin-bottom:10px}
.pop-bar-row{display:flex;align-items:center;gap:8px;margin-bottom:5px}
.pop-bar-lbl{font-size:.76em;color:#8b949e;width:46px;text-align:right;flex-shrink:0}
.pop-bar-track{flex:1;height:9px;background:#21262d;border-radius:5px;overflow:hidden}
.pop-bar-fill{height:100%;border-radius:5px;transition:width .6s ease}
.pop-bar-val{font-size:.86em;font-weight:700;width:32px;flex-shrink:0}
.pop-delta-summary{display:flex;align-items:center;gap:8px;margin:8px 0;
padding:6px 10px;background:#0d1117;border-radius:6px}
.pop-delta-lbl{font-size:.8em;color:#8b949e;flex:1}
.pop-delta-num{font-size:1em;font-weight:700}
.pop-comp-section{margin-top:10px;border-top:1px solid #21262d;padding-top:10px}
.pop-comp-title{font-size:.72em;color:#8b949e;text-transform:uppercase;
letter-spacing:.5px;margin-bottom:6px}
.pop-comp-row{display:flex;align-items:flex-start;gap:7px;margin-bottom:5px;font-size:.82em}
.pop-comp-icon{width:18px;flex-shrink:0;margin-top:1px}
.pop-comp-label{flex:1;color:#c9d1d9;line-height:1.3}
.pop-comp-sub{color:#8b949e;font-size:.88em;display:block}
.pop-comp-val{font-weight:700;width:46px;text-align:right;flex-shrink:0}
.pop-forecast-row{margin-top:10px;display:flex;align-items:center;gap:8px;
padding:8px 11px;border-radius:7px;font-size:.84em;
background:rgba(88,214,141,.07);border:1px solid rgba(88,214,141,.2)}
.pop-forecast-mandate{font-weight:700}
.pop-forecast-budget{font-weight:700;margin-left:auto;color:#f0b429;font-size:.95em}
/* ── FINAL SCREEN ── */
#screen-final{align-items:center;justify-content:center;padding:30px 20px;
background:radial-gradient(ellipse at 50% 40%,#0d2b1a 0%,#0d1117 65%);min-height:100vh}
.final-box{max-width:760px;width:100%;text-align:center;animation:fadeUp .4s ease}
.final-title{font-size:2.4em;font-weight:700;margin-bottom:6px}
.final-sub{color:#8b949e;margin-bottom:22px;font-size:.95em}
.score-ring{display:inline-flex;flex-direction:column;align-items:center;
justify-content:center;width:140px;height:140px;border-radius:50%;
border:4px solid;margin-bottom:16px}
.score-num{font-size:3em;font-weight:700;line-height:1}
.score-lbl{font-size:.75em;color:#8b949e;margin-top:2px}
.grade-tag{display:inline-block;padding:6px 20px;border-radius:6px;
font-size:1.1em;font-weight:700;margin-bottom:24px;border:1px solid}
.grade-S{color:#58d68d;background:rgba(88,214,141,.12);border-color:rgba(88,214,141,.4)}
.grade-A{color:#58d68d;background:rgba(88,214,141,.12);border-color:rgba(88,214,141,.4)}
.grade-B{color:#f0b429;background:rgba(240,180,41,.1);border-color:rgba(240,180,41,.4)}
.grade-C{color:#f85149;background:rgba(248,81,73,.1);border-color:rgba(248,81,73,.35)}
.grade-D{color:#f85149;background:rgba(248,81,73,.1);border-color:rgba(248,81,73,.35)}
.final-indicators{display:grid;grid-template-columns:repeat(5,1fr);gap:8px;margin-bottom:22px}
.fi-card{background:#161b22;border:1px solid #30363d;border-radius:8px;padding:10px 6px;text-align:center}
.fi-emoji{font-size:1.3em}
.fi-name{font-size:.7em;color:#8b949e;margin:2px 0}
.fi-val{font-size:1.1em;font-weight:700}
.fi-green{color:#58d68d}.fi-yellow{color:#f0b429}.fi-red{color:#f85149}
.final-msg{background:#161b22;border:1px solid #30363d;border-radius:9px;
padding:14px 18px;text-align:left;line-height:1.65;color:#adbac7;
font-size:.9em;margin-bottom:22px}
.final-ref{font-size:.75em;color:#484f58;font-style:italic;margin-bottom:18px}
.final-btns{display:flex;gap:12px;justify-content:center}
/* ── ANIMATIONS ── */
@keyframes fadeUp{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:translateY(0)}}
/* ── TUTORIAL ── */
#tutorial-overlay{position:fixed;inset:0;z-index:9000;pointer-events:all;display:none}
#tut-spotlight{position:fixed;border-radius:8px;
box-shadow:0 0 0 9999px rgba(13,17,23,.80);
border:2px solid rgba(56,139,253,.45);
transition:left .35s ease,top .35s ease,width .35s ease,height .35s ease;
pointer-events:none;z-index:9001}
#tut-tip{position:fixed;background:#1c2128;border:1px solid #388bfd;
border-radius:10px;padding:16px 18px;width:290px;
box-shadow:0 8px 32px rgba(0,0,0,.65);z-index:9002;
transition:left .35s ease,top .35s ease}
.tut-title{font-weight:700;font-size:.96em;color:#c9d1d9;margin-bottom:7px}
.tut-body{font-size:.82em;color:#adbac7;line-height:1.6;margin-bottom:13px}
.tut-footer{display:flex;align-items:center;justify-content:space-between}
.tut-counter{font-size:.72em;color:#8b949e}
.tut-btns{display:flex;gap:8px}
.tut-skip{background:none;border:1px solid #30363d;color:#8b949e;
padding:5px 12px;border-radius:6px;cursor:pointer;font-size:.8em;transition:background .15s}
.tut-skip:hover{background:#21262d;color:#c9d1d9}
.tut-next{background:#1f6feb;color:#fff;border:none;
padding:5px 14px;border-radius:6px;cursor:pointer;font-size:.8em;font-weight:600;transition:background .15s}
.tut-next:hover{background:#388bfd}
/* ── TOOLTIP ── */
.tip{position:relative}
.tip-text{display:none;position:absolute;bottom:110%;left:50%;transform:translateX(-50%);
background:#1c2128;border:1px solid #30363d;border-radius:6px;padding:6px 10px;
font-size:.75em;white-space:nowrap;z-index:300;pointer-events:none;color:#adbac7}
.tip:hover .tip-text{display:block}
@media(max-width:900px){
.intro-features,.intro-features.intro-features-5col{grid-template-columns:1fr 1fr}
#game-body{flex-direction:column}
#left-panel,#right-panel{flex:none;width:100%;border-right:none}
#indicators-grid{grid-template-columns:repeat(2,1fr)}
#end-round-bar{position:fixed;width:100%;bottom:0;left:0;right:0}
}
/* ── MOBILE-ONLY ELEMENTS (hidden on desktop) ── */
#mobile-tabs,.mob-tile,#measure-sheet,#measure-sheet-overlay{display:none}
/* ── MOBILE TILE STYLES ── */
.mob-tile{flex-direction:column;align-items:center;justify-content:center;
background:#161b22;border:1px solid #30363d;border-radius:9px;
padding:8px 6px 7px;cursor:pointer;text-align:center;position:relative;
width:88px;min-height:80px;transition:border-color .15s,background .15s;user-select:none}
.mob-tile:active{background:#1c2128}
.mob-tile.mob-sel{border-color:#58d68d;background:rgba(88,214,141,.08)}
.mob-tile.mob-busy{opacity:.35;cursor:not-allowed}
.mob-tile.mob-prior{border-left:3px solid #444c56}
.mtile-icon{font-size:1.3em;line-height:1;margin-bottom:4px}
.mtile-name{font-size:.63em;color:#c9d1d9;line-height:1.25;max-width:80px;
display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
word-break:break-word}
.mtile-badges{display:flex;gap:3px;align-items:center;justify-content:center;
flex-wrap:wrap;margin-top:4px}
/* ── MEASURE BOTTOM SHEET ── */
#measure-sheet-overlay{position:fixed;inset:0;background:rgba(13,17,23,.65);z-index:500}
#measure-sheet{position:fixed;bottom:0;left:0;right:0;z-index:501;
background:#161b22;border-top:1px solid #30363d;border-radius:14px 14px 0 0;
padding:6px 18px 36px;transform:translateY(100%);transition:transform .28s ease;
max-height:78vh;overflow-y:auto}
#measure-sheet.open{transform:translateY(0)}
.ms-handle{width:36px;height:4px;background:#30363d;border-radius:2px;margin:0 auto 14px}
#ms-header{display:flex;align-items:center;gap:10px;margin-bottom:10px}
#ms-cat-icon{font-size:1.5em}
#ms-name{font-size:1.05em;font-weight:700;color:#c9d1d9;flex:1;line-height:1.3}
#ms-cost-badge{background:#30363d;color:#f0b429;border-radius:5px;
padding:3px 9px;font-size:.82em;font-weight:700;white-space:nowrap}
#ms-desc{font-size:.85em;color:#8b949e;line-height:1.55;margin-bottom:10px}
#ms-fx{display:flex;flex-wrap:wrap;gap:4px;margin-bottom:10px}
#ms-repeat-note{font-size:.8em;color:#8b949e;margin-bottom:12px;font-style:italic}
.ms-buy-btn{width:100%;background:#1f6feb;color:#fff;border:none;
padding:13px;font-size:1em;border-radius:8px;cursor:pointer;
font-weight:700;transition:background .2s;min-height:44px}
.ms-buy-btn:hover{background:#388bfd}
.ms-buy-btn.ms-desel{background:transparent;color:#f85149;
border:1px solid rgba(248,81,73,.45)}
.ms-buy-btn:disabled{background:#21262d;color:#8b949e;cursor:not-allowed;border:none}
/* ── MOBILE TAB BAR ── */
#mobile-tabs{background:#161b22;border-bottom:1px solid #30363d;flex-shrink:0;z-index:10}
.mob-tab{flex:1;background:none;border:none;color:#8b949e;padding:11px 0;
font-size:.9em;font-weight:600;cursor:pointer;
border-bottom:2px solid transparent;transition:color .15s,border-color .15s}
.mob-tab.active{color:#c9d1d9;border-bottom-color:#388bfd}
@media(max-width:520px){
/* header: drop decorative/redundant elements */
#game-header .title{display:none}
#h-ssp{display:none}
#round-dots{display:none}
.hstat{min-width:46px}
.hstat .lbl{font-size:.60em}
.hstat .val{font-size:1.05em}
.pop-header-widget{min-width:80px}
.pop-header-mandate{display:none}
#game-header{gap:8px;padding:8px 10px}
/* game layout: natural scroll per tab */
#screen-game{height:auto;overflow:visible}
#game-body{flex-direction:column;height:auto}
#left-panel,#right-panel{flex:none;width:100%;border-right:none;
overflow-y:visible;height:auto}
#right-panel{display:flex;flex-direction:column}
#measures-scroll{padding-bottom:90px}
#end-round-bar{width:100%;left:0;right:0}
/* show tab bar, hide inactive panel */
#mobile-tabs{display:flex}
.mob-hidden{display:none !important}
/* measure tiles: replace 2-col card grid */
.mcard{display:none}
.mob-tile{display:flex}
.cat-body{display:flex;flex-wrap:wrap;gap:8px;padding:10px;
background:transparent;border:none;border-top:1px solid #30363d}
.cat-body.collapsed{display:none}
/* intro screen: move button + loader directly under subtitle */
#screen-intro h1 { order:1 }
#screen-intro .intro-subtitle { order:2; margin-bottom:16px }
#screen-intro #load-overlay { order:3; margin-bottom:8px }
#screen-intro #load-error { order:4 }
#screen-intro .btn-primary { order:5; margin-bottom:24px }
#screen-intro .intro-body { order:6 }
#screen-intro .intro-features { order:7 }
#screen-intro .intro-cite { order:8 }
/* other screens */
.intro-features,.intro-features.intro-features-5col{grid-template-columns:1fr}
.final-indicators{grid-template-columns:repeat(3,1fr)}
.changes-grid{grid-template-columns:1fr}
/* buttons */
.btn-primary,.btn-secondary,.btn-end-round{min-height:44px}
/* tutorial tip: full-width on mobile */
#tut-tip{width:calc(100vw - 32px) !important;box-sizing:border-box}
/* touch tooltips */
.tip:focus .tip-text,.tip:active .tip-text{display:block}
}
/* ── SSP SELECTION ── */
#screen-ssp{align-items:center;justify-content:center;text-align:center;padding:40px 20px;
background:radial-gradient(ellipse at 50% 30%,#0d1f2b 0%,#0d1117 65%);min-height:100vh}
#screen-ssp h2{font-size:2em;color:#58a6ff;margin-bottom:6px;font-weight:700}
.ssp-subtitle{font-size:.95em;color:#8b949e;margin-bottom:32px}
.ssp-cards{display:flex;gap:16px;justify-content:center;flex-wrap:wrap;max-width:860px;margin:0 auto 28px}
.ssp-card{flex:1;min-width:220px;max-width:260px;background:#161b22;border:2px solid #30363d;
border-radius:12px;padding:22px 18px;cursor:pointer;transition:border-color .2s,box-shadow .2s,transform .15s;text-align:left}
.ssp-card:hover{transform:translateY(-3px)}
.ssp-card.ssp-easy:hover{border-color:#58d68d;box-shadow:0 0 18px rgba(88,214,141,.25)}
.ssp-card.ssp-medium:hover{border-color:#f0b429;box-shadow:0 0 18px rgba(240,180,41,.25)}
.ssp-card.ssp-hard:hover{border-color:#f85149;box-shadow:0 0 18px rgba(248,81,73,.25)}
.ssp-card.selected{transform:translateY(-3px)}
.ssp-card.ssp-easy.selected{border-color:#58d68d;box-shadow:0 0 18px rgba(88,214,141,.3)}
.ssp-card.ssp-medium.selected{border-color:#f0b429;box-shadow:0 0 18px rgba(240,180,41,.3)}
.ssp-card.ssp-hard.selected{border-color:#f85149;box-shadow:0 0 18px rgba(248,81,73,.3)}
.ssp-badge{display:inline-block;font-size:.72em;font-weight:700;padding:3px 9px;border-radius:5px;
margin-bottom:10px;letter-spacing:.5px}
.ssp-easy .ssp-badge{background:rgba(88,214,141,.15);color:#58d68d;border:1px solid rgba(88,214,141,.4)}
.ssp-medium .ssp-badge{background:rgba(240,180,41,.15);color:#f0b429;border:1px solid rgba(240,180,41,.4)}
.ssp-hard .ssp-badge{background:rgba(248,81,73,.13);color:#f85149;border:1px solid rgba(248,81,73,.4)}
.ssp-title{font-size:1.1em;font-weight:700;color:#c9d1d9;margin-bottom:6px}
.ssp-desc{font-size:.8em;color:#8b949e;line-height:1.5;margin-bottom:12px}
.ssp-trends{font-size:.75em;line-height:1.6;color:#8b949e}
.ssp-trends span{display:block}
.ssp-trend-g{color:#58d68d}.ssp-trend-y{color:#f0b429}.ssp-trend-r{color:#f85149}
</style>
</head>
<body>
<!-- ═══════════════════════════ INTRO ═══════════════════════════ -->
<div id="screen-intro" class="screen active">
<h1>The Food System Transformation Challenge</h1>
<div class="intro-subtitle">Can you transform the global food system by 2050?</div>
<div class="intro-body">
You are a global food policy coordinator. The current food system is failing:
hunger persists, obesity is rising, biodiversity is collapsing, and agriculture
contributes a third of all greenhouse gas emissions. Over <strong>6 rounds</strong> (each
representing 5 years), you implement 23 food system measures drawn from research.
Every measure has benefits and trade-offs — and your <strong>political popularity</strong> determines
how many policy points you receive each round. Voters reward visible improvements and
punish crises, so you must balance long-term sustainability with near-term approval.
</div>
<div class="intro-features intro-features-5col">
<div class="feat"><div class="feat-icon">🍽️</div>
<div class="feat-title">Health</div>
<div class="feat-desc">Fight hunger AND reduce obesity simultaneously</div></div>
<div class="feat"><div class="feat-icon">🌿</div>
<div class="feat-title">Environment</div>
<div class="feat-desc">Protect biodiversity, climate, water & nitrogen</div></div>
<div class="feat"><div class="feat-icon">💰</div>
<div class="feat-title">Inclusion</div>
<div class="feat-desc">Keep food affordable; improve farm livelihoods</div></div>
<div class="feat"><div class="feat-icon">⚖️</div>
<div class="feat-title">Trade-offs</div>
<div class="feat-desc">No single measure fixes everything — packaging matters</div></div>
<div class="feat"><div class="feat-icon">👥</div>
<div class="feat-title">Popularity</div>
<div class="feat-desc">Budget = mandate. Crises drain approval; progress earns it. Voters judge your policies directly.</div></div>
</div>
<div id="load-overlay" style="margin-bottom:12px;color:#8b949e;font-size:.88em">⏳ Loading game data…</div>
<div id="load-error" style="display:none;color:#f85149;font-size:.85em;margin-bottom:12px;max-width:520px"></div>
<button class="btn-primary" onclick="startGame()">Start Game →</button>
<div class="intro-cite">
Based on: <a href="https://www.nature.com/articles/s43016-025-01268-y" target="_blank" rel="noopener">Bodirsky et al. (2025) "A food system transformation pathway reconciles
1.5°C global warming with improved health, environment and social inclusion." <em>Nature Food.</em></a> <br> Impact of food system measures was roughly parametrized on the study, policy points
and popularity are a pure game dynamic without scientific foundation.
</div>
</div>
<!-- ═══════════════════════════ SSP SELECTION ═══════════════════════════ -->
<div id="screen-ssp" class="screen">
<h2>Choose Your Challenge</h2>
<div class="ssp-subtitle">The baseline trajectory depends on the socioeconomic pathway the world follows.<br>Which scenario will you try to steer from?</div>
<div class="ssp-cards">
<div class="ssp-card ssp-easy" onclick="selectSSP(1)">
<div class="ssp-badge">SSP1 · EASY</div>
<div class="ssp-title">Sustainability</div>
<div class="ssp-desc">A world of low challenges and high cooperation. Poverty and hunger are already declining. Climate policy is advancing. Your reforms build on a benign baseline.</div>
<div class="ssp-trends">
<span class="ssp-trend-g">↓ Poverty −311 m/round</span>
<span class="ssp-trend-g">↓ Hunger −33 m/round</span>
<span class="ssp-trend-g">↓ AFOLU GHG −0.85 GtCO₂/round</span>
<span class="ssp-trend-y">↑ Obesity +127 m/round</span>
<span class="ssp-trend-g">↑ Wages +0.74 USD/round</span>
</div>
</div>
<div class="ssp-card ssp-medium" onclick="selectSSP(2)">
<div class="ssp-badge">SSP2 · MEDIUM</div>
<div class="ssp-title">Middle of the Road</div>
<div class="ssp-desc">Trends follow historical patterns. Some progress on development, but nitrogen and food costs keep rising. A balanced but demanding baseline.</div>
<div class="ssp-trends">
<span class="ssp-trend-g">↓ Poverty −209 m/round</span>
<span class="ssp-trend-g">↓ Hunger −15 m/round</span>
<span class="ssp-trend-r">↑ Nitrogen +9.7 Mt/round</span>
<span class="ssp-trend-y">↑ Obesity +102 m/round</span>
<span class="ssp-trend-g">↑ Wages +0.43 USD/round</span>
</div>
</div>
<div class="ssp-card ssp-hard" onclick="selectSSP(3)">
<div class="ssp-badge">SSP3 · HARD</div>
<div class="ssp-title">Regional Rivalry</div>
<div class="ssp-desc">Fragmented governance, rising nationalism, stalled development. Poverty barely falls; nitrogen and warming accelerate. Every reform faces fierce opposition.</div>
<div class="ssp-trends">
<span class="ssp-trend-r">↑ Poverty +13 m/round</span>
<span class="ssp-trend-r">↑ Hunger +17 m/round</span>
<span class="ssp-trend-r">↑ Nitrogen +18.3 Mt/round</span>
<span class="ssp-trend-r">↑ Warming +0.21 °C/round</span>
<span class="ssp-trend-r">↑ Wages only +0.21 USD/round</span>
</div>
</div>
</div>
<button class="btn-secondary" onclick="setScreen('screen-intro')">← Back</button>
</div>
<!-- ═══════════════════════════ GAME ═══════════════════════════ -->
<div id="screen-game" class="screen">
<div id="game-header">
<div class="title">🌍 The Food System Transformation Challenge</div>
<div class="hstat tip" id="h-year">
<span class="lbl">Year</span>
<span class="val" id="h-year-val">2025</span>
<span class="tip-text">Current simulation year</span>
</div>
<div class="hstat" id="h-round">
<span class="lbl">Round</span>
<span class="val" id="h-round-val">1 / 6</span>
</div>
<div class="round-dots" id="round-dots"></div>
<div class="pop-header-widget" id="h-pop">
<span class="lbl">Popularity</span>
<div class="pop-header-num-row">
<span class="pop-header-num" id="h-pop-val">60</span>
<span class="pop-header-mandate" id="h-pop-mandate">Slim Majority</span>
</div>
<div class="pop-mini-track"><div class="pop-mini-fill" id="h-pop-fill" style="width:60%;background:#f0b429"></div></div>
</div>
<div class="hstat" id="h-budget">
<span class="lbl">Policy Points</span>
<span class="val" id="h-budget-val">8</span>
</div>
<div class="hstat" id="h-ssp">
<span class="lbl">Scenario</span>
<span class="val" id="h-ssp-val" style="font-size:.95em">SSP2</span>
</div>
</div>
<div id="game-body">
<div id="mobile-tabs">
<button id="tab-state" class="mob-tab" onclick="showTab('state')">📊 Outcomes</button>
<button id="tab-policy" class="mob-tab" onclick="showTab('policy')">🎛️ Policies</button>
</div>
<!-- LEFT: indicators -->
<div id="left-panel">
<div class="panel-head">📊 System State</div>
<div id="indicators-grid"></div>
<div id="pop-chart-box">
<h4>👥 Popularity Over Time</h4>
<div id="pop-chart-svg"></div>
</div>
<div class="intro-cite" style="font-size:.7em;margin-top:8px;padding:6px 8px;">
Based on: <a href="https://www.nature.com/articles/s43016-025-01268-y" target="_blank" rel="noopener">Bodirsky et al. (2025) "A food system transformation pathway reconciles 1.5°C global warming with improved health, environment and social inclusion." <em>Nature Food</em>.</a> <br>Impact of food system measures was roughly parametrized on the study, policy points and popularity are a pure game dynamic without scientific foundation.
</div>
</div>
<!-- RIGHT: measures -->
<div id="right-panel">
<div id="measures-scroll">
<div class="panel-head">🎛️ Policy Measures</div>
<div id="measures-list"></div>
<div style="margin:8px 0 4px;padding:8px 10px;background:#1a1535;border:1px solid #4a3567;border-radius:7px;font-size:.74em;color:#bc8cff;line-height:1.45">
🌍 <strong>Cross-Sector events</strong> (Energy Transition, Bioplastics, Timber Cities; and Demographic & Human Development in SSP2/3) appear as <strong>wildcards at each round's end</strong>, drawn automatically from your SSP scenario pool.
</div>
</div>
<div id="end-round-bar">
<div class="forecast-row" id="pop-forecast-bar">Select policies to see popularity forecast</div>
<button class="btn-end-round" id="btn-end" onclick="endRound()">
Advance to 2030 →
</button>
</div>
</div>
</div>
</div>
<!-- ═══════════════════════════ WILDCARD ═══════════════════════════ -->
<div id="screen-wildcard" class="screen">
<div class="wc-screen-box">
<div class="wc-screen-eyebrow">🌍 Cross-Sector Events</div>
<h2 class="wc-screen-title">In the meanwhile, there is progress outside of the food system:</h2>
<div id="wc-screen-events"></div>
<button class="btn-primary" onclick="continueToResult()">Continue →</button>
</div>
</div>
<!-- ═══════════════════════════ RESULT ═══════════════════════════ -->
<div id="screen-result" class="screen">
<div class="result-box">
<div class="result-year" id="res-year"></div>
<div class="result-subtitle" id="res-subtitle"></div>
<div class="narrative-box" id="res-narrative"></div>
<div class="pop-section" id="res-pop-section"><!-- filled by JS --></div>
<div class="measures-taken">
<h4>Measures Implemented This Round</h4>
<div id="res-taken"></div>
</div>
<div id="res-wildcards" class="wildcard-box"></div>
<div class="changes-grid" id="res-changes"></div>
<button class="btn-primary" id="btn-next-round" onclick="nextRound()">Continue →</button>
</div>
</div>
<!-- ═══════════════════════════ FINAL ═══════════════════════════ -->
<div id="screen-final" class="screen">
<div class="final-box">
<div class="final-title" id="fin-title"></div>
<div class="final-sub" id="fin-sub">Global Food System Assessment — 2050</div>
<div class="score-ring" id="fin-ring">
<div class="score-num" id="fin-score"></div>
<div class="score-lbl">/ 100</div>
</div>
<br>
<div class="grade-tag" id="fin-grade"></div>
<div class="final-indicators" id="fin-indicators"></div>
<div class="final-msg" id="fin-msg"></div>
<div class="final-ref">
Bodirsky et al. (2025), Nature Food — research shows combining all 23 food system measures
reduces mortality by 182 million life years/year and near-halves nitrogen surplus by 2050.
</div>
<div class="final-btns">
<button class="btn-secondary" onclick="resetGame()">Play Again</button>
</div>
</div>
</div>
<!-- ═══════════════════════════ MEASURE BOTTOM SHEET (mobile) ═══════════════════════════ -->
<div id="measure-sheet-overlay" onclick="closeMeasureSheet()"></div>
<div id="measure-sheet">
<div class="ms-handle"></div>
<div id="ms-header">
<span id="ms-cat-icon"></span>
<span id="ms-name"></span>
<span id="ms-cost-badge"></span>
</div>
<div id="ms-desc"></div>
<div id="ms-fx"></div>
<div id="ms-repeat-note"></div>
<button class="ms-buy-btn" id="ms-buy-btn" onclick="sheetBuy()"></button>
</div>
<div id="tutorial-overlay">
<div id="tut-spotlight"></div>
<div id="tut-tip">
<div class="tut-title" id="tut-title"></div>
<div class="tut-body" id="tut-body"></div>
<div class="tut-footer">
<span class="tut-counter" id="tut-counter"></span>
<div class="tut-btns">
<button class="tut-skip" onclick="closeTutorial()">Skip</button>
<button class="tut-next" id="tut-next-btn" onclick="tutNext()">Next →</button>
</div>
</div>
</div>
</div>
<script>
// ═══════════════════════════════════════════════════════════════
// DATA — loaded at runtime from indicators.csv and measures.csv
// ═══════════════════════════════════════════════════════════════
let IND_DEFS = []; // populated by loadData()
let MEASURES = []; // populated by loadData()
const CAT_META = {
'Diets': { icon:'🍽️', color:'#58d68d' },
'Livelihoods': { icon:'💼', color:'#58a6ff' },
'Biosphere': { icon:'🌿', color:'#79c0ff' },
'Agriculture': { icon:'🌾', color:'#f0b429' },
'Cross-Sector': { icon:'🌍', color:'#bc8cff' },
};
const NARRATIVES = [
// round 0→1 (shown after round 1 ends)
r => {
const low = getLow();
if(low.includes('climate')) return 'Agricultural GHG emissions continue rising. AFOLU contributes over 11 GtCO₂e/year. The 1.5°C window is closing fast.';
return 'Food systems are under pressure globally. Early action is crucial to shift trajectories before 2030.';
},
r => 'The decade of action is underway. Model projections show that diet and farming changes are beginning to reduce pressure on land and water systems.',
r => 'Midpoint assessment: without the energy transition, global warming remains on track for 2°C+. Combining food system measures with cross-sector action is now critical.',
r => 'Agricultural labour markets are shifting rapidly. Structural change requires careful management of transitions in low-income regions.',
r => 'Final stretch. Biodiversity hotspots remain under pressure. Land conservation measures must be in place by 2045 to protect the most critical ecosystems.',
r => 'The 2050 assessment is complete. Your policy package has shaped the global food system. Results below reflect cumulative impacts of all implemented measures.',
];
// Built from indicators.csv by loadData()
let IND_LABELS = {};
let VOTER_WEIGHTS = {};
// ═══════════════════════════════════════════════════════════════
// CSV LOADER
// ═══════════════════════════════════════════════════════════════
function parseCSV(text) {
const lines = text.trim().split(/\r?\n/);
const headers = lines[0].split(',').map(h => h.trim());
return lines.slice(1).filter(l => l.trim()).map(line => {
const fields = [];
let cur = '', inQ = false;
for (let i = 0; i < line.length; i++) {
const c = line[i];
if (c === '"') { inQ = !inQ; }
else if (c === ',' && !inQ) { fields.push(cur); cur = ''; }
else { cur += c; }
}
fields.push(cur);
const obj = {};
headers.forEach((h, i) => { obj[h] = (fields[i] || '').trim(); });
return obj;
});
}
async function loadData() {
const errEl = document.getElementById('load-error');
try {
const [mRes, iRes] = await Promise.all([
fetch('measures.csv?v=' + Date.now()),
fetch('indicators.csv?v=' + Date.now())
]);
if (!mRes.ok || !iRes.ok) throw new Error('HTTP error');
const [mText, iText] = await Promise.all([mRes.text(), iRes.text()]);
// Build IND_DEFS from indicators.csv
IND_DEFS = parseCSV(iText).map(r => {
const d = {
id: r.id,
name: r.name,
emoji: r.emoji,
unit: r.unit,
value2000: parseFloat(r.value2000),
value2010: parseFloat(r.value2010),
start: parseFloat(r.start),
trendSSP1: parseFloat(r.trendSSP1),
trendSSP2: parseFloat(r.trendSSP2),
trendSSP3: parseFloat(r.trendSSP3),
goodThreshold: parseFloat(r.goodThreshold),
badThreshold: parseFloat(r.badThreshold),
trend: parseFloat(r.trendSSP2), // default until SSP chosen
desc: r.desc,
};
if (r.lowerBetter === 'true') d.lowerBetter = true;
return d;
});
// Derive IND_LABELS and VOTER_WEIGHTS from IND_DEFS rows
parseCSV(iText).forEach(r => {
IND_LABELS[r.id] = r.name;
VOTER_WEIGHTS[r.id] = parseFloat(r.voterWeight) || 1;
});
// Build MEASURES and SYNERGIES from measures.csv
// Effect columns = any column not in the fixed set
const fixedCols = new Set(['id','name','cat','cost','desc','synergy','popularity']);
const mRows = parseCSV(mText);
function parseEffects(r) {
const effects = {};
Object.keys(r).forEach(k => {
if (!fixedCols.has(k)) {
const v = parseFloat(r[k]);
if (!isNaN(v) && v !== 0) effects[k] = v;
}
});
return effects;
}
MEASURES = mRows
.filter(r => !r.synergy || !r.synergy.trim())
.map(r => ({ id:r.id, name:r.name, cat:r.cat, cost:parseInt(r.cost), effects:parseEffects(r), desc:r.desc, popEffect:parseFloat(r.popularity)||0 }));
document.getElementById('load-overlay').style.display = 'none';
initState();
} catch(e) {
errEl.style.display = 'block';
errEl.textContent = '⚠️ Could not load CSV files. Serve this folder via a local web server, e.g.: python -m http.server 8000 --bind 127.0.0.1 and then go to http://localhost:8000/FoodSystem2050.html';
}
}
// ═══════════════════════════════════════════════════════════════
// STATE
// ═══════════════════════════════════════════════════════════════
let state = {};
const RETIREMENT_THRESHOLD = 20; // popularity below this → forced retirement
function generateWildcardSchedule(sspChoice) {
const universalIds = ['EnergyTrans', 'Bioplastics', 'TimberCities'];
const allIds = ['Population', 'HumanDevelop', 'EnergyTrans', 'Bioplastics', 'TimberCities'];
const eligibleIds = sspChoice === 1 ? universalIds : allIds;
// Each measure can be drawn up to 3 times
const pool = [];
eligibleIds.forEach(id => { pool.push(id, id, id); });
// Total draws per SSP: SSP1=9 (all), SSP2=8, SSP3=4
const totalDraws = sspChoice === 1 ? 9 : sspChoice === 2 ? 8 : 4;
// Shuffle pool and pick
const shuffled = pool.slice().sort(() => Math.random() - 0.5);
const chosen = shuffled.slice(0, Math.min(totalDraws, shuffled.length));
// Assign each draw randomly to a round (1–6)
const schedule = {1:[],2:[],3:[],4:[],5:[],6:[]};
chosen.forEach(id => { schedule[Math.ceil(Math.random() * 6)].push(id); });
return schedule;
}
function initState(sspChoice) {
sspChoice = sspChoice || 2;
// Apply SSP-specific trend to each indicator
IND_DEFS.forEach(d => { d.trend = d['trendSSP' + sspChoice]; });
const indicators = {};
IND_DEFS.forEach(d => { indicators[d.id] = d.start; });
state = {
round: 1,
budget: 8,
popularity: 60,
sspChoice,
lastPopDelta: null,
indicators,
history: [{ year: 2020, indicators: {...indicators} }],
popHistory: [60], // popularity at start of each round (for sparkline)
purchaseCounts: {}, // lifetime counts per measure (for synergy logic)
selectedCounts: {}, // this-round selections: measureId → count
prevIndicators: {...indicators},
wildcardCounts: {},
wildcardSchedule: generateWildcardSchedule(sspChoice),
collapsed: window.innerWidth <= 520
? Object.fromEntries([...new Set(MEASURES.map(m=>m.cat))].filter(c=>c!=='Cross-Sector').map(c=>[c,true]))
: {},
retired: false,
};
}
// Cost of one more unit of measure m (given current selectedCounts)
function nextUnitCost(m) {
const priorPurchases = state.purchaseCounts[m.id] || 0;
const thisRound = state.selectedCounts[m.id] || 0;
return m.cost * (priorPurchases + thisRound + 1);
}
// ── Popularity helpers ──────────────────────────────────────────
function budgetFromPopularity(pop) {
if(pop >= 80) return 12; // landslide
if(pop >= 65) return 10; // strong majority
if(pop >= 50) return 8; // slim majority
if(pop >= 35) return 6; // coalition
if(pop >= 20) return 4; // minority govt
return 3; // caretaker
}
function mandateLabel(pop) {
if(pop >= 80) return 'Landslide';
if(pop >= 65) return 'Strong Majority';
if(pop >= 50) return 'Slim Majority';
if(pop >= 35) return 'Coalition';
if(pop >= 20) return 'Minority Govt';
return 'Gov\'t in Crisis';
}
function mandateColor(pop) {
if(pop >= 65) return '#58d68d';
if(pop >= 35) return '#f0b429';
return '#f85149';
}
// Shared popularity computation — pass indicator snapshot and whether to apply measure preview
function _popParts(indicators) {
const activeDefs = IND_DEFS.filter(d => d.id !== 'vestedInterests');
const totalW = activeDefs.reduce((s, d) => s + (VOTER_WEIGHTS[d.id] || 1), 0);
let levelPart = 0, tendencyPart = 0;
activeDefs.forEach(d => {
const w = VOTER_WEIGHTS[d.id] || 1;
const wf = w / totalW; // normalised weight
const norm = normalizeInd(indicators[d.id], d);
// Level: below 0.35 = bad zone (penalise), above 0.7 = good zone (reward)
if(norm < 0.35) levelPart -= (0.35 - norm) / 0.35 * wf * 60;
else if(norm > 0.7) levelPart += (norm - 0.7) / 0.3 * wf * 10;
// Tendency: did this indicator improve or worsen vs previous round?
const prev = state.prevIndicators ? state.prevIndicators[d.id] : null;
if(prev !== null && prev !== undefined) {
const tRange = Math.abs(d.goodThreshold - d.badThreshold);
if(tRange > 0) {
const change = indicators[d.id] - prev;
const normT = (d.lowerBetter ? -change : change) / tRange;
tendencyPart += normT * wf * 100;
}
}
});
return {
levelPart: Math.round(levelPart * 10) / 10,
tendencyPart: Math.round(tendencyPart * 10) / 10,
};
}
// Full delta calculation after a round ends
function calcPopularityDelta(directPart) {
const { levelPart, tendencyPart } = _popParts(state.indicators);
directPart = Math.round((directPart || 0) * 10) / 10;
return {
levelPart,
tendencyPart,
directPart,
total: Math.round((levelPart + tendencyPart + directPart + 10) * 10) / 10,
};
}
// Estimate delta for forecast bar (current selections pre-applied)
function previewPopDelta() {
// Build a projected indicator snapshot with selected measures applied
const proj = { ...state.indicators };
Object.entries(state.selectedCounts).forEach(([id, cnt]) => {
if(cnt <= 0) return;
const m = MEASURES.find(m => m.id === id);
if(!m) return;
Object.entries(m.effects).forEach(([ind, val]) => {
proj[ind] = (proj[ind] || 0) + val * cnt;
});
});
IND_DEFS.forEach(d => { proj[d.id] = (proj[d.id] || 0) + d.trend; });
let directPop = 0;
Object.entries(state.selectedCounts).forEach(([id, cnt]) => {
if(cnt <= 0) return;
const m = MEASURES.find(m => m.id === id);
if(m) directPop += (m.popEffect || 0) * cnt;
});
const { levelPart, tendencyPart } = _popParts(proj);
return { total: Math.round((levelPart + tendencyPart + directPop) * 10) / 10 };
}
// ═══════════════════════════════════════════════════════════════
// GAUGE MATH
// ═══════════════════════════════════════════════════════════════
// Normalise indicator to [0,1]: 0 = at/beyond bad, 1 = at/beyond good
function normalizeInd(val, d) {
const range = Math.abs(d.goodThreshold - d.badThreshold);
if(range === 0) return 0.5;
const raw = d.lowerBetter
? (d.badThreshold - val) / range
: (val - d.badThreshold) / range;
return Math.max(0, Math.min(1, raw));
}
// Per-indicator clamp (allows afoluGHG to go negative)
function clampInd(val, d) {
if(d.id === 'afoluGHG') return Math.max(-20, val);
if(d.id === 'croplandBII' || d.id === 'hotspotBII') return Math.max(0, Math.min(100, val));
return Math.max(0, val);
}
// Colour based on per-indicator thresholds
// Green = met goodThreshold, yellow = between thresholds, red = past badThreshold
function indColor(val, d) {
if (d.lowerBetter) {
if (val <= d.goodThreshold) return '#58d68d';
if (val <= d.badThreshold) return '#f0b429';
return '#f85149';
} else {
if (val >= d.goodThreshold) return '#58d68d';
if (val >= d.badThreshold) return '#f0b429';
return '#f85149';
}
}
// ═══════════════════════════════════════════════════════════════
// RENDER
// ═══════════════════════════════════════════════════════════════
function renderGame() {
renderHeader();
renderIndicators();
renderPopChart();
renderMeasures();
renderEndBtn();
if (window.innerWidth <= 520) showTab('policy');
}
function renderPopChart() {
const W = 440, H = 56, xL = 6, xR = 434, yT = 4, yB = 48;