/* The page's own styles. Copied into site/dist/ under a content-hashed name by
   scripts/build-site.mjs -- see the note there about why the name is hashed.

   Tokens live here for now because there is only one consumer. When the UI
   grows a component with a shadow root, they move to src/web/tokens.js and this
   file consumes them instead of defining them: two token lists that must agree
   but are not the same list is the same footgun the CSP generator avoids. */

:root {
  color-scheme: light dark;

  --bg: #12110f;
  --fg: #eae6df;
  --muted: #9c968c;
  --accent: #d8a657;
  --line: #2b2825;
  --error: #e0685a;

  --sp-1: 0.5rem;
  --sp-2: 1rem;
  --sp-3: 1.5rem;
  --sp-4: 2.5rem;

  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* The light half of `color-scheme: light dark` above. Same token names, so
   every rule that consumes them -- including src/web/waveform.js, which
   reads colors back via getComputedStyle -- repaints with no other change. */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf8f4;
    --fg: #201d18;
    --muted: #756e62;
    --accent: #9a6a1f;
    --line: #ded7c9;
    --error: #b3392b;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
}

#app {
  max-width: 60rem;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-3);
}

h1 {
  margin: 0 0 var(--sp-3);
  font-size: 1.75rem;
  letter-spacing: -0.02em;
  color: var(--accent);
}

noscript p {
  max-width: 40rem;
  margin: var(--sp-4) auto;
  padding: 0 var(--sp-3);
  color: var(--muted);
}

/* The file chooser: a styled <label> wrapping a real <input type="file">.
   The input itself is moved off-screen rather than given display:none, because
   a display:none form control is removed from the tab order and from the
   accessibility tree, and the label would then be a thing only a mouse can
   operate. */

.chooser {
  display: inline-block;
  padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  cursor: pointer;
  transition: background-color 140ms ease-out;
}

.chooser:hover,
.chooser:focus-within {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* The focus ring belongs on the label, since that is what is visibly being
   operated -- the input it decorates is off-screen. */
.chooser:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chooser-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.status {
  margin: var(--sp-2) 0;
  font-family: var(--mono);
  font-size: 0.875rem;
  color: var(--muted);
}

/* A decode or transcription failure, as opposed to ordinary progress text --
   the two were previously indistinguishable, both rendering in --muted. */
.status.is-error {
  color: var(--error);
}

/* The waveform and its playhead.

   The canvas is drawn once per file and once per resize; the playhead is this
   element, positioned from a custom property written every animation frame by
   src/web/player.js. That division is the reason playback does not repaint a
   few thousand rectangles sixty times a second -- and the reason the generated
   CSP grants style-src 'unsafe-inline'. */

.waveform {
  position: relative;
  height: 10rem;
  margin-bottom: var(--sp-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  background: color-mix(in srgb, var(--fg) 3%, transparent);
  cursor: crosshair;
  touch-action: none;
}

.waveform.is-dropping {
  border-color: var(--accent);
}

.waveform-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  /* A percentage of the element's own width, so the browser re-resolves the
     position on every layout. A resize therefore moves the playhead with no
     JavaScript running; writing pixels here would need a resize listener whose
     only job was to correct a number that did not need to be one. */
  left: calc(var(--playhead, 0) * 100%);
  width: 2px;
  margin-left: -1px;
  background: var(--fg);
  /* Clicks are handled by the surface underneath. Without this the playhead
     swallows every click that lands on it, so seeking fails precisely where
     the user is already looking. */
  pointer-events: none;
}

.transport {
  width: 100%;
}

/* States the two gestures a transcript supports that no element on its own
   makes visible: double-click to correct a word, drag the ⋮ to move a
   boundary. Shown once, next to the transcript, rather than relying on
   someone finding either by accidental hover. */
.transcript-hint {
  margin: 0 0 var(--sp-1);
  font-size: 0.8125rem;
  color: var(--muted);
}

.transcript-hint:empty {
  display: none;
}

/* The transcript: one <p> per segment, one clickable <span> per word.
   Scrollable rather than growing the page without bound -- a long recording
   produces a transcript much taller than the waveform above it. */

.transcript {
  max-height: 16rem;
  margin: var(--sp-2) 0;
  padding: var(--sp-2);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.transcript:empty {
  display: none;
}

.transcript-segment {
  margin: 0 0 var(--sp-1);
}

.transcript-segment:last-child {
  margin-bottom: 0;
}

.transcript-word {
  cursor: pointer;
  border-radius: 3px;
  /* Present at rest, not only on hover -- a dotted underline is the
     difference between "clickable" and "plain text," which nothing else
     about a <span> communicates. */
  border-bottom: 1px dotted color-mix(in srgb, var(--muted) 60%, transparent);
  transition: background-color 140ms ease-out;
}

.transcript-word:hover {
  background: color-mix(in srgb, var(--fg) 8%, transparent);
}

/* The word under the playhead. Accent-based, the same signal .action:hover
   already uses for "this is the thing that's active." */
.transcript-word.is-current {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--fg);
}

/* The word being corrected: an <input> swapped in for its <span> for the
   life of a double-click edit. Sized and coloured to read as "this word
   became editable," not as a form appearing in running text. */
.transcript-word-input {
  width: auto;
  min-width: 2ch;
  padding: 0 2px;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--fg);
  font: inherit;
}

