/* ===========================================================================
   The Good Bits

   ONE palette, ONE layout, TWO densities.

   There is deliberately no theme system here any more. Three parallel themes
   (Classic / Terminal / Console) meant none of them got audited, and two of
   the three shipped body text below the 4.5:1 readable minimum. Everything
   below derives from the single token block at the top, and test/contrast
   .test.mjs fails the build if any text role drops under 4.5:1 against the
   surface it sits on.

   The app has one layout and three TASKS - chop, stretch, both - set as
   data-task on <html>. A task decides which settings sections are mounted
   (see the TASK section near the bottom); it is not a separate layout or a
   separate stylesheet. The settings rail is disclosure, tracked separately as
   data-rail, so "which task" and "how much do I want to see" stay independent.
   =========================================================================== */

:root {
  /* surfaces, darkest to lightest */
  --bg: #0c0d0f;
  --bg-panel: #141619;
  --bg-raised: #1c1f23;
  --bg-raised-hover: #242830;
  --border: #2b2f36;
  --border-soft: #1f2228;

  /* ink */
  --text: #eceef1;
  --text-dim: #a8afb7;
  --text-faint: #8a929a;

  /* accent - a signal red. Note the fill uses near-black ink, not white:
     white on this red is only 3.32:1, near-black is 5.82:1. */
  --accent: #ff4b3b;
  --accent-2: #ff8266;
  --accent-dim: #7d2b22;
  --on-accent: #1a0906;

  /* semantic, kept distinct from the accent hue */
  --good: #4fc98a;
  --warn: #e8b95c;
  --danger: #ff6b81;

  --radius: 7px;
  --radius-sm: 5px;

  --font-display: "Barlow Semi Condensed", "Arial Narrow", sans-serif;
  --font-body: "Barlow", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Canvas-drawn waveforms read these directly in JS (see themeColor() in
     app.js), so they must stay custom properties rather than literals. */
  --wave-bg: #0a0b0d;
  --wave-fill: #5b6670;
  --wave-line: rgba(236, 238, 241, 0.45);
  --wave-handle: #eceef1;
  --wave-marker: #ff4b3b;
  --wave-region-a: rgba(255, 75, 59, 0.09);
  --wave-region-b: rgba(255, 130, 102, 0.07);
  --wave-region-sel: rgba(255, 75, 59, 0.16);
  --log-bg: #08090b;
  --log-text: #a8afb7;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05em 0.35em;
  color: var(--text-dim);
}

/* ===========================================================================
   APP SHELL
   Fixed chrome top and bottom, one scrolling stage in the middle, so the
   controls and the Process button never scroll away from the audio.
   =========================================================================== */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------- top bar ---------- */

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 50px;
  padding: 0 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

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

.brand {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: white;
  text-decoration: none;
}

.brand-accent { color: var(--accent); }

.brand:hover {
  opacity: 0.8;
}

.brand:focus-visible {
  outline: 1px solid white;
  outline-offset: 2px;
}

.version-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
  font-variant-numeric: tabular-nums;
}

/* Lives in the settings rail (see "Source material" in index.html) - a 3-column grid rather than
   an auto-width row so it fits the rail's fixed width without wrapping oddly. */
.mode-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }

.mode-btn {
  font: inherit;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
  padding: 7px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--text-dim);
  cursor: pointer;
  transition: color .14s ease, background .14s ease, border-color .14s ease;
}

.mode-btn:hover { color: var(--text); background: var(--bg-raised-hover); }

.mode-btn.mode-card--active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.seg {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.seg-btn {
  font: inherit;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  padding: 6px 12px;
  border: none;
  background: var(--bg-raised);
  color: var(--text-faint);
  cursor: pointer;
  transition: color .14s ease, background .14s ease;
}

.seg-btn:hover { color: var(--text); }
.seg-btn.is-active { background: var(--accent); color: var(--on-accent); font-weight: 500; }

.btn--loop.is-active {
  background: var(--accent);
  color: var(--on-accent);
}

/* ---------- control modules (Advanced only) ---------- */

/* Rail and workspace sit side by side and fill what's left between the header
   and the action bar; each scrolls independently. */
.body { flex: 1; min-height: 0; display: flex; }

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }

/* The settings rail.
   This was a multi-column strip across the top, and it was wrong twice over: it
   ate half the window height on a laptop, and a grid of variable-height modules
   left ragged gaps while squeezing every slider into a ~230px column. A single
   full-height column fixes both - sliders get real width, sections stack at
   their natural height, and the stage keeps the whole window. */
.controls {
  flex: none;
  width: 288px;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
}

.mod {
  padding: 13px 16px 15px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 0;
  border-bottom: 1px solid var(--border-soft);
}

.mod:last-child { border-bottom: none; }

.mod-h {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0;
  font-weight: 500;
}

.mod-h-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.mod-body { display: flex; flex-direction: column; gap: 9px; }
.mod-body[hidden] { display: none; }

.mod-note { margin: 0; font-size: 11.5px; line-height: 1.45; color: var(--text-faint); }
.mod-note strong { color: var(--text-dim); font-weight: 600; }

/* ===========================================================================
   FORM PRIMITIVES
   =========================================================================== */

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 12.5px; color: var(--text-dim); }
.field[hidden] { display: none; }

/* A read-only "label: value" line - detected tempo, resolved stretch ratio, that kind of thing. */
.field-readout { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; color: var(--text-dim); }
.field-readout strong { font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--accent-2); font-weight: 500; font-size: 12px; }

.field--inline { display: flex; flex-direction: column; gap: 4px; }
.field--inline input[type="number"] { width: 90px; }

select,
input[type="text"],
input[type="number"] {
  font: inherit;
  font-size: 13px;
  font-family: var(--font-body);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  width: 100%;
  min-width: 0;
}

select:hover,
input[type="text"]:hover,
input[type="number"]:hover { border-color: var(--accent-dim); }

select:focus-visible,
input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

input[type="checkbox"] { accent-color: var(--accent); }

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
}

.check input { margin: 2px 0 0; flex: none; }
.check span { min-width: 0; }
.check--inline { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-faint); }

/* slider + typable number, paired */

.slider-row { display: flex; align-items: center; gap: 8px; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: none;
  cursor: pointer;
}

input[type="range"]:hover::-webkit-slider-thumb { background: var(--accent); }

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: none;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
}

/* Two classes deep on purpose: a bare .slider-number (0,1,0) loses to the
   generic input[type="number"] (0,1,1) rule above, which sets width:100% and
   blows the number box out to the full column. */
.slider-row .slider-number {
  flex: 0 0 auto;
  width: 3.9rem;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 6px;
  font-variant-numeric: tabular-nums;
}

.slider-unit { flex: 0 0 auto; font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); min-width: 1.9rem; }

/* buttons */

.btn {
  font: inherit;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  padding: 8px 15px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background .14s ease, border-color .14s ease, color .14s ease;
}

.btn:hover { background: var(--bg-raised-hover); border-color: var(--accent-dim); }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn:disabled:hover { background: var(--bg-raised); border-color: var(--border); }

.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: var(--on-accent); }
.btn--primary:disabled:hover { background: var(--accent); border-color: var(--accent); }

.btn--ghost { background: transparent; }
.btn--ghost:hover { background: var(--bg-raised); }

.btn--small { padding: 4px 10px; font-size: 11px; }

.btn--icon {
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  flex: none;
}

/* detection parameters, generated into #params-panel by app.js */

.params-panel { display: flex; flex-direction: column; gap: 10px; }
.params-auto-note { margin: 0; font-size: 11.5px; color: var(--text-faint); }
.params-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 11px; }
.param-row { display: flex; flex-direction: column; gap: 4px; }
.param-row input[type="range"] { width: 100%; }
.param-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-dim); }
.param-value { color: var(--accent-2); font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 11.5px; }
.param-row--checkbox { grid-column: 1 / -1; }

/* file name pattern: token/chip editor - see js/naming-pattern-editor.js */

