aboutsummaryrefslogtreecommitdiff
path: root/main.html
blob: 12eb7ece46e1a4e45821a61c7e052c2144a942ea (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="theme-color" content="#000000">
    <title>WebX11 Module System</title>
    <style>
        :root {
            --bg-color: #000000;
            --bg-secondary: #0a0a0a;
            --bg-tertiary: #111111;
            --text-color: #00ff00;
            --text-muted: #888888;
            --accent-color: #00aa00;
            --border-color: #005500;
            --error-color: #ff5555;
            --warning-color: #ffaa00;
            --info-color: #00aaff;
            --success-color: #00ff00;
            --ai-text-color: #aaddff;
            --ai-bg-color: #001a26;
            --font-primary: 'Courier New', Courier, monospace;
        }
        * { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
        body {
            background-color: var(--bg-color);
            color: var(--text-color);
            font-family: var(--font-primary);
            font-size: var(--term-font-size, 16px);
            height: 100vh;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        @media (max-width: 600px) { body { font-size: var(--term-font-size, 12px); } }
        header {
            border-bottom: 1px solid var(--border-color);
            padding: 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: var(--bg-secondary);
            flex-shrink: 0;
        }
        .header-title { font-weight: bold; font-size: 1.1em; }
        .header-version { font-size: 0.7em; color: var(--text-muted); }
        .status-pill {
            font-size: 0.8em;
            padding: 2px 6px;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            background: var(--bg-tertiary);
        }
        #terminal-container {
            flex-grow: 1;
            overflow-y: auto;
            padding: 10px;
            scroll-behavior: smooth;
            -webkit-overflow-scrolling: touch;
            transition: padding 0.2s;
        }
        #terminal-container.terminal-expanded {
            position: fixed;
            left: 0;
            top: 0;
            width: 100vw;
            height: 100vh;
            z-index: 1000;
            background: var(--bg-color);
            padding: 16px;
        }
        #terminal-container.terminal-expanded + #input-area,
        #terminal-container.terminal-expanded ~ #input-area {
            display: none;
        }
        .line-copy-btn {
            float: right;
            font-size: 0.7em;
            padding: 2px 6px;
            margin-left: 6px;
            border: 1px solid var(--border-color);
            background: var(--bg-tertiary);
            color: var(--text-muted);
            border-radius: 4px;
            cursor: pointer;
            opacity: 0;
            transition: opacity 0.15s;
        }
        .output-line:hover .line-copy-btn { opacity: 1; }
        .line-copy-btn:active { background: var(--accent-color); color: #000; }
        #ai-confirm-area {
            display: none;
            flex-shrink: 0;
            padding: 10px;
            margin: 0 8px 4px;
            border: 1px solid var(--warning-color);
            border-radius: 6px;
            background: var(--bg-secondary);
            z-index: 200;
            font-size: 0.95em;
            min-height: 48px;
            align-items: center;
            gap: 8px;
            flex-wrap: wrap;
            justify-content: center;
            pointer-events: auto;
        }
        #ai-confirm-area.visible { display: flex; }
        #ai-confirm-area.hidden { display: none !important; }
        #ai-confirm-area .confirm-desc {
            flex: 1;
            min-width: 120px;
            color: var(--warning-color);
            word-break: break-word;
        }
        #ai-confirm-area .confirm-btn {
            padding: 12px 24px;
            border: 1px solid var(--success-color);
            color: var(--success-color);
            background: transparent;
            border-radius: 6px;
            cursor: pointer;
            font-family: inherit;
            font-size: 1.1em;
            font-weight: bold;
            touch-action: manipulation;
            min-height: 48px;
            min-width: 90px;
            user-select: none;
            -webkit-user-select: none;
            transition: background 0.15s;
        }
        #ai-confirm-area .confirm-btn:active {
            background: rgba(0, 255, 0, 0.15);
        }
        #ai-confirm-area .confirm-btn.deny {
            border-color: var(--error-color);
            color: var(--error-color);
        }
        #ai-confirm-area .confirm-timer {
            font-size: 0.8em;
            color: var(--warning-color);
            flex-shrink: 0;
        }
        #ai-confirm-area .confirm-timer.urgent {
            color: var(--error-color);
            font-weight: bold;
        }
        #ai-confirm-area .confirm-timer.critical {
            color: #ff0000;
            font-weight: bold;
            animation: pulse 1s infinite;
        }
        /* ── Startup Modules Modal ── */
        .output-line { white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
        .output-line.command-prompt { color: var(--text-color); font-weight: bold; }
        .output-line.error { color: var(--error-color); }
        .output-line.warning { color: var(--warning-color); }
        .output-line.info { color: var(--info-color); }
        .output-line.success { color: var(--success-color); }
        .output-line.text-muted { color: var(--text-muted); }
        .output-line.ollama { 
            color: var(--ai-text-color); 
            background: var(--ai-bg-color);
            padding: 8px;
            border-radius: 4px;
            border: 1px solid #003344;
            margin-bottom: 10px;
            position: relative;
        }
        .output-line.user-prompt-line {
            display: flex;
            align-items: flex-start;
            gap: 6px;
            flex-wrap: wrap;
            padding: 4px 0;
        }
        .output-line.user-prompt-line .prompt-prefix {
            color: var(--accent-color);
            white-space: nowrap;
            flex-shrink: 0;
        }
        .output-line.user-prompt-line .prompt-text {
            color: var(--text-color);
            word-break: break-word;
            flex: 1;
            min-width: 0;
        }
        .copy-btn, .edit-btn {
            font-size: 0.7em;
            padding: 2px 8px;
            cursor: pointer;
            background: var(--bg-tertiary);
            border: 1px solid var(--border-color);
            border-radius: 4px;
            color: var(--text-muted);
            touch-action: manipulation;
            flex-shrink: 0;
            transition: background 0.15s;
        }
        .copy-btn:hover, .edit-btn:hover,
        .copy-btn:active, .edit-btn:active { background: var(--accent-color); color: var(--bg-color); }
        #input-area {
            border-top: 1px solid var(--border-color);
            padding: 8px 10px;
            background: var(--bg-secondary);
            display: flex;
            align-items: flex-start;
            flex-shrink: 0;
            position: relative;
        }
        .prompt-label { margin-right: 8px; color: var(--accent-color); white-space: nowrap; margin-top: 6px; }
        #command-input {
            flex-grow: 1;
            background: transparent;
            border: none;
            color: var(--text-color);
            font-family: var(--font-primary);
            font-size: inherit;
            outline: none;
            resize: none;
            overflow-y: auto;
            max-height: 120px;
            line-height: 1.4;
            padding: 4px 0;
        }
        #send-btn {
            flex-shrink: 0;
            min-width: 48px;
            min-height: 48px;
            padding: 8px 16px;
            font-size: 1em;
            touch-action: manipulation;
            margin-top: 2px;
        }
        #quick-actions { scrollbar-width: none; -ms-overflow-style: none; }
        #quick-actions::-webkit-scrollbar { display: none; }
        @media (max-width: 480px) {
            #input-area { padding: 6px; }
            #command-input { font-size: 0.9em; }
            .prompt-label { font-size: 0.8em; max-width: 80px; overflow: hidden; text-overflow: ellipsis; }
        }
        #autocomplete-dropdown {
            position: absolute;
            bottom: 100%;
            left: 0;
            right: 0;
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            border-top: none;
            max-height: 200px;
            overflow-y: auto;
            display: none;
            z-index: 1001;
        }
        @media (min-height: 700px) {
            #autocomplete-dropdown {
                bottom: auto;
                top: 100%;
                border-top: 1px solid var(--border-color);
                border-bottom: none;
            }
        }
        .autocomplete-item {
            padding: 8px 12px;
            cursor: pointer;
            border-bottom: 1px solid #111;
        }
        .autocomplete-item:hover, .autocomplete-item.selected {
            background: var(--bg-tertiary);
            color: var(--success-color);
        }
        .autocomplete-item .cmd-name { color: var(--text-color); font-weight: bold; }
        .autocomplete-item .cmd-desc { color: var(--text-muted); font-size: 0.85em; }
        #quick-actions {
            display: flex;
            gap: 8px;
            padding: 8px 10px;
            overflow-x: auto;
            border-top: 1px solid #111;
            background: var(--bg-tertiary);
            flex-shrink: 0;
        }
        .qa-btn {
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            color: var(--text-color);
            padding: 8px 12px;
            border-radius: 4px;
            font-family: inherit;
            font-size: 0.9em;
            cursor: pointer;
            white-space: nowrap;
            touch-action: manipulation;
        }
        .qa-btn:active { background: var(--border-color); }
        @keyframes confetti-fall {
            0% { transform: translateY(-10vh) rotate(0deg); opacity: 1; }
            100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
        }
        .confetti-piece {
            position: fixed; top: -5vh; z-index: 9999;
            font-size: 24px; pointer-events: none; user-select: none;
            animation: confetti-fall 3s ease-in forwards;
        }
        #status-bar {
            border-top: 1px solid var(--border-color);
            padding: 4px 10px;
            font-size: 0.8em;
            display: flex;
            justify-content: space-between;
            color: var(--text-muted);
            flex-shrink: 0;
        }
        .modal-overlay {
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            background: rgba(0,0,0,0.85);
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 1000;
        }
        .modal-content {
            background: var(--bg-color);
            border: 1px solid var(--border-color);
            width: 90%;
            max-width: 500px;
            max-height: 80vh;
            display: flex;
            flex-direction: column;
            border-radius: 4px;
        }
        .modal-header {
            padding: 10px;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            justify-content: space-between;
            font-weight: bold;
        }
        .modal-body { padding: 10px; overflow-y: auto; flex-grow: 1; }
        .modal-footer {
            padding: 10px;
            border-top: 1px solid var(--border-color);
            display: flex;
            justify-content: flex-end;
            gap: 8px;
        }
        .btn {
            padding: 6px 12px;
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            color: var(--text-color);
            cursor: pointer;
            border-radius: 3px;
        }
        .btn:hover { background: var(--bg-tertiary); }
        .btn-danger { border-color: var(--error-color); color: var(--error-color); }
        .file-item, .module-item, .model-item {
            padding: 8px;
            border-bottom: 1px solid #111;
            cursor: pointer;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .file-item:hover, .module-item:hover, .model-item:hover { background: var(--bg-tertiary); }
        .file-item.dir { color: var(--info-color); }
        .module-item.active { border-left: 3px solid var(--success-color); }
        .module-item.disabled { opacity: 0.5; }
        .model-item.connected { color: var(--success-color); }
        .hidden { display: none !important; }
        .text-center { text-align: center; }
        .clickable-file, .clickable-dir {
            cursor: pointer;
            display: inline-block;
            padding: 1px 3px;
            border: 1px solid transparent;
            border-radius: 2px;
            margin: 1px 0;
        }
        .clickable-file:hover { background: rgba(0,255,0,0.1); border-color: var(--border-color); }
        .module-url-input {
            width: 100%;
            padding: 8px;
            background: var(--bg-tertiary);
            border: 1px solid var(--border-color);
            color: var(--text-color);
            font-family: var(--font-primary);
            margin-bottom: 10px;
        }
        .ollama-status {
            padding: 10px;
            margin-bottom: 10px;
            border-radius: 4px;
        }
        .ollama-status.connected { background: rgba(0, 255, 0, 0.1); border: 1px solid var(--success-color); }
        .ollama-status.disconnected { background: rgba(255, 85, 85, 0.1); border: 1px solid var(--error-color); }
        /* Toggle slider styles */
        #ollama-optimization-slider::before, #ollama-validator-slider::before, #ollama-stream-slider::before {
            content: "";
            position: absolute;
            height: 20px;
            width: 20px;
            left: 2px;
            bottom: 2px;
            background: var(--text-color);
            border-radius: 50%;
            transition: 0.3s;
        }
        #ollama-optimization-toggle:checked + #ollama-optimization-slider::before,
        #ollama-validator-toggle:checked + #ollama-validator-slider::before,
        #ollama-stream-toggle:checked + #ollama-stream-slider::before {
            transform: translateX(22px);
        }
        #ollama-optimization-toggle:checked + #ollama-optimization-slider,
        #ollama-validator-toggle:checked + #ollama-validator-slider,
        #ollama-stream-toggle:checked + #ollama-stream-slider {
            border-color: var(--success-color);
        }
        /* ── Card Layout Styles ── */
        .msg-card {
            margin-bottom: 8px;
            border: 1px solid var(--border-color);
            border-radius: 6px;
            overflow: hidden;
            background: var(--bg-secondary);
        }
        .msg-card.user { border-left: 3px solid var(--success-color); }
        .msg-card.ai { border-left: 3px solid var(--ai-text-color); background: var(--ai-bg-color); }
        .msg-card.system { border-left: 3px solid var(--text-muted); }
        .msg-card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 6px 10px;
            border-bottom: 1px solid var(--border-color);
            background: var(--bg-tertiary);
        }
        .msg-role { font-weight: bold; font-size: 0.85em; white-space: nowrap; }
        .msg-buttons { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
        .msg-card-body {
            padding: 10px;
            white-space: pre-wrap;
            word-break: break-word;
            line-height: 1.4;
            font-size: 0.9em;
        }
        .card-btn {
            display: inline-flex;
            padding: 4px 12px;
            font-size: 0.75em;
            font-family: inherit;
            background: var(--bg-tertiary);
            border: 1px solid var(--border-color);
            color: var(--text-muted);
            border-radius: 4px;
            cursor: pointer;
            touch-action: manipulation;
            transition: background 0.15s;
            white-space: nowrap;
            line-height: 1.4;
        }
        .card-btn:hover, .card-btn:active { background: var(--accent-color); color: var(--bg-color); }
        .msg-card.ai .ai-render-container {
            margin: 0;
            border: 1px solid var(--border-color);
        }
        .msg-card.ai .ai-content {
            display: inline;
        }
        .msg-card.system .msg-card-body {
            color: inherit;
        }
        /* ── End Card Layout ── */
        .ai-render-container {
            margin: 10px 0;
            border-radius: 6px;
            overflow: hidden;
            border: 1px solid var(--border-color);
            background: #000;
        }
        .ai-render-iframe {
            width: 100%;
            border: none;
            display: block;
            background: #000;
            min-height: 200px;
        }
        .module-badge {
            display: inline-block;
            padding: 2px 6px;
            border-radius: 3px;
            font-size: 0.75em;
            margin-left: 5px;
        }
        .module-badge.builtin { background: var(--bg-tertiary); border: 1px solid var(--border-color); }
        .fetch-content {
            background: var(--bg-tertiary);
            border: 1px solid var(--border-color);
            padding: 10px;
            margin: 5px 0;
            border-radius: 4px;
            max-height: 300px;
            overflow-y: auto;
            font-size: 0.85em;
        }
        .search-result {
            margin-bottom: 10px;
            padding: 8px;
            background: var(--bg-tertiary);
            border-radius: 4px;
            border-left: 3px solid var(--info-color);
        }
        .search-result a {
            color: var(--info-color);
            text-decoration: none;
        }
        .search-result a:hover {
            text-decoration: underline;
        }
        .search-result-image, .search-result-video {
            margin-bottom: 10px;
            padding: 8px;
            background: var(--bg-tertiary);
            border-radius: 4px;
        }
        .search-result-image img, .search-result-video img {
            max-width: 200px;
            max-height: 150px;
            border-radius: 4px;
            object-fit: cover;
        }

        /* ── Splash Screen ── */
        #splash-overlay {
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            background: var(--bg-color);
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 2000;
            transition: opacity 0.3s ease;
        }
        #splash-overlay.hidden {
            opacity: 0;
            pointer-events: none;
        }
        #splash-title {
            font-size: 1.8em;
            font-weight: bold;
            margin-bottom: 4px;
        }
        #splash-version {
            font-size: 0.8em;
            color: var(--text-muted);
            margin-bottom: 24px;
        }
        #splash-progress-track {
            width: 260px;
            max-width: 70vw;
            height: 8px;
            background: var(--bg-tertiary);
            border: 1px solid var(--border-color);
            border-radius: 4px;
            overflow: hidden;
            margin-bottom: 12px;
        }
        #splash-progress-fill {
            height: 100%;
            width: 0%;
            background: var(--accent-color);
            transition: width 0.15s ease;
            border-radius: 3px;
        }
        #splash-phase {
            font-size: 0.75em;
            color: var(--text-muted);
            margin-bottom: 4px;
        }
        #splash-filename {
            font-size: 0.85em;
            color: var(--info-color);
            margin-bottom: 16px;
        }
        #splash-cursor {
            display: inline-block;
            width: 8px;
            height: 14px;
            background: var(--text-color);
            animation: blink 1s step-end infinite;
        }
        @keyframes blink {
            0%, 100% { opacity: 1; }
            50% { opacity: 0; }
        }
        #splash-gear {
            position: absolute;
            top: 12px;
            right: 12px;
            font-size: 1.4em;
            cursor: pointer;
            opacity: 0.5;
            transition: opacity 0.2s;
            touch-action: manipulation;
            padding: 8px;
        }
        #splash-gear:hover { opacity: 1; }
        #splash-error {
            color: var(--error-color);
            font-size: 0.85em;
            margin-top: 12px;
            text-align: center;
            display: none;
        }
        #splash-error.show { display: block; }

        /* ── Startup Modules Modal ── */
        .mod-card {
            display: flex;
            align-items: center;
            padding: 10px 8px;
            border-bottom: 1px solid #111;
            min-height: 44px;
            touch-action: manipulation;
        }
        .mod-card:last-child { border-bottom: none; }
        .mod-card.disabled { opacity: 0.4; pointer-events: none; }
        .mod-card label {
            display: flex;
            align-items: center;
            gap: 10px;
            flex-grow: 1;
            cursor: pointer;
        }
        .mod-card input[type="checkbox"] {
            width: 18px;
            height: 18px;
            accent-color: var(--accent-color);
            flex-shrink: 0;
        }
        .mod-card .mod-name {
            font-size: 0.9em;
            flex-shrink: 0;
        }
        .mod-card .mod-badge {
            font-size: 0.7em;
            padding: 2px 6px;
            border-radius: 3px;
            background: var(--bg-tertiary);
            border: 1px solid var(--border-color);
            color: var(--text-muted);
            margin-left: auto;
        }
        .mod-card .mod-badge.foundation {
            background: #001a00;
            border-color: var(--accent-color);
            color: var(--accent-color);
        }
        .mod-card .mod-badge.ext {
            background: #1a001a;
            border-color: #550055;
            color: #aa55ff;
        }
        .mod-section-header {
            padding: 8px 8px 4px;
            font-size: 0.75em;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 1px;
            border-bottom: 1px solid var(--border-color);
            background: var(--bg-secondary);
        }
        @media (max-width: 400px) {
            .mod-card { padding: 10px 6px; }
            .mod-card .mod-name { font-size: 0.82em; }
        }
        /* ── Command Cards Panel ── */
        #cmd-cards {
            position: fixed; right: 0; top: 48px; bottom: 0; width: 280px;
            background: var(--bg-secondary); border-left: 1px solid var(--border-color);
            z-index: 999; display: none; flex-direction: column;
            backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
            overflow-y: auto;
        }
        #cmd-cards.visible { display: flex; }
        #cmd-cards-header {
            display: flex; justify-content: space-between; align-items: center;
            padding: 12px 14px; border-bottom: 1px solid var(--border-color);
            font-weight: bold; font-size: 0.9em;
            position: sticky; top: 0; background: var(--bg-secondary);
        }
        .cmd-card-section { padding: 10px 14px; }
        .cmd-card-section + .cmd-card-section { border-top: 1px solid var(--border-color); }
        .cmd-card-section-title { font-size: 0.75em; color: var(--text-muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 1px; }
        .cmd-card {
            display: flex; align-items: center; gap: 10px;
            padding: 10px 12px; margin-bottom: 4px;
            background: var(--bg-tertiary); border: 1px solid var(--border-color);
            border-radius: 6px; cursor: pointer; transition: border-color .15s;
            min-height: 44px; touch-action: manipulation;
        }
        .cmd-card:hover { border-color: var(--accent-color); }
        .cmd-card .cmd { font-family: var(--font-primary); font-weight: bold; font-size: 0.85em; color: var(--accent-color); flex-shrink: 0; min-width: 60px; }
        .cmd-card .desc { font-size: 0.78em; color: var(--text-muted); }
        #cmd-cards-toggle { cursor: pointer; font-size: 1.1em; line-height: 1; }

        /* ── Floating UI Module ── */
        #floating-container {
            position: fixed;
            bottom: calc(56px + 36px + 12px);
            right: 12px;
            z-index: 500;
            display: flex;
            flex-direction: column-reverse;
            align-items: flex-end;
            gap: 6px;
            pointer-events: none;
            max-width: 280px;
        }
        .floating-btn {
            pointer-events: auto;
            background: var(--bg-tertiary);
            border: 1px solid var(--border-color);
            color: var(--text-color);
            padding: 8px 14px;
            border-radius: 8px;
            font-family: inherit;
            font-size: 0.9em;
            cursor: grab;
            display: flex;
            align-items: center;
            gap: 6px;
            white-space: nowrap;
            touch-action: manipulation;
            min-height: 44px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.4);
            transition: border-color 0.15s, background 0.15s;
            user-select: none;
        }
        .floating-btn:hover,
        .floating-btn:active {
            border-color: var(--accent-color);
            background: #0a1a0a;
        }
        .floating-btn:active {
            cursor: grabbing;
        }
        .floating-menu {
            pointer-events: auto;
            background: var(--bg-tertiary);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            overflow: hidden;
            min-width: 140px;
            box-shadow: 0 2px 12px rgba(0,0,0,0.5);
        }
        .floating-menu-header {
            padding: 8px 14px;
            cursor: grab;
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 0.9em;
            min-height: 44px;
            touch-action: none;
            user-select: none;
            border-bottom: 1px solid var(--border-color);
        }
        .floating-menu-header:active {
            cursor: grabbing;
        }
        .floating-menu-header:hover {
            background: #0a1a0a;
        }
        .floating-menu-header .arrow {
            transition: transform 0.2s;
            font-size: 0.7em;
        }
        .floating-menu-header .arrow.collapsed {
            transform: rotate(-90deg);
        }
        .floating-menu-body {
            overflow: hidden;
            transition: max-height 0.2s ease-out;
            max-height: 0;
        }
        .floating-menu-body.expanded {
            max-height: 300px;
        }
        .floating-menu-btn {
            display: block;
            width: 100%;
            text-align: left;
            padding: 8px 14px 8px 24px;
            background: transparent;
            border: none;
            color: var(--text-muted);
            font-family: inherit;
            font-size: 0.85em;
            cursor: pointer;
            touch-action: manipulation;
            min-height: 40px;
        }
        .floating-menu-btn:hover,
        .floating-menu-btn:active {
            background: #0a1a0a;
            color: var(--text-color);
        }
        .floating-panel {
            pointer-events: auto;
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            font-size: 0.8em;
            min-width: 120px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.4);
            overflow: hidden;
        }
        .floating-panel-title {
            padding: 6px 10px;
            font-weight: bold;
            color: var(--text-muted);
            font-size: 0.9em;
            cursor: grab;
            touch-action: none;
            user-select: none;
            border-bottom: 1px solid var(--border-color);
            background: rgba(0,0,0,0.15);
        }
        .floating-panel-title:active {
            cursor: grabbing;
        }
        .floating-panel-content {
            padding: 6px 10px;
            color: var(--text-color);
            line-height: 1.4;
        }
        @keyframes float-in {
            from { opacity: 0; transform: translateY(8px) scale(0.95); }
            to { opacity: 1; transform: translateY(0) scale(1); }
        }
        .floating-btn,
        .floating-menu,
        .floating-panel {
            animation: float-in 0.15s ease-out;
        }
    </style>
    <!-- Early persistence restore — apply saved theme + font-size BEFORE bundle loads to prevent FOUC -->
    <script>
    (function() {
        try {
            // Restore font size
            var fs = localStorage.getItem('webx11_font_size');
            if (fs) { document.documentElement.style.fontSize = fs + 'px'; }
            // Restore theme
            var theme = localStorage.getItem('webx11_active_theme');
            if (theme) {
                var themesRaw = localStorage.getItem('webx11_themes');
                var defaults = {
                    'dark': { '--bg-color': '#000000', '--bg-secondary': '#0a0a0a', '--bg-tertiary': '#111111', '--text-color': '#00ff00', '--text-muted': '#888888', '--accent-color': '#00aa00', '--border-color': '#005500' },
                    'light': { '--bg-color': '#ffffff', '--bg-secondary': '#f5f5f5', '--bg-tertiary': '#eeeeee', '--text-color': '#222222', '--text-muted': '#888888', '--accent-color': '#0066cc', '--border-color': '#cccccc' },
                    'amber': { '--bg-color': '#1a0f00', '--bg-secondary': '#2a1a00', '--bg-tertiary': '#332200', '--text-color': '#ffaa00', '--text-muted': '#886600', '--accent-color': '#ff8800', '--border-color': '#663300' },
                    'cyber': { '--bg-color': '#000a14', '--bg-secondary': '#001a2e', '--bg-tertiary': '#002240', '--text-color': '#00ffff', '--text-muted': '#0088aa', '--accent-color': '#ff00ff', '--border-color': '#004466' },
                    'ocean': { '--bg-color': '#0a1628', '--bg-secondary': '#0f2240', '--bg-tertiary': '#142e54', '--text-color': '#88ddff', '--text-muted': '#5599bb', '--accent-color': '#00aaff', '--border-color': '#1a4470' },
                    'forest': { '--bg-color': '#0a1a0e', '--bg-secondary': '#0f2814', '--bg-tertiary': '#14361c', '--text-color': '#88dd88', '--text-muted': '#559955', '--accent-color': '#33cc33', '--border-color': '#1a4a22' },
                    'monochrome': { '--bg-color': '#0a0a0a', '--bg-secondary': '#181818', '--bg-tertiary': '#222222', '--text-color': '#cccccc', '--text-muted': '#666666', '--accent-color': '#999999', '--border-color': '#333333' },
                    'sunset': { '--bg-color': '#1a0a14', '--bg-secondary': '#2a1220', '--bg-tertiary': '#3a1a2c', '--text-color': '#ffbb99', '--text-muted': '#cc7755', '--accent-color': '#ff6644', '--border-color': '#552233' },
                    'midnight': { '--bg-color': '#050510', '--bg-secondary': '#0a0a20', '--bg-tertiary': '#101030', '--text-color': '#aaaaee', '--text-muted': '#555588', '--accent-color': '#6666ff', '--border-color': '#1a1a3a' }
                };
                if (themesRaw) { try { Object.assign(defaults, JSON.parse(themesRaw)); } catch(e){} }
                var t = defaults[theme];
                if (t) { for (var k in t) { document.documentElement.style.setProperty(k, t[k]); } }
            }
        } catch(e) {}
    })();
    </script>
