Spaces:
Running

File size: 56,978 Bytes
0c39847
 
 
 
 
f2491d7
 
0c39847
 
f2491d7
a67d1cc
0c39847
 
 
f2491d7
 
 
 
 
 
 
 
 
 
 
 
0c39847
 
 
f2491d7
 
 
 
 
 
 
61da564
f2491d7
 
 
 
 
 
 
 
9a4e559
f2491d7
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
0c39847
 
 
 
f2491d7
 
 
0c39847
 
 
f2491d7
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
0c39847
f2491d7
 
 
0c39847
f2491d7
 
 
0c39847
f2491d7
 
 
0c39847
 
 
 
f2491d7
 
 
 
 
0c39847
f2491d7
 
 
 
 
0c39847
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
 
f2491d7
0c39847
f2491d7
 
 
 
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
0c39847
f2491d7
 
0c39847
f2491d7
 
0c39847
 
 
 
f2491d7
 
 
 
 
 
 
 
 
 
0c39847
ce880c7
f2491d7
 
 
 
 
0c39847
 
 
f2491d7
 
 
 
 
0c39847
f2491d7
 
0c39847
f2491d7
0c39847
 
f2491d7
 
 
 
 
 
 
 
 
 
0c39847
 
f2491d7
 
0c39847
f2491d7
 
 
 
 
0c39847
f2491d7
 
0c39847
 
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
f2491d7
 
0c39847
f2491d7
 
 
 
0c39847
 
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
 
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
 
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
 
f2491d7
 
 
 
 
 
0c39847
 
f2491d7
 
0c39847
f2491d7
 
0c39847
f2491d7
 
 
 
 
 
 
0c39847
 
f2491d7
 
 
 
 
 
 
 
 
0c39847
 
f2491d7
0c39847
f2491d7
 
0c39847
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
0c39847
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
0c39847
 
 
 
f2491d7
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
 
 
 
 
0c39847
 
 
 
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
 
 
 
9a4e559
f2491d7
9a4e559
f2491d7
 
 
0c39847
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
f2491d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c39847
f2491d7
 
0c39847
f2491d7
a67d1cc
 
 
0c39847
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Cham OCR Studio — Paleographic Transcription &amp; Diagnostic Workbench</title>
    <meta name="description" content="Open-source deep-learning Optical Character Recognition (OCR) workbench for historical and modern Eastern Cham (Akhar Thrah) manuscripts — https://ocr.cham.asia">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Google+Sans+Flex:wght@300..800&family=JetBrains+Mono:wght@400;500;600;700&family=Noto+Sans+Cham:wght@400;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="/static/css/studio.css?v=26.3.2">
