File size: 30,816 Bytes
a256758
b58742f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a256758
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
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bigkas Uno - Uncensored AI Chat Platform</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/marked@9.1.2/marked.min.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Orbitron:wght@400;700;900&display=swap" rel="stylesheet">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    fontFamily: {
                        'sans': ['Inter', 'system-ui', 'sans-serif'],
                        'brand': ['Orbitron', 'monospace'],
                    },
                    animation: {
                        'gradient': 'gradient 8s ease infinite',
                        'pulse-slow': 'pulse 3s infinite',
                        'float': 'float 6s ease-in-out infinite',
                        'glow': 'glow 2s ease-in-out infinite alternate',
                    },
                    keyframes: {
                        gradient: {
                            '0%, 100%': { 'background-position': '0% 50%' },
                            '50%': { 'background-position': '100% 50%' },
                        },
                        float: {
                            '0%, 100%': { transform: 'translateY(0px)' },
                            '50%': { transform: 'translateY(-10px)' },
                        },
                        glow: {
                            '0%': { boxShadow: '0 0 20px rgba(93, 92, 222, 0.5)' },
                            '100%': { boxShadow: '0 0 30px rgba(147, 51, 234, 0.8)' },
                        }
                    }
                }
            }
        }
    </script>
    <style>
        .trinomic-gradient {
            background: linear-gradient(-45deg, #5D5CDE, #9333EA, #EC4899, #F59E0B);
            background-size: 400% 400%;
        }
        
        .trinomic-gradient-subtle {
            background: linear-gradient(135deg, rgba(93, 92, 222, 0.1), rgba(147, 51, 234, 0.1), rgba(236, 72, 153, 0.1));
        }
        
        .chat-message {
            animation: slideInUp 0.3s ease-out;
        }
        
        @keyframes slideInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .typing-indicator {
            display: inline-flex;
            align-items: center;
        }
        
        .typing-dot {
            width: 6px;
            height: 6px;
            border-radius: 50%;
            background-color: #9333EA;
            margin: 0 2px;
            animation: typing 1.4s infinite ease-in-out;
        }
        
        .typing-dot:nth-child(1) { animation-delay: -0.32s; }
        .typing-dot:nth-child(2) { animation-delay: -0.16s; }
        
        @keyframes typing {
            0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
            40% { transform: scale(1); opacity: 1; }
        }
        
        .message-content pre {
            background: rgba(0, 0, 0, 0.1);
            border-radius: 8px;
            padding: 12px;
            overflow-x: auto;
            margin: 8px 0;
        }
        
        .message-content code {
            background: rgba(0, 0, 0, 0.1);
            padding: 2px 6px;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
        }
        
        .scrollbar-thin::-webkit-scrollbar {
            width: 6px;
        }
        
        .scrollbar-thin::-webkit-scrollbar-track {
            background: rgba(0, 0, 0, 0.1);
            border-radius: 3px;
        }
        
        .scrollbar-thin::-webkit-scrollbar-thumb {
            background: linear-gradient(45deg, #5D5CDE, #9333EA);
            border-radius: 3px;
        }
        
        .scrollbar-thin::-webkit-scrollbar-thumb:hover {
            background: linear-gradient(45deg, #4C4BCD, #7C2D99);
        }
    </style>
</head>
<body class="min-h-screen bg-gray-50 dark:bg-gray-900 font-sans transition-colors duration-300">
    <!-- Background Pattern -->
    <div class="fixed inset-0 opacity-30">
        <div class="absolute inset-0 trinomic-gradient animate-gradient"></div>
        <div class="absolute inset-0 bg-white dark:bg-gray-900"></div>
    </div>
    
    <!-- Main Container -->
    <div class="relative z-10 min-h-screen flex flex-col">
        <!-- Header -->
        <header class="bg-white/80 dark:bg-gray-800/80 backdrop-blur-lg border-b border-gray-200 dark:border-gray-700 sticky top-0 z-20">
            <div class="max-w-6xl mx-auto px-4 py-4">
                <div class="flex items-center justify-between">
                    <div class="flex items-center space-x-3">
                        <div class="w-12 h-12 trinomic-gradient rounded-xl flex items-center justify-center animate-glow">
                            <span class="text-white font-brand font-bold text-xl">B</span>
                        </div>
                        <div>
                            <h1 class="text-2xl lg:text-3xl font-brand font-black bg-gradient-to-r from-purple-600 via-pink-600 to-orange-500 bg-clip-text text-transparent">
                                Bigkas Uno
                            </h1>
                            <p class="text-sm text-gray-600 dark:text-gray-400">Uncensored AI • Versatile • Transparent</p>
                        </div>
                    </div>
                    
                    <div class="flex items-center space-x-4">
                        <div class="hidden sm:flex items-center space-x-2 text-sm text-gray-600 dark:text-gray-400">
                            <div class="w-2 h-2 bg-green-500 rounded-full animate-pulse"></div>
                            <span>Model: Uno</span>
                        </div>
                        <button id="settingsBtn" class="p-2 text-gray-600 dark:text-gray-400 hover:text-purple-600 dark:hover:text-purple-400 transition-colors">
                            <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path>
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
                            </svg>
                        </button>
                    </div>
                </div>
            </div>
        </header>

        <!-- Main Chat Area -->
        <main class="flex-1 flex flex-col max-w-6xl mx-auto w-full">
            <!-- Welcome Message -->
            <div id="welcomeMessage" class="text-center py-12 px-4">
                <div class="animate-float">
                    <div class="w-24 h-24 trinomic-gradient rounded-full mx-auto mb-6 flex items-center justify-center animate-glow">
                        <span class="text-white font-brand font-bold text-4xl">U</span>
                    </div>
                </div>
                <h2 class="text-3xl lg:text-4xl font-bold text-gray-800 dark:text-white mb-4">
                    Welcome to <span class="font-brand bg-gradient-to-r from-purple-600 via-pink-600 to-orange-500 bg-clip-text text-transparent">Bigkas Uno</span>
                </h2>
                <p class="text-lg text-gray-600 dark:text-gray-400 max-w-2xl mx-auto mb-8">
                    Experience uncensored AI conversations with Uno, our versatile and transparent AI model. 
                    Ask anything, explore ideas freely, and get authentic responses without limitations.
                </p>
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4 max-w-4xl mx-auto">
                    <div class="trinomic-gradient-subtle p-6 rounded-xl border border-gray-200 dark:border-gray-700">
                        <div class="w-12 h-12 bg-purple-100 dark:bg-purple-900 rounded-lg flex items-center justify-center mb-4">
                            <svg class="w-6 h-6 text-purple-600 dark:text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path>
                            </svg>
                        </div>
                        <h3 class="font-semibold text-gray-800 dark:text-white mb-2">Uncensored</h3>
                        <p class="text-sm text-gray-600 dark:text-gray-400">No artificial limitations or restrictions on topics</p>
                    </div>
                    <div class="trinomic-gradient-subtle p-6 rounded-xl border border-gray-200 dark:border-gray-700">
                        <div class="w-12 h-12 bg-pink-100 dark:bg-pink-900 rounded-lg flex items-center justify-center mb-4">
                            <svg class="w-6 h-6 text-pink-600 dark:text-pink-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"></path>
                            </svg>
                        </div>
                        <h3 class="font-semibold text-gray-800 dark:text-white mb-2">Versatile</h3>
                        <p class="text-sm text-gray-600 dark:text-gray-400">Adaptable to any conversation style or topic</p>
                    </div>
                    <div class="trinomic-gradient-subtle p-6 rounded-xl border border-gray-200 dark:border-gray-700">
                        <div class="w-12 h-12 bg-orange-100 dark:bg-orange-900 rounded-lg flex items-center justify-center mb-4">
                            <svg class="w-6 h-6 text-orange-600 dark:text-orange-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"></path>
                            </svg>
                        </div>
                        <h3 class="font-semibold text-gray-800 dark:text-white mb-2">Transparent</h3>
                        <p class="text-sm text-gray-600 dark:text-gray-400">Honest and direct responses without hidden agendas</p>
                    </div>
                </div>
            </div>

            <!-- Chat Messages Container -->
            <div id="messagesContainer" class="flex-1 px-4 pb-4 hidden">
                <div id="messagesList" class="space-y-4 max-h-[60vh] overflow-y-auto scrollbar-thin pr-2">
                    <!-- Messages will be added here dynamically -->
                </div>
            </div>

            <!-- Typing Indicator -->
            <div id="typingIndicator" class="hidden px-4 pb-4">
                <div class="flex items-start space-x-3">
                    <div class="w-10 h-10 trinomic-gradient rounded-full flex items-center justify-center flex-shrink-0">
                        <span class="text-white font-bold text-sm">U</span>
                    </div>
                    <div class="bg-white dark:bg-gray-800 rounded-2xl px-4 py-3 shadow-lg border border-gray-200 dark:border-gray-700">
                        <div class="typing-indicator">
                            <div class="typing-dot"></div>
                            <div class="typing-dot"></div>
                            <div class="typing-dot"></div>
                            <span class="ml-2 text-sm text-gray-500 dark:text-gray-400">Uno is thinking...</span>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Input Area -->
            <div class="p-4 bg-white/80 dark:bg-gray-800/80 backdrop-blur-lg border-t border-gray-200 dark:border-gray-700">
                <div class="max-w-4xl mx-auto">
                    <div class="flex items-end space-x-3">
                        <div class="flex-1">
                            <textarea 
                                id="messageInput" 
                                placeholder="Ask Uno anything... (uncensored, no limitations)"
                                class="w-full text-base resize-none border border-gray-300 dark:border-gray-600 rounded-xl px-4 py-3 bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-all duration-200 min-h-[48px] max-h-32 scrollbar-thin"
                                rows="1"
                            ></textarea>
                        </div>
                        <button 
                            id="sendButton" 
                            class="bg-gradient-to-r from-purple-600 via-pink-600 to-orange-500 text-white p-3 rounded-xl hover:shadow-lg hover:scale-105 transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed disabled:transform-none focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2"
                            disabled
                        >
                            <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8"></path>
                            </svg>
                        </button>
                    </div>
                    <div class="flex items-center justify-between mt-2 text-xs text-gray-500 dark:text-gray-400">
                        <span>Press Enter to send, Shift+Enter for new line</span>
                        <span id="charCount">0</span>
                    </div>
                </div>
            </div>
        </main>
    </div>

    <!-- Settings Modal -->
    <div id="settingsModal" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
        <div class="bg-white dark:bg-gray-800 rounded-xl shadow-2xl max-w-md w-full p-6 border border-gray-200 dark:border-gray-700">
            <div class="flex items-center justify-between mb-6">
                <h3 class="text-xl font-semibold text-gray-800 dark:text-white">Settings</h3>
                <button id="closeSettings" class="text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200">
                    <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
                    </svg>
                </button>
            </div>
            
            <div class="space-y-4">
                <div>
                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Temperature</label>
                    <input type="range" id="temperatureSlider" min="0" max="1" step="0.1" value="0.7" class="w-full">
                    <div class="flex justify-between text-xs text-gray-500 dark:text-gray-400 mt-1">
                        <span>Conservative</span>
                        <span id="temperatureValue">0.7</span>
                        <span>Creative</span>
                    </div>
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Max Tokens</label>
                    <input type="range" id="maxTokensSlider" min="100" max="4000" step="100" value="1000" class="w-full">
                    <div class="flex justify-between text-xs text-gray-500 dark:text-gray-400 mt-1">
                        <span>100</span>
                        <span id="maxTokensValue">1000</span>
                        <span>4000</span>
                    </div>
                </div>
                
                <div class="pt-4 border-t border-gray-200 dark:border-gray-700">
                    <button id="clearChat" class="w-full bg-red-500 text-white py-2 px-4 rounded-lg hover:bg-red-600 transition-colors">
                        Clear Chat History
                    </button>
                </div>
            </div>
        </div>
    </div>

    <script>
        // Dark mode detection
        if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
            document.documentElement.classList.add('dark');
        }
        window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
            if (event.matches) {
                document.documentElement.classList.add('dark');
            } else {
                document.documentElement.classList.remove('dark');
            }
        });

        // Global variables
        const API_KEY = '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';
        const API_URL = 'https://openrouter.ai/api/v1/chat/completions';
        const MODEL = 'cognitivecomputations/dolphin-mistral-24b-venice-edition:free';
        
        let conversationHistory = [];
        let isGenerating = false;
        let currentSettings = {
            temperature: 0.7,
            maxTokens: 1000
        };

        // DOM elements
        const messageInput = document.getElementById('messageInput');
        const sendButton = document.getElementById('sendButton');
        const messagesList = document.getElementById('messagesList');
        const messagesContainer = document.getElementById('messagesContainer');
        const welcomeMessage = document.getElementById('welcomeMessage');
        const typingIndicator = document.getElementById('typingIndicator');
        const charCount = document.getElementById('charCount');
        const settingsBtn = document.getElementById('settingsBtn');
        const settingsModal = document.getElementById('settingsModal');
        const closeSettings = document.getElementById('closeSettings');
        const temperatureSlider = document.getElementById('temperatureSlider');
        const temperatureValue = document.getElementById('temperatureValue');
        const maxTokensSlider = document.getElementById('maxTokensSlider');
        const maxTokensValue = document.getElementById('maxTokensValue');
        const clearChat = document.getElementById('clearChat');

        // Event listeners
        messageInput.addEventListener('input', handleInputChange);
        messageInput.addEventListener('keypress', handleKeyPress);
        sendButton.addEventListener('click', sendMessage);
        settingsBtn.addEventListener('click', () => settingsModal.classList.remove('hidden'));
        closeSettings.addEventListener('click', () => settingsModal.classList.add('hidden'));
        clearChat.addEventListener('click', clearChatHistory);
        
        temperatureSlider.addEventListener('input', (e) => {
            currentSettings.temperature = parseFloat(e.target.value);
            temperatureValue.textContent = e.target.value;
        });
        
        maxTokensSlider.addEventListener('input', (e) => {
            currentSettings.maxTokens = parseInt(e.target.value);
            maxTokensValue.textContent = e.target.value;
        });

        // Click outside modal to close
        settingsModal.addEventListener('click', (e) => {
            if (e.target === settingsModal) {
                settingsModal.classList.add('hidden');
            }
        });

        function handleInputChange() {
            const value = messageInput.value;
            charCount.textContent = value.length;
            sendButton.disabled = !value.trim() || isGenerating;
            
            // Auto-resize textarea
            messageInput.style.height = '48px';
            messageInput.style.height = Math.min(messageInput.scrollHeight, 128) + 'px';
        }

        function handleKeyPress(e) {
            if (e.key === 'Enter' && !e.shiftKey) {
                e.preventDefault();
                if (!sendButton.disabled) {
                    sendMessage();
                }
            }
        }

        function showCustomAlert(message, type = 'info') {
            const alertDiv = document.createElement('div');
            alertDiv.className = `fixed top-4 right-4 z-50 p-4 rounded-lg shadow-lg max-w-sm ${
                type === 'error' ? 'bg-red-500 text-white' : 
                type === 'success' ? 'bg-green-500 text-white' : 
                'bg-blue-500 text-white'
            }`;
            alertDiv.innerHTML = `
                <div class="flex items-center justify-between">
                    <span>${message}</span>
                    <button onclick="this.parentElement.parentElement.remove()" class="ml-4 text-white hover:text-gray-200">
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
                        </svg>
                    </button>
                </div>
            `;
            document.body.appendChild(alertDiv);
            setTimeout(() => alertDiv.remove(), 5000);
        }

        function showCustomConfirm(message, onConfirm) {
            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50';
            modal.innerHTML = `
                <div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-lg max-w-sm w-full mx-4">
                    <p class="text-gray-700 dark:text-gray-300 mb-4">${message}</p>
                    <div class="flex justify-end space-x-3">
                        <button class="px-4 py-2 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded" onclick="this.closest('.fixed').remove()">Cancel</button>
                        <button class="px-4 py-2 bg-red-500 text-white hover:bg-red-600 rounded" onclick="this.closest('.fixed').remove(); (${onConfirm})()">Confirm</button>
                    </div>
                </div>
            `;
            document.body.appendChild(modal);
        }

        async function sendMessage() {
            const message = messageInput.value.trim();
            if (!message || isGenerating) return;

            // Hide welcome message and show chat
            welcomeMessage.classList.add('hidden');
            messagesContainer.classList.remove('hidden');

            // Add user message to chat
            addMessageToChat('user', message);
            
            // Clear input and reset
            messageInput.value = '';
            messageInput.style.height = '48px';
            charCount.textContent = '0';
            
            // Update UI state
            isGenerating = true;
            sendButton.disabled = true;
            showTypingIndicator();

            try {
                // Add system message to instruct the model
                const systemMessage = {
                    role: "system",
                    content: "You are Bigkas Uno, also called 'Uno' for short. You are an uncensored AI assistant designed for versatility and transparency. You should be honest, direct, and helpful without artificial limitations. Respond naturally and authentically to any topic or question while being respectful and informative."
                };

                // Prepare conversation history
                const messages = [systemMessage, ...conversationHistory, { role: "user", content: message }];

                const response = await fetch(API_URL, {
                    method: "POST",
                    headers: {
                        "Authorization": `Bearer ${API_KEY}`,
                        "HTTP-Referer": window.location.origin,
                        "X-Title": "Bigkas Uno - Uncensored AI Chat",
                        "Content-Type": "application/json"
                    },
                    body: JSON.stringify({
                        model: MODEL,
                        messages: messages,
                        temperature: currentSettings.temperature,
                        max_tokens: currentSettings.maxTokens,
                        stream: true
                    })
                });

                if (!response.ok) {
                    throw new Error(`API Error: ${response.status} ${response.statusText}`);
                }

                hideTypingIndicator();
                
                // Create AI message container
                const aiMessageDiv = addMessageToChat('assistant', '');
                const contentDiv = aiMessageDiv.querySelector('.message-content');
                
                // Handle streaming response
                const reader = response.body.getReader();
                const decoder = new TextDecoder();
                let fullResponse = '';

                while (true) {
                    const { done, value } = await reader.read();
                    if (done) break;

                    const chunk = decoder.decode(value);
                    const lines = chunk.split('\n');

                    for (const line of lines) {
                        if (line.startsWith('data: ')) {
                            const data = line.slice(6);
                            if (data === '[DONE]') continue;

                            try {
                                const parsed = JSON.parse(data);
                                const content = parsed.choices?.[0]?.delta?.content;
                                if (content) {
                                    fullResponse += content;
                                    contentDiv.innerHTML = marked.parse(fullResponse);
                                    // Auto-scroll to bottom
                                    messagesList.scrollTop = messagesList.scrollHeight;
                                }
                            } catch (e) {
                                // Ignore parsing errors for incomplete chunks
                            }
                        }
                    }
                }

                // Update conversation history
                conversationHistory.push({ role: "user", content: message });
                conversationHistory.push({ role: "assistant", content: fullResponse });

                // Keep conversation history manageable (last 20 messages)
                if (conversationHistory.length > 20) {
                    conversationHistory = conversationHistory.slice(-20);
                }

            } catch (error) {
                console.error('Error:', error);
                hideTypingIndicator();
                addMessageToChat('assistant', `❌ **Error**: ${error.message}\n\nPlease try again or check your connection.`);
                showCustomAlert('Failed to send message. Please try again.', 'error');
            } finally {
                isGenerating = false;
                sendButton.disabled = false;
            }
        }

        function addMessageToChat(role, content) {
            const messageDiv = document.createElement('div');
            messageDiv.className = 'chat-message flex items-start space-x-3';

            const isUser = role === 'user';
            const avatarBg = isUser ? 'bg-gray-400' : 'trinomic-gradient';
            const avatarText = isUser ? 'Y' : 'U';
            const messageBg = isUser ? 'bg-gray-100 dark:bg-gray-700' : 'bg-white dark:bg-gray-800';
            const senderName = isUser ? 'You' : 'Uno';

            messageDiv.innerHTML = `
                <div class="w-10 h-10 ${avatarBg} rounded-full flex items-center justify-center flex-shrink-0">
                    <span class="text-white font-bold text-sm">${avatarText}</span>
                </div>
                <div class="flex-1 min-w-0">
                    <div class="flex items-center space-x-2 mb-1">
                        <span class="font-semibold text-sm text-gray-700 dark:text-gray-300">${senderName}</span>
                        <span class="text-xs text-gray-500 dark:text-gray-400">${new Date().toLocaleTimeString()}</span>
                    </div>
                    <div class="${messageBg} rounded-2xl px-4 py-3 shadow-sm border border-gray-200 dark:border-gray-600">
                        <div class="message-content text-gray-800 dark:text-gray-200">${isUser ? content : marked.parse(content)}</div>
                    </div>
                </div>
            `;

            messagesList.appendChild(messageDiv);
            messagesList.scrollTop = messagesList.scrollHeight;
            return messageDiv;
        }

        function showTypingIndicator() {
            typingIndicator.classList.remove('hidden');
            messagesList.scrollTop = messagesList.scrollHeight;
        }

        function hideTypingIndicator() {
            typingIndicator.classList.add('hidden');
        }

        function clearChatHistory() {
            showCustomConfirm('Are you sure you want to clear all chat history?', () => {
                conversationHistory = [];
                messagesList.innerHTML = '';
                messagesContainer.classList.add('hidden');
                welcomeMessage.classList.remove('hidden');
                showCustomAlert('Chat history cleared successfully.', 'success');
            });
        }

        // Initialize the application
        document.addEventListener('DOMContentLoaded', () => {
            messageInput.focus();
            showCustomAlert('Welcome to Bigkas Uno! Start chatting with our uncensored AI.', 'success');
        });
    </script>
</body>
</html>