Spaces:
Running

File size: 62,445 Bytes
279e484
a7a317a
279e484
 
 
a7a317a
279e484
 
 
 
 
 
 
a7a317a
 
040d06f
26b1d01
4faedf7
040d06f
1e59324
279e484
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
040d06f
279e484
270a88a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
040d06f
 
 
 
 
270a88a
2328089
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0e6ea9e
 
 
 
 
 
 
 
4faedf7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
040d06f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279e484
 
 
040d06f
279e484
 
 
a7a317a
040d06f
279e484
 
 
26b1d01
a7a317a
 
26b1d01
a7a317a
270a88a
 
 
26b1d01
a7a317a
26b1d01
a7a317a
279e484
a7a317a
26b1d01
a7a317a
26b1d01
a7a317a
26b1d01
a7a317a
279e484
 
 
26b1d01
 
 
 
 
a7a317a
26b1d01
 
a7a317a
 
 
 
 
 
040d06f
26b1d01
270a88a
 
26b1d01
a7a317a
26b1d01
a7a317a
 
 
26b1d01
279e484
 
26b1d01
a7a317a
 
26b1d01
 
a7a317a
26b1d01
279e484
 
 
 
fd482f0
 
 
040d06f
a7a317a
fd482f0
 
 
a7a317a
 
 
fd482f0
 
 
a7a317a
 
fd482f0
 
 
 
a7a317a
fd482f0
 
 
a7a317a
fd482f0
 
 
a7a317a
fd482f0
 
4faedf7
a7a317a
4faedf7
 
 
a7a317a
4faedf7
 
a7a317a
 
 
 
fd482f0
 
a7a317a
2328089
a7a317a
2328089
a7a317a
2328089
 
a7a317a
2328089
 
 
a7a317a
2328089
 
a7a317a
2328089
a7a317a
2328089
a7a317a
2328089
a7a317a
 
 
 
 
 
2328089
 
 
a7a317a
2328089
a7a317a
 
 
 
0e6ea9e
a7a317a
 
 
 
 
 
 
 
2328089
 
 
a7a317a
4faedf7
a7a317a
4faedf7
a7a317a
4faedf7
a7a317a
 
 
4faedf7
a7a317a
4faedf7
a7a317a
4faedf7
 
 
a7a317a
4faedf7
 
a7a317a
4faedf7
 
 
a7a317a
4faedf7
a7a317a
 
 
4faedf7
 
a7a317a
 
4faedf7
 
 
 
 
 
 
 
a7a317a
4faedf7
a7a317a
 
4faedf7
 
 
 
a7a317a
4faedf7
 
 
 
 
 
 
a7a317a
 
4faedf7
 
 
 
a7a317a
 
4faedf7
 
 
 
 
 
 
 
 
a7a317a
4faedf7
a7a317a
4faedf7
 
a7a317a
4faedf7
 
 
a7a317a
4faedf7
 
 
a7a317a
4faedf7
 
 
a7a317a
4faedf7
 
 
 
 
a7a317a
4faedf7
a7a317a
 
 
 
 
 
 
4faedf7
 
 
 
2328089
fd482f0
a7a317a
fd482f0
a7a317a
1e59324
fd482f0
 
 
 
 
 
 
 
a7a317a
fd482f0
 
a7a317a
fd482f0
 
 
 
a7a317a
fd482f0
 
 
 
 
 
a7a317a
fd482f0
 
 
 
a7a317a
fd482f0
a7a317a
4faedf7
a7a317a
040d06f
fd482f0
 
a7a317a
fd482f0
a7a317a
fd482f0
 
 
a7a317a
fd482f0
 
 
 
 
 
 
 
 
a7a317a
fd482f0
 
 
 
 
 
 
 
 
a7a317a
fd482f0
 
 
 
 
 
 
 
 
a7a317a
fd482f0
 
a7a317a
fd482f0
a7a317a
fd482f0
 
2328089
a7a317a
2328089
a7a317a
2328089
 
 
 
 
 
 
 
a7a317a
2328089
a7a317a
2328089
 
a7a317a
2328089
a7a317a
2328089
 
4faedf7
a7a317a
4faedf7
a7a317a
4faedf7
 
a7a317a
4faedf7
a7a317a
4faedf7
 
 
 
a7a317a
4faedf7
 
 
 
 
 
 
2328089
 
a7a317a
2328089
 
4faedf7
a7a317a
 
4faedf7
a7a317a
 
 
4faedf7
 
a7a317a
2328089
 
a7a317a
2328089
 
 
 
 
 
4faedf7
 
 
 
 
 
 
fd482f0
 
 
 
a7a317a
fd482f0
 
a7a317a
fd482f0
a7a317a
040d06f
2328089
fd482f0
 
 
 
 
 
040d06f
fd482f0
a7a317a
 
 
fd482f0
 
 
 
 
 
a7a317a
fd482f0
 
 
 
a7a317a
fd482f0
 
 
a7a317a
fd482f0
4faedf7
 
a7a317a
4faedf7
040d06f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e59324
040d06f
 
 
1e59324
040d06f
 
 
1e59324
040d06f
 
 
 
 
 
 
 
 
 
1e59324
040d06f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e59324
040d06f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e59324
040d06f
 
1e59324
040d06f
 
 
 
 
 
 
 
 
 
 
1e59324
 
 
040d06f
 
 
1e59324
040d06f
 
 
 
 
1e59324
 
 
 
040d06f
 
 
 
 
1e59324
 
040d06f
 
 
 
 
 
1e59324
040d06f
 
1e59324
040d06f
 
 
 
 
 
 
 
 
 
 
 
1e59324
 
 
 
 
 
 
040d06f
 
1e59324
 
 
 
 
 
 
 
 
040d06f
1e59324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
040d06f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e59324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
040d06f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e59324
 
040d06f
 
1e59324
 
 
040d06f
 
 
 
 
 
 
 
 
 
 
 
1e59324
 
040d06f
 
1e59324
040d06f
 
 
 
 
 
 
 
1e59324
 
040d06f
 
1e59324
040d06f
1e59324
040d06f
 
 
 
 
 
 
 
 
 
 
 
 
 
1e59324
 
