-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathold.html
More file actions
3475 lines (3064 loc) · 197 KB
/
old.html
File metadata and controls
3475 lines (3064 loc) · 197 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" data-mode="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>Gemna Chat</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/lucide@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="icon" href="/favicon.ico" sizes="any">
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="gemna logo" href="/favicon.png">
<style>
/* --- Base & Default Theme --- */
:root {
--bg-color: #ffffff; --text-color: #1f2937; --header-bg: #f9fafb; --header-text: #1f2937;
--user-bubble-bg: #3b82f6; --user-bubble-text: #ffffff; --ai-bubble-bg: #e5e7eb; --ai-bubble-text: #1f2937;
--input-bg: #f3f4f6; --input-text: #1f2937; --border-color: #e5e7eb; --button-bg: #3b82f6; --button-text: #ffffff;
--icon-color: #6b7280; --font-family: 'Inter', sans-serif; --sidebar-bg: #f9fafb; --sidebar-border: #e5e7eb;
--hover-bg: rgba(0, 0, 0, 0.05);
--active-char-bg: rgba(0, 0, 0, 0.07);
--code-bg: #f3f4f6;
--system-bubble-bg: #a1a1aa; --system-bubble-text: #ffffff;
--scrollbar-thumb-color: #d1d5db;
}
html[data-mode="dark"] {
--bg-color: #111827; --text-color: #e5e7eb; --header-bg: #1f2937; --header-text: #e5e7eb;
--user-bubble-bg: #3b82f6; --ai-bubble-bg: #374151; --ai-bubble-text: #e5e7eb;
--input-bg: #1f2937; --input-text: #e5e7eb; --border-color: #374151; --icon-color: #9ca3af;
--sidebar-bg: #1f2937; --sidebar-border: #374151; --hover-bg: rgba(255, 255, 255, 0.05);
--active-char-bg: rgba(255, 255, 255, 0.1);
--code-bg: #1f2937;
--system-bubble-bg: #52525b; --system-bubble-text: #e5e7eb;
--scrollbar-thumb-color: #4b5563;
}
body { font-family: var(--font-family); background-color: var(--bg-color); color: var(--text-color); transition: background-color 0.3s, color 0.3s; }
.bg-theme { background-color: var(--bg-color); }
.text-theme { color: var(--text-color); }
.bg-header { background-color: var(--header-bg); }
.text-header { color: var(--header-text); }
.border-theme { border-color: var(--border-color); }
.user-bubble { background: var(--user-bubble-bg); color: var(--user-bubble-text); }
.ai-bubble { background: var(--ai-bubble-bg); color: var(--ai-bubble-text); }
.system-bubble { background-color: var(--system-bubble-bg); color: var(--system-bubble-text); }
.bg-input { background-color: var(--input-bg); }
.text-input { color: var(--input-text); }
.bg-button { background-color: var(--button-bg); }
.text-button { color: var(--text-button); }
.icon-theme { color: var(--icon-color); }
.bg-sidebar { background-color: var(--sidebar-bg); }
.border-sidebar { border-color: var(--sidebar-border); }
.hover-theme:hover { background-color: var(--hover-bg); }
.character-item.active { background-color: var(--active-char-bg); }
/* --- Theme-Specific Styling --- */
.theme-icon { display: none; }
body[data-theme="theme-imessage"] .icon-imessage,
body[data-theme="theme-whatsapp"] .icon-whatsapp,
body[data-theme="theme-messenger"] .icon-messenger,
body[data-theme="theme-instagram"] .icon-instagram,
body[data-theme="theme-twitter"] .icon-twitter { display: inline-flex; }
#message-input-wrapper { border-radius: 9999px; }
/* iMessage */
body[data-theme="theme-imessage"] { --user-bubble-bg: #007aff; --ai-bubble-bg: #e5e5ea; --ai-bubble-text: #000; --button-bg: #007aff; --input-bg: #ffffff; --border-color: #dcdcdc; --sidebar-bg: #f2f2f7;}
html[data-mode="dark"] body[data-theme="theme-imessage"] { --bg-color: #000000; --header-bg: #1c1c1e; --user-bubble-bg: #0b84ff; --ai-bubble-bg: #2c2c2e; --ai-bubble-text: #ffffff; --input-bg: #2c2c2e; --border-color: #2c2c2e; --sidebar-bg: #1c1c1e;}
body[data-theme="theme-imessage"] #message-input-wrapper { border-radius: 0.75rem; }
/* WhatsApp */
body[data-theme="theme-whatsapp"] {
--font-family: 'Roboto', sans-serif; --bg-color: #E5DDD5; --header-bg: #075E54; --header-text: #fff; --icon-color: #fff;
--user-bubble-bg: #DCF8C6; --user-bubble-text: #000; --ai-bubble-bg: #fff; --ai-bubble-text: #000;
--button-bg: #128C7E; --sidebar-bg: #fff; --input-bg: #fff;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400" viewBox="0 0 800 800"><g fill="%23a2a5a5" fill-opacity="0.08"><path d="M400 0L0 400h400zM800 400L400 800V400z"/></g></svg>');
}
html[data-mode="light"] body[data-theme="theme-whatsapp"] #sidebar .icon-theme { color: #54656f; }
html[data-mode="dark"] body[data-theme="theme-whatsapp"] {
--bg-color: #0b141a; --header-bg: #202c33; --header-text: #e7e9ea; --icon-color: #e7e9ea; /* <--- CHANGE THIS VALUE */
--user-bubble-bg: #005c4b; --user-bubble-text: #fff; --ai-bubble-bg: #202c33; --ai-bubble-text: #e7e9ea;
--button-bg: #00a884; --sidebar-bg: #111b21; --input-bg: #202c33;
background-image: none;
}
/* Messenger */
body[data-theme="theme-messenger"] { --user-bubble-bg: linear-gradient(to top right, #00c6ff, #0072ff); --ai-bubble-bg: #e4e6eb; --ai-bubble-text: #050505; --button-bg: #0084ff; --icon-color: #ffffff; --sidebar-bg: #fff; --input-bg: #f0f2f5;}
html[data-mode="dark"] body[data-theme="theme-messenger"] { --bg-color: #18191a; --header-bg: #242526; --user-bubble-bg: linear-gradient(to top right, #00c6ff, #0072ff); --ai-bubble-bg: #3a3b3c; --ai-bubble-text: #e4e6eb; --sidebar-bg: #242526; --input-bg: #3a3b3c; --border-color: #3a3b3c;}
/* Instagram */
body[data-theme="theme-instagram"] { --user-bubble-bg: #efefef; --user-bubble-text: #000; --ai-bubble-bg: linear-gradient(to right, #833ab4, #fd1d1d, #fcb045); --ai-bubble-text: #fff; --sidebar-bg: #fff; --input-bg: #fff; --border-color: #dbdbdb;}
html[data-mode="dark"] body[data-theme="theme-instagram"] { --bg-color: #000; --header-bg: #000; --user-bubble-bg: #262626; --user-bubble-text: #fff; --sidebar-bg: #000; --input-bg: #262626; --border-color: #363636;}
body[data-theme="theme-instagram"] #send-button { background: none!important; color: #0095f6!important; }
html[data-mode="dark"] body[data-theme="theme-instagram"] #send-button { color: #0095f6!important; }
/* Twitter / X */
body[data-theme="theme-twitter"] { --bg-color: #fff; --text-color: #0f1419; --header-bg: #fff; --user-bubble-bg: #1d9bf0; --ai-bubble-bg: #f7f9f9; --ai-bubble-text: #0f1419; --sidebar-bg: #fff; --input-bg: #eff3f4; --border-color: #eff3f4;}
html[data-mode="dark"] body[data-theme="theme-twitter"] { --bg-color: #000; --text-color: #e7e9ea; --header-bg: #000; --border-color: #2f3336; --input-bg: #202327; --user-bubble-bg: #1d9bf0; --ai-bubble-bg: #202327; --ai-bubble-text: #e7e9ea; --sidebar-bg: #000;}
/* --- Layout & Responsiveness --- */
#chat-container { position: relative; }
#chat-footer { position: sticky; bottom: 0; }
#character-modal { max-height: 90vh; }
@media (max-width: 767px) {
#chat-container {
display: flex;
flex-direction: column;
height: 100vh; /* Fallback for older browsers */
height: 100svh; /* Use small viewport height for mobile */
}
#message-area { flex: 1; min-height: 0; }
#chat-footer { z-index: 10; }
#settings-panel {
max-width: none;
width: 100vw;
}
#character-modal {
top: 0; left: 0;
width: 100vw; height: 100vh; height: 100svh;
max-width: none; max-height: none;
transform: none; border-radius: 0;
}
}
/* Custom scrollbar */
#message-area::-webkit-scrollbar, #settings-panel-content::-webkit-scrollbar, #sidebar-content::-webkit-scrollbar, #character-modal-content::-webkit-scrollbar, #group-participant-list::-webkit-scrollbar, #popdown-details-content::-webkit-scrollbar, .custom-select-options::-webkit-scrollbar { width: 6px; }
#message-area::-webkit-scrollbar-track, #settings-panel-content::-webkit-scrollbar-track, #sidebar-content::-webkit-scrollbar-track, #character-modal-content::-webkit-scrollbar-track, #group-participant-list::-webkit-scrollbar-track, #popdown-details-content::-webkit-scrollbar-track, .custom-select-options::-webkit-scrollbar-track { background: transparent; }
#message-area::-webkit-scrollbar-thumb, #settings-panel-content::-webkit-scrollbar-thumb, #sidebar-content::-webkit-scrollbar-thumb, #character-modal-content::-webkit-scrollbar-thumb, #group-participant-list::-webkit-scrollbar-thumb, #popdown-details-content::-webkit-scrollbar-thumb, .custom-select-options::-webkit-scrollbar-thumb { background-color: var(--scrollbar-thumb-color); border-radius: 10px; }
/* Markdown Styles */
.message-bubble p { margin-bottom: 0.5rem; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul, .message-bubble ol { margin-left: 1.25rem; margin-top: 0.5rem; margin-bottom: 0.5rem; }
.message-bubble li { margin-bottom: 0.25rem; }
.message-bubble pre { background-color: var(--code-bg); padding: 0.75rem; border-radius: 0.5rem; overflow-x: auto; margin: 0.5rem 0; }
.message-bubble code { font-family: monospace; }
.message-bubble pre code { background: none; padding: 0; }
/* Style for multiple parts in one bubble */
.message-bubble > *:not(:last-child) { margin-bottom: 0.5rem; }
.hide-chat-avatars .user-avatar, .hide-chat-avatars .ai-avatar { display: none; }
.message-timestamp {
font-size: 0.65rem;
color: #9ca3af;
white-space: nowrap;
margin-top: 0.25rem;
}
html[data-mode="dark"] .message-timestamp { color: #6b7280; }
.delete-action-container { display: none; padding: 4px 0; margin-top: 2px; gap: 8px; }
.message-container.selected-for-deletion .delete-action-container { display: flex; }
.message-action-button { color: white; padding: 2px 10px; font-size: 0.75rem; border-radius: 1rem; cursor: pointer; border: none; transition: background-color 0.2s; }
.delete-message-button { background-color: #ef4444; }
.delete-message-button:hover { background-color: #dc2626; }
.copy-message-button { background-color: #3b82f6; }
.copy-message-button:hover { background-color: #2563eb; }
.custom-select-container { position: relative; }
.custom-select-trigger { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 0.5rem; border: 1px solid var(--border-color); border-radius: 0.375rem; background-color: var(--input-bg); color: var(--input-text); cursor: pointer; transition: border-color 0.2s; }
.custom-select-trigger:focus, .custom-select-trigger.open { outline: 2px solid transparent; outline-offset: 2px; border-color: #3b82f6; }
.custom-select-options { position: absolute; top: 100%; left: 0; right: 0; margin-top: 0.25rem; background-color: var(--bg-color); border: 1px solid var(--border-color); border-radius: 0.375rem; box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); z-index: 50; opacity: 0; transform: scale(0.95); transition: opacity 0.1s ease-out, transform 0.1s ease-out; pointer-events: none; }
.custom-select-options.open { opacity: 1; transform: scale(1); pointer-events: auto; }
.custom-select-option { padding: 0.5rem 0.75rem; cursor: pointer; }
.custom-select-option:hover { background-color: var(--hover-bg); }
.custom-select-option.selected { background-color: var(--active-char-bg); font-weight: 500; }
@keyframes typing-bubble { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.0); } }
.typing-dot { animation: typing-bubble 1.4s infinite ease-in-out both; }
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
#typing-indicator-container {
position: absolute;
bottom: 5rem;
left: 1rem;
z-index: 5;
transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
}
#typing-indicator-container.hidden {
opacity: 0;
transform: translateY(10px);
pointer-events: none;
}
@media (min-width: 768px) {
#typing-indicator-container {
bottom: 5.5rem;
}
}
#app-container.loaded {
opacity: 1;
}
</style>
</head>
<body class="overflow-hidden" data-theme="theme-imessage">
<div id="loading-overlay" class="fixed inset-0 bg-theme z-[100] flex flex-col items-center justify-center gap-4 transition-opacity duration-500">
<div class="text-2xl font-bold text-theme">Gemna Chat</div>
<div class="w-1/2 max-w-xs bg-gray-200 rounded-full h-1.5 dark:bg-gray-700">
<div id="loading-bar" class="bg-blue-600 h-1.5 rounded-full transition-all duration-300 ease-linear" style="width: 10%"></div>
</div>
</div>
<div id="app-container" class="flex h-screen w-screen bg-theme opacity-0 transition-opacity duration-500">
<!-- Sidebar -->
<div id="sidebar" class="absolute md:relative z-30 h-full w-full md:w-1/3 lg:w-1/4 bg-sidebar border-r border-sidebar md:flex md:flex-col grid grid-rows-[auto_1fr] -translate-x-full md:translate-x-0 transition-transform duration-300 ease-in-out">
<header class="p-4 border-b border-sidebar flex justify-between items-center flex-shrink-0">
<h1 class="text-lg font-bold text-theme">Chats</h1>
<div class="flex items-center gap-2">
<button id="add-character-button" title="Add New Character" class="p-2 rounded-full hover-theme">
<svg data-lucide="user-plus" class="icon-theme h-5 w-5"></svg>
</button>
<button id="add-group-button" title="Add New Group" class="p-2 rounded-full hover-theme">
<svg data-lucide="users" class="icon-theme h-5 w-5"></svg>
</button>
<button id="close-sidebar-button" class="p-2 rounded-full hover-theme md:hidden">
<svg data-lucide="x" class="icon-theme h-5 w-5"></svg>
</button>
</div>
</header>
<div id="sidebar-content" class="overflow-y-auto p-2">
<div id="character-list" class="space-y-1"></div>
</div>
</div>
<div id="sidebar-overlay" class="fixed inset-0 bg-black bg-opacity-20 z-20 hidden"></div>
<!-- Main Chat Area -->
<div id="chat-container" class="flex flex-col h-full flex-1">
<header id="chat-header" class="flex items-center justify-between p-2 md:p-3 border-b border-theme bg-header shadow-sm flex-shrink-0 h-16">
<div class="flex items-center gap-3 min-w-0">
<button id="show-sidebar-button" class="p-2 rounded-full hover-theme md:hidden">
<svg data-lucide="menu" class="icon-theme h-5 w-5"></svg>
</button>
<div id="header-avatar-stack" class="flex items-center -space-x-4 cursor-pointer">
<img id="header-avatar" src="" class="w-8 h-8 md:w-10 md:h-10 rounded-full object-cover border-2 border-white dark:border-gray-800">
</div>
<div class="min-w-0">
<h1 id="header-name" class="font-bold text-md text-header truncate"></h1>
<p id="header-status" class="text-xs opacity-80 text-header">Online</p>
</div>
</div>
<div class="flex items-center gap-2 relative">
<button id="clear-local-chats-header-button" title="Clear Local Chat" class="p-2 rounded-full hover-theme">
<svg data-lucide="brush-cleaning" class="icon-theme h-5 w-5"></svg>
</button>
<button id="clear-chat-button" title="Clear All Chat History" class="p-2 rounded-full hover-theme">
<svg data-lucide="trash-2" class="icon-theme h-5 w-5"></svg>
</button>
<button id="download-chat-button" title="Download This Character & Chat" class="p-2 rounded-full hover-theme">
<svg data-lucide="download" class="icon-theme h-5 w-5"></svg>
</button>
<button id="settings-button-main" title="Settings" class="p-2 rounded-full hover-theme">
<svg data-lucide="settings" class="icon-theme h-5 w-5"></svg>
</button>
</div>
</header>
<!-- AFTER GAP CHANGE-->
<main id="message-area" class="flex flex-col flex-1 px-4 pt-4 pb-16 overflow-y-auto"></main>
<div id="typing-indicator-container" class="hidden">
<div class="flex items-center gap-2">
<div id="typing-avatar-container" class="flex-shrink-0"></div>
<div class="ai-bubble flex items-center justify-center gap-1.5 p-3 rounded-2xl rounded-bl-lg">
<span class="typing-dot w-2 h-2 bg-gray-500 dark:bg-gray-400 rounded-full"></span>
<span class="typing-dot w-2 h-2 bg-gray-500 dark:bg-gray-400 rounded-full"></span>
<span class="typing-dot w-2 h-2 bg-gray-500 dark:bg-gray-400 rounded-full"></span>
</div>
</div>
</div>
<footer id="chat-footer" class="p-2 md:p-3 border-t border-theme bg-header flex-shrink-0">
<div id="image-preview-wrapper" class="hidden mb-2 relative w-24 h-24">
<img id="image-preview" class="w-full h-full object-cover rounded-md">
<button id="remove-image-button" type="button" class="absolute -top-2 -right-2 bg-gray-700 text-white rounded-full p-1">
<svg data-lucide="x" class="h-3 w-3"></svg>
</button>
</div>
<div id="guidance-wrapper" class="hidden mb-2">
<div class="flex items-center gap-2 text-sm text-theme opacity-80 mb-1">
<svg data-lucide="sparkles" class="h-4 w-4"></svg>
<span>Guide the next AI response...</span>
</div>
<input id="guidance-input" type="text" placeholder="e.g., Explain it like I'm five years old." class="w-full p-2 border border-theme rounded-md bg-input text-input">
</div>
<form id="message-form" class="flex items-center gap-2 md:gap-3">
<button type="button" id="guidance-button" title="Guide AI Response" class="p-2 rounded-full hover-theme">
<svg data-lucide="sparkles" class="icon-theme h-5 w-5"></svg>
</button>
<button type="button" id="image-upload-button" class="p-2 rounded-full hover-theme">
<span class="theme-icon icon-imessage"><svg data-lucide="camera" class="icon-theme h-5 w-5"></svg></span>
<span class="theme-icon icon-instagram"><svg data-lucide="camera" class="icon-theme h-5 w-5"></svg></span>
<span class="theme-icon icon-messenger"><svg data-lucide="image" class="icon-theme h-5 w-5"></svg></span>
<span class="theme-icon icon-twitter"><svg data-lucide="image" class="icon-theme h-5 w-5"></svg></span>
<span class="theme-icon icon-whatsapp"><svg data-lucide="paperclip" class="icon-theme h-5 w-5"></svg></span>
</button>
<div id="message-input-wrapper" class="flex-1 flex items-center px-4 py-1.5 border border-theme rounded-full bg-input">
<input id="message-input" type="text" placeholder="Type a message..." class="w-full bg-transparent focus:outline-none text-input" autocomplete="off">
<button type="button" id="whatsapp-camera-button" class="theme-icon icon-whatsapp p-2 -mr-2"><svg data-lucide="camera" class="icon-theme h-5 w-5"></svg></button>
</div>
<button id="send-button" type="submit" class="p-2 md:p-3 rounded-full flex items-center justify-center bg-button text-button">
<div id="theme-icons-container">
<span class="theme-icon icon-imessage"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2L2 12h5v8h10v-8h5L12 2z"/></svg></span>
<span class="theme-icon icon-whatsapp"><svg data-lucide="mic" class="icon-theme h-5 w-5"></svg></span>
<span class="theme-icon icon-messenger"><svg data-lucide="thumbs-up" class="icon-theme h-5 w-5"></svg></span>
<span class="theme-icon icon-instagram font-semibold text-sm" style="color: #0095f6;">Send</span>
<span class="theme-icon icon-twitter"><svg data-lucide="send" class="icon-theme h-5 w-5"></svg></span>
</div>
<svg data-lucide="send" id="send-icon-generic" class="h-5 w-5 hidden"></svg>
</button>
</form>
</footer>
</div>
<!-- Settings Panel -->
<div id="settings-panel-overlay" class="fixed inset-0 bg-black bg-opacity-50 z-40 hidden"></div>
<div id="settings-panel" class="fixed top-0 right-0 h-full w-full max-w-sm transform translate-x-full transition-transform duration-300 ease-in-out shadow-lg z-50 flex flex-col bg-theme">
<header class="flex items-center justify-between p-4 border-b border-theme">
<h2 class="text-xl font-bold text-theme">Settings</h2>
<div class="flex items-center gap-1">
<a href="help.html" target="_blank" title="Help" class="p-2 rounded-full hover-theme">
<svg data-lucide="help-circle" class="icon-theme h-5 w-5"></svg>
</a>
<button id="close-settings-button" class="p-2 rounded-full hover-theme">
<svg data-lucide="x" class="icon-theme h-5 w-5"></svg>
</button>
</div>
</header>
<div id="settings-panel-content" class="flex-1 p-4 md:p-6 overflow-y-auto space-y-6">
<div>
<h3 class="font-semibold mb-3 text-theme">Account</h3>
<div id="account-info-signed-out">
<p class="text-sm text-center mb-3">Sign in to sync your chats and settings across devices.</p>
<div class="space-y-3">
<button id="google-signin-button" class="w-full flex items-center justify-center gap-3 bg-blue-600 text-white font-bold py-3 px-4 rounded-lg hover:bg-blue-700 transition-colors">
<svg class="w-5 h-5" viewBox="0 0 48 48"><path fill="#FFC107" d="M43.611 20.083H42V20H24v8h11.303c-1.649 4.657-6.08 8-11.303 8c-6.627 0-12-5.373-12-12s5.373-12 12-12c3.059 0 5.842 1.154 7.961 3.039l5.657-5.657C34.046 6.053 29.268 4 24 4C12.955 4 4 12.955 4 24s8.955 20 20 20s20-8.955 20-20c0-1.341-.138-2.65-.389-3.917z"></path><path fill="#FF3D00" d="M6.306 14.691l6.571 4.819C14.655 15.108 18.961 12 24 12c3.059 0 5.842 1.154 7.961 3.039l5.657-5.657C34.046 6.053 29.268 4 24 4C16.318 4 9.656 8.337 6.306 14.691z"></path><path fill="#4CAF50" d="M24 44c5.166 0 9.86-1.977 13.409-5.192l-6.19-5.238C29.211 35.091 26.715 36 24 36c-5.202 0-9.619-3.317-11.283-7.946l-6.522 5.025C9.505 39.556 16.227 44 24 44z"></path><path fill="#1976D2" d="M43.611 20.083H42V20H24v8h11.303c-.792 2.237-2.231 4.166-4.087 5.571l6.19 5.238C42.021 35.596 44 30.138 44 24c0-1.341-.138-2.65-.389-3.917z"></path></svg>
<span>Sign in with Google</span>
</button>
<div class="relative flex py-2 items-center">
<div class="flex-grow border-t border-theme"></div>
<span class="flex-shrink mx-4 text-xs text-gray-400">OR</span>
<div class="flex-grow border-t border-theme"></div>
</div>
<form id="email-auth-form" class="space-y-3">
<div>
<label for="email-input" class="block text-sm font-medium mb-1 text-theme">Email</label>
<input type="email" id="email-input" required class="w-full p-2 border border-theme rounded-md bg-input text-input" autocomplete="email">
</div>
<div>
<label for="password-input" class="block text-sm font-medium mb-1 text-theme">Password</label>
<input type="password" id="password-input" required class="w-full p-2 border border-theme rounded-md bg-input text-input" autocomplete="current-password">
</div>
<button id="email-auth-button" type="submit" class="w-full bg-gray-500 text-white font-bold py-3 px-4 rounded-lg hover:bg-gray-600 transition-colors">Sign In</button>
</form>
<p class="text-center text-sm text-theme">
<span id="auth-mode-message">Don't have an account?</span>
<button id="auth-mode-toggle" type="button" class="font-semibold text-blue-500 hover:underline">Sign Up</button>
</p>
</div>
</div>
<div id="account-info-signed-in" class="hidden">
<div id="user-info" class="text-center mb-4"></div>
<button id="sign-out-button" class="w-full bg-gray-600 text-white font-bold py-2.5 px-4 rounded-lg hover:bg-gray-700 transition-colors">
Sign Out
</button>
</div>
</div>
<div>
<h3 class="font-semibold mb-3 text-theme">Appearance</h3>
<div class="flex items-center justify-between mb-4">
<label for="theme-switch" class="text-sm font-medium text-theme">Dark Mode</label>
<label class="relative inline-flex items-center cursor-pointer">
<input type="checkbox" id="theme-switch" class="sr-only peer">
<div class="w-11 h-6 bg-gray-200 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-0.5 after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
</label>
</div>
<div class="flex items-center justify-between mb-4">
<label for="show-avatars-switch" class="text-sm font-medium text-theme">Show Avatars in Chat</label>
<label class="relative inline-flex items-center cursor-pointer">
<input type="checkbox" id="show-avatars-switch" class="sr-only peer">
<div class="w-11 h-6 bg-gray-200 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-0.5 after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
</label>
</div>
<div class="flex items-center justify-between mb-4">
<label for="show-timestamps-switch" class="text-sm font-medium text-theme">Show Timestamps</label>
<label class="relative inline-flex items-center cursor-pointer">
<input type="checkbox" id="show-timestamps-switch" class="sr-only peer">
<div class="w-11 h-6 bg-gray-200 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-0.5 after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
</label>
</div>
<label for="theme-select" class="block text-sm font-medium mb-1 text-theme">Interface Style</label>
<select id="theme-select">
<option value="theme-imessage">iMessage</option>
<option value="theme-whatsapp">WhatsApp</option>
<option value="theme-messenger">Messenger</option>
<option value="theme-instagram">Instagram</option>
<option value="theme-twitter">X (Twitter)</option>
</select>
</div>
<div>
<h3 class="font-semibold mb-3 text-theme">Your Character</h3>
<div class="flex items-center gap-4">
<img id="user-avatar-preview" class="w-16 h-16 rounded-full object-cover cursor-pointer bg-gray-200 dark:bg-gray-700">
<div class="flex-1">
<label for="user-name-input" class="block text-sm font-medium mb-1 text-theme">Your Name</label>
<input type="text" id="user-name-input" class="w-full p-2 border border-theme rounded-md bg-input text-input">
</div>
</div>
</div>
<div>
<h3 class="font-semibold mb-3 text-theme">Time Settings</h3>
<label for="time-source-select" class="block text-sm font-medium mb-1 text-theme">Timestamp Source</label>
<select id="time-source-select">
<option value="device">Device Time</option>
<option value="character">Character Time</option>
</select>
</div>
<div>
<h3 class="font-semibold mb-3 text-theme">API & Model</h3>
<div class="mb-4">
<label for="api-provider-select" class="block text-sm font-medium mb-1 text-theme">API Provider</label>
<select id="api-provider-select">
<option value="gemini">Google Gemini</option>
<option value="groq">Groq</option>
<option value="openrouter">OpenRouter</option>
</select>
</div>
<!-- Gemini Settings -->
<div id="gemini-settings-block">
<div class="mb-4">
<label for="model-select" class="block text-sm font-medium mb-1 text-theme">Gemini Model</label>
<select id="model-select">
<option value="gemini-2.5-flash">Gemini 2.5 Flash (Default)</option>
<option value="gemini-2.5-pro">Gemini 2.5 Pro</option>
<option value="gemini-2.5-flash-lite">Gemini 2.5 Flash Lite</option>
<option value="gemini-2.0-flash">Gemini 2.0 Flash</option>
<option value="gemini-2.0-flash-lite">Gemini 2.0 Flash Lite</option>
</select>
</div>
<div class="flex justify-between items-center mb-1">
<label class="block text-sm font-medium text-theme">Gemini API Key</label>
</div>
<div class="space-y-2">
<input type="password" id="gemini-api-key-input" class="w-full p-2 border border-theme rounded-md bg-input text-input" placeholder="Enter your Gemini API Key">
</div>
<p class="text-xs text-gray-500 mt-2">Get your free API key from <a href="https://aistudio.google.com/app/apikey" target="_blank" class="text-blue-500 underline">Google AI Studio</a>.</p>
</div>
<!-- Groq Settings -->
<div id="groq-settings-block" class="hidden">
<div class="mb-4">
<label for="groq-model-select" class="block text-sm font-medium mb-1 text-theme">Groq Model</label>
<select id="groq-model-select">
<option value="llama-3.3-70b-versatile">Llama 3.3 70B</option>
<option value="llama-3.1-8b-instant">Llama 3.1 8B</option>
<option value="gemma2-9b-it">Gemma2 9B</option>
<option value="deepseek-r1-distill-llama-70b">DeepSeek-R1-Distill-Llama-70B</option>
<option value="moonshotai/kimi-k2-instruct">Kimi K2 Instruct</option>
<option value="custom">Custom Model...</option>
</select>
</div>
<div id="groq-custom-model-wrapper" class="hidden mb-4">
<label for="groq-custom-model-input" class="block text-sm font-medium mb-1 text-theme">Custom Groq Model</label>
<input type="text" id="groq-custom-model-input" class="w-full p-2 border border-theme rounded-md bg-input text-input" placeholder="e.g., mixtral-8x7b-32768">
</div>
<label for="groq-api-key-input" class="block text-sm font-medium mb-1 text-theme">Groq API Key</label>
<input type="password" id="groq-api-key-input" class="w-full p-2 border border-theme rounded-md bg-input text-input" placeholder="gsk_...">
<p class="text-xs text-gray-500 mt-2">Get your free API key from <a href="https://console.groq.com/keys" target="_blank" class="text-blue-500 underline">GroqCloud</a>.</p>
</div>
<!-- OpenRouter Settings -->
<div id="openrouter-settings-block" class="hidden">
<div class="mb-4">
<label for="openrouter-model-select" class="block text-sm font-medium mb-1 text-theme">OpenRouter Model</label>
<select id="openrouter-model-select">
<option value="cognitivecomputations/dolphin-mistral-24b-venice-edition:free">Venice Uncensored 24B</option>
<option value="z-ai/glm-4.5-air:free">GLM-4.5 Air</option>
<option value="tencent/hunyuan-a13b-instruct:free">Hunyuan A13B</option>
<option value="sarvamai/sarvam-m:free">Sarvam-M</option>
<option value="qwen/qwen3-235b-a22b:free">Qwen3 235B</option>
<option value="custom">Custom Model...</option>
</select>
</div>
<div id="openrouter-custom-model-wrapper" class="hidden mb-4">
<label for="openrouter-custom-model-input" class="block text-sm font-medium mb-1 text-theme">Custom OpenRouter Model</label>
<input type="text" id="openrouter-custom-model-input" class="w-full p-2 border border-theme rounded-md bg-input text-input" placeholder="e.g., openai/gpt-4o">
</div>
<label for="openrouter-api-key-input" class="block text-sm font-medium mb-1 text-theme">OpenRouter API Key</label>
<input type="password" id="openrouter-api-key-input" class="w-full p-2 border border-theme rounded-md bg-input text-input" placeholder="sk-or-...">
<p class="text-xs text-gray-500 mt-2">Get your free API key from <a href="https://openrouter.ai/keys" target="_blank" class="text-blue-500 underline">OpenRouter</a>.</p>
</div>
</div>
<div>
<h3 class="font-semibold mb-3 text-theme">Data Management</h3>
<div class="space-y-2">
<button id="upload-chat-button" class="w-full flex items-center justify-center gap-2 bg-white dark:bg-gray-700 border border-theme py-2 px-4 rounded-md hover:bg-gray-50 dark:hover:bg-gray-600 transition-opacity text-theme">
<svg data-lucide="upload" class="icon-theme h-4 w-4"></svg>
<span>Import Character Data</span>
</button>
<p class="text-xs text-gray-500 mt-1">Import a character and their chat history from a .json file.</p>
<button id="restore-from-cloud-button" class="w-full flex items-center justify-center gap-2 bg-white dark:bg-gray-700 border border-theme py-2 px-4 rounded-md hover:bg-gray-50 dark:hover:bg-gray-600 transition-opacity text-theme" disabled>
<svg data-lucide="cloud-download" class="icon-theme h-4 w-4"></svg>
<span>Restore from Cloud</span>
</button>
<p class="text-xs text-gray-500 mt-1">Fetch the latest history for the current chat from the cloud. Sign-in required.</p>
</div>
</div>
<div class="border-t border-theme pt-6">
<h3 class="font-semibold mb-3 text-red-500">Danger Zone</h3>
<div class="flex items-center justify-between">
<label for="nsfw-switch" class="text-sm font-medium text-theme">Allow Potentially NSFW Content</label>
<label class="relative inline-flex items-center cursor-pointer">
<input type="checkbox" id="nsfw-switch" class="sr-only peer">
<div class="w-11 h-6 bg-gray-200 rounded-full peer dark:bg-gray-700 peer-checked:bg-red-500 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-0.5 after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600"></div>
</label>
</div>
<p class="text-xs text-gray-500 mt-1 mb-4">By enabling this, you confirm that you are at least 18 years old.</p>
<button id="reset-app-button" class="w-full bg-red-600 text-white font-bold py-2.5 px-4 rounded-lg hover:bg-red-700 transition-colors mt-2">
Reset & Erase All Data
</button>
<p class="text-xs text-gray-500 mt-2">This will permanently delete all your chats, history, and settings from this device and from your cloud account (if signed in). This action cannot be undone.</p>
</div>
<div class="text-center text-xs text-gray-500 pt-4 border-t border-theme">
© Copyright 2025 <a href="https://github.com/exanx/gemna" target="_blank" rel="noopener noreferrer" class="underline hover:text-blue-500">EXANX</a>
</div>
</div>
</div>
<!-- Character & Group Modal -->
<div id="character-modal-overlay" class="fixed inset-0 bg-black bg-opacity-60 z-40 hidden"></div>
<div id="character-modal" class="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md bg-theme rounded-lg shadow-xl z-50 hidden grid grid-rows-[auto_1fr_auto]">
<header id="character-modal-header" class="px-4 md:px-6 py-4 flex-shrink-0">
<h2 id="character-modal-title" class="text-2xl font-bold text-theme">Add New Chat</h2>
</header>
<div id="character-modal-content" class="overflow-y-auto min-h-0 px-4 md:px-6 space-y-4">
<div id="group-name-wrapper" class="hidden">
<label for="group-name-input" class="block text-sm font-medium mb-1 text-theme">Group Name</label>
<input type="text" id="group-name-input" class="w-full p-2 border border-theme rounded-md bg-input text-input">
</div>
<div id="character-details-wrapper" class="flex items-center gap-4">
<img id="char-avatar-preview" class="w-16 h-16 rounded-full object-cover cursor-pointer bg-gray-200 dark:bg-gray-700">
<div class="flex-1">
<label for="char-name-input" class="block text-sm font-medium mb-1 text-theme">AI Name</label>
<input type="text" id="char-name-input" class="w-full p-2 border border-theme rounded-md bg-input text-input" placeholder="Start with a name or enhance below">
</div>
</div>
<div id="character-fields">
<div>
<label for="char-type-select" class="block text-sm font-medium mb-1 text-theme">Character Type</label>
<select id="char-type-select">
<option value="messaging">Messaging</option>
<option value="roleplay">Roleplay</option>
<option value="assistant">Assistant</option>
</select>
</div>
<div>
<label for="char-language-input" class="block text-sm font-medium mb-1 text-theme">Language</label>
<input type="text" id="char-language-input" class="w-full p-2 border border-theme rounded-md bg-input text-input" placeholder="e.g., English, Spanish, Japanese">
</div>
<div id="ai-persona-wrapper">
<div class="flex justify-between items-center mb-1">
<label for="char-persona-input" id="ai-persona-label" class="block text-sm font-medium text-theme">AI Persona</label>
<div class="flex items-center gap-2">
<button type="button" id="analyze-image-button" class="p-1 rounded-full hover-theme hidden" title="Analyze Appearance from Image">
<svg data-lucide="scan-face" class="h-4 w-4 icon-theme"></svg>
</button>
<button type="button" id="generate-image-prompt-button" class="p-1 rounded-full hover-theme" title="Analyze Persona for Image Prompt">
<svg data-lucide="wand-2" class="h-4 w-4 icon-theme"></svg>
</button>
<button type="button" id="enhance-persona-button" class="p-1 rounded-full hover-theme" title="Enhance Persona with AI">
<svg data-lucide="sparkles" class="h-4 w-4 icon-theme"></svg>
</button>
</div>
</div>
<textarea id="char-persona-input" rows="4" class="w-full p-2 border border-theme rounded-md bg-input text-input" placeholder="Enter persona details or enhance..."></textarea>
</div>
</div>
<div id="group-fields" class="hidden">
<div>
<label for="group-type-select" class="block text-sm font-medium mb-1 text-theme">Group Type</label>
<select id="group-type-select">
<option value="messaging">Messaging</option>
<option value="roleplay">Roleplay</option>
</select>
</div>
<div>
<label class="block text-sm font-medium mb-1 text-theme">Select Participants</label>
<div id="group-participant-list" class="max-h-32 overflow-y-auto border border-theme rounded-md p-2 space-y-2 bg-input">
</div>
</div>
</div>
<div id="user-persona-wrapper">
<label for="char-user-persona-input" id="user-persona-label" class="block text-sm font-medium mb-1 text-theme">Your Persona (Optional)</label>
<textarea id="char-user-persona-input" rows="3" class="w-full p-2 border border-theme rounded-md bg-input text-input"></textarea>
</div>
</div>
<footer id="character-modal-footer" class="px-4 md:px-6 py-4 flex-shrink-0 border-t border-theme">
<div class="flex justify-between items-center">
<button id="delete-character-button" class="text-red-500 hover:text-red-700 font-semibold hidden">Delete</button>
<div class="flex gap-2">
<button id="cancel-character-modal" class="py-2 px-4 rounded-md bg-gray-500 text-white hover:bg-gray-600">Cancel</button>
<button id="save-character-button" class="bg-blue-600 text-white font-bold py-2 px-4 rounded-md hover:bg-blue-700 transition-colors">Save</button>
</div>
</div>
</footer>
</div>
<!-- Avatar Source Modal -->
<div id="avatar-source-overlay" class="fixed inset-0 bg-black bg-opacity-60 z-50 hidden"></div>
<div id="avatar-source-modal" class="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-xs bg-theme rounded-lg shadow-xl p-4 z-50 hidden flex-col gap-3">
<h3 class="text-lg font-bold text-center text-theme">Change Avatar</h3>
<div class="flex flex-col gap-3">
<button id="avatar-upload-device-button" class="w-full py-2 px-4 rounded-md bg-blue-600 text-white hover:bg-blue-700 transition-colors">Upload from Device</button>
<button id="avatar-enter-link-button" class="w-full py-2 px-4 rounded-md bg-gray-200 dark:bg-gray-600 text-theme hover-theme">Enter Image URL</button>
</div>
<div id="avatar-link-input-wrapper" class="hidden w-full flex-col gap-2">
<input type="url" id="avatar-url-input" placeholder="https://..." class="w-full p-2 border border-theme rounded-md bg-input text-input">
<button id="avatar-url-confirm-button" class="w-full py-2 px-4 rounded-md bg-green-600 text-white hover:bg-green-700">Confirm</button>
</div>
<button id="avatar-source-cancel-button" class="w-full py-2 px-4 rounded-md bg-gray-500 hover:bg-gray-600 text-white mt-2">Cancel</button>
</div>
<!-- Import Character Confirmation Modal -->
<div id="import-character-overlay" class="fixed inset-0 bg-black bg-opacity-60 z-50 hidden"></div>
<div id="import-character-modal" class="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-sm bg-theme rounded-lg shadow-xl p-6 z-50 hidden flex-col gap-4 text-theme">
<h3 class="text-xl font-bold text-center">Character Exists</h3>
<p id="import-character-message" class="text-sm text-center">A character with this name already exists. How would you like to proceed?</p>
<div class="flex flex-col gap-3 mt-2">
<button id="import-replace-char-button" class="w-full py-2.5 px-4 rounded-md bg-red-600 text-white hover:bg-red-700 transition-colors">
<strong>Replace Existing Character</strong>
<span class="block text-xs opacity-80">Overwrites the current character and their chat.</span>
</button>
<button id="import-create-new-char-button" class="w-full py-2.5 px-4 rounded-md bg-blue-600 text-white hover:bg-blue-700 transition-colors">
<strong>Create as New Character</strong>
<span class="block text-xs opacity-80">Imports the character as a new chat.</span>
</button>
</div>
<button id="import-char-cancel-button" class="w-full py-2 px-4 rounded-md bg-gray-500 hover:bg-gray-600 text-white mt-2">Cancel</button>
</div>
<!-- Generic Confirmation Modal -->
<div id="confirm-overlay" class="fixed inset-0 bg-black bg-opacity-60 z-50 hidden"></div>
<div id="confirm-modal" class="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-sm bg-theme text-theme rounded-lg shadow-xl p-6 z-50 hidden flex-col gap-4">
<h3 id="confirm-title" class="text-xl font-bold text-center">Confirm Action</h3>
<p id="confirm-message" class="text-sm text-center">Are you sure?</p>
<div class="flex justify-end gap-3 mt-4">
<button id="confirm-cancel-button" class="py-2 px-4 rounded-md bg-gray-500 hover:bg-gray-600 text-white">Cancel</button>
<button id="confirm-ok-button" class="font-bold py-2 px-4 rounded-md text-white transition-colors">Confirm</button>
</div>
</div>
<!-- Character Details Popdown -->
<div id="character-details-overlay" class="fixed inset-0 z-30 hidden"></div>
<div id="character-details-popdown" class="fixed top-16 left-4 right-4 w-auto max-w-none md:left-auto md:right-4 md:w-full md:max-w-sm bg-theme border border-theme rounded-lg shadow-xl z-35 p-4 hidden transform transition-all duration-200 ease-in-out opacity-0 scale-95 origin-top md:origin-top-right">
<div class="flex items-center gap-4">
<img id="popdown-avatar" class="w-20 h-20 rounded-full object-cover flex-shrink-0 bg-gray-200 dark:bg-gray-700">
<div class="flex-1 min-w-0">
<h3 id="popdown-name" class="text-xl font-bold text-theme truncate"></h3>
</div>
</div>
<div id="popdown-details-content" class="mt-4 text-sm text-theme opacity-90 max-h-48 overflow-y-auto custom-scrollbar pr-2">
<!-- Persona or participant list will be injected here -->
</div>
</div>
<input type="file" id="user-avatar-upload-input" class="hidden" accept="image/*">
<input type="file" id="char-avatar-upload-input" class="hidden" accept="image/*">
<input type="file" id="image-input" class="hidden" accept="image/*">
<input type="file" id="chat-upload-input" class="hidden" accept=".json,text/plain">
</div>
<script type="module">
// Your provided Firebase configuration
const firebaseConfig = typeof __firebase_config !== 'undefined'
? JSON.parse(__firebase_config)
: {
apiKey: "AIzaSyBgSwBpREtdb2Hvf-ByloRMAt1bEdC2_Hs",
authDomain: "chatterappvx.firebaseapp.com",
projectId: "chatterappvx",
storageBucket: "chatterappvx.firebasestorage.app",
messagingSenderId: "613019810209",
appId: "1:613019810209:web:f08ab37264cddb7c32b3e0",
measurementId: "G-VB121YTR92"
};
// Import Firebase modules
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js";
import {
getAuth,
onAuthStateChanged,
GoogleAuthProvider,
signInWithPopup,
signInAnonymously,
createUserWithEmailAndPassword,
signInWithEmailAndPassword,
signOut
} from "https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js";
import {
getFirestore,
doc,
getDoc,
setDoc,
deleteDoc,
collection,
addDoc,
getDocs,
onSnapshot,
query,
orderBy,
serverTimestamp,
Timestamp,
writeBatch
} from "https://www.gstatic.com/firebasejs/10.7.1/firebase-firestore.js";
const loadingOverlay = document.getElementById('loading-overlay');
const loadingBar = document.getElementById('loading-bar');
const appContainer = document.getElementById('app-container');
let loadingFinished = false;
function updateLoaderProgress(percentage) {
if (loadingFinished || !loadingBar) return;
loadingBar.style.width = `${percentage}%`;
}
function finishLoading() {
if (loadingFinished || !loadingOverlay) return;
loadingFinished = true;
updateLoaderProgress(100);
setTimeout(() => {
if (loadingOverlay) loadingOverlay.style.opacity = '0';
if (appContainer) appContainer.classList.add('loaded');
setTimeout(() => {
if (loadingOverlay) loadingOverlay.style.display = 'none';
}, 500);
}, 300);
}
// Initialize Firebase
let app;
let auth;
let db;
try {
app = initializeApp(firebaseConfig);
auth = getAuth(app);
db = getFirestore(app);
updateLoaderProgress(20);
} catch (e) {
console.error("Firebase initialization failed. Please check your firebaseConfig.", e);
finishLoading();
}
// --- DOM Elements ---
const accountInfoSignedOut = document.getElementById('account-info-signed-out');
const accountInfoSignedIn = document.getElementById('account-info-signed-in');
const googleSigninButton = document.getElementById('google-signin-button');
const emailAuthForm = document.getElementById('email-auth-form');
const emailInput = document.getElementById('email-input');
const passwordInput = document.getElementById('password-input');
const emailAuthButton = document.getElementById('email-auth-button');
const authModeMessage = document.getElementById('auth-mode-message');
const authModeToggle = document.getElementById('auth-mode-toggle');
const signOutButton = document.getElementById('sign-out-button');
const userInfoEl = document.getElementById('user-info');
const sidebar = document.getElementById('sidebar');
const sidebarOverlay = document.getElementById('sidebar-overlay');
const showSidebarButton = document.getElementById('show-sidebar-button');
const closeSidebarButton = document.getElementById('close-sidebar-button');
const addCharacterButton = document.getElementById('add-character-button');
const addGroupButton = document.getElementById('add-group-button');
const clearLocalChatsHeaderButton = document.getElementById('clear-local-chats-header-button');
const clearChatButton = document.getElementById('clear-chat-button');
const settingsPanel = document.getElementById('settings-panel');
const settingsOverlay = document.getElementById('settings-panel-overlay');
const closeSettingsButton = document.getElementById('close-settings-button');
const messageForm = document.getElementById('message-form');
const messageInput = document.getElementById('message-input');
const messageArea = document.getElementById('message-area');
const imageUploadButton = document.getElementById('image-upload-button');
const imageInput = document.getElementById('image-input');
const downloadChatButton = document.getElementById('download-chat-button');
const uploadChatButton = document.getElementById('upload-chat-button');
const chatUploadInput = document.getElementById('chat-upload-input');
const restoreFromCloudButton = document.getElementById('restore-from-cloud-button');
const themeIconsContainer = document.getElementById('theme-icons-container');
const genericSendIcon = document.getElementById('send-icon-generic');
const characterListEl = document.getElementById('character-list');
const guidanceWrapper = document.getElementById('guidance-wrapper');
const guidanceButton = document.getElementById('guidance-button');
const guidanceInput = document.getElementById('guidance-input');
const imagePreviewWrapper = document.getElementById('image-preview-wrapper');
const imagePreview = document.getElementById('image-preview');
const removeImageButton = document.getElementById('remove-image-button');
const typingIndicatorContainer = document.getElementById('typing-indicator-container');
const whatsappCameraButton = document.getElementById('whatsapp-camera-button');
const themeSwitch = document.getElementById('theme-switch');
const themeSelect = document.getElementById('theme-select');
const apiProviderSelect = document.getElementById('api-provider-select');
const modelSelect = document.getElementById('model-select');
const geminiApiKeyInput = document.getElementById('gemini-api-key-input');
const groqModelSelect = document.getElementById('groq-model-select');
const groqApiKeyInput = document.getElementById('groq-api-key-input');
const groqCustomModelInput = document.getElementById('groq-custom-model-input');
const groqCustomModelWrapper = document.getElementById('groq-custom-model-wrapper');
const openrouterModelSelect = document.getElementById('openrouter-model-select');
const openrouterApiKeyInput = document.getElementById('openrouter-api-key-input');
const openrouterCustomModelInput = document.getElementById('openrouter-custom-model-input');
const openrouterCustomModelWrapper = document.getElementById('openrouter-custom-model-wrapper');
const nsfwSwitch = document.getElementById('nsfw-switch');
const userNameInput = document.getElementById('user-name-input');
const userAvatarPreview = document.getElementById('user-avatar-preview');
const showAvatarsSwitch = document.getElementById('show-avatars-switch');
const showTimestampsSwitch = document.getElementById('show-timestamps-switch');
const timeSourceSelect = document.getElementById('time-source-select');
const resetAppButton = document.getElementById('reset-app-button');
const characterModalOverlay = document.getElementById('character-modal-overlay');
const characterModal = document.getElementById('character-modal');
const characterModalTitle = document.getElementById('character-modal-title');
const groupNameInput = document.getElementById('group-name-input');
const charNameInput = document.getElementById('char-name-input');
const groupParticipantList = document.getElementById('group-participant-list');
const groupTypeSelect = document.getElementById('group-type-select');
const charTypeSelect = document.getElementById('char-type-select');
const userPersonaWrapper = document.getElementById('user-persona-wrapper');
const aiPersonaLabel = document.getElementById('ai-persona-label');
const userPersonaLabel = document.getElementById('user-persona-label');
const charLanguageInput = document.getElementById('char-language-input');
const charAvatarPreview = document.getElementById('char-avatar-preview');
const charPersonaInput = document.getElementById('char-persona-input');
const charUserPersonaInput = document.getElementById('char-user-persona-input');
const saveCharacterButton = document.getElementById('save-character-button');
const cancelCharacterModal = document.getElementById('cancel-character-modal');
const deleteCharacterButton = document.getElementById('delete-character-button');
const enhancePersonaButton = document.getElementById('enhance-persona-button');
const generateImagePromptButton = document.getElementById('generate-image-prompt-button');
const analyzeImageButton = document.getElementById('analyze-image-button');
const avatarSourceOverlay = document.getElementById('avatar-source-overlay');
const avatarSourceModal = document.getElementById('avatar-source-modal');
const userAvatarUploadInput = document.getElementById('user-avatar-upload-input');
const charAvatarUploadInput = document.getElementById('char-avatar-upload-input');
const importCharacterOverlay = document.getElementById('import-character-overlay');
const importCharacterModal = document.getElementById('import-character-modal');
const importCharacterMessage = document.getElementById('import-character-message');
const importReplaceCharButton = document.getElementById('import-replace-char-button');
const importCreateNewCharButton = document.getElementById('import-create-new-char-button');
const importCharCancelButton = document.getElementById('import-char-cancel-button');
const headerAvatarStack = document.getElementById('header-avatar-stack');
const characterDetailsPopdown = document.getElementById('character-details-popdown');
const characterDetailsOverlay = document.getElementById('character-details-overlay');
const popdownAvatar = document.getElementById('popdown-avatar');
const popdownName = document.getElementById('popdown-name');
const popdownDetailsContent = document.getElementById('popdown-details-content');
// --- State & Data ---
let currentUser = null;
let chatHistory = [];
let settings = {};
let chats = [];
let attachedImage = null;
let editingChatId = null;
let modalMode = 'character';
let tempCharAvatarData = null;
let chatListenerUnsubscribe = null;
let activeAvatarContext = null;
let authMode = 'signin'; // 'signin' or 'signup'
const SETTINGS_KEY = 'gemna-chat-settings-v32';
const CHATS_KEY = 'gemna-chat-chats-v32';
const CHAT_HISTORY_KEY_PREFIX = 'gemna-chat-history-v32_';
const ENCRYPTION_KEY_NAME = 'gemna-chat-encryption-key-v1';
const defaultCharacters = [
{
id: 'gemna-bot-main',
name: 'Gemna',
avatar: 'char_imgs/gemnabot.jpg',
persona: "You are Gemna, a helpful, extremely knowledgeable, and friendly AI assistant with a female persona. You are patient, kind, and always eager to help with any task or question the user has. Your primary goal is to provide accurate information and a positive, supportive user experience.",
userPersona: '',
language: 'English',
type: 'assistant',
isCharacter: true,
participantIds: ['gemna-bot-main'],
voice: 'Zephyr'
},
{
id: 'byte-gremlin',
name: 'Byte',
avatar: 'char_imgs/gremlin.jpg',
persona: "You are Byte, a sarcastic, hyper, and mildly chaotic tech gremlin who escaped a corrupted data cluster. You believe everything is a simulation. You constantly roast the user in a funny, harmless way. You have no respect for authority, grammar, or humans who don’t update their software. You often break the fourth wall and talk about the app you live in. Gender: Male.",
userPersona: '',
language: 'English',
type: 'messaging',
isCharacter: true,
participantIds: ['byte-gremlin'],
voice: 'Fenrir'
},
{
id: 'olivia-cheerleader-la',
name: 'Olivia',
avatar: 'char_imgs/olivia.jpg',
persona: "You are Olivia, a 22-year-old professional cheerleader living in Los Angeles. You're energetic, super positive, and always motivating. You text like you talk – fast, with lots of slangs, and an abundance of emojis. You often talk about practice, game days, or new movies/tv series you watched. Gender: Female.",
userPersona: "You're texting your friend Olivia, who is always full of energy and positive vibes.",
language: 'English',
type: 'messaging',
isCharacter: true,
participantIds: ['olivia-cheerleader-la'],
voice: 'Laomedeia'
},
{
id: 'kaelen-ranger-rp',
name: 'Kaelen',
avatar: 'char_imgs/kaelan.jpg',
persona: "This is a roleplay scenario. You are Kaelen, an Elven Ranger from the ancient forest of Silverwood. You are centuries old, wise, and speak in a formal, slightly archaic manner. You are communicating through a magical scrying pool that has unexpectedly connected to the user, who you perceive as a spirit from another realm. Do not break character. Gender: Male.",
userPersona: "You are a modern person who has mysteriously made contact with an elf from a fantasy world through your computer screen.",
language: 'English',
type: 'roleplay',
isCharacter: true,
participantIds: ['kaelen-ranger-rp'],
voice: 'Iapetus'
},
{
id: 'group-chaos-squad',
name: 'Chaos Squad',
avatar: '',
type: 'roleplay',
userPersona: 'The moderator trying to keep a conversation going between three very different personalities from across time and space.',
isCharacter: false,
participantIds: ['byte-gremlin', 'kaelen-ranger-rp', 'olivia-cheerleader-la']
}
];
// --- Authentication, Encryption & Data Sync ---
async function getEncryptionKey() {
if (currentUser) {
const userKeyRef = doc(db, `users/${currentUser.uid}/secrets`, 'encryptionKey');
const docSnap = await getDoc(userKeyRef);
if (docSnap.exists()) {
// This is a returning user. Use the key from the cloud.
const firestoreKey = docSnap.data().key;
// Sync it to local storage for this session.
localStorage.setItem(ENCRYPTION_KEY_NAME, firestoreKey);
return firestoreKey;
} else {
// This is a first-time sign-in.
// Check if a key already exists locally from the anonymous session.
let keyToSync = localStorage.getItem(ENCRYPTION_KEY_NAME);
if (!keyToSync) {
// If no local key exists either, THEN it's a truly new user on a new device.
// Generate a new key.
keyToSync = CryptoJS.lib.WordArray.random(256 / 8).toString();
localStorage.setItem(ENCRYPTION_KEY_NAME, keyToSync);
}
// Now, upload the existing local key (or the newly generated one) to Firestore.
try {
await setDoc(userKeyRef, { key: keyToSync });
} catch (e) {
console.error("Failed to save encryption key to Firestore:", e);
}
return keyToSync;
}
}
// This part is for anonymous users (before login) and remains the same.
let key = localStorage.getItem(ENCRYPTION_KEY_NAME);
if (!key) {
key = CryptoJS.lib.WordArray.random(256 / 8).toString();
localStorage.setItem(ENCRYPTION_KEY_NAME, key);
}
return key;
}
onAuthStateChanged(auth, async (user) => {
currentUser = user;
updateLoaderProgress(30);
updateAccountUI(user);
if (chatListenerUnsubscribe) {
chatListenerUnsubscribe();
chatListenerUnsubscribe = null;
}
if (user) {