/* ================== TOKENS ================== */
:root {
  --bg: #0e0d10;
  --surface-1: #16151a;
  --surface-2: #1d1c22;
  --surface-3: #26252c;
  --border: #2c2b33;
  --border-strong: #3a3942;
  --text: #e8e6ee;
  --text-dim: #8f8d99;
  --text-faint: #5b5963;
  --accent: oklch(0.74 0.16 60);
  --accent-2: oklch(0.66 0.18 280);
  --danger: #ff5a4f;
  --radius: 6px;
  --radius-lg: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}
.theme-light {
  --bg: #f4f3ef;
  --surface-1: #ffffff;
  --surface-2: #f0eee9;
  --surface-3: #e7e4dd;
  --border: #d9d6cf;
  --border-strong: #c0bdb4;
  --text: #1c1b1f;
  --text-dim: #6e6c75;
  --text-faint: #a3a0a8;
}

* { box-sizing: border-box; }
html, body, #root { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
body.dragging,
body.dragging * {
  user-select: none !important;
  -webkit-user-select: none !important;
  cursor: inherit;
}
/* While the user is holding the right mouse button to brush-erase clips
   in Paint mode, force the delete cursor everywhere so it stays visible
   over clips, the ruler, label gutter, and any other inner element. */
body.right-deleting,
body.right-deleting * {
  user-select: none !important;
  -webkit-user-select: none !important;
  cursor: not-allowed !important;
}
.timeline, .clip, .tl-row-cells, .wave-canvas, .tl-ruler {
  user-select: none;
  -webkit-user-select: none;
}
.mono { font-family: var(--mono); font-feature-settings: 'tnum'; }

button { font-family: inherit; cursor: pointer; border: 0; }
input { font-family: inherit; }

/* ================== APP ================== */
.app {
  display: grid;
  grid-template-rows: 56px 56px 1fr;
  height: 100vh;
  background: var(--bg);
  color: var(--text);
}
.main {
  display: grid;
  grid-template-columns: 280px 1fr 340px;
  min-height: 0;
  background: var(--bg);
}
.left, .center, .right {
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.left { border-right: 1px solid var(--border); }
.right { border-left: 1px solid var(--border); }

/* ================== TOP BAR ================== */
.topbar {
  display: grid;
  grid-template-columns: 220px auto auto 1fr auto auto;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface-1));
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { display: grid; grid-template-columns: repeat(3, 8px); gap: 3px; }
.brand-mark span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--accent);
}
.brand-mark span:nth-child(2) { background: oklch(0.74 0.16 200); box-shadow: 0 0 8px oklch(0.74 0.16 200); }
.brand-mark span:nth-child(3) { background: oklch(0.74 0.16 320); box-shadow: 0 0 8px oklch(0.74 0.16 320); }
.brand-title { font-size: 13px; font-weight: 700; letter-spacing: 0.18em; }
.brand-sub { font-size: 9px; color: var(--text-faint); letter-spacing: 0.14em; text-transform: uppercase; font-family: var(--mono); }
/* Inline-editable project name in the top bar. Borderless until focused
   so it reads as a label, not a form field. */
.project-name {
  width: 200px;
  background: transparent;
  border: none;
  outline: none;
  padding: 2px 4px;
  margin: 0;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s, color 0.15s;
}
.project-name:hover { color: var(--text); border-bottom-color: rgba(255,255,255,0.15); }
.project-name:focus { color: var(--text); border-bottom-color: rgba(255,255,255,0.4); }

.transport { display: flex; gap: 4px; }
.tbtn {
  width: 32px; height: 32px;
  background: var(--surface-3); color: var(--text);
  border-radius: 4px;
  font-size: 13px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
}
.tbtn:hover { background: var(--border-strong); }
.tbtn.active { background: var(--accent); color: var(--bg); border-color: var(--accent); box-shadow: 0 0 12px var(--accent); }

