:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #222631;
  --border: #2c3140;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --accent: #6c8cff;
  --accent-2: #00d6a4;
  --danger: #ff5c7a;
  --port: #6c8cff;
  --port-out: #00d6a4;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

#toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  height: 58px;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; }

/* Cloud save state: reads CloudStore's pending-write count, never a guess. */
.sync-pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #223; color: #9be29b; border: 1px solid #334; }
.sync-pill[data-state="saving"] { color: #f7cb61; }
.sync-pill[data-state="offline"] { color: #f08080; }
.version-pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #3a2a10; color: #f7cb61; border: 1px solid #665020; cursor: pointer; }
.spacer { flex: 1; }
.add-label { color: var(--muted); font-size: 13px; }

select {
  padding: 7px 10px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text);
  font-size: 13px;
}

.btn {
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel-2);
  color: var(--text); font-size: 13px; font-weight: 600;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }

.settings-panel {
  position: absolute; top: 70px; right: 14px; z-index: 80;
  width: 340px; padding: 14px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 18px 50px rgba(0,0,0,.45);
}
.settings-head, .settings-actions { display: flex; align-items: center; justify-content: space-between; }
.settings-title { font-size: 16px; font-weight: 700; }
.settings-section { margin-top: 14px; }
.settings-label {
  display: block; margin-bottom: 8px;
  color: var(--muted); font-size: 12px; font-weight: 700;
}
.settings-input {
  width: 100%; padding: 8px 10px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 13px;
}
.settings-storage-row { display: flex; align-items: center; gap: 8px; }
.settings-storage-name {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  padding: 7px 8px; font-size: 12px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  white-space: nowrap;
}
#settingsAccountEmail { display: block; }
.settings-colors { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.settings-keys { display: flex; flex-direction: column; gap: 6px; }
.settings-key-row { display: flex; align-items: center; gap: 6px; }
.settings-key-name { font-size: 12px; min-width: 110px; }
.settings-key-status { font-size: 11px; opacity: 0.7; min-width: 86px; }
.settings-key-row .settings-input { flex: 1; min-width: 0; }
.settings-check-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text); cursor: pointer; }
.settings-color-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 8px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px;
}
.settings-color-row span { font-size: 12px; text-transform: capitalize; }
.settings-color-row input { width: 34px; height: 26px; padding: 0; border: 0; background: transparent; }
.settings-actions { justify-content: flex-end; margin-top: 14px; }

/* Sign-in gate: covers the editor until an allowlisted user is signed in */
.gate {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.gate[hidden] { display: none; }
.gate-card {
  width: 380px; max-width: calc(100vw - 40px); padding: 28px 30px; text-align: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 18px 50px rgba(0,0,0,.45);
}
.gate-card h1 { margin: 0 0 8px; font-size: 22px; }
.gate-card p { margin: 0 0 18px; color: var(--muted); font-size: 13px; line-height: 1.5; }

/* AI graph-builder dialog (opened from the "+" add-tab menu) */
.ai-dialog-overlay {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: flex-start; justify-content: center;
  background: rgba(0,0,0,.45);
}
.ai-dialog {
  margin-top: 120px; width: 520px; max-width: calc(100vw - 40px);
  padding: 14px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 18px 50px rgba(0,0,0,.45);
}
.ai-dialog-head { display: flex; align-items: center; justify-content: space-between; }
.ai-dialog-title { font-size: 16px; font-weight: 700; }
.ai-dialog-input {
  width: 100%; margin-top: 12px; padding: 8px 10px; resize: vertical;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 13px; font-family: inherit;
}
.ai-dialog-budget {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 10px; color: var(--muted); font-size: 12px;
}
.ai-dialog-budget input[type="range"] { width: 140px; }
.ai-dialog-status {
  margin-top: 10px; min-height: 16px;
  color: var(--muted); font-size: 12px; white-space: pre-wrap;
}
.ai-dialog-status.error { color: var(--danger); }
.ai-dialog-status.warn { color: var(--accent-2); }
.ai-dialog-actions { display: flex; justify-content: flex-end; margin-top: 12px; }

/* tab bar (project tabs, photoshop-style) sits under the toolbar */
#tabbar {
  position: absolute; top: 58px; left: 0; right: 0; height: 34px;
  display: flex; align-items: stretch; gap: 0;
  padding: 0 8px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden;
}
#tabs { display: flex; align-items: stretch; gap: 4px; }
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 0 12px; max-width: 220px;
  font-size: 12px; color: var(--muted); cursor: pointer;
  background: var(--panel); border: 1px solid var(--border);
  border-bottom: none; border-radius: 8px 8px 0 0;
  margin-top: 5px; white-space: nowrap; user-select: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--bg); border-color: var(--accent); }