040d06f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e59324
040d06f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279e484
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>FlexiscanPro - Professional Scanner Control</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#005293',
                        primarylight: '#e6f0f8',
                        primarydark: '#003a6d',
                        firewire: '#FF4500',
                        thunderbolt: '#0071C5',
                        usb: '#00a651',
                        network: '#8e44ad'
                    }
                }
            }
        }
    </script>
    <style>
        @keyframes scannerActive {
            0% { opacity: 0.5; }
            50% { opacity: 1; }
            100% { opacity: 0.5; }
        }
        
        .scanner-active {
            animation: scannerActive 1.5s infinite;
        }
        
        .preview-container {
            background-image: linear-gradient(45deg, #eee 25%, transparent 25%), 
                              linear-gradient(-45deg, #eee 25%, transparent 25%), 
                              linear-gradient(45deg, transparent 75%, #eee 75%), 
                              linear-gradient(-45deg, transparent 75%, #eee 75%);
            background-size: 20px 20px;
            background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
            position: relative;
        }
        
        input[type="range"] {
            -webkit-appearance: none;
            width: 100%;
            height: 8px;
            border-radius: 4px;
            background: #e5e7eb;
            outline: none;
        }
        
        input[type="range"]::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 18px;
            height: 18px;
            border-radius: 50%;
            background: #005293;
            cursor: pointer;
            transition: transform 0.1s;
        }

        input[type="range"]::-webkit-slider-thumb:active {
            transform: scale(1.2);
        }

        .tooltip {
            display: none;
            position: absolute;
            z-index: 10;
            background-color: black;
            color: white;
            font-size: 0.75rem;
            padding: 0.25rem 0.5rem;
            border-radius: 0.25rem;
            transform: translateX(-50%);
            left: 50%;
            bottom: 100%;
            margin-bottom: 0.5rem;
            white-space: nowrap;
        }

        .tooltip-container:hover .tooltip {
            display: block;
        }

        .film-option {
            transition: all 0.2s;
        }
        
        .film-option:hover {
            background-color: #f0f0f0;
        }

        .expert-border {
            border: 2px dashed #4a5568;
        }

        .expert-only {
            display: none;
        }

        .expert-mode .expert-only {
            display: block;
        }

        .expert-setting {
            background-color: #f8fafc;
            border-left: 3px solid #4a5568;
            transition: background-color 0.2s;
        }

        .expert-setting:hover {
            background-color: #edf2f7;
        }

        /* Interface color indicators */
        .interface-indicator {
            display: inline-block;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            margin-right: 5px;
        }

        .interface-thunderbolt {
            background-color: #0071C5;
        }

        .interface-firewire {
            background-color: #FF4500;
        }

        .interface-usb {
            background-color: #00a651;
        }

        .interface-network {
            background-color: #8e44ad;
        }
    </style>
</head>
<body class="bg-gray-100">
    <div class="container mx-auto px-4 py-6 max-w-7xl" id="appContainer">
        <!-- Header -->
        <header class="flex justify-between items-center mb-8">
            <div class="flex items-center">
                <h1 class="text-2xl font-bold text-primary">FlexiscanPro</h1>
                <span id="liveIndicator" class="ml-2 text-xs bg-primary text-white px-2 py-1 rounded">LIVE MODE</span>
            </div>
            <div class="flex items-center space-x-4">
                <div id="connectionStatus" class="flex items-center">
                    <div class="relative group">
                        <span id="connectionIndicator" class="h-3 w-3 rounded-full bg-gray-500 mr-2"></span>
                        <span id="connectionText" class="text-sm">Searching devices...</span>
                        <div class="absolute z-10 hidden group-hover:block bg-white p-2 rounded shadow-lg text-xs w-64">
                            <span id="connectionTooltip">Scanning for available devices</span>
                        </div>
                    </div>
                </div>
                <div class="flex space-x-2">
                    <button id="refreshDevicesBtn" class="text-primary hover:text-primary/80 tooltip-container">
                        <i class="fas fa-sync-alt text-xl"></i>
                        <span class="tooltip">Rescan devices</span>
                    </button>
                    <button id="connectionMethodBtn" class="text-primary hover:text-primary/80 tooltip-container">
                        <i class="fas fa-plug text-xl"></i>
                        <span class="tooltip">Connection method</span>
                    </button>
                    <button id="infoBtn" class="text-primary hover:text-primary/80 tooltip-container">
                        <i class="fas fa-info-circle text-xl"></i>
                        <span class="tooltip">Information</span>
                    </button>
                </div>
            </div>
        </header>

        <!-- Connection Method Modal -->
        <div id="connectionMethodModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
            <div class="bg-white rounded-lg p-6 max-w-lg w-full">
                <h3 class="text-xl font-bold text-primary mb-4">Connection Settings</h3>
                
                <div class="mb-4">
                    <h4 class="font-medium mb-2">Default Interface</h4>
                    <select id="connectionPriority" class="w-full p-2 border rounded focus:ring-2 focus:ring-primary/50 focus:border-primary">
                        <option value="any">Automatic detection (recommended)</option>
                        <option value="thunderbolt">Thunderbolt (if available)</option>
                        <option value="firewire">Firewire (if available)</option>
                        <option value="usb">USB (if available)</option>
                        <option value="network">Network (if available)</option>
                    </select>
                </div>
                
                <div class="bg-yellow-50 p-3 rounded border border-yellow-200 mb-4">
                    <h4 class="font-medium text-yellow-800 mb-1"><i class="fas fa-exclamation-triangle mr-1"></i> Firewire/Thunderbolt Requirements</h4>
                    <ul class="text-xs text-yellow-700 list-disc pl-5">
                        <li>Firewire: 1394 drivers must be installed</li>
                        <li>Thunderbolt: System must support Thunderbolt devices</li>
                        <li>Third-party software like IIDC driver may be required</li>
                    </ul>
                </div>
                
                <div class="flex justify-between">
                    <button id="saveConnectionPrefBtn" class="px-4 py-2 bg-primary text-white rounded hover:bg-primary/90">
                        Save Settings
                    </button>
                    <button id="closeConnectionModalBtn" class="px-4 py-2 bg-gray-200 text-gray-700 rounded hover:bg-gray-300">
                        Cancel
                    </button>
                </div>
            </div>
        </div>

        <!-- Main Content -->
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
            <!-- Scanner Control Panel -->
            <div id="scannerPanel" class="scanner-panel lg:col-span-1 bg-white rounded-lg shadow p-6 expert-border">
                <h2 class="text-lg font-semibold text-gray-800 mb-4">Scanner Control</h2>
                
                <div class="space-y-4">
                    <div>
                        <label for="scannerSelect" class="block text-sm font-medium text-gray-700 mb-1">Available Scanners</label>
                        <select id="scannerSelect" class="w-full p-2 border rounded focus:ring-2 focus:ring-primary/50 focus:border-primary">
                            <option value="">Select scanner...</option>
                        </select>
                    </div>
                    
                    <button id="connectBtn" class="w-full bg-primary text-white py-2 px-4 rounded hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed">
                        Connect
                    </button>
                    
                    <div id="scannerDetails" class="hidden mt-4 border-t pt-4 space-y-2 text-sm">
                        <div class="flex justify-between">
                            <span class="text-gray-600">Model:</span>
                            <span id="scannerModel" class="font-medium">-</span>
                        </div>
                        <div class="flex justify-between">
                            <span class="text-gray-600">Vendor:</span>
                            <span id="scannerVendor" class="font-medium">-</span>
                        </div>
                        <div class="flex justify-between">
                            <span class="text-gray-600">Type:</span>
                            <span id="scannerType" class="font-medium">-</span>
                        </div>
                        <div class="flex justify-between">
                            <span class="text-gray-600">Max Resolution:</span>
                            <span id="scannerResolution" class="font-medium">-</span>
                        </div>
                        <div class="flex justify-between">
                            <span class="text-gray-600">Dynamic Range:</span>
                            <span id="scannerDynamicRange" class="font-medium">-</span>
                        </div>
                        <div class="flex justify-between">
                            <span class="text-gray-600">Interface:</span>
                            <span id="scannerInterface" class="font-medium">-</span>
                        </div>
                    </div>
                    
                    <!-- Operation mode section -->
                    <div class="mt-4 border-t pt-4">
                        <h3 class="text-sm font-medium text-gray-700 mb-2">Operation Mode</h3>
                        <div class="grid grid-cols-2 gap-2">
                            <button id="standardModeBtn" class="text-sm py-1 px-3 bg-gray-200 text-gray-700 rounded hover:bg-gray-300 transition">
                                Standard
                            </button>
                            <button id="expertModeBtn" class="text-sm py-1 px-3 bg-primary text-white rounded hover:bg-primary/90 transition">
                                Expert
                            </button>
                        </div>
                        <p id="modeDescription" class="text-xs text-gray-500 mt-1">Expert mode with full control over all settings</p>
                    </div>
                    
                    <!-- Scan settings section -->
                    <div id="scanSettings" class="mt-4 border-t pt-4 space-y-2">
                        <h3 class="text-sm font-medium text-gray-700 mb-2">Scan Parameters</h3>
                        
                        <!-- Transparency mode -->
                        <div>
                            <label for="transparencyMode" class="block text-xs font-medium text-gray-600 mb-1">Transparency Mode</label>
                            <select id="transparencyMode" class="w-full p-1 text-sm border rounded focus:ring-1 focus:ring-primary/50 focus:border-primary">
                                <option value="auto">Automatic</option>
                                <option value="film">Film</option>
                                <option value="slide">Slide</option>
                                <option value="negative">Negative</option>
                            </select>
                        </div>
                        
                        <!-- Film simulation -->
                        <div>
                            <label for="filmSimulation" class="block text-xs font-medium text-gray-600 mb-1">Film Simulation</label>
                            <select id="filmSimulation" class="w-full p-1 text-sm border rounded focus:ring-1 focus:ring-primary/50 focus:border-primary">
                                <option value="none">None</option>
                                <option value="velvia" class="film-option">Fuji Velvia 50 (saturated colors)</option>
                                <option value="provia" class="film-option">Fuji Provia 100F (neutral)</option>
                                <option value="astia" class="film-option">Fuji Astia 100F (soft skin tones)</option>
                                <option value="ektar" class="film-option">Kodak Ektar 100 (vivid colors)</option>
                                <option value="portra160" class="film-option">Kodak Portra 160 (portrait)</option>
                                <option value="portra400" class="film-option">Kodak Portra 400 (universal)</option>
                                <option value="portra800" class="film-option">Kodak Portra 800 (low light)</option>
                                <option value="tri-x" class="film-option">Kodak Tri-X 400 (B&W, grainy)</option>
                                <option value="tmax400" class="film-option">Kodak T-Max 400 (B&W, fine grain)</option>
                                <option value="hp5" class="film-option">Ilford HP5 Plus 400 (B&W, classic)</option>
                            </select>
                        </div>
                        
                        <!-- Expert settings -->
                        <div id="expertSettings" class="expert-only space-y-2 mt-3 pt-3 border-t border-dashed border-gray-200">
                            <h4 class="text-xs font-medium text-gray-700 mb-1">Expert Settings</h4>
                            
                            <!-- Resolution -->
                            <div class="expert-setting p-2 rounded">
                                <label for="resolutionSelect" class="block text-xs font-medium text-gray-600 mb-1">Scan Resolution (dpi)</label>
                                <select id="resolutionSelect" class="w-full p-1 text-sm border rounded focus:ring-1 focus:ring-primary/50 focus:border-primary">
                                    <option value="800">800 dpi (Preview)</option>
                                    <option value="1600">1600 dpi (Standard)</option>
                                    <option value="3200" selected>3200 dpi (High Quality)</option>
                                    <option value="4800">4800 dpi (Premium)</option>
                                    <option value="6400">6400 dpi (Maximum Resolution)</option>
                                </select>
                            </div>
                            
                            <!-- Output size -->
                            <div class="expert-setting p-2 rounded">
                                <label for="outputSize" class="block text-xs font-medium text-gray-600 mb-1">
                                    Output Size 
                                    <span id="outputSizeLabel" class="text-xs text-gray-400">(Original)</span>
                                </label>
                                <div class="flex items-center space-x-2">
                                    <select id="outputSizeMode" class="w-1/2 p-1 text-sm border rounded focus:ring-1 focus:ring-primary/50 focus:border-primary">
                                        <option value="original">Original</option>
                                        <option value="percentage">Percentage</option>
                                        <option value="fixed-width">Fixed Width</option>
                                        <option value="fixed-height">Fixed Height</option>
                                    </select>
                                    <input id="outputSizeValue" type="number" min="1" max="5000" value="100" 
                                        class="w-1/2 p-1 text-sm border rounded focus:ring-1 focus:ring-primary/50 focus:border-primary" disabled>
                                    <select id="outputSizeUnit" class="w-1/4 p-1 text-sm border rounded focus:ring-1 focus:ring-primary/50 focus:border-primary hidden">
                                        <option value="percent">%</option>
                                        <option value="pixels">px</option>
                                        <option value="cm">cm</option>
                                        <option value="inches">inch</option>
                                    </select>
                                </div>
                            </div>
                            
                            <!-- Color space -->
                            <div class="expert-setting p-2 rounded">
                                <label for="colorspaceSelect" class="block text-xs font-medium text-gray-600 mb-1">Color Space</label>
                                <select id="colorspaceSelect" class="w-full p-1 text-sm border rounded focus:ring-1 focus:ring-primary/50 focus:border-primary">
                                    <option value="srgb">sRGB (Standard)</option>
                                    <option value="adobe-rgb">Adobe RGB (1998)</option>
                                    <option value="prophoto">ProPhoto RGB</option>
                                    <option value="eci-rgb-v2">ECI-RGB v2</option>
                                    <option value="grayscale">16-Bit Grayscale</option>
                                </select>
                            </div>
                            
                            <!-- Multipass Scanning -->
                            <div class="expert-setting p-2 rounded">
                                <label class="block text-xs font-medium text-gray-600 mb-1">Multipass Scanning</label>
                                <div class="flex items-center">
                                    <input type="checkbox" id="multipassCheck" class="mr-2 rounded border-gray-300 text-primary focus:ring-primary">
                                    <label for="multipassCheck" class="text-xs">Multiple scans for noise reduction</label>
                                </div>
                                
                                <div id="multipassControls" class="mt-1 hidden ml-6">
                                    <div class="flex items-center space-x-2">
                                        <label for="multipassCount" class="text-xs text-gray-600">Passes:</label>
                                        <select id="multipassCount" class="p-1 text-xs border rounded focus:ring-1 focus:ring-primary/50 focus:border-primary">
                                            <option value="2">2x</option>
                                            <option value="4">4x</option>
                                            <option value="8">8x</option>
                                            <option value="16">16x</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Advanced ROI settings -->
                            <div class="expert-setting p-2 rounded">
                                <label class="block text-xs font-medium text-gray-600 mb-1">Scan Area (ROI)</label>
                                <div class="grid grid-cols-2 gap-2">
                                    <div>
                                        <label for="roiX" class="block text-2xs text-gray-500 mb-1">X Position</label>
                                        <input type="number" id="roiX" min="0" max="100" value="0" class="w-full p-1 text-sm border rounded">
                                    </div>
                                    <div>
                                        <label for="roiY" class="block text-2xs text-gray-500 mb-1">Y Position</label>
                                        <input type="number" id="roiY" min="0" max="100" value="0" class="w-full p-1 text-sm border rounded">
                                    </div>
                                    <div>
                                        <label for="roiWidth" class="block text-2xs text-gray-500 mb-1">Width</label>
                                        <input type="number" id="roiWidth" min="1" max="100" value="100" class="w-full p-1 text-sm border rounded">
                                    </div>
                                    <div>
                                        <label for="roiHeight" class="block text-2xs text-gray-500 mb-1">Height</label>
                                        <input type="number" id="roiHeight" min="1" max="100" value="100" class="w-full p-1 text-sm border rounded">
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Dark current compensation -->
                            <div class="expert-setting p-2 rounded">
                                <label for="darkCurrentComp" class="block text-xs font-medium text-gray-600 mb-1">Dark Current Compensation</label>
                                <select id="darkCurrentComp" class="w-full p-1 text-sm border rounded focus:ring-1 focus:ring-primary/50 focus:border-primary">
                                    <option value="auto">Automatic</option>
                                    <option value="low">Low</option>
                                    <option value="medium">Medium</option>
                                    <option value="high">High</option>
                                    <option value="none">None</option>
                                </select>
                            </div>
                        </div>
                        
                        <div class="mt-4 flex space-x-2">
                            <button id="previewBtn" class="w-1/2 bg-gray-200 text-gray-800 py-2 px-4 rounded hover:bg-gray-300 disabled:opacity-50 disabled:cursor-not-allowed">
                                <i class="fas fa-eye mr-1"></i> Preview
                            </button>
                            <button id="scanBtn" class="w-1/2 bg-primary text-white py-2 px-4 rounded hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed">
                                <i class="fas fa-sscan mr-1"></i> Scan
                            </button>
                        </div>
                    </div>
                    
                    <div class="relative mt-2 h-4">
                        <div id="scannerLight" class="absolute left-0 top-0 h-4 w-4 rounded-full bg-red-600 opacity-0"></div>
                    </div>
                    
                    <!-- Progress bar -->
                    <div id="progressContainer" class="hidden mt-2">
                        <div class="w-full bg-gray-200 rounded-full h-2.5">
                            <div id="progressBar" class="bg-primary h-2.5 rounded-full" style="width: 0%"></div>
                        </div>
                        <div id="progressPercent" class="text-right text-xs mt-1 text-gray-600">0%</div>
                    </div>
                    
                    <div id="statusMessage" class="text-sm text-gray-600 mt-2 italic">Searching for available scanners...</div>
                </div>
            </div>
            
            <!-- Image Preview -->
            <div class="lg:col-span-2 bg-white rounded-lg shadow overflow-hidden">
                <div class="p-4 border-b">
                    <h2 class="text-lg font-semibold text-gray-800">Preview & Results</h2>
                </div>
                <div id="previewContainer" class="preview-container h-96 flex items-center justify-center">
                    <div id="placeholderText" class="text-center p-6 text-gray-500">
                        <i class="fas fa-image text-4xl mb-2 opacity-50"></i>
                        <p class="text-sm">No image available.<br>Click "Preview" or "Scan" to start.</p>
                    </div>
                    <img id="previewImage" src="" alt="Scan Result" class="hidden max-w-full max-h-full object-contain">
                    
                    <!-- ROI Rectangle for Expert Mode -->
                    <div id="roiRectangle" class="absolute border-2 border-yellow-400 pointer-events-none hidden" style="background-color: rgba(255, 255, 0, 0.2);"></div>
                </div>
                
                <!-- Advanced image settings -->
                <div class="p-4 border-t">
                    <h3 class="text-md font-medium text-gray-800 mb-3">Image Settings</h3>
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Brightness</label>
                            <input type="range" min="0" max="200" value="100" class="slider" id="brightnessSlider">
                            <div class="flex justify-between text-xs text-gray-500 mt-1">
                                <span>-</span>
                                <span id="brightnessValue">100</span>
                                <span>+</span>
                            </div>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Contrast</label>
                            <input type="range" min="0" max="200" value="100" class="slider" id="contrastSlider">
                            <div class="flex justify-between text-xs text-gray-500 mt-1">
                                <span>-</span>
                                <span id="contrastValue">100</span>
                                <span>+</span>
                            </div>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Sharpness</label>
                            <input type="range" min="0" max="100" value="50" class="slider" id="sharpnessSlider">
                            <div class="flex justify-between text-xs text-gray-500 mt-1">
                                <span>0</span>
                                <span id="sharpnessValue">50</span>
                                <span>100</span>
                            </div>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Color Balance</label>
                            <input type="range" min="-20" max="20" value="0" class="slider" id="colorBalanceSlider">
                            <div class="flex justify-between text-xs text-gray-500 mt-1">
                                <span>Cooler</span>
                                <span id="colorBalanceValue">0</span>
                                <span>Warmer</span>
                            </div>
                        </div>
                        
                        <!-- Saturation slider -->
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Saturation</label>
                            <input type="range" min="-100" max="100" value="0" class="slider" id="saturationSlider">
                            <div class="flex justify-between text-xs text-gray-500 mt-1">
                                <span>-100%</span>
                                <span id="saturationValue">0</span>
                                <span>+100%</span>
                            </div>
                        </div>
                        
                        <!-- Gradation correction -->
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-1">Gradation Correction</label>
                            <input type="range" min="0" max="100" value="0" class="slider" id="gradationSlider">
                            <div class="flex justify-between text-xs text-gray-500 mt-1">
                                <span>Soft</span>
                                <span id="gradationValue">0</span>
                                <span>Hard</span>
                            </div>
                        </div>
                        
                        <!-- Expert image settings -->
                        <div class="expert-only">
                            <label class="block text-sm font-medium text-gray-700 mb-1">Density Matching</label>
                            <input type="range" min="0" max="100" value="50" class="slider" id="densitySlider">
                            <div class="flex justify-between text-xs text-gray-500 mt-1">
                                <span>Flat</span>
                                <span id="densityValue">50</span>
                                <span>Contrasty</span>
                            </div>
                        </div>
                        
                        <div class="expert-only">
                            <label class="block text-sm font-medium text-gray-700 mb-1">Shadow Correction</label>
                            <input type="range" min="0" max="100" value="0" class="slider" id="shadowSlider">
                            <div class="flex justify-between text-xs text-gray-500 mt-1">
                                <span>0%</span>
                                <span id="shadowValue">0</span>
                                <span>100%</span>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Histogram display with advanced features -->
                    <div class="mt-4 bg-gray-50 p-2 rounded border border-gray-200">
                        <div class="flex justify-between items-center mb-1">
                            <div class="flex items-center space-x-2">
                                <span class="text-xs font-medium text-gray-700">Histogram</span>
                                <select id="histogramChannel" class="expert-only text-xs border rounded p-1" title="Histogram Channel">
                                    <option value="rgb">RGB</option>
                                    <option value="red">Red</option>
                                    <option value="green">Green</option>
                                    <option value="blue">Blue</option>
                                </select>
                            </div>
                            <span class="text-xs text-gray-500" id="histogramInfo">RGB Distribution</span>
                        </div>
                        <div class="h-16 w-full bg-gray-200 rounded" id="histogramContainer">
                            <!-- Here the histogram would be rendered in a real app -->
                            <div class="h-full flex items-end">
                                <div class="h-1/4 w-full bg-red-500 opacity-30"></div>
                                <div class="h-1/2 w-full bg-green-500 opacity-30 ml-1"></div>
                                <div class="h-3/4 w-full bg-blue-500 opacity-30 ml-1"></div>
                            </div>
                        </div>
                        <div class="expert-only flex justify-between mt-1">
                            <span class="text-2xs text-gray-500">0</span>
                            <span class="text-2xs text-gray-500">64</span>
                            <span class="text-2xs text-gray-500">128</span>
                            <span class="text-2xs text-gray-500">192</span>
                            <span class="text-2xs text-gray-500">255</span>
                        </div>
                    </div>
                    
                    <div class="flex justify-between mt-4">
                        <button id="saveImageBtn" class="px-4 py-2 bg-gray-200 text-gray-800 rounded hover:bg-gray-300 disabled:opacity-50 disabled:cursor-not-allowed">
                            <i class="fas fa-save mr-1"></i> Save
                        </button>
                        <button id="resetSettingsBtn" class="px-4 py-2 bg-gray-200 text-gray-800 rounded hover:bg-gray-300">
                            <i class="fas fa-undo mr-1"></i> Reset
                        </button>
                        <button id="hardwareStatusBtn" class="px-4 py-2 bg-green-200 text-green-800 rounded hover:bg-green-300">
                            <i class="fas fa-plug mr-1"></i> <span id="hardwareStatusText">Live Mode</span>
                        </button>
                    </div>
                </div>
            </div>
            
            <!-- Scan Information -->
            <div class="lg:col-span-3 bg-white rounded-lg shadow p-6">
                <h2 class="text-lg font-semibold text-gray-800 mb-2">Scanner Hub</h2>
                <div id="scanInfo" class="text-sm text-gray-600">
                    <p class="mb-2">Searching for compatible devices...</p>
                    <p id="connectionInfo" class="hidden text-xs bg-primarylight p-2 rounded border border-primary/30">
                        <i class="fas fa-info-circle text-primary mr-1"></i> <span id="connectionTypeInfo"></span>
                    </p>
                </div>
                
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mt-4">
                    <div class="bg-gray-50 p-3 rounded border border-gray-200">
                        <h3 class="text-sm font-medium text-gray-700 mb-1 flex items-center">
                            <i class="fas fa-bolt text-thunderbolt mr-1"></i> Thunderbolt Help
                        </h3>
                        <ul class="text-xs text-gray-600 space-y-1">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mr-1 mt-0.5"></i>
                                <span>Install latest Thunderbolt drivers</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mr-1 mt-0.5"></i>
                                <span>System must support Thunderbolt devices</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mr-1 mt-0.5"></i>
                                <span>For best performance connect directly</span>
                            </li>
                        </ul>
                    </div>
                    
                    <div class="bg-gray-50 p-3 rounded border border-gray-200">
                        <h3 class="text-sm font-medium text-gray-700 mb-1 flex items-center">
                            <i class="fas fa-fire-alt text-firewire mr-1"></i> Firewire Help
                        </h3>
                        <ul class="text-xs text-gray-600 space-y-1">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mr-1 mt-0.5"></i>
                                <span>1394 drivers must be installed</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mr-1 mt-0.5"></i>
                                <span>Older Macs may need Legacy Drivers</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mr-1 mt-0.5"></i>
                                <span>Chain no more than 4 devices</span>
                            </li>
                        </ul>
                    </div>
                    
                    <div class="bg-gray-50 p-3 rounded border border-gray-200">
                        <h3 class="text-sm font-medium text-gray-700 mb-1 flex items-center">
                            <i class="fas fa-usb text-usb mr-1"></i> USB Help
                        </h3>
                        <ul class="text-xs text-gray-600 space-y-1">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mr-1 mt=0.5"></i>
                                <span>Install vendor-specific USB drivers</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mr-1 mt=0.5"></i>
                                <span>Use USB 3.0+ for high resolution</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mr-1 mt=0.5"></i>
                                <span>Avoid USB hubs for stability</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // Scanner detection implementation for Live Mode

        // DOM elements
        const scannerSelect = document.getElementById('scannerSelect');
        const connectBtn = document.getElementById('connectBtn');
        const previewBtn = document.getElementById('previewBtn');
        const scanBtn = document.getElementById('scanBtn');
        const scannerDetails = document.getElementById('scannerDetails');
        const previewImage = document.getElementById('previewImage');
        const placeholderText = document.getElementById('placeholderText');
        const connectionIndicator = document.getElementById('connectionIndicator');
        const connectionText = document.getElementById('connectionText');
        const connectionTooltip = document.getElementById('connectionTooltip');
        const refreshDevicesBtn = document.getElementById('refreshDevicesBtn');
        const liveIndicator = document.getElementById('liveIndicator');
        const hardwareStatusBtn = document.getElementById('hardwareStatusBtn');
        const hardwareStatusText = document.getElementById('hardwareStatusText');
        const connectionMethodBtn = document.getElementById('connectionMethodBtn');
        const connectionMethodModal = document.getElementById('connectionMethodModal');
        const closeConnectionModalBtn = document.getElementById('closeConnectionModalBtn');
        const saveConnectionPrefBtn = document.getElementById('saveConnectionPrefBtn');
        const connectionPriority = document.getElementById('connectionPriority');
        const standardModeBtn = document.getElementById('standardModeBtn');
        const expertModeBtn = document.getElementById('expertModeBtn');
        const scannerPanel = document.getElementById('scannerPanel');
        const scannerLight = document.getElementById('scannerLight');
        const progressContainer = document.getElementById('progressContainer');
        const progressBar = document.getElementById('progressBar');
        const progressPercent = document.getElementById('progressPercent');
        const saveImageBtn = document.getElementById('saveImageBtn');
        const resetSettingsBtn = document.getElementById('resetSettingsBtn');
        const statusMessage = document.getElementById('statusMessage');
        const multipassCheck = document.getElementById('multipassCheck');
        const multipassControls = document.getElementById('multipassControls');
        const connectionInfo = document.getElementById('connectionInfo');
        const connectionTypeInfo = document.getElementById('connectionTypeInfo');
        const scannerModel = document.getElementById('scannerModel');
        const scannerVendor = document.getElementById('scannerVendor');
        const scannerType = document.getElementById('scannerType');
        const scannerResolution = document.getElementById('scannerResolution');
        const scannerDynamicRange = document.getElementById('scannerDynamicRange');
        const scannerInterface = document.getElementById('scannerInterface');

        // State variables
        let isConnected = false;
        let isExpertMode = false;
        let currentScanner = null;
        let connectionMethod = 'auto';
        let scanningProgress = 0;
        let timer = null;

        // DOM Content Loaded
        document.addEventListener('DOMContentLoaded', function() {
            initializeApp();
        });

        function initializeApp() {
            // Event listeners
            connectBtn.addEventListener('click', toggleScannerConnection);
            previewBtn.addEventListener('click', startPreview);
            scanBtn.addEventListener('click', startScan);
            refreshDevicesBtn.addEventListener('click', refreshScanners);
            hardwareStatusBtn.addEventListener('click', showHardwareInfo);
            connectionMethodBtn.addEventListener('click', showConnectionMethodModal);
            closeConnectionModalBtn.addEventListener('click', hideConnectionMethodModal);
            saveConnectionPrefBtn.addEventListener('click', saveConnectionPreferences);
            standardModeBtn.addEventListener('click', setStandardMode);
            expertModeBtn.addEventListener('click', setExpertMode);
            saveImageBtn.addEventListener('click', saveImage);
            resetSettingsBtn.addEventListener('click', resetSettings);
            multipassCheck.addEventListener('change', toggleMultipassControls);
            connectionPriority.addEventListener('change', updateConnectionPriority);

            // Sliders with immediate feedback
            document.getElementById('brightnessSlider').addEventListener('input', updateSliderValue);
            document.getElementById('contrastSlider').addEventListener('input', updateSliderValue);
            document.getElementById('sharpnessSlider').addEventListener('input', updateSliderValue);
            document.getElementById('colorBalanceSlider').addEventListener('input', updateSliderValue);
            document.getElementById('saturationSlider').addEventListener('input', updateSliderValue);
            document.getElementById('gradationSlider').addEventListener('input', updateSliderValue);
            document.getElementById('densitySlider').addEventListener('input', updateSliderValue);
            document.getElementById('shadowSlider').addEventListener('input', updateSliderValue);

            // Initialize the app
            updateUI();
            detectScanners();
        }

        function updateUI() {
            // Update connection status indicators
            if (isConnected) {
                connectBtn.textContent = 'Disconnect';
                connectBtn.classList.remove('bg-primary');
                connectBtn.classList.add('bg-red-500');
                previewBtn.disabled = false;
                scanBtn.disabled = false;
                connectionIndicator.classList.remove('bg-gray-500');
                connectionIndicator.classList.add('bg-green-500');
                connectionText.textContent = 'Connected';
                connectionTooltip.textContent = 'Scanner is ready for operation';
                scannerLight.classList.add('scanner-active');
            } else {
                connectBtn.textContent = 'Connect';
                connectBtn.classList.add('bg-primary');
                connectBtn.classList.remove('bg-red-500');
                previewBtn.disabled = true;
                scanBtn.disabled = true;
                connectionIndicator.classList.remove('bg-green-500');
                connectionText.textContent = 'Disconnected';
                connectionTooltip.textContent = 'No scanner connected';
                scannerLight.classList.remove('scanner-active');
                scannerDetails.classList.add('hidden');
            }

            // Update expert mode
            if (isExpertMode) {
                expertModeBtn.classList.add('bg-primarydark');
                document.getElementById('appContainer').classList.add('expert-mode');
            } else {
                expertModeBtn.classList.remove('bg-primarydark');
                document.getElementById('appContainer').classList.remove('expert-mode');
            }
        }

        function detectScanners() {
            statusMessage.textContent = 'Searching for available scanners...';

            // Clear existing options
            while (scannerSelect.options.length > 1) {
                scannerSelect.remove(1);
            }

            // Attempt to detect real scanners
            detectRealScanners().then(scanners => {
                if (scanners.length > 0) {
                    let preferredScannerIndex = -1;

                    // Add detected scanners to dropdown
                    scanners.forEach((scanner, index) => {
                        const option = document.createElement('option');
                        option.value = scanner.id;
                        
                        // Add interface indicator
                        let interfaceClass = '';
                        if (scanner.interface === 'Thunderbolt') interfaceClass = 'interface-thunderbolt';
                        if (scanner.interface === 'Firewire') interfaceClass = 'interface-firewire';
                        if (scanner.interface === 'USB') interfaceClass = 'interface-usb';
                        if (scanner.interface === 'Network') interfaceClass = 'interface-network';
                        
                        option.innerHTML = `<span class="${interfaceClass} interface-indicator"></span>${scanner.name}`;
                        scannerSelect.appendChild(option);

                        // Check if this matches our connection priority
                        if (connectionPriority.value.toLowerCase() === scanner.interface.toLowerCase() || 
                            (connectionPriority.value === 'any' && preferredScannerIndex === -1)) {
                            preferredScannerIndex = index;
                        }
                    });

                    // Select preferred scanner if found
                    if (preferredScannerIndex >= 0) {
                        scannerSelect.selectedIndex = preferredScannerIndex + 1;
                    }

                    statusMessage.textContent = `${scanners.length} scanner(s) found`;
                    connectionIndicator.classList.remove('bg-gray-500');
                    connectionIndicator.classList.add('bg-yellow-500');
                    connectionText.textContent = 'Devices available';
                    connectionTooltip.textContent = 'Click connect to establish scanner connection';
                } else {
                    statusMessage.textContent = 'No compatible scanners detected';
                    connectionIndicator.classList.remove('bg-yellow-500');
                    connectionIndicator.classList.remove('bg-green-500');
                    connectionIndicator.classList.add('bg-gray-500');
                    connectionText.textContent = 'No devices';
                    connectionTooltip.textContent = 'No compatible scanners were detected';
                }
            }).catch(error => {
                console.error('Scanner detection error:', error);
                statusMessage.textContent = 'Error detecting scanners';
                connectionIndicator.classList.add('bg-gray-500');
                connectionText.textContent = 'Detection failed';
                connectionTooltip.textContent = 'Error scanning for devices: ' + error.message;
            });
        }

        function detectRealScanners() {
            return new Promise((resolve, reject) => {
                try {
                    // In a real application, this would interface with:
                    // 1. SANE backend (Linux)
                    // 2. TWAIN drivers (Windows)
                    // 3. Image Capture Framework (Mac)
                    // 
                    // This is a simulation of what that API might look like
                    
                    // Simulate detection delay
                    setTimeout(() => {
                        // Check if the browser has TWAIN or WIA access (not possible in real web apps)
                        const hasTwainAccess = false;
                        const hasWiaAccess = false;
                        
                        if (hasTwainAccess) {
                            // In a real native app, we would enumerate TWAIN devices
                            resolve([
                                {
                                    id: 'usb-real-001',
                                    name: 'Epson Perfection V600 (USB)',
                                    model: 'Perfection V600',
                                    vendor: 'Epson',
                                    type: 'Flatbed Scanner',
                                    resolution: '6400 dpi',
                                    dynamicRange: '3.4 Dmax',
                                    interface: 'USB'
                                }
                            ]);
                        } else if (hasWiaAccess) {
                            // In a real native app, we would enumerate WIA devices
                            resolve([
                                {
                                    id: 'usb-real-002',
                                    name: 'Canon CanoScan 9000F (USB)',
                                    model: 'CanoScan 9000F',
                                    vendor: 'Canon',
                                    type: 'Film Scanner',
                                    resolution: '9600 dpi',
                                    dynamicRange: '3.6 Dmax',
                                    interface: 'USB'
                                }
                            ]);
                        } else {
                            // In a real web application, we would need a:
                            // 1. Browser extension that provides scanner access
                            // 2. Localhost server that interfaces with SANE/TWAIN
                            // 3. Electron/NW.js app with native bindings
                            
                            // For this demo, we'll just return an empty array
                            resolve([]);
                            
                            // If this were a real native app, we would:
                            // try {
                            //     const devices = window.scannerAPI.getDevices();
                            //     resolve(devices);
                            // } catch (error) {
                            //     reject(error);
                            // }
                        }
                    }, 1500);
                } catch (error) {
                    reject(error);
                }
            });
        }

        function toggleScannerConnection() {
            if (isConnected) {
                disconnectScanner();
            } else {
                connectScanner();
            }
        }

        function connectScanner() {
            const selectedScannerId = scannerSelect.value;
            
            if (!selectedScannerId) {
                statusMessage.textContent = 'Please select a scanner first';
                return;
            }

            statusMessage.textContent = 'Establishing connection...';
            
            // In a real app, we would call the scanner API to connect
            // For this demo, we'll just simulate connecting to a generic scanner
            setTimeout(() => {
                currentScanner = {
                    id: selectedScannerId,
                    name: scannerSelect.options[scannerSelect.selectedIndex].text.replace(/<[^>]*>/g, '').trim(),
                    model: 'Connected Scanner',
                    vendor: 'Manufacturer',
                    type: 'Flatbed Scanner',
                    resolution: '1200 dpi',
                    dynamicRange: '3.0 Dmax',
                    interface: 'USB'
                };
                
                isConnected = true;
                
                // Update scanner details
                scannerModel.textContent = currentScanner.model;
                scannerVendor.textContent = currentScanner.vendor;
                scannerType.textContent = currentScanner.type;
                scannerResolution.textContent = currentScanner.resolution;
                scannerDynamicRange.textContent = currentScanner.dynamicRange;
                scannerInterface.textContent = currentScanner.interface;
                
                // Update connection info
                connectionTypeInfo.innerHTML = `Connected via <strong class="text-primary">${currentScanner.interface}</strong> to <strong>${currentScanner.vendor} ${currentScanner.model}</strong>`;
                connectionInfo.classList.remove('hidden');
                
                // Interface-specific styling
                if (currentScanner.interface === 'Thunderbolt') {
                    scannerPanel.classList.add('border-thunderbolt');
                } else if (currentScanner.interface === 'Firewire') {
                    scannerPanel.classList.add('border-firewire');
                } else if (currentScanner.interface === 'USB') {
                    scannerPanel.classList.add('border-usb');
                } else if (currentScanner.interface === 'Network') {
                    scannerPanel.classList.add('border-network');
                }
                
                statusMessage.textContent = `Connected to ${currentScanner.vendor} ${currentScanner.model}`;
                scannerDetails.classList.remove('hidden');
                updateUI();
            }, 1000);
        }

        function disconnectScanner() {
            statusMessage.textContent = 'Disconnecting...';
            
            // Clear any ongoing scans
            clearInterval(timer);
            progressContainer.classList.add('hidden');
            
            setTimeout(() => {
                isConnected = false;
                currentScanner = null;
                previewImage.src = '';
                previewImage.classList.add('hidden');
                placeholderText.classList.remove('hidden');
                connectionInfo.classList.add('hidden');
                
                // Reset panel border
                scannerPanel.classList.remove('border-thunderbolt', 'border-firewire', 'border-usb', 'border-network');
                
                statusMessage.textContent = 'Scanner disconnected';
                updateUI();
            }, 500);
        }

        function startPreview() {
            if (!isConnected) return;
            
            statusMessage.textContent = 'Creating preview scan...';
            scannerLight.style.opacity = '1';
            
            // In a real app, we would call the scanner API to do a preview scan
            // This is just a simulation
            setTimeout(() => {
                statusMessage.textContent = 'Preview completed';
                scannerLight.style.opacity = '0';
                alert("In a real application, this would show a preview from the connected scanner.");
            }, 1500);
        }

        function startScan() {
            if (!isConnected) return;
            
            statusMessage.textContent = 'Starting full resolution scan...';
            scannerLight.style.opacity = '1';
            progressContainer.classList.remove('hidden');
            progressBar.style.width = '0%';
            progressPercent.textContent = '0%';
            scanningProgress = 0;
            
            // In a real app, we would call the scanner API to do a full scan
            // This is just a simulation of progress
            clearInterval(timer);
            timer = setInterval(() => {
                scanningProgress += 5;
                
                if (scanningProgress >= 100) {
                    scanningProgress = 100;
                    clearInterval(timer);
                    
                    progressBar.style.width = '100%';
                    progressPercent.textContent = '100%';
                    scannerLight.style.opacity = '0';
                    statusMessage.textContent = 'Scan completed';
                    alert("In a real application, this would show the scanned image.");
                } else {
                    progressBar.style.width = `${scanningProgress}%`;
                    progressPercent.textContent = `${scanningProgress}%`;
                }
            }, 100);
        }

        function refreshScanners() {
            if (isConnected) {
                disconnectScanner();
            }
            
            scannerLight.style.opacity = '1';
            setTimeout(() => {
                detectScanners();
                scannerLight.style.opacity = '0';
            }, 500);
        }

        function showHardwareInfo() {
            alert("Live Mode: The application will attempt to detect actual connected hardware. For full functionality, this should be run as a native application with proper scanner drivers installed.");
        }

        function showConnectionMethodModal() {
            connectionMethodModal.classList.remove('hidden');
        }

        function hideConnectionMethodModal() {
            connectionMethodModal.classList.add('hidden');
        }

        function saveConnectionPreferences() {
            connectionMethod = connectionPriority.value;
            hideConnectionMethodModal();
            refreshScanners();
        }

        function updateConnectionPriority() {
            const selectedPriority = connectionPriority.value;
            console.log('Connection priority set to:', selectedPriority);
        }

        function setStandardMode() {
            isExpertMode = false;
            updateUI();
        }

        function setExpertMode() {
            isExpertMode = true;
            updateUI();
        }

        function saveImage() {
            alert("In a real application, this would save the scanned image to disk.");
        }

        function resetSettings() {
            // Reset all sliders to defaults
            document.getElementById('brightnessSlider').value = 100;
            document.getElementById('brightnessValue').textContent = '100';
            document.getElementById('contrastSlider').value = 100;
            document.getElementById('contrastValue').textContent = '100';
            document.getElementById('sharpnessSlider').value = 50;
            document.getElementById('sharpnessValue').textContent = '50';
            document.getElementById('colorBalanceSlider').value = 0;
            document.getElementById('colorBalanceValue').textContent = '0';
            document.getElementById('saturationSlider').value = 0;
            document.getElementById('saturationValue').textContent = '0';
            document.getElementById('gradationSlider').value = 0;
            document.getElementById('gradationValue').textContent = '0';
            document.getElementById('densitySlider').value = 50;
            document.getElementById('densityValue').textContent = '50';
            document.getElementById('shadowSlider').value = 0;
            document.getElementById('shadowValue').textContent = '0';
            
            if (isConnected) {
                statusMessage.textContent = 'Settings reset to defaults';
            }
        }

        function toggleMultipassControls() {
            if (multipassCheck.checked) {
                multipassControls.classList.remove('hidden');
            } else {
                multipassControls.classList.add('hidden');
            }
        }

        function updateSliderValue(e) {
            const sliderId = e.target.id;
            const valueElement = document.getElementById(sliderId.replace('Slider', 'Value'));
            valueElement.textContent = e.target.value;
        }
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=WDFluho/flextight-control1" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>