:root {
  --bg: #0a0a0c; --bg-elev: #131319; --surface: #1a1a22; --surface-hover: #22222c;
  --border: #2a2a34; --border-bright: #3d3d4a; --fg: #f0eee6; --fg-muted: #6e6e7a;
  --fg-dim: #4a4a54; --accent: #ff8c42; --accent-2: #ffa765; --accent-glow: rgba(255, 140, 66, 0.4);
  --teal: #4dd8c8; --teal-2: #6ee8d8; --teal-glow: rgba(77, 216, 200, 0.4);
  --fx-noise: #a78bfa; /* per-segment identity color for noise removal (must match PER_SEGMENT_EFFECTS in state.js) */
  --rec: #ff3a5c; --rec-glow: rgba(255, 58, 92, 0.45);
  /* Control sizing — icon-only button hit area + glyph sizes, kept uniform app-wide */
  --ctl: 32px; --icon: 18px; --icon-label: 16px;
  /* Type scale floor/ideal (HIG: 11pt legibility floor; Material: 11sp caption floor, 13-14sp
     recommended for continuous-reading body copy). --fs-floor is the hard minimum for any text
     in the app (eyebrow labels, badges); --fs-body is the ideal size for text meant to be read
     continuously (paragraphs, list items, row descriptions). */
  --fs-floor: 11px; --fs-body: 13px;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Space Grotesk', system-ui, sans-serif; background: var(--bg); color: var(--fg);
  height: 100dvh; position: relative; -webkit-font-smoothing: antialiased;
}
body::before {
  content: ''; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(255, 140, 66, 0.09), transparent 60%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(77, 216, 200, 0.06), transparent 60%),
    radial-gradient(ellipse 60% 40% at 0% 100%, rgba(255, 58, 92, 0.04), transparent 60%);
}
body::after {
  content: ''; position: fixed; inset: 0; z-index: 0; pointer-events: none; mix-blend-mode: overlay;
  background-image: repeating-linear-gradient(0deg, transparent 0, transparent 3px, rgba(255,255,255,0.012) 3px, rgba(255,255,255,0.012) 4px);
}

.app {
  position: relative; z-index: 1; max-width: 1280px; margin: 0 auto; padding: 14px 24px;
  height: 100dvh; display: flex; flex-direction: column; gap: 12px; overflow: hidden;
}
.app-header {
  display: flex; justify-content: space-between; align-items: center; padding-bottom: 10px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 12px; flex-shrink: 0;
}
.brand-mark { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 32px; height: 32px; border: 1.5px solid var(--accent); border-radius: 6px;
  display: grid; place-items: center; background: rgba(255, 140, 66, 0.06); position: relative;
}
.brand-logo::before { content: ''; width: 10px; height: 10px; background: var(--accent); border-radius: 50%; box-shadow: 0 0 14px var(--accent-glow); }
.brand-logo::after { content: ''; position: absolute; inset: -4px; border: 1px solid rgba(255, 140, 66, 0.2); border-radius: 8px; animation: ring-breathe 3s ease-in-out infinite; }
@keyframes ring-breathe { 0%, 100% { transform: scale(1); opacity: 0.6; } 50% { transform: scale(1.15); opacity: 0; } }
.brand-name { font-size: 13px; font-weight: 600; letter-spacing: 0.28em; text-transform: uppercase; }
.help-button {
  width: var(--ctl); height: var(--ctl); border-radius: 8px; flex-shrink: 0;
  background: transparent; border: none; color: var(--fg-muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0;
  transition: color 0.15s, background 0.15s;
}
.help-button svg { width: var(--icon); height: var(--icon); }
.help-button:hover { color: var(--accent); border-color: var(--accent); background: rgba(255, 140, 66, 0.06); }
.stage {
  background: linear-gradient(180deg, rgba(28, 28, 36, 0.7), rgba(20, 20, 26, 0.4));
  border: 1px solid var(--border); border-radius: 14px; padding: 18px 18px 26px; position: relative; 
  overflow: hidden; flex: 1 1 0; min-height: 0; display: flex; flex-direction: column;
}
.stage::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgba(255,255,255,0.018) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.018) 1px, transparent 1px);
  background-size: 40px 40px; mask-image: radial-gradient(ellipse at center, black 40%, transparent 100%);
}
.view { position: relative; z-index: 1; flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.view[hidden] { display: none !important; }

.quality-config { background: rgba(0,0,0,0.2); border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px; }
.quality-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.quality-title { font-family: 'JetBrains Mono', monospace; font-size: var(--fs-floor); color: var(--fg-muted); letter-spacing: 0.25em; text-transform: uppercase; }
.quality-bitrate { font-family: 'JetBrains Mono', monospace; font-size: var(--fs-body); color: var(--accent); letter-spacing: 0.05em; font-weight: 500; padding: 4px 10px; background: rgba(255, 140, 66, 0.08); border: 1px solid rgba(255, 140, 66, 0.25); border-radius: 6px; }
.quality-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.quality-setting { display: flex; flex-direction: column; gap: 8px; }
.quality-label { font-family: 'JetBrains Mono', monospace; font-size: var(--fs-floor); color: var(--fg-muted); letter-spacing: 0.18em; text-transform: uppercase; display: flex; justify-content: space-between; align-items: baseline; }
.quality-label-hint { font-size: var(--fs-floor); color: var(--fg-dim); letter-spacing: 0.12em; text-transform: none; }
.quality-options { display: flex; gap: 3px; background: var(--bg); padding: 3px; border-radius: 6px; border: 1px solid var(--border); }
.quality-option {
  flex: 1; padding: 8px 6px; background: transparent; border: none; color: var(--fg-muted);
  font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 500; cursor: pointer;
  border-radius: 4px; transition: all 0.15s; letter-spacing: 0.04em;
}
.quality-option:hover:not(:disabled) { color: var(--fg); background: rgba(255,255,255,0.03); }
.quality-option.active { background: var(--accent); color: var(--bg); box-shadow: 0 2px 8px rgba(255, 140, 66, 0.3); }
.quality-option.active:hover { background: var(--accent); color: var(--bg); box-shadow: 0 2px 8px rgba(255, 140, 66, 0.3); }

.rm-device-select {
  appearance: none;
  -webkit-appearance: none;
  color-scheme: dark;
  accent-color: var(--accent);
  flex: 1; min-width: 0; padding: 6px 30px 6px 12px;
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg); font-family: 'JetBrains Mono', monospace; font-size: var(--fs-body);
  letter-spacing: 0.02em; cursor: pointer; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%23a0a0aa' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='3,4.5 6,7.5 9,4.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px 12px;
  transition: border-color 0.15s, background-color 0.15s;
}
.rm-device-select:hover:not(:disabled) {
  border-color: var(--border-bright);
  background-color: rgba(255, 255, 255, 0.09);
}
.rm-device-select:focus {
  outline: none;
  border-color: var(--accent);
  background-color: rgba(255, 255, 255, 0.09);
}
.rm-device-select:disabled { opacity: 0.5; cursor: default; }
/* Option list inside the native dropdown popup — `color-scheme: dark` on the
   select handles background/system colors; these rules theme the per-option
   text and selection highlight to match the dark UI. */
