/* ============================================================
   Clips view (js/clips-view.js) — full-cover view above the canvas
   for a workflow tab: "Made from" cards wired into the preview, takes,
   the transport bar and the timeline of clips.
   Slate tokens only (css/slate.css).
   ============================================================ */

.clips-view {
    /* "Inside a clip": the parent clip's colour while a child is open. */
    --cv-inside: oklch(0.74 0.13 300);
    --cv-inside-tint: oklch(0.74 0.13 300 / 0.2);
    position: absolute;
    inset: 0;
    z-index: 9500;
    display: flex;
    flex-direction: column;
    background: var(--sl-app);
    color: var(--sl-text-1);
    font-family: var(--sl-font-ui);
    font-size: 13px;
}
.clips-view.hidden { display: none; }
:where(.clips-view button) { font: inherit; color: inherit; }
.clips-view .cv-ic { display: inline-flex; flex: none; }

/* toolbar toggle */
.canvas-view-toggle.hidden { display: none; }
.canvas-view-toggle .sl-seg-btn .cv-ic { display: inline-flex; }

/* ---- top: crumbs/info | preview | takes, then the prompt bar ---- */
.cv-top {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 16px;
    background-image: radial-gradient(oklch(0.36 0.01 250 / 0.5) 1px, transparent 1px);
    background-size: 18px 18px;
}
/* Three columns with equal sides, so the preview is always centred. */
.cv-main { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
.cv-left { position: relative; z-index: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding-right: 40px; }
.cv-stage { min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; }
.cv-side { min-width: 0; min-height: 0; display: flex; align-items: center; padding-left: 16px; }

.cv-crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 12px; color: var(--sl-text-2); }
.cv-crumbs .cv-ic { color: var(--sl-text-3); }
.cv-cr { padding: 3px 7px; border: 0; border-radius: var(--sl-r-6); background: none; white-space: nowrap; cursor: pointer; }
button.cv-cr:hover { background: var(--sl-wash); color: var(--sl-text-1); }
.cv-cr.is-on { color: var(--sl-text-1); font-weight: 600; cursor: default; }

.cv-info { display: flex; flex-direction: column; gap: 4px; padding: 0 7px; }
.cv-kind, .cv-role {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--sl-text-3);
}
.cv-name { font-size: 15px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.cv-shared { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--sl-text-2); }

/* status dot + label */
.cv-st { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--sl-text-2); white-space: nowrap; }
.cv-st i { width: 6px; height: 6px; border-radius: 50%; background: var(--sl-text-3); flex: none; }
.cv-st-sent, .cv-st-done { color: var(--sl-success); }
.cv-st-sent i, .cv-st-done i { background: var(--sl-success); }
.cv-st-review, .cv-st-gen { color: var(--sl-accent-text); }
.cv-st-review i, .cv-st-gen i { background: var(--sl-accent); }
.cv-st-gen i { animation: cv-blink 1s infinite; }
.cv-st-err { color: var(--sl-danger-text); }
.cv-st-err i { background: var(--sl-red); }
.cv-st-ref i { background: var(--sl-text-2); }

/* preview frame — sized by fitPreview() to the media's aspect ratio */
.cv-frame {
    position: relative;
    flex: none;
    border-radius: var(--sl-r-12);
    overflow: hidden;
    background: oklch(0.12 0.004 250);
    box-shadow: var(--sl-shadow-float), inset 0 0 0 1px var(--sl-hairline);
}
.cv-frame.is-empty { border: 1px dashed var(--sl-border-strong); box-shadow: none; }
.cv-media { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.cv-audio { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--sl-text-2); background: oklch(0.12 0.004 250); }
.cv-audio audio { width: 80%; }
.cv-frame-empty {
    position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 8px; padding: 18px; text-align: center; color: var(--sl-text-2);
}
.cv-frame-empty b { color: var(--sl-text-1); font-size: 14px; }
.cv-frame-busy {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
    background: oklch(0.12 0.004 250 / .75); color: var(--sl-accent-text); font-size: 12px; pointer-events: none;
}
.cv-pills { position: absolute; left: 10px; top: 10px; right: 10px; display: flex; gap: 6px; pointer-events: none; }
.cv-pill {
    height: 22px; padding: 0 8px; border-radius: 999px; display: inline-flex; align-items: center; gap: 5px;
    font-size: 11px; background: oklch(0.12 0.004 250 / .72); color: var(--sl-text-1); white-space: nowrap;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.cv-pill-r { margin-left: auto; }
.cv-empty-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--sl-quiet); color: var(--sl-text-2); }

