/* ============================================================
   Speech Elf
   An artsy little voice-clinic studio: cursive display type,
   soft rounded UI, calm teal + warm amber accents.
   Light and dark themes via [data-theme] on <html>.
   Display font: Parisienne (cursive) with a system-cursive
   fallback so the app still looks intentional offline.
   ============================================================ */

:root,
:root[data-theme="light"] {
  --paper:   #F4F7F6;
  --paper-2: #EAF1EF;
  --card:    #FFFFFF;
  --ink:     #1C2B2D;
  --muted:   #5F7271;
  --line:    #D9E2E0;
  --teal:    #2E6E6A;
  --teal-dark: #235451;
  --teal-soft: #EAF4F2;
  --amber:   #D99021;
  --danger:  #B3432B;
  --shadow:  0 10px 30px rgba(28, 43, 45, 0.08);
}

:root[data-theme="dark"] {
  --paper:   #101817;
  --paper-2: #16201F;
  --card:    #1A2625;
  --ink:     #E8F0EE;
  --muted:   #97AAA8;
  --line:    #2A3938;
  --teal:    #5FB8B0;
  --teal-dark: #82CFC7;
  --teal-soft: #1E2E2C;
  --amber:   #E7AE54;
  --danger:  #E0735A;
  --shadow:  0 10px 30px rgba(0, 0, 0, 0.45);
}

:root {
  --font-ui: "Quicksand", system-ui, -apple-system, "Segoe UI", Roboto,
             "Noto Sans", "Nirmala UI", "Latha", sans-serif;
  --font-display: "Parisienne", "Snell Roundhand", "Brush Script MT",
                  "Segoe Script", cursive;
  --font-ipa: "Charis SIL", "Doulos SIL", "Gentium Plus", Georgia,
              "Times New Roman", "Nirmala UI", serif;
  --radius: 14px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 380px at 12% -8%, var(--teal-soft), transparent 60%),
    radial-gradient(700px 320px at 100% 0%, var(--paper-2), transparent 55%),
    var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* ---------- Masthead ---------- */

.masthead {
  max-width: 880px;
  margin: 0 auto;
  padding: 38px 24px 0;
}

.masthead-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  font-size: 1.9rem;
  color: var(--amber);
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(217, 144, 33, 0.35));
}

.masthead h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 3.4rem;
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: 0.01em;
  color: var(--teal-dark);
}

.masthead-ipa {
  margin: 4px 0 0;
  font-family: var(--font-ipa);
  color: var(--muted);
  font-size: 0.95rem;
  font-style: italic;
}

/* ---------- Theme toggle ---------- */

.theme-toggle {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
  flex: none;
}
.theme-toggle:hover { transform: rotate(-12deg) scale(1.05); border-color: var(--teal); }

.masthead-controls { display: flex; align-items: center; gap: 10px; }

.logout-btn { color: var(--muted); }
.logout-btn:hover { transform: none; color: var(--danger); border-color: var(--danger); }
.logout-btn.hidden { display: none; }
.theme-icon { display: none; line-height: 1; }
:root[data-theme="light"] .theme-icon-moon { display: block; color: var(--teal); }
:root[data-theme="dark"]  .theme-icon-sun  { display: block; color: var(--amber); }

.wave {
  display: block;
  width: 100%;
  height: 30px;
  margin-top: 16px;
  color: var(--amber);
  opacity: 0.85;
}

/* ---------- Tabs ---------- */

.tabs {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 12px 18px 10px;
  font-family: var(--font-ui);
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  transition: color 0.15s ease;
}

.tab small {
  display: block;
  font-family: var(--font-ipa);
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--muted);
  opacity: 0.7;
}

.tab.active {
  color: var(--ink);
  border-bottom-color: var(--teal);
}
.tab:hover { color: var(--ink); }