.rm-device-select option {
  background-color: var(--bg-elev);
  color: var(--fg);
}

.empty-state {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; z-index: 1; pointer-events: none;
}
.empty-state-icon { width: 48px; height: 48px; color: var(--fg-dim); opacity: 0.5; }
.empty-state-text { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--fg-muted); letter-spacing: 0.08em; max-width: 420px; text-align: center; line-height: 1.6; }
.empty-state-actions { display: flex; gap: 8px; }
.empty-state-actions .btn { pointer-events: auto; }

.playback-view { gap: 0; justify-content: flex-start; overflow: visible; }

.editor-section {
  position: relative;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 0 64px;
  overflow: visible;
}

/* The 64px side margins on .editor-section horizontally center the waveform +
    transport block within the stage. The right margin doubles as reserved space
    for the append ("+") button so it sits past the waveform edge.
    64px = 32px button + 2×16px gap (APPEND_BUTTON_SIZE_CSS_PX / APPEND_BUTTON_PAD_CSS_PX in state.js). */
.editor-top-bar { display: flex; align-items: center; flex-shrink: 0; margin-top: 6px; }
.waveform-container { position: relative; flex: 1 1 0; min-height: 60px; cursor: default; margin: 32px 0 56px; }
.waveform-container::before { content: 'WAVEFORM'; position: absolute; top: 8px; left: 10px; font-family: 'JetBrains Mono', monospace; font-size: var(--fs-floor); color: var(--fg-dim); letter-spacing: 0.25em; z-index: 2; pointer-events: none; }
.waveform-segment-count { position: absolute; bottom: 8px; right: 10px; font-family: 'JetBrains Mono', monospace; font-size: var(--fs-floor); color: var(--accent); letter-spacing: 0.15em; z-index: 2; pointer-events: none; padding: 2px 8px; background: rgba(255, 140, 66, 0.08); border: 1px solid rgba(255, 140, 66, 0.2); border-radius: 4px; }
.waveform-segment-count.hidden { display: none; }
.waveform-canvas { width: 100%; height: 100%; display: block; }
.timeline-ruler-canvas { position: absolute; left: 0; top: -26px; width: 100%; height: 26px; cursor: pointer; z-index: 1; }

/* Drag overlay canvas — used only while a segment reorder drag is active (see
   drawDragFrame in waveform.js). Lets the lifted floating card's effects (lift,
   scale-up, drop shadow, accent edge glow) paint beyond the waveform canvas's
   edges without being clipped by it. Extends SEGMENT_DRAG_HEADROOM_CSS_PX on
   all four sides (must match the constant in state.js) — the lifted card is
   transparent to the geometry problem in every direction: the 14px lift goes
   up; the +9px shadowOffsetY + 20px shadowBlur go down; the 1.03× scale-up
   plus the accent edge glow extend left and right. Sized to match
   SEGMENT_DRAG_HEADROOM_CSS_PX. z-index 3 sits above the ruler (1) and the
   'WAVEFORM' label (2), but below the playhead caret (8) so the caret still
   paints on top. pointer-events:none keeps it strictly an output layer (the
   ruler still owns clicks). */
.drag-overlay-canvas { position: absolute; left: -28px; top: -28px; width: calc(100% + 56px); height: calc(100% + 56px); pointer-events: none; z-index: 3; }

.append-button {
  /* Fixed 32px (not var(--ctl)): its position is computed in JS from
     APPEND_BUTTON_SIZE_CSS_PX (state.js), which must match this exactly. */
  position: absolute;
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border-bright);
  color: var(--fg-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0; z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  transition: opacity 0.18s ease, background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  pointer-events: none; opacity: 0;
}
.append-button svg { width: var(--icon); height: var(--icon); }
.append-button.visible { opacity: 1; pointer-events: auto; }
.append-button:hover {
  color: var(--accent); border-color: var(--accent);
  background: rgba(255, 140, 66, 0.08);
  box-shadow: 0 4px 16px rgba(255, 140, 66, 0.25);
}

.append-menu {
  position: absolute;
  z-index: 20;
  min-width: 200px;
  background: var(--bg-elev);
  border: 1px solid var(--border-bright);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  display: flex; flex-direction: column; gap: 2px;
}
.append-menu[hidden] { display: none; }
.append-menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 14px;
  background: transparent; border: none;
  color: var(--fg); cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.12em; text-transform: uppercase;
  border-radius: 6px;
  transition: all 0.15s;
  white-space: nowrap;
}
.append-menu-item svg {
  width: var(--icon-label); height: var(--icon-label);
  flex-shrink: 0;
}
.append-menu-item:first-child svg { stroke: currentColor; fill: none; }
.append-menu-item:last-child svg { stroke: currentColor; fill: none; }
.append-menu-item:hover {
  background: var(--surface-hover);
  color: var(--accent);
}