</head>
<body>
    <header>
        <div>
            <span class="header-title">WebX11</span>
            <span class="header-version"></span>
        </div>
        <div id="header-status" class="status-pill">Mem: --</div>
        <span id="cmd-cards-toggle" onclick="if(webx11)webx11.toggleCmdCards()" title="Quick Commands (Ctrl+K)">📋</span>
    </header>

    <!-- Command Cards Panel -->
    <div id="cmd-cards">
        <div id="cmd-cards-header">
            <span>📋 Quick Commands</span>
            <span onclick="if(webx11)webx11.toggleCmdCards()" style="cursor:pointer;font-size:1.2em;">✕</span>
        </div>
        <div class="cmd-card-section">
            <div class="cmd-card-section-title">🟢 Beginners</div>
            <div class="cmd-card" onclick="webx11?.executeCommand('help')"><span class="cmd">help</span><span class="desc">Show all commands</span></div>
            <div class="cmd-card" onclick="webx11?.executeCommand('ls')"><span class="cmd">ls</span><span class="desc">List files</span></div>
            <div class="cmd-card" onclick="webx11?.executeCommand('clear')"><span class="cmd">clear</span><span class="desc">Clear terminal</span></div>
            <div class="cmd-card" onclick="webx11?.executeCommand('status')"><span class="cmd">status</span><span class="desc">System health</span></div>
        </div>
        <div class="cmd-card-section">
            <div class="cmd-card-section-title">🤖 AI</div>
            <div class="cmd-card" onclick="webx11?.executeCommand('ai \"what can you do?\"')"><span class="cmd">ai "..."</span><span class="desc">Ask AI assistant</span></div>
            <div class="cmd-card" onclick="webx11?.executeCommand('ai-model')"><span class="cmd">ai-model</span><span class="desc">Set AI model</span></div>
        </div>
        <div class="cmd-card-section">
            <div class="cmd-card-section-title">🔍 Explore</div>
            <div class="cmd-card" onclick="webx11?.executeCommand('modules')"><span class="cmd">modules</span><span class="desc">List loaded modules</span></div>
            <div class="cmd-card" onclick="webx11?.executeCommand('tutorial')"><span class="cmd">tutorial</span><span class="desc">Interactive tour</span></div>
        </div>
        <div class="cmd-card-section">
            <div class="cmd-card-section-title">🚀 Advanced</div>
            <div class="cmd-card" onclick="webx11?.executeCommand('cron-every 60 echo hello')"><span class="cmd">cron</span><span class="desc">Schedule tasks</span></div>
            <div class="cmd-card" onclick="webx11?.executeCommand('webdav-status')"><span class="cmd">webdav</span><span class="desc">Cloud sync</span></div>
            <div class="cmd-card" onclick="webx11?.executeCommand('help.html')"><span class="cmd">help</span><span class="desc">Full reference</span></div>
        </div>
    </div>

    <!-- Terminal Container -->
    <div id="terminal-container">
        <div class="output-line info" id="terminal-welcome">WebX11 Module System - Unix-like Terminal</div>
        <div class="output-line info">Commands: ls, cd, pwd, cat, echo, rm, mkdir, mv, cp, touch, tree, find, grep</div>
        <div class="output-line info">Type 'help' for all commands</div>
        <div class="output-line"></div>
        <div class="output-line info loading" id="loading-indicator">Loading modules...</div>
    </div>

    <!-- Floating UI Container — populated by FloatingModule -->
    <div id="floating-container"></div>

    <!-- AI Confirm Area — fixed outside scrollable output, always visible -->
    <div id="ai-confirm-area" class="hidden"></div>

    <div id="quick-actions">
        <button class="qa-btn" onclick="webx11.executeCommand('ls')">📁 Files</button>
        <button class="qa-btn" onclick="webx11.executeCommand('help')">📖 Help</button>
        <button class="qa-btn" onclick="webx11.executeCommand('modules')">🧩 Modules</button>
        <button class="qa-btn" onclick="webx11.openOllamaManager()">🤖 Ollama</button>
        <button class="qa-btn" onclick="webx11.openSkillsManager()">📚 Skills</button>
        <button class="qa-btn" onclick="webx11.openConfigManager()">⚙ Config</button>
        <button class="qa-btn" onclick="webx11.executeCommand('clear')">🧹 Clear</button>
        <button class="qa-btn" id="voice-toggle-btn" onclick="webx11.toggleMicVisibility()">🎤 Mic</button>
        <button class="qa-btn" onclick="webx11.toggleDebugPanel()">🐞 Debug</button>
        <button class="qa-btn" id="sound-toggle-btn">🔊 Sound</button>
    </div>

    <div id="input-area">
        <span class="prompt-label">$</span>
        <textarea id="command-input" rows="1" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" placeholder="Type a command..." style="resize:none; overflow-y:auto; max-height:120px;"></textarea>
        <button id="send-btn" onclick="var i=document.getElementById('command-input');webx11.executeCommand(i.value);i.value='';i.style.height='auto'" style="background:var(--bg-tertiary); border:1px solid var(--border-color); color:var(--success-color); padding:6px 12px; border-radius:4px; cursor:pointer; font-family:inherit; font-size:0.9em; margin-left:6px; white-space:nowrap; flex-shrink:0;">⏎ Send</button>
        <div id="autocomplete-dropdown"></div>
    </div>

    <div id="status-bar">
        <span id="status-text">Ready</span>
        <span id="network-status">📶 Online</span>
        <span id="stream-status" style="font-size:0.75em; margin-left:4px; color:var(--success-color);">▶ Stream</span>
        <button id="ai-cancel-btn" style="display:none; background:var(--error-color); color:#fff; border:none; border-radius:4px; padding:2px 10px; cursor:pointer; font-family:inherit; font-size:0.8em; touch-action:manipulation; min-height:28px;" onclick="webx11.executeCommand('ai-stop')">⏹ Stop</button>
    </div>

    <!-- File Browser Modal -->
    <div id="file-browser" class="modal-overlay">
        <div class="modal-content">
            <div class="modal-header">
                <span>File Browser</span>
                <span style="cursor:pointer" onclick="webx11.closeFileBrowser()">✕</span>
            </div>
            <div class="modal-body" id="fb-content"></div>
            <div class="modal-footer">
                <button class="btn" onclick="document.getElementById('file-upload-input').click()">⬆️ Upload</button>
                <button class="btn" onclick="webx11.closeFileBrowser()">Close</button>
            </div>
        </div>
    </div>

    <!-- Module Manager Modal -->
    <div id="module-manager" class="modal-overlay">
        <div class="modal-content" style="max-width: 600px;">
            <div class="modal-header">
                <span>Module Manager</span>
                <span style="cursor:pointer" onclick="webx11.closeModuleManager()">✕</span>
            </div>
            <div class="modal-body">
                <div style="margin-bottom: 15px;">
                    <input type="text" id="module-url-input" class="module-url-input" placeholder="Enter module URL (https://example.com/module.js)">
                    <button class="btn" onclick="webx11.loadModuleFromURL()" style="width: 100%;">Load Module from URL</button>
                </div>
                <h4 style="color: var(--info-color); margin-bottom: 10px;">Loaded Modules</h4>
                <div id="module-list"></div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-danger" onclick="webx11.clearAllModules()">Clear All</button>
                <button class="btn" onclick="webx11.closeModuleManager()">Close</button>
            </div>
        </div>
    </div>

    <!-- Ollama Manager Modal -->
    <div id="ollama-manager" class="modal-overlay">
        <div class="modal-content" style="max-width: 600px;">
            <div class="modal-header">
                <span>Ollama AI Manager</span>
                <span style="cursor:pointer" onclick="webx11.closeOllamaManager()">✕</span>
            </div>
            <div class="modal-body">
                <div id="ollama-status" class="ollama-status disconnected">
                    <strong>Status:</strong> <span id="ollama-status-text">Disconnected</span>
                </div>
                <div style="margin-bottom: 15px;">
                    <label style="display: block; margin-bottom: 5px; color: var(--text-muted);">Ollama Endpoint:</label>
                    <input type="text" id="ollama-endpoint" class="module-url-input" value="http://localhost:11434" placeholder="http://localhost:11434">
                    <button class="btn" onclick="webx11.connectOllama()" style="width: 100%;">Connect</button>
                </div>
                <h4 style="color: var(--info-color); margin-bottom: 10px;">Available Models</h4>
                <input type="text" id="ollama-search" class="module-url-input" placeholder="Search models..." oninput="webx11.renderOllamaModels()" style="margin-bottom: 8px;">
                <div id="ollama-model-count" style="font-size: 0.8em; color: var(--text-muted); margin-bottom: 6px;"></div>
                <div id="ollama-models" style="max-height: 300px; overflow-y: auto;"></div>
                <div style="margin-top: 15px;">
                    <label style="display: block; margin-bottom: 5px; color: var(--text-muted);">Current Model:</label>
                    <select id="ollama-current-model" class="module-url-input">
                        <option value="">Select a model</option>
                    </select>
                    <button class="btn" onclick="webx11.setOllamaModel()" style="width: 100%;">Set Model</button>
                </div>
                <hr style="border-color:var(--border-color); margin: 15px 0;">
                <h4 style="color: var(--accent-color); margin-bottom: 10px;">⚡ AI Agent Optimization</h4>
                <div style="display:flex; align-items:center; gap:10px; margin-bottom: 12px;">
                    <span style="color:var(--text-muted); font-size:0.85em;">Agent Loop Optimizations:</span>
                    <label style="position:relative; display:inline-block; width:48px; height:26px;">
                        <input type="checkbox" id="ollama-optimization-toggle" onchange="webx11.toggleOptimization()" style="opacity:0; width:0; height:0;">
                        <span id="ollama-optimization-slider" style="position:absolute; cursor:pointer; inset:0; background:var(--bg-tertiary); border:1px solid var(--border-color); border-radius:26px; transition:0.3s;"></span>
                    </label>
                    <span id="ollama-optimization-label" style="font-size:0.85em; color:var(--success-color);">Enabled</span>
                </div>
                <div style="font-size:0.8em; color:var(--text-muted); margin-bottom: 10px;">
                    ⚡ Tool def caching, trivial query skip, parallel safe tools, debounced reflection<br>
                    <span style="color:var(--warning-color);">Disable for debugging or if model behaves unexpectedly. Reload after toggle.</span>
                </div>
                <hr style="border-color:var(--border-color); margin: 15px 0;">
                <h4 style="color: var(--accent-color); margin-bottom: 10px;">⚡ Response Streaming</h4>
                <div style="display:flex; align-items:center; gap:10px; margin-bottom: 6px;">
                    <span style="color:var(--text-muted); font-size:0.85em;">Stream Tokens:</span>
                    <label style="position:relative; display:inline-block; width:48px; height:26px;">
                        <input type="checkbox" id="ollama-stream-toggle" onchange="webx11.toggleStream()" style="opacity:0; width:0; height:0;">
                        <span id="ollama-stream-slider" style="position:absolute; cursor:pointer; inset:0; background:var(--bg-tertiary); border:1px solid var(--border-color); border-radius:26px; transition:0.3s;"></span>
                    </label>
                    <span id="ollama-stream-label" style="font-size:0.85em; color:var(--success-color);">Enabled</span>
                </div>
                <div style="font-size:0.8em; color:var(--text-muted); margin-bottom: 10px;">
                    Show AI responses token-by-token. Disable for instant full responses and reduced crash risk.<br>
                    <span style="color:var(--warning-color);">Disable on slow connections or when browser becomes unresponsive during long outputs.</span>
                </div>
                <hr style="border-color:var(--border-color); margin: 15px 0;">
                <h4 style="color: var(--info-color); margin-bottom: 10px;">🔍 Validator Agent</h4>
                <div style="font-size:0.85em; color:var(--text-muted); margin-bottom: 10px;">
                    A separate lightweight AI that validates the main agent's tool results. Has its own
                    endpoint and model — independent from your active AI model.<br>
                    <span style="color:var(--success-color);">⚡ Best validator model: <strong>qwen2.5:0.5b</strong> (1.94s, 352MB)</span>
                </div>
                <div style="display:flex; align-items:center; gap:10px; margin-bottom: 10px;">
                    <span style="color:var(--text-muted); font-size:0.85em;">Enable Validator:</span>
                    <label style="position:relative; display:inline-block; width:48px; height:26px;">
                        <input type="checkbox" id="ollama-validator-toggle" onchange="webx11.toggleValidator()" style="opacity:0; width:0; height:0;">
                        <span id="ollama-validator-slider" style="position:absolute; cursor:pointer; inset:0; background:var(--bg-tertiary); border:1px solid var(--border-color); border-radius:26px; transition:0.3s;"></span>
                    </label>
                    <span id="ollama-validator-label" style="font-size:0.85em; color:var(--text-muted);">Disabled</span>
                </div>
                <div style="margin-bottom: 8px;">
                    <label style="display: block; margin-bottom: 3px; color: var(--text-muted); font-size:0.85em;">Validator Endpoint:</label>
                    <input type="text" id="validator-endpoint-input" class="module-url-input" value="http://localhost:11434" placeholder="http://localhost:11434" style="margin-bottom:6px;">
                    <button class="btn" onclick="webx11.connectValidatorEndpoint()" style="width:100%; border-color:var(--info-color); color:var(--info-color);">🔌 Connect & Load Models</button>
                    <div id="validator-connection-status" style="font-size:0.8em; margin-top:4px;"></div>
                </div>
                <div style="margin-bottom: 10px;">
                    <label style="display: block; margin-bottom: 3px; color: var(--text-muted); font-size:0.85em;">Validator Model:</label>
                    <select id="validator-model-select" class="module-url-input" style="margin-bottom:6px;" disabled>
                        <option value="">Connect to load models</option>
                    </select>
                    <button class="btn" onclick="webx11.saveValidatorConfig()" style="width:100%; border-color:var(--info-color); color:var(--info-color);">Save Validator Config</button>
                </div>
                <div style="font-size:0.8em; color:var(--warning-color); border:1px solid var(--border-color); border-radius:4px; padding:10px; margin-top:10px;">
                    <strong>⚠️ Connection Notes</strong><br>
                    • Cloud models (deepseek-v4*, gemma4:*b-cloud) via Ollama proxy often <strong>ignore tool calls</strong>
                      and answer from training data instead. Use local models for tool calling.<br>
                    • To connect to local Ollama from a web page: set <code>OLLAMA_ORIGINS</code> on the server:
                      <code>export OLLAMA_ORIGINS="https://webx11.duckdns.org"</code> then restart Ollama.<br>
                    • Test local connection: open a terminal and run <code>curl http://localhost:11434/api/tags</code><br>
                    • If you see <strong>403</strong> errors in console: the <code>OLLAMA_ORIGINS</code> env var isn't matching your page URL.
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn" onclick="webx11.closeOllamaManager()">Close</button>
            </div>
        </div>
    </div>

    <!-- Splash Screen -->
    <div id="splash-overlay">
        <span id="splash-gear" onclick="openStartupModulesSplash(event)" title="Select startup modules">⚙</span>
        <div id="splash-title">⚡ WebX11</div>
        <div id="splash-version"></div>
        <div id="splash-progress-track"><div id="splash-progress-fill"></div></div>
        <div id="splash-phase">Initializing...</div>
        <div id="splash-filename"></div>
        <div><span id="splash-cursor"></span></div>
        <div id="splash-error"></div>
    </div>

    <!-- Skills Manager Modal -->
    <div id="skills-manager" class="modal-overlay">
        <div class="modal-content" style="max-width: 750px; max-height: 90vh;">
            <div class="modal-header">
                <span>📚 Skills Manager</span>
                <span style="cursor:pointer" onclick="webx11.closeSkillsManager()">✕</span>
            </div>
            <div class="modal-body" style="display:flex; flex-direction:column; gap:8px;">
                <!-- Stats header -->
                <div id="skills-stats" style="display:flex; gap:12px; flex-wrap:wrap; font-size:0.85em; color:var(--text-muted); padding-bottom:6px; border-bottom:1px solid var(--border-color);"></div>
                <!-- Search + action bar -->
                <div style="display:flex; gap:6px; align-items:center; flex-shrink:0;">
                    <input type="text" id="skills-search-input" class="module-url-input" placeholder="🔍 Search skills..." style="flex:1;" oninput="webx11.refreshSkillsList()">
                    <button class="btn" onclick="webx11.exportAllSkillsUI()" style="padding:4px 10px; font-size:0.8em">📤 Export All</button>
                    <button class="btn" onclick="document.getElementById('skills-import-input').click()" style="padding:4px 10px; font-size:0.8em">📥 Import</button>
                    <input type="file" id="skills-import-input" accept=".json" style="display:none" onchange="webx11.importSkillsUI(event)">
                    <button class="btn" onclick="webx11.syncSkillsToWebdavUI()" style="padding:4px 10px; font-size:0.8em">☁️ Sync</button>
                </div>
                <!-- Skills list with category groups -->
                <div id="skills-list" style="max-height:300px;overflow-y:auto; flex-shrink:0;"></div>
                <!-- Preview (collapsible) -->
                <div id="skill-preview" style="display:none; flex-shrink:0; background:var(--bg-tertiary); border:1px solid var(--border-color); border-radius:4px; padding:10px; overflow-y:auto; white-space:pre-wrap; font-family:var(--font-primary); font-size:0.85em; color:var(--text-color);">
                    <div style="display:flex; justify-content:space-between; margin-bottom:6px;">
                        <span id="skill-preview-title" style="color:var(--success-color); font-weight:bold;"></span>
                        <div style="display:flex; gap:6px;">
                            <button class="btn" id="skill-preview-expand-btn" onclick="webx11.toggleSkillPreviewSize()" style="padding:2px 6px; font-size:0.75em">⛶ Expand</button>
                            <span style="cursor:pointer; color:var(--text-muted); font-size:1.2em;" onclick="webx11.closeSkillPreview()">✕</span>
                        </div>
                    </div>
                    <div id="skill-preview-content"></div>
                </div>
                <!-- Create form -->
                <div style="flex-shrink:0; border-top:1px solid var(--border-color); padding-top:8px;">
                    <h4 style="color: var(--info-color); margin-bottom: 6px;">Create New Skill</h4>
                    <div style="display:flex; gap:6px; flex-wrap:wrap;">
                        <input type="text" id="skill-name-input" class="module-url-input" placeholder="Name (kebab-case)" style="flex:2; min-width:140px;">
                        <input type="text" id="skill-desc-input" class="module-url-input" placeholder="Description" style="flex:3; min-width:180px;">
                        <select id="skill-category-input" class="module-url-input" style="flex:1; min-width:100px;">
                            <option value="general">general</option>
                            <option value="system">system</option>
                            <option value="research">research</option>
                            <option value="dev">dev</option>
                            <option value="productivity">productivity</option>
                            <option value="ui">ui</option>
                            <option value="security">security</option>
                        </select>
                    </div>
                    <div style="display:flex; gap:6px; margin-top:6px;">
                        <input type="text" id="skill-tags-input" class="module-url-input" placeholder="Tags (comma-separated)" style="flex:1;">
                        <button class="btn" onclick="webx11.createSkillFromUI()" style="border-color:var(--success-color);color:var(--success-color); flex-shrink:0;">Create</button>
                    </div>
                    <textarea id="skill-content-input" class="module-url-input" style="margin-top:6px; height:80px; resize:vertical; font-family:var(--font-primary)" placeholder="Markdown content (optional — will use template)"></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn" onclick="webx11.refreshSkillsList()">🔄 Refresh</button>
                <button class="btn" onclick="webx11.closeSkillsManager()">Close</button>
            </div>
        </div>
    </div>

    <!-- Preview Modal -->
    <div id="preview-modal" class="modal-overlay">
        <div class="modal-content" style="max-width: 95%; max-height: 90vh; width: 95%;">
            <div class="modal-header">
                <span id="preview-title">📄 Preview</span>
                <span style="display:flex;gap:10px;align-items:center">
                    <button class="btn btn-sm" onclick="var f=document.getElementById('preview-iframe');if(f&&f.srcdoc){var w=window.open('','_blank');if(w){w.document.open();w.document.write(f.srcdoc);w.document.close();}}" title="Open in new tab">⛶</button>
                    <span style="cursor:pointer" onclick="webx11.closePreview()">✕</span>
                </span>
            </div>
            <div class="modal-body" style="padding:0; overflow:hidden; height:75vh;">
                <iframe id="preview-iframe" style="width:100%; height:100%; border:none; background:var(--bg-color);" sandbox="allow-same-origin allow-scripts"></iframe>
            </div>
            <div class="modal-footer">
                <button class="btn" onclick="webx11.closePreview()">Close</button>
            </div>
        </div>
    </div>

    <!-- Config Manager Modal -->
    <div id="config-manager" class="modal-overlay">
        <div class="modal-content" style="max-width: 550px; max-height: 80vh;">
            <div class="modal-header">
                <span>⚙ Configuration</span>
                <span style="cursor:pointer" onclick="webx11.closeConfigManager()">✕</span>
            </div>
            <div class="modal-body" id="config-manager-body">
                <div id="config-list" style="margin-bottom:16px;"></div>
                <div style="border-top:1px solid var(--border-color); padding-top:12px;">
                    <h4 style="color:var(--info-color); margin-bottom:8px;">Add / Update Config</h4>
                    <div style="display:flex; gap:6px; flex-wrap:wrap;">
                        <input type="text" id="config-key-input" class="module-url-input" placeholder="Key" style="flex:1; min-width:100px;">
                        <input type="text" id="config-value-input" class="module-url-input" placeholder="Value" style="flex:3; min-width:150px;">
                        <button class="btn" onclick="webx11.addConfigFromUI()" style="border-color:var(--success-color);color:var(--success-color); padding:6px 14px;">Add</button>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn" onclick="webx11.exportConfigFromUI()">📤 Export</button>
                <button class="btn btn-danger" onclick="webx11.resetConfigFromUI()">🗑 Reset All</button>
                <button class="btn" onclick="webx11.closeConfigManager()">Close</button>
            </div>
        </div>
    </div>

    <!-- Welcome Tour Modal -->
    <div id="welcome-modal" class="modal-overlay">
        <div class="modal-content" style="max-width:500px;text-align:center;">
            <div class="modal-header">
                <span>🚀 Welcome to newOS4</span>
            </div>
            <div class="modal-body" style="padding:24px;">
                <div style="font-size:3em;margin-bottom:12px;">🖥️</div>
                <h2 style="margin:0 0 8px;color:var(--accent-color);">Let's Get Started</h2>
                <p style="color:var(--text-muted);margin-bottom:16px;line-height:1.6;">
                    newOS4 is a terminal-centric browser OS with AI, filesystem, and modules.
                    Take the <strong>2-minute guided tour</strong> to learn the basics.
                </p>
                <div style="display:flex;gap:12px;justify-content:center;flex-wrap:wrap;">
                    <button class="btn" onclick="var m=document.getElementById('welcome-modal');if(m)m.style.display='none';if(webx11&&webx11.tutorialModule)webx11.tutorialModule.startTutorial()"
                            style="border-color:var(--success-color);color:var(--success-color);padding:12px 28px;font-size:1em;">
                        🎮 Start Tutorial
                    </button>
                    <button class="btn" onclick="var m=document.getElementById('welcome-modal');if(m)m.style.display='none';location.href='course.html'"
                            style="border-color:var(--info-color);color:var(--info-color);padding:12px 28px;font-size:1em;">
                        📚 Full Course
                    </button>
                    <button class="btn" onclick="if(webx11)webx11.dismissWelcome()"
                            style="border-color:var(--text-muted);color:var(--text-muted);padding:12px 28px;font-size:1em;">
                        Skip — I'll explore
                    </button>
                </div>
                <label style="display:flex;align-items:center;justify-content:center;gap:6px;margin-top:14px;font-size:0.78em;color:var(--text-muted);cursor:pointer;">
                    <input type="checkbox" id="welcome-dont-show" onchange="if(this.checked)localStorage.setItem('webx11_welcome_dismissed','1');else localStorage.removeItem('webx11_welcome_dismissed')">
                    Don't show this again
                </label>
                <p style="font-size:0.78em;color:var(--text-muted);margin-top:16px;">
                    Your progress is saved. Type <code>tutorial</code> anytime to resume.
                </p>
            </div>
        </div>
    </div>

    <!-- Startup Modules Modal -->
    <div id="startup-modules" class="modal-overlay">
        <div class="modal-content" style="max-width: 500px;">
            <div class="modal-header">
                <span>⚙ Startup Modules</span>
                <span style="cursor:pointer" onclick="var w=window.webx11;if(w&&typeof w.closeStartupModules==='function')w.closeStartupModules();else document.getElementById('startup-modules').style.display='none'">✕</span>
            </div>
            <div class="modal-body" id="startup-modules-body"></div>
            <div class="modal-footer">
                <button class="btn btn-danger" onclick="webx11.closeStartupModules()">Cancel</button>
                <button class="btn" onclick="webx11.saveStartupModules()" style="border-color:var(--info-color);color:var(--info-color)">Save & Reload</button>
            </div>
        </div>
    </div>

    <!-- Code Editor Modal -->
    <div id="code-editor" class="modal-overlay">
        <div class="modal-content" style="max-width: 90vw; max-height: 90vh; width: 900px; height: 80vh;">
            <div class="modal-header">
                <span id="code-editor-title">📝 Edit Module</span>
                <span style="cursor:pointer" onclick="if(webx11) webx11.closeCodeEditor()">✕</span>
            </div>
            <div class="modal-body" style="padding:0; display:flex; flex-direction:column; height:calc(100% - 100px);">
                <div id="code-editor-info" style="padding:6px 10px; font-size:0.8em; color:var(--text-muted); border-bottom:1px solid var(--border-color); flex-shrink:0; display:flex; justify-content:space-between; align-items:center;">
                    <span id="code-editor-status">Ready</span>
                    <span><button class="btn" style="font-size:0.7em;padding:2px 8px" onclick="window._editorToggleFullscreen()">⤢ Fullscreen</button></span>
                </div>
                <div id="code-editor-wrapper" style="flex:1; display:flex; overflow:hidden; position:relative;">
                    <div id="code-editor-gutter" style="flex-shrink:0; width:40px; background:var(--bg-secondary); color:var(--text-muted); font-family:monospace; font-size:13px; line-height:20px; padding:10px 4px; text-align:right; overflow:hidden; user-select:none; border-right:1px solid var(--border-color);"></div>
                    <textarea id="code-editor-textarea" style="flex:1; border:none; background:var(--bg-tertiary); color:var(--text-color); font-family:monospace; font-size:13px; line-height:20px; padding:10px; resize:none; outline:none; tab-size:2; white-space:pre; overflow:auto; display:block;" spellcheck="false"></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-danger" onclick="if(webx11) webx11.closeCodeEditor()">Cancel</button>
                <button class="btn" onclick="(async()=>{if(webx11)await webx11.saveCodeEditor()})()" style="border-color:var(--info-color);color:var(--info-color)">💾 Save & Test</button>
            </div>
        </div>
    </div>

    <input type="file" id="file-upload-input" style="display:none">


    <!-- Gear splash function — works before webx11 initializes -->
    <script>
    function openStartupModulesSplash(event) {
        event.stopPropagation();
        var w = window.webx11;
        if (w && typeof w.openStartupModules === 'function') {
            w.openStartupModules();
        } else {
            var overlay = document.getElementById('startup-modules');
            if (!overlay) return;
            // Bare-bones render for when webx11 isn't ready yet
            var body = document.getElementById('startup-modules-body');
            if (body && !body.children.length) {
                var mods = [
                    ['Foundation (always loaded)', ['virtual-fs.js','module-manager.js','ollama-manager.js','terminal.js'], true],
                    ['Built-in modules', ['module-system.js','module-fs.js','module-ollama.js','module-my.js','module-searxng.js','module-servermon.js','module-ollamamodels.js','module-config.js','module-simplegui.js','module-io.js','module-dynamicprompts.js','module-aiassist.js','module-aiasm.js','module-smartctx.js','module-duckduckgo.js','module-fetcher.js','module-chatstudio.js'], false],
                    ['Extensions', ['calc.js','voice.js','cron.js','theme.js','wpm.js','mindmap.js','webdav.js','skill-pack-core.js','editor.js','diff.js','alias.js','finder.js','filemgr.js','cryptogzip.js','tutorial.js','busybox.js','floating.js','console.js','kanban.js','course.js'], false]
                ];
                var isSel = function(name) { return true; }; // default: all selected
                mods.forEach(function(section) {
                    var h = document.createElement('div');
                    h.className = 'mod-section-header';
                    h.textContent = section[0];
                    body.appendChild(h);
                    section[1].forEach(function(name) {
                        var card = document.createElement('div');
                        card.className = 'mod-card' + (section[2] ? ' disabled' : '');
                        var label = document.createElement('label');
                        var cb = document.createElement('input');
                        cb.type = 'checkbox';
                        cb.checked = section[2] || isSel(name);
                        cb.disabled = section[2];
                        cb.dataset.name = name;
                        var nameSpan = document.createElement('span');
                        nameSpan.className = 'mod-name';
                        nameSpan.textContent = name;
                        var badgeSpan = document.createElement('span');
                        badgeSpan.className = 'mod-badge' + (section[2] ? ' foundation' : '');
                        badgeSpan.textContent = section[2] ? 'foundation' : 'built-in';
                        label.appendChild(cb);
                        label.appendChild(nameSpan);
                        card.appendChild(label);
                        card.appendChild(badgeSpan);
                        body.appendChild(card);
                    });
                });
            }
            overlay.style.display = 'flex';
        }
    }
    </script>

    <!-- v4.5.63: A2A scratchpad fixes + agent-register arg fix -->