</head>
<body>

    <!-- =====================================================================
         1. Minimalist 3-Cluster Top Command Header (Linear / Claude Style)
         ===================================================================== -->
    <header class="studio-header">
        <!-- Cluster 1 (Left): Brand Identity -->
        <div class="header-cluster header-cluster-left">
            <a href="/" class="header-brand" title="Cham OCR Studio — https://ocr.cham.asia">
                <span class="brand-emblem" aria-hidden="true">ꨌ</span>
                <span class="brand-text-wrap">
                    <span class="brand-title">Cham OCR Studio</span>
                    <span class="brand-subtitle">Paleographic Workbench</span>
                </span>
            </a>
        </div>

        <!-- Cluster 2 (Center): Model & Pipeline Engine + Primary Transcribe Action -->
        <div class="header-cluster header-cluster-center">
            <div class="popover-anchor">
                <div class="engine-bar">
                    <span class="engine-label">Model</span>
                    <select id="model-select" class="model-select" aria-label="Select Recognition Model">
                        <optgroup label="Paleographic Cham Specialists">
                            <option value="v24_1_r4" selected>V26.1 SOTA</option>
                            <option value="v24_1_r3_1">V24.1-R3.1</option>
                            <option value="v24_1_r2_1_6">V24.1-R2.1.6</option>
                        </optgroup>
                        <optgroup label="Multiscript &amp; Bilingual">
                            <option value="auto">Auto Router</option>
                            <option value="vi">Vietnamese</option>
                        </optgroup>
                        <optgroup label="Historical Baselines">
                            <option value="v25">V25 Bilingual (Legacy)</option>
                            <option value="v24">V24 Baseline</option>
                            <option value="v23">V23 Legacy</option>
                        </optgroup>
                    </select>
                    <button type="button" class="engine-gear-btn" onclick="StudioApp.togglePopover('popover-engine', event)" title="Segmentation &amp; Reading Order Parameters">
                        <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
                    </button>
                </div>

                <div class="popover-menu align-left" id="popover-engine" style="width: 280px;">
                    <div class="popover-section-label">Segmentation Pipeline</div>
                    <div class="popover-form-row">
                        <label for="sel-seg-method">Line Detection Engine</label>
                        <select id="sel-seg-method" class="popover-select" onchange="StudioApp.setSegMethod(this.value)">
                            <option value="dbnet" selected>Hybrid Cham-DBNet (Polygon Ribbon)</option>
                            <option value="valley">Indic Valley-Cut Projection</option>
                            <option value="adaptive">Adaptive Threshold Profile</option>
                        </select>
                    </div>
                    <div class="popover-form-row">
                        <label for="sel-reading-order">Multi-Column Reading Order</label>
                        <select id="sel-reading-order" class="popover-select" onchange="StudioApp.setReadingOrder(this.value)">
                            <option value="auto" selected>Automatic Column Detection</option>
                            <option value="rows">Strict Top-to-Bottom Rows</option>
                        </select>
                    </div>
                    <div class="popover-divider"></div>
                    <div class="popover-section-label">Heuristic Fallback Parameters</div>
                    <div class="popover-form-row">
                        <label>Minimum Interlinear Gap (px) <span id="lbl-gap-val">12</span></label>
                        <input type="range" min="4" max="36" value="12" oninput="document.getElementById('lbl-gap-val').innerText=this.value; StudioApp.setValleyGap(this.value)">
                    </div>
                </div>
            </div>

            <button type="button" class="btn btn-primary" id="btn-run" onclick="StudioApp.runActiveOCR()" disabled title="Transcribe Active Manuscript Folio (Ctrl+Enter)">
                <svg width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><polygon points="5 3 19 12 5 21 5 3"/></svg>
                <span>Transcribe</span>
            </button>
        </div>

        <!-- Cluster 3 (Right): Layout ▾ + Ctrl+K + Export + Help ▾ -->
        <div class="header-cluster header-cluster-right">
            <!-- Layout Mode Dropdown -->
            <div class="popover-anchor">
                <button type="button" class="btn" id="btn-layout-menu" onclick="StudioApp.togglePopover('popover-layout', event)" title="Switch Workspace Layout (Alt+1..4)">
                    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="9" y1="3" x2="9" y2="21"/></svg>
                    <span id="active-layout-label" class="header-hide-md">3-Pane</span>
                    <span style="font-size:10px;opacity:0.7;">▾</span>
                </button>
                <div class="popover-menu" id="popover-layout" style="min-width: 240px;">
                    <div class="popover-section-label">Workspace Layout</div>
                    <button type="button" class="popover-item layout-opt active" data-view="workbench" onclick="StudioApp.setLayoutMode('workbench')">
                        <span class="popover-item-left">3-Pane Workbench</span>
                        <span class="kbd-hint">Alt+1</span>
                    </button>
                    <button type="button" class="popover-item layout-opt" data-view="side" onclick="StudioApp.setLayoutMode('side')">
                        <span class="popover-item-left">Side-by-Side Compare</span>
                        <span class="kbd-hint">Alt+2</span>
                    </button>
                    <button type="button" class="popover-item layout-opt" data-view="stacked" onclick="StudioApp.setLayoutMode('stacked')">
                        <span class="popover-item-left">Stacked (Palm-Leaf)</span>
                        <span class="kbd-hint">Alt+3</span>
                    </button>
                    <button type="button" class="popover-item layout-opt" data-view="focus" onclick="StudioApp.setLayoutMode('focus')">
                        <span class="popover-item-left">Focus Reader</span>
                        <span class="kbd-hint">Alt+4</span>
                    </button>
                </div>
            </div>

            <!-- Command Palette Pill -->
            <button type="button" class="cmdk-trigger" onclick="StudioApp.openCommandPalette()" title="Open Command Palette (Ctrl+K)">
                <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
                <span class="kbd-hint">Ctrl+K</span>
            </button>

            <!-- Export Modal Trigger -->
            <button type="button" class="btn" onclick="StudioApp.openModal('export-modal')" title="Export Folio or Multi-Page Corpus (Ctrl+E)">
                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
                <span class="header-hide-md">Export</span>
            </button>

            <!-- Consolidated Help & Docs Dropdown -->
            <div class="popover-anchor">
                <button type="button" class="btn" onclick="StudioApp.togglePopover('popover-more', event)" title="User Guide, Technical Report &amp; Diagnostics">
                    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
                    <span class="header-hide-md">Help</span>
                    <span style="font-size:10px;opacity:0.7;">▾</span>
                </button>
                <div class="popover-menu" id="popover-more" style="min-width: 285px;">
                    <div class="popover-section-label">Guides &amp; Research</div>
                    <a href="/help" target="_blank" rel="noopener noreferrer" class="popover-item">
                        <span class="popover-item-left">
                            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
                            <span>User Guide &amp; Manual</span>
                        </span>
                        <span class="kbd-hint">?</span>
                    </a>
                    <a href="/research" target="_blank" rel="noopener noreferrer" class="popover-item">
                        <span class="popover-item-left">
                            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>
                            <span>Academic Technical Report</span>
                        </span>
                        <span>↗</span>
                    </a>
                    <button type="button" class="popover-item" onclick="StudioApp.openModal('about-modal')">
                        <span class="popover-item-left">
                            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="4" width="18" height="16" rx="2"/><line x1="7" y1="9" x2="17" y2="9"/><line x1="7" y1="13" x2="13" y2="13"/></svg>
                            <span>Architecture &amp; Quick Shortcuts</span>
                        </span>
                    </button>
                    <div class="popover-divider"></div>
                    <div class="popover-section-label">Diagnostics &amp; Community</div>
                    <button type="button" class="popover-item" onclick="StudioApp.openModal('logs-modal')">
                        <span class="popover-item-left">
                            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>
                            <span>System Runtime Logs</span>
                        </span>
                    </button>
                    <a href="https://github.com/phucsd/Cham-OCR" target="_blank" rel="noopener noreferrer" class="popover-item">
                        <span class="popover-item-left">
                            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22"/></svg>
                            <span>GitHub Repository</span>
                        </span>
                        <span>↗</span>
                    </a>
                    <a href="mailto:phucsd@gmail.com" class="popover-item">
                        <span class="popover-item-left">
                            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/><polyline points="22,6 12,13 2,6"/></svg>
                            <span>Contact Maintainer</span>
                        </span>
                    </a>
                </div>
            </div>
        </div>
    </header>

    <!-- =====================================================================
         2. Flexible Resizable Multi-Pane Workspace
         ===================================================================== -->
    <main class="workspace layout-workbench is-empty-landing" id="main-workspace">

        <!-- 2A. Left Pane: Manuscript Corpus Queue & Batch Engine -->
        <aside class="sidebar-pane collapsed" id="sidebar-pane" aria-label="Manuscript Corpus Queue">
            <div class="pane-header">
                <div class="pane-title">
                    <span>Corpus Queue</span>
                    <span class="count-pill" id="queue-total-pill">0</span>
                </div>
                <div style="display: inline-flex; align-items: center; gap: 4px;">
                    <button type="button" class="btn btn-soft-accent btn-xs" id="btn-batch-run" onclick="StudioApp.runBatchOCR('unprocessed')" disabled title="Batch Transcribe All Queued Folios (Ctrl+Shift+Enter)">
                        <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4"><polygon points="3 4 13 12 3 20 3 4"/><polygon points="13 4 23 12 13 20 13 4"/></svg>
                        <span>Batch</span>
                    </button>
                    <button type="button" class="icon-btn" style="width:24px;height:24px;" onclick="StudioApp.clearEntireQueue()" title="Clear Entire Queue">
                        <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
                    </button>
                    <button type="button" class="icon-btn" style="width:24px;height:24px;" onclick="StudioApp.toggleSidebarPane()" title="Collapse Queue Drawer (Alt+Q)">
                        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><polyline points="15 18 9 12 15 6"/></svg>
                    </button>
                </div>
            </div>

            <!-- Multi-File & PDF Intake Dropzone -->
            <div class="intake-box" id="intake-dropzone">
                <div class="intake-actions">
                    <button type="button" class="btn btn-primary btn-sm" onclick="document.getElementById('file-input').click()" title="Upload Multiple Images or Multi-Page PDF (Ctrl+O)">
                        <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
                        <span>Add Images / PDF</span>
                    </button>
                    <button type="button" class="btn btn-sm" onclick="StudioApp.openModal('samples-modal')" title="Browse Built-in Archival Specimens">
                        <span>Specimens</span>
                    </button>
                </div>
                <input type="file" id="file-input" multiple accept="image/*,application/pdf,.pdf,application/json,.json" style="display: none;" onchange="StudioApp.handleIncomingFiles(this.files); this.value='';">
                <div class="intake-meta-row">
                    <label class="toggle-switch-label" title="Automatically run OCR when new images or PDF pages are added">
                        <input type="checkbox" id="chk-auto-ocr" onchange="StudioApp.setAutoOcr(this.checked)">
                        <span>Auto-transcribe on upload</span>
                    </label>
                </div>
            </div>

            <!-- Live Batch OCR Progress Strip -->
            <div class="batch-progress-card" id="batch-progress-card">
                <div class="batch-progress-top">
                    <span id="batch-progress-count">Batch OCR: 0 / 0</span>
                    <button type="button" class="btn btn-xs" onclick="StudioApp.stopBatchOCR()">Stop</button>
                </div>
                <div class="batch-progress-track">
                    <div class="batch-progress-fill" id="batch-progress-fill"></div>
                </div>
                <div class="batch-progress-sub" id="batch-progress-sub">Preparing queue...</div>
            </div>

            <!-- Search & Status Filter Pills -->
            <div class="queue-filter-section">
                <input type="search" class="queue-search-input" placeholder="Filter folios by filename..." oninput="StudioApp.setQueueSearch(this.value)">
                <div class="filter-pills">
                    <button type="button" class="filter-pill active" data-filter="all" data-label="All" onclick="StudioApp.setQueueFilter('all')">All (0)</button>
                    <button type="button" class="filter-pill" data-filter="needs_review" data-label="Review" onclick="StudioApp.setQueueFilter('needs_review')">Review</button>
                    <button type="button" class="filter-pill" data-filter="ocr_done" data-label="OCR Done" onclick="StudioApp.setQueueFilter('ocr_done')">OCR Done</button>
                    <button type="button" class="filter-pill" data-filter="verified" data-label="Verified" onclick="StudioApp.setQueueFilter('verified')">Verified</button>
                    <button type="button" class="filter-pill" data-filter="unprocessed" data-label="Pending" onclick="StudioApp.setQueueFilter('unprocessed')">Pending</button>
                </div>
            </div>

            <!-- Draggable Folio Queue List -->
            <div class="queue-list" id="queue-list"></div>

            <!-- Corpus Summary Footer -->
            <div class="sidebar-footer">
                <div class="corpus-stats-row">
                    <span id="corpus-footer-summary"><strong>0</strong> folios · <strong>0</strong> lines</span>
                    <span id="corpus-footer-pct">0% verified</span>
                </div>
                <div class="corpus-verified-bar">
                    <div class="corpus-verified-fill" id="corpus-verified-fill"></div>
                </div>
            </div>
        </aside>

        <!-- Vertical Splitter 1: Sidebar <-> Main Stage (Double-click to reset) -->
        <div class="pane-resizer-v" id="resizer-sidebar" title="Drag to resize Corpus Queue (Double-click to reset)"></div>

        <!-- 2B. Main Split Stage (Manuscript Canvas + Transcription Editor) -->
        <div class="main-split-stage" id="main-split-stage">

            <!-- Center Pane: Paleographic Document Canvas (Full-Bleed with Floating Glass HUD) -->
            <section class="viewer-pane" id="viewer-pane" aria-label="Manuscript Viewer">
                <!-- Interactive Pan/Zoom Stage -->
                <div class="viewer-stage" id="viewer-stage" tabindex="0">
                    <!-- Top-Left Floating Context Pill (Queue Toggle + Active Folio Chip) -->
                    <div class="canvas-top-pill" id="canvas-top-pill" style="display: none;">
                        <button type="button" class="canvas-queue-btn" id="btn-canvas-queue" onclick="StudioApp.toggleSidebarPane()" title="Toggle Corpus Queue Drawer (Alt+Q)">
                            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="9" y1="3" x2="9" y2="21"/></svg>
                            <span>Queue</span>
                            <span class="canvas-queue-badge" id="canvas-queue-count">0</span>
                        </button>
                        <div class="active-folio-chip" id="viewer-folio-chip" style="display: none;" title="Active Manuscript Folio">
                            <span class="folio-dot" id="header-folio-dot"></span>
                            <span class="folio-name" id="header-folio-name"></span>
                            <span class="doc-badge unprocessed" id="header-doc-badge" style="display: none;"></span>
                        </div>
                    </div>

                    <div class="viewer-transform-layer" id="viewer-transform-layer">
                        <img id="document-image" class="manuscript-img" src="" alt="Active Manuscript Folio">
                        <svg id="polygon-overlay" class="polygon-svg-overlay"></svg>
                        <div id="bbox-overlay" class="bbox-layer spotlight-mode"></div>
                        <div id="drawing-bbox-rect" class="drawing-bbox-rect" style="display: none;"></div>
                    </div>

                    <!-- Bottom-Center Floating Glass Pill HUD (Figma / Preview Style) -->
                    <div class="canvas-floating-hud" id="canvas-floating-hud" style="display: none;" role="toolbar" aria-label="Manuscript Canvas Controls">
                        <button type="button" class="hud-pill-btn" onclick="StudioApp.zoomToFit()" title="Fit Folio in Viewport">
                            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/></svg>
                        </button>
                        <button type="button" class="hud-pill-btn" onclick="StudioApp.zoomToWidth()" title="Fit Folio Width">
                            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M4 12h16M4 5v14M20 5v14"/></svg>
                        </button>
                        <button type="button" class="hud-pill-btn" onclick="StudioApp.zoomTo100()" title="Actual Pixel Size (1:1)">
                            <span style="font-size:10px;font-weight:700;font-family:var(--font-mono);">1:1</span>
                        </button>
                        <button type="button" class="hud-pill-btn" onclick="StudioApp.zoomStep(0.84)" title="Zoom Out">
                            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><line x1="5" y1="12" x2="19" y2="12"/></svg>
                        </button>
                        <span class="zoom-readout" id="zoom-readout">100%</span>
                        <button type="button" class="hud-pill-btn" onclick="StudioApp.zoomStep(1.18)" title="Zoom In">
                            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
                        </button>
                        <button type="button" class="hud-pill-btn" onclick="StudioApp.rotateActiveImage90()" title="Rotate Folio 90° Clockwise">
                            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg>
                        </button>

                        <div class="hud-divider"></div>

                        <button type="button" class="hud-pill-btn" id="btn-draw-bbox" onclick="StudioApp.toggleDrawBboxMode()" title="Draw Manual Bounding Box &amp; Transcribe Region (Key: D)">
                            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/></svg>
                        </button>
                        <button type="button" class="hud-pill-btn active" id="btn-toggle-bbox" onclick="StudioApp.cycleBboxMode()" title="Cycle Line Overlay: Spotlight Baselines → All Boxes → Hidden (Key: B)">
                            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="5" width="18" height="14" rx="2" stroke-dasharray="4 2"/></svg>
                            <span class="hud-pill-label" id="lbl-bbox-mode">Spotlight</span>
                        </button>
                        <button type="button" class="hud-pill-btn active" id="btn-toggle-poly" onclick="StudioApp.togglePolygonOverlay()" title="Toggle Curved Polygon Ribbon Contours (Key: P)">
                            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 9c4-3 8 3 12 0s6-2 6-2v8s-2 2-6 2-8-3-12 0V9z"/></svg>
                        </button>

                        <div class="hud-divider"></div>

                        <button type="button" class="hud-pill-btn" id="btn-magnifier" onclick="StudioApp.toggleMagnifier()" title="Toggle 2.6× Paleographic Magnifier Loupe (Key: L)">
                            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/><line x1="11" y1="8" x2="11" y2="14"/><line x1="8" y1="11" x2="14" y2="11"/></svg>
                        </button>

                        <!-- Non-Destructive Manuscript Image Enhancement Filters (Opens Upward) -->
                        <div class="popover-anchor">
                            <button type="button" class="hud-pill-btn" onclick="StudioApp.togglePopover('popover-filters', event)" title="Paleographic Contrast &amp; Ink Enhancement Filters">
                                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M12 2a10 10 0 0 0 0 20z" fill="currentColor"/></svg>
                            </button>
                            <div class="popover-menu popover-upward" id="popover-filters" style="width: 245px;">
                                <div class="popover-section-label">Folio Optical Filters</div>
                                <div class="popover-form-row">
                                    <label>Contrast <span id="lbl-filter-contrast">100%</span></label>
                                    <input type="range" id="inp-filter-contrast" min="60" max="240" value="100" oninput="StudioApp.updateFilterControl('contrast', this.value)">
                                </div>
                                <div class="popover-form-row">
                                    <label>Brightness <span id="lbl-filter-brightness">100%</span></label>
                                    <input type="range" id="inp-filter-brightness" min="50" max="180" value="100" oninput="StudioApp.updateFilterControl('brightness', this.value)">
                                </div>
                                <div class="popover-form-row">
                                    <label>Monochrome Desaturation <span id="lbl-filter-grayscale">0%</span></label>
                                    <input type="range" id="inp-filter-grayscale" min="0" max="100" value="0" oninput="StudioApp.updateFilterControl('grayscale', this.value)">
                                </div>
                                <div class="popover-form-row">
                                    <label class="toggle-switch-label">
                                        <input type="checkbox" id="inp-filter-invert" onchange="StudioApp.updateFilterControl('invert', this.checked)">
                                        <span>Invert Dark/Rubbing Ink</span>
                                    </label>
                                </div>
                                <div class="popover-divider"></div>
                                <button type="button" class="popover-item" onclick="StudioApp.resetCanvasFilters()">
                                    <span class="popover-item-left">↺ Reset Optical Filters</span>
                                </button>
                            </div>
                        </div>
                    </div>

                    <!-- Paleographic Magnifier Loupe -->
                    <div id="magnifier-loupe" class="magnifier-loupe"></div>

                    <!-- OCR Execution Spinner -->
                    <div id="ocr-loading-overlay" class="ocr-loading-overlay">
                        <div class="ocr-spinner"></div>
                        <div class="ocr-loading-text" id="ocr-loading-text">Transcribing manuscript folio...</div>
                    </div>

                    <!-- Onboarding Empty State with Instant Demo Specimens -->
                    <div class="empty-stage-card" id="empty-stage-card">
                        <div class="empty-hero-box">
                            <div class="empty-icon-circle">
                                <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>
                            </div>
                            <div class="empty-hero-title">Load Historical Cham Manuscripts or Multi-Page PDFs</div>
                            <p class="empty-hero-desc">
                                Drag &amp; drop single or multiple folio scans, import a multi-page PDF document, or paste directly from your clipboard (<kbd class="kbd-hint">Ctrl+V</kbd>).
                            </p>
                            <div class="empty-cta-row">
                                <button type="button" class="btn btn-primary" onclick="document.getElementById('file-input').click()">
                                    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
                                    <span>Upload Images / PDF</span>
                                </button>
                                <button type="button" class="btn" onclick="StudioApp.loadDemoBatchSet()">
                                    <span>Load 4-Folio Demo Batch</span>
                                </button>
                                <button type="button" class="btn" onclick="StudioApp.openModal('samples-modal')">
                                    <span>Browse 6 Specimens</span>
                                </button>
                            </div>

                            <div class="quick-samples-strip" id="quick-samples-strip" style="display: none;">
                                <div class="quick-samples-header">
                                    <span>Instant Archival Specimens</span>
                                    <button type="button" class="btn btn-xs" onclick="StudioApp.openModal('samples-modal')">View All ▸</button>
                                </div>
                                <div class="quick-samples-grid" id="quick-samples-grid"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>

            <!-- Resizers between Viewer and Editor -->
            <div class="pane-resizer-v" id="resizer-editor-v" title="Drag to resize Transcription Editor (Double-click to reset)"></div>
            <div class="pane-resizer-h" id="resizer-editor-h" title="Drag vertically to resize Stacked Panes (Double-click to reset)"></div>

            <!-- Right Pane: Scholarly Transcription Editor -->
            <section class="editor-pane" id="editor-pane" aria-label="Transcription Editor">
                <div class="editor-toolbar">
                    <div class="hud-group">
                        <div class="editor-mode-pills" role="tablist">
                            <button type="button" class="editor-mode-btn active" data-emode="lines" onclick="StudioApp.setEditorMode('lines')" title="Diplomatic Line-by-Line Edition">Lines</button>
                            <button type="button" class="editor-mode-btn" data-emode="paragraphs" onclick="StudioApp.setEditorMode('paragraphs')" title="Continuous Paragraph &amp; Stanza Reconstruction (Alt+P)">Stanza</button>
                        </div>
                        <span class="count-pill" id="editor-line-count">0 lines</span>
                    </div>

                    <div class="hud-group">
                        <button type="button" class="btn btn-xs" id="btn-header-keyboard" onclick="ChamKeyboard.toggle()" title="Toggle Akhar Thrah Virtual Keyboard (Alt+K)">
                            <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><rect x="2" y="5" width="20" height="14" rx="2"/><line x1="6" y1="9" x2="6.01" y2="9"/><line x1="10" y1="9" x2="10.01" y2="9"/><line x1="14" y1="9" x2="14.01" y2="9"/><line x1="18" y1="9" x2="18.01" y2="9"/><line x1="8" y1="15" x2="16" y2="15"/></svg>
                            <span>KB</span>
                        </button>
                        <div class="hud-group" id="editor-post-ocr-tools" style="display: none;">
                            <button type="button" class="btn btn-xs active" id="btn-toggle-crops" onclick="StudioApp.cycleCropMode()" title="Cycle Line Cutout Strip: Focus Active Line → All Lines → Hidden (Alt+C)">
                                <span id="lbl-crop-mode">Crop: Focus</span>
                            </button>
                            <button type="button" class="btn btn-xs" id="btn-toggle-roman" onclick="StudioApp.toggleRomanized()" title="Show Scholarly Romanized Transliteration (Alt+T)">Aa</button>
                            <button type="button" class="btn btn-xs" id="btn-toggle-inspector" onclick="StudioApp.toggleInspector()" title="Toggle Unicode Codepoint &amp; Cluster Inspector (Alt+U)">U+</button>
                            <button type="button" class="icon-btn" style="width:25px;height:25px;" id="btn-toggle-find" onclick="StudioApp.toggleFindBar()" title="Search &amp; Replace in Folio (Ctrl+F)">
                                <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
                            </button>
                            <button type="button" class="icon-btn" style="width:24px;height:25px;" id="btn-undo" onclick="StudioApp.undoEdit()" disabled title="Undo (Ctrl+Z)">↶</button>
                            <button type="button" class="icon-btn" style="width:24px;height:25px;" id="btn-redo" onclick="StudioApp.redoEdit()" disabled title="Redo (Ctrl+Y)">↷</button>
                        </div>
                    </div>
                </div>

                <!-- Collapsible Find & Replace Strip -->
                <div class="find-replace-bar" id="find-replace-bar">
                    <input type="text" id="find-query-input" class="find-input" placeholder="Find Cham or Latin text..." oninput="StudioApp.handleFindQueryChange(this.value)">
                    <input type="text" id="replace-query-input" class="find-input" placeholder="Replace with...">
                    <button type="button" class="btn btn-xs btn-primary" onclick="StudioApp.executeReplaceAll()">Replace All</button>
                    <button type="button" class="btn btn-xs" onclick="StudioApp.toggleFindBar(false)">✕</button>
                </div>

                <!-- Folio Detection & Latency Telemetry Strip -->
                <div class="doc-telemetry-strip" id="doc-telemetry-strip"></div>

                <!-- Main Transcription Scroll Area -->
                <div class="editor-scroll-body" id="editor-scroll-body"></div>

                <!-- On-Demand Collapsible Unicode Cluster & Codepoint Inspector Drawer -->
                <div class="inspector-drawer" id="inspector-drawer">
                    <div class="inspector-header">
                        <span class="inspector-title">Unicode Paleographic Cluster Inspector (U+AA00–U+AA5F)</span>
                        <button type="button" class="btn btn-xs" onclick="StudioApp.toggleInspector(false)">Hide</button>
                    </div>
                    <div id="inspector-content"></div>
                </div>

                <!-- Streamlined QA Progress & Review Navigator (Visible Only When Lines > 0) -->
                <div class="line-action-bar" id="line-action-bar" style="display: none;">
                    <div class="action-bar-status" id="action-bar-status">
                        <span>0 / 0 verified</span>
                    </div>
                    <div style="display: inline-flex; align-items: center; gap: 4px;">
                        <button type="button" class="btn btn-xs" onclick="StudioApp.navFlaggedLine('prev')" title="Previous Flagged / Low-Confidence Line ([)">‹ Flagged</button>
                        <button type="button" class="btn btn-xs" onclick="StudioApp.navFlaggedLine('next')" title="Next Flagged / Low-Confidence Line (])">Flagged ›</button>
                        <button type="button" class="btn btn-xs" style="color:var(--confidence-high);border-color:rgba(47,125,92,0.35);background:var(--confidence-high-bg);" onclick="StudioApp.approveAllHighConfidence()" title="Batch verify all lines with confidence ≥ 75%">✓ Verify ≥75%</button>
                    </div>
                </div>
            </section>

        </div>
    </main>

    <!-- =====================================================================
         3. Draggable Cham Paleographic Virtual Keyboard (Akhar Thrah)
         ===================================================================== -->
    <section class="cham-kb-panel closed" id="cham-kb-panel" aria-label="Akhar Thrah Virtual Keyboard">
        <div class="cham-kb-header" id="cham-kb-header">
            <div class="cham-kb-title">
                <span title="Drag header to reposition">⋮⋮</span>
                <span>Cham Virtual Keyboard</span>
                <span class="count-pill">Akhar Thrah</span>
            </div>
            <div class="cham-kb-controls">
                <label>Grid
                    <select onchange="ChamKeyboard.setRowLayout(this.value)">
                        <option value="5" selected>5-Row Compact</option>
                        <option value="6">6-Row Balanced</option>
                        <option value="9">9-Row Canonical</option>
                    </select>
                </label>
                <label>Legend
                    <select onchange="ChamKeyboard.setPhoneticMode(this.value)">
                        <option value="traditional" selected>Traditional</option>
                        <option value="sanskrit">Sanskrit</option>
                        <option value="none">Glyph Only</option>
                    </select>
                </label>
                <label>Size
                    <select onchange="ChamKeyboard.setFontSize(this.value)">
                        <option value="16">16px</option>
                        <option value="18" selected>18px</option>
                        <option value="20">20px</option>
                        <option value="22">22px</option>
                    </select>
                </label>
                <button type="button" class="btn btn-xs" onclick="ChamKeyboard.resetPosition()" title="Dock to bottom-right corner">⟲</button>
                <button type="button" class="btn btn-xs" onclick="ChamKeyboard.toggle(false)" title="Close Keyboard (Alt+K / Esc)">✕</button>
            </div>
        </div>

        <div class="cham-kb-scratchbar">
            <input type="text" id="cham-kb-scratchpad" class="cham-kb-scratchpad" placeholder="Type directly into an active OCR line edit, or compose in this scratchpad...">
            <button type="button" class="btn btn-sm" onclick="ChamKeyboard.normalizeScratchpad()" title="Normalize scratchpad clusters into canonical Logical Order">Normalize</button>
            <button type="button" class="btn btn-sm" onclick="ChamKeyboard.copyScratchpad()">Copy</button>
            <button type="button" class="btn btn-sm btn-primary" onclick="ChamKeyboard.insertScratchpadToLine()">Insert ↵</button>
            <button type="button" class="btn btn-sm" onclick="ChamKeyboard.clearScratchpad()">Clear</button>
        </div>

        <div class="cham-kb-body" id="cham-kb-body"></div>
    </section>

    <!-- =====================================================================
         4. Command Palette Modal (Ctrl+K)
         ===================================================================== -->
    <div class="modal-backdrop" id="cmdk-modal">
        <div class="cmdk-dialog" role="dialog" aria-label="Studio Command Palette">
            <div class="cmdk-input-row">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" stroke-width="2.2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
                <input type="text" id="cmdk-input" class="cmdk-input" placeholder="Type a command (e.g. Batch OCR, Stacked Layout, Stanza Flow, Export ZIP)...">
                <span class="kbd-hint">Esc</span>
            </div>
            <div class="cmdk-list" id="cmdk-list"></div>
        </div>
    </div>

    <!-- =====================================================================
         5. Multi-Page PDF Import Modal
         ===================================================================== -->
    <div class="modal-backdrop" id="pdf-modal">
        <div class="modal-dialog" style="max-width: 480px;">
            <div class="modal-header">
                <h2>📄 Import Multi-Page PDF Manuscript</h2>
                <button type="button" class="btn btn-xs" onclick="StudioApp.closeModal('pdf-modal')">✕</button>
            </div>
            <div class="modal-body">
                <p id="pdf-modal-info" style="font-size: 13px; color: var(--text-secondary);"></p>
                <div class="popover-form-row" style="padding:0;">
                    <label for="pdf-page-range">Page Range (e.g. <code>1-10</code>, <code>1,3,5</code>, or <code>all</code>)</label>
                    <input type="text" id="pdf-page-range" class="popover-select" value="1-10">
                </div>
                <div class="popover-form-row" style="padding:0;">
                    <label for="pdf-dpi-select">Rasterization Resolution</label>
                    <select id="pdf-dpi-select" class="popover-select">
                        <option value="1.6">Standard Archival (150 DPI — Fast)</option>
                        <option value="2.2" selected>High-Detail Paleographic (220 DPI — Recommended)</option>
                        <option value="3.0">Ultra-Fine Epigraphic (300 DPI)</option>
                    </select>
                </div>
                <div id="pdf-import-status" style="font-size: 12px; font-weight: 600; color: var(--accent);"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn" onclick="StudioApp.closeModal('pdf-modal')">Cancel</button>
                <button type="button" class="btn btn-primary" id="btn-confirm-pdf" onclick="StudioApp.confirmPdfImport()">Import Pages to Queue</button>
            </div>
        </div>
    </div>

    <!-- =====================================================================
         6. Curated Demo Manuscript Specimens Modal
         ===================================================================== -->
    <div class="modal-backdrop" id="samples-modal">
        <div class="modal-dialog modal-wide">
            <div class="modal-header">
                <h2>📜 Curated Archival &amp; Benchmark Manuscript Specimens</h2>
                <button type="button" class="btn btn-xs" onclick="StudioApp.closeModal('samples-modal')">✕</button>
            </div>
            <div class="modal-body">
                <p style="font-size: 13px; color: var(--text-secondary);">
                    Select an individual specimen to inspect line segmentation and recognition quality, or load a multi-folio batch to evaluate automated queue processing.
                </p>
                <div class="samples-modal-grid" id="samples-modal-grid"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-soft-accent" onclick="StudioApp.loadDemoBatchSet()">Load 4-Folio Demo Batch</button>
                <button type="button" class="btn" onclick="StudioApp.closeModal('samples-modal')">Close</button>
            </div>
        </div>
    </div>

    <!-- =====================================================================
         7. Multi-Format Corpus & Active Learning Export Modal
         ===================================================================== -->
    <div class="modal-backdrop" id="export-modal">
        <div class="modal-dialog">
            <div class="modal-header">
                <h2>📦 Export Paleographic Transcription &amp; Training Corpus</h2>
                <button type="button" class="btn btn-xs" onclick="StudioApp.closeModal('export-modal')">✕</button>
            </div>
            <div class="modal-body">
                <div class="popover-form-row" style="padding: 0;">
                    <label for="export-scope-select">Export Scope</label>
                    <select id="export-scope-select" class="popover-select">
                        <option value="active">Active Manuscript Folio Only</option>
                        <option value="corpus">Entire Transcribed Corpus Queue (Multi-Page)</option>
                    </select>
                </div>

                <div class="export-options-grid">
                    <button type="button" class="export-card" onclick="StudioApp.exportFormat('copy_txt')">
                        <span class="export-card-title">📋 Copy Plaintext to Clipboard</span>
                        <span class="export-card-desc">Canonical Unicode Logical Order lines ready for immediate pasting.</span>
                    </button>
                    <button type="button" class="export-card" onclick="StudioApp.exportFormat('txt')">
                        <span class="export-card-title">📄 Unicode Plaintext (.txt)</span>
                        <span class="export-card-desc">Clean UTF-8 diplomatic line transcription file.</span>
                    </button>
                    <button type="button" class="export-card" onclick="StudioApp.exportFormat('md')">
                        <span class="export-card-title">📑 Scholarly Markdown Report (.md)</span>
                        <span class="export-card-desc">Includes folio metadata, confidence scores, and Romanized transliteration.</span>
                    </button>
                    <button type="button" class="export-card" onclick="StudioApp.exportFormat('json')">
                        <span class="export-card-title">🗂 Structured JSON (.json)</span>
                        <span class="export-card-desc">Bounding boxes, polygons, confidences &amp; RealScan-Gold ingest format.</span>
                    </button>
                    <button type="button" class="export-card" onclick="StudioApp.exportFormat('pagexml')">
                        <span class="export-card-title">🏛 Archival PAGE-XML (.xml)</span>
                        <span class="export-card-desc">PRImA 2019 standard XML compatible with Transkribus &amp; eScriptorium.</span>
                    </button>
                    <button type="button" class="export-card" style="border-color: var(--selection-border); background: var(--accent-soft);" onclick="StudioApp.exportFormat('zip')">
                        <span class="export-card-title" style="color: var(--accent);">⚡ Active Learning Dataset (.zip)</span>
                        <span class="export-card-desc">Complete archive bundling cropped PNG strips, <code>train_list.txt</code>, and <code>corrections.jsonl</code>.</span>
                    </button>
                </div>
            </div>
            <div class="modal-footer">
                <span style="font-size: 11.5px; color: var(--text-tertiary);">All Cham strings are exported in canonical Unicode Logical Order.</span>
                <button type="button" class="btn" onclick="StudioApp.closeModal('export-modal')">Close</button>
            </div>
        </div>
    </div>

    <!-- =====================================================================
         8. Architecture Overview & Keyboard Shortcuts Modal
         ===================================================================== -->
    <div class="modal-backdrop" id="about-modal">
        <div class="modal-dialog modal-wide">
            <div class="modal-header">
                <h2>🏛 Cham OCR Studio — System Architecture &amp; Keyboard Shortcuts</h2>
                <button type="button" class="btn btn-xs" onclick="StudioApp.closeModal('about-modal')">✕</button>
            </div>
            <div class="modal-body" style="line-height: 1.6; font-size: 13px;">
                <div style="padding: 12px 16px; background: var(--accent-soft); border-left: 4px solid var(--accent); border-radius: 6px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;">
                    <div>
                        <strong style="color: var(--text-primary);">Complete Peer-Style Technical Report Available</strong>
                        <div style="font-size: 12px; color: var(--text-secondary);">Explore mathematical formulations, DBNet polygon ribbon rectification, V24.1-R4 / V25 / V26 ablations, and multi-GPU scaling benchmarks.</div>
                    </div>
                    <a href="/research" target="_blank" rel="noopener noreferrer" class="btn btn-primary btn-sm">Read Full Technical Report ↗</a>
                </div>

                <div style="display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;">
                    <div style="padding: 12px; border: 1px solid var(--border-subtle); border-radius: 10px; background: var(--bg-elevated);">
                        <strong style="color: var(--accent);">1. Hybrid Cham-DBNet Polygon Segmentation</strong>
                        <p style="margin-top: 4px; color: var(--text-secondary); font-size: 12px;">
                            Combines Legacy-First quality gating with <code>Cham-DBNet v1_poly_u1.8</code> curved-ribbon rectification and neighbor-line masking, protecting delicate super/subscript vowel signs (<code>0.40 × median_line_height</code> cushion).
                        </p>
                    </div>
                    <div style="padding: 12px; border: 1px solid var(--border-subtle); border-radius: 10px; background: var(--bg-elevated);">
                        <strong style="color: var(--accent);">2. Masked-SVTR Recognition &amp; Tri-Specialist Routing</strong>
                        <p style="margin-top: 4px; color: var(--text-secondary); font-size: 12px;">
                            Deploys <strong>V26.1 Masked-SVTR</strong> (W=480 padding-masked WiSE-FT pure-Cham SOTA, 6/6 Gates, 2.07% real-camera crop CER) and the adaptive <strong>Auto Tri-Router v2.2</strong> (W=480 + W=320 + Vietnamese PP-OCRv5) with per-line recognizer provenance and Logical Order normalization.
                        </p>
                    </div>
                </div>

                <div>
                    <strong style="font-size: 13.5px;">Workbench Keyboard Shortcuts</strong>
                    <div style="display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; margin-top: 8px; font-size: 12px; color: var(--text-secondary);">
                        <div><span class="kbd-hint">Ctrl+K</span> Open Command Palette</div>
                        <div><span class="kbd-hint">Ctrl+Enter</span> Transcribe Active Folio</div>
                        <div><span class="kbd-hint">Ctrl+Shift+Enter</span> Batch Transcribe Queue</div>
                        <div><span class="kbd-hint">Alt+1..4</span> Switch Layout (3-Pane / Compare / Stacked / Reader)</div>
                        <div><span class="kbd-hint">Alt+K</span> Toggle Cham Virtual Keyboard</div>
                        <div><span class="kbd-hint">Alt+P / Alt+T / Alt+U</span> Stanza Flow / Romanization / Cluster Inspector</div>
                        <div><span class="kbd-hint">A / W</span> Verify Line / Flag Line for Review</div>
                        <div><span class="kbd-hint">S / M / R</span> Split at Caret / Merge Below / Re-OCR Line</div>
                        <div><span class="kbd-hint">D / P / L</span> Draw BBox / Toggle Polygons / Magnifier Loupe</div>
                        <div><span class="kbd-hint">[ / ]</span> Previous / Next Needs-Review Line</div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <span style="font-size: 12px; color: var(--text-tertiary);">Official Web Service: <a href="https://ocr.cham.asia" style="color:var(--accent);font-weight:600;">https://ocr.cham.asia</a></span>
                <button type="button" class="btn btn-primary" onclick="StudioApp.closeModal('about-modal')">Close</button>
            </div>
        </div>
    </div>

    <!-- =====================================================================
         9. System Runtime Logs Modal
         ===================================================================== -->
    <div class="modal-backdrop" id="logs-modal">
        <div class="modal-dialog">
            <div class="modal-header">
                <h2>🖥 System Runtime &amp; Telemetry Logs</h2>
                <button type="button" class="btn btn-xs" onclick="StudioApp.closeModal('logs-modal')">✕</button>
            </div>
            <div class="modal-body">
                <pre id="system-logs-container" style="font-family: var(--font-mono); font-size: 11.5px; line-height: 1.55; background: var(--bg-panel-soft); border: 1px solid var(--border-subtle); border-radius: 8px; padding: 12px; max-height: 360px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;"></pre>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn" onclick="StudioApp.clearLogs()">Clear Buffer</button>
                <button type="button" class="btn btn-primary" onclick="StudioApp.closeModal('logs-modal')">Close</button>
            </div>
        </div>
    </div>

    <!-- Toast Container -->
    <div class="toast-stack" id="toast-stack"></div>

    <!-- Modular Studio Scripts -->
    <script src="/static/js/transliteration.js?v=26.3.2"></script>
    <script src="/static/js/cham-keyboard.js?v=26.3.2"></script>
    <script src="/static/js/studio.js?v=26.3.2"></script>
</body>
</html>