:root {
  color-scheme: dark;
  --bg: #0a160c;
  --bg-deep: #050b06;
  --panel: #112312;
  --panel-2: #132615;
  --surface: #182f1c;
  --surface-2: #172b1a;
  --overlay: #0c1a0e;
  --scrim: rgba(4, 12, 8, 0.82);
  --accent-soft: rgba(212, 162, 74, 0.18);
  --app-bg: radial-gradient(130% 120% at 50% -8%, #142a17 0%, #0a160c 50%, #050b06 100%);
  --line: #233a26;
  --line-strong: #314836;
  --text: #f0f1ea;
  --muted: #9fb4a7;
  --soft: #dfe2d8;
  --accent: #d4a24a;
  --accent-2: #ecc572;
  --danger: #ff6f61;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

.cf-source-video {
  position: absolute;
  left: -9999px;
  width: 2px;
  height: 2px;
  opacity: 0;
  pointer-events: none;
}

html, body { width: 100%; height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--app-bg, var(--bg));
  color: var(--text);
}

button, input, select { font: inherit; }

button,
select,
input[type="text"],
input[type="number"] {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

button { cursor: pointer; }

button:disabled,
a.is-disabled {
  cursor: not-allowed;
  opacity: 0.48;
  pointer-events: none;
}

/* ---- Chrome (shared with suite) ---- */
.app-shell {
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-width: 960px;
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--overlay);
}

.brand { display: flex; align-items: center; gap: 12px; }
.top-actions { display: flex; align-items: center; gap: 10px; }

.brand { min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid #63706d;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 13px;
  font-weight: 850;
}

.brand h1 { margin: 0; font-size: 18px; line-height: 1.1; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.suite-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.icon-button,
.primary-button,
.secondary-button,
.secondary-link,
.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
}

.suite-tabs .secondary-link {
  min-height: 30px;
  padding: 0 10px;
  border-color: transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.suite-tabs .secondary-link.is-active {
  border-color: rgba(212, 162, 74, 0.48);
  background: #2e2613;
  color: #dcfff7;
}

.icon-button { width: 40px; padding: 0; }
.icon-button svg { width: 19px; height: 19px; fill: currentColor; }

.primary-button {
  padding: 0 18px;
  border-color: rgba(212, 162, 74, 0.55);
  background: #2e2613;
  color: #eafff8;
  font-weight: 800;
}

.primary-button.is-recording {
  border-color: rgba(255, 111, 97, 0.7);
  background: #3a1b1a;
  color: #ffe4df;
}

.secondary-button,
.secondary-link,
.mini-button {
  padding: 0 14px;
  background: var(--surface);
  color: var(--soft);
  font-weight: 750;
}

.mini-button { min-height: 30px; padding: 0 10px; font-size: 12px; }

.secondary-button.is-active {
  border-color: rgba(212, 162, 74, 0.68);
  background: #2e2613;
  color: #eafff8;
}

button:hover,
.secondary-link:hover { border-color: var(--line-strong); background: var(--surface-2); }

/* ---- Workspace: preview + export panel (top) / timeline (bottom) ---- */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-rows: minmax(0, 1fr) minmax(220px, 42%);
  min-height: 0;
}

.preview-area {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--line);
}