.tab:focus-visible,
.btn:focus-visible,
select:focus-visible,
textarea:focus-visible,
.dropzone:focus-visible,
.theme-toggle:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ---------- Layout ---------- */

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.panel { display: none; animation: fade 0.25s ease; }
.panel.active { display: block; }
.hidden { display: none !important; }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* ---------- Form pieces ---------- */

/* Bottom-align the fields so selects/inputs line up even when one label
   wraps to two lines (e.g. the Key terms hint on narrower screens). */
.controls-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 10px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field.block { width: 100%; margin-bottom: 18px; }
.field.grow { flex: 1 1 260px; min-width: 240px; } /* fills the rest of the row */

.field-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--muted);
}

.hint-line {
  margin: 0 0 18px;
  font-size: 0.85rem;
  color: var(--muted);
}

select, textarea, input[type="text"] {
  font-family: var(--font-ui);
  font-size: 1rem;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  transition: border-color 0.15s ease, background-color 0.25s ease;
}

input[type="text"] { width: 100%; }

.field-hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  font-size: 0.78rem;
  opacity: 0.85;
}

select { min-width: 230px; }

textarea {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  line-height: 1.7;
}

/* ---------- Dropzone ---------- */

.dropzone {
  background: var(--card);
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--teal);
  background: var(--teal-soft);
  transform: translateY(-1px);
}

.dz-title { margin: 0; font-size: 1.08rem; font-weight: 600; }
.dz-hint { margin: 6px 0 0; color: var(--muted); font-size: 0.85rem; }
.dz-file { margin: 12px 0 0; font-weight: 700; color: var(--teal-dark); }
.dz-file:empty { display: none; }

/* ---------- Job list (bulk transcribe) ---------- */

#jobs { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }

.job {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.job-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.job-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.job-name { font-weight: 700; word-break: break-word; }
.job-status { font-size: 0.85rem; color: var(--muted); }
.job-status.err { color: var(--danger); }

.job-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.job-actions .btn { padding: 6px 12px; font-size: 0.85rem; }

.job-transcript {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  font-size: 1.02rem;
  line-height: 1.6;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--font-ui);
  color: var(--ink);
}

.job-sublabel {
  margin: 12px 0 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--teal-dark);
}

.job-tanglish {
  width: 100%;
  min-height: 70px;
  resize: vertical;
  font-size: 0.98rem;
  line-height: 1.6;
  background: var(--teal-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--font-ui);
  color: var(--ink);
}

.job-segments {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  max-height: 220px;
  overflow-y: auto;
}

/* ---------- Buttons & status ---------- */

.actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 18px 0;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid var(--teal);
  color: var(--teal-dark);
  background: var(--card);
  border-radius: 999px;
  padding: 9px 20px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}

.btn:hover:not(:disabled) { background: var(--teal-soft); }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn.primary {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
  box-shadow: 0 6px 16px rgba(46, 110, 106, 0.3);
}
.btn.primary:hover:not(:disabled) { background: var(--teal-dark); }
:root[data-theme="dark"] .btn.primary { color: #0c1413; }

.btn.ghost { border-color: var(--line); color: var(--muted); background: transparent; }
.btn.ghost:hover:not(:disabled) { color: var(--ink); background: var(--teal-soft); }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.status { color: var(--muted); font-size: 0.92rem; }
.status.error { color: var(--danger); }

/* ---------- Results ---------- */

.result {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-top: 8px;
  box-shadow: var(--shadow);
}

.result-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.result-head h2 { margin: 0; font-size: 1.15rem; }
.meta { font-weight: 400; color: var(--muted); font-size: 0.85rem; }

.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.segments { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }

.segment {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  padding: 6px 0;
  font-size: 0.95rem;
}
.segment.has-rom { grid-template-columns: 110px 1fr; }
.segment .seg-text { display: flex; flex-direction: column; gap: 2px; }
.segment .seg-rom { color: var(--muted); font-size: 0.86rem; font-style: italic; }

/* Clickable timestamp → seeks the player. */
.seg-time {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--teal-dark);
  font-family: var(--font-ui);
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  padding: 2px 6px;
  border-radius: 7px;
  cursor: pointer;
  height: fit-content;
  transition: background 0.12s, border-color 0.12s;
}
.seg-time:hover { background: var(--teal-soft); border-color: var(--teal); }

