:root {
  color-scheme: light dark;
  --canvas: #f0efeb;
  --surface: #fcfcfb;
  --well: #e9e7e1;
  --ink: #17171a;
  --ink-secondary: rgb(23 23 26 / 0.68);
  --line: rgb(23 23 26 / 0.12);
  --accent: #1478ce;
  --on-accent: #ffffff;
  --critical: #af4a42;
  --active: #fde9a8;
  --match: rgb(20 120 206 / 0.14);
  --speaker-0: #1478ce;
  --speaker-1: #8a5d16;
  --speaker-2: #2e7a5a;
  --speaker-3: #9a3f6e;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", Tahoma, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #121214;
    --surface: #1d1d21;
    --well: #26262b;
    --ink: #f3f3f1;
    --ink-secondary: rgb(243 243 241 / 0.64);
    --line: rgb(255 255 255 / 0.12);
    --accent: #57adea;
    --on-accent: #07131c;
    --critical: #dd7c72;
    --active: #5a4a12;
    --match: rgb(87 173 234 / 0.2);
    --speaker-0: #57adea;
    --speaker-1: #d8a05c;
    --speaker-2: #63be95;
    --speaker-3: #e08fb8;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.85em; background: var(--well); padding: 1px 4px; border-radius: 4px; overflow-wrap: anywhere; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.page { max-width: 72rem; margin: 0 auto; padding: 32px 16px 48px; }
.crumb { margin: 0 0 4px; font-size: 0.875rem; }
h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); line-height: 1.2; margin: 0 0 8px; letter-spacing: -0.01em; }
h2 { font-size: 1rem; line-height: 1.3; margin: 0 0 12px; }
.lede { margin: 0; max-width: 46rem; color: var(--ink-secondary); }
.hint { margin: 8px 0 0; font-size: 0.875rem; color: var(--ink-secondary); }
.hint:empty { display: none; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.files { margin: 24px 0 16px; }
.file-fields { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); }
.field label, .field-label { display: block; font-weight: 600; font-size: 0.9375rem; margin-bottom: 6px; }
input[type="file"] { display: block; max-width: 100%; font: inherit; font-size: 0.875rem; color: var(--ink-secondary); }
input[type="file"]::file-selector-button {
  font: inherit; font-weight: 600; color: var(--ink); background: var(--well);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; margin-inline-end: 10px; cursor: pointer;
}
.status { margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--line); font-size: 0.9375rem; }
.status:empty { display: none; }
.status.is-error { color: var(--critical); }

.layout { display: grid; gap: 16px; }
.controls { display: grid; gap: 16px; align-content: start; min-width: 0; }
@media (min-width: 40rem) and (max-width: 59.99rem) {
  .controls { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .controls > :last-child { grid-column: 1 / -1; }
}
@media (min-width: 60rem) {
  .layout { grid-template-columns: minmax(0, 24rem) minmax(0, 1fr); align-items: start; }
  .controls { position: sticky; top: 16px; }
}

.button {
  font: inherit; font-size: 0.9375rem; font-weight: 600; color: var(--ink); background: var(--well);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
.button.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.button:disabled { opacity: 0.5; cursor: default; }

.simulated { display: grid; gap: 12px; }
.simulated .button { justify-self: start; }
.scrubber { display: flex; align-items: center; gap: 12px; min-width: 0; }
.scrubber input { flex: 1; min-width: 0; margin: 0; accent-color: var(--accent); }
.time { font-size: 0.875rem; color: var(--ink-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.media-slot video, .media-slot audio { display: block; width: 100%; border-radius: 8px; }
.media-slot video { max-height: 50vh; background: #000; }

.caption {
  margin: 0; min-height: calc(2 * 1.8em + 24px); padding: 12px 14px; border-radius: 8px; background: var(--well);
  font-size: 1.3rem; line-height: 1.8; text-align: center;
}
.caption .speaker { font-size: 0.75rem; }
.caption-note { font-size: 0.875rem; color: var(--ink-secondary); }
.caption + .hint { margin-bottom: 12px; }

.search-input {
  display: block; width: 100%; font: inherit; color: var(--ink); background: var(--canvas);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.results { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; max-height: 16rem; overflow-y: auto; }
.results:empty { display: none; }
.results button {
  display: flex; align-items: baseline; gap: 10px; width: 100%; font: inherit; color: var(--ink); text-align: start;
  background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.results button:hover { background: var(--well); }
.snippet { flex: 1; min-width: 0; font-size: 1.05rem; line-height: 1.7; }
mark { background: var(--active); color: inherit; border-radius: 3px; padding: 0 2px; }

.transcript-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 4px; }
.transcript-head h2 { margin: 0; }
.meta { margin: 0; font-size: 0.875rem; color: var(--ink-secondary); }
.turns { font-size: 1.25rem; line-height: 2; }
.turns .empty { margin: 8px 0 0; font-size: 0.9375rem; line-height: 1.5; color: var(--ink-secondary); }
.turn { padding: 12px 0; border-top: 1px solid var(--line); }
.turn:first-child { border-top: 0; }
.turn-head { display: flex; align-items: center; gap: 8px; font-size: 0.8125rem; line-height: 1.4; }
.turn-time {
  font: inherit; color: var(--ink-secondary); font-variant-numeric: tabular-nums;
  background: none; border: 0; border-radius: 4px; padding: 2px 4px; cursor: pointer;
}
.turn-time:hover { color: var(--accent); text-decoration: underline; }
.turn-text { margin: 2px 0 0; overflow-wrap: anywhere; }

.speaker { font-weight: 600; font-size: 0.8125rem; color: var(--speaker-0); }
.speaker-1 { color: var(--speaker-1); }
.speaker-2 { color: var(--speaker-2); }
.speaker-3 { color: var(--speaker-3); }

.word { cursor: pointer; border-radius: 4px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.word:hover { background: var(--well); }
.word.is-match { background: var(--match); box-shadow: inset 0 -2px 0 var(--accent); }
.word.is-active, .cue-word.is-active { background: var(--active); box-shadow: none; border-radius: 4px; }

.source { margin-top: 32px; font-size: 0.875rem; color: var(--ink-secondary); }
.source p { margin: 0; max-width: 46rem; }

@media (prefers-reduced-motion: no-preference) {
  .word, .cue-word { transition: background-color 0.08s linear; }
}