.readouts { display: flex; gap: 10px; }
.readout {
  display: flex; flex-direction: column; gap: 1px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  min-width: 64px;
}
.ro-label { font-size: 8px; color: var(--text-faint); letter-spacing: 0.14em; font-family: var(--mono); }
.ro-value { font-size: 14px; font-weight: 600; color: var(--text); }
.ro-input { background: transparent; border: 0; color: var(--text); font-size: 14px; font-weight: 600; width: 48px; padding: 0; font-family: var(--mono); outline: none; }

.tools { display: flex; gap: 4px; }
.tool {
  width: 30px; height: 30px;
  border-radius: 4px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
}
.tool.on { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.tool.export-btn {
  width: auto;
  padding: 0 10px;
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text);
}
.tool.export-btn:hover { background: var(--accent); color: var(--bg); border-color: var(--accent); }

/* file menu dropdown */
.file-menu { position: relative; }
.file-menu-btn {
  width: auto;
  padding: 0 12px;
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text);
  display: flex; align-items: center; gap: 4px;
}
.file-menu-btn:hover { background: var(--surface-3); }
.file-menu-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.3);
  padding: 4px;
  z-index: 100;
  display: flex; flex-direction: column; gap: 1px;
  animation: fmFadeIn 0.08s ease-out;
}
@keyframes fmFadeIn {
  from { opacity: 0; transform: translateY(-2px); }
  to { opacity: 1; transform: translateY(0); }
}
.file-menu-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
}
.file-menu-item:hover { background: var(--surface-3); }
.file-menu-item.primary { color: var(--accent); }
.file-menu-item.primary:hover { background: var(--accent); color: var(--bg); }
.file-menu-item.primary:hover .fm-hint { color: var(--bg); opacity: 0.8; }
.fm-glyph {
  font-family: var(--mono);
  font-size: 14px;
  text-align: center;
  color: var(--text-dim);
}
.file-menu-item:hover .fm-glyph,
.file-menu-item.primary .fm-glyph { color: inherit; }
.fm-label { font-weight: 600; }
.fm-hint {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-faint);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.file-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

/* resolution selector */
.res-group {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px 3px 10px;
}
.res-label {
  font-size: 8px; color: var(--text-faint); letter-spacing: 0.16em;
}
.res-list {
  display: flex; gap: 2px;
  background: var(--bg);
  border-radius: 3px;
  padding: 2px;
}
.res-btn {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 2px;
  letter-spacing: 0.04em;
  min-width: 36px;
}
.res-btn:hover { color: var(--text); }
.res-btn.on {
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 0 8px oklch(0.74 0.16 60 / 0.4);
}

