-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathcommunity.html
More file actions
1648 lines (1563 loc) · 91 KB
/
Copy pathcommunity.html
File metadata and controls
1648 lines (1563 loc) · 91 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" />
<meta name="description" content="The Tiny World Builder community — text rooms, direct messages, and a member directory. Chat with other builders in the tinyverse." />
<title>Community - Tiny World Builder</title>
<link rel="icon" href="assets/twlogo.png" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300..700&display=swap" />
<link rel="stylesheet" href="styles/landing.css" />
<script>
// Auth bootstrap — mirrors tiny-world-builder.html so the community page can
// sign users in directly (Netlify Identity) without bouncing to the builder.
(function communityAuthBootstrap() {
window.__tinyworldAuthReady = new Promise(function (resolve) {
window.__resolveTinyWorldAuthReady = resolve;
setTimeout(function () { resolve(false); }, 2500);
});
})();
</script>
<script id="tinyworld-auth-importmap" type="importmap">
{
"imports": {
"@netlify/identity": "./vendor/netlify/identity.js",
"gotrue-js": "./vendor/netlify/gotrue.js"
}
}
</script>
<script src="engine/world/00-custom-confirm.js"></script>
<script type="module" src="vendor/tinyworld-auth.js"></script>
<style>
/* -------- community page -------- */
[hidden] { display: none !important; }
.community-main {
width: min(1680px, calc(100vw - 32px));
max-width: none;
height: 100vh;
height: 100dvh; /* dvh handles mobile browser chrome; vh is the fallback above */
margin: 0 auto;
padding: 116px 16px 24px;
display: flex;
flex-direction: column;
overflow: hidden; /* outer page never scrolls on desktop; chat scrolls internally */
}
.community-headline {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 24px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.community-headline h1 {
font-family: var(--display-font);
font-size: clamp(30px, 4vw, 44px);
margin: 0 0 4px;
color: #1c2533;
}
.community-headline p { margin: 0; color: #404a5c; font-size: 15px; max-width: 52ch; }
.me-chip {
display: inline-flex; align-items: center; gap: 9px;
height: 42px; padding: 0 14px 0 6px; border-radius: var(--radius-md);
background: rgba(255,255,255,0.66); border: 1px solid rgba(255,255,255,0.55);
font-size: 13px; font-weight: 700;
cursor: pointer; color: var(--ink); font-family: inherit; white-space: nowrap;
}
.me-chip:hover { background: rgba(255,255,255,0.85); }
.me-chip .avatar { width: 28px; height: 28px; font-size: 11px; }
/* auth controls living inside the nav pill */
.site-nav .nav-auth { flex: 0 0 auto; margin-left: 2px; }
/* [hidden] must beat the display rules below (author .btn/.icon-btn display
overrides the UA [hidden]{display:none}, otherwise signed-in users still
see "Sign in" and signed-out users see the edit/chip controls). */
.site-nav .nav-auth[hidden] { display: none !important; }
.site-nav .btn.primary.nav-auth {
height: 42px; border-radius: var(--radius-md); padding: 0 16px;
font-weight: 750; font-size: 13px;
background: linear-gradient(180deg, #2d7ef5 0%, var(--accent) 100%);
box-shadow: inset 0 1px 0 rgba(255,255,255,0.42), inset 0 -4px 0 rgba(17,51,128,0.22), 0 12px 24px -14px rgba(22,76,170,0.68);
}
.site-nav .icon-btn.nav-auth {
width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center;
border-radius: var(--radius-md); background: rgba(255,255,255,0.66);
border: 1px solid rgba(255,255,255,0.55); color: var(--ink); cursor: pointer; padding: 0;
}
.site-nav .icon-btn.nav-auth:hover { background: rgba(255,255,255,0.85); }
.site-nav .icon-btn.nav-auth svg { width: 16px; height: 16px; }
/* human verification banner */
.verify-banner {
display: flex; align-items: center; gap: 14px;
margin: 0 0 14px; padding: 12px 14px;
border: 1px solid rgba(255,255,255,0.55); border-radius: var(--radius-lg);
background: rgba(255,255,255,0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(180%);
-webkit-backdrop-filter: blur(18px) saturate(180%);
}
.verify-banner svg { width: 26px; height: 26px; flex: 0 0 auto; color: var(--accent); fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.verify-banner .vb-text { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-width: 0; }
.verify-banner .vb-text strong { font-size: 14px; color: #1c2533; }
.verify-banner .vb-text span { font-size: 12.5px; color: #404a5c; }
.verify-timing-note { font-size: 12.5px; color: #404a5c; background: rgba(58,114,200,0.08); border: 1px solid rgba(58,114,200,0.16); border-radius: var(--radius-md); padding: 9px 11px; }
.community-policy-footer {
margin-top: 16px;
padding: 12px 16px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
font-size: 12.5px;
color: #404a5c;
}
.community-policy-footer strong { color: #1c2533; }
.community-policy-footer nav { display: flex; flex-wrap: wrap; gap: 10px; }
.community-policy-footer a { color: var(--accent); font-weight: 700; text-decoration: none; }
.community-policy-footer a:hover { text-decoration: underline; }
/* shell: 3 columns */
.community-shell {
display: grid;
grid-template-columns: 248px minmax(0, 1fr) 268px;
gap: 18px;
align-items: stretch;
flex: 1 1 auto;
min-height: 0;
}
.c-panel {
background: rgba(255,255,255,0.72);
border: 1px solid rgba(255,255,255,0.6);
border-radius: var(--radius-lg);
box-shadow: var(--shadow);
backdrop-filter: blur(20px) saturate(180%);
-webkit-backdrop-filter: blur(20px) saturate(180%);
display: flex; flex-direction: column; min-height: 0;
}
.c-panel-head {
display: flex; align-items: center; justify-content: space-between; gap: 8px;
padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.c-panel-head h2 {
margin: 0; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase;
color: var(--muted); font-weight: 700;
}
.c-panel-body { overflow-y: auto; padding: 10px; flex: 1 1 auto; min-height: 0; }
/* right rail: members (capped, scrolls inside) + live CCTV feeds below */
.right-rail { display: flex; flex-direction: column; gap: 18px; min-height: 0; }
.right-rail .members-panel { flex: 0 1 auto; max-height: 340px; }
.right-rail .cctv-panel { flex: 1 1 auto; min-height: 160px; }
.cctv-panel .c-panel-body { padding: 0; display: flex; position: relative; background: #05060a; overflow: hidden; }
.cctv-panel iframe { width: 100%; height: 100%; border: 0; display: block; background: #05060a; opacity: 0; pointer-events: none; transition: opacity 0.18s ease; }
.cctv-panel iframe.is-ready { opacity: 1; pointer-events: auto; }
.cctv-loading {
position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
padding: 18px; text-align: center; color: var(--muted); font-size: 13px; background: #05060a;
}
.cctv-loading .skeleton-line { max-width: 170px; }
.cctv-empty { margin: auto; padding: 18px; text-align: center; color: var(--muted); font-size: 13px; }
.icon-btn {
display: inline-flex; align-items: center; justify-content: center;
width: 28px; height: 28px; border-radius: var(--radius-sm);
border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer;
padding: 0; transition: filter .15s, transform .15s;
}
.icon-btn:hover { filter: brightness(0.97); transform: translateY(-1px); }
.icon-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.danger-icon { color: #c0392b; border-color: #f0d2d2; background: #fbecec; }
.icon-btn.danger-icon:hover { filter: brightness(0.98); }
/* rooms + dm list */
.c-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.c-list-section { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 10px 8px 5px; }
.room-row, .dm-row {
display: flex; align-items: center; gap: 9px; width: 100%;
padding: 8px 10px; border-radius: var(--radius-md);
border: 1px solid transparent; background: transparent; cursor: pointer;
text-align: left; color: var(--ink); font-family: inherit; font-size: 14px;
}
.room-row:hover, .dm-row:hover { background: rgba(58,114,200,0.08); }
.room-row.active, .dm-row.active { background: rgba(58,114,200,0.14); border-color: rgba(58,114,200,0.30); font-weight: 600; }
.room-row .hash { color: var(--muted); font-weight: 700; }
.room-row .lock { width: 13px; height: 13px; color: var(--muted); }
.room-row .name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* avatars */
.avatar {
width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
object-fit: cover; background: #dfe7f2; border: 1px solid var(--line);
display: inline-flex; align-items: center; justify-content: center;
font-size: 12px; font-weight: 700; color: #4a5b78; text-transform: uppercase;
}
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.avatar.sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-wrap { position: relative; flex: 0 0 auto; }
.presence-dot {
position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px;
border-radius: 50%; background: #b8c0cc; border: 2px solid #fff;
}
.presence-dot.online { background: #36b37e; }
/* center: chat */
.chat-panel { overflow: hidden; }
.chat-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.chat-head .title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chat-head .title strong { font-size: 16px; display: flex; align-items: center; gap: 7px; }
.chat-head .title span { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .head-actions { margin-left: auto; display: flex; gap: 6px; }
.chat-scroll { flex: 1 1 auto; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.msg { display: flex; gap: 11px; }
.msg.hidden-message { opacity: 0.76; }
.msg .body { min-width: 0; flex: 1 1 auto; }
.msg .by { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg .by strong { font-size: 14px; }
.msg .by time { font-size: 11px; color: var(--muted); }
.msg .text { font-size: 14px; line-height: 1.5; color: var(--ink); word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.hidden-message .text { color: #576174; font-style: italic; }
.msg-hidden-badge { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: #7a5a1a; background: rgba(255,199,93,0.20); border: 1px solid rgba(170,113,25,0.22); border-radius: 999px; padding: 2px 7px; }
.msg-mod-actions { margin-left: auto; display: inline-flex; gap: 5px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-mod-actions, .msg:focus-within .msg-mod-actions { opacity: 1; }
.msg-mod-btn { border: 1px solid var(--line); background: rgba(255,255,255,0.78); color: var(--ink); border-radius: 999px; height: 24px; padding: 0 8px; font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; }
.msg-mod-btn:hover { filter: brightness(0.97); }
.msg-mod-btn.danger { color: #c0392b; border-color: #f0d2d2; background: #fff5f5; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); font-size: 14px; padding: 40px; }
.composer { border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
flex: 1 1 auto; resize: none; min-height: 42px; max-height: 140px;
padding: 11px 13px; border-radius: var(--radius-md); border: 1px solid var(--line);
font-family: inherit; font-size: 14px; color: var(--ink); background: #fff; line-height: 1.4;
}
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58,114,200,0.14); }
.send-btn {
display: inline-flex; align-items: center; justify-content: center; gap: 7px;
height: 42px; padding: 0 16px; border-radius: var(--radius-md); border: none;
background: var(--accent); color: #fff; font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.send-btn:hover { filter: brightness(1.08); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.send-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.composer-note { font-size: 11.5px; color: var(--muted); padding: 0 16px 10px; }
.composer-note.err { color: #c0392b; }
/* members */
.member-row {
display: flex; align-items: center; gap: 10px; width: 100%;
padding: 7px 9px; border-radius: var(--radius-md); border: 1px solid transparent;
background: transparent; cursor: pointer; text-align: left; font-family: inherit; color: var(--ink);
}
.member-row:hover { background: rgba(58,114,200,0.08); }
.member-row .mname { flex: 1 1 auto; overflow: hidden; }
.member-row .mname b { display: block; font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-row .mname small { font-size: 11.5px; color: var(--muted); }
/* modal */
.c-modal-back {
position: fixed; inset: 0; z-index: 100; display: none;
align-items: center; justify-content: center; padding: 20px;
background: rgba(20,28,44,0.42); backdrop-filter: blur(4px);
}
.c-modal-back.open { display: flex; }
.c-modal {
width: 100%; max-width: 420px; background: var(--panel);
border-radius: var(--radius-lg); box-shadow: 0 30px 80px -24px rgba(20,30,55,0.5);
border: 1px solid var(--line); padding: 22px; display: flex; flex-direction: column; gap: 16px;
}
.c-modal h2 { margin: 0; font-size: 20px; color: var(--ink); font-family: var(--display-font); }
.c-modal label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.c-modal input[type=text], .c-modal input[type=password], .c-modal textarea, .c-modal select {
width: 100%; padding: 10px 12px; border-radius: var(--radius-md); border: 1px solid var(--line);
font-family: inherit; font-size: 14px; color: var(--ink); background: #fff;
}
.c-modal input:focus, .c-modal textarea:focus, .c-modal select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58,114,200,0.14); }
.c-modal .field { display: flex; flex-direction: column; }
.c-modal .field + .field { margin-top: 12px; }
.c-modal .row { display: flex; gap: 10px; }
.c-modal .row > * { flex: 1; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.btn {
display: inline-flex; align-items: center; justify-content: center; gap: 7px;
height: 40px; padding: 0 16px; border-radius: var(--radius-md); cursor: pointer;
font-family: inherit; font-size: 14px; font-weight: 600; border: 1px solid var(--line); background: #fff; color: var(--ink);
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: #fbecec; color: #c0392b; border-color: #f0d2d2; }
.btn.full { width: 100%; }
.btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.sm { height: 32px; padding: 0 11px; font-size: 12.5px; }
/* profile card */
.profile-card-head { display: flex; gap: 14px; align-items: center; }
.profile-card-head .pc-meta h3 { margin: 0 0 2px; font-size: 18px; color: var(--ink); }
.profile-card-head .pc-meta span { font-size: 13px; color: var(--muted); }
.profile-about { font-size: 14px; line-height: 1.5; color: var(--ink); background: var(--line-soft); border-radius: var(--radius-md); padding: 12px 14px; }
.profile-about.muted { color: var(--muted); font-style: italic; }
.pc-socials { display: flex; flex-direction: column; gap: 7px; }
.pc-social { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink); text-decoration: none; }
.pc-social svg { width: 16px; height: 16px; flex: 0 0 auto; }
.pc-social a, .pc-social .val { color: var(--accent); text-decoration: none; font-weight: 600; }
.pc-social a:hover { text-decoration: underline; }
.handle-input { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius-md); background: #fff; overflow: hidden; }
.handle-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58,114,200,0.14); }
.handle-input .handle-at { padding: 0 4px 0 12px; color: var(--muted); font-weight: 600; }
.handle-input input { border: none; outline: none; flex: 1 1 auto; padding: 10px 12px 10px 2px; font-family: inherit; font-size: 14px; color: var(--ink); background: transparent; }
#profile-edit-modal { max-height: 88vh; overflow-y: auto; }
#profile-edit-modal textarea { width: 100%; resize: vertical; min-height: 64px; padding: 10px 12px; border-radius: var(--radius-md); border: 1px solid var(--line); font-family: inherit; font-size: 14px; color: var(--ink); background: #fff; }
#profile-edit-modal textarea:focus, #profile-edit-modal input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58,114,200,0.14); }
.avatar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.avatar-opt { padding: 0; border: 2px solid var(--line); border-radius: var(--radius-md); background: #fff; cursor: pointer; overflow: hidden; aspect-ratio: 1; transition: border-color .15s, transform .15s; }
.avatar-opt img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-opt:hover { transform: translateY(-1px); border-color: rgba(58,114,200,0.5); }
.avatar-opt.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58,114,200,0.18); }
.modal-error { background: #fbecec; color: #c0392b; border-radius: var(--radius-md); padding: 9px 12px; font-size: 13px; }
.modal-ok { background: #e9f6ef; color: #1d7a4d; border-radius: var(--radius-md); padding: 9px 12px; font-size: 13px; word-break: break-all; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.04em; }
.pill.role { background: rgba(58,114,200,0.12); color: var(--accent); }
.pill.role-admin { background: rgba(200,58,90,0.12); color: #c0392b; }
.pill.role-moderator { background: rgba(58,114,200,0.14); color: var(--accent); }
.pill.role-channel_creator { background: rgba(46,160,110,0.14); color: #1d7a4d; }
#pc-role-wrap { display: flex; flex-wrap: wrap; gap: 5px; }
.pc-roles-admin { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.pc-roles-label { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.pc-roles-toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.role-toggle { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border-radius: var(--radius-md); border: 1px solid var(--line); background: #fff; cursor: pointer; font-family: inherit; font-size: 13px; color: var(--ink); }
.role-toggle:hover { filter: brightness(0.97); }
.role-toggle.on { border-color: var(--accent); background: rgba(58,114,200,0.10); font-weight: 600; }
.role-toggle .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.role-toggle.on .dot { background: var(--accent); }
/* sign-in / empty gate */
.gate {
grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; justify-content: center;
gap: 14px; text-align: center; padding: 64px 24px; color: var(--muted);
}
.gate svg { width: 44px; height: 44px; stroke: var(--muted); fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.gate h2 { margin: 0; color: var(--ink); font-size: 20px; font-family: var(--display-font); }
.gate p { margin: 0; max-width: 44ch; font-size: 14px; }
.skeleton-line { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--line) 25%, var(--line-soft) 37%, var(--line) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; margin: 8px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
@media (max-width: 1040px) {
.community-shell { grid-template-columns: 220px minmax(0,1fr); }
.right-rail { display: none; }
}
@media (max-width: 720px) {
.community-main { width: min(100vw, calc(100vw - 16px)); padding: 104px 8px 18px; height: auto; min-height: 100dvh; overflow: visible; }
.community-shell { grid-template-columns: 1fr; min-height: auto; }
.rooms-panel { order: 1; max-height: 220px; }
.chat-panel { order: 2; min-height: min(560px, calc(100vh - 260px)); }
.community-policy-footer { flex-direction: column; align-items: flex-start; }
}
</style>
</head>
<body class="landing-page">
<header class="site-header" aria-label="Tiny World Builder">
<a class="site-logo" href="/" aria-label="Tiny World Builder home">
<img src="assets/twlogo-wordmark.png" alt="Tiny World Builder" width="1064" height="403" />
</a>
<nav class="site-nav" aria-label="Primary">
<a href="/">Home</a>
<a href="/#features">Features</a>
<a href="/#workflow">How it works</a>
<a href="/worlds">Worlds</a>
<a href="/docs">Docs</a>
<a href="/features">Suggest</a>
<a href="/community" aria-current="page">Community</a>
<a href="/news">News</a>
<a href="https://github.com/jasonkneen/tiny-world-builder" rel="noopener noreferrer">GitHub</a>
<a class="nav-cta" href="/tiny-world-builder">Start building</a>
<button class="btn primary nav-auth" id="headline-login-btn" hidden>Sign in</button>
<button class="icon-btn nav-auth" id="edit-profile-btn" title="Edit profile" aria-label="Edit profile" hidden>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z"/></svg>
</button>
<button id="me-chip" class="me-chip nav-auth" title="Sign out" hidden></button>
</nav>
</header>
<main class="community-main">
<div class="community-headline">
<div>
<h1>Community</h1>
<p>Rooms, direct messages, and the people of the tinyverse. Chat with other builders, share worlds, and get help.</p>
</div>
</div>
<div class="verify-banner" id="verify-banner" hidden>
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2 4 5v6c0 5 3.4 7.8 8 9 4.6-1.2 8-4 8-9V5z"/><path d="M9 12l2 2 4-4"/></svg>
<div class="vb-text">
<strong>One quick human check</strong>
<span>Answer a few easy questions to unlock posting, DMs, and joining rooms.</span>
</div>
<button class="btn primary sm" id="verify-banner-btn">Verify I'm human</button>
</div>
<div class="community-shell" id="community-shell">
<!-- Rooms / DMs -->
<aside class="c-panel rooms-panel" aria-label="Rooms and direct messages">
<div class="c-panel-head">
<h2>Channels</h2>
<div style="display:flex;gap:6px">
<button class="icon-btn" id="redeem-invite-btn" title="Redeem an invite code" aria-label="Redeem invite">
<svg viewBox="0 0 24 24"><path d="M20 12v8a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-8"/><path d="M2 7h20v5H2z"/><path d="M12 22V7"/><path d="M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z"/><path d="M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z"/></svg>
</button>
<button class="icon-btn" id="create-room-btn" title="Create a channel" aria-label="Create channel" hidden>
<svg viewBox="0 0 24 24"><path d="M12 5v14"/><path d="M5 12h14"/></svg>
</button>
</div>
</div>
<div class="c-panel-body" id="rooms-body">
<div class="skeleton-line" style="width:70%"></div>
<div class="skeleton-line" style="width:55%"></div>
<div class="skeleton-line" style="width:62%"></div>
</div>
</aside>
<!-- Chat -->
<section class="c-panel chat-panel" aria-label="Messages">
<div class="chat-head" id="chat-head">
<div class="title"><strong>Select a channel</strong><span>Pick a room or a direct message to start chatting.</span></div>
</div>
<div class="chat-scroll" id="chat-scroll">
<div class="chat-empty">No channel selected yet.</div>
</div>
<div class="composer-note err" id="composer-note" hidden></div>
<div class="composer" id="composer" hidden>
<textarea id="composer-input" rows="1" maxlength="2000" placeholder="Write a message…" aria-label="Message"></textarea>
<button class="send-btn" id="send-btn" disabled>
<svg viewBox="0 0 24 24"><path d="M22 2 11 13"/><path d="M22 2 15 22l-4-9-9-4 20-7z"/></svg>
Send
</button>
</div>
</section>
<!-- Right rail: members (top) + live CCTV feeds (below) -->
<div class="right-rail">
<aside class="c-panel members-panel" aria-label="Members">
<div class="c-panel-head">
<h2>Members</h2>
<span id="member-count" style="font-size:12px;color:var(--muted);font-weight:600"></span>
</div>
<div class="c-panel-body" id="members-body">
<div class="skeleton-line" style="width:80%"></div>
<div class="skeleton-line" style="width:65%"></div>
<div class="skeleton-line" style="width:72%"></div>
</div>
</aside>
<aside class="c-panel cctv-panel" aria-label="Live feeds">
<div class="c-panel-head">
<h2>Live feeds</h2>
<span id="cctv-world-label" style="font-size:12px;color:var(--muted);font-weight:600"></span>
</div>
<div class="c-panel-body" id="cctv-body"></div>
</aside>
</div>
</div>
<footer class="c-panel community-policy-footer" aria-label="Community policy links">
<div><strong>Zero tolerance:</strong> violations suspend community and game access — 4 hours, then 24 hours, then permanent.</div>
<nav aria-label="Legal and safety">
<a href="/terms">Terms</a>
<a href="/privacy">Privacy</a>
<a href="/code-of-conduct">Code of Conduct</a>
</nav>
</footer>
</main>
<!-- Profile card modal -->
<div class="c-modal-back" id="profile-modal-back" role="dialog" aria-modal="true" aria-labelledby="pc-name">
<div class="c-modal" id="profile-modal">
<div class="profile-card-head">
<div class="avatar-wrap"><span class="avatar lg" id="pc-avatar"></span><span class="presence-dot" id="pc-dot"></span></div>
<div class="pc-meta">
<h3 id="pc-name">Member</h3>
<span id="pc-username">@member</span>
<div id="pc-role-wrap" style="margin-top:6px" hidden><span class="pill role" id="pc-role"></span></div>
</div>
</div>
<div class="profile-about muted" id="pc-about">No bio yet.</div>
<div id="pc-socials" class="pc-socials"></div>
<div class="modal-error" id="pc-error" hidden></div>
<div class="modal-ok" id="pc-ok" hidden></div>
<div class="modal-actions">
<button class="btn primary" id="pc-message-btn">
<svg viewBox="0 0 24 24"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
Message
</button>
<button class="btn" id="pc-block-btn">Block</button>
<button class="btn danger" id="pc-ban-btn" hidden>Ban…</button>
</div>
<div id="pc-roles-admin" class="pc-roles-admin" hidden>
<div class="pc-roles-label">Roles</div>
<div id="pc-roles-toggles" class="pc-roles-toggles"></div>
</div>
<div id="pc-ban-form" hidden>
<div class="row">
<div class="field">
<label for="pc-ban-duration">Ban duration</label>
<select id="pc-ban-duration">
<option value="1">1 hour</option>
<option value="24">24 hours</option>
<option value="168">7 days</option>
<option value="0">Permanent</option>
</select>
</div>
<div class="field">
<label for="pc-ban-reason">Reason (optional)</label>
<input type="text" id="pc-ban-reason" maxlength="200" placeholder="Spam, abuse…" />
</div>
</div>
<div class="modal-actions" style="margin-top:12px">
<button class="btn" id="pc-ban-cancel">Cancel</button>
<button class="btn danger" id="pc-ban-confirm">Confirm ban</button>
</div>
</div>
<button class="btn full" id="pc-close-btn">Close</button>
</div>
</div>
<!-- Create room modal -->
<div class="c-modal-back" id="room-modal-back" role="dialog" aria-modal="true" aria-labelledby="room-modal-title">
<div class="c-modal">
<h2 id="room-modal-title">Create a room</h2>
<div class="field">
<label for="room-name">Room name</label>
<input type="text" id="room-name" maxlength="80" placeholder="e.g. show-and-tell" />
</div>
<div class="field">
<label for="room-topic">Topic (optional)</label>
<input type="text" id="room-topic" maxlength="200" placeholder="What's this room about?" />
</div>
<div class="field">
<label for="room-world">Linked world slug (optional)</label>
<input type="text" id="room-world" maxlength="60" placeholder="e.g. tidewater-bay" />
</div>
<div class="field">
<label style="display:flex;align-items:center;gap:8px;font-weight:500;cursor:pointer">
<input type="checkbox" id="room-private" style="width:auto" /> Invite-only (private)
</label>
</div>
<div class="modal-error" id="room-error" hidden></div>
<div class="modal-actions">
<button class="btn" id="room-cancel">Cancel</button>
<button class="btn primary" id="room-create">Create room</button>
</div>
</div>
</div>
<!-- Link world modal -->
<div class="c-modal-back" id="linkworld-modal-back" role="dialog" aria-modal="true" aria-labelledby="linkworld-modal-title">
<div class="c-modal">
<h2 id="linkworld-modal-title">Link a world</h2>
<div class="field">
<label for="linkworld-slug">World slug</label>
<input type="text" id="linkworld-slug" maxlength="60" placeholder="e.g. tidewater-bay (blank to unlink)" />
</div>
<div class="modal-error" id="linkworld-error" hidden></div>
<div class="modal-actions">
<button class="btn" id="linkworld-cancel">Cancel</button>
<button class="btn primary" id="linkworld-save">Save</button>
</div>
</div>
</div>
<!-- Invite modal -->
<div class="c-modal-back" id="invite-modal-back" role="dialog" aria-modal="true" aria-labelledby="invite-modal-title">
<div class="c-modal">
<h2 id="invite-modal-title">Invite to room</h2>
<p style="margin:0;color:var(--muted);font-size:13.5px" id="invite-sub">Create a shareable invite link.</p>
<div class="row">
<div class="field">
<label for="invite-expiry">Expires in</label>
<select id="invite-expiry">
<option value="0">Never</option>
<option value="24">24 hours</option>
<option value="168">7 days</option>
</select>
</div>
<div class="field">
<label for="invite-maxuses">Max uses</label>
<input type="text" id="invite-maxuses" inputmode="numeric" placeholder="Unlimited" />
</div>
</div>
<div class="modal-error" id="invite-error" hidden></div>
<div class="modal-ok" id="invite-result" hidden></div>
<div class="modal-actions">
<button class="btn" id="invite-close">Close</button>
<button class="btn primary" id="invite-generate">Generate link</button>
</div>
</div>
</div>
<!-- Redeem invite modal -->
<div class="c-modal-back" id="redeem-modal-back" role="dialog" aria-modal="true" aria-labelledby="redeem-modal-title">
<div class="c-modal">
<h2 id="redeem-modal-title">Redeem an invite</h2>
<div class="field">
<label for="redeem-code">Invite code</label>
<input type="text" id="redeem-code" maxlength="64" placeholder="Paste your invite code" />
</div>
<div class="modal-error" id="redeem-error" hidden></div>
<div class="modal-actions">
<button class="btn" id="redeem-cancel">Cancel</button>
<button class="btn primary" id="redeem-confirm">Join room</button>
</div>
</div>
</div>
<!-- Sign-in modal -->
<div class="c-modal-back" id="login-modal-back" role="dialog" aria-modal="true" aria-labelledby="login-modal-title">
<div class="c-modal">
<h2 id="login-modal-title">Sign in</h2>
<p style="margin:0;color:var(--muted);font-size:13.5px" id="login-sub">Sign in to chat, send DMs, and join rooms.</p>
<button class="btn full" id="login-wallet-btn" style="gap:9px">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 7.5h11.8a2.7 2.7 0 0 1 0 5.4H9.2"/><path d="M3 5.5h14a3 3 0 0 1 3 3v7a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3z"/><circle cx="16.5" cy="12" r="1.2" fill="currentColor" stroke="none"/></svg>
<span class="login-wallet-label">Sign in with Phantom</span>
</button>
<div style="display:flex;align-items:center;gap:10px;color:var(--muted);font-size:12px">
<span style="flex:1;height:1px;background:var(--line)"></span>or email<span style="flex:1;height:1px;background:var(--line)"></span>
</div>
<div class="field">
<label for="login-email">Email</label>
<input type="text" id="login-email" autocomplete="email" placeholder="you@example.com" />
</div>
<div class="field">
<label for="login-password">Password</label>
<input type="password" id="login-password" autocomplete="current-password" placeholder="Your password" />
</div>
<div class="field" id="login-name-field" hidden>
<label for="login-name">Display name</label>
<input type="text" id="login-name" maxlength="80" placeholder="How you'll appear" />
</div>
<div class="modal-error" id="login-error" hidden></div>
<div class="modal-ok" id="login-ok" hidden></div>
<div class="modal-actions">
<button class="btn" id="login-close">Close</button>
<button class="btn primary" id="login-submit">Sign in</button>
</div>
<div style="font-size:12.5px;color:var(--muted);text-align:center">
<span id="login-toggle-text">No account yet?</span>
<a href="#" id="login-toggle" style="color:var(--accent);font-weight:600;text-decoration:none">Create one</a>
</div>
</div>
</div>
<!-- Edit-profile modal (display name, bio, avatar, handles) -->
<div class="c-modal-back" id="socials-modal-back" role="dialog" aria-modal="true" aria-labelledby="socials-modal-title">
<div class="c-modal" id="profile-edit-modal">
<h2 id="socials-modal-title">Edit your profile</h2>
<p style="margin:0;color:var(--muted);font-size:13.5px" id="socials-sub">Set how you appear to other builders. A Twitter/X handle is required to post and chat.</p>
<div class="field">
<label>Avatar</label>
<div id="avatar-grid" class="avatar-grid" role="radiogroup" aria-label="Choose an avatar"></div>
</div>
<div class="field">
<label for="profile-displayname">Display name</label>
<input type="text" id="profile-displayname" maxlength="80" placeholder="Your name in the community" autocomplete="off" />
</div>
<div class="field">
<label for="profile-about">About <span style="color:var(--muted)">(optional)</span></label>
<textarea id="profile-about" rows="3" maxlength="1000" placeholder="A short bio — keep it friendly."></textarea>
</div>
<div class="field">
<label for="socials-twitter">Twitter / X handle <span style="color:#c0392b">*</span></label>
<div class="handle-input"><span class="handle-at">@</span><input type="text" id="socials-twitter" maxlength="40" placeholder="yourhandle" autocomplete="off" /></div>
</div>
<div class="field">
<label for="socials-github">GitHub username <span style="color:var(--muted)">(optional)</span></label>
<div class="handle-input"><span class="handle-at">@</span><input type="text" id="socials-github" maxlength="40" placeholder="yourhandle" autocomplete="off" /></div>
</div>
<div style="font-size:11.5px;color:var(--muted)">Names and bios are filtered — no sexual, nude, or abusive content.</div>
<div class="modal-error" id="socials-error" hidden></div>
<div class="modal-ok" id="socials-ok" hidden></div>
<div class="modal-actions">
<button class="btn" id="socials-cancel">Later</button>
<button class="btn primary" id="socials-save">Save</button>
</div>
</div>
</div>
<!-- Human verification modal (anti-AI questionnaire for new members) -->
<div class="c-modal-back" id="verify-modal-back" role="dialog" aria-modal="true" aria-labelledby="verify-modal-title">
<div class="c-modal">
<h2 id="verify-modal-title">Quick human check</h2>
<p style="margin:0;color:var(--muted);font-size:13.5px">
New members answer a few quick questions before joining the chat. This keeps the
tinyverse community human. Take your time — there's no trick.
</p>
<div id="verify-questions" style="display:flex;flex-direction:column;gap:12px;margin-top:4px"></div>
<div class="verify-timing-note" id="verify-timing-note" hidden>Answer the questions, then wait a second for the human-check timer to unlock submit.</div>
<!-- honeypot: hidden from humans, irresistible to naive bots. Do not remove. -->
<div aria-hidden="true" style="position:absolute;left:-9999px;top:-9999px;height:0;width:0;overflow:hidden">
<label for="verify-mid">Middle initial</label>
<input type="text" id="verify-mid" name="middle_initial" tabindex="-1" autocomplete="off" />
</div>
<div class="modal-error" id="verify-error" hidden></div>
<div class="modal-ok" id="verify-ok" hidden></div>
<div class="modal-actions">
<button class="btn" id="verify-refresh" title="Get new questions">New questions</button>
<button class="btn primary" id="verify-submit">Submit & join</button>
</div>
</div>
</div>
<script>
(function () {
'use strict';
// ---- auth: reuse the same token sources the app uses ----
// 1) wallet session token in localStorage, 2) Netlify Identity nf_jwt cookie.
const TW_WALLET_SESSION_KEY = 'tinyworld:auth:wallet-session.v1';
function walletSessionToken() {
try { return localStorage.getItem(TW_WALLET_SESSION_KEY) || ''; } catch (_) { return ''; }
}
function identityCookieToken() {
try { const m = document.cookie.match(/(?:^|; )nf_jwt=([^;]*)/); return m ? decodeURIComponent(m[1]) : ''; } catch (_) { return ''; }
}
async function accessToken() {
const Auth = window.TinyWorldAuth;
if (Auth && typeof Auth.getUser === 'function') {
try {
const user = await Auth.getUser();
if (user) {
if (typeof user.jwt === 'function') { try { return await user.jwt(); } catch (_) {} }
if (user.token && user.token.access_token) return user.token.access_token;
}
} catch (_) {}
}
return walletSessionToken() || identityCookieToken() || '';
}
function setWalletSessionToken(t) { try { localStorage.setItem(TW_WALLET_SESSION_KEY, t || ''); } catch (_) {} }
function clearWalletSessionToken() { try { localStorage.removeItem(TW_WALLET_SESSION_KEY); } catch (_) {} }
// ---- login (email via Netlify Identity, or Phantom wallet) ----
// Reuses the same vendored auth bridge + /api/wallet flow as the builder, so
// people can sign in here without bouncing to /tiny-world-builder.
let loginMode = 'login'; // 'login' | 'signup'
async function emailLogin(email, password) {
const Auth = window.TinyWorldAuth;
if (!Auth || typeof Auth.login !== 'function') throw new Error('Email sign-in is unavailable right now.');
await Auth.login(email, password, true);
}
async function emailSignup(email, password, name) {
const Auth = window.TinyWorldAuth;
if (!Auth || typeof Auth.signup !== 'function') throw new Error('Sign-up is unavailable right now.');
await Auth.signup(email, password, name ? { full_name: name, name } : undefined);
// Try an immediate login so new accounts enter the community without a
// separate verification step when Identity autoconfirm is enabled.
try { await Auth.login(email, password, true); } catch (_) {}
}
function phantomProvider() {
const p = window.phantom && window.phantom.solana ? window.phantom.solana : window.solana;
return p && p.isPhantom ? p : null;
}
function bytesToBase64(bytes) {
let bin = ''; Array.from(bytes || []).forEach(b => { bin += String.fromCharCode(Number(b) & 0xff); });
return btoa(bin);
}
async function walletApi(body) {
const r = await fetch('/api/wallet', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin', body: JSON.stringify(body || {}) });
const text = await r.text();
let data = null; try { data = text ? JSON.parse(text) : null; } catch (_) { data = { error: text || ('HTTP ' + r.status) }; }
if (!r.ok) { const e = new Error((data && data.error) || ('HTTP ' + r.status)); e.status = r.status; throw e; }
return data;
}
async function walletLogin() {
const provider = phantomProvider();
if (!provider) throw new Error('Phantom wallet was not found. Install Phantom, then try again.');
if (typeof provider.signMessage !== 'function') throw new Error('This Phantom provider cannot sign messages.');
const connected = await provider.connect();
const publicKey = connected && connected.publicKey ? connected.publicKey.toString() : (provider.publicKey && provider.publicKey.toString());
if (!publicKey) throw new Error('Wallet did not return a public key.');
const challenge = await walletApi({ action: 'loginChallenge', publicKey });
const signed = await provider.signMessage(new TextEncoder().encode(challenge.message), 'utf8');
const signature = bytesToBase64(signed.signature || signed);
const result = await walletApi({ action: 'login', publicKey, message: challenge.message, challengeToken: challenge.challengeToken, signature });
if (!result || !result.sessionToken) throw new Error('Wallet login did not return a session.');
setWalletSessionToken(result.sessionToken);
}
async function api(path, method, body) {
const token = await accessToken();
const opts = { method: method || 'GET', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin' };
if (token) opts.headers.Authorization = 'Bearer ' + token;
if (body) opts.body = JSON.stringify(body);
const r = await fetch(path, opts);
const text = await r.text();
let data = null;
try { data = text ? JSON.parse(text) : null; } catch (_) { data = { error: text || ('HTTP ' + r.status) }; }
if (!r.ok) { const out = data || {}; out.status = r.status; out.error = out.error || ('HTTP ' + r.status); throw out; }
return data || {};
}
// ---- helpers ----
function esc(s) { return String(s == null ? '' : s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); }
function initials(name) { return String(name || '?').trim().split(/\s+/).map(w => w[0]).join('').slice(0, 2).toUpperCase() || '?'; }
function fmtTime(iso) {
if (!iso) return '';
const d = new Date(iso); if (isNaN(d)) return '';
const now = new Date();
const sameDay = d.toDateString() === now.toDateString();
const t = d.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' });
return sameDay ? t : (d.toLocaleDateString([], { month: 'short', day: 'numeric' }) + ' ' + t);
}
function avatarHTML(member, cls) {
const c = cls ? (' ' + cls) : '';
if (member && member.image) return '<img class="avatar' + c + '" src="' + esc(member.image) + '" alt="" loading="lazy" onerror="this.replaceWith(Object.assign(document.createElement(\'span\'),{className:this.className,textContent:\'' + esc(initials(member.displayName || member.username)) + '\'}))" />';
return '<span class="avatar' + c + '">' + esc(initials(member ? (member.displayName || member.username) : '?')) + '</span>';
}
// ---- state ----
const VERIFY_MIN_ELAPSED_MS = 2500;
let verifyCountdownTimer = null;
const state = {
me: null, admin: false, verified: false,
caps: {}, roleOptions: [],
rooms: [], members: [], dms: [], blocks: [],
sel: null, // { type: 'room'|'dm', id } — id is roomId or other-profile-id
messages: [], pollTimer: null, lastFocus: null,
verify: null, // { token, questions:[{id,prompt}], shownAt }
};
const byId = id => document.getElementById(id);
// ---- rendering: rooms + dms ----
function renderRooms() {
const el = byId('rooms-body');
const joined = state.rooms;
let html = '<div class="c-list-section">Rooms</div><ul class="c-list">';
if (!joined.length) html += '<li style="padding:8px 10px;color:var(--muted);font-size:13px">No rooms yet.</li>';
for (const r of joined) {
const active = state.sel && state.sel.type === 'room' && state.sel.id === r.id ? ' active' : '';
const lock = r.isPrivate ? '<svg class="lock" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>' : '<span class="hash">#</span>';
html += '<li><button class="room-row' + active + '" data-room="' + r.id + '">' + lock + '<span class="name">' + esc(r.name) + '</span></button></li>';
}
html += '</ul>';
html += '<div class="c-list-section">Direct messages</div><ul class="c-list">';
if (!state.dms.length) html += '<li style="padding:8px 10px;color:var(--muted);font-size:13px">No conversations yet. Open a member to start one.</li>';
for (const d of state.dms) {
if (!d.other || !d.other.id) continue;
const active = state.sel && state.sel.type === 'dm' && state.sel.id === d.other.id ? ' active' : '';
html += '<li><button class="dm-row' + active + '" data-dm="' + d.other.id + '">' +
'<span class="avatar-wrap">' + avatarHTML(d.other, 'sm') + '<span class="presence-dot ' + (d.other.online ? 'online' : '') + '" style="width:8px;height:8px"></span></span>' +
'<span class="name">' + esc(d.other.displayName || d.other.username) + '</span></button></li>';
}
html += '</ul>';
el.innerHTML = html;
el.querySelectorAll('[data-room]').forEach(b => b.addEventListener('click', () => selectRoom(Number(b.dataset.room))));
el.querySelectorAll('[data-dm]').forEach(b => b.addEventListener('click', () => selectDm(Number(b.dataset.dm))));
}
function renderMembers() {
const el = byId('members-body');
const onlineMembers = state.members.filter(m => m && m.online);
byId('member-count').textContent = onlineMembers.length ? String(onlineMembers.length) : '';
if (!onlineMembers.length) { el.innerHTML = '<div style="padding:12px;color:var(--muted);font-size:13px">No members online.</div>'; return; }
el.innerHTML = '<ul class="c-list">' + onlineMembers.map(m =>
'<li><button class="member-row" data-member="' + m.id + '">' +
'<span class="avatar-wrap">' + avatarHTML(m) + '<span class="presence-dot ' + (m.online ? 'online' : '') + '"></span></span>' +
'<span class="mname"><b>' + esc(m.displayName || m.username) + '</b><small>' + (m.online ? 'Online' : 'Offline') + '</small></span>' +
'</button></li>').join('') + '</ul>';
el.querySelectorAll('[data-member]').forEach(b => b.addEventListener('click', () => openProfile(Number(b.dataset.member))));
}
function currentRoom() { return state.sel && state.sel.type === 'room' ? state.rooms.find(r => r.id === state.sel.id) : null; }
// Live CCTV feeds for the active room's linked world. Mounts a single lazy
// iframe into the right rail; only reveals it after the embedded CCTV wall
// renders so the builder boot/loading chrome never flashes in the panel.
let cctvSlug = undefined;
let cctvFrame = null;
window.addEventListener('message', ev => {
const msg = ev.data || {};
if (!cctvFrame || ev.source !== cctvFrame.contentWindow || msg.type !== 'tinyworld:cctv-ready') return;
cctvFrame.classList.add('is-ready');
const loading = byId('cctv-loading');
if (loading) loading.remove();
});
function renderCctv() {
const body = byId('cctv-body'); if (!body) return;
const label = byId('cctv-world-label');
const r = currentRoom();
const slug = (r && r.worldSlug) ? r.worldSlug : null;
if (slug === cctvSlug) return;
cctvSlug = slug;
if (!slug) {
cctvFrame = null;
body.innerHTML = '<div class="cctv-empty">No world linked to this channel.</div>';
if (label) label.textContent = '';
return;
}
if (label) label.textContent = slug;
const ifr = document.createElement('iframe');
ifr.src = 'tiny-world-builder.html?world=' + encodeURIComponent(slug) + '&view=cctv';
ifr.loading = 'lazy';
ifr.title = 'Live feeds — ' + slug;
ifr.allow = 'autoplay';
body.innerHTML = '<div class="cctv-loading" id="cctv-loading" role="status" aria-live="polite"><div>Connecting live feeds…</div><div class="skeleton-line" style="width:70%"></div><div class="skeleton-line" style="width:54%"></div></div>';
cctvFrame = ifr;
body.appendChild(ifr);
}
function memberById(id) { return state.members.find(m => m.id === id) || null; }
function hasCap(name) { return !!(state.admin || (state.caps && state.caps[name])); }
function canModerateCurrentConversation() {
if (!state.sel) return false;
if (state.sel.type === 'dm') return hasCap('canModerate');
const r = currentRoom();
return !!(hasCap('canModerate') || (r && (r.role === 'owner' || r.role === 'mod')));
}
function renderChatHead() {
const head = byId('chat-head');
if (!state.sel) { head.innerHTML = '<div class="title"><strong>Select a channel</strong><span>Pick a room or a direct message to start chatting.</span></div>'; return; }
if (state.sel.type === 'room') {
const r = currentRoom(); if (!r) return;
const isOwnerMod = r.role === 'owner' || r.role === 'mod';
let actions = '';
if (isOwnerMod || state.admin) actions += '<button class="icon-btn" id="room-invite-btn" title="Create invite" aria-label="Invite"><svg viewBox="0 0 24 24"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M19 8v6"/><path d="M22 11h-6"/></svg></button>';
if (r.role === 'owner' || hasCap('canModerate')) actions += '<button class="icon-btn" id="room-linkworld-btn" title="Link world (live feeds)" aria-label="Link world"><svg viewBox="0 0 24 24"><path d="M15 10l4.55-2.28A1 1 0 0 1 21 8.62v6.76a1 1 0 0 1-1.45.9L15 14"/><rect x="3" y="6" width="12" height="12" rx="2"/></svg></button>';
if (r.role && r.role !== 'owner') actions += '<button class="icon-btn" id="room-leave-btn" title="Leave room" aria-label="Leave"><svg viewBox="0 0 24 24"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><path d="M16 17l5-5-5-5"/><path d="M21 12H9"/></svg></button>';
else if (!r.role) actions += '<button class="btn sm primary" id="room-join-btn">Join</button>';
if (r.role === 'owner' || hasCap('canModerate')) actions += '<button class="icon-btn danger-icon" id="room-delete-btn" title="Delete channel" aria-label="Delete channel"><svg viewBox="0 0 24 24"><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><path d="M10 11v6"/><path d="M14 11v6"/></svg></button>';
head.innerHTML = '<div class="title"><strong>' + (r.isPrivate ? '' : '# ') + esc(r.name) + (r.role ? ' <span class="pill role">' + esc(r.role) + '</span>' : '') + '</strong><span>' + esc(r.topic || 'No topic set') + '</span></div><div class="head-actions">' + actions + '</div>';
const ib = byId('room-invite-btn'); if (ib) ib.addEventListener('click', () => openInvite(r));
const wb = byId('room-linkworld-btn'); if (wb) wb.addEventListener('click', () => openLinkWorld(r));
const lb = byId('room-leave-btn'); if (lb) lb.addEventListener('click', () => leaveRoom(r.id));
const jb = byId('room-join-btn'); if (jb) jb.addEventListener('click', () => joinRoom(r.id));
const db = byId('room-delete-btn'); if (db) db.addEventListener('click', () => deleteRoom(r));
} else {
const m = memberById(state.sel.id) || (state.dms.find(d => d.other && d.other.id === state.sel.id) || {}).other;
const name = m ? (m.displayName || m.username) : 'Direct message';
head.innerHTML = '<span class="avatar-wrap">' + avatarHTML(m || {}, 'sm') + '</span><div class="title"><strong>' + esc(name) + '</strong><span>Direct message</span></div><div class="head-actions"><button class="icon-btn" id="dm-profile-btn" title="View profile" aria-label="Profile"><svg viewBox="0 0 24 24"><circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/></svg></button></div>';
const pb = byId('dm-profile-btn'); if (pb && m) pb.addEventListener('click', () => openProfile(m.id));
}
}
function renderMessages() {
const el = byId('chat-scroll');
if (!state.sel) { el.innerHTML = '<div class="chat-empty">No channel selected yet.</div>'; return; }
if (!state.messages.length) { el.innerHTML = '<div class="chat-empty">No messages yet. Be the first to say hello.</div>'; return; }
const nearBottom = el.scrollHeight - el.scrollTop - el.clientHeight < 80;
const canMod = canModerateCurrentConversation();
el.innerHTML = state.messages.map(m => {
const hiddenClass = m.hidden ? ' hidden-message' : '';
const hiddenBadge = m.hidden ? '<span class="msg-hidden-badge">Hidden</span>' : '';
const actions = canMod
? '<span class="msg-mod-actions">' +
(m.hidden
? '<button type="button" class="msg-mod-btn" data-msg-unhide="' + m.id + '">Restore</button>'
: '<button type="button" class="msg-mod-btn" data-msg-hide="' + m.id + '">Hide</button>') +
'<button type="button" class="msg-mod-btn danger" data-msg-delete="' + m.id + '">Delete</button>' +
'</span>'
: '';
return '<div class="msg' + hiddenClass + '" data-message-id="' + m.id + '">' + avatarHTML(m.author) +
'<div class="body"><div class="by"><strong>' + esc(m.author.displayName || m.author.username) + '</strong><time>' + esc(fmtTime(m.createdAt)) + '</time>' + hiddenBadge + actions + '</div>' +
'<div class="text">' + esc(m.body) + '</div></div></div>';
}).join('');
el.querySelectorAll('[data-msg-hide]').forEach(b => b.addEventListener('click', () => moderateMessage(Number(b.dataset.msgHide), 'hideMessage')));
el.querySelectorAll('[data-msg-unhide]').forEach(b => b.addEventListener('click', () => moderateMessage(Number(b.dataset.msgUnhide), 'unhideMessage')));
el.querySelectorAll('[data-msg-delete]').forEach(b => b.addEventListener('click', () => moderateMessage(Number(b.dataset.msgDelete), 'deleteMessage')));
if (nearBottom) el.scrollTop = el.scrollHeight;
}
function canParticipate() { return !!(state.admin || state.verified); }
function showComposer(show) {
// Unverified members can read but not write — steer them to the questionnaire.
if (show && !canParticipate()) {
byId('composer').hidden = true;
composerError('Complete the quick human check to post here.');
return;
}
composerError('');
byId('composer').hidden = !show;
byId('send-btn').disabled = !show || !byId('composer-input').value.trim();
}
function composerError(msg) {
const n = byId('composer-note');
if (!msg) { n.hidden = true; n.textContent = ''; return; }
n.hidden = false; n.textContent = msg;
}
// ---- selection + polling ----
function stopPolling() { if (state.pollTimer) { clearInterval(state.pollTimer); state.pollTimer = null; } }
function startPolling() {
stopPolling();