-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.html
More file actions
1748 lines (1670 loc) · 111 KB
/
Index.html
File metadata and controls
1748 lines (1670 loc) · 111 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>Vital Vortex — Macro Tracker</title>
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&family=Orbitron:wght@600;800&display=swap" rel="stylesheet">
<style>
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
/* Lisa Frank neons on space darks */
--pink: #2D0A2E; --pink-mid: #FF2D9B; --pink-dark: #FF80CC;
--mint: #071A2E; --mint-mid: #00FFD4; --mint-dark: #7FFFEE;
--peach: #1A0A2E; --peach-mid: #BF5FFF; --peach-dark: #E0AAFF;
--lavender: #120827; --lav-mid: #A855F7; --lav-dark: #E0AAFF;
--amber-light: #1A1000; --amber-mid: #FFD600; --amber-dark: #FFE97A;
--blue-light: #050D1F; --blue-mid: #00B4FF; --blue-dark: #80DAFF;
--green-light: #071A14; --green-mid: #00FFA3; --green-dark: #80FFD4;
--bg: #070B1A; --card: #0F1629; --border: rgba(168,85,247,0.18);
--text: #F0E6FF; --muted: #8B7FAB;
--radius: 12px; --radius-sm: 8px;
--vv-accent: #BF5FFF; --vv-accent2: #00FFD4;
--star1: #FF2D9B; --star2: #00FFD4; --star3: #FFD600; --star4: #00B4FF;
}
html { font-size: 16px; }
body { font-family: 'Nunito', sans-serif; background: var(--bg); color: var(--text); font-size: 1rem; line-height: 1.4; background-image: radial-gradient(ellipse at 20% 30%, rgba(191,95,255,0.08) 0%, transparent 60%), radial-gradient(ellipse at 80% 70%, rgba(0,180,255,0.07) 0%, transparent 60%); background-attachment: fixed; }
.app { max-width: 680px; margin: 0 auto; padding: 0 0 100px; }
/* Top bar */
.top-bar { background: var(--card); border-bottom: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; }
.app-title { font-family: 'Orbitron', monospace; font-size: 18px; font-weight: 800; background: linear-gradient(90deg, #FF2D9B, #BF5FFF, #00FFD4); -webkit-background-clip: text; -webkit-text-fill-color: transparent; letter-spacing: 1px; }
.vv-header-sub { font-size: 10px; color: var(--muted); font-family: 'Orbitron', monospace; letter-spacing: 1px; margin-top: 1px; }
.sync-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: #444; }
.sync-dot.synced { background: #00FFD4; }
.sync-dot.syncing { background: #FFD600; animation: pulse 1s infinite; }
.sync-dot.error { background: #FF2D9B; }
@keyframes pulse { 0%,100%{opacity:1}50%{opacity:.4} }
.date-display { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 2px; }
/* Nav */
.nav { display: flex; padding: 0 4px; background: var(--card); position: sticky; top: 57px; z-index: 99; border-bottom: 1px solid var(--border); overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav-btn { flex: 0 0 auto; padding: 13px 14px; border: none; background: transparent; border-bottom: 3px solid transparent; font-size: 13px; font-weight: 700; color: var(--muted); cursor: pointer; transition: all .2s; text-align: center; font-family: 'Nunito', sans-serif; white-space: nowrap; }
.nav-btn.active { color: var(--vv-accent); border-bottom-color: var(--vv-accent); }
/* Pages */
.page { display: none; padding: 16px 16px; }
.page.active { display: block; }
.section-title { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin: 16px 0 8px; }
/* Water bar */
.water-bar { background: var(--blue-light); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.water-bar-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.water-label { font-size: 11px; color: var(--blue-dark); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.water-oz { font-size: 12px; color: var(--blue-dark); font-weight: 700; white-space: nowrap; }
.water-track { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-start; }
.water-cup-btn { background: transparent; border: none; cursor: pointer; padding: 2px; transition: transform .15s; position: relative; }
.water-cup-btn:active { transform: scale(.92); }
/* Macro fill cards */
.daily-totals { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 6px; margin-bottom: 12px; }
.macro-card { position: relative; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 8px 8px; text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; overflow: hidden; background: var(--card); height: 80px; }
.macro-card.cal { border-top: 3px solid #FF2D2D; }
.macro-card.fat { border-top: 3px solid #FF7A00; }
.macro-card.carb { border-top: 3px solid #FFD600; }
.macro-card.fiber { border-top: 3px solid #00DD44; }
.macro-card.sugar { border-top: 3px solid #00B4FF; }
.macro-card.protein{ border-top: 3px solid #BF5FFF; }
.macro-card > * { position: relative; z-index: 1; }
.macro-val { font-size: 20px; font-weight: 800; color: var(--text); line-height: 1.1; }
.macro-goal-lbl { font-size: 9px; color: var(--muted); font-weight: 600; }
.macro-lbl { font-size: 10px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
/* Black hole card */
.macro-card.blackhole { border: 2px solid #1a0033; background: #000 !important; }
.macro-card.blackhole .macro-val { color: transparent; text-shadow: none; }
.macro-card.blackhole .macro-goal-lbl { color: transparent; }
.macro-card.blackhole .macro-lbl { color: rgba(80,0,120,0.6); }
@keyframes blackholePull {
0% { transform: scale(1) rotate(0deg); filter: brightness(1); }
40% { transform: scale(0.97) rotate(-1deg); filter: brightness(0.7); }
100% { transform: scale(1) rotate(0deg); filter: brightness(1); }
}
@keyframes spaghetti {
0% { transform: scaleX(1) scaleY(1) translateY(0); opacity: 1; }
60% { transform: scaleX(0.3) scaleY(1.6) translateY(4px); opacity: 0.5; }
100% { transform: scaleX(0.05) scaleY(2) translateY(8px); opacity: 0; }
}
/* Protein goal */
.protein-goal-bar { background: var(--mint); border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.protein-goal-track { flex: 1; height: 10px; background: rgba(0,0,0,0.08); border-radius: 5px; overflow: hidden; }
.protein-goal-fill { height: 100%; background: var(--mint-mid); border-radius: 5px; transition: width .4s ease; }
.protein-goal-fill.done { background: #00FFD4; }
.protein-goal-label { font-size: 12px; font-weight: 700; color: var(--mint-dark); white-space: nowrap; }
.protein-goal-edit { font-size: 12px; font-weight: 700; color: var(--mint-dark); background: transparent; border: none; cursor: pointer; text-decoration: underline; font-family: 'Nunito', sans-serif; padding: 0; white-space: nowrap; }
@keyframes dropRise {
0% { transform: translateY(0) translateX(0) scale(1); opacity: 1; }
70% { opacity: 1; }
100% { transform: translateY(-85vh) translateX(var(--drift)) scale(0.4); opacity: 0; }
}
@keyframes waveRise {
0% { height: 0; opacity: 0; }
15% { opacity: 1; }
60% { height: 38vh; }
100% { height: 32vh; opacity: 0; }
}
@keyframes waveRise2 {
0% { height: 0; opacity: 0; }
15% { opacity: 1; }
60% { height: 28vh; }
100% { height: 22vh; opacity: 0; }
}
@keyframes msgPop {
0% { opacity: 0; transform: translateX(-50%) translateY(12px); }
100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}
/* Meals */
.meals-grid { display: flex; flex-direction: column; gap: 10px; }
.meal-card { background: var(--card); border-radius: var(--radius); overflow: hidden; }
/* m0 Breakfast — hot pink */
.m0 { border: 1.5px solid #FF2D9B; }
.m0 .meal-header { background: linear-gradient(135deg, #2D0A1E 0%, #1a0510 100%); border-bottom: 1px solid rgba(255,45,155,0.4); }
.m0 .meal-name { color: #FF80CC; }
.m0 .meal-cals { color: #FF2D9B; }
.m0 .meal-badge { background: rgba(255,45,155,0.25); font-size: 20px; }
/* m1 Morning Snack — cyan */
.m1 { border: 1.5px solid #00FFD4; }
.m1 .meal-header { background: linear-gradient(135deg, #041A18 0%, #020e0c 100%); border-bottom: 1px solid rgba(0,255,212,0.4); }
.m1 .meal-name { color: #7FFFEE; }
.m1 .meal-cals { color: #00FFD4; }
.m1 .meal-badge { background: rgba(0,255,212,0.2); font-size: 20px; }
/* m2 Lunch — rainbow / gold */
.m2 { border: 1.5px solid #FFD600; }
.m2 .meal-header { background: linear-gradient(135deg, #1A1400 0%, #0e0b00 100%); border-bottom: 1px solid rgba(255,214,0,0.4); }
.m2 .meal-name { color: #FFE97A; }
.m2 .meal-cals { color: #FFD600; }
.m2 .meal-badge { background: rgba(255,214,0,0.2); font-size: 20px; }
/* m3 Afternoon Snack — electric purple */
.m3 { border: 1.5px solid #BF5FFF; }
.m3 .meal-header { background: linear-gradient(135deg, #150827 0%, #0a0414 100%); border-bottom: 1px solid rgba(191,95,255,0.4); }
.m3 .meal-name { color: #E0AAFF; }
.m3 .meal-cals { color: #BF5FFF; }
.m3 .meal-badge { background: rgba(191,95,255,0.25); font-size: 20px; }
/* m4 Dinner — electric blue */
.m4 { border: 1.5px solid #00B4FF; }
.m4 .meal-header { background: linear-gradient(135deg, #021420 0%, #010a14 100%); border-bottom: 1px solid rgba(0,180,255,0.4); }
.m4 .meal-name { color: #80DAFF; }
.m4 .meal-cals { color: #00B4FF; }
.m4 .meal-badge { background: rgba(0,180,255,0.2); font-size: 20px; }
.meal-header { padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; }
.meal-name { font-weight: 700; font-size: 15px; }
.meal-cals { font-size: 13px; font-weight: 600; }
.meal-badge { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.meal-body { padding: 0 16px 14px; border-top: 1px solid rgba(255,255,255,0.06); }
.food-item { display: flex; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.food-item:last-child { border-bottom: none; }
.food-name { font-weight: 700; font-size: 14px; flex: 1; }
.food-portion { font-size: 12px; color: var(--muted); margin-top: 2px; }
.remove-btn { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); background: transparent; cursor: pointer; color: var(--muted); font-size: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.remove-btn:active { background: rgba(255,45,155,0.15); color: #FF2D9B; }
.add-food-btn { margin-top: 10px; width: 100%; padding: 12px; border: 1.5px dashed var(--border); border-radius: var(--radius-sm); background: transparent; color: var(--muted); font-size: 14px; font-weight: 700; cursor: pointer; transition: all .15s; font-family: 'Nunito', sans-serif; }
.add-food-btn:active { border-color: var(--lav-mid); color: var(--lav-dark); background: var(--lavender); }
.clear-day-btn { width: 100%; padding: 13px; background: var(--peach); border: none; border-radius: var(--radius-sm); color: var(--peach-dark); font-weight: 700; font-size: 14px; cursor: pointer; font-family: 'Nunito', sans-serif; margin-bottom: 14px; }
.clear-day-btn:active { background: var(--peach-mid); color: #fff; }
/* Food picker */
.food-picker { position: fixed; inset: 0; background: rgba(2,4,20,0.75); z-index: 200; display: flex; align-items: flex-end; justify-content: center; }
.food-picker-inner { background: var(--card); border-radius: var(--radius) var(--radius) 0 0; width: 100%; max-width: 680px; max-height: 80vh; overflow-y: auto; padding: 16px 16px 50px; -webkit-overflow-scrolling: touch; }
.picker-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; }
.picker-search { width: 100%; padding: 13px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 16px; margin-bottom: 10px; outline: none; font-family: 'Nunito', sans-serif; }
.picker-search:focus { border-color: var(--lav-mid); }
.picker-item { display: flex; align-items: center; justify-content: space-between; padding: 13px 0; border-bottom: none; cursor: pointer; }
.picker-item:active { background: var(--lavender); margin: 0 -16px; padding: 13px 16px; }
.picker-item.expanded { background: var(--lavender); margin: 0 -16px; padding: 13px 16px; border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.picker-food-name { font-weight: 700; font-size: 14px; }
.picker-food-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.picker-qty-row { display: none; align-items: center; justify-content: space-between; padding: 10px 16px 13px; margin: 0 -16px; background: var(--lavender); border-radius: 0 0 var(--radius-sm) var(--radius-sm); border-top: 1px solid rgba(168,85,247,0.25); margin-bottom: 1px; gap: 10px; border-bottom: 1px solid var(--border); }
.picker-qty-row.open { display: flex; }
.picker-qty-controls { display: flex; align-items: center; gap: 0; background: var(--card); border: 1px solid var(--lav-mid); border-radius: var(--radius-sm); overflow: hidden; }
.picker-qty-btn { width: 38px; height: 38px; border: none; background: transparent; color: var(--lav-dark); font-size: 22px; font-weight: 700; cursor: pointer; font-family: 'Nunito', sans-serif; display: flex; align-items: center; justify-content: center; }
.picker-qty-btn:active { background: rgba(168,85,247,0.2); }
.picker-qty-num { min-width: 36px; text-align: center; font-size: 18px; font-weight: 800; color: var(--text); padding: 0 4px; }
.picker-qty-add { flex: 1; padding: 10px 0; background: var(--vv-accent); border: none; border-radius: var(--radius-sm); color: #fff; font-weight: 700; font-size: 14px; cursor: pointer; font-family: 'Nunito', sans-serif; text-align: center; }
.picker-close { float: right; border: none; background: transparent; font-size: 28px; cursor: pointer; color: var(--muted); margin-top: -6px; font-family: 'Nunito', sans-serif; padding: 4px 8px; }
/* Menu */
.menu-search { width: 100%; padding: 13px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 16px; margin-bottom: 12px; outline: none; font-family: 'Nunito', sans-serif; }
.menu-search:focus { border-color: var(--lav-mid); }
.menu-list { display: flex; flex-direction: column; gap: 8px; }
.menu-item-row { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.menu-item-view { padding: 13px 14px; display: flex; align-items: center; gap: 10px; }
.menu-item-info { flex: 1; min-width: 0; }
.menu-item-name { font-weight: 700; font-size: 14px; }
.menu-item-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.menu-item-actions { display: flex; gap: 8px; flex-shrink: 0; }
.edit-btn { border: 1px solid var(--border); background: var(--lavender); color: var(--lav-dark); cursor: pointer; font-size: 13px; font-weight: 700; padding: 8px 12px; border-radius: var(--radius-sm); font-family: 'Nunito', sans-serif; }
.edit-btn:active { background: var(--lav-mid); color: #fff; }
.menu-delete { border: 1px solid var(--border); background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; padding: 8px 10px; border-radius: var(--radius-sm); font-family: 'Nunito', sans-serif; }
.menu-delete:active { background: rgba(255,45,155,0.15); color: #FF2D9B; }
.menu-item-edit { padding: 14px; background: var(--lavender); border-top: 1px solid var(--border); display: none; }
.menu-item-edit.open { display: block; }
.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.edit-group { display: flex; flex-direction: column; gap: 4px; }
.edit-group.full { grid-column: 1/-1; }
.edit-label { font-size: 11px; font-weight: 700; color: var(--lav-dark); text-transform: uppercase; letter-spacing: .4px; }
.edit-input { padding: 11px 12px; border: 1px solid var(--lav-mid); border-radius: var(--radius-sm); font-size: 15px; outline: none; width: 100%; font-family: 'Nunito', sans-serif; background: #fff; }
.edit-input:focus { border-color: var(--vv-accent); }
.edit-actions { display: flex; gap: 8px; margin-top: 12px; }
.save-edit-btn { flex: 1; padding: 12px; background: var(--vv-accent); border: none; border-radius: var(--radius-sm); color: #fff; font-weight: 700; font-size: 14px; cursor: pointer; font-family: 'Nunito', sans-serif; }
.cancel-edit-btn { padding: 12px 16px; background: transparent; border: 1px solid var(--lav-mid); border-radius: var(--radius-sm); color: var(--lav-dark); font-weight: 700; font-size: 14px; cursor: pointer; font-family: 'Nunito', sans-serif; }
/* Add food */
.add-form { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.form-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; color: var(--lav-dark); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full { grid-column: 1/-1; }
.form-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.form-input { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 15px; outline: none; width: 100%; font-family: 'Nunito', sans-serif; }
.form-input:focus { border-color: var(--lav-mid); }
.submit-btn { margin-top: 14px; width: 100%; padding: 14px; background: var(--lavender); border: none; border-radius: var(--radius-sm); color: var(--lav-dark); font-weight: 700; font-size: 15px; cursor: pointer; font-family: 'Nunito', sans-serif; }
.submit-btn:active { background: var(--lav-mid); color: #fff; }
.scanner-box { background: var(--mint); border-radius: var(--radius); padding: 16px; margin-top: 10px; text-align: center; }
.scanner-title { font-size: 14px; font-weight: 700; color: var(--mint-dark); margin-bottom: 6px; }
.scanner-sub { font-size: 13px; color: var(--mint-dark); opacity: .7; }
/* History / Calendar */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-nav-btn { border: 1px solid var(--border); background: var(--card); border-radius: var(--radius-sm); padding: 8px 18px; font-size: 16px; cursor: pointer; font-family: 'Nunito', sans-serif; font-weight: 700; color: var(--text); }
.cal-nav-btn:active { background: var(--lavender); color: var(--lav-dark); }
.cal-month-label { font-size: 15px; font-weight: 700; color: var(--text); }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap: 3px; margin-bottom: 12px; }
.cal-day-header { text-align: center; font-size: 10px; font-weight: 700; color: var(--muted); padding: 4px 0; text-transform: uppercase; letter-spacing: .4px; }
.cal-day { height: 38px; border-radius: var(--radius-sm); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: var(--muted); background: transparent; cursor: default; position: relative; }
.cal-day.has-log { background: var(--lavender); color: var(--lav-dark); cursor: pointer; }
.cal-day.has-log:active { background: var(--lav-mid); color: #fff; }
.cal-day.today { border: 2px solid var(--vv-accent); color: var(--vv-accent); font-weight: 800; }
.cal-day.today.has-log { background: var(--lavender); }
.cal-day.selected { background: var(--vv-accent); color: #fff; }
.cal-day.empty { visibility: hidden; }
.cal-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--vv-accent); margin-top: 2px; }
.cal-day.selected .cal-dot { background: #fff; }
.log-detail { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.log-detail-date { font-size: 14px; font-weight: 700; color: var(--lav-dark); margin-bottom: 10px; }
.log-macros { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; margin-bottom: 10px; }
.log-water { background: var(--blue-light); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; color: var(--blue-dark); font-weight: 600; }
.log-edit-btn { margin-top: 10px; width: 100%; padding: 11px; background: var(--lavender); border: none; border-radius: var(--radius-sm); color: var(--lav-dark); font-weight: 700; font-size: 13px; cursor: pointer; font-family: 'Nunito', sans-serif; }
.log-edit-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; margin: 12px 0; }
.log-edit-group { display: flex; flex-direction: column; gap: 4px; }
.log-edit-label { font-size: 11px; font-weight: 700; color: var(--lav-dark); text-transform: uppercase; letter-spacing: .4px; }
.log-edit-input { padding: 11px 12px; border: 1px solid var(--lav-mid); border-radius: var(--radius-sm); font-size: 15px; outline: none; width: 100%; font-family: 'Nunito', sans-serif; background: #fff; }
.log-edit-input:focus { border-color: var(--vv-accent); }
.log-edit-actions { display: flex; gap: 8px; margin-top: 4px; }
.log-save-btn { flex: 1; padding: 12px; background: var(--vv-accent); border: none; border-radius: var(--radius-sm); color: #fff; font-weight: 700; font-size: 14px; cursor: pointer; font-family: 'Nunito', sans-serif; }
.log-cancel-btn { padding: 12px 16px; background: transparent; border: 1px solid var(--lav-mid); border-radius: var(--radius-sm); color: var(--lav-dark); font-weight: 700; font-size: 14px; cursor: pointer; font-family: 'Nunito', sans-serif; }
.no-log-msg { text-align: center; padding: 30px 20px; color: var(--muted); font-size: 14px; }
.loading-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 80px 20px; gap: 16px; }
.loading-title { font-family: 'Orbitron', monospace; font-size: 14px; font-weight: 600; color: var(--vv-accent); }
.loading-sub { font-size: 14px; color: var(--muted); }
.spinner { width: 40px; height: 40px; border: 3px solid var(--lavender); border-top-color: var(--vv-accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%); background: #1A0A2E; color: #E0AAFF; border: 1px solid rgba(191,95,255,0.4); padding: 12px 22px; border-radius: 24px; font-size: 14px; font-weight: 600; z-index: 300; opacity: 0; transition: opacity .3s; pointer-events: none; white-space: nowrap; }
.toast.show { opacity: 1; }
/* Theme dropdown */
.theme-select { background: rgba(191,95,255,0.12); border: 1px solid rgba(191,95,255,0.35); color: var(--text); font-family: 'Nunito', sans-serif; font-size: 11px; font-weight: 700; border-radius: 8px; padding: 4px 8px; cursor: pointer; outline: none; }
.theme-select option { background: #1a0a2e; color: #F0E6FF; }
/* Desktop tweaks */
@media (min-width: 600px) {
.daily-totals { grid-template-columns: repeat(6, minmax(0,1fr)); }
.log-macros { grid-template-columns: repeat(6, minmax(0,1fr)); }
.log-edit-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
.nav-btn { flex: 1; }
}
</style>
</head>
<body>
<div class="app">
<div class="top-bar">
<div>
<div class="app-title">VITAL VORTEX</div>
<div class="vv-header-sub">MACRO TRACKER</div>
</div>
<div style="display:flex;flex-direction:column;align-items:flex-end;gap:4px">
<div style="display:flex;align-items:center;gap:8px">
<button onclick="openProfile()" style="background:transparent;border:none;cursor:pointer;font-size:18px;padding:2px 4px;opacity:0.7" title="My Profile">⚙️</button>
<div class="sync-status"><div class="sync-dot" id="syncDot"></div><span id="syncLabel">connecting...</span></div>
</div>
<div class="date-display" id="dateDisplay"></div>
</div>
</div>
<div class="nav">
<button class="nav-btn active" onclick="showPage('planner',this)">Today</button>
<button class="nav-btn" onclick="showPage('tomorrow',this)">Tomorrow</button>
<button class="nav-btn" onclick="showPage('history',this)">History</button>
<button class="nav-btn" onclick="showPage('menu',this)">Menu</button>
</div>
<!-- PLANNER -->
<div class="page active" id="page-planner">
<div id="plannerContent">
<div class="loading-screen">
<div class="spinner"></div>
<div class="loading-title">LOADING</div>
<div class="loading-sub">Starting up Vital Vortex...</div>
</div>
</div>
</div>
<!-- TOMORROW -->
<div class="page" id="page-tomorrow">
<div id="tomorrowContent"></div>
</div>
<!-- HISTORY -->
<div class="page" id="page-history">
<div class="cal-nav">
<button class="cal-nav-btn" onclick="changeMonth(-1)">←</button>
<div class="cal-month-label" id="calMonthLabel"></div>
<button class="cal-nav-btn" onclick="changeMonth(1)">→</button>
</div>
<div class="cal-grid" id="calGrid"></div>
<div id="logDetail"><div class="no-log-msg">Tap a highlighted date to view that day's summary.</div></div>
</div>
<!-- MENU -->
<div class="page" id="page-menu">
<input class="menu-search" id="menuSearch" placeholder="Search menu..." oninput="renderMenu()">
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:8px">
<div class="section-title" style="margin:0">All Foods (<span id="menuCount">0</span>)</div>
<button onclick="toggleMenuAddForm()" id="menuAddToggle" style="background:var(--lavender);border:1px solid var(--lav-mid);color:var(--lav-dark);font-family:'Nunito',sans-serif;font-size:12px;font-weight:700;padding:6px 12px;border-radius:var(--radius-sm);cursor:pointer">✦ Add New Food</button>
</div>
<div id="menuAddForm" style="display:none;background:var(--lavender);border:1px solid rgba(168,85,247,0.3);border-radius:var(--radius);padding:14px;margin-bottom:12px">
<div class="form-grid">
<div class="form-group full"><div class="form-label">Food Name</div><input class="form-input" id="mf-name" placeholder="e.g. Greek Yogurt"></div>
<div class="form-group full"><div class="form-label">Portion Size</div><input class="form-input" id="mf-portion" placeholder="e.g. 1 cup (227g)"></div>
<div class="form-group"><div class="form-label">Calories</div><input class="form-input" id="mf-cal" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Fat (g)</div><input class="form-input" id="mf-fat" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Carbs (g)</div><input class="form-input" id="mf-carb" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Fiber (g)</div><input class="form-input" id="mf-fiber" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Sugar (g)</div><input class="form-input" id="mf-sugar" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Protein (g)</div><input class="form-input" id="mf-protein" type="number" min="0" placeholder="0"></div>
</div>
<div style="display:flex;gap:8px;margin-top:12px">
<button onclick="addFoodFromMenu()" style="flex:1;padding:12px;background:var(--vv-accent);border:none;border-radius:var(--radius-sm);color:#fff;font-weight:700;font-size:14px;cursor:pointer;font-family:'Nunito',sans-serif">✦ Save to Menu</button>
<button onclick="toggleMenuAddForm()" style="padding:12px 16px;background:transparent;border:1px solid var(--lav-mid);border-radius:var(--radius-sm);color:var(--lav-dark);font-weight:700;font-size:14px;cursor:pointer;font-family:'Nunito',sans-serif">Cancel</button>
</div>
</div>
<div class="menu-list" id="menuList"></div>
</div>
<!-- ADD FOOD -->
<div class="page" id="page-add">
<div class="add-form">
<div class="form-title">Add New Food to Menu</div>
<div class="form-grid">
<div class="form-group full"><div class="form-label">Food Name</div><input class="form-input" id="f-name" placeholder="e.g. Greek Yogurt"></div>
<div class="form-group full"><div class="form-label">Portion Size</div><input class="form-input" id="f-portion" placeholder="e.g. 1 cup (227g)"></div>
<div class="form-group"><div class="form-label">Calories</div><input class="form-input" id="f-cal" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Fat (g)</div><input class="form-input" id="f-fat" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Carbs (g)</div><input class="form-input" id="f-carb" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Fiber (g)</div><input class="form-input" id="f-fiber" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Sugar (g)</div><input class="form-input" id="f-sugar" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Protein (g)</div><input class="form-input" id="f-protein" type="number" min="0" placeholder="0"></div>
</div>
<button class="submit-btn" onclick="addFood()">✦ Add to Menu</button>
</div>
<div class="scanner-box">
<div class="scanner-title">📷 Nutrition Label Scanner</div>
<div class="scanner-sub">Camera scanning coming in a future update.</div>
</div>
</div>
</div>
<!-- PROFILE PANEL -->
<div id="profileOverlay" style="display:none;position:fixed;inset:0;background:rgba(2,4,20,0.75);z-index:200;display:none;align-items:flex-end;justify-content:center">
<div style="background:var(--card);border-radius:var(--radius) var(--radius) 0 0;width:100%;max-width:680px;max-height:85vh;overflow-y:auto;padding:16px 16px 50px;-webkit-overflow-scrolling:touch">
<button onclick="closeProfile()" style="float:right;border:none;background:transparent;font-size:28px;cursor:pointer;color:var(--muted);margin-top:-6px;font-family:'Nunito',sans-serif;padding:4px 8px">×</button>
<div style="padding:0" id="page-profile">
<div class="add-form" style="border-color:rgba(191,95,255,0.3)">
<div class="form-title">My Profile</div>
<div class="section-title" style="margin-top:0;margin-bottom:8px">App Style</div>
<select class="theme-select" id="themeSelect" onchange="applyTheme(this.value)" style="width:100%;padding:10px 12px;font-size:13px;margin-bottom:8px">
<option value="cosmic-lisa-frank">🌌 Cosmic Lisa Frank</option>
</select>
<div class="section-title" style="margin-bottom:8px">Body Stats</div>
<div class="form-grid">
<div class="form-group"><div class="form-label">Age</div><input class="form-input" id="p-age" type="number" min="1" placeholder="38"></div>
<div class="form-group"><div class="form-label">Height (inches)</div><input class="form-input" id="p-height" type="number" min="1" placeholder="63"></div>
<div class="form-group"><div class="form-label">Current Weight (lbs)</div><input class="form-input" id="p-weight" type="number" min="1" placeholder="194"></div>
<div class="form-group"><div class="form-label">Goal Weight (lbs)</div><input class="form-input" id="p-goal" type="number" min="1" placeholder="165"></div>
<div class="form-group full"><div class="form-label">Activity Level</div>
<select class="form-input" id="p-activity" style="cursor:pointer">
<option value="1.2">Sedentary (desk job, little exercise)</option>
<option value="1.375" selected>Lightly Active (light exercise 1-3x/wk)</option>
<option value="1.55">Moderately Active (exercise 3-5x/wk)</option>
<option value="1.725">Very Active (hard exercise 6-7x/wk)</option>
</select>
</div>
<div class="form-group full"><div class="form-label">Weekly Loss Goal</div>
<select class="form-input" id="p-rate" style="cursor:pointer">
<option value="250">0.5 lbs/week (mild deficit)</option>
<option value="500">1 lb/week (moderate deficit)</option>
<option value="750">1.5 lbs/week</option>
<option value="1000">2 lbs/week</option>
<option value="1500" selected>3 lbs/week (aggressive)</option>
</select>
</div>
</div>
<button class="submit-btn" onclick="saveProfile()" style="background:var(--vv-accent);color:#fff;margin-top:16px">✦ Recalculate My Goals</button>
</div>
<div id="profileResults" style="margin-top:4px"></div>
</div>
</div></div>
<!-- Food Picker -->
<div class="food-picker" id="foodPicker" style="display:none">
<div class="food-picker-inner">
<button class="picker-close" onclick="closePicker()">×</button>
<div class="picker-title" id="pickerTitle">Add food to meal</div>
<input class="picker-search" id="pickerSearch" placeholder="Search foods..." oninput="renderPickerItems()">
<div id="pickerItems"></div>
<div id="pickerInlineAdd" style="display:none;padding-top:4px">
<div style="font-size:13px;font-weight:700;color:var(--lav-dark);margin-bottom:12px">✦ New food — saves to menu & adds to meal</div>
<div class="form-grid">
<div class="form-group full"><div class="form-label">Food Name</div><input class="form-input" id="pia-name" placeholder="e.g. Greek Yogurt"></div>
<div class="form-group full"><div class="form-label">Portion Size</div><input class="form-input" id="pia-portion" placeholder="e.g. 1 cup (227g)"></div>
<div class="form-group"><div class="form-label">Calories</div><input class="form-input" id="pia-cal" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Fat (g)</div><input class="form-input" id="pia-fat" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Carbs (g)</div><input class="form-input" id="pia-carb" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Fiber (g)</div><input class="form-input" id="pia-fiber" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Sugar (g)</div><input class="form-input" id="pia-sugar" type="number" min="0" placeholder="0"></div>
<div class="form-group"><div class="form-label">Protein (g)</div><input class="form-input" id="pia-protein" type="number" min="0" placeholder="0"></div>
</div>
<div style="display:flex;gap:8px;margin-top:12px">
<button onclick="savePickerAddFood()" style="flex:1;padding:13px;background:var(--vv-accent);border:none;border-radius:var(--radius-sm);color:#fff;font-weight:700;font-size:14px;cursor:pointer;font-family:'Nunito',sans-serif">✦ Save & Add to Meal</button>
<button onclick="closePickerAddForm()" style="padding:13px 16px;background:transparent;border:1px solid var(--lav-mid);border-radius:var(--radius-sm);color:var(--lav-dark);font-weight:700;font-size:14px;cursor:pointer;font-family:'Nunito',sans-serif">← Back</button>
</div>
</div>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
// ─── ENVIRONMENT DETECTION ────────────────────────────────────────────────
// When running locally via server.py, API calls go to http://localhost:8765/api.
// When running as a deployed Google Apps Script web app, API calls use
// google.script.run (the built-in Apps Script bridge) instead of fetch.
const IS_LOCAL = (location.hostname === 'localhost' || location.hostname === '127.0.0.1');
const API_URL = 'http://localhost:8765/api'; // only used when IS_LOCAL is true
// ─── PROFILE & GOAL CALCULATOR ─────────────────────────────────────────────
let userProfile = {age:38, heightIn:63, weightLbs:194, goalLbs:165, activity:1.375, ratePerWeek:1500};
let customGoals = {}; // overrides: {cal, protein, fat, carb} — empty means use calcGoals()
function loadProfile(){
try{
const p=localStorage.getItem('vitalvortex_profile');
if(p) userProfile=JSON.parse(p);
const c=localStorage.getItem('vitalvortex_custom_goals');
if(c) customGoals=JSON.parse(c);
}catch(e){}
}
function saveProfileLocal(){
try{
localStorage.setItem('vitalvortex_profile',JSON.stringify(userProfile));
localStorage.setItem('vitalvortex_custom_goals',JSON.stringify(customGoals));
}catch(e){}
}
function activeGoals(){
// Returns the goals actually in use: custom overrides on top of calculated values
const g = calcGoals(userProfile);
return {
cal: customGoals.cal ?? g.cal,
protein: customGoals.protein ?? g.protein,
fat: customGoals.fat ?? g.fat,
carb: customGoals.carb ?? g.carb,
sugar: g.sugar,
fiber: g.fiber,
tdee: g.tdee,
bmr: g.bmr
};
}
function calcGoals(profile){
// Mifflin-St Jeor BMR for female
const bmr = 10*(profile.weightLbs/2.205) + 6.25*(profile.heightIn*2.54) - 5*profile.age - 161;
const tdee = Math.round(bmr * profile.activity);
const cal = Math.max(1200, tdee - profile.ratePerWeek);
const protein = Math.round(profile.weightLbs * 0.7); // 0.7g per lb
const fat = Math.round(cal * 0.30 / 9);
const carb = Math.round(cal * 0.40 / 4);
const sugar = Math.round(cal * 0.10 / 4);
const fiber = 25;
return {cal, protein, fat, carb, sugar, fiber, tdee, bmr:Math.round(bmr)};
}
function renderProfilePage(){
document.getElementById('p-age').value = userProfile.age;
document.getElementById('p-height').value = userProfile.heightIn;
document.getElementById('p-weight').value = userProfile.weightLbs;
document.getElementById('p-goal').value = userProfile.goalLbs;
document.getElementById('p-activity').value = userProfile.activity;
document.getElementById('p-rate').value = userProfile.ratePerWeek;
const g = calcGoals(userProfile); // always the pure formula recommendation
const a = activeGoals(); // what's actually in use (may include custom overrides)
const weeksLeft = Math.ceil((userProfile.weightLbs - userProfile.goalLbs) / (userProfile.ratePerWeek/500));
const hasCustom = Object.keys(customGoals).length > 0;
const goalFields = [
{key:'cal', label:'Calories/day', rec:g.cal, unit:'', color:'#FF2D2D', cur:a.cal},
{key:'protein', label:'Protein/day', rec:g.protein, unit:'g', color:'#BF5FFF', cur:a.protein},
{key:'fat', label:'Fat/day', rec:g.fat, unit:'g', color:'#FF7A00', cur:a.fat},
{key:'carb', label:'Carbs/day', rec:g.carb, unit:'g', color:'#FFD600', cur:a.carb},
];
const inputCards = goalFields.map(f=>{
const isCustom = customGoals[f.key] !== undefined;
return `<div style="background:var(--card);border:1px solid ${isCustom?f.color:'var(--border)'};border-radius:var(--radius-sm);padding:10px;text-align:center">
<input id="cg-${f.key}" type="number" min="1" value="${f.cur}" style="width:100%;background:transparent;border:none;outline:none;font-size:20px;font-weight:800;color:${f.color};text-align:center;font-family:'Nunito',sans-serif;padding:0;margin-bottom:2px">
<div style="font-size:10px;color:var(--muted);text-transform:uppercase;font-weight:700">${f.label}</div>
<div style="font-size:10px;color:var(--muted);margin-top:3px">rec: ${f.rec}${f.unit}${isCustom?' <span style="color:'+f.color+';font-weight:700">✎</span>':''}</div>
</div>`;
}).join('');
document.getElementById('profileResults').innerHTML = `
<div class="add-form" style="border-color:rgba(0,255,212,0.2);margin-top:0">
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:12px">
<div class="form-title" style="color:var(--mint-dark);margin-bottom:0">Daily Goals</div>
${hasCustom ? '<span style="font-size:10px;font-weight:700;background:rgba(0,255,212,0.12);color:var(--mint-mid);padding:3px 8px;border-radius:10px">✎ custom</span>' : '<span style="font-size:10px;color:var(--muted)">tap any value to edit</span>'}
</div>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:12px">${inputCards}</div>
<div style="display:flex;gap:8px;margin-bottom:12px">
<button onclick="saveCustomGoals()" style="flex:1;padding:10px;background:var(--vv-accent);border:none;border-radius:var(--radius-sm);color:#fff;font-weight:700;font-size:13px;cursor:pointer;font-family:'Nunito',sans-serif">✦ Save My Goals</button>
${hasCustom ? '<button onclick="resetCustomGoals()" style="padding:10px 14px;background:transparent;border:1px solid var(--lav-mid);border-radius:var(--radius-sm);color:var(--lav-dark);font-weight:700;font-size:13px;cursor:pointer;font-family:\'Nunito\',sans-serif">↺ Reset to Recommended</button>' : ''}
</div>
<div style="font-size:12px;color:var(--muted);line-height:1.6;border-top:1px solid var(--border);padding-top:10px">
BMR: <strong style="color:var(--text)">${g.bmr} cal</strong> ·
TDEE: <strong style="color:var(--text)">${g.tdee} cal</strong> ·
Deficit: <strong style="color:#FF2D2D">${g.tdee - g.cal} cal/day</strong><br>
${userProfile.weightLbs > userProfile.goalLbs ? `Est. <strong style="color:var(--vv-accent2)">${weeksLeft} weeks</strong> to reach ${userProfile.goalLbs} lbs` : '🎉 Goal weight reached!'}
</div>
</div>`;
}
function saveCustomGoals(){
const cal = parseInt(document.getElementById('cg-cal').value);
const protein = parseInt(document.getElementById('cg-protein').value);
const fat = parseInt(document.getElementById('cg-fat').value);
const carb = parseInt(document.getElementById('cg-carb').value);
const g = calcGoals(userProfile);
// Only store keys that differ from the recommendation (keep customGoals lean)
customGoals = {};
if(!isNaN(cal) && cal !== g.cal) customGoals.cal = cal;
if(!isNaN(protein) && protein !== g.protein) customGoals.protein = protein;
if(!isNaN(fat) && fat !== g.fat) customGoals.fat = fat;
if(!isNaN(carb) && carb !== g.carb) customGoals.carb = carb;
// Apply to live tracking goals
const a = activeGoals();
MACRO_GOALS.cal = a.cal;
MACRO_GOALS.protein = a.protein;
MACRO_GOALS.fat = a.fat;
MACRO_GOALS.carb = a.carb;
proteinGoal = a.protein;
saveProfileLocal();
saveLocal();
renderProfilePage();
renderPlanner();
toast('✦ Goals saved!');
}
function resetCustomGoals(){
customGoals = {};
const g = calcGoals(userProfile);
MACRO_GOALS.cal = g.cal;
MACRO_GOALS.protein = g.protein;
MACRO_GOALS.fat = g.fat;
MACRO_GOALS.carb = g.carb;
MACRO_GOALS.sugar = g.sugar;
MACRO_GOALS.fiber = g.fiber;
proteinGoal = g.protein;
saveProfileLocal();
saveLocal();
renderProfilePage();
renderPlanner();
toast('Goals reset to recommended values.');
}
function openProfile(){
renderProfilePage();
const el=document.getElementById('profileOverlay');
el.style.display='flex';
}
function closeProfile(){
document.getElementById('profileOverlay').style.display='none';
}
function saveProfile(){
const age=parseInt(document.getElementById('p-age').value)||38;
const heightIn=parseFloat(document.getElementById('p-height').value)||63;
const weightLbs=parseFloat(document.getElementById('p-weight').value)||194;
const goalLbs=parseFloat(document.getElementById('p-goal').value)||165;
const activity=parseFloat(document.getElementById('p-activity').value)||1.375;
const ratePerWeek=parseInt(document.getElementById('p-rate').value)||1500;
userProfile={age,heightIn,weightLbs,goalLbs,activity,ratePerWeek};
// Recalculate clears any custom overrides so fresh formula values apply
customGoals={};
saveProfileLocal();
const g=calcGoals(userProfile);
MACRO_GOALS.cal=g.cal;
MACRO_GOALS.protein=g.protein;
MACRO_GOALS.fat=g.fat;
MACRO_GOALS.carb=g.carb;
MACRO_GOALS.sugar=g.sugar;
MACRO_GOALS.fiber=g.fiber;
proteinGoal=g.protein;
saveLocal();
renderProfilePage();
renderPlanner();
toast('✦ Goals recalculated!');
}
// ─── THEMES ────────────────────────────────────────────────────────────────
const THEMES = {
'cosmic-lisa-frank': {
'--pink':'#2D0A2E','--pink-mid':'#FF2D9B','--pink-dark':'#FF80CC',
'--mint':'#071A2E','--mint-mid':'#00FFD4','--mint-dark':'#7FFFEE',
'--peach':'#1A0A2E','--peach-mid':'#BF5FFF','--peach-dark':'#E0AAFF',
'--lavender':'#120827','--lav-mid':'#A855F7','--lav-dark':'#E0AAFF',
'--amber-light':'#1A1000','--amber-mid':'#FFD600','--amber-dark':'#FFE97A',
'--blue-light':'#050D1F','--blue-mid':'#00B4FF','--blue-dark':'#80DAFF',
'--green-light':'#071A14','--green-mid':'#00FFA3','--green-dark':'#80FFD4',
'--bg':'#070B1A','--card':'#0F1629','--border':'rgba(168,85,247,0.18)',
'--text':'#F0E6FF','--muted':'#8B7FAB',
'--vv-accent':'#BF5FFF','--vv-accent2':'#00FFD4',
'--star1':'#FF2D9B','--star2':'#00FFD4','--star3':'#FFD600','--star4':'#00B4FF',
'bodyBg':'radial-gradient(ellipse at 20% 30%, rgba(191,95,255,0.08) 0%, transparent 60%), radial-gradient(ellipse at 80% 70%, rgba(0,180,255,0.07) 0%, transparent 60%)'
}
};
function applyTheme(id){
const t = THEMES[id];
if(!t) return;
const root = document.documentElement;
Object.entries(t).forEach(([k,v])=>{ if(k!=='bodyBg') root.style.setProperty(k,v); });
if(t.bodyBg) document.body.style.backgroundImage = t.bodyBg;
document.getElementById('themeSelect').value = id;
try{ localStorage.setItem('vitalvortex_theme', id); }catch(e){}
}
const STARTER_FOODS = [
{id:1, name:"Adventureful Cookie", portion:"1 cookie", cal:60, fat:3, carb:8, fiber:0.5, sugar:4.5, protein:0.5},
{id:2, name:"Apple", portion:"1 medium", cal:72, fat:0.2, carb:19.1, fiber:3.3, sugar:14.3, protein:0.4},
{id:3, name:"Blueberries", portion:"1 Cup", cal:84, fat:0.5, carb:21, fiber:4, sugar:15, protein:1},
{id:4, name:"Broccoli", portion:"1 cup", cal:31, fat:0.5, carb:6, fiber:3, sugar:0, protein:2},
{id:5, name:"Brown Rice", portion:"1/2 cup cooked", cal:160, fat:1, carb:34, fiber:1, sugar:0, protein:3},
{id:6, name:"Butternut Squash", portion:"3/4 Cup", cal:45, fat:0, carb:12, fiber:1, sugar:2, protein:1},
{id:7, name:"Cacao Chia Seed Pudding", portion:"1 serving", cal:265, fat:9, carb:12, fiber:20, sugar:0, protein:19},
{id:8, name:"Carrots", portion:"1 Cup", cal:41, fat:0.2, carb:9.6, fiber:2.8, sugar:0, protein:0.9},
{id:9, name:"Cherry Coke Zero", portion:"1 can", cal:0, fat:0, carb:0, fiber:0, sugar:0, protein:0},
{id:10, name:"Chicken Sausage", portion:"1 link", cal:160, fat:10, carb:1, fiber:0, sugar:0, protein:14},
{id:11, name:"Easy Banana Protein Pancakes", portion:"1 serving", cal:180, fat:5, carb:13, fiber:2, sugar:9, protein:14},
{id:12, name:"Eggs", portion:"2 Whole", cal:141, fat:11, carb:1, fiber:0, sugar:0, protein:13},
{id:13, name:"Grapes", portion:"1 Cup", cal:110, fat:0.2, carb:28, fiber:1.4, sugar:24.7, protein:1.1},
{id:14, name:"Greek Yogurt Silk Vanilla", portion:"1 serving", cal:190, fat:11, carb:13, fiber:0, sugar:9, protein:10},
{id:15, name:"Grilled Avo and Eggs", portion:"1 serving", cal:350, fat:30, carb:3, fiber:8, sugar:0, protein:13},
{id:16, name:"Grilled Chicken", portion:"100g", cal:165, fat:3.6, carb:0, fiber:0, sugar:0, protein:31},
{id:17, name:"Homemade White Bread", portion:"1 Slice", cal:125, fat:2.5, carb:21.8, fiber:0.8, sugar:1.8, protein:3.5},
{id:18, name:"Honey Bunches of Oats", portion:"1 cup", cal:160, fat:2, carb:34, fiber:2, sugar:9, protein:3},
{id:19, name:"Hot Tea", portion:"1 cup", cal:0, fat:0, carb:0, fiber:0, sugar:0, protein:0},
{id:20, name:"Jacksons Sweet Potato Chips", portion:"1 serving", cal:150, fat:9, carb:16, fiber:2, sugar:3, protein:1},
{id:21, name:"Jif Peanut Butter", portion:"1 Tbsp", cal:95, fat:8, carb:4, fiber:1, sugar:1.5, protein:3.5},
{id:22, name:"Lemon Chicken and Green Veggies", portion:"1 serving", cal:190, fat:16, carb:16, fiber:9, sugar:0, protein:27},
{id:23, name:"Minute Chicken and Herb Seasoned Rice", portion:"1 serving", cal:230, fat:3, carb:44, fiber:1, sugar:1, protein:5},
{id:24, name:"Mixed Veggies (sausage pasta sauce)", portion:"1 serving", cal:80, fat:1, carb:15, fiber:3, sugar:0, protein:3},
{id:25, name:"Oatmeal with Added Protein", portion:"1/2 cup", cal:160, fat:2.5, carb:24, fiber:3, sugar:0, protein:10},
{id:26, name:"Olive Oil", portion:"1 Tbsp", cal:119, fat:13.5,carb:0, fiber:0, sugar:0, protein:0},
{id:27, name:"Peanut Butter Energy Bites", portion:"1 bite", cal:90, fat:4.5, carb:9, fiber:4, sugar:7, protein:5},
{id:28, name:"Protein Berry Overnight Oats", portion:"1 serving", cal:225, fat:6, carb:19, fiber:14, sugar:2, protein:19},
{id:29, name:"Quinoa", portion:"1/4 cup dry", cal:160, fat:2.5, carb:31, fiber:3, sugar:2, protein:6},
{id:30, name:"Quinoa and Roasted Veggie Bowl", portion:"1 bowl", cal:310, fat:14, carb:18, fiber:6, sugar:0, protein:37},
{id:31, name:"Romaine Lettuce", portion:"2 Large Leaves", cal:5, fat:0, carb:1, fiber:0.6, sugar:0.3, protein:0.3},
{id:32, name:"Samoa Cookies", portion:"2 cookies", cal:0, fat:0, carb:0, fiber:0, sugar:0, protein:0},
{id:33, name:"Spaghetti Squash", portion:"1 Cup", cal:42, fat:0.4, carb:10, fiber:2.2, sugar:0, protein:1},
{id:34, name:"Spinach", portion:"1 Cup", cal:7, fat:0.1, carb:1, fiber:0.7, sugar:0.1, protein:0.8},
{id:35, name:"Starbucks Grande Vanilla Latte (Oat Milk)", portion:"1 grande", cal:0, fat:0, carb:0, fiber:0, sugar:0, protein:0},
{id:36, name:"Strawberries", portion:"1 Cup", cal:53, fat:0.5, carb:12.75,fiber:3.3, sugar:7.7, protein:1.1},
{id:37, name:"Sweet Potato", portion:"1 medium", cal:103, fat:0.2, carb:24, fiber:4, sugar:7, protein:2},
{id:38, name:"Tuna Creations Deli Style Tuna Salad", portion:"1 pouch", cal:80, fat:1.5, carb:3, fiber:1, sugar:0, protein:13},
{id:39, name:"Turkey and Tater Sandwich", portion:"1 sandwich", cal:140, fat:2.5, carb:13, fiber:6, sugar:5, protein:14},
{id:40, name:"Turkey Deli Meat", portion:"2 oz", cal:50, fat:0.5, carb:0, fiber:0, sugar:0, protein:11},
{id:41, name:"Turkey Taco Bowl", portion:"1 bowl", cal:310, fat:10, carb:16, fiber:4, sugar:0, protein:37},
{id:42, name:"Yum Yum Sauce", portion:"1 Tbsp", cal:0, fat:0, carb:0, fiber:0, sugar:0, protein:0}
];
const MEALS = [
{name:"Breakfast",emoji:"✨️"},
{name:"Morning Snack",emoji:"💎️"},
{name:"Lunch",emoji:"🌈️"},
{name:"Afternoon Snack",emoji:"⚡️"},
{name:"Dinner",emoji:"🌠️"}
];
const MACROS = [{k:'cal',lbl:'Calories',cls:'cal'},{k:'fat',lbl:'Fat g',cls:'fat'},{k:'carb',lbl:'Carbs g',cls:'carb'},{k:'fiber',lbl:'Fiber g',cls:'fiber'},{k:'sugar',lbl:'Sugar g',cls:'sugar'},{k:'protein',lbl:'Protein g',cls:'protein'}]; // order: cal=red, protein=orange, fiber=yellow, carb=green, sugar=blue, fat=violet
// Daily goals: 38yo female, 5'3", 194 lbs → 165 lbs at ~3 lbs/wk
// BMR ~1604, TDEE ~1925 (lightly active), deficit target ~1450 cal/day
const MACRO_GOALS = {cal:1450, protein:100, fiber:25, carb:145, sugar:25, fat:48};
const GOOD_MACROS = new Set(['protein','fiber']); // more is better
const BAD_MACROS = new Set(['cal','carb','sugar','fat']); // over = bad
function blackholeSVG(){
return `<svg viewBox="0 0 80 80" xmlns="http://www.w3.org/2000/svg" style="position:absolute;inset:0;width:100%;height:100%;z-index:2;pointer-events:none">
<defs>
<radialGradient id="bhGlow" cx="50%" cy="50%" r="50%">
<stop offset="0%" stop-color="#000" stop-opacity="1"/>
<stop offset="45%" stop-color="#1a0040" stop-opacity="1"/>
<stop offset="70%" stop-color="#4400aa" stop-opacity="0.6"/>
<stop offset="85%" stop-color="#7700ff" stop-opacity="0.3"/>
<stop offset="100%" stop-color="transparent" stop-opacity="0"/>
</radialGradient>
<radialGradient id="bhRing" cx="50%" cy="50%" r="50%">
<stop offset="55%" stop-color="transparent"/>
<stop offset="68%" stop-color="#aa44ff" stop-opacity="0.9"/>
<stop offset="74%" stop-color="#ff88ff" stop-opacity="1"/>
<stop offset="80%" stop-color="#aa44ff" stop-opacity="0.7"/>
<stop offset="100%" stop-color="transparent"/>
</radialGradient>
<filter id="bhBlur"><feGaussianBlur stdDeviation="1.5"/></filter>
</defs>
<!-- accretion disc glow (blurred ellipse for perspective) -->
<ellipse cx="40" cy="44" rx="34" ry="10" fill="none" stroke="#9933ff" stroke-width="5" opacity="0.35" filter="url(#bhBlur)"/>
<ellipse cx="40" cy="44" rx="34" ry="10" fill="none" stroke="#ff88ff" stroke-width="2" opacity="0.5" filter="url(#bhBlur)"/>
<!-- photon ring -->
<circle cx="40" cy="40" r="26" fill="url(#bhRing)" filter="url(#bhBlur)"/>
<!-- event horizon -->
<circle cx="40" cy="40" r="18" fill="url(#bhGlow)"/>
<!-- singularity -->
<circle cx="40" cy="40" r="7" fill="#000"/>
<!-- lensing streaks being pulled in -->
<line x1="10" y1="18" x2="32" y2="36" stroke="#cc66ff" stroke-width="1" opacity="0.5"/>
<line x1="70" y1="16" x2="48" y2="35" stroke="#cc66ff" stroke-width="1" opacity="0.5"/>
<line x1="6" y1="52" x2="30" y2="42" stroke="#aa44ff" stroke-width="1" opacity="0.4"/>
<line x1="74" y1="54" x2="50" y2="43" stroke="#aa44ff" stroke-width="1" opacity="0.4"/>
<line x1="30" y1="6" x2="38" y2="28" stroke="#ff88ff" stroke-width="0.8" opacity="0.4"/>
<line x1="50" y1="6" x2="42" y2="28" stroke="#ff88ff" stroke-width="0.8" opacity="0.4"/>
</svg>`;
}
function buildMacroCards(totals){
const colors = {cal:'255,45,45',fat:'255,122,0',carb:'255,214,0',fiber:'0,221,68',sugar:'0,180,255',protein:'191,95,255'};
return MACROS.map(m=>{
const goal = m.k==='protein' ? proteinGoal : MACRO_GOALS[m.k];
const val = Math.round(totals[m.k]);
const pct = goal>0 ? Math.min(100,Math.round((val/goal)*100)) : 0;
const isOver = val > goal;
const isBad = BAD_MACROS.has(m.k);
const crashed = isOver && isBad;
if(crashed){
return `<div class="macro-card ${m.cls} blackhole" style="animation:blackholePull 0.8s ease forwards">${blackholeSVG()}<div class="macro-val" style="position:relative;z-index:3;animation:spaghetti 0.8s ease forwards">${val}</div><div class="macro-goal-lbl" style="position:relative;z-index:3;animation:spaghetti 0.9s ease forwards">/ ${goal}</div><div class="macro-lbl" style="position:relative;z-index:3">${m.lbl}</div></div>`;
}
// good macros: keep color filling even over goal; bad macros under goal: normal fill
const rgb = colors[m.k];
const bg = `linear-gradient(to top, rgba(${rgb},0.25) ${pct}%, transparent ${pct}%)`;
return `<div class="macro-card ${m.cls}" style="background:${bg}"><div class="macro-val">${val}</div><div class="macro-goal-lbl">/ ${goal}</div><div class="macro-lbl">${m.lbl}</div></div>`;
}).join('');
}
let state = {foods:[],meals:[[],[],[],[],[]],water:0,tomorrowMeals:[[],[],[],[],[]],nextId:43,confirmedMeals:[false,false,false,false,false]};
// Per-group recents: breakfast(0), snacks(1+3), mains(2+4)
let recentFoods = {breakfast:[], snacks:[], mains:[]};
// Map meal index → group key
function mealGroup(mi){ return mi===0?'breakfast':(mi===1||mi===3)?'snacks':'mains'; }
let proteinGoal = 100;
let waterCelebrated = false;
let editingId = null;
let dailyLog = {};
let calViewDate = new Date();
let selectedLogDate = null;
let midnightTimer = null;
function todayKey(){
const d=new Date();
return d.getFullYear()+'-'+String(d.getMonth()+1).padStart(2,'0')+'-'+String(d.getDate()).padStart(2,'0');
}
function setSyncStatus(s){
document.getElementById('syncDot').className='sync-dot '+s;
document.getElementById('syncLabel').textContent=s==='synced'?'saved':s==='syncing'?'saving...':'offline';
}
function toast(msg){
const t=document.getElementById('toast');
t.textContent=msg;t.classList.add('show');
setTimeout(()=>t.classList.remove('show'),2400);
}
// ─── LOCAL STORAGE (fast, in-browser cache) ────────────────────────────────
function loadLocal(){
try{
const s=localStorage.getItem('vitalvortex_plan');
if(s){
const p=JSON.parse(s);
state.meals=p.meals||[[],[],[],[],[]];
state.tomorrowMeals=p.tomorrowMeals||[[],[],[],[],[]];
state.water=p.water||0;
if(p.proteinGoal) proteinGoal=p.proteinGoal;
state.confirmedMeals=p.confirmedMeals||[false,false,false,false,false];
}
const l=localStorage.getItem('vitalvortex_log');
if(l){dailyLog=JSON.parse(l);}
const r=localStorage.getItem('vitalvortex_recent');
if(r){
const parsed=JSON.parse(r);
// migrate old flat array to new grouped format
if(Array.isArray(parsed)) recentFoods={breakfast:parsed,snacks:[...parsed],mains:[...parsed]};
else recentFoods={breakfast:parsed.breakfast||[],snacks:parsed.snacks||[],mains:parsed.mains||[]};
}
}catch(e){}
}
function saveRecent(){
try{localStorage.setItem('vitalvortex_recent',JSON.stringify(recentFoods));}catch(e){}
}
function trackRecent(id, mi){
const grp=mealGroup(mi);
recentFoods[grp]=recentFoods[grp].filter(x=>x!==id);
recentFoods[grp].unshift(id);
if(recentFoods[grp].length>5)recentFoods[grp]=recentFoods[grp].slice(0,5);
saveRecent();
}
function saveLocal(){
try{localStorage.setItem('vitalvortex_plan',JSON.stringify({meals:state.meals,tomorrowMeals:state.tomorrowMeals,water:state.water,proteinGoal,confirmedMeals:state.confirmedMeals}));}catch(e){}
}
function saveLogLocal(){
try{localStorage.setItem('vitalvortex_log',JSON.stringify(dailyLog));}catch(e){}
}
// ─── API CALLS ───────────────────────────────────────────────────────────────────
// Unified API bridge: local calls go to the Python server via fetch;
// deployed calls use google.script.run (Apps Script's server bridge).
// Wrap google.script.run in a Promise so we can await it like fetch.
function gsRun(params){
return new Promise((resolve) => {
google.script.run
.withSuccessHandler(result => resolve(result))
.withFailureHandler(err => { console.error('gs.run error:', err); resolve(null); })
.handleRequest(params);
});
}
async function apiFetch(path, options={}){
if(IS_LOCAL){
try{
const res = await fetch(path, {...options, headers:{'Content-Type':'application/json'}});
return await res.json();
}catch(e){
console.error('API error:', e);
return null;
}
} else {
// Deployed: extract action and body from the call and use google.script.run
try{
const url = new URL(path, location.href);
const action = url.searchParams.get('action') || (options.body ? JSON.parse(options.body).action : '');
const body = options.body ? JSON.parse(options.body) : {};
const params = {...body, action};
return await gsRun(params);
}catch(e){
console.error('gsRun error:', e);
return null;
}
}
}
async function loadFoodsFromSheet(){
setSyncStatus('syncing');
try{
const data = await apiFetch(API_URL+'?action=read');
if(data && data.ok && data.foods && data.foods.length > 0){
state.foods = data.foods.map(f=>({
id:Number(f.id), name:String(f.name), portion:String(f.portion),
cal:Number(f.cal)||0, fat:Number(f.fat)||0, carb:Number(f.carb)||0,
sugar:Number(f.sugar)||0, fiber:Number(f.fiber)||0, protein:Number(f.protein)||0
}));
state.nextId = Math.max(...state.foods.map(f=>f.id)) + 1;
setSyncStatus('synced');
return true;
}
}catch(e){}
setSyncStatus('error');
return false;
}
async function saveFoodsToSheet(){
setSyncStatus('syncing');
const data = await apiFetch(API_URL, {method:'POST', body:JSON.stringify({action:'write', foods:state.foods})});
if(data && data.ok){ setSyncStatus('synced'); return true; }
setSyncStatus('error');
toast('Could not save — is the server running?');
return false;
}
async function saveLogToSheet(dateKey, entry){
await apiFetch(API_URL, {method:'POST', body:JSON.stringify({action:'log', date:dateKey, entry})});
}
async function loadLogFromSheet(){
const data = await apiFetch(API_URL+'?action=readlog');
if(data && data.ok && data.log){ dailyLog = data.log; saveLogLocal(); }
}
async function savePlanToSheet(){
setSyncStatus('syncing');
const blob = JSON.stringify({meals:state.meals, tomorrowMeals:state.tomorrowMeals, water:state.water, confirmedMeals:state.confirmedMeals});
const data = await apiFetch(API_URL, {method:'POST', body:JSON.stringify({action:'saveplan', blob})});
if(data && data.ok){ setSyncStatus('synced'); return true; }
setSyncStatus('error');
toast('Could not save plan — is the server running?');
return false;
}
async function loadPlanFromSheet(){
const data = await apiFetch(API_URL+'?action=loadplan');
if(data && data.ok && data.blob){
const p = JSON.parse(data.blob);
state.meals = p.meals||[[],[],[],[],[]];
state.tomorrowMeals = p.tomorrowMeals||[[],[],[],[],[]];
state.water = p.water||0;
if(p.confirmedMeals) state.confirmedMeals = p.confirmedMeals;
// also sync the per-key localStorage entries so renderPlanner stays consistent
state.confirmedMeals.forEach((confirmed, mi) => {
if(confirmed) localStorage.setItem(todayKey()+'-confirm-'+mi, '1');
else localStorage.removeItem(todayKey()+'-confirm-'+mi);
});
return true;
}
return false;
}
// ─── REST OF APP (unchanged) ───────────────────────────────────────────────
// Meal entries are stored as {id, qty, frac} objects.
// frac is a decimal multiplier: 1=full, 0.75=3/4, 0.5=1/2, 0.333=1/3, 0.25=1/4
// qty is how many of that entry (e.g. 3 eggs)
// Legacy bare-integer entries (including negative-id half-servings) are migrated on load.
const FRACS = [
{val:1, label:'Full'},
{val:0.75, label:'¾'},
{val:0.5, label:'½'},
{val:0.333,label:'⅓'},
{val:0.25, label:'¼'}
];
function normEntry(e){
// Accept either a legacy bare integer or a new {id,qty,frac} object
if(typeof e === 'number') return {id: Math.abs(e), qty:1, frac: e<0 ? 0.5 : 1};
return {id: e.id||e, qty: e.qty||1, frac: e.frac||1};
}
function entryMult(e){ const n=normEntry(e); return n.qty * n.frac; }
function entryId(e){ return normEntry(e).id; }
// Keep old names as thin wrappers so nothing else breaks
function realId(e){ return entryId(e); }
function macroMult(f, e){ return entryMult(e); }
function computeTotals(){
const t={cal:0,fat:0,carb:0,sugar:0,fiber:0,protein:0};
state.meals.forEach(meal=>meal.forEach(fid=>{
const f=state.foods.find(x=>x.id===realId(fid));
const m=macroMult(f,fid);
if(f){t.cal+=f.cal*m;t.fat+=f.fat*m;t.carb+=f.carb*m;t.sugar+=f.sugar*m;t.fiber+=f.fiber*m;t.protein+=f.protein*m;}
}));
return t;
}
async function saveTodayToLog(){
const key=todayKey();
const totals=computeTotals();
const hasSomething=state.meals.some(m=>m.length>0)||state.water>0;
if(!hasSomething)return;
const entry={cal:Math.round(totals.cal),fat:Math.round(totals.fat),carb:Math.round(totals.carb),sugar:Math.round(totals.sugar),fiber:Math.round(totals.fiber),protein:Math.round(totals.protein),water:state.water*8};
dailyLog[key]=entry;
saveLogLocal();
await saveLogToSheet(key,entry);
}
function scheduleMidnightSave(){ /* disabled — save manually via Save & Clear button */ }
function sortedFoods(list){
return [...list].sort((a,b)=>a.name.localeCompare(b.name));
}
function showPage(id,btn){
document.querySelectorAll('.page').forEach(p=>p.classList.remove('active'));
document.querySelectorAll('.nav-btn').forEach(b=>b.classList.remove('active'));
document.getElementById('page-'+id).classList.add('active');
if(btn)btn.classList.add('active');
if(id==='planner')renderPlanner();
if(id==='tomorrow')renderTomorrow();
if(id==='menu'){editingId=null;renderMenu();}
if(id==='history')renderCalendar();
}
function renderPlanner(){
document.getElementById('dateDisplay').textContent=new Date().toLocaleDateString('en-US',{weekday:'short',month:'short',day:'numeric'});
const totals=computeTotals();