/* ---------- Per-job media player ---------- */

.job-media {
  width: 100%;
  margin: 4px 0 12px;
  border-radius: 10px;
  background: var(--teal-soft);
}
audio.job-media { height: 40px; }
video.job-media { max-height: 320px; display: block; }

/* ---------- IPA / Tanglish output ---------- */

.ipa-block {
  font-family: var(--font-ipa);
  font-size: 1.25rem;
  line-height: 1.9;
  background: var(--teal-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.tanglish-block { margin-top: 18px; }
.tanglish-text {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.7;
  background: var(--teal-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 18px;
}

.words-title {
  margin: 22px 0 10px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
}

.word-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--card);
}

.word-card .w { font-size: 0.92rem; }
.word-card .p {
  font-family: var(--font-ipa);
  color: var(--teal-dark);
  font-size: 1.05rem;
}

/* ---------- Morphology tab ---------- */

.morph-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--card);
  text-align: center;
}
.stat-value { font-size: 1.25rem; font-weight: 700; color: var(--teal-dark); }
.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-top: 2px;
}

.utt-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.utt-head { margin-bottom: 8px; }
.utt-text { font-size: 0.98rem; font-weight: 600; margin-bottom: 6px; }
.utt-counts { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  display: inline-block;
  font-size: 0.74rem;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--muted);
}
.chip-noun { background: var(--teal-soft); color: var(--teal-dark); border-color: var(--teal); }
.chip-verb { background: var(--teal-soft); color: var(--amber); border-color: var(--amber); }
.chip-tense { color: var(--ink); }

.morph-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}
.morph-table th {
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
.morph-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.morph-table tr:last-child td { border-bottom: none; }
.morph-table .w-cell { font-weight: 600; }
.morph-table .feat-cell { color: var(--muted); font-size: 0.78rem; word-break: break-word; }
.pos-noun { color: var(--teal-dark); font-weight: 600; }
.pos-verb { color: var(--amber); font-weight: 600; }
.pos-unknown { color: var(--danger); }

#morph-hint { color: var(--muted); font-size: 0.85rem; margin: 4px 0 10px; }
#morph-hint code {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 4px;
}
#morph-input { min-height: 140px; }

/* ---------- Footer ---------- */

footer {
  max-width: 880px;
  margin: 0 auto;
  padding: 8px 24px 48px;
  color: var(--muted);
  font-size: 0.85rem;
}
footer p { margin: 2px 0; }
footer .footnote {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--teal);
  opacity: 0.9;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media (max-width: 560px) {
  .masthead h1 { font-size: 2.6rem; }
  .segment { grid-template-columns: 80px 1fr; }
  select { min-width: 100%; }
}

/* ---------- Live dictation ---------- */

/* The mic floats inside the textarea's top-right corner, so dictation
   takes no vertical space of its own. */
.field.block { position: relative; }

.field-head {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
}

.dict-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Keep typed/placeholder text clear of the floating mic. */
.field-head + textarea { padding-right: 56px; }

/* Status sits left of the mic, over the textarea — give it a readable
   backdrop, and remove it (and its gap) when empty. */
.dict-inline .status {
  max-width: min(420px, 60vw);
  text-align: right;
  line-height: 1.35;
  background: var(--card);
  border-radius: 8px;
  padding: 3px 8px;
}
.dict-inline .status:empty { display: none; }

/* Round icon-only mic button. */
.mic-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--teal);
  cursor: pointer;
  flex: none;
  box-shadow: 0 2px 8px rgba(28, 43, 45, 0.12); /* lift off the textarea */
  transition: background-color 0.2s ease, border-color 0.2s ease,
              color 0.2s ease;
}