.tab .tab-name { overflow: hidden; text-overflow: ellipsis; }
.tab .tab-dirty { color: var(--accent-2); font-weight: 700; }
.tab .tab-close {
  font-size: 14px; line-height: 1; color: var(--muted);
  border-radius: 4px; padding: 0 3px;
}
.tab .tab-close:hover { color: var(--danger); background: rgba(255,92,122,.15); }
.tab.dragging { opacity: .45; }
.tab.drop-before { box-shadow: -2px 0 0 0 var(--accent); }
.tab.drop-after { box-shadow: 2px 0 0 0 var(--accent); }
.tab-rename-input {
  width: 110px; padding: 2px 4px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--accent);
  border-radius: 4px; color: var(--text); outline: none;
}
.tab-new {
  align-self: center; margin: 5px 0 0 6px;
  width: 26px; height: 24px; padding: 0; line-height: 1;
  font-size: 16px; cursor: pointer; color: var(--muted);
  background: transparent; border: 1px solid var(--border); border-radius: 6px;
}
.tab-new:hover { color: var(--text); border-color: var(--accent); }

#canvas {
  position: absolute; top: 92px; bottom: 28px; left: 0; right: 0;
  overflow: hidden;
  background-image:
    radial-gradient(circle, #232838 1px, transparent 1px);
  background-size: 22px 22px;
  cursor: default;
}
#canvas.panning { cursor: grabbing; }
/* undo / redo live on the work area, not the toolbar: history is scoped to the tab */
.undo-bar {
  position: absolute; top: 8px; left: 8px; z-index: 5;
  display: flex; gap: 4px; padding: 3px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
}
.undo-bar .btn:disabled { opacity: .35; cursor: default; }
#wires { position: absolute; top: 0; left: 0; width: 4000px; height: 3000px; pointer-events: none; transform-origin: 0 0; overflow: visible; }
#nodes { position: absolute; top: 0; left: 0; width: 4000px; height: 3000px; transform-origin: 0 0; }

.node {
  position: absolute; width: 280px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.4);
  user-select: none;
}
.node.running { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(108,140,255,.4); }
.node.done { border-color: var(--accent-2); }
.node.error { border-color: var(--danger); }