/* takes beside the preview */
.cv-takes { flex: none; display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: var(--sl-r-12); background: var(--sl-panel); border: 1px solid var(--sl-hairline); max-height: 100%; overflow-y: auto; }
.cv-takes-h { font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--sl-text-2); }
.cv-takes-g { display: grid; grid-template-columns: repeat(2, 54px); gap: 6px; }
.cv-tk {
    position: relative; width: 54px; aspect-ratio: 9 / 16; padding: 0; border: 0; border-radius: 7px; overflow: hidden;
    background: var(--sl-quiet); box-shadow: inset 0 0 0 1px var(--sl-hairline); opacity: .8; cursor: pointer;
    transition: opacity .15s ease, box-shadow .15s ease;
}
.cv-tk:hover { opacity: 1; }
.cv-tk.is-on { opacity: 1; box-shadow: 0 0 0 2px var(--sl-accent); }
.cv-tk img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cv-tk-ph { width: 100%; height: 100%; display: grid; place-items: center; color: var(--sl-text-3); }
.cv-tk-n { position: absolute; left: 3px; top: 3px; padding: 0 4px; border-radius: 4px; font-size: 9.5px; font-family: var(--sl-font-mono); background: oklch(0 0 0 / .55); color: var(--sl-text-1); }
.cv-tk-dot { position: absolute; right: 4px; bottom: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--sl-accent); box-shadow: 0 0 0 1.5px oklch(0 0 0 / .5); }

/* prompt bar: Studio's settings control on the left, the prompt, Generate on the right.
   The slot keeps one line of room in the layout; the bar sits on its bottom edge,
   so an opened prompt grows UP over the preview instead of pushing it. */