.segment-context-menu {
  position: fixed;
  z-index: 40;
  min-width: 180px;
  background: var(--bg-elev);
  border: 1px solid var(--border-bright);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  display: flex; flex-direction: column; gap: 2px;
}
.segment-context-menu[hidden] { display: none; }
.segment-context-menu-item[hidden] { display: none; }
.segment-context-menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 14px;
  background: transparent; border: none;
  color: var(--fg); cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.12em; text-transform: uppercase;
  border-radius: 6px;
  transition: all 0.15s;
  white-space: nowrap;
}
.segment-context-menu-item svg {
  width: var(--icon-label); height: var(--icon-label);
  flex-shrink: 0;
}
.segment-context-menu-item:hover {
  background: var(--surface-hover);
  color: var(--accent);
}
.segment-context-menu-item.disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}
.segment-context-menu-item-danger:hover {
  background: rgba(255, 58, 92, 0.1);
  color: var(--rec);
}
.segment-context-menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border-bright);
}

.playhead {
  position: absolute;
  z-index: 8;
  cursor: default;
  padding: 0;
  margin: 0;
  background: transparent;
  border: none;
  color: var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0.85;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 0.15s, color 0.15s;
  line-height: 0;
  -webkit-user-select: none;
  user-select: none;
}
.playhead:hover,
.playhead.dragging {
  opacity: 1;
  color: var(--accent-2);
}
.playhead.dragging {
  transition: none;
}
.playhead-grip {
  width: 26px;
  height: 26px;
  display: block;
  flex: none;
  pointer-events: auto;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));
  transition: transform 0.15s;
}
.playhead:hover .playhead-grip {
  transform: scale(1.15);
}
.playhead.dragging .playhead-grip {
  transform: scale(1.2);
  transition: none;
}
.playhead-line {
  /* 10px-wide hit strip; the visible 2px line is the centered ::before */
  width: 10px;
  margin-top: -6px; /* tuck the line's top under the grip tip's empty viewBox margin */
  display: flex;
  justify-content: center;
  pointer-events: auto;
}
.playhead-line::before {
  content: '';
  width: 2px;
  border-radius: 1px;
  background: currentColor;
  box-shadow: 0 0 6px rgba(255, 140, 66, 0.6);
  transition: box-shadow 0.15s;
}
.playhead:hover .playhead-line::before,
.playhead.dragging .playhead-line::before {
  box-shadow: 0 0 9px rgba(255, 140, 66, 0.85);
}
.transport { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex-shrink: 0; }
.restart-button {
  width: 36px; height: 36px; border-radius: 50%; background: var(--surface); border: none; cursor: pointer;
  display: grid; place-items: center; color: var(--fg); transition: all 0.2s;
  flex-shrink: 0;
}
.restart-button:hover { background: var(--surface-hover); color: var(--accent); }
.restart-button:active { transform: scale(0.96); }
.restart-button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; color: var(--fg-dim); }
.restart-button svg { width: var(--icon); height: var(--icon); }

.skip-forward-button {
  width: 36px; height: 36px; border-radius: 50%; background: var(--surface); border: none; cursor: pointer;
  display: grid; place-items: center; color: var(--fg); transition: all 0.2s;
  flex-shrink: 0;
}
.skip-forward-button:hover { background: var(--surface-hover); color: var(--accent); }
.skip-forward-button:active { transform: scale(0.96); }
.skip-forward-button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; color: var(--fg-dim); }
.skip-forward-button svg { width: var(--icon); height: var(--icon); }

.play-button { 
  width: 44px; height: 44px; border-radius: 50%; background: var(--accent); border: none; cursor: pointer; 
  display: grid; place-items: center; color: var(--bg); transition: all 0.2s; 
  box-shadow: 0 0 18px rgba(255, 140, 66, 0.35); flex-shrink: 0; position: relative; 
}
.play-button:hover { background: var(--accent-2); transform: scale(1.06); box-shadow: 0 0 26px rgba(255, 140, 66, 0.55); }
.play-button:active { transform: scale(0.96); }
.play-button:disabled { background: var(--surface); color: var(--fg-dim); box-shadow: none; cursor: not-allowed; transform: none; }

.play-button svg {
  position: absolute;
  width: 20px; height: 20px; fill: currentColor;
  top: 50%; left: 50%; transform: translate(-50%, -50%); 
  transition: opacity 0.1s; 
}
.play-button .icon-pause { display: none; }
.play-button.playing .icon-pause { display: block; }
.play-button.playing .icon-play { display: none; }

.time-display { font-family: 'JetBrains Mono', monospace; font-size: 14px; letter-spacing: 0.05em; min-width: 150px; }
.time-current { color: var(--accent); font-weight: 500; }
.time-sep { color: var(--fg-dim); margin: 0 8px; }
.time-total { color: var(--fg-muted); }

.transport-actions { display: flex; gap: 10px; align-items: center; }
.action-divider { width: 1px; height: 24px; background: var(--border); flex-shrink: 0; }
.btn[hidden] { display: none; }
.btn {
  font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 500; letter-spacing: 0.18em; text-transform: uppercase;
  padding: 10px 18px; border-radius: 6px; border: 1px solid var(--border-bright); background: var(--surface); color: var(--fg);
  cursor: pointer; transition: all 0.18s; display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover:not(:disabled):not(.btn-inactive) { background: var(--surface-hover); border-color: var(--fg-muted); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled, .btn.btn-inactive { color: var(--fg-dim); border-color: var(--border); cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.btn-primary:hover:not(:disabled):not(.btn-inactive) { background: var(--accent-2); border-color: var(--accent-2); box-shadow: 0 4px 20px rgba(255, 140, 66, 0.4); }
.btn-danger:hover:not(:disabled):not(.btn-inactive) { color: var(--rec); border-color: var(--rec); background: rgba(255, 58, 92, 0.06); }
.btn-edit:hover:not(:disabled):not(.btn-inactive) { color: var(--accent); border-color: var(--accent); background: rgba(255, 140, 66, 0.06); }
/* Persistent effect toggles (loudness normalize, remove noise) while enabled */
.btn-edit.effect-active,
.btn-edit.effect-active:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); background: rgba(255, 140, 66, 0.12); }
/* Noise removal carries its own identity color (violet) so it reads as the
   same effect as its per-segment chips, distinct from the orange whole-
   recording effects (loudness) and the teal waveform/selection. */
.btn-edit.effect-noise.effect-active,
.btn-edit.effect-noise.effect-active:hover:not(:disabled) { color: var(--fx-noise); border-color: var(--fx-noise); background: rgba(167, 139, 250, 0.14); }
.btn svg { width: var(--icon-label); height: var(--icon-label); fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn svg.spin { animation: spin 0.8s linear infinite; }
/* Icon-only .btn (toolbar undo/redo/split/delete): square hit area, full-size glyph */
.btn-icon { width: var(--ctl); height: var(--ctl); padding: 0; justify-content: center; }
.btn-icon svg { width: var(--icon); height: var(--icon); }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Audio-tool popovers (trim silence, normalize loudness) — anchored below
   their toolbar button, dismiss on outside click / Escape (see ui.js). */
.tool-anchor { position: relative; display: inline-flex; }
.tool-popover {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 30;
  display: grid; grid-template-columns: auto 90px; gap: 8px 10px; align-items: center;
  min-width: 230px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border-bright); border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--fg);
  letter-spacing: 0.12em; text-transform: uppercase;
}
.tool-popover[hidden] { display: none; }
.tool-field { display: contents; cursor: pointer; }
.tool-popover input {
  width: 100%; padding: 6px 8px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; color: var(--fg); font-family: inherit; font-size: 11px;
  letter-spacing: 0.04em; text-transform: none;
}
.tool-popover input:focus { outline: none; border-color: var(--accent); }
.tool-apply { grid-column: 1 / span 2; justify-content: center; padding: 8px; margin-top: 2px; }
/* Enable-effect toggle row at the top of an effect popover (spans the grid) */
.tool-toggle { grid-column: 1 / span 2; display: flex; align-items: center; gap: 8px; cursor: pointer; padding-bottom: 2px; }
.tool-popover .tool-toggle input { width: auto; accent-color: var(--accent); }