.mic-btn:hover { background: var(--teal-soft); border-color: var(--teal); }
.mic-btn:active { transform: translateY(1px); }
.mic-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.mic-btn.recording,
.mic-btn.recording:hover {
  background: #D93A2B;
  border-color: #D93A2B;
  color: #fff;
  animation: mic-pulse 1.6s ease-out infinite;
}

@keyframes mic-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(217, 58, 43, 0.45); }
  70%  { box-shadow: 0 0 0 12px rgba(217, 58, 43, 0); }
  100% { box-shadow: 0 0 0 0 rgba(217, 58, 43, 0); }
}

.dict-inline .status { font-size: 0.82rem; }

/* ============================================================
   OCR tab
   ============================================================ */

/* ---------- Notices ---------- */

.notice {
  border: 1px solid var(--amber);
  background: color-mix(in srgb, var(--amber) 12%, transparent);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.notice p { margin: 0 0 6px; }
.notice p:last-child { margin-bottom: 0; }
.notice code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  background: var(--paper-2);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.86em;
}

/* ---------- Presets ---------- */

.preset-row { margin-bottom: 14px; }
.preset-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

.preset-chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 16px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
}

.preset-chip:hover { color: var(--ink); border-color: var(--teal); }

.preset-chip.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.preset-hint {
  margin: 8px 0 0;
  font-size: 0.84rem;
  color: var(--muted);
  min-height: 1.2em;
}

/* ---------- Language chips ---------- */

.chip-group { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.86rem;
  cursor: pointer;
  user-select: none;
  transition: all 0.18s ease;
}

.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip:hover { border-color: var(--teal); }

.chip:has(input:checked) {
  background: var(--teal-soft);
  border-color: var(--teal);
  color: var(--teal-dark);
  font-weight: 700;
}

.chip:has(input:focus-visible) { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ---------- Settings boxes ---------- */

.settings-box {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.settings-title {
  margin: 0 0 12px;
  font-weight: 700;
  font-size: 0.95rem;
}

.settings-box.advanced { padding: 0; }

.settings-box.advanced summary {
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.95rem;
  list-style: none;
}

.settings-box.advanced summary::-webkit-details-marker { display: none; }

.settings-box.advanced summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  color: var(--teal);
  transition: transform 0.2s ease;
}

.settings-box.advanced[open] summary::before { transform: rotate(90deg); }
.settings-box.advanced > *:not(summary) { padding: 0 18px 16px; }

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.toggle:hover { border-color: var(--teal); background: var(--teal-soft); }
.toggle:has(input:checked) { border-color: var(--teal); background: var(--teal-soft); }
.toggle input { margin-top: 3px; accent-color: var(--teal); flex: none; }
.toggle span { display: flex; flex-direction: column; line-height: 1.3; }
.toggle strong { font-size: 0.88rem; font-weight: 700; }
.toggle em { font-size: 0.76rem; color: var(--muted); font-style: normal; }

.slider-field { margin-top: 14px; max-width: 320px; }
.slider-field input[type="range"] { accent-color: var(--teal); width: 100%; }

/* ---------- Job cards ---------- */

#ocr-jobs { display: flex; flex-direction: column; gap: 16px; margin-top: 6px; }

.ocr-progress {
  height: 4px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0 4px;
}

.ocr-progress-fill {
  height: 100%;
  width: 0;
  background: var(--teal);
  transition: width 0.25s ease;
}

/* ---------- Summary stats ---------- */

.ocr-summary { margin: 14px 0 4px; }

.ocr-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.ocr-stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--paper-2);
  border-radius: 10px;
  padding: 9px 12px;
}