/* ================== COMMAND BAR ================== */
.cmdbar {
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  align-items: center;
  gap: 18px;
  padding: 0 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.cmdbar-section { display: flex; align-items: center; gap: 10px; }
.cmdbar-label { font-size: 9px; letter-spacing: 0.18em; color: var(--text-faint); font-family: var(--mono); }
.cmdbar-divider { width: 1px; height: 28px; background: var(--border); }
.cmd-list { display: flex; gap: 4px; }
.cmd-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.cmd-btn:hover { border-color: var(--border-strong); }
.cmd-btn.on {
  background: var(--accent); color: var(--bg); border-color: var(--accent);
  box-shadow: 0 0 10px oklch(0.74 0.16 60 / 0.4);
}
.cmd-icon { font-size: 13px; line-height: 1; }
.cmd-name { font-size: 11px; }

.palette {
  display: flex; gap: 4px; flex-wrap: wrap;
  max-width: 360px;
}
.swatch {
  width: 22px; height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.4);
  cursor: pointer;
}
.swatch-add {
  background: var(--surface-3);
  color: var(--text);
  font-size: 14px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px dashed var(--border);
}
.swatch-add:hover { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }
.swatch-popover {
  position: fixed;
  z-index: 1000;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  display: flex; flex-direction: column; gap: 6px;
  min-width: 140px;
}
.swatch-popover-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; font-size: 10px; letter-spacing: 0.1em; color: var(--text-dim);
}
.swatch-popover-row input[type="color"] {
  width: 36px; height: 24px; padding: 0; border: 1px solid var(--border);
  background: transparent; cursor: pointer;
}
.swatch-popover-remove {
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 8px; font-size: 11px; cursor: pointer;
}
.swatch-popover-remove:hover:not(:disabled) { background: #c0392b; color: white; border-color: #c0392b; }
.swatch-popover-remove:disabled { opacity: 0.4; cursor: not-allowed; }
.swatch-popover-actions {
  display: flex; align-items: center; gap: 6px;
  margin-top: 4px;
}
.swatch-popover-spacer { flex: 1; }
.swatch-popover-btn {
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 10px; font-size: 11px; cursor: pointer;
  font-family: var(--mono); letter-spacing: 0.04em;
}
.swatch-popover-btn:hover { background: var(--surface-2); }
.swatch-popover-btn.primary {
  background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 700;
}
.swatch-popover-btn.primary:hover { filter: brightness(1.08); }
.swatch-popover-preview {
  height: 24px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.cmdbar-hint { font-size: 9px; color: var(--text-faint); text-align: right; letter-spacing: 0.04em; }

/* ================== TRACK LIST ================== */
.tracklist { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.tl-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.tl-title { font-size: 10px; letter-spacing: 0.16em; color: var(--text-dim); font-family: var(--mono); }
.tl-add-group { position: relative; }
.tl-add {
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 8px; border-radius: 4px; font-size: 11px;
}
.tl-add:hover { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.tl-add-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  padding: 4px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: 0 12px 32px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  gap: 1px;
  z-index: 30;
}
.tl-add-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 12px;
}
.tl-add-item:hover { background: var(--surface-3); }

.tl-rows { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.tl-ball {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.tl-ball-row { display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; align-items: center; margin-bottom: 6px; }
.tl-handle {
  width: 32px; height: 22px;
  border-radius: 4px;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 10px; font-weight: 700;
  color: rgba(0,0,0,0.7); letter-spacing: 0.06em;
}
.tl-name { font-size: 12px; font-weight: 500; }
.tl-leds { display: flex; gap: 6px; }
.tl-rm {
  width: 18px; height: 18px;
  background: transparent; color: var(--text-faint);
  border-radius: 3px; font-size: 14px; line-height: 1;
}
.tl-rm:hover { background: var(--danger); color: white; }

.led-dot { display: flex; align-items: center; gap: 3px; }
.led-dot-label { font-family: var(--mono); font-size: 8px; color: var(--text-faint); }
.led-dot-bulb { width: 8px; height: 8px; border-radius: 50%; transition: all .06s linear; }

.tl-led-row { display: grid; grid-template-columns: 38px 1fr; gap: 6px; align-items: center; margin-top: 2px; }
.tl-led-tag { font-family: var(--mono); font-size: 8px; color: var(--text-faint); letter-spacing: 0.1em; }
.tl-led-meter { height: 4px; background: var(--surface-3); border-radius: 2px; overflow: hidden; }
.tl-led-fill { height: 100%; transition: all .06s linear; }

/* ================== WAVEFORM ================== */
.wave-track {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  height: 96px;
  flex: 0 0 96px;
  display: grid;
  grid-template-columns: 110px 1fr;
}
.wave-viewport {
  position: relative;
  overflow: hidden;
  height: 96px;
}
.wave-rail {
  position: relative;
  height: 96px;
  will-change: transform;
}
.wave-label {
  background: var(--surface-3);
  border-right: 1px solid var(--border);
  padding: 8px 10px;
  display: flex; flex-direction: column; gap: 2px; justify-content: center;
}
.wave-label-title { font-size: 10px; letter-spacing: 0.18em; color: var(--text); font-weight: 700; }
.wave-label-sub { font-size: 9px; color: var(--text-faint); }
.wave-label-bpm {
  margin-top: 4px;
  font-size: 9px; color: var(--accent); letter-spacing: 0.1em;
  align-self: flex-start;
  background: oklch(0.74 0.16 60 / 0.12);
  padding: 1px 6px; border-radius: 3px;
}
.wave-label-actions {
  display: flex; gap: 4px; margin-top: 6px;
}
.wave-import-btn {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px;
  font-size: 9px; letter-spacing: 0.06em; font-weight: 700;
  padding: 3px 6px; cursor: pointer;
  font-family: var(--mono);
}
.wave-import-btn:hover { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.wave-canvas {
  position: relative;
  height: 96px;
  cursor: pointer;
  overflow: hidden;
  background:
    linear-gradient(180deg, var(--surface-1) 0%, oklch(0.13 0.005 60) 100%);
}
.wave-bars {
  display: flex; align-items: center;
  height: 100%;
  width: 100%;
  gap: 1px;
  padding: 8px 0;
}
.wave-bar {
  flex: 1;
  min-height: 2px;
  background: linear-gradient(180deg, var(--accent), oklch(0.55 0.14 60));
  border-radius: 1px;
  align-self: center;
}
.wave-svg { width: 100%; height: 100%; display: block; }
.wave-spec { display: flex; height: 100%; gap: 0; }
.wave-spec-col { flex: 1; height: 100%; }

.wave-ticks {
  position: absolute; inset: 0;
  pointer-events: none;
}
.wave-tick {
  position: absolute; top: 0; bottom: 0;
  border-left: 1px solid rgba(255,255,255,0.06);
}
.wave-tick.bar { border-left-color: rgba(255,255,255,0.18); }
.wave-tick-num { position: absolute; top: 4px; left: 4px; font-size: 9px; color: var(--text-faint); }
.wave-playhead {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  pointer-events: none;
  z-index: 5;
}
.wave-clip {
  user-select: none;
  border-left: 1px solid rgba(255,255,255,0.18);
  border-right: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.02);
}
.wave-clip:hover { background: rgba(255,255,255,0.04); }
body.dragging .wave-clip { cursor: grabbing; }
.wave-trim-handle {
  position: absolute; top: 0; bottom: 0;
  width: 6px;
  background: rgba(255,255,255,0.12);
  cursor: ew-resize;
  z-index: 4;
}
.wave-trim-handle:hover { background: var(--accent); }
.wave-trim-start { left: 0; }
.wave-trim-end { right: 0; }
.wave-volume {
  display: flex; align-items: center; gap: 6px;
  margin-top: 4px;
  font-size: 9px; color: var(--text-faint); letter-spacing: 0.12em;
}
.wave-volume input[type="range"] {
  flex: 1; min-width: 0; height: 14px;
  accent-color: var(--accent);
}

/* ================== TIMELINE ================== */
.center { display: flex; flex-direction: column; }
.timeline { flex: 1; overflow: auto; position: relative; background: var(--surface-1); }
.tl-ruler {
  position: sticky; top: 0; z-index: 10;
  height: 28px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  margin-left: 110px;
}
.tl-tick { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--border); }
.tl-tick.bar { border-left-color: var(--border-strong); }
.tl-tick-label { position: absolute; top: 4px; left: 4px; font-size: 10px; color: var(--text-dim); font-weight: 600; }
.tl-playhead-head { position: absolute; top: 0; bottom: -10000px; pointer-events: none; }
.tl-playhead-flag {
  position: absolute; top: 2px; left: -16px;
  background: var(--accent); color: var(--bg);
  font-size: 9px; font-weight: 700;
  padding: 2px 5px; border-radius: 3px;
  white-space: nowrap;
}

.tl-grid { position: relative; padding-bottom: 200px; }
.tl-row {
  position: relative;
  height: 30px;
  display: grid; grid-template-columns: 110px 1fr;
  border-bottom: 1px solid var(--border);
}
.tl-row.ledA { background: var(--surface-1); }
.tl-row.ledB { background: var(--surface-2); }
.tl-row-label {
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  border-right: 1px solid var(--border);
  background: inherit;
  position: sticky; left: 0; z-index: 5;
}
.tl-row-ball { font-family: var(--mono); font-size: 10px; font-weight: 700; }
.tl-row-led { font-family: var(--mono); font-size: 9px; color: var(--text-faint); letter-spacing: 0.1em; }
.tl-row-cells { position: relative; height: 100%; }
/* Per-tool cursors on empty grid cells. Each tool gets a distinct shape so
   the active mode is obvious before clicking. */
.timeline.tool-paint  .tl-row-cells { cursor: crosshair; }
.timeline.tool-select .tl-row-cells { cursor: cell; }
.timeline.tool-erase  .tl-row-cells { cursor: not-allowed; }
/* When hovering a clip, paint and select stay as grab (move handle);
   erase becomes the prohibition sign so the user knows the click will
   destroy the clip. */
.timeline.tool-erase  .clip { cursor: not-allowed; }
.tl-subline { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--border); opacity: 0.25; pointer-events: none; }
.tl-subline.beat { opacity: 0.7; background: var(--border-strong); }
.tl-subline.bar { opacity: 1; background: var(--border-strong); width: 1px; }

.tl-playhead {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  pointer-events: none;
  z-index: 8;
  margin-left: 110px;
}

.clip {
  position: absolute; top: 3px; bottom: 3px;
  border-radius: 3px;
  cursor: grab;
  overflow: hidden;
}
.clip:active { cursor: grabbing; }
.clip-fill { position: absolute; inset: 0; border-radius: 3px; }
.clip.sel { outline: 2px solid var(--text); outline-offset: 1px; z-index: 4; }
.clip.overlap {
  outline: 2px solid #ff2d2d;
  outline-offset: 1px;
  box-shadow: 0 0 10px rgba(255,45,45,0.7), 0 0 2px rgba(255,45,45,0.9);
  animation: clip-overlap-pulse 1s ease-in-out infinite;
  z-index: 5;
}
.clip.overlap.sel { outline: 2px solid var(--text); }
.clip.overlap::after {
  content: '⚠ OVERLAP';
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 9px; font-weight: 700; letter-spacing: 0.12em;
  color: #fff;
  text-shadow: 0 0 4px #000, 0 0 2px #000;
  background:
    repeating-linear-gradient(45deg, rgba(255,45,45,0.55) 0 6px, rgba(0,0,0,0.0) 6px 14px),
    rgba(255,45,45,0.18);
  border-radius: 3px;
  pointer-events: none;
  z-index: 4;
}
@keyframes clip-overlap-pulse {
  0%,100% { box-shadow: 0 0 10px rgba(255,45,45,0.7), 0 0 2px rgba(255,45,45,0.9); }
  50%     { box-shadow: 0 0 16px rgba(255,45,45,1),   0 0 4px rgba(255,45,45,1);   }
}
.clip-label {
  position: absolute; left: 4px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; gap: 4px;
  font-size: 9px; font-weight: 600;
  color: rgba(0,0,0,0.85);
  text-shadow: 0 0 4px rgba(255,255,255,0.4);
  letter-spacing: 0.04em;
  pointer-events: none;
  white-space: nowrap;
  z-index: 2;
}
.clip-resize {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: 8px;
  cursor: ew-resize;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25));
  opacity: 0;
  transition: opacity .08s;
  z-index: 3;
}
.clip:hover .clip-resize { opacity: 1; }
.clip.sel .clip-resize { opacity: 1; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.5)); }