/* Master "Finishing" button + popover (in the tracks-panel header). Applies
   loudness normalization to the whole mix. */
.master-fx-button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border: 1px solid var(--border); border-radius: 7px; cursor: pointer;
  background: var(--surface); color: var(--fg-muted);
  font-family: inherit; font-size: var(--fs-floor); font-weight: 500; white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.master-fx-button svg { width: 14px; height: 14px; }
.master-fx-button:hover { color: var(--fg); border-color: var(--border-bright); }
.master-fx-button.is-on { color: var(--accent); border-color: var(--accent); }
.master-fx-popover { left: auto; right: 0; }
.master-fx-popover .fx-popover-title { grid-column: 1 / span 2; }
.fx-presets { grid-column: 1 / span 2; display: flex; flex-wrap: wrap; gap: 6px; }
.fx-preset {
  padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
  background: var(--bg); color: var(--fg-muted);
  font-family: inherit; font-size: 10px; letter-spacing: 0.02em; text-transform: none;
  transition: color 0.15s, border-color 0.15s;
}
.fx-preset:hover { color: var(--fg); border-color: var(--accent); }

/* Per-track effects dropdown (shared popover, anchored under a row's FX
   button). A vertical stack of effect toggles, each with minimal settings. */
.track-fx.is-on { color: var(--accent); border-color: var(--accent); }
.track-fx.is-busy { color: var(--accent); }
.track-fx-popover {
  position: absolute; z-index: 40; min-width: 250px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--border-bright); border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--fg);
}
.track-fx-popover[hidden] { display: none; }
.fx-popover-title { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--fg-muted); }
.track-fx-popover .tool-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.track-fx-popover .tool-toggle input { width: auto; accent-color: var(--accent); }
.fx-settings { display: flex; flex-direction: column; gap: 6px; padding: 0 0 4px 22px; }
.fx-settings .tool-field { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.fx-settings input[type="number"] {
  width: 68px; padding: 4px 6px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; color: var(--fg); font-family: inherit; font-size: 11px;
}
.fx-slider { display: flex; align-items: center; gap: 8px; font-size: 10px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.fx-slider span { width: 34px; flex-shrink: 0; }
.fx-slider input[type="range"] { flex: 1; accent-color: var(--accent); cursor: pointer; }


/* Export Modal Styles */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 10, 12, 0.85); backdrop-filter: blur(12px);
  display: grid; place-items: center; z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
}
.modal-overlay.visible { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--bg-elev); border: 1px solid var(--border-bright); border-radius: 16px;
  width: min(440px, 90vw); padding: 28px; box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  transform: translateY(20px) scale(0.96); transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative; overflow: hidden;
}
.modal-overlay.visible .modal { transform: translateY(0) scale(1); }
.modal::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.modal-title { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--fg); letter-spacing: 0.25em; text-transform: uppercase; font-weight: 600; }
.modal-close { background: transparent; border: none; color: var(--fg-muted); font-size: 24px; cursor: pointer; transition: color 0.15s; padding: 0; line-height: 1; width: var(--ctl); height: var(--ctl); display: grid; place-items: center; border-radius: 6px; margin: -4px -6px -4px 0; flex-shrink: 0; }
.modal-close:hover { color: var(--rec); }
.export-section { margin-bottom: 20px; }
.export-section-label { font-family: 'JetBrains Mono', monospace; font-size: var(--fs-floor); color: var(--fg-dim); letter-spacing: 0.2em; text-transform: uppercase; margin-bottom: 10px; }
.export-formats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.export-format-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--fg-muted);
  padding: 14px; border-radius: 10px; cursor: pointer; text-align: center; transition: all 0.18s;
  display: flex; flex-direction: column; gap: 4px; font-family: inherit;
}
.export-format-btn:hover { border-color: var(--border-bright); color: var(--fg); }
.export-format-btn.active {
  background: rgba(255, 140, 66, 0.08); border-color: var(--accent); color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 16px rgba(255, 140, 66, 0.15);
}
.fmt-name { font-size: 15px; font-weight: 600; letter-spacing: 0.1em; }
.fmt-desc { font-size: var(--fs-floor); letter-spacing: 0.15em; text-transform: uppercase; opacity: 0.7; }
.export-quality-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; }
.export-quality-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--fg-muted);
  padding: 10px 6px; border-radius: 6px; cursor: pointer; transition: all 0.15s;
  font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 500;
}
.export-quality-btn:hover { color: var(--fg); background: var(--surface-hover); }
.export-quality-btn.active {
  background: var(--accent); color: var(--bg); border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(255, 140, 66, 0.3);
}
.export-info {
  background: rgba(0,0,0,0.3); border: 1px solid var(--border); border-radius: 10px; padding: 14px;
  margin-bottom: 20px; display: flex; flex-direction: column; gap: 10px;
}
.info-row { display: flex; justify-content: space-between; align-items: center; font-family: 'JetBrains Mono', monospace; font-size: var(--fs-body); }
.info-row span:first-child { color: var(--fg-dim); letter-spacing: 0.15em; text-transform: uppercase; font-size: var(--fs-floor); }
.info-row span:last-child { color: var(--fg); font-weight: 500; }
.export-confirm { width: 100%; justify-content: center; padding: 14px; font-size: var(--fs-body); }