<script src="modules/core/core-bundle.js?v=v4.6.146"></script>

    <!-- Async dependency-ordered module loader now only initializes terminal and loads optional ext modules -->
<script src="modules/core/module-loader.js?v=v4.6.146"></script>

    <!-- Critical ext bundle loads AFTER webx11 exists so registerModule calls work -->
<script src="modules/ext/critical-ext-bundle.js?v=v4.6.146"></script>

<script>
// ═══ ONE TRUE VERSION SOURCE ═══
// Reads from module-loader.js src attribute (single source of truth)
(function(){
    var version = 'v4.0'; // fallback
    var scripts = document.getElementsByTagName('script');
    for (var i = 0; i < scripts.length; i++) {
        var m = scripts[i].src && scripts[i].src.match(/module-loader\.js\?v=([v\d\.]+)/);
        if (m) { version = m[1]; break; }
    }
    window.NEWOS4_VERSION = version;
    var el = document.getElementById('splash-version');
    if (el) el.textContent = version;
    el = document.querySelector('.header-version');
    if (el) el.textContent = version;
    el = document.getElementById('terminal-welcome');
    if (el) el.textContent = 'WebX11 Module System ' + version + ' - Unix-like Terminal';
    document.title = 'WebX11 Module System ' + version;
})();
</script>