.ocr-stat-value { font-weight: 700; font-size: 0.98rem; word-break: break-word; }
.ocr-stat-label { font-size: 0.74rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.ocr-stat-hint  { font-size: 0.74rem; color: var(--muted); }

.conf-bar {
  display: flex;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
  background: var(--line);
}

.conf-seg { display: block; height: 100%; }
.conf-0,  .key.conf-0  { background: #C6503A; }
.conf-50, .key.conf-50 { background: #E09A3E; }
.conf-70, .key.conf-70 { background: #D9C64B; }
.conf-85, .key.conf-85 { background: #7FB069; }
.conf-95, .key.conf-95 { background: #3E8E5A; }

.conf-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin: 8px 0 0;
  font-size: 0.74rem;
  color: var(--muted);
}

.conf-legend .key {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-left: 8px;
}

.conf-legend .key:first-child { margin-left: 0; }

/* ---------- Sub-tabs ---------- */

.subtabs {
  display: flex;
  gap: 4px;
  margin: 16px 0 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.subtab {
  border: none;
  background: none;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.subtab:hover { color: var(--ink); }
.subtab.active { color: var(--teal-dark); border-bottom-color: var(--teal); }

.ocr-body { padding-top: 14px; }
.ocr-view { animation: fade 0.2s ease; }

.ocr-text {
  width: 100%;
  min-height: 320px;
  resize: vertical;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  line-height: 1.6;
}

.ocr-text:focus { outline: 2px solid var(--teal); outline-offset: -1px; }

/* ---------- Pages view ---------- */

.ocr-page {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
  background: var(--paper-2);
}

.ocr-page.err { border-color: var(--danger); }

.ocr-page h4 {
  margin: 0 0 10px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.badge-digital { background: var(--teal-soft); color: var(--teal-dark); border-color: var(--teal); }
.badge-ocr { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); border-color: var(--amber); }

table.kv { border-collapse: collapse; width: 100%; font-size: 0.84rem; }
table.kv th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  padding: 3px 12px 3px 0;
  white-space: nowrap;
  width: 190px;
  vertical-align: top;
}
table.kv td { padding: 3px 0; word-break: break-word; }

.flagged { margin-top: 10px; font-size: 0.84rem; }
.flagged summary { cursor: pointer; color: var(--danger); font-weight: 600; }
.flag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.flag-word {
  border: 1px solid var(--danger);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.82rem;
}

.flag-word em { color: var(--muted); font-style: normal; font-size: 0.76rem; }

.ocr-page-text {
  margin: 12px 0 0;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  max-height: 340px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.88rem;
  line-height: 1.6;
}

/* ---------- Words table ---------- */

.table-scroll { max-height: 520px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }

table.word-table { border-collapse: collapse; width: 100%; font-size: 0.82rem; }

table.word-table thead th {
  position: sticky;
  top: 0;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 8px 10px;
  font-weight: 700;
  z-index: 1;
}

table.word-table td { padding: 5px 10px; border-bottom: 1px solid var(--line); }
table.word-table tbody tr:hover { background: var(--teal-soft); }
table.word-table tr.low { background: color-mix(in srgb, var(--danger) 8%, transparent); }
table.word-table .w-text { font-weight: 600; word-break: break-word; }

/* ---------- Overlay view ---------- */

.overlay-page { margin-bottom: 20px; }
.overlay-page h4 { margin: 0 0 8px; font-size: 0.95rem; display: flex; gap: 10px; align-items: baseline; }

.overlay-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  line-height: 0;
}

.overlay-wrap img { display: block; max-width: 100%; height: auto; }

.obox {
  position: absolute;
  border: 1.5px solid;
  border-radius: 2px;
  pointer-events: auto;
  cursor: help;
}

.obox:hover { background: rgba(46, 110, 106, 0.25); }
.obox.c0  { border-color: #C6503A; }
.obox.c50 { border-color: #E09A3E; }
.obox.c70 { border-color: #D9C64B; }
.obox.c85 { border-color: #7FB069; }
.obox.c95 { border-color: rgba(62, 142, 90, 0.55); }

/* ---------- JSON view ---------- */

.json-block {
  margin: 0;
  padding: 14px 16px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  max-height: 560px;
  overflow: auto;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.55;
  white-space: pre;
}

@media (max-width: 620px) {
  .ocr-stats { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  table.kv th { width: auto; }
}