/* The split control: a sliver between two words. Its full-width fill only
   appears on hover or focus, so the transcript does not read as perforated
   at every word boundary while idle -- but a faint rest-state mark (below)
   still makes it findable by scanning rather than only by accidental hover. */
.transcript-split {
  display: inline-block;
  position: relative;
  width: 0.75rem;
  height: 1em;
  vertical-align: middle;
  margin: 0 -0.375rem;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: transparent;
  cursor: col-resize;
  transition: background-color 140ms ease-out;
}

/* A faint mark at rest -- findable by scanning the transcript, not only by
   an accidental hover -- that brightens into the full hover/focus fill. */
.transcript-split::after {
  content: '';
  position: absolute;
  top: 15%;
  bottom: 15%;
  left: 50%;
  width: 1px;
  background: color-mix(in srgb, var(--muted) 45%, transparent);
}

.transcript-split:hover,
.transcript-split:focus-visible {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}

.transcript-split:hover::after,
.transcript-split:focus-visible::after {
  background: transparent;
}

/* Low-confidence words: dimmed, and given a warning-coloured underline
   instead of the neutral one every word gets at rest. Absent confidence
   (whisper didn't report one) draws with neither -- an unknown is not a low
   score. */
.transcript-word.is-low-confidence {
  opacity: 0.6;
  border-bottom-color: color-mix(in srgb, var(--error) 55%, transparent);
}

/* The insert control: a slot before every word and after the last one --
   unlike split, it is valid at a segment's very first and very last gap too,
   since a new word can be added at either edge. Same rest-state idiom as
   .transcript-split: invisible until found. */
.transcript-insert {
  display: inline-block;
  position: relative;
  width: 0.75rem;
  height: 1em;
  vertical-align: middle;
  margin: 0 -0.375rem;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: transparent;
  cursor: text;
  transition: background-color 140ms ease-out;
}

.transcript-insert::after {
  content: '+';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.7em;
  line-height: 1;
  color: color-mix(in srgb, var(--muted) 45%, transparent);
}

.transcript-insert:hover,
.transcript-insert:focus-visible {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}

.transcript-insert:hover::after,
.transcript-insert:focus-visible::after {
  color: var(--fg);
}

/* Between segments: the drag handle and the merge control share this row,
   the way controls sharing a boundary in a timeline editor usually do -- one
   strip of affordances rather than two competing for the same pixels. */
.transcript-boundary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  height: 1.75rem;
  color: var(--muted);
}

.transcript-boundary-handle,
.transcript-merge {
  padding: var(--sp-1) var(--sp-1);
  border: 1px dashed var(--line);
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color 140ms ease-out, color 140ms ease-out;
}

.transcript-boundary-handle {
  cursor: row-resize;
  /* Bigger than its glyph alone -- ⋮ in a one-line row is a hard target to
     land a drag on; the padding above widens it without changing the row's
     visual weight. */
  min-width: 2rem;
}

.transcript-boundary-handle::before {
  content: '⋮';
}

.transcript-boundary-handle:hover,
.transcript-boundary-handle.is-dragging,
.transcript-merge:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.transcript-boundary-handle:focus-visible,
.transcript-merge:focus-visible,
.transcript-split:focus-visible,
.transcript-insert:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* The engine's controls: which model, transcribe, and the two exports.
   One row that wraps, rather than a grid -- there are five controls and the
   only relationship between them is left-to-right order. */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-2);
  margin: var(--sp-3) 0 var(--sp-2);
}

.field-label {
  font-size: 0.875rem;
  color: var(--muted);
}

.model-select,
.action {
  padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  background: color-mix(in srgb, var(--fg) 4%, transparent);
  color: var(--fg);
  font: inherit;
  font-size: 0.9375rem;
  transition: background-color 140ms ease-out, border-color 140ms ease-out, color 140ms ease-out;
}

.action {
  cursor: pointer;
}

.action:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

/* Transcribe is the one control that moves the page from "nothing happened
   yet" to "there's a transcript" -- everything else (the two downloads) only
   makes sense after it, so it carries the accent fill they don't. */
.action.is-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--bg);
}

.action.is-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 85%, var(--fg));
  color: var(--bg);
}

/* Cancel: the same --error token .status.is-error already uses, so a
   cancellable run and a failed one read as related states, not two
   unrelated colours invented for this one button. */
.action.is-danger {
  border-color: var(--error);
  color: var(--error);
}

.action.is-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--error) 12%, transparent);
  border-color: var(--error);
  color: var(--error);
}

/* Disabled controls are dimmed rather than hidden. Every one of them is
   disabled for a reason the status line states -- no file open, no transcript
   yet -- and a control that vanishes leaves that sentence answering a question
   about something the reader can no longer see. */
.action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.model-select:focus-visible,
.action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Full width, because what it measures is the width of the page: a download of
   tens of megabytes and then a transcription of a whole recording. Hidden
   between runs via the `hidden` attribute rather than a class, so it is out of
   the accessibility tree as well as out of the layout. */
.progress {
  width: 100%;
  height: 0.5rem;
  margin-bottom: var(--sp-1);
}

/* Two short lines that belong next to the controls they explain: whether the
   selected model needs downloading, and whether this host runs single- or
   multi-threaded. Grouped so both can be visible at once (a plausible first
   visit: an uncached model on a non-isolated host) without each fighting the
   controls row for its own line. */
.control-hints {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin: 0 0 var(--sp-1);
}

.model-hint,
.speed-hint {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.model-hint:empty,
.speed-hint:empty {
  display: none;
}