.cv-prompt-slot { position: relative; z-index: 5; flex: none; align-self: center; width: min(900px, 100%); height: 46px; }
.cv-prompt {
    position: absolute; left: 0; right: 0; bottom: 0;
    display: flex; align-items: flex-end; gap: 8px; padding: 7px;
    border-radius: var(--sl-r-14); background: var(--sl-raised); border: 1px solid var(--sl-line-pop);
    box-shadow: 0 24px 60px -18px oklch(0 0 0 / 0.9);
    transition: border-color .15s ease;
}
.cv-prompt:focus-within { border-color: var(--sl-accent-line); }
.cv-prompt-in {
    flex: 1; min-width: 80px; height: 30px; margin: 0; padding: 6px 6px; box-sizing: border-box;
    border: 0; background: transparent; resize: none; outline: none;
    color: var(--sl-text-1); font: inherit; font-size: 13.5px; line-height: 18px; text-align: left;
    white-space: nowrap; overflow: hidden;
    /* the rest of a long prompt fades out at the edge while it is closed */
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
    transition: height .22s cubic-bezier(.2, .8, .2, 1);
}
.cv-prompt-in.is-open { white-space: pre-wrap; overflow-y: auto; -webkit-mask-image: none; mask-image: none; }
.cv-prompt-in::placeholder { color: var(--sl-text-3); }
.cv-prompt-text { flex: 1; min-width: 0; align-self: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; padding: 0 8px; }
.cv-prompt-text.is-empty { color: var(--sl-text-3); }
.cv-gen {
    flex: none; height: 32px; padding: 0 12px 0 14px; border: 0; border-radius: var(--sl-r-8);
    display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; cursor: pointer;
    background: var(--sl-accent); color: var(--sl-on-accent); font-size: 12.5px; font-weight: 700;
    transition: filter .15s ease, background .15s ease;
}
.cv-gen:hover { filter: brightness(1.08); }
.cv-gen:active { transform: scale(.98); }
.cv-gen.is-stop { background: var(--sl-danger-wash); color: var(--sl-danger-text); box-shadow: inset 0 0 0 1px var(--sl-danger-line); }
.cv-gen.is-first { background: var(--sl-control); color: var(--sl-text-1); font-weight: 600; }
.cv-gen.is-first:hover { background: var(--sl-control-hover); filter: none; }
.cv-kbd { font-family: var(--sl-font-mono); font-size: 10px; font-weight: 500; padding: 1px 5px; border-radius: 6px; background: oklch(0.15 0.02 240 / 0.16); }
.cv-btn { flex: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.cv-edit-link {
    align-self: flex-start; display: inline-flex; align-items: center; gap: 5px; margin-top: 4px; padding: 3px 7px 3px 5px;
    border: 0; border-radius: var(--sl-r-6); background: transparent; color: var(--sl-text-2); font-size: 11.5px; cursor: pointer;
}
.cv-edit-link:hover { background: var(--sl-wash); color: var(--sl-text-1); }

/* settings — Studio's button + popover (studio.js settingsButton / settingsPopover) */
.cv-set { position: relative; flex: none; }
.cv-set-btn { max-width: 330px; }
.cv-set-btn.is-open { background: var(--sl-control-hover); }
.cv-set-sum { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cv-set-btn .cv-ic:last-child { color: var(--sl-text-3); }
.cv-set-pop {
    position: absolute; bottom: calc(100% + 10px); left: -7px; z-index: 30;
    min-width: 230px; max-width: 340px; max-height: min(520px, calc(100vh - 170px)); overflow-y: auto;
    animation: cv-pop-in .16s ease-out;
}
.cv-set-box { display: flex; flex-direction: column; gap: 8px; padding: 6px; width: 292px; box-sizing: border-box; }
.cv-set-row { display: flex; flex-direction: column; gap: 4px; }
.cv-set-label { padding: 0 3px; }
.cv-set-note { font-size: 11px; line-height: 1.4; color: var(--sl-text-3); padding: 0 3px; }
/* segmented track (Standard .sl-seg look): panel inset, hairline, 3px pad */
.cv-seg { display: flex; gap: 2px; padding: 3px; background: var(--sl-panel); border: 1px solid var(--sl-hairline); border-radius: 8px; }
.cv-seg-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; }
.cv-opt {
    flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px; height: 26px; padding: 0 4px;
    border: 0; border-radius: 6px; background: transparent; color: var(--sl-text-2);
    font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .12s ease, color .12s ease;
}
.cv-opt:hover { color: var(--sl-text-1); }
.cv-opt.is-on { background: var(--sl-segment-on); color: var(--sl-text-1); }
.cv-opt.is-mono { font-family: var(--sl-font-mono); font-size: 10.5px; }
.cv-opt.is-wide { padding: 0 6px; }
.cv-asp { flex: none; box-sizing: border-box; border: 1.5px solid currentColor; border-radius: 2px; }
.cv-set-model { display: flex; align-items: center; gap: 8px; width: 100%; cursor: pointer; text-align: left; color: var(--sl-text-3); }
.cv-set-model.is-open { border-color: var(--sl-focus); }
.cv-set-model-name { flex: 1; font-size: 12px; font-weight: 600; color: var(--sl-text-1); }
.cv-set-list { display: flex; flex-direction: column; gap: 1px; max-height: 196px; overflow-y: auto; background: var(--sl-panel); border: 1px solid var(--sl-hairline); border-radius: 8px; padding: 3px; }
.cv-set-item { flex: none; width: 100%; border: 0; background: transparent; color: var(--sl-text-1); text-align: left; cursor: pointer; }
.cv-set-item.is-on { background: var(--sl-wash); }
.cv-set-item .cv-ic { color: var(--sl-link); }
.cv-set-item:disabled { opacity: .45; cursor: not-allowed; }
.cv-set-item-name { flex: 1; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-set-item.is-on .cv-set-item-name { font-weight: 600; }
@keyframes cv-pop-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }

/* Send under the takes */
.cv-send {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 30px; padding: 0 10px; border: 0;
    border-radius: var(--sl-r-8); background: var(--sl-accent); color: var(--sl-on-accent); font-size: 12px; font-weight: 700; cursor: pointer;
}
.cv-send:hover { filter: brightness(1.08); }
.cv-sent { display: inline-flex; align-items: center; justify-content: center; gap: 5px; height: 26px; font-size: 12px; color: var(--sl-success); }

/* "Made from": the focused node's children as cards, wired into the preview */
.cv-wires { position: absolute; left: 0; top: 0; z-index: 0; pointer-events: none; overflow: visible; }
.cv-w { fill: none; stroke-width: 2; }
.cv-w.ok { stroke: var(--sl-accent-line); }
.cv-w.pend { stroke: oklch(1 0 0 / .2); stroke-dasharray: 5 4; }
.cv-sk { fill: var(--sl-panel); stroke-width: 1.5; }
.cv-sk.ok { stroke: var(--sl-accent); }
.cv-sk.pend { stroke: var(--sl-text-3); }
/* Right beside the preview: the margin is the room the wires need. */
/* Right-aligned in the left column, against the preview; the column's right
   padding is the room the wires need. */
.cv-in {
    position: relative; z-index: 1; flex: 1; min-height: 0; width: 212px; max-width: 100%; align-self: flex-end;
    overflow-y: auto; display: flex; flex-direction: column; justify-content: safe center;
    align-items: flex-end; gap: 8px; padding: 6px 2px 6px 0;
}
.cv-in-h {
    display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; font-weight: 600;
    letter-spacing: .06em; text-transform: uppercase; color: var(--sl-text-3);
}
.cv-hint { font-size: 12px; color: var(--sl-text-3); text-align: right; }
.cv-card {
    position: relative; flex: none; width: 100%; max-width: 220px; display: flex; align-items: center; gap: 9px;
    padding: 7px 10px 7px 7px; border-radius: var(--sl-r-10); background: var(--sl-card); border: 1px solid var(--sl-hairline);
    text-align: left; cursor: pointer; transition: border-color .15s ease, background .15s ease;
}
.cv-card:hover { border-color: var(--sl-border-strong); background: var(--sl-quiet-hover); }
.cv-card-th { width: 46px; height: 46px; border-radius: 7px; object-fit: cover; flex: none; }
.cv-card.is-gen .cv-card-th { width: 32px; height: 56px; }
.cv-ph { display: grid; place-items: center; background: var(--sl-quiet); color: var(--sl-text-3); }
.cv-card-tx { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cv-card-tx b { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-card-from { display: flex; align-items: center; gap: 3px; margin-top: 2px; }
.cv-av { width: 16px; height: 16px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 1.5px var(--sl-card); }
.cv-card-from em { font-style: normal; font-size: 10.5px; color: var(--sl-text-3); margin-left: 3px; }
.cv-card-shared { display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; color: var(--sl-text-2); }
.cv-socket {
    flex: none; width: 100%; max-width: 220px; height: 38px; display: flex; align-items: center; justify-content: center; gap: 6px;
    border-radius: var(--sl-r-10); border: 1px dashed var(--sl-border-strong); background: var(--sl-app);
    color: var(--sl-text-2); font-size: 12px; cursor: pointer; transition: all .15s ease;
}
.cv-socket:hover { color: var(--sl-text-1); border-color: var(--sl-accent-line); background: var(--sl-accent-tint); }
.cv-frame.is-anchored { cursor: pointer; }

/* transport bar (where the "Made from" tray used to sit) */
.cv-bar {
    flex: none; height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 12px;
    background: var(--sl-panel); border-top: 1px solid var(--sl-hairline);
}
.cv-transport { display: flex; align-items: center; gap: 2px; }
.cv-tbtn {
    flex: none; height: 30px; min-width: 30px; padding: 0 6px; border: 0; border-radius: var(--sl-r-8);
    display: inline-flex; align-items: center; justify-content: center; gap: 5px;
    background: transparent; color: var(--sl-text-2); cursor: pointer; transition: background .15s ease, color .15s ease;
}
.cv-tbtn:hover { background: var(--sl-wash); color: var(--sl-text-1); }
.cv-tbtn:active { transform: scale(.96); }
.cv-tbtn.is-on { color: var(--sl-accent-text); background: var(--sl-accent-tint); }
.cv-tbtn-play { width: 36px; height: 36px; border-radius: 50%; background: var(--sl-text-1); color: var(--sl-app); margin: 0 4px; }
.cv-tbtn-play:hover { background: #fff; color: var(--sl-app); }
.cv-tbtn-text { font-size: 12px; font-weight: 600; padding: 0 9px; }
.cv-clock { display: inline-flex; align-items: baseline; gap: 6px; margin-left: 6px; font-family: var(--sl-font-mono); font-size: 13px; }
.cv-clock-t { color: var(--sl-text-1); font-weight: 600; min-width: 62px; }
.cv-clock-sep, .cv-clock-total { color: var(--sl-text-3); }
.cv-rate { padding: 2px 6px; border-radius: 5px; background: var(--sl-accent-tint); color: var(--sl-accent-text); font-family: var(--sl-font-mono); font-size: 11px; }
.cv-rate.hidden { display: none; }
.cv-bar-gap { flex: 1; }
.cv-zoom { width: 110px; accent-color: var(--sl-accent); cursor: pointer; }
.cv-keys { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: var(--sl-r-8); color: var(--sl-text-3); cursor: help; }
.cv-keys:hover { color: var(--sl-text-1); background: var(--sl-wash); }

/* timeline: clips end to end, width = length (timeline() in clips-view.js sets the px per second) */
.cv-timeline {
    flex: none; height: 118px; display: flex;
    background: oklch(0.14 0.004 250); border-top: 1px solid var(--sl-hairline);
}
.cv-tl-side {
    flex: none; width: 112px; display: flex; flex-direction: column; justify-content: center; gap: 2px;
    padding: 0 14px; border-right: 1px solid var(--sl-hairline);
}
.cv-tl-total { font-family: var(--sl-font-mono); font-size: 18px; font-weight: 600; color: var(--sl-text-1); }
.cv-tl-sub { font-size: 11px; color: var(--sl-text-3); white-space: nowrap; }
.cv-tl-scroll { flex: 1; min-width: 0; overflow-x: auto; overflow-y: hidden; padding: 0 16px; }
.cv-tl-inner { position: relative; height: 100%; display: flex; flex-direction: column; padding: 4px 0 10px; box-sizing: border-box; }

/* ruler: labelled major ticks + minor ticks drawn as a repeating background */
.cv-ruler {
    position: relative; flex: none; height: 22px; cursor: pointer;
    background-image: linear-gradient(to right, oklch(1 0 0 / .16) 1px, transparent 1px);
    background-repeat: repeat-x; background-position: 0 100%;
}
.cv-tick {
    position: absolute; top: 0; bottom: 0; padding: 1px 0 0 4px;
    border-left: 1px solid oklch(1 0 0 / .3);
    font-family: var(--sl-font-mono); font-size: 10px; color: var(--sl-text-3); white-space: nowrap; pointer-events: none;
}

/* the track: segments touch — a cut is a 1px dark line, not a gap */
.cv-track { position: relative; flex: none; height: 72px; display: flex; border-radius: var(--sl-r-8); overflow: hidden; background: oklch(0.11 0.004 250); }
.cv-clip {
    position: relative; flex: none; height: 100%; min-width: 0; margin: 0; padding: 6px 8px;
    display: flex; flex-direction: column; justify-content: space-between;
    border: 0; border-radius: 0; overflow: hidden; text-align: left; cursor: pointer;
    background-color: oklch(0.2 0.006 250); background-repeat: repeat-x; background-size: auto 100%; background-position: 0 0;
    box-shadow: inset -1px 0 0 oklch(0 0 0 / .75);
}
/* legibility over the frames */
.cv-clip::before {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background: linear-gradient(to bottom, oklch(0 0 0 / .62), transparent 38%, transparent 52%, oklch(0 0 0 / .72));
}
.cv-clip > span { position: relative; z-index: 1; display: flex; align-items: center; gap: 6px; min-width: 0; }
.cv-clip-top b { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 2px oklch(0 0 0 / .8); }
.cv-clip-bot { justify-content: space-between; }
.cv-clip-bot .cv-st { min-width: 0; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 2px oklch(0 0 0 / .8); }
.cv-clip-n {
    flex: none; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 5px; display: inline-grid; place-items: center;
    background: oklch(0 0 0 / .55); font-size: 10.5px; font-weight: 600; font-family: var(--sl-font-mono); color: var(--sl-text-1);
}
.cv-clip-dur {
    flex: none; padding: 1px 5px; border-radius: 4px; background: oklch(0 0 0 / .55);
    font-family: var(--sl-font-mono); font-size: 10.5px; color: var(--sl-text-1);
}
.cv-clip.is-planned .cv-clip-dur { color: var(--sl-text-3); }
.cv-clip.no-thumb {
    background-image: repeating-linear-gradient(135deg, oklch(1 0 0 / .035) 0 8px, transparent 8px 16px);
    background-size: auto; background-repeat: repeat;
}
.cv-clip:hover::before { background: linear-gradient(to bottom, oklch(0 0 0 / .45), transparent 38%, transparent 52%, oklch(0 0 0 / .6)); }
.cv-clip.is-on::after {
    content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 2;
    box-shadow: inset 0 0 0 2px var(--sl-accent);
}
.cv-track .cv-clip:first-child::after { border-radius: var(--sl-r-8) 0 0 var(--sl-r-8); }
.cv-track .cv-clip:last-child { box-shadow: none; }
.cv-track .cv-clip:last-child::after { border-radius: 0 var(--sl-r-8) var(--sl-r-8) 0; }
.cv-track .cv-clip:only-child::after { border-radius: var(--sl-r-8); }

/* playhead */
.cv-playhead {
    position: absolute; top: 4px; bottom: 10px; width: 2px; margin-left: -1px; z-index: 3; pointer-events: none;
    background: var(--sl-accent);
}
.cv-ph-t {
    position: absolute; top: 0; left: 1px; transform: translateX(-50%);
    padding: 1px 5px; border-radius: 4px; background: var(--sl-accent); color: var(--sl-on-accent);
    font-family: var(--sl-font-mono); font-size: 10px; font-weight: 600; white-space: nowrap;
}
/* Inside a child: the parent clip turns violet, and so does the playhead. */
.cv-clip.is-inside::after {
    content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 2;
    box-shadow: inset 0 0 0 2px var(--cv-inside);
}
.cv-clip.is-inside { background-color: oklch(0.26 0.05 300); }
.cv-clip.is-inside::before {
    background: linear-gradient(to bottom, oklch(0.3 0.1 300 / .75), oklch(0.3 0.1 300 / .25) 38%, oklch(0.3 0.1 300 / .25) 52%, oklch(0.2 0.06 300 / .8));
}
.cv-clip-inside {
    align-self: flex-start; padding: 1px 6px; border-radius: 4px; max-width: 100%;
    background: var(--cv-inside); color: oklch(0.18 0.04 300);
    font-size: 10px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cv-playhead.is-inside, .cv-playhead.is-inside .cv-ph-t { background: var(--cv-inside); color: oklch(0.18 0.04 300); }
/* At 0:00 a centred label would be cut off by the scroll edge. */
.cv-playhead.at-start .cv-ph-t { left: -1px; transform: none; }

/* empty tab */
.cv-empty { margin: auto; max-width: 360px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 24px; }
.cv-empty h2 { font-size: 17px; font-weight: 600; }
.cv-empty p { color: var(--sl-text-2); }

.cv-cr:focus-visible, .cv-card:focus-visible, .cv-socket:focus-visible, .cv-tk:focus-visible, .cv-tbtn:focus-visible, .cv-keys:focus-visible, .cv-gen:focus-visible, .cv-send:focus-visible, .cv-edit-link:focus-visible, .cv-opt:focus-visible, .cv-set-item:focus-visible { outline: 2px solid var(--sl-focus); outline-offset: 2px; }

.cv-clip:focus-visible { outline: 2px solid var(--sl-focus); outline-offset: -2px; }

@keyframes cv-blink { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .cv-st-gen i, .cv-set-pop { animation: none; } .cv-prompt-in { transition: none; } }
@media (max-width: 1100px) {
    .cv-left { padding-right: 28px; }
    .cv-in { width: 170px; }
}

/* ---- references: remove button on a card ---- */
.cv-card { outline: none; }
.cv-card-x {
    position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%;
    display: grid; place-items: center; padding: 0; border: 1px solid oklch(1 0 0 / 0.22);
    background: oklch(0.32 0.008 250); color: var(--sl-text-1); cursor: pointer; opacity: 0; transition: opacity .15s ease, background .15s ease;
}
.cv-card:hover .cv-card-x, .cv-card:focus-within .cv-card-x, .cv-card:focus-visible .cv-card-x { opacity: 1; }
.cv-card-x:hover { background: var(--sl-danger-wash); color: var(--sl-danger-text); }

/* ---- timeline: New clip, Run all, reorder ---- */
.cv-track { align-self: flex-start; }
.cv-newclip {
    position: absolute; top: 30px; width: 120px; height: 72px; border-radius: var(--sl-r-8);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    border: 1px dashed var(--sl-border-strong); background: transparent; color: var(--sl-text-2); font-size: 12px; cursor: pointer;
    transition: all .15s ease;
}
.cv-newclip:hover { color: var(--sl-text-1); border-color: var(--sl-accent-line); background: var(--sl-accent-tint); }
.cv-runall {
    align-self: flex-start; margin-top: 6px; display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 8px;
    border: 1px solid oklch(1 0 0 / 0.1); border-radius: var(--sl-r-6); background: var(--sl-control); color: var(--sl-text-1);
    font-size: 11px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.cv-runall:hover { background: var(--sl-control-hover); }
.cv-runall.is-stop { background: var(--sl-danger-wash); color: var(--sl-danger-text); border-color: var(--sl-danger-line); }
.cv-clip { touch-action: pan-x; }   /* a finger scrolls the timeline; a mouse drag reorders */
.cv-clip.is-dragging { opacity: .55; z-index: 4; cursor: grabbing; }
.cv-drop-mark { position: absolute; top: -4px; bottom: -4px; width: 3px; margin-left: -1.5px; border-radius: 2px; background: var(--sl-accent); z-index: 5; pointer-events: none; }
.cv-track { overflow: visible; }

/* ---- dropping files or assets on the view ---- */
.clips-view.is-drop::after {
    content: attr(data-drop); position: absolute; inset: 10px; z-index: 40; pointer-events: none;
    display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px;
    border: 2px dashed var(--sl-accent-line); border-radius: var(--sl-r-14); background: oklch(0.165 0.004 250 / .82);
    color: var(--sl-accent-text); font-size: 15px; font-weight: 600;
}

/* ---- right-click menu on a clip ---- */
.cv-menu { position: fixed; z-index: 10100; min-width: 180px; display: flex; flex-direction: column; animation: cv-pop-in .12s ease-out; }
.cv-menu-item { width: 100%; border: 0; background: transparent; color: var(--sl-text-1); text-align: left; cursor: pointer; font-family: var(--sl-font-ui); }

.cv-empty-acts { display: flex; gap: 8px; margin-top: 4px; }

/* ============================================================
   Reference picker (js/clips-ref-picker.js) — ComfyField's MediaPicker:
   one modal, tabs, a grid of square tiles, an Upload tile first.
   ============================================================ */
.rp {
    position: fixed; inset: 0; z-index: 10200; display: flex; align-items: center; justify-content: center; padding: 24px;
    background: oklch(0.1 0.004 250 / 0.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    animation: rp-fade .16s ease-out;
}
.rp.is-closing { animation: rp-out .14s ease-in forwards; }
.rp-card {
    width: min(760px, 100%); height: min(640px, calc(100vh - 48px)); display: flex; flex-direction: column;
    background: var(--sl-raised); border: 1px solid var(--sl-line-pop); border-radius: 14px; box-shadow: var(--sl-shadow-modal);
    color: var(--sl-text-1); font-family: var(--sl-font-ui); outline: none; overflow: hidden;
    animation: rp-in .18s cubic-bezier(.2, .8, .2, 1);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.rp-card.is-over { border-color: var(--sl-accent); box-shadow: var(--sl-shadow-modal), 0 0 0 3px var(--sl-accent-tint); }
.rp-head { flex: none; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 16px 8px; }
.rp-titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rp-titles h3 { margin: 0; font-size: 15px; font-weight: 600; }
.rp-sub { font-size: 12px; color: var(--sl-text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rp-x { flex: none; width: 30px; height: 30px; border: 0; border-radius: var(--sl-r-8); background: transparent; color: var(--sl-text-2); display: grid; place-items: center; cursor: pointer; }
.rp-x:hover { background: var(--sl-wash); color: var(--sl-text-1); }
.rp-bar { flex: none; display: flex; align-items: center; gap: 10px; padding: 0 16px 10px; }
.rp-tabs { flex: none; }
.rp-tab.is-on { background: var(--sl-segment-on); color: var(--sl-text-1); }
.rp-search { flex: 1; display: flex; align-items: center; gap: 6px; max-width: 280px; margin-left: auto; color: var(--sl-text-3); }
.rp-search[hidden] { display: none; }
.rp-search-in { flex: 1; min-width: 0; height: 30px; }
.rp-err { flex: none; margin: 0 16px 10px; padding: 8px 10px; border-radius: var(--sl-r-8); background: var(--sl-danger-wash); color: var(--sl-danger-text); font-size: 12px; }
.rp-err[hidden] { display: none; }
.rp-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 12px; }
.rp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.rp-tile {
    position: relative; aspect-ratio: 1; padding: 0; border: 1px solid var(--sl-hairline); border-radius: 10px; overflow: hidden;
    background: var(--sl-card); color: var(--sl-text-2); cursor: pointer; font-family: inherit;
    animation: rp-tile .22s ease-out backwards; animation-delay: calc(var(--i, 0) * 18ms);
    transition: border-color .15s ease, transform .15s ease;
}
.rp-tile:hover { border-color: var(--sl-border-strong); transform: translateY(-1px); }
.rp-tile:focus-visible { outline: 2px solid var(--sl-focus); outline-offset: 2px; }
.rp-tile img, .rp-tile video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.rp-badge { position: absolute; right: 6px; bottom: 6px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: oklch(0 0 0 / .6); color: var(--sl-text-1); }
.rp-label { position: absolute; left: 6px; top: 6px; padding: 1px 5px; border-radius: 4px; background: oklch(0 0 0 / .6); font-family: var(--sl-font-mono); font-size: 10px; color: var(--sl-text-1); }
.rp-audio { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 10px; font-size: 11.5px; text-align: center; overflow-wrap: anywhere; }
.rp-up {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    border: 1.5px dashed var(--sl-border-strong); background: transparent; animation: none;
}
.rp-up b { font-size: 13px; color: var(--sl-text-1); }
.rp-up span { font-size: 11px; color: var(--sl-text-3); }
.rp-up:hover { border-color: var(--sl-accent-line); background: var(--sl-accent-tint); }
.rp-up.is-busy { cursor: progress; opacity: .8; background: linear-gradient(110deg, var(--sl-card) 30%, var(--sl-quiet-hover) 50%, var(--sl-card) 70%); background-size: 200% 100%; animation: rp-shim 1.4s linear infinite; }
.rp-gen .rp-ic { color: var(--sl-link); }
.rp-file { display: none; }
.rp-empty { padding: 48px 12px; text-align: center; color: var(--sl-text-3); font-size: 13px; }
.rp-foot { flex: none; padding: 10px 16px; border-top: 1px solid var(--sl-hairline); font-size: 11px; color: var(--sl-text-3); }
@keyframes rp-fade { from { opacity: 0; } }
@keyframes rp-out { to { opacity: 0; } }
@keyframes rp-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes rp-tile { from { opacity: 0; transform: translateY(6px); } }
@keyframes rp-shim { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .rp, .rp-card, .rp-tile, .rp.is-closing { animation: none; } }

/* ============================================================
   Phone (body.pw-mobile, js/mobile-mode.js): one column.
   Crumbs, the preview, its references in a row, its takes in a row,
   the prompt, a compact transport, the timeline. No wires.
   ============================================================ */
body.pw-mobile .canvas-view-toggle { display: inline-flex; }
body.pw-mobile .canvas-view-toggle.hidden { display: none; }
body.pw-mobile .canvas-view-toggle .sl-seg-btn { padding: 0 9px; font-size: 0; gap: 0; height: 30px; }
body.pw-mobile .canvas-view-toggle .sl-seg-btn .cv-ic svg { width: 15px; height: 15px; }

body.pw-mobile .cv-top { padding: 8px 10px; gap: 8px; }
body.pw-mobile .cv-main { display: flex; flex-direction: column; gap: 8px; }
body.pw-mobile .cv-left { display: contents; }
body.pw-mobile .cv-crumbs { order: 0; flex: none; }
body.pw-mobile .cv-info { display: none; }
body.pw-mobile .cv-stage { order: 1; flex: 1; min-height: 150px; }
body.pw-mobile .cv-in {
    order: 2; flex: none; width: auto; max-width: none; align-self: stretch;
    flex-direction: row; justify-content: flex-start; align-items: stretch;
    overflow-x: auto; overflow-y: hidden; padding: 2px 2px 4px; gap: 8px;
}
body.pw-mobile .cv-in-h, body.pw-mobile .cv-in .cv-hint { display: none; }
body.pw-mobile .cv-card { width: auto; max-width: 200px; padding: 5px 9px 5px 5px; }
body.pw-mobile .cv-card-th { width: 36px; height: 36px; }
body.pw-mobile .cv-card.is-gen .cv-card-th { width: 24px; height: 42px; }
body.pw-mobile .cv-card-x { opacity: 1; }
body.pw-mobile .cv-socket { width: auto; max-width: none; height: auto; min-height: 44px; padding: 0 14px; white-space: nowrap; }
body.pw-mobile .cv-side { order: 3; flex: none; padding-left: 0; }
body.pw-mobile .cv-takes { flex-direction: row; align-items: center; max-height: none; overflow-x: auto; padding: 6px; }
body.pw-mobile .cv-takes-h { display: none; }
body.pw-mobile .cv-takes-g { grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: 40px; }
body.pw-mobile .cv-tk { width: 40px; }
body.pw-mobile .cv-send, body.pw-mobile .cv-sent { flex: none; }
body.pw-mobile .cv-wires { display: none; }

body.pw-mobile .cv-prompt-slot { width: 100%; }
body.pw-mobile .cv-prompt { gap: 6px; padding: 6px; }
body.pw-mobile .cv-set-btn { max-width: 38vw; padding: 0 8px; }
body.pw-mobile .cv-set-pop { left: -6px; width: min(304px, calc(100vw - 20px)); max-width: none; }
body.pw-mobile .cv-set-box { width: 100%; }
body.pw-mobile .cv-kbd { display: none; }
body.pw-mobile .cv-gen { padding: 0 12px; }

body.pw-mobile .cv-bar { padding: 0 6px; gap: 2px; overflow-x: auto; }
body.pw-mobile .cv-clock-sep, body.pw-mobile .cv-clock-total,
body.pw-mobile .cv-zoom, body.pw-mobile .cv-keys,
body.pw-mobile .cv-bar .cv-tbtn-text { display: none; }
body.pw-mobile .cv-clock { margin-left: 2px; }

body.pw-mobile .cv-timeline { height: 110px; }
body.pw-mobile .cv-tl-side { width: 92px; padding: 0 8px; }
body.pw-mobile .cv-runall { padding: 0 6px; font-size: 10.5px; }
body.pw-mobile .cv-tl-total { font-size: 13px; }
body.pw-mobile .cv-tl-sub { display: none; }
body.pw-mobile .cv-tl-scroll { padding: 0 10px; }

/* the picker fills the phone */
body.pw-mobile .rp { padding: 0; }
body.pw-mobile .rp-card { width: 100%; height: 100%; border-radius: 0; border: 0; }
body.pw-mobile .rp-bar { flex-wrap: wrap; }
body.pw-mobile .rp-search { max-width: none; margin-left: 0; flex-basis: 100%; }
body.pw-mobile .rp-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
body.pw-mobile .rp-x { width: 40px; height: 40px; }