/* Quality Settings Modal (Dave Ying spec) */
.quality-modal-overlay {
  position: fixed; inset: 0; z-index: 42;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: grid; place-items: center;
  opacity: 0; pointer-events: none;
  transition: opacity 250ms ease-out;
}
.quality-modal-overlay.visible { opacity: 1; pointer-events: auto; }
.quality-modal-overlay .modal {
  transform: translateY(20px) scale(0.96);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.quality-modal-overlay.visible .modal { transform: translateY(0) scale(1); }

/* ===== Record modal ===== */
.record-modal .modal { width: min(860px, 94vw); }

/* Mic status chip */
.rm-mic { display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 18px; background: rgba(0,0,0,0.2); border: 1px solid var(--border); border-radius: 10px; }
.rm-mic-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-dim); flex-shrink: 0; transition: background 0.2s, box-shadow 0.2s; }
.rm-mic-dot.connected { background: var(--teal); box-shadow: 0 0 8px var(--teal-glow); }
.rm-mic-icon { width: var(--icon); height: var(--icon); color: var(--teal); flex-shrink: 0; }
.rm-mic-name { font-family: 'JetBrains Mono', monospace; font-size: var(--fs-body); color: var(--fg); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rm-icon-btn { background: transparent; border: none; cursor: pointer; width: var(--ctl); height: var(--ctl); display: grid; place-items: center; color: var(--fg-muted); border-radius: 6px; transition: color 0.15s, background 0.15s; flex-shrink: 0; }
.rm-icon-btn:hover { color: var(--accent); background: rgba(255,255,255,0.05); }
.rm-icon-btn svg { width: var(--icon); height: var(--icon); }
#rmDisconnectBtn:hover { color: var(--rec); }

/* Collapsible capture settings inside record modal */
.rm-settings-wrap {
  overflow: hidden;
  max-height: 0;
  margin-bottom: 0;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              margin-bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.rm-settings-wrap.expanded {
  max-height: 180px;
  margin-bottom: 18px;
}
.rm-settings-inner {
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
}

/* Stage: one view per state, all absolutely fill */
.rm-stage { position: relative; height: 300px; border-radius: 12px; background: rgba(0,0,0,0.3); border: 1px solid var(--border); overflow: hidden; }
.rm-ready, .rm-nomic, .rm-live, .rm-review { position: absolute; inset: 0; }

/* Ready view */
.rm-ready { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; }
.rm-big-record { width: 92px; height: 92px; border-radius: 50%; background: rgba(255, 58, 92, 0.07); border: 2px solid var(--rec); cursor: pointer; display: grid; place-items: center; transition: all 0.2s; }
.rm-big-record-dot { width: 38px; height: 38px; border-radius: 50%; background: var(--rec); box-shadow: 0 0 26px var(--rec-glow); transition: transform 0.2s; }
.rm-big-record:hover { background: rgba(255, 58, 92, 0.14); box-shadow: 0 0 0 8px rgba(255, 58, 92, 0.06); }
.rm-big-record:hover .rm-big-record-dot { transform: scale(1.08); }
.rm-big-record:active .rm-big-record-dot { transform: scale(0.94); }
.rm-ready-hint { font-size: var(--fs-body); color: var(--fg-muted); }
.rm-ready-spec { font-family: 'JetBrains Mono', monospace; font-size: var(--fs-floor); color: var(--fg-dim); letter-spacing: 0.18em; text-transform: uppercase; }

/* Disconnected view */
.rm-nomic { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.rm-nomic-icon { width: 44px; height: 44px; color: var(--fg-dim); opacity: 0.55; }
.rm-nomic-text { font-family: 'JetBrains Mono', monospace; font-size: var(--fs-body); color: var(--fg-muted); letter-spacing: 0.1em; }

/* Recording view */
.rm-live #liveCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: 2; }
.rm-live-hud { position: absolute; top: 14px; left: 16px; right: 16px; display: flex; justify-content: space-between; align-items: center; z-index: 3; pointer-events: none; }
.rm-rec { display: flex; align-items: center; gap: 8px; font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 600; letter-spacing: 0.2em; color: var(--rec); }
.rm-rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--rec); box-shadow: 0 0 12px var(--rec-glow); animation: blink 0.9s ease-in-out infinite; }
@keyframes blink { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.3; transform: scale(0.85); } }
.rm-live-hud .live-timer { font-family: 'JetBrains Mono', monospace; font-size: 14px; color: var(--fg); letter-spacing: 0.08em; font-weight: 500; }
.rm-live-meter { position: absolute; bottom: 14px; left: 16px; right: 16px; height: 5px; background: rgba(255,255,255,0.06); border: 1px solid var(--border); border-radius: 3px; overflow: hidden; z-index: 3; }
.rm-live-meter .level-meter-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--teal) 0%, var(--teal) 55%, var(--accent) 80%, var(--rec) 100%); transition: width 0.04s linear; }