.tl-marquee {
  position: absolute;
  background: oklch(0.74 0.16 60 / 0.12);
  border: 1px dashed var(--accent);
  pointer-events: none;
  z-index: 9;
  border-radius: 2px;
}

/* ================== PREVIEW ================== */
.preview {
  border-bottom: 1px solid var(--border);
  padding: 14px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface-1));
}
.preview-head { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.preview-head-row { display: flex; align-items: baseline; justify-content: space-between; }
.preview-title { font-size: 10px; letter-spacing: 0.18em; color: var(--text-dim); font-family: var(--mono); }
.preview-sub { font-size: 9px; color: var(--text-faint); }

/* ---- Performance-sim controls (header inline) ---- */
.preview-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.sim-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px;
  font: 500 10.5px/1 var(--mono, ui-monospace, Menlo, monospace);
  letter-spacing: 0.06em;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s;
}
.sim-toggle:hover { color: var(--text); border-color: var(--text-dim); }
.sim-toggle .sim-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(255,255,255,0.18);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
  transition: background .15s, box-shadow .15s;
}
.sim-toggle.on { color: #ffd28c; border-color: rgba(255,180,80,0.55); background: rgba(255,180,80,0.07); }
.sim-toggle.on .sim-dot {
  background: #ffb060;
  box-shadow: 0 0 6px rgba(255,176,96,0.85), inset 0 0 0 1px rgba(255,220,180,0.9);
}

.sim-pattern {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  height: 24px;
}
.sim-pattern-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 0 8px;
  height: 100%;
  font: 500 10px/1 var(--mono, ui-monospace, Menlo, monospace);
  letter-spacing: 0.06em;
  cursor: pointer;
  border-right: 1px solid var(--border);
  transition: color .12s, background .12s;
}
.sim-pattern-btn:last-child { border-right: 0; }
.sim-pattern-btn:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.sim-pattern-btn.on { color: #ffd28c; background: rgba(255,180,80,0.10); }

.sim-settings-wrap { position: relative; margin-left: auto; }
.sim-gear {
  appearance: none;
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s;
}
.sim-gear:hover, .sim-gear.on { color: var(--text); border-color: var(--text-dim); background: rgba(255,255,255,0.04); }

.sim-popover {
  position: absolute;
  right: 0; top: calc(100% + 6px);
  z-index: 50;
  min-width: 220px;
  padding: 10px 12px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  display: flex; flex-direction: column; gap: 8px;
}
.sim-pop-title {
  font-size: 9px; letter-spacing: 0.18em; color: var(--text-faint);
  margin-bottom: 2px;
}
.sim-slider { display: flex; flex-direction: column; gap: 4px; }
.sim-slider-row {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 10px; color: var(--text-dim);
}
.sim-slider-val { font-size: 10px; color: var(--text-faint); }
.sim-slider input[type="range"] { width: 100%; accent-color: #ffb060; }
.sim-checkbox {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10px; color: var(--text-dim);
  cursor: pointer;
  margin-top: 2px;
}
.sim-checkbox input { accent-color: #ffb060; }
.preview-stage {
  height: 220px;
  background: radial-gradient(circle at 50% 60%, oklch(0.18 0.01 60), oklch(0.10 0.01 60));
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  position: relative;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  padding: 12px;
}
.preview-stage.layout-line { flex-direction: row; gap: 8px; flex-wrap: wrap; }
.preview-stage.layout-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; place-items: center; }
.preview-stage.layout-circle { display: block; }
.preview-stage.layout-performance {
  display: block;
  height: 320px;
  /* Real performance happens in the dark — drop the lighter radial gradient
     so the trails read with full contrast. */
  background: #050505;
}
/* In sim mode the trail canvas IS the light. The stylized orb with its
   specular highlights and shell would otherwise read as a static physical
   object stuck on top of the moving streak. Hide it; keep a small label so
   choreographers can still tell which trail is which ball. */
.preview-stage.layout-performance .ball-orb { display: none; }
.preview-stage.layout-performance .ball-prev {
  pointer-events: none;
  gap: 0;
}
.preview-stage.layout-performance .ball-prev-label {
  font-size: 8px;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.08em;
  text-shadow: 0 0 4px rgba(0,0,0,0.9);
  margin-top: 14px;
}
.preview-stage .trail-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}
.preview-stage .orbit-guide-ring,
.preview-stage .orbit-guide-pivot { z-index: 1; }
.preview-stage .ball-prev { z-index: 2; }
.preview-stage .sim-zoom-overlay { z-index: 5; }

/* Floating zoom widget (only rendered while sim is on) */
.sim-zoom-overlay {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 7px;
  font-size: 10px;
  color: rgba(255,255,255,0.7);
  user-select: none;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.sim-zoom-overlay button {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0;
  font: inherit;
  letter-spacing: 0.04em;
}
.sim-zoom-btn {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 4px;
  font-size: 13px; line-height: 1;
}
.sim-zoom-btn:hover { background: rgba(255,255,255,0.10); color: #fff; }
.sim-zoom-pct {
  min-width: 36px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: rgba(255,255,255,0.85);
}
.sim-zoom-reset {
  height: 18px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.sim-zoom-reset:hover:not(:disabled) { background: rgba(255,255,255,0.10); color: #fff; }
.sim-zoom-reset.dim, .sim-zoom-reset:disabled {
  color: rgba(255,255,255,0.30);
  cursor: default;
}
.preview-stage .orbit-guide-ring {
  position: absolute;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.preview-stage .orbit-guide-ring.weave { border-style: dashed; opacity: 0.6; }
.preview-stage .orbit-guide-pivot {
  position: absolute;
  width: 4px; height: 4px;
  background: rgba(255,255,255,0.25);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.ball-prev { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.ball-orb {
  width: 44px; height: 44px;
  border-radius: 50%;
  position: relative;
  transition: box-shadow .06s linear;
  isolation: isolate;
  overflow: hidden;
}
/* dark translucent diffuser body — visible when LEDs are off / dim */
.ball-body {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2b2a30 0%, #141318 70%, #0a0a0d 100%);
  border: 1px solid rgba(255,255,255,0.05);
}
/* additive light layer — uses mix-blend-mode: screen on inline style */
.ball-light {
  position: absolute; inset: 0;
  border-radius: 50%;
  pointer-events: none;
  transition: background .05s linear;
}
/* canvas variant: per-ball linear-light renderer (replaces .ball-light).
   The canvas already does its own circular mask, so no border-radius needed,
   but we still clip to the orb in case the diffuser σ pushes light outside. */
.ball-light-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border-radius: 50%;
  pointer-events: none;
  image-rendering: auto; /* let the browser smooth the upscale */
}
/* glossy specular highlight on top */
.ball-spec {
  position: absolute; inset: 0;
  border-radius: 50%;
  pointer-events: none;
  background:
    radial-gradient(ellipse 50% 30% at 32% 22%, rgba(255,255,255,0.22), transparent 70%),
    radial-gradient(circle at 50% 50%, transparent 60%, rgba(0,0,0,0.35) 100%);
  mix-blend-mode: screen;
}
/* tiny bright die visible through diffuser */
.ball-die {
  position: absolute;
  width: 4px; height: 4px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 3;
  transition: all .05s linear;
}
.ball-prev-label { font-size: 9px; color: var(--text-faint); letter-spacing: 0.06em; }

/* ================== INSPECTOR ================== */
.inspector { padding: 14px; flex: 1; overflow-y: auto; }
.ins-title {
  font-size: 10px; letter-spacing: 0.18em; font-family: var(--mono);
  color: var(--text-dim); margin-bottom: 14px;
  border-bottom: 1px solid var(--border); padding-bottom: 8px;
}
.ins-section { margin-bottom: 14px; }
.ins-label, .ins-label-row { font-size: 9px; letter-spacing: 0.14em; color: var(--text-faint); font-family: var(--mono); margin-bottom: 6px; text-transform: uppercase; }
.ins-label-row { display: flex; justify-content: space-between; }
.ins-val { color: var(--text); font-size: 11px; }
.ins-swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.ins-sw { width: 100%; aspect-ratio: 1; border-radius: 4px; border: 1px solid rgba(0,0,0,0.4); }
.ins-sw.on { outline: 2px solid var(--text); outline-offset: 2px; }

.ins-cmd-list { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; }
.ins-cmd {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font-size: 10px;
}
.ins-cmd.on { background: var(--accent); color: var(--bg); border-color: var(--accent); }

.inspector input[type="range"] {
  width: 100%; -webkit-appearance: none;
  height: 4px; background: var(--surface-3);
  border-radius: 2px; outline: none;
}
.inspector input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  box-shadow: 0 0 8px var(--accent);
}
.ins-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ins-cell { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 6px 10px; }
.ins-del {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
  padding: 8px; border-radius: 4px;
  margin-top: 12px; font-size: 11px;
}
.ins-del:hover { background: var(--danger); color: white; border-color: var(--danger); }
.inspector.empty .ins-empty { font-size: 12px; color: var(--text-dim); line-height: 1.6; }
.ins-empty-sub { font-size: 10px; color: var(--text-faint); font-family: var(--mono); }

/* scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--surface-1); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