.export-panel {
  grid-column: 2;
  grid-row: 1;
  min-height: 0;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.timeline { grid-column: 1 / -1; grid-row: 2; }

/* export section (mirrors the other apps' control-group/field pattern) */
.control-group {
  display: grid;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.group-header h2 {
  margin: 0;
  color: var(--soft);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}
.field { display: grid; gap: 6px; }
.field > span { color: var(--muted); font-size: 12px; }
.field select {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.button-row { display: grid; gap: 8px; }
.button-row.single-action { grid-template-columns: 1fr; }
.button-row .primary-button { width: 100%; }
.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--soft);
  font-weight: 750;
  text-decoration: none;
}
.download-link:not(.is-disabled) { border-color: rgba(255, 188, 95, 0.58); color: #ffe1ad; }
.download-link.is-disabled { opacity: 0.48; pointer-events: none; }
.download-link[hidden] { display: none; }
.export-note { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.export-toggle { display: flex; align-items: center; gap: 8px; color: var(--soft); font-size: 12px; }
.export-toggle input { width: 16px; height: 16px; }

.preview-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 16px;
}

#previewCanvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.preview-drop {
  position: absolute;
  inset: 16px;
  display: grid;
  place-items: center;
  border: 1px dashed #5a6663;
  border-radius: 10px;
  background: var(--overlay);
  text-align: center;
}

.preview-drop[hidden] { display: none; }
.preview-drop .drop-inner strong { display: block; font-size: 15px; }
.preview-drop .drop-inner small { color: var(--muted); }

.workspace.is-dragging .preview-drop {
  border-color: var(--accent);
  background: rgba(20, 40, 36, 0.6);
}

.transport {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.transport-spacer { flex: 1 1 auto; }
.time-readout { color: var(--soft); font-variant-numeric: tabular-nums; font-size: 13px; }
.transport .hint { color: var(--muted); font-size: 12px; }

/* ---- Timeline ---- */
.timeline {
  position: relative;
  display: grid;
  grid-template-rows: 26px 22px minmax(0, 1fr);
  min-height: 0;
  background: var(--panel);
  overflow: hidden;
}

.beat-ruler {
  position: relative;
  border-bottom: 1px solid var(--line);
  background: var(--bg-deep);
  overflow: hidden;
}
.beat-ruler .beat-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}
.beat-ruler .beat-tick.bar {
  border-left-color: rgba(255, 188, 95, 0.5);
  padding-left: 4px;
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  line-height: 22px;
}

.beat-grid {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 3;
}
.beat-grid .gridline {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.05);
}
.beat-grid .gridline.bar { background: rgba(255, 188, 95, 0.22); }

.tempo-controls { display: flex; align-items: center; gap: 8px; }
.tempo-bpm { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.tempo-bpm input {
  width: 54px;
  min-height: 28px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
#snapToggle[aria-pressed="true"] {
  border-color: rgba(212, 162, 74, 0.6);
  background: #2e2613;
  color: #eafff8;
}
#snapDivisionSelect {
  min-height: 28px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--soft);
  font-size: 12px;
}

.timeline-ruler {
  position: relative;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
}

