-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyscrash.html
More file actions
1657 lines (1486 loc) · 95.4 KB
/
syscrash.html
File metadata and controls
1657 lines (1486 loc) · 95.4 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>System Crash - Card Game</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<script src="https://unpkg.com/peerjs@1.5.2/dist/peerjs.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Share+Tech+Mono&display=swap');
body {
font-family: 'Share Tech Mono', monospace;
background-color: #0f172a;
color: #33ff33;
overflow: hidden;
touch-action: manipulation;
}
.pixel-font {
font-family: 'Press Start 2P', cursive;
}
.card {
transition: transform 0.2s, box-shadow 0.2s;
user-select: none;
aspect-ratio: 2/3;
}
.card:hover {
transform: translateY(-10px);
z-index: 50;
}
.flying-card {
position: fixed;
z-index: 100;
pointer-events: none;
transition: all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
.crt::before {
content: " ";
display: block;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
z-index: 2;
background-size: 100% 2px, 3px 100%;
pointer-events: none;
}
@keyframes glitch {
0% { transform: translate(0) }
20% { transform: translate(-2px, 2px) }
40% { transform: translate(-2px, -2px) }
60% { transform: translate(2px, 2px) }
80% { transform: translate(2px, -2px) }
100% { transform: translate(0) }
}
.glitch:hover {
animation: glitch 0.3s cubic-bezier(.25, .46, .45, .94) both infinite;
}
.emote-float-up { animation: floatUp 4s ease-out forwards; }
@keyframes floatUp { 0% { transform: translateY(0); opacity: 1; } 90% { opacity: 1; } 100% { transform: translateY(-80px); opacity: 0; } }
@keyframes emergency-pulse {
0%, 100% { box-shadow: 0 0 20px 10px rgba(220, 38, 38, 0.5); transform: scale(1); }
50% { box-shadow: 0 0 40px 20px rgba(220, 38, 38, 0.8); transform: scale(1.05); }
}
.emergency-card {
animation: emergency-pulse 1s infinite;
}
@keyframes shrink-width {
from { width: 100%; }
to { width: 0%; }
}
.timer-bar {
animation: shrink-width 3s linear forwards;
}
.scrollbar-hide::-webkit-scrollbar { display: none; }
input[type=range] { -webkit-appearance: none; background: transparent; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; height: 20px; width: 20px; background: #4ade80; cursor: pointer; margin-top: -8px; box-shadow: 2px 2px 0px 0px #000; }
input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 4px; cursor: pointer; background: #334155; border-radius: 2px; }
/* --- GLOWING NAME EFFECTS --- */
.name-owner-container {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
white-space: nowrap;
}
.name-owner-text {
background: linear-gradient(to right, #e879f9, #c084fc, #a855f7, #c084fc, #e879f9);
-webkit-background-clip: text;
color: transparent;
animation: gradient-x 2s linear infinite;
filter: drop-shadow(0px 0px 4px rgba(192, 132, 252, 0.8));
background-size: 200% 100%;
}
@keyframes gradient-x {
0% { background-position: 100% 0; }
100% { background-position: -100% 0; }
}
.name-owner-container::before, .name-owner-container::after {
content: '✦';
position: absolute;
color: #d8b4fe;
font-size: 8px;
text-shadow: 0 0 5px #c084fc;
animation: float-around 3s ease-in-out infinite;
pointer-events: none;
}
.name-owner-container::after {
animation-delay: -1.5s;
animation-direction: reverse;
}
@keyframes float-around {
0% { transform: translate(-20px, -10px) scale(0.8); opacity: 0.8; }
33% { transform: translate(20px, -15px) scale(1.2); opacity: 1; }
66% { transform: translate(15px, 10px) scale(0.6); opacity: 0.5; }
100% { transform: translate(-20px, -10px) scale(0.8); opacity: 0.8; }
}
</style>
</head>
<body class="h-screen w-screen relative overflow-hidden crt bg-slate-900">
<!-- GAME CONTAINER -->
<div id="app" class="h-full w-full flex flex-col items-center justify-center relative z-10">
<!-- AUTH SCREEN -->
<div id="auth-screen" class="absolute inset-0 bg-slate-900 flex flex-col items-center justify-center z-[60]">
<h1 class="text-3xl md:text-5xl text-green-400 pixel-font mb-8 text-center glitch">SYSTEM LOGIN</h1>
<div id="auth-buttons" class="flex flex-col gap-4 w-64">
<button onclick="showLogin()" class="bg-blue-600 hover:bg-blue-500 text-black py-3 px-6 rounded shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] font-bold text-lg pixel-font transition">LOGIN</button>
<button onclick="showSignup()" class="bg-purple-600 hover:bg-purple-500 text-white py-3 px-6 rounded shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] font-bold text-lg pixel-font transition">SIGN UP</button>
<button onclick="guestLogin()" class="bg-slate-600 hover:bg-slate-500 text-white py-2 px-6 rounded shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] font-bold text-sm pixel-font transition mt-4">GUEST MODE</button>
</div>
<div id="login-form" class="hidden flex-col gap-4 w-72">
<input type="text" id="login-user" placeholder="USERNAME" class="bg-slate-800 border-2 border-blue-500 text-white p-3 pixel-font text-sm">
<input type="password" id="login-pass" placeholder="PASSWORD" class="bg-slate-800 border-2 border-blue-500 text-white p-3 pixel-font text-sm">
<button onclick="performLogin()" class="bg-green-600 hover:bg-green-500 text-black py-3 rounded font-bold pixel-font">ENTER</button>
<button onclick="showAuthButtons()" class="text-slate-500 text-xs pixel-font hover:text-white">BACK</button>
</div>
<div id="signup-form" class="hidden flex-col gap-4 w-72">
<input type="text" id="signup-user" placeholder="NEW USERNAME" maxlength="12" class="bg-slate-800 border-2 border-purple-500 text-white p-3 pixel-font text-sm">
<input type="password" id="signup-pass" placeholder="PASSWORD" class="bg-slate-800 border-2 border-purple-500 text-white p-3 pixel-font text-sm">
<button onclick="performSignup()" class="bg-green-600 hover:bg-green-500 text-black py-3 rounded font-bold pixel-font">CREATE</button>
<button onclick="showAuthButtons()" class="text-slate-500 text-xs pixel-font hover:text-white">BACK</button>
</div>
<div id="loading-msg" class="text-yellow-400 text-center text-sm pixel-font mt-8 hidden animate-pulse z-[70]">CONNECTING TO DATABASE...</div>
</div>
<!-- MAIN MENU -->
<div id="main-menu" class="absolute inset-0 bg-slate-900 flex flex-col items-center justify-center z-50 hidden">
<h1 class="text-4xl md:text-6xl text-green-400 pixel-font mb-4 text-center glitch">SYSTEM CRASH</h1>
<div class="bg-slate-800 border border-slate-600 p-4 rounded mb-6 w-72 text-center relative">
<div id="save-indicator" class="absolute top-2 right-2 text-[10px] text-green-500 opacity-0 transition-opacity duration-500 pixel-font">SAVED</div>
<div class="pixel-font text-xl text-white mb-2" id="menu-username">GUEST</div>
<div class="flex justify-between text-xs text-yellow-400 pixel-font mb-1">
<span>LVL <span id="menu-level">1</span></span>
<span>XP <span id="menu-xp">0</span>/<span id="menu-xp-next">100</span></span>
</div>
<div class="w-full bg-slate-900 h-2 rounded-full overflow-hidden mb-2">
<div id="xp-bar" class="bg-yellow-500 h-full w-0 transition-all duration-500"></div>
</div>
<!-- NEW BITS CURRENCY DISPLAY -->
<div class="flex justify-center items-center text-xs text-yellow-400 pixel-font mt-2">
<i class="fas fa-coins mr-2"></i> <span id="menu-bits">0</span> BITS
</div>
</div>
<div class="space-y-4 flex flex-col w-72">
<button onclick="startGame('single')" class="bg-green-600 hover:bg-green-500 text-black py-4 px-6 rounded shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] font-bold text-lg pixel-font transition">SOLO RUN</button>
<button onclick="showMultiplayerMenu()" class="bg-blue-600 hover:bg-blue-500 text-black py-4 px-6 rounded shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] font-bold text-lg pixel-font transition">MULTIPLAYER</button>
<!-- NEW HUB BUTTONS -->
<div class="flex gap-2 w-full mt-2">
<button onclick="showLeaderboard()" class="flex-1 bg-yellow-600 hover:bg-yellow-500 text-black py-2 rounded shadow-[2px_2px_0px_0px_rgba(0,0,0,1)] font-bold text-xs pixel-font transition"><i class="fas fa-trophy block mb-1 text-lg"></i>RANKS</button>
<button onclick="showDaily()" class="flex-1 bg-cyan-600 hover:bg-cyan-500 text-black py-2 rounded shadow-[2px_2px_0px_0px_rgba(0,0,0,1)] font-bold text-xs pixel-font transition"><i class="fas fa-calendar-check block mb-1 text-lg"></i>DAILY</button>
<button onclick="showPass()" class="flex-1 bg-purple-600 hover:bg-purple-500 text-white py-2 rounded shadow-[2px_2px_0px_0px_rgba(0,0,0,1)] font-bold text-xs pixel-font transition"><i class="fas fa-ticket-alt block mb-1 text-lg"></i>PASS</button>
</div>
<button onclick="logout()" class="text-xs text-slate-500 hover:text-red-400 underline pt-4">LOGOUT</button>
</div>
<p class="mt-4 text-slate-500 text-xs">v4.0.0 | Cloud Hub Integration</p>
</div>
<!-- MULTIPLAYER LOBBY -->
<div id="lobby-menu" class="absolute inset-0 bg-slate-900 flex flex-col items-center justify-center z-50 hidden">
<h2 class="text-3xl text-blue-400 pixel-font mb-4">NET LOBBY</h2>
<div id="lobby-controls" class="space-y-4 flex flex-col w-80 text-center bg-slate-800 p-6 rounded-lg border border-slate-700">
<div class="mb-4 border-b border-slate-600 pb-4">
<label class="block text-green-400 pixel-font text-xs mb-2">MAX PLAYERS: <span id="max-players-val" class="text-white">4</span></label>
<input type="range" id="max-players-input" min="2" max="50" value="4" class="w-full" oninput="document.getElementById('max-players-val').innerText = this.value">
</div>
<!-- Chat Toggle -->
<div id="host-options" class="flex items-center justify-center gap-2 mb-2 hidden">
<input type="checkbox" id="chat-enabled-check" class="w-4 h-4 cursor-pointer accent-green-600">
<label for="chat-enabled-check" class="text-xs text-green-400 pixel-font cursor-pointer">ENABLE CHAT (EXP)</label>
</div>
<button id="btn-public-match" onclick="findPublicRoom()" class="bg-yellow-500 hover:bg-yellow-400 text-black py-3 px-6 rounded shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] font-bold text-lg pixel-font w-full animate-pulse">FIND PUBLIC MATCH</button>
<p id="guest-lock-msg" class="text-[10px] text-red-400 hidden">ACCOUNTS ONLY</p>
<div class="flex items-center justify-between text-slate-500 text-xs pixel-font my-2"><span>-- OR --</span></div>
<button onclick="createRoom(false)" class="bg-purple-600 hover:bg-purple-500 text-white py-2 px-6 rounded shadow-[4px_4px_0px_0px_rgba(255,255,255,0.2)] font-bold text-sm pixel-font w-full">HOST PRIVATE</button>
<div class="flex gap-2 mt-2">
<input type="text" id="room-code-input" placeholder="CODE" maxlength="4" class="bg-slate-900 border-2 border-slate-600 text-white p-2 w-full text-center pixel-font uppercase rounded">
<button onclick="joinRoom()" class="bg-green-600 hover:bg-green-500 text-black p-2 rounded font-bold pixel-font text-sm">JOIN</button>
</div>
<button onclick="backToMain()" class="text-slate-400 hover:text-white mt-4 underline text-xs">Return to Menu</button>
</div>
<!-- Waiting Room -->
<div id="waiting-room" class="hidden flex flex-col items-center w-full max-w-md">
<div class="bg-slate-800 p-6 rounded-lg border-2 border-green-500 w-full mb-4 relative">
<span id="room-type-badge" class="absolute top-2 right-2 text-[10px] bg-slate-700 text-slate-300 px-2 rounded pixel-font">PRIVATE</span>
<p class="text-center text-slate-400 mb-2">SERVER CODE</p>
<p id="display-room-code" class="text-4xl text-center text-white font-bold tracking-widest pixel-font select-all"></p>
</div>
<div class="w-full bg-slate-800 p-4 rounded-lg min-h-[150px] max-h-[300px] overflow-y-auto mb-4 scrollbar-hide">
<h3 class="text-green-400 border-b border-green-700 pb-2 mb-2 flex justify-between">
<span>PLAYERS:</span>
<span id="player-count-display" class="text-white">0/0</span>
</h3>
<ul id="player-list" class="space-y-2 text-white text-sm pixel-font"></ul>
</div>
<button id="start-mp-btn" onclick="startMultiplayerGame()" class="hidden bg-red-600 hover:bg-red-500 text-white py-3 w-full rounded shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] font-bold text-lg pixel-font animate-pulse">EXECUTE START</button>
<p id="waiting-msg" class="text-yellow-400 mt-4 animate-pulse hidden pixel-font text-center">WAITING FOR HOST TO START...</p>
</div>
</div>
<!-- NEW HUB MODALS -->
<!-- LEADERBOARD MODAL -->
<div id="leaderboard-modal" class="absolute inset-0 bg-slate-900 bg-opacity-95 flex flex-col items-center justify-center z-[55] hidden">
<h2 class="text-3xl text-yellow-400 pixel-font mb-6"><i class="fas fa-trophy mr-2"></i>GLOBAL RANKS</h2>
<div class="bg-slate-800 border-2 border-yellow-500 rounded-lg p-4 w-11/12 max-w-md h-96 overflow-y-auto scrollbar-hide">
<table class="w-full text-white pixel-font text-[10px] md:text-xs text-left">
<thead><tr class="text-slate-400 border-b border-slate-600"><th class="pb-2 w-8">#</th><th class="pb-2">USER</th><th class="pb-2 text-right">LVL</th><th class="pb-2 text-right">XP</th></tr></thead>
<tbody id="leaderboard-list">
<tr><td colspan="4" class="text-center py-4 text-slate-500 animate-pulse">FETCHING DATA...</td></tr>
</tbody>
</table>
</div>
<button onclick="closeHubModals()" class="mt-6 text-slate-400 hover:text-white underline text-xs pixel-font">RETURN</button>
</div>
<!-- DAILY REWARDS MODAL -->
<div id="daily-modal" class="absolute inset-0 bg-slate-900 bg-opacity-95 flex flex-col items-center justify-center z-[55] hidden">
<h2 class="text-3xl text-cyan-400 pixel-font mb-2">DAILY LOGIN</h2>
<p class="text-slate-400 text-xs pixel-font mb-6">STREAK: <span id="daily-streak-text" class="text-white">0</span>/4</p>
<div class="flex gap-2 md:gap-4 mb-8" id="daily-cards-container">
<!-- Filled via JS -->
</div>
<button id="claim-daily-btn" onclick="claimDaily()" class="bg-cyan-600 hover:bg-cyan-500 text-black py-4 px-8 rounded shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] font-bold text-xl pixel-font transition">CLAIM REWARD</button>
<button onclick="closeHubModals()" class="mt-6 text-slate-400 hover:text-white underline text-xs pixel-font">RETURN</button>
</div>
<!-- SEASON PASS MODAL -->
<div id="pass-modal" class="absolute inset-0 bg-slate-900 bg-opacity-95 flex flex-col items-center justify-center z-[55] hidden">
<h2 class="text-3xl text-purple-400 pixel-font mb-2">SYSTEM PASS</h2>
<div class="w-11/12 max-w-lg mb-6">
<div class="flex justify-between text-xs text-purple-300 pixel-font mb-1">
<span>PASS LVL <span id="pass-level-text">1</span></span>
<span><span id="pass-xp-text">0</span>/500 XP</span>
</div>
<div class="w-full bg-slate-800 h-4 rounded-full border border-purple-500 overflow-hidden">
<div id="pass-xp-bar" class="bg-purple-500 h-full w-0 transition-all duration-500"></div>
</div>
</div>
<div class="bg-slate-800 border-2 border-purple-500 rounded-lg p-4 w-11/12 max-w-lg h-72 overflow-y-auto scrollbar-hide space-y-2" id="pass-tiers-container">
<!-- Filled via JS -->
</div>
<button onclick="closeHubModals()" class="mt-6 text-slate-400 hover:text-white underline text-xs pixel-font">RETURN</button>
</div>
<!-- GAME BOARD -->
<div id="game-board" class="w-full h-full flex flex-col justify-between p-2 hidden relative bg-slate-900 bg-opacity-95">
<!-- Reveal Overlay -->
<div id="reveal-overlay" class="absolute inset-0 z-[90] flex items-center justify-center bg-black bg-opacity-80 hidden">
<div class="flex flex-col items-center">
<h2 class="text-red-500 pixel-font text-3xl mb-4 animate-pulse text-center">CRITICAL ALERT</h2>
<div class="card w-48 h-72 rounded-lg border-4 border-red-600 flex flex-col items-center justify-between p-4 shadow-lg bg-red-600 emergency-card">
<div class="absolute top-2 left-2 text-sm font-bold text-white pixel-font">SYSTEM CRASH</div>
<i class="fas fa-skull text-8xl text-white drop-shadow-md my-auto"></i>
<div class="text-sm text-center leading-tight text-white font-bold pixel-font px-1">TOTAL FAILURE IMMINENT</div>
</div>
<p id="reveal-msg" class="text-white pixel-font mt-4 text-xl">DETECTED...</p>
</div>
</div>
<!-- Interrupt Overlay -->
<div id="interrupt-overlay" class="absolute inset-0 z-[95] flex flex-col items-center justify-center bg-red-900 bg-opacity-90 hidden">
<h2 class="text-white pixel-font text-2xl mb-4 animate-pulse">INTERRUPT WINDOW</h2>
<div class="w-64 h-4 bg-black rounded mb-8 border border-white">
<div class="timer-bar bg-white h-full w-full"></div>
</div>
<p id="interrupt-text" class="text-white pixel-font mb-8 text-center">PLAYER IS ATTEMPTING ACTION...</p>
<button id="btn-use-denied" onclick="playDeniedCard()" class="hidden bg-red-600 hover:bg-red-500 text-white py-4 px-8 rounded shadow-[4px_4px_0px_0px_#000] font-bold text-2xl pixel-font animate-bounce border-2 border-white">PLAY DENIED!</button>
</div>
<!-- Target Modal -->
<div id="target-modal" class="absolute inset-0 bg-black bg-opacity-90 z-[80] flex-col items-center justify-center hidden">
<h2 class="text-2xl text-yellow-400 pixel-font mb-4">SELECT TARGET</h2>
<div id="target-options" class="flex flex-col gap-2 w-64"></div>
<button onclick="closeTargetModal()" class="mt-8 text-slate-500 text-xs pixel-font">CANCEL</button>
</div>
<!-- Chat Agreement Modal -->
<div id="chat-agree-modal" class="absolute inset-0 bg-black bg-opacity-95 z-[100] flex-col items-center justify-center hidden">
<div class="bg-slate-800 border-2 border-green-500 p-6 rounded-lg max-w-sm text-center">
<h2 class="text-xl text-green-400 pixel-font mb-4">COMM PROTOCOL</h2>
<p class="text-white text-sm mb-4 font-mono">By enabling chat, you agree to:</p>
<ul class="text-slate-300 text-xs text-left mb-6 font-mono list-disc pl-4 space-y-2">
<li>Be respectful to other units.</li>
<li>Avoid spam or flooding.</li>
<li>No harmful or illegal content.</li>
<li>The Host may mute you at any time.</li>
</ul>
<div class="flex gap-4 justify-center">
<button onclick="acceptChat()" class="bg-green-600 hover:bg-green-500 text-black py-2 px-4 rounded pixel-font text-xs">I AGREE</button>
<button onclick="closeChatAgree()" class="bg-red-600 hover:bg-red-500 text-white py-2 px-4 rounded pixel-font text-xs">DECLINE</button>
</div>
</div>
</div>
<!-- Hack Modal -->
<div id="hack-modal" class="absolute inset-0 bg-black bg-opacity-95 z-[85] flex-col items-center justify-center hidden">
<h2 class="text-2xl text-red-500 pixel-font mb-4">SYSTEM BREACH</h2>
<p class="text-green-400 text-xs mb-4">SELECT DATA TO STEAL:</p>
<div id="hack-cards" class="flex flex-wrap justify-center gap-2 max-w-2xl"></div>
<button onclick="closeHackModal()" class="mt-8 text-slate-500 text-xs pixel-font">CANCEL</button>
</div>
<!-- Game Area -->
<div id="opponents-container" class="flex flex-wrap justify-center content-start gap-2 pt-2 h-1/4 w-full overflow-y-auto scrollbar-hide"></div>
<div class="flex-1 flex items-center justify-center gap-4 md:gap-12 relative min-h-[150px]">
<div id="draw-pile" class="relative w-20 h-32 md:w-28 md:h-44 bg-slate-800 rounded-lg border-2 border-slate-600 shadow-xl cursor-pointer group" onclick="playerDrawCard()">
<div class="absolute inset-0 bg-[url('https://www.transparenttextures.com/patterns/diagmonds-light.png')] opacity-10"></div>
<div class="absolute inset-0 flex flex-col items-center justify-center text-center">
<i class="fas fa-microchip text-3xl md:text-4xl text-slate-500 group-hover:text-green-400 transition"></i>
<span class="mt-2 text-xs text-slate-500 pixel-font">DRAW</span>
<span id="deck-count" class="absolute -top-3 -right-3 bg-red-500 text-white rounded-full w-6 h-6 flex items-center justify-center text-xs font-bold border border-black">?</span>
</div>
</div>
<div id="discard-pile" class="relative w-20 h-32 md:w-28 md:h-44 bg-slate-800 rounded-lg border-2 border-dashed border-slate-600 flex items-center justify-center">
<span class="text-slate-600 text-xs pixel-font">DISCARD</span>
<div id="last-played-card" class="absolute inset-0"></div>
</div>
<div id="game-status" class="absolute top-0 left-0 right-0 text-center pointer-events-none mt-[-2rem] flex flex-col items-center">
<span id="status-msg" class="bg-black bg-opacity-70 text-green-400 px-4 py-1 rounded text-sm md:text-lg pixel-font shadow-lg"></span>
<button id="host-skip-btn" onclick="hostForceSkip()" class="hidden pointer-events-auto mt-2 bg-red-900 hover:bg-red-700 text-white text-[10px] px-3 py-1 rounded pixel-font border border-red-500">FORCE SKIP</button>
</div>
</div>
<div class="h-1/3 w-full flex flex-col justify-end pb-4">
<div class="flex justify-between items-end px-4 mb-2">
<div class="flex items-center gap-2 relative" id="player-info-area">
<div class="w-3 h-3 rounded-full bg-green-500 animate-pulse"></div>
<span id="player-name" class="font-bold text-green-400">UNIT_YOU</span>
<!-- New Location for Interrupt Button -->
<div id="local-interrupt-area" class="absolute -top-12 left-0 w-full flex justify-center hidden z-[85]">
<button onclick="playDeniedCard()" class="bg-red-600 hover:bg-red-500 text-white py-1 px-3 rounded shadow-lg font-bold text-xs pixel-font animate-bounce border border-white">
PLAY DENIED! <div class="w-full bg-black h-1 mt-1 rounded"><div class="timer-bar bg-white h-full w-full"></div></div>
</button>
</div>
<div id="player-emote-container" class="absolute -top-24 left-0 z-[80]"></div>
</div>
<div class="flex gap-2 relative">
<button onclick="toggleReportMenu()" class="bg-red-700 p-2 rounded-full hover:bg-red-600 border border-slate-500 w-10 h-10 flex items-center justify-center"><i class="fas fa-exclamation text-white"></i></button>
<button onclick="toggleEmoteMenu()" class="bg-slate-700 p-2 rounded-full hover:bg-slate-600 border border-slate-500"><i class="fas fa-comment-dots text-white"></i></button>
<div id="emote-menu" class="absolute bottom-12 right-0 bg-slate-800 border border-slate-600 rounded p-2 grid grid-cols-4 gap-2 hidden min-w-[280px] max-h-[300px] overflow-y-auto scrollbar-hide z-[90]">
<!-- Emotes added via JS -->
<div id="chat-input-row" class="col-span-4 hidden items-center justify-between gap-1 bg-slate-700 p-1 rounded border border-slate-500 mt-1">
<input type="text" id="chat-input-box" maxlength="100" class="w-full bg-transparent text-white text-xs px-2 py-1 pixel-font focus:outline-none placeholder-slate-400" placeholder="TYPE MESSAGE..." onkeypress="handleChatKey(event)">
<button onclick="sendChatMessage()" class="text-green-400 hover:text-white px-2"><i class="fas fa-paper-plane"></i></button>
</div>
</div>
<div id="report-menu" class="absolute bottom-12 right-12 bg-red-900 border-2 border-red-500 rounded p-4 hidden min-w-[200px] z-[90] flex-col gap-2">
<h4 class="text-white pixel-font text-xs mb-2 border-b border-red-400 pb-1">REPORT PLAYER</h4>
<select id="report-target" class="bg-black text-white p-2 text-xs pixel-font mb-2"></select>
<button onclick="submitReport('KICK')" class="bg-red-600 hover:bg-red-500 text-white text-xs py-1 px-2 rounded pixel-font">VOTE KICK (3)</button>
<button id="admin-rename-btn" onclick="submitReport('RENAME')" class="hidden bg-orange-600 hover:bg-orange-500 text-white text-xs py-1 px-2 rounded pixel-font">SANITIZE NAME</button>
<button id="admin-mute-btn" onclick="submitReport('MUTE')" class="hidden bg-slate-600 hover:bg-slate-500 text-white text-xs py-1 px-2 rounded pixel-font">MUTE/UNMUTE</button>
</div>
</div>
</div>
<!-- SCROLLABLE HAND CONTAINER -->
<div class="relative w-full flex items-end justify-center">
<button id="scroll-left" onclick="scrollHand(-1)" class="absolute left-0 bottom-10 z-50 bg-slate-800 text-white p-2 rounded-r-lg opacity-50 hover:opacity-100 hidden border border-slate-600"><i class="fas fa-chevron-left"></i></button>
<div id="player-hand" class="flex justify-start items-end gap-[-4rem] overflow-x-auto px-4 pb-2 min-h-[160px] scrollbar-hide w-full md:justify-center"></div>
<button id="scroll-right" onclick="scrollHand(1)" class="absolute right-0 bottom-10 z-50 bg-slate-800 text-white p-2 rounded-l-lg opacity-50 hover:opacity-100 hidden border border-slate-600"><i class="fas fa-chevron-right"></i></button>
</div>
</div>
<!-- Future/Debug Modal -->
<div id="future-modal" class="absolute inset-0 bg-black bg-opacity-90 z-[70] flex-col items-center justify-center hidden">
<h2 id="future-title" class="text-2xl text-purple-400 pixel-font mb-4">DATA STREAM</h2>
<div id="future-cards" class="flex gap-4"></div>
<button onclick="closeFutureModal()" class="mt-8 bg-slate-700 text-white px-6 py-2 rounded pixel-font hover:bg-slate-600">CLOSE</button>
</div>
<div id="game-over-modal" class="absolute inset-0 bg-red-900 bg-opacity-90 z-[70] flex flex-col items-center justify-center hidden">
<h2 id="winner-text" class="text-4xl text-white pixel-font mb-4 text-center">SYSTEM CRASH</h2>
<div id="xp-gain-msg" class="text-yellow-400 pixel-font mb-4 animate-bounce"></div>
<button onclick="backToMain()" class="bg-white text-black px-8 py-4 rounded font-bold pixel-font hover:bg-gray-200">RETURN TO BASE</button>
</div>
</div>
</div>
<!-- MAIN SCRIPT -->
<script>
// ==========================================
// CONFIGURATION: APPS SCRIPT WEB APP URL
// ==========================================
const APPS_SCRIPT_URL = "https://script.google.com/macros/s/AKfycbwFWsZRWMCE2TzC3ItKan9Nx_or66-34je-KbKVR33YKWtvO3rnM0v0lBDqJIHDll-e/exec"; // <--- PASTE YOUR DEPLOYMENT URL HERE
// === GLOBAL UTILS ===
function showToast(msg) {
const el = document.createElement('div');
el.className = 'absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-black border-2 border-green-500 text-green-500 p-4 z-[80] pixel-font text-xl shadow-lg pointer-events-none';
el.innerText = msg;
document.getElementById('app').appendChild(el);
setTimeout(() => el.remove(), 2000);
}
// Returns styled HTML for names based on their role
function getNameHTML(name, status) {
const cleanName = name ? name.toString().replace(/</g, "<").replace(/>/g, ">") : "UNKNOWN";
if (status === "Verified") {
return `<span class="text-blue-300 font-bold" style="text-shadow: 0 0 5px #93c5fd, 0 0 10px #3b82f6;">${cleanName} <i class="fas fa-check-circle text-[8px] text-blue-400"></i></span>`;
} else if (status === "Admin") {
return `<span class="text-red-500 font-bold" style="text-shadow: 0 0 5px #ef4444, 0 0 10px #dc2626;">${cleanName} <i class="fas fa-shield-alt text-[8px] text-red-500"></i></span>`;
} else if (status === "Owner") {
return `<span class="name-owner-container"><span class="name-owner-text">${cleanName} <i class="fas fa-crown text-[8px] text-yellow-400"></i></span></span>`;
} else {
return `<span class="text-green-400">${cleanName}</span>`;
}
}
// === PEERJS & STATE ===
let peer = null;
let connections = [];
let hostConn = null;
let myPeerId = null;
let isHost = false;
let hasAgreedToChat = false;
let userData = {
username: "GUEST",
xp: 0,
level: 1,
status: "Player",
isGuest: true,
moreInfo: { bits: 0, dailyStreak: 0, lastDaily: "", passXp: 0, passClaimed: [] }
};
// Define cards with 'requiresTarget' flag for dynamic logic
const CARD_TYPES = {
CRASH: { id: 'CRASH', name: 'SYSTEM CRASH', color: 'bg-red-600', icon: 'fa-skull', desc: 'You explode. No questions asked.', requiresTarget: false },
PATCH: { id: 'PATCH', name: 'PATCH', color: 'bg-green-600', icon: 'fa-wrench', desc: 'Defuse a System Crash.', requiresTarget: false },
ATTACK: { id: 'ATTACK', name: 'DDOS', color: 'bg-yellow-600', icon: 'fa-meteor', desc: 'End turn. Next bot takes 2 turns.', requiresTarget: false },
SKIP: { id: 'SKIP', name: 'LAG SPIKE', color: 'bg-blue-600', icon: 'fa-forward', desc: 'End your turn without drawing.', requiresTarget: false },
FUTURE: { id: 'FUTURE', name: 'DEBUG', color: 'bg-purple-600', icon: 'fa-eye', desc: 'See the top 3 cards.', requiresTarget: false },
SHUFFLE: { id: 'SHUFFLE', name: 'REBOOT', color: 'bg-gray-600', icon: 'fa-random', desc: 'Shuffle the deck.', requiresTarget: false },
STEAL: { id: 'STEAL', name: 'PHISH', color: 'bg-orange-600', icon: 'fa-hand-paper', desc: 'Steal a random card from a player.', requiresTarget: false },
FRAG_0: { id: 'FRAG_0', name: 'FRAG 0', color: 'bg-teal-600', icon: 'fa-0', desc: 'Collect matching pair to steal.', requiresTarget: false },
FRAG_1: { id: 'FRAG_1', name: 'FRAG 1', color: 'bg-teal-600', icon: 'fa-1', desc: 'Collect matching pair to steal.', requiresTarget: false },
DENIED: { id: 'DENIED', name: 'DENIED', color: 'bg-red-900', icon: 'fa-ban', desc: 'Stop an action card immediately.', requiresTarget: false },
HACK: { id: 'HACK', name: 'HACK', color: 'bg-red-800', icon: 'fa-user-secret', desc: 'Look at a hand and steal a specific card.', requiresTarget: true },
SUDO: { id: 'SUDO', name: 'SUDO', color: 'bg-yellow-700', icon: 'fa-terminal', desc: 'Force a player to draw 2 cards.', requiresTarget: true },
BACKUP: { id: 'BACKUP', name: 'BACKUP', color: 'bg-cyan-700', icon: 'fa-hdd', desc: 'Draw 1 card from the bottom of the deck.', requiresTarget: false },
CACHE: { id: 'CACHE', name: 'CACHE', color: 'bg-green-700', icon: 'fa-box-open', desc: 'Draw 2 cards.', requiresTarget: false }
};
let localState = {
players: [], deck: [], discardPile: [], turnIndex: 0, status: 'LOBBY',
attacksBuffered: 0, mode: 'single', maxPlayers: 4, isPublic: false, kickVotes: {}, cardsPlayedThisGame: 0,
activeFlashCard: null,
interruptWindow: null,
chatEnabled: false
};
// === INITIALIZATION ===
window.onload = () => {
initEmotes();
// Pre-fill username from local cache if it exists, but don't auto-login bypassing security
const cachedUser = localStorage.getItem('system_crash_username');
if (cachedUser) {
document.getElementById('login-user').value = cachedUser;
}
};
function initEmotes() {
const emojis = ['🤖','💥','🤬','👀','🗑️','🔥','💀','🤡','🤑','💤','👋','🫠','😵','🕳','🫡','👍','🍞','🫴🃏','😬','🥲','😀','🤣','💩','😐','😑','😶','🙃','😎'];
const textEmotes = ['GG', 'YOOO', '*Cooked*', 'Nice...', 'Kick?', 'Yes', 'No'];
const container = document.getElementById('emote-menu');
let html = '';
emojis.forEach(e => html += `<button onclick="sendEmote('${e}')" class="text-2xl hover:bg-slate-700 rounded p-1">${e}</button>`);
textEmotes.forEach(t => { html += `<button onclick="sendEmote('${t}')" class="col-span-2 text-[10px] md:text-xs text-yellow-400 hover:bg-slate-700 py-1 font-bold pixel-font border border-slate-600 rounded">${t}</button>`; });
// The input row is static HTML, so we PREPEND our buttons to it
const inputRow = document.getElementById('chat-input-row');
container.innerHTML = html + container.innerHTML;
}
// --- AUTH HANDLERS ---
window.showLogin = () => { document.getElementById('auth-buttons').classList.add('hidden'); document.getElementById('login-form').classList.replace('hidden', 'flex'); }
window.showSignup = () => { document.getElementById('auth-buttons').classList.add('hidden'); document.getElementById('signup-form').classList.replace('hidden', 'flex'); }
window.showAuthButtons = () => { document.getElementById('login-form').classList.replace('flex', 'hidden'); document.getElementById('signup-form').classList.replace('flex', 'hidden'); document.getElementById('auth-buttons').classList.remove('hidden'); }
window.performLogin = async () => {
const user = document.getElementById('login-user').value.trim().toUpperCase();
const pass = document.getElementById('login-pass').value.trim();
if(!user || !pass) return alert("Missing Creds");
if (APPS_SCRIPT_URL === "YOUR_WEB_APP_URL_HERE") {
alert("Developer: Please set your Google Apps Script URL in the code!");
return;
}
document.getElementById('login-form').classList.add('hidden');
document.getElementById('loading-msg').innerText = "AUTHENTICATING...";
document.getElementById('loading-msg').classList.remove('hidden');
try {
const response = await fetch(APPS_SCRIPT_URL, {
method: 'POST',
body: JSON.stringify({ action: 'login', username: user, password: pass })
});
const result = await response.json();
if (result.success) {
let info = { bits: 0, dailyStreak: 0, lastDaily: "", passXp: 0, passClaimed: [] };
if (result.data.moreInfo) {
try { info = JSON.parse(result.data.moreInfo); } catch(e) {}
}
userData = { username: user, xp: result.data.xp, level: result.data.level, status: result.data.status, moreInfo: info, isGuest: false };
localStorage.setItem('system_crash_username', user); // Remember username for next time
updateMenuUI();
document.getElementById('auth-screen').classList.add('hidden');
document.getElementById('main-menu').classList.remove('hidden');
} else {
alert("Login Failed: " + result.message);
document.getElementById('login-form').classList.remove('hidden');
}
} catch (e) {
console.error(e);
alert("Network error. Please check your connection or Apps Script URL.");
document.getElementById('login-form').classList.remove('hidden');
}
document.getElementById('loading-msg').classList.add('hidden');
}
window.performSignup = async () => {
const user = document.getElementById('signup-user').value.trim().toUpperCase();
const pass = document.getElementById('signup-pass').value.trim();
if(!user || !pass) return alert("Missing Creds");
if (APPS_SCRIPT_URL === "YOUR_WEB_APP_URL_HERE") {
alert("Developer: Please set your Google Apps Script URL in the code!");
return;
}
document.getElementById('signup-form').classList.add('hidden');
document.getElementById('loading-msg').innerText = "CREATING ACCOUNT...";
document.getElementById('loading-msg').classList.remove('hidden');
try {
const response = await fetch(APPS_SCRIPT_URL, {
method: 'POST',
body: JSON.stringify({ action: 'signup', username: user, password: pass })
});
const result = await response.json();
if (result.success) {
alert("Account Created! You can now log in.");
document.getElementById('login-user').value = user;
showAuthButtons();
} else {
alert("Signup Failed: " + result.message);
document.getElementById('signup-form').classList.remove('hidden');
}
} catch (e) {
console.error(e);
alert("Network error. Please check your connection or Apps Script URL.");
document.getElementById('signup-form').classList.remove('hidden');
}
document.getElementById('loading-msg').classList.add('hidden');
}
window.guestLogin = () => { userData = { username: "GUEST_" + Math.floor(Math.random()*999), xp: 0, level: 1, status: "Player", isGuest: true, moreInfo: { bits: 0, dailyStreak: 0, lastDaily: "", passXp: 0, passClaimed: [] } }; updateMenuUI(); document.getElementById('auth-screen').classList.add('hidden'); document.getElementById('main-menu').classList.remove('hidden'); }
window.logout = () => { localStorage.removeItem('system_crash_username'); location.reload(); }
function updateMenuUI() {
document.getElementById('menu-username').innerHTML = getNameHTML(userData.username, userData.status);
document.getElementById('menu-level').innerText = userData.level;
const nextXp = Math.floor(100 * Math.pow(1.2, userData.level - 1));
document.getElementById('menu-xp').innerText = Math.floor(userData.xp);
document.getElementById('menu-xp-next').innerText = nextXp;
const pct = Math.min(100, (userData.xp / nextXp) * 100);
document.getElementById('xp-bar').style.width = `${pct}%`;
document.getElementById('menu-bits').innerText = userData.moreInfo.bits || 0;
}
function syncCloud() {
if (userData.isGuest || APPS_SCRIPT_URL === "YOUR_WEB_APP_URL_HERE") return;
fetch(APPS_SCRIPT_URL, {
method: 'POST',
body: JSON.stringify({
action: 'update',
username: userData.username,
xp: userData.xp,
lvl: userData.level,
moreInfo: userData.moreInfo
})
}).catch(e => console.log("Failed to sync data to cloud."));
}
function addXp(amount) {
if (userData.isGuest) return;
userData.xp += amount;
if(!userData.moreInfo.passXp) userData.moreInfo.passXp = 0;
userData.moreInfo.passXp += amount; // Earn Pass XP simultaneously
let nextXp = Math.floor(100 * Math.pow(1.2, userData.level - 1));
while (userData.xp >= nextXp) {
userData.xp -= nextXp;
userData.level++;
nextXp = Math.floor(100 * Math.pow(1.2, userData.level - 1));
showToast("LEVEL UP!");
}
updateMenuUI();
// Sync to Database
if (APPS_SCRIPT_URL !== "YOUR_WEB_APP_URL_HERE") {
fetch(APPS_SCRIPT_URL, {
method: 'POST',
body: JSON.stringify({ action: 'update', username: userData.username, xp: userData.xp, lvl: userData.level })
}).catch(e => console.log("Failed to sync XP to cloud."));
}
}
// --- HUB FUNCTIONS (LEADERBOARD, DAILY, PASS) ---
window.closeHubModals = () => {
document.getElementById('leaderboard-modal').classList.add('hidden');
document.getElementById('daily-modal').classList.add('hidden');
document.getElementById('pass-modal').classList.add('hidden');
}
window.showLeaderboard = async () => {
document.getElementById('leaderboard-modal').classList.remove('hidden');
document.getElementById('leaderboard-list').innerHTML = `<tr><td colspan="4" class="text-center py-4 text-slate-500 animate-pulse">FETCHING DATABASE...</td></tr>`;
if (APPS_SCRIPT_URL === "YOUR_WEB_APP_URL_HERE") {
document.getElementById('leaderboard-list').innerHTML = `<tr><td colspan="4" class="text-center py-4 text-red-500">NO DATABASE CONNECTED</td></tr>`;
return;
}
try {
const response = await fetch(APPS_SCRIPT_URL, { method: 'POST', body: JSON.stringify({ action: 'leaderboard' }) });
const result = await response.json();
if (result.success && result.data) {
let html = '';
result.data.forEach((p, i) => {
const rankColor = i === 0 ? 'text-yellow-400' : (i === 1 ? 'text-slate-300' : (i === 2 ? 'text-amber-600' : 'text-white'));
html += `<tr class="border-b border-slate-700 hover:bg-slate-700 transition">
<td class="py-3 ${rankColor} font-bold">${i + 1}</td>
<td class="py-3">${getNameHTML(p.name, p.status)}</td>
<td class="py-3 text-right text-cyan-400">${p.lvl}</td>
<td class="py-3 text-right text-yellow-500">${Math.floor(p.xp)}</td>
</tr>`;
});
document.getElementById('leaderboard-list').innerHTML = html;
}
} catch (e) {
document.getElementById('leaderboard-list').innerHTML = `<tr><td colspan="4" class="text-center py-4 text-red-500">FAILED TO LOAD</td></tr>`;
}
}
window.showDaily = () => {
document.getElementById('daily-modal').classList.remove('hidden');
renderDailyUI();
}
function renderDailyUI() {
const today = new Date().toDateString();
const streak = userData.moreInfo.dailyStreak || 0;
const alreadyClaimed = userData.moreInfo.lastDaily === today;
document.getElementById('daily-streak-text').innerText = streak;
const btn = document.getElementById('claim-daily-btn');
if (alreadyClaimed) {
btn.innerText = "CLAIMED";
btn.classList.add('opacity-50', 'cursor-not-allowed');
btn.disabled = true;
} else {
btn.innerText = "CLAIM REWARD";
btn.classList.remove('opacity-50', 'cursor-not-allowed');
btn.disabled = false;
}
const rewards = [50, 100, 200, 500]; // Bits rewards
const container = document.getElementById('daily-cards-container');
let html = '';
for(let i=0; i<4; i++) {
const isActive = (!alreadyClaimed && i === streak);
const isPast = i < streak || (alreadyClaimed && streak===0 && i<3) || (alreadyClaimed && i <= streak);
let border = "border-slate-600";
let iconColor = "text-slate-500";
if (isActive) { border = "border-cyan-400 animate-pulse"; iconColor = "text-cyan-400"; }
else if (isPast && !isActive) { border = "border-green-500 opacity-50"; iconColor = "text-green-500"; }
html += `
<div class="w-16 h-24 md:w-24 md:h-32 bg-slate-800 rounded border-2 ${border} flex flex-col items-center justify-center relative">
<div class="absolute top-1 text-[8px] text-slate-400 pixel-font">DAY ${i+1}</div>
<i class="fas fa-coins text-2xl md:text-4xl ${iconColor} mb-2"></i>
<div class="text-[10px] md:text-xs text-yellow-400 pixel-font">${rewards[i]}</div>
</div>
`;
}
container.innerHTML = html;
}
window.claimDaily = () => {
if (userData.isGuest) return showToast("GUESTS CANNOT CLAIM");
const today = new Date().toDateString();
if (userData.moreInfo.lastDaily === today) return;
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
if (userData.moreInfo.lastDaily === yesterday.toDateString()) {
userData.moreInfo.dailyStreak = (userData.moreInfo.dailyStreak + 1) % 4;
} else {
userData.moreInfo.dailyStreak = 0;
}
const rewards = [50, 100, 200, 500];
const earned = rewards[userData.moreInfo.dailyStreak];
if(!userData.moreInfo.bits) userData.moreInfo.bits = 0;
userData.moreInfo.bits += earned;
userData.moreInfo.lastDaily = today;
if (userData.moreInfo.dailyStreak === 3) userData.moreInfo.dailyStreak = -1; // Reset mechanism
showToast(`CLAIMED ${earned} BITS!`);
syncCloud();
renderDailyUI();
updateMenuUI();
}
window.showPass = () => {
document.getElementById('pass-modal').classList.remove('hidden');
const xp = userData.moreInfo.passXp || 0;
const level = Math.floor(xp / 500) + 1;
const currentXp = xp % 500;
document.getElementById('pass-level-text').innerText = level;
document.getElementById('pass-xp-text').innerText = currentXp;
document.getElementById('pass-xp-bar').style.width = `${(currentXp / 500) * 100}%`;
const container = document.getElementById('pass-tiers-container');
let html = '';
if (!userData.moreInfo.passClaimed) userData.moreInfo.passClaimed = [];
// Show current level and next 4 levels
for(let i = level; i < level + 5; i++) {
const isClaimed = userData.moreInfo.passClaimed.includes(i);
const canClaim = i < level;
const isCurrent = i === level;
let btnHtml = '';
if (isClaimed) btnHtml = `<button class="bg-slate-700 text-slate-500 py-1 px-3 rounded pixel-font text-[10px]" disabled>CLAIMED</button>`;
else if (canClaim) btnHtml = `<button onclick="claimPass(${i})" class="bg-purple-600 hover:bg-purple-500 text-white py-1 px-3 rounded shadow-[2px_2px_0px_0px_#000] pixel-font text-[10px] animate-pulse">CLAIM</button>`;
else btnHtml = `<button class="bg-slate-700 text-slate-500 py-1 px-3 rounded pixel-font text-[10px]" disabled>LOCKED</button>`;
html += `
<div class="flex items-center justify-between bg-slate-900 p-3 rounded border ${isCurrent ? 'border-purple-500' : 'border-slate-700'}">
<div class="flex items-center gap-4">
<div class="text-purple-400 pixel-font text-xs w-12">LVL ${i}</div>
<div class="flex items-center gap-2 text-yellow-400 pixel-font text-xs"><i class="fas fa-coins"></i> 100 BITS</div>
</div>
${btnHtml}
</div>
`;
}
container.innerHTML = html;
}
window.claimPass = (tierLevel) => {
if (userData.isGuest) return;
if (!userData.moreInfo.passClaimed) userData.moreInfo.passClaimed = [];
if (userData.moreInfo.passClaimed.includes(tierLevel)) return;
userData.moreInfo.passClaimed.push(tierLevel);
if(!userData.moreInfo.bits) userData.moreInfo.bits = 0;
userData.moreInfo.bits += 100;
showToast("CLAIMED 100 BITS!");
syncCloud();
window.showPass();
updateMenuUI();
}
// --- GAME LOGIC ---
function setupDeckForDeal(playerCount) {
let deck = [];
const multipliers = Math.max(1, Math.ceil((playerCount * 4 + 75) / 60));
for(let i=0; i < 4 * multipliers; i++) deck.push(CARD_TYPES.ATTACK, CARD_TYPES.SKIP, CARD_TYPES.FUTURE, CARD_TYPES.SHUFFLE, CARD_TYPES.STEAL, CARD_TYPES.FRAG_0, CARD_TYPES.FRAG_1, CARD_TYPES.HACK, CARD_TYPES.DENIED, CARD_TYPES.SUDO, CARD_TYPES.CACHE, CARD_TYPES.BACKUP);
for(let i=0; i < 3 * multipliers; i++) deck.push(CARD_TYPES.ATTACK, CARD_TYPES.SKIP, CARD_TYPES.FRAG_0, CARD_TYPES.FRAG_1);
localState.deck = shuffle(deck);
}
function dealHands() {
localState.players.forEach(p => {
p.hand = [CARD_TYPES.PATCH];
for(let i=0; i<4; i++) { if (localState.deck.length > 0) p.hand.push(localState.deck.pop()); }
});
}
function insertBombs(playerCount) {
const extraDefuses = Math.max(2, Math.floor(playerCount * 0.5));
for (let i = 0; i < extraDefuses; i++) localState.deck.push(CARD_TYPES.PATCH);
const bombsNeeded = playerCount - 1;
for (let i = 0; i < bombsNeeded; i++) localState.deck.push(CARD_TYPES.CRASH);
localState.deck = shuffle(localState.deck);
}
function shuffle(array) { return array.sort(() => Math.random() - 0.5); }
window.startGame = (mode) => {
document.getElementById('main-menu').classList.add('hidden');
if (mode === 'single') startSinglePlayer();
}
window.showMultiplayerMenu = () => {
document.getElementById('main-menu').classList.add('hidden');
document.getElementById('lobby-menu').classList.remove('hidden');
}
function startSinglePlayer() {
localState.mode = 'single';
isHost = true;
myPeerId = 'player';
localState.players = [
{ id: 'player', name: userData.username, hand: [], isBot: false, isDead: false, turnsToTake: 1, emote: null, muted: false, status: userData.status },
{ id: 'bot1', name: 'BOT_ALPHA', hand: [], isBot: true, isDead: false, turnsToTake: 1, emote: null, muted: false, status: 'Player' },
{ id: 'bot2', name: 'BOT_BETA', hand: [], isBot: true, isDead: false, turnsToTake: 1, emote: null, muted: false, status: 'Player' },
{ id: 'bot3', name: 'BOT_GAMMA', hand: [], isBot: true, isDead: false, turnsToTake: 1, emote: null, muted: false, status: 'Player' }
];
localState.cardsPlayedThisGame = 0;
localState.chatEnabled = false;
setupDeckForDeal(4);
dealHands();
insertBombs(4);
localState.status = 'PLAYING';
localState.turnIndex = Math.floor(Math.random() * 4);
document.getElementById('game-board').classList.remove('hidden');
renderGame();
checkBotTurn();
}
// --- NETWORKING ---
window.createRoom = (isPublic = false) => {
const code = Math.random().toString(36).substring(2, 6).toUpperCase();
const peerId = 'syscrash_' + code;
initPeer(peerId, true, null, isPublic);
}
window.joinRoom = () => {
const code = document.getElementById('room-code-input').value.toUpperCase();
if(code.length !== 4) return alert("Invalid Code");
const peerId = 'syscrash_' + code;
initPeer(null, false, peerId);
}
window.findPublicRoom = () => {
alert("Public Matchmaking unavailable in Serverless Mode. Hosting New Game...");
createRoom(true);
}
function initPeer(id, host, targetId, isPublic = false) {
isHost = host;
peer = new Peer(id);
peer.on('open', (myId) => {
myPeerId = myId;
if (isHost) {
const code = myId.split('_')[1];
document.getElementById('display-room-code').innerText = code;
enterWaitingRoom();
localState.mode = 'multi';
localState.players = [{ id: myId, name: userData.username, hand: [], isBot: false, isDead: false, turnsToTake: 1, emote: null, muted: false, status: userData.status }];
localState.status = 'LOBBY';
localState.maxPlayers = parseInt(document.getElementById('max-players-input').value) || 4;
localState.isPublic = isPublic;
localState.chatEnabled = document.getElementById('chat-enabled-check').checked;
// Show host options
document.getElementById('host-options').classList.remove('hidden');
renderLobby();
} else {
hostConn = peer.connect(targetId);
hostConn.on('open', () => {
enterWaitingRoom();
document.getElementById('display-room-code').innerText = targetId.split('_')[1];
hostConn.send({ type: 'JOIN', name: userData.username, status: userData.status });
});
hostConn.on('data', (data) => handleClientData(data));
hostConn.on('close', () => { alert("Disconnected from Host"); backToMain(); });
}
});
peer.on('connection', (conn) => {
if (isHost) {
connections.push(conn);
conn.on('data', (data) => handleHostData(data, conn));
conn.on('close', () => connections = connections.filter(c => c !== conn));
}
});
peer.on('error', (err) => { console.error(err); alert("Connection Error. Check network."); });
}
function handleHostData(data, conn) {
if (data.type === 'JOIN') {
if (localState.status !== 'LOBBY') return;
const newP = { id: conn.peer, name: data.name, hand: [], isBot: false, isDead: false, turnsToTake: 1, emote: null, muted: false, status: data.status || 'Player' };
localState.players.push(newP);
broadcastState();
}
else if (data.type === 'PLAY_CARD') {
const pIdx = localState.players.findIndex(p => p.id === conn.peer);
if (pIdx === localState.turnIndex) window.playCard(data.cardIndex);
}
else if (data.type === 'PLAY_TARGETED') {
const pIdx = localState.players.findIndex(p => p.id === conn.peer);
if (pIdx === localState.turnIndex) {
const card = localState.players[pIdx].hand[data.cardIndex];
if(card.requiresTarget) triggerInterrupt(card, pIdx, data.cardIndex, data.targetId);
else executeCardEffect(card, pIdx, data.cardIndex, data.targetId);
}
}
else if (data.type === 'DRAW_CARD') {
const pIdx = localState.players.findIndex(p => p.id === conn.peer);
if (pIdx === localState.turnIndex) window.playerDrawCard(true);
}
else if (data.type === 'EMOTE') {
const pIdx = localState.players.findIndex(p => p.id === conn.peer);
if (pIdx > -1) {
// Check Mute
if (localState.players[pIdx].muted) return;
localState.players[pIdx].emote = data.emoji;
broadcastState();
setTimeout(() => { localState.players[pIdx].emote = null; broadcastState(); }, 2000);
}
}
else if (data.type === 'PLAY_DENIED') handleDenied(conn.peer);
else if (data.type === 'HACK_COMPLETE') executeHackSteal(data.targetId, data.cardIdx);
else if (data.type === 'CHAT') {
// Broadcast chat if enabled and not muted
if (localState.chatEnabled) {
const pIdx = localState.players.findIndex(p => p.id === conn.peer);
if (pIdx > -1 && !localState.players[pIdx].muted) {
localState.players[pIdx].emote = data.msg; // Reuse emote bubble
broadcastState();
setTimeout(() => { localState.players[pIdx].emote = null; broadcastState(); }, 4000);
}
}
}
else if (data.type === 'SELECT_TARGET') {
// Should not happen on Host
}
}
function handleClientData(data) {