.naming-pattern-editor-wrap { display: flex; flex-direction: column; gap: 6px; }

.naming-token-row { display: flex; gap: 5px; flex-wrap: wrap; }

.naming-token-btn {
  font: inherit;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--accent-2);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.naming-token-btn:hover { background: var(--bg-raised-hover); border-color: var(--accent-dim); }

.naming-pattern-editor {
  font: inherit;
  font-size: 13px;
  font-family: var(--font-mono);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  min-height: 2.3em;
  line-height: 1.5;
  word-break: break-word;
  outline: none;
}
.naming-pattern-editor:hover { border-color: var(--accent-dim); }
.naming-pattern-editor:focus-visible,
.naming-pattern-editor:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.naming-pattern-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
}

.naming-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--accent-dim);
  color: var(--text);
  border-radius: 999px;
  padding: 1px 3px 1px 8px;
  margin: 0 1px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: default;
  user-select: none;
}
.naming-chip-label { pointer-events: none; }
.naming-chip-remove {
  font: inherit;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 50%;
  width: 1.2em;
  height: 1.2em;
  line-height: 1;
  padding: 0;
}
.naming-chip-remove:hover { color: var(--on-accent); background: var(--accent); }

/* naming preview */

.naming-preview {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--accent-2);
  background: var(--log-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin: 0;
  overflow-wrap: break-word;
}

.essentia-status { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); margin: 0; }
.essentia-status--ok { color: var(--good); }
.essentia-status--warn { color: var(--warn); }

/* ===========================================================================
   STAGE - your audio. The only region that scrolls.
   =========================================================================== */

.stage {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stage.is-dragover {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
  background: rgba(255, 75, 59, 0.05);
}

.banner {
  margin: 0;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  border: 1px solid transparent;
}

.banner:empty { display: none; }
.banner--good { background: rgba(79, 201, 138, .09); border-color: rgba(79, 201, 138, .22); color: var(--good); }
.banner--info { background: rgba(232, 185, 92, .09); border-color: rgba(232, 185, 92, .22); color: var(--warn); }

/* drop zone */

.dropzone {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  padding: 18px;
}

.dropzone-copy { display: flex; flex-direction: column; gap: 2px; }
.dropzone-copy strong { font-family: var(--font-display); font-size: 15px; font-weight: 600; letter-spacing: .02em; }
.dropzone-copy span { font-size: 12.5px; color: var(--text-faint); }
.dropzone-actions { display: flex; gap: 7px; flex-wrap: wrap; }

/* queued sources */

.folder-list { display: flex; flex-direction: column; gap: 7px; }
.folder-list:empty { display: none; }
.folder-list-empty { color: var(--text-faint); font-size: 12.5px; }

.folder-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}

.folder-row-info { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.folder-row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.folder-row-count { color: var(--text-faint); font-size: 12px; font-family: var(--font-mono); }
.folder-row--pending { border-style: dashed; background: transparent; }
.folder-row-pending-actions { display: flex; align-items: center; gap: 6px; flex: none; }

/* results */

.results-panel { display: flex; flex-direction: column; gap: 12px; }
.result-folder { display: flex; flex-direction: column; gap: 9px; }

.result-folder h3 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 500;
}