/* Review view */
.rm-review-canvas-area { position: absolute; inset: 0; cursor: pointer; }
#rmReviewCanvas { width: 100%; height: 100%; display: block; }
.rm-playhead { position: absolute; top: 0; bottom: 0; z-index: 8; padding: 0; margin: 0; background: transparent; border: none; color: var(--accent); display: flex; flex-direction: column; align-items: center; opacity: 0.9; transform: translateX(-50%); transition: opacity 0.15s, color 0.15s; line-height: 0; -webkit-user-select: none; user-select: none; pointer-events: none; }
.rm-playhead:hover, .rm-playhead.dragging { opacity: 1; color: var(--accent-2); }
.rm-playhead.dragging { transition: none; }
.rm-playhead-grip { width: 24px; height: 24px; display: block; flex: none; filter: drop-shadow(0 1px 3px rgba(0,0,0,0.5)); transition: transform 0.15s; pointer-events: auto; }
.rm-playhead:hover .rm-playhead-grip { transform: scale(1.15); }
.rm-playhead.dragging .rm-playhead-grip { transform: scale(1.2); transition: none; }
.rm-playhead-line { flex: 1; width: 12px; margin-top: -5px; display: flex; justify-content: center; pointer-events: auto; }
.rm-playhead-line::before { content: ''; width: 2px; height: 100%; border-radius: 1px; background: currentColor; box-shadow: 0 0 8px rgba(255, 140, 66, 0.6); }
.rm-playhead:hover .rm-playhead-line::before, .rm-playhead.dragging .rm-playhead-line::before { box-shadow: 0 0 12px rgba(255, 140, 66, 0.85); }