<!-- Phase 6: Boot Watchdog — auto-revert if recent commit broke the system -->
<script>
(function() {
    // Wait for modules to load, then check health
    var watchdogTimer = null;
    var watchdogStarted = false;

    function checkBoot() {
        if (watchdogStarted) return;
        watchdogStarted = true;

        // Check if core modules loaded
        if (typeof webx11 === 'undefined' || !webx11.moduleManager) {
            // Critical: webx11 object doesn't exist — system is broken
            handleBootFailure('webx11 object not found');
            return;
        }

        var mm = webx11.moduleManager;
        var loadedModules = Object.keys(mm.modules).length;

        // If less than 50% of expected modules loaded, boot failed
        // Expected: ~19 modules at full load
        if (loadedModules < 10) {
            handleBootFailure('Only ' + loadedModules + ' modules loaded (expected ≥10)');
            return;
        }

        // Boot OK — save current state as last-good
        try {
            var lastGood = {
                version: window.NEWOS4_VERSION || 'unknown',
                moduleCount: loadedModules,
                timestamp: Date.now()
            };
            localStorage.setItem('newos4_last_good_boot', JSON.stringify(lastGood));
        } catch (e) {}
    }

    function handleBootFailure(reason) {
        console.error('[Boot Watchdog] Boot failure detected: ' + reason);

        // Check if there was a recent commit (within last 30 min)
        var commitLog = null;
        try {
            // Check localStorage for recent commit info
            var lastCommit = localStorage.getItem('newos4_last_commit');
            if (lastCommit) {
                var commit = JSON.parse(lastCommit);
                if (commit && commit.timestamp && (Date.now() - commit.timestamp < 1800000)) {
                    console.warn('[Boot Watchdog] Recent commit detected (version ' + commit.version + '), attempting auto-revert...');
                    attemptRevert(commit);
                    return;
                }
            }
        } catch (e) {}

        // No recent commit or no revert info — just alert
        console.error('[Boot Watchdog] No recent commit to revert. System may need manual intervention.');
        var banner = document.createElement('div');
        banner.style.cssText = 'position:fixed;top:0;left:0;right:0;background:#ff4444;color:#fff;padding:10px;font-family:monospace;font-size:12px;z-index:99999;text-align:center;';
        banner.textContent = '⚠️ Boot Watchdog: System failed to load (' + reason + '). Try hard refresh or clear localStorage.';
        document.body.insertBefore(banner, document.body.firstChild);
    }

    function attemptRevert(commit) {
        // Try to restore the previous version by setting the version back
        if (commit.previousVersion) {
            console.warn('[Boot Watchdog] Reverting to version ' + commit.previousVersion);
            // Replace all ?v= in script tags with previous version
            var scripts = document.getElementsByTagName('script');
            var reverted = 0;
            for (var i = 0; i < scripts.length; i++) {
                var src = scripts[i].src || '';
                if (src.indexOf('?v=') !== -1) {
                    scripts[i].src = src.replace(/\?v=[^&"']*/, '?v=' + commit.previousVersion);
                    reverted++;
                }
            }
            console.log('[Boot Watchdog] Reverted ' + reverted + ' script tags to ' + commit.previousVersion);

            // Show warning banner
            var banner = document.createElement('div');
            banner.style.cssText = 'position:fixed;top:0;left:0;right:0;background:#ffaa00;color:#000;padding:10px;font-family:monospace;font-size:12px;z-index:99999;text-align:center;';
            banner.textContent = '⚠️ Boot Watchdog: Auto-reverted from ' + commit.version + ' to ' + commit.previousVersion + '. Refresh page to load reverted version.';
            document.body.insertBefore(banner, document.body.firstChild);

            // Force reload after 3 seconds
            setTimeout(function() {
                // Update URL with previous version to force cache bypass
                window.location.href = window.location.pathname + '?v=' + commit.previousVersion + '&watchdog=1';
            }, 3000);
        } else {
            console.error('[Boot Watchdog] No previous version stored. Manual intervention required.');
        }
    }

    // Start watchdog after a delay to allow modules to load
    watchdogTimer = setTimeout(checkBoot, 8000);
})();
</script>

</body>
</html>