.timeline-ruler .tick {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 1px solid var(--line);
  padding-left: 4px;
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.timeline-body {
  position: relative;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.lane {
  position: relative;
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  border-bottom: 1px solid var(--line);
}

.lane-composite { background: #11201d; }

.lane-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  min-width: 0;
}

.lane-title {
  font-size: 12px;
  font-weight: 750;
  color: var(--soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lane-head .lane-spacer { flex: 1 1 auto; }

.lane-head .lane-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  min-height: 26px;
  padding: 0;
  border-radius: 6px;
  font-size: 13px;
  color: var(--muted);
}

.lane-head .lane-btn.is-active { color: var(--accent); border-color: rgba(64,215,181,0.5); }

.lane-track {
  position: relative;
  min-height: 64px;
  background: repeating-linear-gradient(90deg, #141817 0, #141817 39px, #181d1c 39px, #181d1c 40px);
}

.lane-composite .lane-track { min-height: 56px; background: #0e1c19; }

/* clip block */
.clip {
  position: absolute;
  top: 6px;
  bottom: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
  cursor: default;
  user-select: none;
}

.clip-zone { position: absolute; left: 8px; right: 8px; }
.clip-zone.top { top: 0; height: 50%; cursor: crosshair; }
.clip-zone.bottom { top: 50%; height: 50%; cursor: grab; }
.clip-zone.bottom:active { cursor: grabbing; }
.clip-zone.full { top: 0; bottom: 0; cursor: grab; }
.clip-zone.full:active { cursor: grabbing; }

.clip-audio {
  background: repeating-linear-gradient(90deg, #16252b 0, #16252b 3px, #1a2d33 3px, #1a2d33 6px);
}
.lane-audio .lane-track { min-height: 48px; }

.clip.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(64,215,181,0.5) inset; }
.clip .clip-label {
  position: absolute;
  left: 8px;
  top: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--soft);
  pointer-events: none;
  white-space: nowrap;
}

.clip .trim-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  background: rgba(212, 162, 74, 0.18);
}
.clip .trim-handle.left { left: 0; }
.clip .trim-handle.right { right: 0; }

/* swipe override band on a source lane */
.override-band {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(212, 162, 74, 0.22);
  border-left: 1px solid rgba(64,215,181,0.6);
  border-right: 1px solid rgba(64,215,181,0.6);
  cursor: grab;
}
.override-band:active { cursor: grabbing; }

.override-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 7px;
  cursor: ew-resize;
  background: rgba(212, 162, 74, 0.55);
}
.override-handle.left { left: 0; }
.override-handle.right { right: 0; }

/* minimal per-lane audio button */
.lane-btn.audio-btn {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.lane-btn.audio-btn svg { width: 15px; height: 15px; fill: currentColor; }
.lane-btn.audio-btn.is-active { color: var(--accent); }
.lane-btn.audio-btn:hover { background: var(--surface-2); }

/* export controls (transport bar) */
.export-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.export-controls label { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.export-controls select {
  min-height: 28px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--soft);
  font-size: 12px;
}

/* composite segment block */
.comp-seg {
  position: absolute;
  top: 6px;
  bottom: 6px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  overflow: hidden;
  cursor: pointer;
}
.comp-seg { border-left-width: 3px; }

.comp-seg-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.comp-seg .comp-seg-label {
  position: absolute;
  left: 8px;
  top: 5px;
  z-index: 1;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  pointer-events: none;
  white-space: nowrap;
}
.comp-seg.is-selected { box-shadow: 0 0 0 2px var(--accent) inset; }

.comp-seg { z-index: 1; }
.xfade-handle {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 12px;
  margin-left: -6px;
  border-radius: 4px;
  background: rgba(255, 188, 95, 0.5);
  border: 1px solid var(--accent-2);
  cursor: ew-resize;
  z-index: 6;
}

.timeline-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 4px;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
}
.timeline-empty[hidden] { display: none; }
.timeline-empty strong { color: var(--soft); }

.timeline-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--accent-2);
  pointer-events: none;
  z-index: 5;
}

/* ---- Export ratio chips (ported from frameflow for export parity) ---- */
.ratio-toolbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

.topbar-ratio-toolbar {
  flex: 0 1 330px;
  min-width: 0;
}

.topbar-ratio-toolbar .ratio-chips {
  max-width: min(28vw, 320px);
  overflow-x: auto;
  scrollbar-width: none;
}

.topbar-ratio-toolbar .ratio-chips::-webkit-scrollbar {
  display: none;
}

.ratio-chips {
  display: flex;
  gap: 5px;
}

.ratio-remove-button,
.ratio-select-button,
.ratio-add-button {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--soft);
  font-size: 12px;
  font-weight: 800;
}

.ratio-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.ratio-remove-button {
  min-height: 20px;
  width: 20px;
  padding: 0;
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
}

.ratio-chip.is-active .ratio-select-button {
  border-color: rgba(76, 212, 154, 0.66);
  color: #dffff8;
  background: #2e2613;
}

.ratio-chip.is-active .ratio-remove-button {
  border-color: rgba(76, 212, 154, 0.36);
}

.ratio-add-button {
  width: 28px;
  padding: 0;
}

.ratio-menu {
  position: absolute;
  z-index: 40;
  top: 34px;
  left: 0;
  display: grid;
  gap: 4px;
  min-width: 132px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--overlay);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

.ratio-menu.is-hidden {
  display: none;
}

.ratio-menu button {
  justify-content: flex-start;
  min-height: 30px;
  padding: 0 9px;
  border-radius: 6px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 750;
  text-align: left;
}

/* Collapsible right export panel (shared handle in right-drawer.js). */
body.is-right-collapsed .export-panel { display: none; }
body.is-right-collapsed .workspace { grid-template-columns: minmax(0, 1fr); }