/* Controls row below stage */
.rm-controls { display: flex; align-items: center; justify-content: center; gap: 18px; min-height: 56px; margin-top: 18px; }
.rm-stop { width: 52px; height: 52px; border-radius: 50%; background: var(--rec); border: none; cursor: pointer; display: grid; place-items: center; color: #fff; transition: all 0.2s; box-shadow: 0 0 22px var(--rec-glow); }
.rm-stop:hover { background: #ff5a7a; transform: scale(1.06); box-shadow: 0 0 30px rgba(255,58,92,0.55); }
.rm-stop:active { transform: scale(0.94); }
.rm-stop svg { width: 18px; height: 18px; fill: currentColor; }

.rm-play-btn { width: 48px; height: 48px; border-radius: 50%; background: var(--accent); border: none; cursor: pointer; display: grid; place-items: center; color: var(--bg); transition: all 0.2s; box-shadow: 0 0 18px rgba(255, 140, 66, 0.3); position: relative; flex-shrink: 0; }
.rm-play-btn:hover { background: var(--accent-2); transform: scale(1.06); box-shadow: 0 0 28px rgba(255, 140, 66, 0.5); }
.rm-play-btn:active { transform: scale(0.94); }
.rm-play-btn svg { position: absolute; width: 19px; height: 19px; top: 50%; left: 50%; transform: translate(-50%, -50%); transition: opacity 0.1s; }
.rm-play-btn .rm-pause-icon { display: none; }
.rm-play-btn.playing .rm-pause-icon { display: block; }
.rm-play-btn.playing .rm-play-icon { display: none; }
.rm-review-time { font-family: 'JetBrains Mono', monospace; font-size: 14px; letter-spacing: 0.05em; }
.rm-review-time .time-sep { color: var(--fg-dim); margin: 0 8px; }
#rmReviewCurrent { color: var(--accent); font-weight: 500; }
#rmReviewTotal { color: var(--fg-muted); }

/* Review actions */
.rm-actions { display: flex; gap: 12px; margin-top: 18px; }
.rm-actions .btn { flex: 1; justify-content: center; padding: 13px 18px; }

/* ===== Confirm Modal ===== */
.confirm-modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: grid; place-items: center;
  opacity: 0; pointer-events: none;
  transition: opacity 250ms ease-out;
}
.confirm-modal-overlay.visible { opacity: 1; pointer-events: auto; }
.confirm-modal-overlay .modal {
  transform: translateY(20px) scale(0.96);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.confirm-modal-overlay.visible .modal { transform: translateY(0) scale(1); }
.confirm-modal { width: min(380px, 90vw); }
.confirm-message { font-family: 'JetBrains Mono', monospace; font-size: var(--fs-body); color: var(--fg-muted); line-height: 1.6; letter-spacing: 0.05em; margin-bottom: 22px; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1; justify-content: center; padding: 12px; }
.confirm-actions .btn-danger { color: var(--rec); border-color: rgba(255, 58, 92, 0.4); background: rgba(255, 58, 92, 0.08); }
.confirm-actions .btn-danger:hover { background: rgba(255, 58, 92, 0.14); border-color: var(--rec); }

/* ===== Help Modal ===== */
.help-modal { width: min(760px, 92vw); height: min(600px, 82vh); display: flex; flex-direction: column; padding: 0; }
.help-modal-close { position: absolute; top: 20px; right: 20px; z-index: 1; }
.help-body { display: flex; min-height: 0; flex: 1; }
.help-tabs {
  display: flex; flex-direction: column; gap: 1px; flex-shrink: 0; width: 196px;
  background: var(--bg); padding: 40px 14px 24px; align-self: stretch;
}
.help-tab {
  padding: 10px 12px; background: transparent; border: none; color: var(--fg-muted); text-align: left;
  font-family: 'JetBrains Mono', monospace; font-size: var(--fs-floor); font-weight: 500; letter-spacing: 0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; border-radius: 6px; transition: all 0.15s;
}
.help-tab:hover:not(.active) { color: var(--fg); background: rgba(255,255,255,0.04); }
.help-tab.active { background: rgba(255, 140, 66, 0.12); color: var(--accent); font-weight: 600; }
.help-content { min-width: 0; min-height: 0; flex: 1; display: flex; flex-direction: column; padding: 48px 10px 36px 36px; }
.help-panel { overflow-y: auto; max-height: 100%; padding-right: 24px; margin-right: 0; scrollbar-width: thin; scrollbar-color: var(--border-bright) transparent; }
.help-panel::-webkit-scrollbar { width: 8px; }
.help-panel::-webkit-scrollbar-track { background: transparent; }
.help-panel::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 4px; }
.help-panel::-webkit-scrollbar-thumb:hover { background: var(--fg-dim); }
.help-group { margin-bottom: 18px; }
.help-group:last-child { margin-bottom: 0; }
.help-group-title { font-family: 'JetBrains Mono', monospace; font-size: var(--fs-floor); color: var(--fg-dim); letter-spacing: 0.2em; text-transform: uppercase; margin-bottom: 10px; }
.shortcut-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); gap: 12px; }
.shortcut-row:last-child { border-bottom: none; }
.shortcut-desc { font-size: var(--fs-body); color: var(--fg); letter-spacing: 0.02em; }
.shortcut-keys { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.shortcut-or { font-family: 'JetBrains Mono', monospace; font-size: var(--fs-floor); color: var(--fg-dim); }
kbd {
  font-family: 'JetBrains Mono', monospace; font-size: var(--fs-floor); color: var(--fg-muted);
  background: var(--surface); border: 1px solid var(--border-bright); border-radius: 5px;
  padding: 3px 7px; box-shadow: 0 2px 0 rgba(0,0,0,0.3);
}
.about-text { font-size: var(--fs-body); color: var(--fg-muted); line-height: 1.6; letter-spacing: 0.02em; }
.changelog-list { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.changelog-group .help-group-title { color: var(--accent); letter-spacing: 0.12em; }
.changelog-list li {
  font-size: var(--fs-body); color: var(--fg-muted); line-height: 1.6; letter-spacing: 0.02em;
  padding-left: 16px; position: relative;
}
.changelog-list li::before { content: ''; position: absolute; left: 0; top: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(100px); background: var(--surface); border: 1px solid var(--border-bright); color: var(--fg); padding: 12px 20px; border-radius: 8px; font-size: var(--fs-body); box-shadow: 0 12px 40px rgba(0,0,0,0.6); z-index: 1000; opacity: 0; transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); display: flex; align-items: center; gap: 10px; max-width: 90vw; font-family: 'JetBrains Mono', monospace; letter-spacing: 0.05em; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast-icon { width: 16px; height: 16px; color: var(--teal); flex-shrink: 0; }
.toast.error .toast-icon { color: var(--rec); }
.toast.error { border-color: rgba(255, 58, 92, 0.4); }

.app-footer { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.app-footer-text { flex: 1 1 auto; min-width: 0; text-align: center; font-family: 'JetBrains Mono', monospace; font-size: var(--fs-floor); color: var(--fg-dim); letter-spacing: 0.18em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.github-link { flex-shrink: 0; display: inline-flex; align-items: center; color: var(--fg-dim); transition: color 0.18s, transform 0.18s; }
.github-link:hover { color: var(--fg); transform: translateY(-1px); }
.github-link:active { transform: translateY(0); }
.github-icon { width: 22px; height: 22px; display: block; }
.github-icon-light { display: none; }
[data-theme="light"] .github-icon-dark { display: none; }
[data-theme="light"] .github-icon-light { display: block; }

@media (max-width: 768px) {
  .app { padding: 12px 14px; gap: 10px; }
  .app-header { padding-bottom: 8px; gap: 8px; }
  .brand-logo { width: 28px; height: 28px; }
  .brand-name { font-size: 11px; letter-spacing: 0.2em; }
  .action-divider { display: none; }

  /* Editor toolbar: the desktop single-row layout overflows the stage on
     phones (the effect-scope labels + effect buttons run past the right edge
     and get clipped by .stage's overflow:hidden). Let it wrap onto as many
     rows as needed and center each row so nothing is unreachable. */
  .editor-top-bar { justify-content: center; margin-top: 4px; }
  .transport-actions { flex-wrap: wrap; justify-content: center; row-gap: 8px; column-gap: 8px; }

  /* Reclaim horizontal space: the 64px side margins (reserved partly for the
     append "+" button) leave the waveform far too narrow on a phone. 40px
     still clears the 32px append button in the right gap (+ stage padding). */
  .editor-section { margin: 0 40px; }
  .waveform-container { margin: 28px 0 44px; }
  .record-modal .modal { padding: 20px; }
  .rm-stage { height: 210px; }
  .rm-big-record { width: 76px; height: 76px; }
  .rm-big-record-dot { width: 30px; height: 30px; }
  .stage { padding: 14px 14px 22px; border-radius: 12px; }
  .quality-config { padding: 12px; }
  .quality-header { margin-bottom: 10px; gap: 8px; }
  .quality-title { font-size: var(--fs-floor); }
  .quality-bitrate { font-size: var(--fs-floor); padding: 3px 8px; }
  .quality-grid { gap: 8px; }
  .quality-setting { gap: 6px; }
  .quality-label { font-size: var(--fs-floor); }
  .quality-option { font-size: var(--fs-floor); padding: 6px 4px; }
  /* Larger touch targets on small screens (HIG/Material minimums); glyphs stay full-size */
  :root { --ctl: 40px; }
  .restart-button { width: 40px; height: 40px; }
  .skip-forward-button { width: 40px; height: 40px; }
  .play-button { width: 48px; height: 48px; }
  .time-display { font-size: var(--fs-body); min-width: 0; }
  /* Transport row: center the play controls + time, and give the Export button
     its own full-width row (overriding the desktop inline margin-left:auto). */
  .transport { justify-content: center; row-gap: 12px; }
  #downloadButton { margin-left: 0 !important; width: 100%; justify-content: center; }
  .btn { padding: 8px 12px; font-size: var(--fs-floor); }
  .btn-icon { padding: 0; }
  .append-menu { min-width: 170px; }
  .append-menu-item { padding: 8px 12px; font-size: var(--fs-floor); gap: 8px; }
  .playhead-grip { width: 22px; height: 22px; }
  .playhead-line { margin-top: -5px; }
  .readout { padding: 8px 6px; gap: 2px; }

  .app-footer-text { font-size: var(--fs-floor); letter-spacing: 0.1em; }
  .github-icon { width: 18px; height: 18px; }
}

/* ===== Help modal: phone/narrow layout =====
   The desktop help modal is a two-pane split (196px vertical tab rail +
   scrolling content). Below ~600px that rail eats half the width, the content
   column collapses, and the shortcut key chips overflow and get clipped by the
   modal's overflow:hidden. Switch to a stacked layout: tabs become a wrapping
   strip across the top, and each shortcut row stacks its keys under its label
   so nothing is ever cut off. */
@media (max-width: 600px) {
  .help-body { flex-direction: column; }
  .help-tabs {
    flex-direction: row; flex-wrap: wrap; width: auto; align-self: stretch;
    padding: 14px 52px 12px 14px; /* right pad clears the absolute close button */
    gap: 6px; border-bottom: 1px solid var(--border);
  }
  .help-tab { flex: 0 0 auto; }
  .help-modal-close { top: 12px; right: 14px; }
  .help-content { padding: 18px 16px 24px; }
  .help-panel { padding-right: 8px; }
  .shortcut-row { flex-direction: column; align-items: flex-start; gap: 6px; }
  .shortcut-keys { flex-wrap: wrap; }
}

/* ===== Small phones ===== */
@media (max-width: 480px) {
  /* Stack the empty-state buttons so "Upload Audio File" stops wrapping to
     three lines next to Record. */
  .empty-state-actions { flex-direction: column; align-items: stretch; width: min(260px, 78vw); }
  .empty-state-actions .btn { justify-content: center; }

  /* Record-modal capture settings: three side-by-side setting groups (sample
     rate / bit depth / channels) don't fit the ~340px modal — the Channels
     column overflows and gets clipped. Stack them into one column, and raise
     the expanded panel's max-height so the taller stacked content isn't cut. */
  .quality-grid { grid-template-columns: 1fr; gap: 12px; }
  .rm-settings-wrap.expanded { max-height: 360px; }
}

@media (max-height: 500px) {
  .app { gap: 8px; padding: 8px 12px; }
  .app-header { padding-bottom: 4px; }
  .app-footer, .readouts { display: none; }
}

/* ===== Multi-lane timeline (NLE-style rows) =====
   Each track is a row: a fixed-width control header on the left and, on the
   right, a waveform lane on a shared time axis. One playhead spans every lane.
   --tl-header-w must match HEADER_W in js/timeline.js. */
:root { --tl-header-w: 220px; }

.timeline {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  margin: 6px 0 10px;
}
.timeline[hidden] { display: none; }

.tl-ruler-row {
  display: flex; align-items: flex-end; flex-shrink: 0; height: 26px;
  position: sticky; top: 0; z-index: 4; background: var(--bg);
}
.tl-corner { width: var(--tl-header-w); flex-shrink: 0; }
.tl-ruler { flex: 1 1 0; height: 26px; display: block; cursor: pointer; }

.tl-grid { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }

.waveform-home { flex: 1 1 0; min-height: 0; position: relative; display: flex; flex-direction: column; }
.waveform-home[hidden] { display: none; }

.tl-lane {
  display: flex; align-items: stretch; gap: 0; min-height: 96px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tl-lane.is-active { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal-glow); }
.tl-lane.is-drop-target { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent-glow); }

/* Horizontal scrollbar (shown only when zoomed in past fit). */
.tl-scrollbar {
  position: sticky; left: 0; height: 10px; margin-left: var(--tl-header-w);
  margin-top: 4px; flex-shrink: 0; cursor: pointer;
}
.tl-scrollbar[hidden] { display: none; }
.tl-scroll-thumb {
  position: absolute; top: 2px; height: 6px; border-radius: 3px;
  background: var(--border-bright); min-width: 28px;
}
.tl-scroll-thumb:hover { background: var(--fg-muted); }

/* Zoom controls in the transport bar. */
.tl-zoom { display: inline-flex; align-items: center; gap: 2px; }
.tl-zoom-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 28px; min-width: 28px; padding: 0 8px;
  background: var(--surface); color: var(--fg-muted);
  border: 1px solid var(--border); border-radius: 7px;
  font-size: var(--fs-floor); font-weight: 600; cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.tl-zoom-btn:hover { color: var(--fg); border-color: var(--border-bright); }
.tl-zoom-btn svg { width: 14px; height: 14px; }
.tl-zoom-fit { letter-spacing: 0.04em; }

.tl-lane-head {
  width: var(--tl-header-w); flex-shrink: 0;
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px 10px; cursor: pointer;
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
}
.tl-head-top { display: flex; align-items: center; gap: 8px; }
.tl-track-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; flex-shrink: 0;
  background: var(--surface); color: var(--fg-muted);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: var(--fs-floor); font-weight: 700; font-variant-numeric: tabular-nums;
}
.tl-lane.is-active .tl-track-num { background: var(--teal); color: var(--bg); border-color: var(--teal); }
.tl-track-name { font-size: var(--fs-body); color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-head-controls { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.tl-head-vol { display: flex; align-items: center; }
.tl-head-vol .track-vol { width: 100%; }

.tl-lane-body { position: relative; flex: 1 1 0; min-width: 0; background: var(--bg); cursor: grab; }
.timeline.is-dragging-clip .tl-lane-body { cursor: grabbing; }
.tl-lane-canvas { display: block; }
.tl-lane-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: 'JetBrains Mono', monospace; font-size: var(--fs-floor);
  color: var(--fg-dim); letter-spacing: 0.06em; pointer-events: none; padding: 0 12px; text-align: center;
}

/* One shared playhead across every lane. */
.tl-playhead {
  position: absolute; top: 0; width: 2px;
  background: var(--accent); box-shadow: 0 0 8px var(--accent-glow);
  pointer-events: none; z-index: 3;
}

/* Shared control-button styling (used by lane headers). */
.track-ctl {
  display: inline-flex; align-items: center; justify-content: center;
  height: 26px; min-width: 26px; padding: 0 5px;
  background: var(--surface); color: var(--fg-muted);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: var(--fs-floor); font-weight: 600; cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.track-ctl:hover { color: var(--fg); border-color: var(--border-bright); }
.track-ctl svg { width: 14px; height: 14px; }
.track-mute.is-on { color: var(--rec); border-color: var(--rec); }
.track-solo.is-on { color: var(--teal); border-color: var(--teal); }
.track-solo.is-dimmed { opacity: 0.5; }
.track-fx.is-on { color: var(--teal); border-color: var(--teal); }
.track-del:hover { color: var(--rec); border-color: var(--rec); }
.track-vol { accent-color: var(--teal); cursor: pointer; }

/* "Add track" lives in the transport bar now. */
.add-track-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  background: transparent; color: var(--fg-muted);
  border: 1px dashed var(--border-bright); border-radius: 8px;
  font-size: var(--fs-body); font-weight: 600; cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.add-track-button:hover { color: var(--teal); border-color: var(--teal); background: rgba(77, 216, 200, 0.06); }
.add-track-button svg { width: 15px; height: 15px; }

@media (max-width: 640px) {
  :root { --tl-header-w: 140px; }
  .tl-head-controls { gap: 4px; }
}