.result-file {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px 13px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.result-file--skipped {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  border-color: rgba(232, 185, 92, .3);
  background: rgba(232, 185, 92, .05);
}

.result-file--skipped .result-file-meta { color: var(--warn); }

.result-file-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.result-file-title-group { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.result-file-name { font-family: var(--font-display); font-size: 15px; font-weight: 600; }
.result-file-meta { color: var(--text-faint); font-size: 11.5px; font-family: var(--font-mono); }
.result-file-header-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.result-file-static { display: flex; flex-direction: column; gap: 8px; }

.result-subheading {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.chop-list { display: flex; flex-direction: column; gap: 4px; }
.chop-row { display: flex; align-items: center; gap: 10px; font-size: 12.5px; }

.chop-name {
  min-width: 128px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chop-row audio { height: 30px; flex: 1; max-width: 300px; min-width: 0; }

/* waveforms */

.waveform-canvas {
  display: block;
  width: 100%;
  height: 68px;
  border-radius: var(--radius-sm);
  background: var(--wave-bg);
  border: 1px solid var(--border-soft);
}

.waveform-canvas--editable { height: 108px; cursor: grab; touch-action: none; border-color: var(--border); }
.waveform-canvas--dragging { cursor: grabbing; }

/* the interactive waveform - always present on a result card, not a mode you enter */

.editable-waveform { display: flex; flex-direction: column; gap: 6px; outline: none; }
.editable-waveform:focus-visible .waveform-canvas--editable { border-color: var(--accent); }
.editable-waveform-toolbar { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.editable-waveform-toolbar .btn--small { padding: 3px 9px; }
.editable-waveform-toolbar .is-playing { color: var(--accent); border-color: var(--accent-dim); }

.editable-waveform-zoom-label {
  margin-left: auto;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.editable-waveform-hint {
  margin: 0;
  color: var(--text-faint);
  font-size: 11.5px;
  font-family: var(--font-mono);
}

.result-file-editor { display: block; }

/* Informational + action row under the editor: edits are already canonical (see renderFileResult
   in app.js), so this is no longer a "you have unsaved changes" warning - just a neutral strip. */
.result-apply-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
}

.result-apply-row[hidden] { display: none; }
.result-apply-note { flex: 1; font-size: 12.5px; color: var(--text-faint); }

/* Re-chop: an intentionally destructive per-file action, so it's visually separated from the
   editor toolbar above rather than blended into it. */
.result-rechop-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

.result-rechop-row[hidden] { display: none; }

.rechop-count-input {
  width: 56px;
  font: inherit;
  font-size: 12.5px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
}

.rechop-bars-select {
  font: inherit;
  font-size: 12.5px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  width: auto;
}

/* the row matching the slice selected on the waveform */
.chop-row.is-selected {
  background: rgba(255, 75, 59, .12);
  box-shadow: inset 2px 0 0 var(--accent);
  border-radius: var(--radius-sm);
}

.chop-row.is-selected .chop-name { color: var(--text); }

.seg--small .seg-btn { padding: 4px 9px; font-size: 10px; }

/* ===========================================================================
   STRETCH WORKSPACE
   STRETCH's central area: pick a file, browse/tweak a character, compare
   Original vs. Processed. Built by js/stretch-workspace.js; CHOP/BOTH still
   use .results-panel above, untouched. See updateStretchWorkspaceVisibility()
   in app.js for when this shows at all.
   =========================================================================== */

.stretch-workspace { display: flex; flex-direction: column; gap: 14px; }
.stretch-workspace[hidden] { display: none; }

.stretch-file-strip { display: flex; flex-wrap: wrap; gap: 6px; }
.stretch-file-strip[hidden] { display: none; }

.stretch-file-chip {
  font: inherit;
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-raised);
  color: var(--text-dim);
  cursor: pointer;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.stretch-file-chip:hover { color: var(--text); background: var(--bg-raised-hover); }
.stretch-file-chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 500; }
.stretch-file-chip.is-unprocessed { opacity: .55; font-style: italic; }

/* Time / Target - mode, source/target tempo, resolved ratio. Moved in from the old sidebar (still
   there, unchanged, for BOTH) so the source->target relationship sits right next to the audio it
   produces - see js/stretch-workspace.js's createStretchWorkspace(). */
.stretch-time-target {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px 13px;
}

.stretch-time-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px 20px;
}

.stretch-time-readout { flex: 0 0 auto; min-width: 84px; flex-direction: column; align-items: flex-start; gap: 2px; }
.stretch-time-readout strong { font-size: 15px; }
.stretch-time-slider-field { flex: 1 1 220px; min-width: 200px; }

.stretch-ab { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }

.stretch-pane {
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px 13px;
  min-width: 0;
  transition: border-color .15s ease, box-shadow .15s ease;
}

/* Processed gets a touch more visual weight than Original - it's the creative output - plus a
   restrained warm/orange tint on the panel itself (not the waveform canvas, which stays on its own
   neutral --wave-bg for readability) so the two panes read as "source" vs. "result" at a glance even
   before you look at the labels. color-mix keeps this one step removed from a literal colour value,
   the same way the rest of the palette is themed. */
.stretch-pane--processed {
  border-color: var(--accent-dim);
  background: color-mix(in srgb, var(--bg-panel) 92%, var(--accent) 8%);
}
.stretch-pane--processed.is-stale { border-color: var(--warn); }

/* Which side currently owns audition focus (Left/Right, or whichever was last played) - additional
   to, and visually distinct from, Processed's permanent tint above: a brighter accent border. */
.stretch-pane.is-focused { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

.stretch-pane-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.stretch-pane-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.stretch-pane--processed .stretch-pane-head h3 { color: var(--text); }
.stretch-pane-meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; text-align: right; }

.stretch-stale-badge {
  margin: 0;
  font-size: 11.5px;
  color: var(--warn);
  background: rgba(232, 185, 92, .09);
  border: 1px solid rgba(232, 185, 92, .22);
  border-radius: var(--radius-sm);
  padding: 5px 9px;
}
.stretch-stale-badge[hidden] { display: none; }

/* Auto-preview in flight - neutral/informational, deliberately not the stale badge's warning
   colour, and never covers the waveform itself (see setProcessing() in stretch-workspace.js). */
.stretch-processing-badge {
  margin: 0;
  font-size: 11.5px;
  color: var(--accent-2);
  background: rgba(255, 75, 59, .07);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius-sm);
  padding: 5px 9px;
}
.stretch-processing-badge[hidden] { display: none; }

.stretch-error-badge {
  margin: 0;
  font-size: 11.5px;
  color: var(--danger);
  background: rgba(255, 107, 129, .08);
  border: 1px solid rgba(255, 107, 129, .25);
  border-radius: var(--radius-sm);
  padding: 5px 9px;
}
.stretch-error-badge[hidden] { display: none; }

/* the plain audition waveform - see js/preview-waveform.js */
.preview-waveform { display: flex; flex-direction: column; gap: 6px; outline: none; }
.preview-waveform:focus-visible .preview-waveform-canvas { border-color: var(--accent); }
.preview-waveform-canvas { height: 64px; cursor: pointer; touch-action: none; }
.preview-waveform-bar { display: flex; align-items: center; gap: 6px; }
.preview-waveform-bar .btn.is-playing { color: var(--accent); border-color: var(--accent-dim); }
.preview-waveform-time {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* the character browser */
.stretch-character-browser { display: flex; flex-direction: column; gap: 10px; }
.stretch-character-browser-head { display: flex; align-items: center; justify-content: space-between; }
.stretch-character-browser-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.stretch-character-groups { display: flex; flex-direction: column; gap: 12px; }
.stretch-character-group h4 {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 500;
}
.stretch-character-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }

.stretch-character-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-start;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.stretch-character-card:hover { background: var(--bg-raised-hover); border-color: var(--accent-dim); }
.stretch-character-card.is-active { background: var(--accent-dim); border-color: var(--accent); }

.stretch-character-card-label {
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text);
}
.stretch-character-card-desc {
  font-size: 10.8px;
  line-height: 1.35;
  color: var(--text-faint);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.stretch-character-card.is-active .stretch-character-card-desc { color: var(--text-dim); }

.stretch-character-detail {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  padding: 12px 14px 13px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stretch-character-detail:empty { display: none; }
.stretch-character-detail-head { display: flex; flex-direction: column; gap: 2px; }
.stretch-character-detail-head strong { font-family: var(--font-display); font-size: 14px; }
.stretch-character-detail-head span { font-size: 12px; color: var(--text-faint); }

.stretch-macro-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.stretch-character-detail-foot { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }

/* ===========================================================================
   LOG + ACTION BAR
   =========================================================================== */

.log-panel {
  flex: none;
  height: 128px;
  overflow-y: auto;
  background: var(--log-bg);
  border-top: 1px solid var(--border);
  padding: 9px 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.7;
  color: var(--log-text);
}

/* An empty log is a dead black band across the bottom of the window, so it
   only takes up space once it has something to say. */
.log-panel:empty { display: none; }

.log-line { white-space: pre-wrap; word-break: break-word; }
.log-line--warn { color: var(--warn); }

.actionbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
}

.actionbar-status {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.actionbar-status:empty { display: none; }

.result-oneshot-toggle { gap: 6px; align-items: center; cursor: pointer; }
.result-oneshot-toggle input { margin: 0; }

.progress-row { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 120px; }
.progress-row[hidden] { display: none; }

.progress-bar { flex: 1; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.progress-bar-fill { height: 100%; width: 0%; background: var(--accent); transition: width .15s ease-out; }

/* ===========================================================================
   MODAL
   =========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 8, .72);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 1000;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .8);
}

.modal h3 { margin: 0 0 9px; font-family: var(--font-display); font-size: 17px; font-weight: 600; }
.modal p { margin: 0 0 12px; color: var(--text-dim); font-size: 13px; }
.modal-remember { margin: 0 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 7px; flex-wrap: wrap; }

/* ===========================================================================
   TASK
   Everything that differs between chop / stretch / both lives here.
   A section declares the tasks it belongs to with data-tasks; anything that
   doesn't apply is unmounted rather than shown and ignored.
   =========================================================================== */

.mod { display: none; }
[data-task="chop"] .mod[data-tasks~="chop"],
[data-task="stretch"] .mod[data-tasks~="stretch"],
[data-task="both"] .mod[data-tasks~="both"] { display: flex; }

/* Time-stretch: STRETCH's whole purpose is stretching, so its own enable checkbox (meaningful only
   when stretching is optional, i.e. in BOTH) and the reciprocal "it's just on" note swap in/out
   rather than both being shown at once. See updateStretchTaskVisibility() in app.js. */
[data-task="stretch"] .both-only { display: none; }
[data-task="both"] .stretch-only { display: none; }

/* The rail is disclosure, independent of task. */
[data-rail="closed"] .controls { display: none; }

#settings-toggle {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* With nothing queued, the drop zone is the only thing to do, so it takes the
   room rather than sitting as a thin bar above an empty window. It stops
   growing the moment there are results worth looking at. */
.stage > .dropzone {
  flex: 1 1 auto;
  min-height: 150px;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  gap: 18px;
  padding: 26px 22px;
}

.dropzone-copy { align-items: center; }
.dropzone-actions { justify-content: center; }

.stage:has(.folder-row) > .dropzone,
.stage:has(.result-file) > .dropzone {
  flex: none;
  min-height: 0;
  flex-direction: row;
  text-align: left;
  padding: 13px 16px;
  gap: 16px;
}

.stage:has(.folder-row) .dropzone-copy,
.stage:has(.result-file) .dropzone-copy { align-items: flex-start; }
.stage:has(.folder-row) .dropzone-copy strong,
.stage:has(.result-file) .dropzone-copy strong { font-size: 14px; }

/* Chop rows lay out in columns whenever there's room. This used to be tied to
   "Advanced", but a 40-file batch is just as unscannable in any task, and the
   settings rail already keeps the stage wide. */
.chop-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 3px 14px;
}

/* ===========================================================================
   RESPONSIVE
   Below the breakpoint the fixed-chrome shell stops making sense, so the
   whole page reverts to normal document flow and scrolls as one.
   =========================================================================== */

@media (max-width: 900px) {
  .app { height: auto; min-height: 100vh; }
  .body { flex-direction: column; }
  .stage { overflow: visible; }
  .controls { width: auto; overflow: visible; border-right: none; border-bottom: 1px solid var(--border); }
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 12px; gap: 10px; }
  .log-panel { height: 100px; }
  .actionbar { position: sticky; bottom: 0; }
  .chop-list { grid-template-columns: 1fr; }
  .stretch-ab { grid-template-columns: 1fr; }
}

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