.node-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; cursor: grab;
  background: var(--panel-2); border-radius: 12px 12px 0 0;
  border-bottom: 1px solid var(--border);
}
.node-head .title { font-size: 13px; font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* debug id badge — only visible when the "Show node IDs" setting is on */
.node-head .node-id { display: none; font-size: 11px; font-weight: 700; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; }
body.show-node-ids .node-head .node-id { display: inline-block; }
.node-head .run { color: var(--accent-2); cursor: pointer; font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 4px; }
.node-head .run:hover { background: var(--accent-2); color: #0f1115; }
.node-head .reset-3d { color: var(--accent); cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 4px; border-radius: 4px; }
.node-head .reset-3d:hover { background: var(--accent); color: #0f1115; }
.node-head .gpu-status { cursor: pointer; font-size: 12px; line-height: 1; padding: 2px 4px; border-radius: 4px; }
.node-head .gpu-status:hover { background: var(--accent); }
.node-head .node-cancel { color: var(--danger); cursor: pointer; font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 4px; }
.node-head .node-cancel:hover { background: var(--danger); color: #0f1115; }
.node-head .size-up, .node-head .size-down {
  color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1;
  padding: 2px 4px; border-radius: 4px; font-weight: 700;
}
.node-head .size-up:hover, .node-head .size-down:hover { background: var(--accent); color: #0f1115; }
.node-head .del { color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; }
.node-head .del:hover { color: var(--danger); }

/* Group box — an organizational frame that sits behind node cards. Its tint
   (border/fills) is set inline per box by GroupBoxView from the box's color. */
.group-box {
  position: absolute; box-sizing: border-box;
  border: 1.5px solid; border-radius: 12px;
  user-select: none;
}
.group-box-head {
  display: flex; align-items: center; justify-content: flex-end; gap: 6px;
  padding: 5px 10px; cursor: grab;
  border-radius: 10px 10px 0 0;
}
/* Name label sits in the box body, not the header; its size/opacity come from
   config.js (GROUP_BOX_NAME_FONT_SIZE / GROUP_BOX_NAME_OPACITY) via inline style. */
.group-box .gb-name {
  display: block; width: calc(100% - 24px); margin: 6px 12px 0;
  font-weight: 700; background: transparent; border: none; outline: none;
  color: var(--text); padding: 0;
}
.group-box-head .gb-color {
  width: 22px; height: 18px; padding: 0; border: none;
  background: transparent; cursor: pointer;
}
.group-box-head .del { color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; }
.group-box-head .del:hover { color: var(--danger); }
.gb-resize {
  position: absolute; right: 0; bottom: 0; width: 16px; height: 16px;
  cursor: nwse-resize; border-radius: 8px 0 10px 0;
}

/* Loop box — a REAL node rendered as a frame: its body (the nodes inside) is
   click-through (pointer-events pass to the member cards), while the header,
   control panel, pins and grip stay interactive. Size is set inline from
   node.values.w/h by the strategy. */
.node.loop-box-node {
  pointer-events: none;
  background: rgba(108,140,255,.05);
  border: 2px dashed var(--accent);
  box-shadow: none;
}
.node.loop-box-node .node-head,
.node.loop-box-node .node-body,
.node.loop-box-node .node-foot,
.node.loop-box-node .node-duplicate,
.node.loop-box-node .port,
.node.loop-box-node .loop-box-resize { pointer-events: auto; }
.node.loop-box-node .node-head {
  background: rgba(108,140,255,.16);
  border-bottom: 1px dashed var(--accent);
}
.node.loop-box-node .node-head .badge { color: var(--accent); font-weight: 700; }
.node.loop-box-node .node-head .size-up,
.node.loop-box-node .node-head .size-down { display: none; }
.node.loop-box-node .node-body {
  width: 240px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0 0 10px 0;
}
.node.loop-box-node .node-foot { width: 240px; }
.node.loop-box-node .node-duplicate {
  position: absolute; left: 8px; bottom: 8px; width: auto; padding: 3px 10px;
}
.node-head .loop-stop { color: var(--danger); cursor: pointer; font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 4px; }
.node-head .loop-stop:hover { background: var(--danger); color: #0f1115; }
.node-head .loop-clear { color: var(--muted); cursor: pointer; font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 4px; }
.node-head .loop-clear:hover { background: var(--accent); color: #0f1115; }
.node-head .loop-redo { color: var(--danger); cursor: pointer; font-size: 11px; line-height: 1; padding: 2px 5px; border-radius: 4px; border: 1px solid var(--danger); }
.node-head .loop-redo:hover { background: var(--danger); color: #0f1115; }
.node.foreach-box-node .fe-seg.fe-fail { cursor: pointer; }
/* interior iteration pin: sits on the panel's right edge, facing INTO the box */
.node.loop-box-node .loop-i-port { right: auto; left: 232px; }
.node.loop-box-node .loop-i-row { margin-bottom: 4px; }
.node.loop-box-node .loop-i-row label { color: var(--accent); text-align: right; margin-bottom: 0; }
/* For Each Box: teal frame accent + per-slot progress strip (fills out of order) */
.node.foreach-box-node { border-color: rgba(0, 214, 164, .45); }
.node.foreach-box-node .fe-strip { display: flex; gap: 2px; margin: 6px 0 2px; }
.node.foreach-box-node .fe-seg { flex: 1; height: 6px; min-width: 4px; border-radius: 2px; background: var(--panel-2); border: 1px solid var(--border); }
.node.foreach-box-node .fe-seg.fe-done { background: var(--accent-2); border-color: var(--accent-2); }
.node.foreach-box-node .fe-seg.fe-fail { background: var(--danger); border-color: var(--danger); }
.node.foreach-box-node .fe-seg.fe-running { background: var(--accent); border-color: var(--accent); animation: fe-pulse 1.2s ease-in-out infinite; }
.node.foreach-box-node .fe-seg.fe-canceled { background: var(--muted); border-color: var(--muted); opacity: .5; }
@keyframes fe-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
/* Results dock: right-interior panel whose in-pin faces INTO the box, so the
   final node has a visible destination (its wire names the terminal node) */
.node.foreach-box-node .fe-result-panel {
  position: absolute; top: 36px; right: 0; width: 340px;
  padding: 8px 10px; box-sizing: border-box; pointer-events: auto;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 0 0 0 10px;
}
.node.foreach-box-node .fe-result-panel label {
  display: block; font-size: 11px; color: var(--accent-2); margin: 0;
}
/* the box's outcome preview lives in the dock (output side), not the left panel */
.node.foreach-box-node .fe-result-panel .node-foot { width: auto; padding: 8px 0 0; }
.node.foreach-box-node .fe-result-port { left: auto; right: 332px; }
.loop-box-resize {
  position: absolute; right: 0; bottom: 0; width: 16px; height: 16px;
  cursor: nwse-resize; border-radius: 8px 0 10px 0;
  background: rgba(108,140,255,.45);
}

.node-body { padding: 10px 12px; }
.field { margin-bottom: 9px; }
.field label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 6px 8px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); resize: vertical;
}
.field textarea { min-height: 52px; }

/* slider (range) fields */
.field input.slider {
  width: 100%; padding: 0; height: 18px; accent-color: var(--accent);
  background: transparent; border: none; cursor: pointer;
}
.field .slider-val { float: right; color: var(--text); font-variant-numeric: tabular-nums; }

/* dual-knob trim range (Trim Video node) */
.trim-range { position: relative; height: 26px; margin-top: 6px; }
.trim-range .tr-track {
  position: absolute; top: 10px; left: 0; right: 0; height: 6px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 3px;
}
.trim-range .tr-fill {
  position: absolute; top: 10px; height: 6px; border-radius: 3px;
  background: var(--accent); pointer-events: none;
}
.trim-range input[type=range] {
  position: absolute; top: 5px; left: 0; width: 100%; height: 16px; margin: 0;
  -webkit-appearance: none; appearance: none;
  background: transparent; border: none; padding: 0;
  pointer-events: none; /* only the thumbs are interactive so both knobs work */
}
.trim-range input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; pointer-events: auto;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent-2); border: 2px solid #0f1115; cursor: pointer;
}
.trim-range input[type=range]::-moz-range-thumb {
  pointer-events: auto; width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent-2); border: 2px solid #0f1115; cursor: pointer;
}
.trim-range input[type=range]::-webkit-slider-runnable-track { background: transparent; }
.trim-range input[type=range]::-moz-range-track { background: transparent; }
/* precise time entry under the trim slider */
.trim-times { display: flex; gap: 6px; margin-top: 4px; }
.trim-times input {
  flex: 1; min-width: 0; padding: 4px 6px; font-size: 11px; text-align: center;
  font-variant-numeric: tabular-nums;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text);
}

/* waveform preview (Trim Audio node) */
.trim-wave {
  width: 100%; height: auto; display: block; border-radius: 6px;
  border: 1px solid var(--border); background: #0b0e14;
}
/* Play / Stop controls under the Trim Audio waveform */
.trim-controls { display: flex; gap: 6px; margin-top: 6px; }
.trim-controls button {
  flex: 1; padding: 5px 8px; font-size: 12px; cursor: pointer;
  color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 6px;
}
.trim-controls button:hover { border-color: var(--accent); }
.trim-controls button.trim-play.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

/* drag & drop file source */
.dropzone {
  border: 1.5px dashed var(--border); border-radius: 8px;
  padding: 14px 10px; text-align: center; color: var(--muted);
  font-size: 12px; background: var(--panel-2); transition: border-color .15s, background .15s;
}
.dropzone.dragover { border-color: var(--accent); background: rgba(108,140,255,.12); color: var(--text); }
.dropzone.loaded { border-style: solid; border-color: var(--accent-2); }
.dropzone .dz-info { margin-top: 6px; font-size: 11px; color: var(--text); word-break: break-all; }
.dropzone .dz-thumb { margin-top: 8px; }
.dropzone .dz-thumb img, .dropzone .dz-thumb video { width: 100%; border-radius: 6px; display: block; background: #000; }
.dropzone .dz-thumb audio { width: 100%; }
.dz-clear { float: right; cursor: pointer; color: var(--danger); font-size: 10px; }
.dz-clear:hover { text-decoration: underline; }

/* collect node */
.collect-slot { position: relative; padding: 6px 8px; margin-bottom: 7px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; }
.collect-slot label { margin-bottom: 0; }
.collect-slot .slot-remove { float: right; cursor: pointer; color: var(--danger); font-size: 11px; }
.collect-slot .slot-remove:hover { text-decoration: underline; }
.collect-add { width: 100%; margin-top: 2px; }
/* text overlay: one config block per slot, stacked under the slot's label */
.overlay-entry { margin-top: 6px; }
.overlay-entry .field { margin-bottom: 6px; }
.overlay-entry .field:last-child { margin-bottom: 0; }
.overlay-entry .field label { margin-bottom: 3px; }

/* ----- Video Composer — a "mini Premiere" timeline ("composer" family) ----- */
.node.video-composer { width: 280px; }
/* the body keeps the standard node padding so the stage/preview line up with
   the footer output and the right edge; the top-edge pins sit above the card */
.node.video-composer .port.in.port-top { background: var(--pin, var(--port)); }

/* the editor surface: clips, ruler and waveforms share one px-per-second scale */
.composer-stage {
  position: relative; box-sizing: border-box; overflow: hidden;
  background: #05070c; border: 1px solid var(--border); border-radius: 8px; padding: 0;
}
.composer-vlane { position: relative; height: 60px; }
.composer-clip {
  position: absolute; top: 2px; height: 56px; box-sizing: border-box;
  background: var(--panel-2); background-size: cover; background-position: center;
  border: 1px solid var(--accent); border-radius: 6px;
  overflow: hidden; cursor: grab; user-select: none;
}
.composer-clip.composer-clip-empty { background: var(--panel-2); }
.composer-clip.dragging { opacity: .5; cursor: grabbing; }
.composer-clip.drop-target { border-color: var(--accent-2); box-shadow: 0 0 0 2px rgba(108,231,178,.4); }
.composer-clip .composer-clip-num {
  position: absolute; top: 2px; left: 4px;
  font-size: 12px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px #000;
}
.composer-clip .composer-clip-cap {
  position: absolute; bottom: 2px; left: 0; right: 0; text-align: center;
  font-size: 9px; color: #e8eef5; background: rgba(0,0,0,.45);
}
.composer-clip .composer-clip-del {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 38px; height: 13px; border-radius: 0 0 4px 4px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.6); color: #ff7a7a; font-size: 10px; line-height: 1;
  cursor: pointer; pointer-events: auto; text-shadow: 0 1px 2px #000;
}
.composer-clip .composer-clip-del:hover { background: var(--danger); color: #fff; }

/* hover-revealed trim/move controls on a clip thumb */
.composer-clip .composer-clip-handles {
  position: absolute; inset: 0; opacity: 0; pointer-events: none;
  transition: opacity .12s ease; z-index: 4;
}
.composer-clip:hover .composer-clip-handles { opacity: 1; }
.composer-clip .composer-clip-move {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); color: #fff; font-size: 13px;
  cursor: grab; pointer-events: auto; text-shadow: 0 1px 2px #000;
}
.composer-clip .composer-clip-move:hover { background: var(--accent); color: #fff; }
.composer-clip .composer-clip-move:active { cursor: grabbing; }
.composer-clip .composer-clip-trim {
  position: absolute; top: 0; bottom: 0; width: 16px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.5); color: #ffe08a; font-size: 12px; font-weight: 700;
  cursor: ew-resize; pointer-events: auto; user-select: none;
}
.composer-clip .composer-clip-trim.left { left: 0; }
.composer-clip .composer-clip-trim.right { right: 0; }
.composer-clip .composer-clip-trim:hover { background: rgba(231,196,108,.35); color: #fff; }

/* ruler / ticker between the video and audio lanes */
.composer-ruler {
  position: relative; height: 16px; margin: 3px 0;
  background-image: repeating-linear-gradient(90deg, #2a3645 0 1px, transparent 1px 12px);
  background-position: bottom; border-radius: 3px;
}
.composer-crop-shade { position: absolute; top: 0; bottom: 0; background: rgba(0,0,0,.55); pointer-events: none; z-index: 2; }
.composer-crop-knob {
  position: absolute; top: -2px; width: 8px; height: 20px;
  background: var(--accent-2); border-radius: 2px; transform: translateX(-4px);
  cursor: ew-resize; z-index: 3;
}
.composer-crop-knob.start { background: #6ce7b2; }
.composer-crop-knob.end { background: #e7c46c; }

/* audio lanes carry the decoded waveform, scaled to the same timeline */
.composer-audio-row {
  position: relative; height: 36px; margin-top: 4px; overflow: hidden;
  background: var(--panel-2); border: 1px solid #3a5a4a; border-radius: 6px;
}
/* a track sits in a positioned clip box (offset + trimmed width) so it can be
   slid and trimmed like a video clip */
.composer-audio-clip {
  position: absolute; top: 1px; height: 34px; box-sizing: border-box;
  border: 1px solid var(--accent); border-radius: 5px; overflow: hidden;
  cursor: grab; user-select: none; background: rgba(108,231,178,.06);
}
.composer-audio-clip.sliding { opacity: .6; cursor: grabbing; }
.composer-audio-clip .composer-audio-trim {
  position: absolute; top: 0; bottom: 0; width: 14px; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.5); color: #ffe08a; font-size: 11px; font-weight: 700;
  cursor: ew-resize; opacity: 0; transition: opacity .12s ease;
}
.composer-audio-clip:hover .composer-audio-trim { opacity: 1; }
.composer-audio-clip .composer-audio-trim.left { left: 0; }
.composer-audio-clip .composer-audio-trim.right { right: 0; }
.composer-audio-clip .composer-audio-trim:hover { background: rgba(231,196,108,.35); color: #fff; }
.composer-wave { position: absolute; left: 0; top: 0; height: 34px; }
.composer-audio-row .composer-audio-label {
  position: absolute; left: 6px; top: 2px; font-size: 10px; color: var(--muted);
  font-weight: 600; pointer-events: none; text-shadow: 0 1px 2px #000;
}
.composer-audio-row .slot-remove {
  position: absolute; top: 2px; right: 6px; cursor: pointer; color: var(--danger); font-size: 11px; z-index: 2;
}
/* transport + add-slot strip: five evenly-split buttons under the timeline */
.composer-toolbar { display: flex; gap: 6px; margin-top: 8px; }
.composer-tool { flex: 1; min-width: 0; padding: 5px 4px; }
.composer-tool.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* the playhead spans every lane on the surface */
.composer-playhead {
  position: absolute; top: 6px; bottom: 6px; width: 2px;
  background: #ff5a5a; z-index: 4; cursor: ew-resize;
}
.composer-playhead-time {
  position: absolute; top: -2px; left: 4px;
  font-size: 9px; color: #ff9a9a; white-space: nowrap; text-shadow: 0 1px 2px #000;
}
/* past the timeline midpoint, hang the label on the left so it stays in view */
.composer-playhead-time.flip { left: auto; right: 4px; }

/* live edit preview: a local play/scrub surface (not the Run button) */
.composer-preview { margin-top: 10px; }
.composer-preview-canvas {
  width: 100%; border-radius: 8px; display: block; background: #000;
}

/* audio mixer node: per-input volume slider rows */
.mixer-vol { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.mixer-vol input[type="range"] { flex: 1; min-width: 0; }
.mixer-vol .mixer-pct { font-size: 11px; color: var(--muted); min-width: 34px; text-align: right; }

/* text search & replace node: boxed find/replace pin pairs */
.replace-pair {
  position: relative; padding: 6px 8px; margin-bottom: 7px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
}
.replace-pair-head { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.replace-pair-head .slot-remove { float: right; cursor: pointer; color: var(--danger); font-size: 11px; }
.replace-pair-head .slot-remove:hover { text-decoration: underline; }
.replace-slot { position: relative; margin-bottom: 4px; }
.replace-slot:last-child { margin-bottom: 0; }
.replace-slot label { margin-bottom: 0; }

/* 3D Transform node: an embedded Three.js viewer (standard card width; the
   user can enlarge it via the header size controls). */
.viewer-3d {
  margin-top: 8px; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; background: #05070c; min-height: 120px;
}
.viewer-3d canvas { display: block; width: 100%; height: auto; }
/* Frame Extractor: an always-paused <video> scrubbed by the position slider */
.viewer-3d video.fe-preview { display: block; width: 100%; height: auto; background: #000; }

.node-foot { font-size: 11px; color: var(--muted); padding: 0 12px 8px; }

/* per-node duplicate button at the card bottom */
.node-duplicate {
  display: block; width: calc(100% - 24px); margin: 0 12px 10px;
  padding: 5px 8px; font-size: 11px; cursor: pointer;
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  transition: color .15s, border-color .15s, background .15s;
}
.node-duplicate:hover { color: var(--text); border-color: var(--accent); }

.preview { margin-top: 6px; }
.preview img, .preview video { width: 100%; border-radius: 8px; display: block; background: #000; }
.preview audio { width: 100%; display: block; }
/* Web Preview node: sandboxed page render + interact/release shield */
.preview .web-preview-wrap { position: relative; }
.preview iframe.web-preview {
  width: 100%; aspect-ratio: 16 / 9; border: 1px solid var(--border);
  border-radius: 8px; display: block; background: #fff;
}
.preview .web-preview-shield {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; background: rgba(5, 7, 12, 0.35); color: #fff;
  font-size: 12px; cursor: pointer; user-select: none;
}
.preview .web-preview-shield:hover { background: rgba(5, 7, 12, 0.5); }
.preview .web-preview-release {
  position: absolute; top: 6px; right: 6px; padding: 2px 8px;
  border: 1px solid var(--border); border-radius: 6px;
  background: rgba(5, 7, 12, 0.75); color: #fff; font-size: 11px; cursor: pointer;
}
/* 3D object (.glb) output: an interactive turntable viewer in the preview */
.preview .model-prev { width: 100%; border-radius: 8px; overflow: hidden; background: #05070c; margin-bottom: 4px; }
.preview .model-prev canvas { display: block; width: 100%; height: auto; }
.preview a { font-size: 11px; color: var(--accent); word-break: break-all; }
.preview .text-wrap { position: relative; }
.preview .text-out {
  max-height: 160px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  font-size: 12px; color: var(--text); line-height: 1.4;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px;
  /* let the user select & copy generated text (the node itself is no-select) */
  user-select: text; -webkit-user-select: text; cursor: text;
}
/* one-click copy button floating in the corner of the text output */
.preview .copy-text {
  position: absolute; top: 4px; right: 4px; z-index: 2;
  width: 22px; height: 22px; padding: 0; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; cursor: pointer;
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--border); border-radius: 5px;
  opacity: .6; transition: opacity .15s, color .15s, border-color .15s;
}
.preview .text-wrap:hover .copy-text { opacity: 1; }
/* contact sheet: a small grid of thumbnails when previewing an array */
.preview .contact-sheet {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 4px; max-height: 220px; overflow: auto;
}
.preview .contact-sheet .sheet-cell { display: block; line-height: 0; }
.preview .contact-sheet .sheet-cell img,
.preview .contact-sheet .sheet-cell video {
  width: 100%; height: 64px; object-fit: cover; border-radius: 6px;
  background: #000; display: block;
}
.preview .contact-sheet .sheet-cell audio { width: 100%; }
.preview .contact-sheet .sheet-cell .cell-open {
  display: block; line-height: 1.4; font-size: 11px; color: var(--accent); text-decoration: none;
}
.preview .contact-sheet .sheet-cell.text-cell {
  line-height: 1.3; font-size: 11px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px; max-height: 64px; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
}
/* selectable contact sheet: click a thumb to toggle checked (✓) / excluded (✗) */
.preview .contact-sheet .sheet-cell.selectable { position: relative; cursor: pointer; }
.preview .contact-sheet .sheet-cell.selectable .mark {
  position: absolute; top: 4px; right: 4px;
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; line-height: 1; font-weight: 700; color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.6);
}
.preview .contact-sheet .sheet-cell.is-checked .mark { background: var(--accent-2, #2ecc71); }
.preview .contact-sheet .sheet-cell.is-excluded .mark { background: var(--danger, #ff5c7a); }
.preview .contact-sheet .sheet-cell.is-excluded img {
  filter: grayscale(1) brightness(.5); opacity: .55;
}
/* For Each results sheet: index-aligned cells with a hover ↻ redo overlay */
.preview .contact-sheet .fe-cell { position: relative; line-height: 0; }
.preview .contact-sheet .fe-cell .fe-redo {
  position: absolute; top: 4px; right: 4px; z-index: 2;
  width: 20px; height: 20px; padding: 0; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; cursor: pointer;
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--border); border-radius: 5px;
  opacity: 0; transition: opacity .15s, color .15s, border-color .15s;
}
.preview .contact-sheet .fe-cell:hover .fe-redo { opacity: 1; }
.preview .contact-sheet .fe-cell .fe-redo:hover { color: var(--text); border-color: var(--accent); }
.preview .contact-sheet .fe-cell .fe-slot {
  height: 64px; border-radius: 6px; border: 1px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; line-height: 1; color: var(--muted); background: var(--panel-2);
}
.preview .contact-sheet .fe-cell .fe-slot.fe-slot-fail { color: var(--danger); border-color: var(--danger); }
/* a positional collection's missing item keeps its cell; the box view marks a failed one */
.preview .contact-sheet .sheet-cell.sheet-empty {
  height: 64px; border-radius: 6px; border: 1px dashed var(--border); background: var(--panel-2);
  display: flex; align-items: center; justify-content: center; font-size: 14px; line-height: 1; color: var(--muted);
}
.preview .contact-sheet .sheet-cell.sheet-empty.fe-slot-fail { color: var(--danger); border-color: var(--danger); }
.preview .contact-sheet .sheet-cell.fe-redoable { position: relative; }
.preview .contact-sheet .sheet-cell.fe-redoable .fe-redo {
  position: absolute; top: 4px; right: 4px; z-index: 2;
  width: 20px; height: 20px; padding: 0; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; cursor: pointer;
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--border); border-radius: 5px;
  opacity: 0; transition: opacity .15s, color .15s, border-color .15s;
}
.preview .contact-sheet .sheet-cell.fe-redoable:hover .fe-redo { opacity: 1; }
.preview .contact-sheet .sheet-cell.fe-redoable .fe-redo:hover { color: var(--text); border-color: var(--accent); }
.preview .copy-text:hover { color: var(--text); border-color: var(--accent); }
.preview .copy-text.copied { color: var(--accent-2); border-color: var(--accent-2); opacity: 1; }

/* ports */
.port {
  position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #0f1115; cursor: crosshair; z-index: 5;
}
.port.in { left: -9px; background: var(--pin, var(--port)); }
.port.in.connected { cursor: pointer; }
.port.in.hover { background: var(--danger); border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(255,92,122,.35); }
.port.out { right: -9px; top: 22px; background: var(--pin, var(--port-out)); }
.port-label { position: absolute; font-size: 10px; color: var(--muted); }

#status {
  position: absolute; bottom: 0; left: 0; right: 0; height: 28px;
  display: flex; align-items: center; padding: 0 14px;
  background: var(--panel); border-top: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
}

/* ----- Run Log panel ----- */
.log-panel {
  position: absolute; right: 14px; bottom: 40px; z-index: 900;
  width: 460px; max-width: calc(100vw - 28px); max-height: 60vh;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 34px rgba(0,0,0,.5);
}
.log-panel[hidden] { display: none; }
.log-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
}
.log-title { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.log-actions { display: flex; gap: 6px; }
.log-list { overflow-y: auto; padding: 6px; font-size: 12px; }
.log-row { padding: 5px 8px; border-bottom: 1px solid var(--border); color: var(--text); }
.log-row:last-child { border-bottom: none; }
.log-row-head { white-space: pre-wrap; word-break: break-word; }
.log-row.log-error .log-row-head { color: var(--danger); font-weight: 600; }
.log-detail {
  margin: 6px 0 0; padding: 6px 8px; border-radius: 6px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted); font-size: 11px; line-height: 1.4;
  white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow-y: auto;
}

path.wire { fill: none; stroke: var(--accent-2); stroke-width: 2.5; }
/* control wire (e.g. into Verify Input): a wide stroke split into two rails */
path.wire.control { stroke-width: 7; }
path.wire.control-gap { stroke: var(--bg) !important; stroke-width: 3; }
path.wire.temp { stroke: var(--accent); stroke-dasharray: 6 4; }

.badge { font-size: 10px; padding: 1px 6px; border-radius: 20px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }

/* right-click "add node" context menu */
.ctx-menu {
  position: fixed; z-index: 1000;
  min-width: 220px; max-height: 70vh;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 34px rgba(0,0,0,.5);
  padding: 4px;
}
.ctx-menu .ctx-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 6px 10px 4px;
}
.ctx-menu .ctx-search {
  margin: 2px 4px 6px; padding: 6px 8px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); outline: none;
}
.ctx-menu .ctx-search:focus { border-color: var(--accent); }
.ctx-menu .ctx-list { overflow-y: auto; }
.ctx-menu .ctx-empty {
  padding: 7px 10px; font-size: 12px; color: var(--muted); font-style: italic;
}
.ctx-menu .ctx-item {
  padding: 7px 10px; font-size: 12px; color: var(--text);
  border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.ctx-menu .ctx-item:hover { background: var(--accent); color: #fff; }

/* routing submenu inside the context menu */
.ctx-menu .ctx-submenu-header {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  color: #c9a3ff; font-weight: 600;
}
.ctx-menu .ctx-submenu { display: none; padding-left: 8px; }
.ctx-menu .ctx-submenu.open { display: block; }
.ctx-menu .ctx-route-add { color: #c9a3ff; }
.ctx-menu .ctx-node-group-header {
  padding: 8px 10px 3px; font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--accent-2); font-weight: 600;
}

/* route nodes — a distinct purple identity vs. regular (blue) nodes */
.node.route-node { border-color: #7c4dff; box-shadow: 0 0 0 1px rgba(124,77,255,.35), 0 8px 24px rgba(0,0,0,.45); }
.node.route-node .node-head { background: linear-gradient(180deg, rgba(124,77,255,.30), rgba(124,77,255,.10)); }
.node.route-node .badge { border-color: #7c4dff; color: #c9a3ff; }

/* route sink: editable name + labelled pin rows */
.route-name { margin-bottom: 8px; }
.route-pin { position: relative; padding: 6px 8px; margin-bottom: 7px;
  background: var(--panel-2); border: 1px solid #4a3a7a; border-radius: 6px; }
.route-pin .route-pin-label { width: 100%; box-sizing: border-box; }
.route-pin .slot-remove { position: absolute; top: 6px; right: 6px;
  cursor: pointer; color: var(--danger); font-size: 11px; }
.route-out-row { position: relative; padding: 6px 8px; margin-bottom: 7px;
  background: var(--panel-2); border: 1px solid #4a3a7a; border-radius: 6px; text-align: right; }
.route-out-row label { margin-bottom: 0; }
.route-missing { font-size: 12px; color: var(--danger); padding: 6px 8px; }
/* route output ports stack down the right edge (purple) */
.port.out.route-out { background: var(--pin, #7c4dff); }

/* Get Details — one media input row + right-aligned numeric output pins */
.gd-row.gd-out { position: relative; padding: 6px 8px; margin-bottom: 7px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; text-align: right; }
.gd-row.gd-out label { margin-bottom: 0; }
.gd-row.gd-out .gd-val { margin-left: 6px; color: var(--accent-2); font-variant-numeric: tabular-nums; }

/* ----- Super Nodes — a distinct teal/green identity ----- */
.ctx-menu .ctx-super-header { color: #54e3c2; }
.ctx-menu .ctx-super-item { color: #54e3c2; }

/* super node tabs are tinted teal so they read as "not a normal tab" */
.tab.supernode-tab { border-color: #1f9e85; color: #8ff0dd; }
.tab.supernode-tab.active { border-color: #54e3c2; color: #b9f7ec;
  background: linear-gradient(180deg, rgba(84,227,194,.14), rgba(84,227,194,.04)); }

/* super node cards (input/output helpers + placed instances) */
.node.supernode-node { border-color: #1f9e85;
  box-shadow: 0 0 0 1px rgba(84,227,194,.30), 0 8px 24px rgba(0,0,0,.45); }
.node.supernode-node .node-head {
  background: linear-gradient(180deg, rgba(84,227,194,.26), rgba(84,227,194,.08)); }
.node.supernode-node .badge { border-color: #1f9e85; color: #8ff0dd; }

/* labelled pin rows on super node helpers / instances */
.super-pin { position: relative; padding: 6px 8px; margin-bottom: 7px;
  background: var(--panel-2); border: 1px solid #2a6b5e; border-radius: 6px; }
.super-pin .route-pin-label { width: 100%; box-sizing: border-box; }
.super-pin .slot-remove { position: absolute; top: 6px; right: 6px;
  cursor: pointer; color: var(--danger); font-size: 11px; }
.super-pin-row { position: relative; padding: 6px 8px; margin-bottom: 7px;
  background: var(--panel-2); border: 1px solid #2a6b5e; border-radius: 6px; }
.super-pin-row label { margin-bottom: 0; }
.super-pin-row.super-out-row { text-align: right; }
.field.route-out-row.super-pin { text-align: right; }

/* super node output ports (teal) */
.port.out.super-out { background: var(--pin, #54e3c2); }

/* placed super node "card" — one collapsed node standing in for the whole group */
.node.super-card-node { min-width: 180px; }
.node.super-card-node .super-toggle {
  cursor: pointer; color: #8ff0dd; font-size: 13px; margin-left: 4px; }
.node.super-card-node .super-toggle:hover { color: #b9f7ec; }
.super-card-row {
  position: relative; display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 8px; margin-bottom: 7px; min-height: 16px;
  background: var(--panel-2); border: 1px solid #2a6b5e; border-radius: 6px; }
.super-card-in-label { color: #8ff0dd; font-size: 11px; }
.super-card-out-label { color: #8ff0dd; font-size: 11px; text-align: right; }
.node.super-card-node .port.out { background: var(--pin, #54e3c2); }
