/**
 * TransportBar Component Styles
 * One-row FLAT instrument-panel toolbar (launch redesign, variant B) +
 * progress bar, scrubbing, and loop controls.
 *
 * Toolbar layout model: a single 64px row where every control sits on
 * one line — no stacked control pairs. Wide desktops get labeled tool
 * buttons; 1440–1560 compacts to icon-only with tooltips. Below 1440px,
 * TopbarWiringMethods reparents secondary controls into the named
 * Controls sections (.topbar-secondary-row) — same nodes, same wiring.
 * Stages: desktop ≥1440 · A ≤1439 · B ≤900 · mobile ≤560.
 */

.transport-bar {
    /* Variant-B visual identity — component-scoped, ≥2 consumers each */
    --tb-bar-grad-top: #26282d;
    --tb-bar-grad-bot: #1d1f23;
    --tb-lcd-bg: #0c0e11;
    --tb-lcd-text: #dfe6ee;
    --tb-lcd-muted: rgba(200, 214, 230, 0.4);
    --tb-field-bg: rgba(0, 0, 0, 0.32);
    --tb-field-border: rgba(255, 255, 255, 0.12);
    --tb-radius: 7px;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    z-index: 1000;
    background: transparent;
    color: #fff;
    user-select: none;
    /* Drawers escape the bar's box; keep layout isolation without paint
       containment, which would clip those surfaces. */
    contain: layout style;
    isolation: isolate;
}

/* ────────────────────────────────────────────────────────────
   BAR SHELL — one row
   ──────────────────────────────────────────────────────────── */
.topbar-panel {
    position: relative;
    z-index: 20;
    width: 100%;
    background: linear-gradient(var(--tb-bar-grad-top), var(--tb-bar-grad-bot));
    border-bottom: 1px solid rgb(0, 0, 0);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.topbar-primary-row {
    display: flex;
    align-items: center;
    height: 64px;
    padding: 0 var(--space-2);
    gap: 7px;
}

.tb-sep {
    flex: none;
    width: 1px;
    height: 38px;
    background: rgba(255, 255, 255, 0.08);
}

/* Flat layout: former stacks lay out inline. The wrappers remain so the
   stage reparenting map and Controls-panel styles keep working. */
.tb-stack {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 7px;
    flex: none;
}

.tb-row {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Hide rows whose only remaining children are stage anchors */
.tb-row:not(:has(> :not(.tb-stage-anchor))) {
    display: none;
}

.tb-stage-anchor {
    display: none;
}

/* Rendered for screen readers and tests, invisible in the bar. Unlike
   `hidden`, a clipped live region still fires announcements. */
.tb-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Neutralize legacy control-group chrome: grouping comes from hairline
   separators and proximity, not card surfaces. */
.topbar-panel .control-group {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
}

/* ────────────────────────────────────────────────────────────
   BRAND (original ChordBuddy wordmark)
   ──────────────────────────────────────────────────────────── */
.panel-left {
    position: relative;
    display: flex;
    align-items: center;
    flex: none;
}

.topbar-brand {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    border: 0;
    background: transparent;
}

.topbar-world-switcher {
    position: relative;
    z-index: 30;
    flex: 0 0 auto;
}

.topbar-world-trigger {
    min-height: 44px;
    padding: 2px 0;
    display: inline-flex;
    align-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.topbar-world-trigger:hover,
.topbar-world-trigger:focus-visible,
.topbar-world-switcher.is-open .topbar-world-trigger {
    background: linear-gradient(110deg, rgba(45, 146, 255, 0.13), rgba(255, 52, 94, 0.09));
    box-shadow: 0 0 0 1px rgba(98, 172, 255, 0.28), 0 0 18px rgba(44, 136, 255, 0.28);
}

.topbar-world-trigger:focus-visible {
    outline: 2px solid #8cc4ff;
    outline-offset: 2px;
}

.topbar-world-trigger picture,
.topbar-brand picture {
    display: flex;
    justify-content: center;
}

.topbar-world-panel {
    position: absolute;
    top: calc(100% - 4px);
    left: -5px;
    z-index: 29;
    width: min(236px, calc(100vw - 20px));
    padding: 7px;
    display: grid;
    gap: 5px;
    border: 1px solid rgba(151, 190, 225, 0.28);
    border-radius: 12px;
    background: linear-gradient(145deg, #20242b, #111216 72%);
    box-shadow: 0 20px 42px rgba(0, 0, 0, 0.5), 0 0 28px rgba(40, 133, 255, 0.12);
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px);
    transition: opacity 140ms ease, transform 140ms ease, visibility 0s linear 140ms;
}

.topbar-world-switcher.is-open .topbar-world-panel {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    transition-delay: 0s;
}

.topbar-world-choice {
    min-height: 58px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 11px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.025);
    color: #f5f7fb;
    text-align: left;
    cursor: pointer;
    transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease, opacity 140ms ease, background 140ms ease;
}

.topbar-world-choice.is-current {
    border-color: rgba(105, 181, 255, 0.34);
    background: rgba(43, 139, 242, 0.12);
}

.topbar-world-choice--synth.is-current {
    border-color: rgba(255, 75, 113, 0.42);
    background: linear-gradient(100deg, rgba(255, 43, 84, 0.14), rgba(139, 27, 255, 0.12));
}

.topbar-world-switcher:has(.topbar-world-choice:hover) .topbar-world-choice:not(:hover),
.topbar-world-switcher:has(.topbar-world-choice:focus-visible) .topbar-world-choice:not(:focus-visible) {
    opacity: 0.45;
}

.topbar-world-choice:hover,
.topbar-world-choice:focus-visible {
    position: relative;
    z-index: 1;
    transform: translateX(2px);
    border-color: rgba(111, 205, 255, 0.72);
    background: linear-gradient(100deg, rgba(37, 146, 255, 0.22), rgba(132, 47, 255, 0.15));
    box-shadow: 0 0 22px rgba(58, 160, 255, 0.46), inset 0 0 15px rgba(115, 72, 255, 0.12);
    outline: none;
}

.topbar-world-choice--synth:hover,
.topbar-world-choice--synth:focus-visible {
    border-color: rgba(255, 75, 113, 0.78);
    background: linear-gradient(100deg, rgba(255, 43, 84, 0.22), rgba(139, 27, 255, 0.18));
    box-shadow: 0 0 24px rgba(255, 44, 91, 0.48), 0 0 34px rgba(139, 27, 255, 0.26);
}

.topbar-world-choice__chordbuddy,
.topbar-world-synth-mark {
    width: 39px;
    height: 39px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 7px;
}

.topbar-world-choice__chordbuddy {
    background: #0d1118;
}

.topbar-world-choice__chordbuddy img {
    width: 47px;
    height: auto;
    filter: drop-shadow(0 0 5px rgba(64, 160, 255, 0.48));
}

.topbar-world-synth-mark {
    position: relative;
    border: 1px solid rgba(255, 97, 126, 0.62);
    background: radial-gradient(circle at 26% 24%, #6120b0, #25102f 53%, #100f17 100%);
    box-shadow: inset 0 0 14px rgba(255, 43, 84, 0.22);
}

.topbar-world-synth-mark i {
    position: absolute;
    width: 29px;
    height: 4px;
    border-radius: 99px;
    background: linear-gradient(90deg, #ff436a, #ffbd6d);
    box-shadow: 0 0 8px rgba(255, 57, 100, 0.9);
    transform: rotate(-24deg);
}

.topbar-world-synth-mark i:nth-child(1) { top: 10px; left: 3px; }
.topbar-world-synth-mark i:nth-child(2) { top: 18px; left: 8px; transform: rotate(25deg); }
.topbar-world-synth-mark i:nth-child(3) { top: 26px; left: 4px; }

.topbar-world-choice__copy {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.topbar-world-choice__copy strong {
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.topbar-world-choice__copy small {
    color: rgba(221, 231, 242, 0.66);
    font-size: 10px;
    letter-spacing: 0.05em;
}

.topbar-brand-logo {
    display: block;
    width: auto;
    height: 38px;
    max-width: min(20vw, 160px);
    object-fit: contain;
    filter: drop-shadow(0 0 6px rgba(41, 141, 255, 0.35));
}

@media (prefers-reduced-motion: reduce) {
    .topbar-world-choice,
    .topbar-world-panel {
        transition: none;
    }

    .topbar-world-choice:hover,
    .topbar-world-choice:focus-visible {
        transform: none;
    }
}

/* ────────────────────────────────────────────────────────────
   FILE / CREATE — one line of labeled tool buttons (icon over label).
   SketchLibraryPanel appends its handle as the 4th button.
   ──────────────────────────────────────────────────────────── */
.file-ops-group {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: none;
}

.file-ops-group > .ui-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: auto;
    min-width: 44px;
    height: 46px;
    min-height: 46px;
    padding: 0 6px;
    border: 0;
    border-radius: var(--tb-radius);
    background: transparent;
    color: var(--text-2);
    font-size: 9.5px;
    white-space: nowrap;
}

.sketch-export-control {
    position: relative;
    flex: none;
}

.sketch-export-control > summary {
    list-style: none;
}

.sketch-export-control > summary::-webkit-details-marker {
    display: none;
}

.file-ops-group > .sketch-export-control > .sketch-export-summary {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 44px;
    height: 46px;
    min-height: 46px;
    padding: 0 6px;
    border: 0;
    border-radius: var(--tb-radius);
    background: transparent;
    color: var(--text-2);
    font-size: 9.5px;
    white-space: nowrap;
    cursor: pointer;
}

.file-ops-group > .sketch-export-control > .sketch-export-summary:hover,
.sketch-export-control[open] > .sketch-export-summary {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-1);
}

.sketch-export-summary .icon,
.sketch-export-summary .icon svg {
    display: inline-flex;
    width: 16px;
    height: 16px;
}

.sketch-export-summary[aria-disabled="true"] {
    opacity: 0.55;
    pointer-events: none;
}

.sketch-export-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 90;
    display: grid;
    min-width: 188px;
    padding: 6px;
    border: 1px solid rgba(142, 217, 255, 0.28);
    border-radius: var(--radius-md);
    background: rgba(8, 16, 25, 0.98);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.42);
}

.sketch-export-menu button {
    min-height: 34px;
    padding: 0 10px;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--text-1);
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.sketch-export-menu button:hover:not(:disabled) {
    background: rgba(142, 217, 255, 0.12);
}

.sketch-export-menu button:disabled {
    opacity: 0.5;
    cursor: default;
}

.file-ops-group > .ui-button:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-1);
}

.file-ops-group > .ui-button .icon {
    display: inline-flex;
    width: 16px;
    height: 16px;
    flex: none;
}

.file-ops-group > .ui-button .icon svg {
    width: 16px;
    height: 16px;
}

.file-ops-group .sketch-library-handle__icon {
    font-size: 13px;
    line-height: 1;
}

/* ────────────────────────────────────────────────────────────
   SONG CONTEXT
   ──────────────────────────────────────────────────────────── */
.topbar-song {
    flex: 1 1 150px;
    min-width: 100px;
    max-width: 300px;
    padding: 2px var(--space-2) 2px 0;
}

.topbar-song-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-song-status {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
    font-size: var(--font-xs);
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
}

.topbar-song-status-dot {
    flex: none;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #35c46a;
}

.topbar-song[data-song-state="mixed"] .topbar-song-status-dot {
    background: var(--status-warn);
}

.topbar-song[data-song-state="empty"] .topbar-song-status-dot {
    background: var(--text-3);
}

.topbar-song[data-song-state="empty"] .topbar-song-title {
    color: var(--text-3);
    font-weight: 500;
}

/* ────────────────────────────────────────────────────────────
   TRANSPORT — raised hardware buttons; Play dominates
   ──────────────────────────────────────────────────────────── */
.transport-main-group {
    flex: none;
    gap: var(--space-1);
}

.transport-main-group .ui-button {
    display: grid;
    place-items: center;
    width: 38px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    border: 1px solid var(--tb-field-border);
    border-radius: var(--tb-radius);
    background: linear-gradient(#33353b, #282a2f);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    color: #dde3ea;
}

.transport-main-group .ui-button:hover {
    background: linear-gradient(#3b3d44, #2e3036);
    color: #fff;
}

.transport-main-group .ui-button .icon svg {
    width: 16px;
    height: 16px;
}

.transport-main-group .play-button {
    width: 46px;
    height: 44px;
    background: linear-gradient(#3c3f46, #2c2e34);
    color: #fff;
    font-size: 17px;
}

.transport-main-group .play-button:hover {
    background: linear-gradient(#44474f, #33363c);
}

.transport-main-group .play-button.is-playing {
    background: linear-gradient(#4aa0ff, #2b78e8);
    border-color: rgba(56, 145, 255, 0.7);
    box-shadow: var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.sketch-record-button {
    color: #ff6f7d;
    width: auto;
    min-width: 38px;
    padding: 0 8px;
    gap: 4px;
    transition: background var(--dur-base) var(--ease-out),
                box-shadow var(--dur-base) var(--ease-out),
                color var(--dur-base) var(--ease-out);
}

.sketch-record-status {
    font: 700 var(--font-xs) var(--font-mono);
    letter-spacing: 0.04em;
}

.sketch-count-in-select {
    height: 30px;
    max-width: 106px;
    border: 1px solid var(--tb-field-border);
    border-radius: var(--radius-md);
    color: var(--text-2);
    background: var(--tb-field-bg);
    font-size: var(--font-xs);
}

.sketch-count-in-select[hidden] {
    display: none !important;
}

.sketch-record-button[hidden] {
    display: none !important;
}

.sketch-record-button:disabled {
    color: rgba(255, 110, 125, 0.35);
    cursor: not-allowed;
}

.sketch-record-button--active,
.sketch-record-button[aria-pressed="true"] {
    background: rgba(255, 70, 92, 0.25);
    color: #ffd0d6;
    box-shadow: 0 0 8px rgba(255, 70, 92, 0.6);
    animation: sketch-record-pulse 1.05s ease-in-out infinite;
}

@keyframes sketch-record-pulse {
    0%, 100% { box-shadow: 0 0 6px rgba(255, 70, 92, 0.5); }
    50% { box-shadow: 0 0 14px rgba(255, 70, 92, 1); }
}

/* History toggle — single entry point for the rolling MIDI buffer overlay. */
.history-toggle-button--sketch {
    color: var(--text-1);
    box-shadow: inset 0 0 0 1px var(--border-strong);
}

.history-toggle-button--sketch:hover {
    box-shadow: inset 0 0 0 1px var(--accent);
}

.history-toggle-button--active,
.history-toggle-button[aria-pressed="true"] {
    background: var(--accent-bg-soft);
    color: var(--accent);
    box-shadow: var(--accent-glow);
}

/* ────────────────────────────────────────────────────────────
   LCD — recessed display: position · tempo · transpose/pitch
   ──────────────────────────────────────────────────────────── */
.topbar-lcd {
    display: flex;
    align-items: stretch;
    flex: none;
    height: 46px;
    background: var(--tb-lcd-bg);
    border: 1px solid rgba(0, 0, 0, 0.9);
    border-radius: 9px;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.55),
                inset 0 -1px 0 rgba(255, 255, 255, 0.04),
                0 1px 0 rgba(255, 255, 255, 0.05);
    overflow: hidden;
}

.lcd-seg {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 0 10px;
}

.lcd-seg + .lcd-seg,
.topbar-lcd .lcd-duo {
    border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.lcd-caption {
    font-size: 8px;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--tb-lcd-muted);
    line-height: 1;
    pointer-events: none;
}

.lcd-unit {
    font-size: 9.5px;
    color: var(--tb-lcd-muted);
    margin-left: 3px;
}

/* position segment */
.topbar-status-panel {
    flex: none;
}

.musical-position-display {
    display: inline-flex;
    align-items: center;
    gap: 0;
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: #eaf2fb;
    white-space: nowrap;
    transition: opacity 150ms ease;
}

.musical-position-display.inactive {
    opacity: 0.45;
}

.musical-position-display .pos-separator {
    color: var(--text-3);
    inline-size: 1ch;
    text-align: center;
}

.musical-position-display .pos-bar,
.musical-position-display .pos-beat,
.musical-position-display .pos-sixteenth {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.musical-position-display .pos-bar { inline-size: 4ch; }
.musical-position-display .pos-beat { inline-size: 2ch; color: var(--accent-hover); }
.musical-position-display .pos-sixteenth { inline-size: 2ch; }

.time-signature-display {
    display: inline-flex;
    justify-content: flex-end;
    margin-left: 4px;
    inline-size: 20px;
    font-size: var(--font-xs);
    font-family: var(--font-system);
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

/* tempo segment */
.lcd-seg-tempo {
    position: relative;
    padding-right: 18px;
}

.tempo-control {
    display: flex;
    align-items: baseline;
}

.tempo-display {
    min-width: 38px;
    padding: 0;
    border: 0;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 500;
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--tb-lcd-text);
    cursor: ns-resize;
    user-select: none;
    touch-action: none;
}

.tempo-display:hover {
    color: #fff;
}

.tempo-display.dragging {
    color: var(--accent);
}

.tempo-display:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

.lcd-stepper {
    position: absolute;
    right: 3px;
    top: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 1px;
}

.lcd-seg-tempo:hover .lcd-stepper,
.lcd-seg-tempo:focus-within .lcd-stepper {
    display: flex;
}

.tempo-btn {
    width: 14px;
    height: 12px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
}

.tempo-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

.tempo-btn svg {
    width: 8px;
    height: 8px;
    fill: currentColor;
}

/* transpose / master-pitch — full-height LCD segments, like tempo */
.lcd-duo {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    padding: 0;
}

.lcd-mini {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 0 var(--space-2);
    border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.lcd-mini:hover {
    background: rgba(255, 255, 255, 0.045);
}

.lcd-mini-controls {
    display: flex;
    align-items: center;
    gap: 1px;
}

/* Octave accelerators appear only on roomy desktops; ±1, drag, typing and
   keyboard still cover the full ±12 range directly. */
.lcd-step.octave-down,
.lcd-step.octave-up {
    display: none;
}

.lcd-step {
    display: grid;
    place-items: center;
    min-width: 13px;
    height: 16px;
    padding: 0 2px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-3);
    font-size: 9px;
    font-family: var(--font-mono);
    cursor: pointer;
}

.lcd-step:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

.lcd-step:disabled,
.lcd-step.disabled {
    opacity: 0.3;
    cursor: default;
}

.lcd-step svg {
    width: 8px;
    height: 8px;
    fill: currentColor;
}

.lcd-step:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.pitch-display {
    min-width: 26px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--tb-lcd-text);
    cursor: pointer;
}

.pitch-display:hover {
    color: #fff;
    background: var(--border-default);
}

.pitch-display.nonzero {
    color: var(--accent);
}

.pitch-display:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ────────────────────────────────────────────────────────────
   SONG SOUND — instrument over preset + edit + level knob
   ──────────────────────────────────────────────────────────── */
.song-control-group {
    flex: none;
    gap: 5px;
    min-width: 0;
}

.song-select-stack .ui-select {
    height: 30px;
    min-height: 30px;
    padding: 0 18px 0 var(--space-2);
    font-size: var(--font-sm);
    background-color: var(--tb-field-bg);
    border-color: var(--tb-field-border);
}

.song-instrument-select,
.song-preset-select {
    width: 96px;
}

.topbar-panel .song-instrument-edit-btn {
    height: 30px;
    width: 28px;
    border: 0;
    background: transparent;
    border-radius: var(--tb-radius);
}

.topbar-panel .song-instrument-edit-btn:hover {
    background: rgba(255, 255, 255, 0.07);
}

/* knob */
.topbar-knob {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    width: 38px;
    flex: none;
    cursor: ns-resize;
    touch-action: none;
}

.topbar-knob > svg {
    width: 28px;
    height: 28px;
    display: block;
}

.topbar-knob .knob-track { stroke: rgba(255, 255, 255, 0.14); }
.topbar-knob .knob-fill { stroke: var(--accent); }
.topbar-knob .knob-face { fill: #33363c; stroke: rgba(255, 255, 255, 0.16); }
.topbar-knob .knob-pointer { stroke: #e8edf4; }

.topbar-knob:hover .knob-face { fill: #3b3e45; }

.knob-caption {
    font-size: 8px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
    line-height: 1;
    pointer-events: none;
}

.knob-value {
    position: absolute;
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    padding: 2px 7px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--surface-0);
    font-family: var(--font-mono);
    font-size: var(--font-xs);
    color: var(--text-1);
    white-space: nowrap;
    pointer-events: none;
    z-index: 40;
}

.topbar-knob:hover .knob-value,
.topbar-knob.dragging .knob-value,
.topbar-knob:focus-within .knob-value {
    display: block;
}

/* Inside the 64px fixed bar the bubble opens downward so it cannot clip
   above the viewport; in the Controls surface there is headroom above. */
.topbar-primary-row .topbar-knob .knob-value {
    top: calc(100% + 4px);
}

.topbar-knob .knob-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}

.topbar-knob.is-disabled {
    opacity: 0.38;
    cursor: default;
}

/* ────────────────────────────────────────────────────────────
   PRACTICE — one line: Metro · click · subdivision · Loop · snap ·
   bars · Wait. Anchor toggles are labeled tool buttons.
   ──────────────────────────────────────────────────────────── */
.practice-group {
    flex: none;
    gap: 5px;
}

.practice-group .tb-row,
.workspace-stack {
    gap: 5px;
}

.practice-group .tb-row .ui-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: auto;
    min-width: 40px;
    height: 46px;
    min-height: 46px;
    padding: 0 6px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-2);
    font-size: 9.5px;
}

.practice-group .tb-row .ui-button:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-1);
}

.practice-group .tb-row .ui-button.active,
.practice-group .tb-row .ui-button[aria-pressed="true"] {
    background: var(--accent-bg-soft);
    border-color: rgba(56, 145, 255, 0.35);
    color: var(--accent-hover);
}

.practice-group .tb-row .ui-button .icon {
    display: inline-flex;
    width: 16px;
    height: 16px;
}

.practice-group .tb-row .ui-button .icon svg {
    width: 16px;
    height: 16px;
}

.topbar-primary-row .workspace-stack .account-button-label {
    display: none;
}

/* keep the bar's shortcuts handle icon-compact */
.workspace-stack .shortcuts-hud__title,
.workspace-stack .shortcuts-hud__chevron {
    display: none;
}

.practice-group .topbar-knob {
    width: 24px;
    flex-direction: row;
}

.practice-group .topbar-knob > svg {
    width: 22px;
    height: 22px;
}

.practice-group .topbar-knob .knob-caption {
    display: none;
}

/* segmented switches */
.metronome-subdivision-group,
.snap-segment-track {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0;
    border: 1px solid var(--tb-field-border);
    border-radius: var(--radius-md);
    background: var(--tb-field-bg);
    overflow: hidden;
    gap: 0;
}

.metronome-subdivision-button,
.snap-segment-btn {
    height: 100%;
    min-width: 0;
    padding: 0 6px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-3);
    font-size: var(--font-xs);
    font-weight: 500;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out);
}

.metronome-subdivision-button + .metronome-subdivision-button,
.snap-segment-btn + .snap-segment-btn {
    border-left: 1px solid rgba(255, 255, 255, 0.07);
}

.metronome-subdivision-button:hover,
.snap-segment-btn:hover {
    color: var(--text-1);
}

.metronome-subdivision-button.active,
.snap-segment-btn.active {
    background: var(--accent-bg-soft);
    color: var(--accent-hover);
}

.metronome-subdivision-button:focus-visible,
.snap-segment-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.snap-toggle {
    display: inline-flex;
    align-items: center;
}

.snap-title {
    display: none;
}

.loop-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.loop-bars-group {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

/* Quick-set bar buttons are roomy-desktop accelerators for the direct
   Bar Count field. */
.topbar-primary-row .loop-bar-btn {
    display: none;
}

.loop-bar-btn {
    width: 20px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    color: var(--text-3);
    font-family: var(--font-mono);
    font-size: var(--font-xs);
    font-weight: 700;
    cursor: pointer;
}

.loop-bar-btn:hover {
    border-color: rgba(120, 170, 255, 0.42);
    background: var(--accent-bg-soft);
    color: #fff;
}

.loop-bar-btn.active {
    border-color: rgba(56, 145, 255, 0.62);
    background: rgba(56, 145, 255, 0.34);
    color: #fff;
}

.loop-bar-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.loop-bars-field {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0 6px 0 2px;
    border: 1px solid var(--tb-field-border);
    border-radius: var(--radius-md);
    background: var(--tb-field-bg);
}

.loop-bars-input {
    width: 26px;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    text-align: right;
    font-family: var(--font-mono);
    font-size: var(--font-sm);
    color: var(--text-1);
}

.loop-bars-input::-webkit-outer-spin-button,
.loop-bars-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.loop-bars-suffix {
    font-size: 9px;
    color: var(--text-3);
    margin-left: 3px;
}

/* Wait — standalone practice-mode button, amber when armed */
.practice-group > .wait-for-note-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 44px;
    height: 46px;
    min-height: 46px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-2);
}

.practice-group > .wait-for-note-button .icon svg {
    width: 15px;
    height: 15px;
}

.practice-group > .wait-for-note-button .button-label {
    font-size: 9px;
    color: var(--text-3);
}

.practice-group > .wait-for-note-button:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-1);
}

.wait-for-note-button.active,
.wait-for-note-button[aria-pressed="true"] {
    background: var(--status-warn-bg-soft);
    border-color: rgba(255, 171, 64, 0.4);
    color: var(--status-warn);
}

.wait-for-note-button.active .button-label,
.wait-for-note-button[aria-pressed="true"] .button-label {
    color: var(--status-warn);
}

.wait-for-note-button.waiting {
    background: var(--status-warn-bg-soft);
    color: var(--status-warn);
    animation: pulse-waiting 2s infinite;
}

@keyframes pulse-waiting {
    0% { box-shadow: 0 0 0 0 rgba(255, 171, 64, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(255, 171, 64, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 171, 64, 0); }
}

/* ────────────────────────────────────────────────────────────
   WORKSPACE — one line: Mixer · zoom · shortcuts · account · settings
   ──────────────────────────────────────────────────────────── */
.topbar-utilities-group {
    flex: none;
}

.workspace-stack .ui-button {
    display: flex;
    align-items: center;
    gap: 5px;
    width: auto;
    height: 30px;
    min-height: 30px;
    padding: 0 var(--space-1);
    border: 0;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-2);
    font-size: var(--font-sm);
}

.workspace-stack .mixer-toggle-button {
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    min-width: 42px;
    height: 46px;
    min-height: 46px;
    padding: 0 6px;
    font-size: 9.5px;
}

.workspace-stack .ui-button:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-1);
}

.workspace-stack .ui-button .icon {
    display: inline-flex;
    width: 15px;
    height: 15px;
}

.workspace-stack .ui-button .icon svg {
    width: 15px;
    height: 15px;
}

.workspace-stack .settings-button .button-label,
.workspace-stack .account-button .button-label {
    display: none;
}

.zoom-control {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0 var(--space-1);
    color: var(--text-3);
}

.zoom-icon {
    display: inline-flex;
    width: 12px;
    height: 12px;
    opacity: 0.6;
}

.zoom-icon svg {
    width: 12px;
    height: 12px;
}

.topbar-panel .visual-speed-slider {
    height: 3px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.18);
}

.visual-speed-slider {
    --range-width: 46px;
    width: 46px;
}

/* ────────────────────────────────────────────────────────────
   DEV IDENTITY + UTILITY DOCK
   ──────────────────────────────────────────────────────────── */
.dev-identity-strip {
    box-sizing: border-box;
    height: 28px;
    max-width: 150px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 9px;
    border-radius: var(--radius-pill);
    border: 1px solid rgba(111, 207, 151, 0.36);
    background: rgba(30, 92, 58, 0.36);
    color: rgba(226, 255, 238, 0.92);
    font-family: var(--font-mono);
    font-size: var(--font-xs);
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    flex: 0 0 auto;
}

.dev-identity-strip:hover {
    border-color: rgba(111, 207, 151, 0.72);
    background: rgba(30, 116, 68, 0.48);
    color: #fff;
}

.dev-identity-strip:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.dev-identity-strip__label {
    color: rgba(181, 238, 204, 0.72);
    text-transform: uppercase;
    font-size: 10px;
}

.dev-identity-strip__value {
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
}

.dev-identity-strip--copied {
    border-color: rgba(56, 145, 255, 0.72);
    background: rgba(56, 145, 255, 0.24);
    color: #fff;
}

.topbar-panel .dev-identity-strip {
    position: absolute;
    left: 0;
    top: -4px;
    z-index: 2;
    height: 18px;
    max-width: 42px;
    padding: 0 5px;
    gap: 0;
    font-size: 9px;
    justify-content: center;
}

.topbar-panel .dev-identity-strip__value {
    display: none;
}

.transport-utility-dock {
    position: fixed;
    right: 12px;
    bottom: calc(var(--statusbar-height, 40px) + var(--keyboard-height, 150px) + 12px);
    z-index: 1201;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    pointer-events: none;
}

.transport-utility-dock .dev-identity-strip {
    height: 28px;
    max-width: min(150px, calc(100vw - 24px));
    padding: 0 9px;
    gap: 6px;
    font-size: var(--font-xs);
    justify-content: flex-end;
    pointer-events: auto;
}

.transport-utility-dock .dev-identity-strip__value {
    display: inline-block;
}

.topbar-shortcuts-mount {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ────────────────────────────────────────────────────────────
   CONTROLS TRIGGER + SECTIONED CONTROLS SURFACE (<1440)
   ──────────────────────────────────────────────────────────── */
.topbar-menu-button {
    display: none;
    align-items: center;
    gap: var(--space-1);
    height: 40px;
    min-width: 40px;
    padding: 0 var(--space-3);
    border: 1px solid var(--tb-field-border);
    border-radius: var(--tb-radius);
    background: rgba(0, 0, 0, 0.25);
    color: var(--text-1);
    font-size: var(--font-md);
    font-weight: 600;
    flex: none;
    margin-left: auto;
}

.topbar-menu-button:hover {
    border-color: var(--border-strong);
    background: rgba(255, 255, 255, 0.05);
}

.topbar-menu-button.active,
.topbar-menu-button[aria-expanded="true"] {
    background: var(--accent-bg-soft);
    color: var(--accent-hover);
    border-color: rgba(56, 145, 255, 0.5);
}

.topbar-secondary-row {
    display: none;
}

/* ────────────────────────────────────────────────────────────
   RESPONSIVE STAGES
   ──────────────────────────────────────────────────────────── */

/* Roomy desktop (≥1900): labeled flat, wider brand/selects */
@media (min-width: 1900px) {
    .topbar-primary-row {
        gap: 7px;
        padding: 0 var(--space-2);
    }

    .topbar-brand-logo {
        height: 40px;
        max-width: 138px;
    }

    .topbar-song {
        max-width: 380px;
    }

    .song-instrument-select,
    .song-preset-select {
        width: 96px;
    }

    .file-ops-group > .ui-button {
        min-width: 40px;
    }

    .transport-main-group .ui-button {
        width: 40px;
    }

    .transport-main-group .play-button {
        width: 50px;
    }

    .visual-speed-slider {
        --range-width: 44px;
        width: 44px;
    }
}

/* Very wide (≥2100): octave and quick-bar accelerators return */
@media (min-width: 2100px) {
    .lcd-step.octave-down,
    .lcd-step.octave-up {
        display: grid;
    }

    .topbar-primary-row .loop-bar-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .song-instrument-select,
    .song-preset-select {
        width: 122px;
    }

    .topbar-song {
        max-width: 420px;
    }
}

/* Compact desktop (1440–1899): flat trades labels for icons here —
   tooltips carry the names; the roomy tier restores them. */
@media (max-width: 1899px) {
    .topbar-primary-row {
        gap: 4px;
        padding: 0 var(--space-2);
    }

    .tb-sep {
        display: none;
    }

    .topbar-brand-logo {
        height: 28px;
        max-width: 78px;
    }

    .topbar-song {
        max-width: 240px;
        min-width: 80px;
    }

    .file-ops-group > .ui-button,
    .practice-group .tb-row .ui-button {
        flex-direction: row;
        height: 30px;
        min-height: 30px;
        min-width: 0;
        padding: 0 5px;
        gap: 0;
    }

    .workspace-stack .mixer-toggle-button {
        flex-direction: row;
        height: 30px;
        min-height: 30px;
        min-width: 0;
        padding: 0 5px;
        gap: 0;
    }

    .file-ops-group > .ui-button .button-label,
    .file-ops-group .sketch-library-handle__label,
    .practice-group .tb-row .ui-button .button-label,
    .workspace-stack .mixer-toggle-button .button-label {
        display: none;
    }

    .practice-group > .wait-for-note-button {
        flex-direction: row;
        width: 30px;
        height: 30px;
        min-height: 30px;
        gap: 0;
    }

    .practice-group > .wait-for-note-button .button-label {
        display: none;
    }

    .song-instrument-select,
    .song-preset-select {
        width: 86px;
    }

    .song-select-stack .ui-select {
        font-size: 10.5px;
        padding: 0 14px 0 6px;
    }

    .song-select-stack {
        gap: 4px;
    }

    .topbar-panel .song-instrument-edit-btn {
        width: 24px;
    }

    .lcd-seg {
        padding: 0 var(--space-2);
    }

    .musical-position-display {
        font-size: 15px;
    }

    .lcd-seg-tempo {
        padding-right: 15px;
    }

    /* transpose/pitch: value + caption only; ±1 steppers reveal on
       hover/focus, exactly like the tempo segment */
    .lcd-mini {
        position: relative;
        padding: 0 12px;
    }

    .lcd-mini .lcd-step {
        display: none;
    }

    .lcd-mini:hover .lcd-step.semitone-down,
    .lcd-mini:focus-within .lcd-step.semitone-down {
        display: grid;
        position: absolute;
        left: 1px;
        top: 50%;
        transform: translateY(-50%);
    }

    .lcd-mini:hover .lcd-step.semitone-up,
    .lcd-mini:focus-within .lcd-step.semitone-up {
        display: grid;
        position: absolute;
        right: 1px;
        top: 50%;
        transform: translateY(-50%);
    }

    .pitch-display {
        min-width: 24px;
    }

    .knob-caption {
        display: none;
    }

    .topbar-knob {
        width: 26px;
    }

    .topbar-knob > svg {
        width: 24px;
        height: 24px;
    }

    .metronome-subdivision-button,
    .snap-segment-btn {
        padding: 0 3px;
    }

    .loop-bars-input {
        width: 20px;
    }

    .loop-bars-suffix {
        display: none;
    }

    .practice-group .tb-row,
    .workspace-stack,
    .practice-group,
    .song-control-group {
        gap: 4px;
    }

    .file-ops-group {
        gap: 2px;
    }

    .file-ops-group > .ui-button,
    .practice-group .tb-row .ui-button {
        padding: 0 4px;
    }

    .file-ops-group > .ui-button .icon svg,
    .practice-group .tb-row .ui-button .icon svg {
        width: 15px;
        height: 15px;
    }

    .workspace-stack .shortcuts-hud__summary {
        padding: 0 4px;
    }

    .zoom-control {
        padding: 0 2px;
        gap: 3px;
    }

    .visual-speed-slider {
        --range-width: 30px;
        width: 30px;
    }

    .transport-main-group .ui-button {
        width: 34px;
    }

    .transport-main-group .play-button {
        width: 42px;
    }
}

/* Compact sketch mode (1440–1620): the contextual Record + count-in pair
   joins the row, so every family narrows a step further — nothing hides. */
@media (max-width: 1620px) {
    .topbar-panel[data-sketch-mode] .sketch-record-status {
        font-size: 9px;
    }

    .topbar-panel[data-sketch-mode] .sketch-count-in-select {
        max-width: 70px;
    }

    .topbar-panel[data-sketch-mode] .sketch-record-button {
        padding: 0 5px;
    }

    .topbar-panel[data-sketch-mode] .file-ops-group {
        gap: 1px;
    }

    .topbar-panel[data-sketch-mode] .topbar-brand-logo {
        max-width: 64px;
    }

    .topbar-panel[data-sketch-mode] .song-instrument-select,
    .topbar-panel[data-sketch-mode] .song-preset-select {
        width: 78px;
    }

    .topbar-panel[data-sketch-mode] .lcd-mini .lcd-caption,
    .topbar-panel[data-sketch-mode] .knob-caption {
        display: none;
    }

    .topbar-panel[data-sketch-mode] .lcd-seg,
    .topbar-panel[data-sketch-mode] .lcd-mini {
        padding: 0 6px;
    }

    .topbar-panel[data-sketch-mode] .topbar-song {
        min-width: 64px;
    }

    .topbar-panel[data-sketch-mode] .visual-speed-slider {
        --range-width: 24px;
        width: 24px;
    }

    .topbar-panel[data-sketch-mode] .metronome-subdivision-button,
    .topbar-panel[data-sketch-mode] .snap-segment-btn {
        padding: 0 2px;
    }

    .topbar-panel[data-sketch-mode] .topbar-primary-row {
        gap: 3px;
    }
}

/* Stage A (≤1439): Controls trigger appears; JS moves secondary families
   into the sections. Remaining anchors keep the bar calm. */
@media (max-width: 1439px) {
    .topbar-menu-button {
        display: flex;
    }

    .tb-sep {
        display: none;
    }

    .topbar-song {
        max-width: 320px;
    }

    .practice-group .tb-row .ui-button,
    .workspace-stack .ui-button,
    .file-ops-group > .ui-button {
        height: 34px;
        min-height: 34px;
        padding: 0 var(--space-2);
        gap: 5px;
    }

    .practice-group .tb-row .ui-button .button-label,
    .workspace-stack .mixer-toggle-button .button-label,
    .file-ops-group > .ui-button .button-label,
    .file-ops-group .sketch-library-handle__label {
        display: inline;
    }

    .practice-group .tb-row,
    .workspace-stack .tb-row {
        height: auto;
    }

    /* Transient overlay, not a workspace band.
     *
     * In normal flow this row grew the toolbar by ~205px, which grew
     * --transport-topbar-height and pushed every surface below it down — on a
     * 620px viewport that left 115px for the whole workspace, and the mixer
     * rail did not follow the push while its lanes did. Floating it means the
     * disclosure consumes zero vertical band: it is a launcher you open,
     * change one thing in, and close. Reparenting/staging is untouched; only
     * the box it renders in changed. */
    .topbar-secondary-row.is-open {
        display: flex;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-wrap: wrap;
        gap: var(--space-5) 34px;
        padding: var(--space-4) var(--space-4) var(--space-5);
        background: linear-gradient(#232529, #1c1e22);
        border-top: 1px solid var(--border-subtle);
        border-bottom: 1px solid rgba(0, 0, 0, 0.9);
        box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55);
        /* Bounded so a tall control stack scrolls itself instead of running
         * off-screen or over the keyboard. */
        max-height: calc(100vh - var(--transport-topbar-height, 60px) - var(--statusbar-height, 28px) - 12px);
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .cp-section {
        min-width: 150px;
    }

    /* a section only exists once the stage has moved controls into it */
    .cp-section:has(> .cp-slot:empty) {
        display: none;
    }

    .cp-section-title {
        margin: 0 0 var(--space-2);
        font-size: var(--font-xs);
        font-weight: 600;
        letter-spacing: 0.12em;
        text-transform: uppercase;
        color: var(--text-3);
    }

    .cp-slot {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-2);
    }

    /* moved controls relax to touchable sizes inside the panel */
    .cp-slot .ui-button,
    .cp-slot .ui-select {
        height: 32px;
        min-height: 32px;
    }

    .cp-slot .ui-button {
        border: 1px solid var(--border-default);
        background: rgba(0, 0, 0, 0.25);
        padding: 0 var(--space-3);
        white-space: nowrap;
        width: auto;
    }

    .cp-slot .button-label {
        display: inline !important;
    }

    .cp-slot .lcd-duo {
        flex-direction: column;
        align-items: flex-start;
        border: 0;
        padding: 0;
        gap: var(--space-2);
    }

    .cp-slot .lcd-mini {
        flex-direction: row;
        height: 26px;
        gap: var(--space-2);
        border-left: 0;
        padding: 0;
        background: transparent;
    }

    .cp-slot .lcd-mini .lcd-caption {
        order: -1;
        width: 52px;
        font-size: var(--font-sm);
        text-transform: none;
        letter-spacing: 0;
        color: var(--text-2);
    }

    .cp-slot .lcd-mini .lcd-step {
        display: grid;
        position: static;
        transform: none;
    }

    .cp-slot .lcd-step,
    .cp-slot .pitch-display {
        height: 24px;
        min-width: 24px;
        border: 1px solid var(--border-default);
        background: rgba(0, 0, 0, 0.25);
    }

    .cp-slot .song-select-stack {
        flex-direction: column;
        gap: var(--space-2);
    }

    .cp-slot .song-instrument-select,
    .cp-slot .song-preset-select {
        width: 160px;
    }

    .cp-slot .topbar-knob {
        flex-direction: row;
        width: auto;
        gap: var(--space-2);
    }

    .cp-slot .topbar-knob .knob-caption {
        display: inline;
        font-size: var(--font-sm);
        text-transform: none;
        letter-spacing: 0;
        color: var(--text-2);
    }

    .cp-slot .loop-quick-set {
        flex-wrap: wrap;
        gap: var(--space-2);
    }

    .cp-slot .loop-bar-btn {
        display: inline-flex;
        width: 26px;
        height: 26px;
        align-items: center;
        justify-content: center;
    }

    .cp-slot .metronome-subdivision-group,
    .cp-slot .snap-segment-track,
    .cp-slot .loop-bars-field {
        height: 28px;
    }

    .cp-slot .zoom-control .visual-speed-slider {
        --range-width: 140px;
        width: 140px;
    }

    .cp-slot .wait-for-note-button {
        flex-direction: row;
        width: auto;
        height: 32px;
        min-height: 32px;
        gap: var(--space-2);
        padding: 0 var(--space-3);
    }

    .cp-slot .wait-for-note-button .button-label {
        font-size: var(--font-sm);
    }
}

/* Stage A tightening (covers 1024 exactly) */
@media (max-width: 1120px) {
    .topbar-primary-row {
        gap: var(--space-1);
    }

    .topbar-brand-logo {
        height: 32px;
        max-width: 120px;
    }

    .topbar-song {
        max-width: 220px;
        min-width: 96px;
    }

    .lcd-seg {
        padding: 0 var(--space-2);
    }

    .practice-group .tb-row .ui-button .button-label,
    .workspace-stack .mixer-toggle-button .button-label,
    .file-ops-group > .ui-button .button-label,
    .file-ops-group .sketch-export-summary .button-label,
    .file-ops-group .sketch-library-handle__label {
        display: none;
    }

    .file-ops-group > .ui-button,
    .file-ops-group .sketch-export-summary,
    .practice-group .tb-row .ui-button {
        padding: 0 5px;
        gap: 0;
    }

    .transport-main-group .ui-button {
        width: 34px;
    }

    .transport-main-group .play-button {
        width: 42px;
    }
}

/* Stage B (≤900): brand, Load, Capture, song, transport, tempo,
   Metro, Loop, Controls */
@media (max-width: 900px) {
    .topbar-brand-logo {
        max-width: 92px;
    }

    .lcd-seg {
        padding: 0 var(--space-2);
    }

    .lcd-seg-tempo {
        padding-right: 14px;
    }

    .topbar-song {
        min-width: 88px;
        flex-basis: 110px;
    }

}

@media (min-width: 561px) and (max-width: 800px) {
    .topbar-brand-logo {
        max-width: 64px;
    }
}

/* Mobile (≤560): brand mark, song, Stop, Play, Capture/Record, Controls.
   Controls opens as a full-height scrollable sheet. */
@media (max-width: 560px) {
    .topbar-primary-row {
        height: 60px;
        gap: 6px;
        padding: 0 var(--space-2);
    }

    .topbar-primary-row > .practice-group,
    .topbar-primary-row > .topbar-utilities-group,
    .topbar-primary-row > .song-control-group,
    .topbar-primary-row > .file-ops-group {
        display: none;
    }

    .topbar-brand-logo {
        height: 28px;
        max-width: 84px;
    }

    .topbar-song {
        min-width: 56px;
        flex-basis: 60px;
        max-width: none;
    }

    .topbar-song-status {
        display: none;
    }

    .transport-main-group .ui-button {
        width: 44px;
        height: 44px;
    }

    .transport-main-group .play-button {
        width: 50px;
        height: 46px;
    }

    .topbar-lcd {
        display: none;
    }

    .topbar-menu-button {
        height: 44px;
        min-width: 44px;
    }

    .topbar-menu-button .button-label {
        display: none;
    }

    /* .transport-bar's layout containment makes it the containing block
       for fixed descendants, so the sheet anchors below the panel and
       sizes itself to the remaining viewport instead. */
    .topbar-secondary-row.is-open {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        height: calc(100vh - var(--transport-topbar-height, 60px));
        overflow-y: auto;
        background: rgb(30, 32, 36);
        flex-direction: column;
        flex-wrap: nowrap;
        gap: var(--space-6);
        padding: var(--space-4) var(--space-4) 40px;
        z-index: 90;
    }

    .cp-slot .ui-button,
    .cp-slot .ui-select {
        height: 44px;
        min-height: 44px;
        font-size: var(--font-lg);
    }

    .cp-slot .lcd-mini {
        height: 40px;
    }

    .cp-slot .lcd-step,
    .cp-slot .pitch-display {
        height: 38px;
        min-width: 38px;
        font-size: var(--font-md);
    }

    .cp-slot .tempo-control {
        align-items: center;
        gap: var(--space-2);
    }

    .cp-slot .tempo-display {
        font-size: 18px;
        cursor: ns-resize;
    }

    .cp-slot .lcd-stepper {
        position: static;
        display: flex;
        flex-direction: row;
        gap: var(--space-2);
    }

    .cp-slot .tempo-btn {
        width: 38px;
        height: 38px;
        border: 1px solid var(--border-default);
        background: rgba(0, 0, 0, 0.25);
    }

    .cp-slot .metronome-subdivision-group,
    .cp-slot .snap-segment-track,
    .cp-slot .loop-bars-field {
        height: 38px;
    }

    .cp-slot .metronome-subdivision-button,
    .cp-slot .snap-segment-btn {
        padding: 0 var(--space-4);
        font-size: var(--font-md);
    }

    .cp-slot .song-instrument-select,
    .cp-slot .song-preset-select {
        width: 200px;
    }

    .cp-slot .zoom-control .visual-speed-slider {
        --range-width: 170px;
        width: 170px;
    }
}

@media (max-width: 360px) {
    .topbar-brand-logo {
        max-width: 48px;
    }

    .topbar-song {
        min-width: 40px;
    }

    .transport-main-group .ui-button {
        width: 40px;
    }

    .transport-main-group .play-button {
        width: 44px;
    }
}

/* Hide the floating dev-identity dock while the Controls surface is open.
   Media-scoped so a stale open state can never affect desktop. */
@media (max-width: 1439px) {
    body.cb-topbar-controls-open .transport-utility-dock {
        display: none;
    }
}

.progress-bar-container {
    --timeline-label-height: 18px;
    position: relative;
    margin-left: var(--mixer-reserved-left, 0px);
    width: calc(
        100%
        - var(--mixer-reserved-left, 0px)
        - var(--mixer-reserved-right, 0px)
    );
    height: var(--transport-progress-height, 45px);
    background-color: rgb(25, 25, 30);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    overflow: hidden;
    contain: layout paint style;
    flex-shrink: 0;
    /* Prevent crushing */
}

.progress-bar-container.pan-hover,
.progress-bar-container.pan-hover .progress-bar-bg,
.progress-bar-container.pan-hover .progress-fill,
.progress-bar-container.pan-hover .timeline-canvas,
.progress-bar-container.pan-hover .time-signature-marker-hitbox,
.progress-bar-container.pan-modifier,
.progress-bar-container.pan-modifier .progress-bar-bg,
.progress-bar-container.pan-modifier .progress-fill,
.progress-bar-container.pan-modifier .timeline-canvas,
.progress-bar-container.pan-modifier .time-signature-marker-hitbox {
    cursor: grab;
}

.progress-bar-container.pan-active,
.progress-bar-container.pan-active .progress-bar-bg,
.progress-bar-container.pan-active .progress-fill,
.progress-bar-container.pan-active .timeline-canvas,
.progress-bar-container.pan-active .time-signature-marker-hitbox,
.progress-bar-container.pan-active .loop-grab-strip {
    cursor: grabbing;
}

.progress-bar-container.pan-hover .progress-zoom-badge,
.progress-bar-container.pan-modifier .progress-zoom-badge,
.progress-bar-container.pan-active .progress-zoom-badge {
    cursor: zoom-out;
}

.progress-bar-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.05);
    z-index: 0;
}

.progress-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background-color: rgb(56, 145, 255);
    transform-origin: left center;
    transform: scaleX(0);
    transition: transform 100ms ease-out;
    will-change: transform;
    z-index: 0;
    opacity: 0.08;
}

.timeline-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.progress-bar-container .timeline-canvas.timeline-static {
    z-index: 1;
}

.progress-bar-container .timeline-canvas.timeline-moving {
    z-index: 2;
}

.timeline-labels {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: var(--timeline-label-height);
    pointer-events: none;
    color: rgba(255, 255, 255, 0.4);
    font-size: 10px;
    font-family: monospace;
    z-index: 3;
}

.measure-markers {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 4;
}

.progress-pan-zone-hint {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    opacity: 0;
    transition: opacity 160ms ease;
    transition-delay: 0ms;
}

.progress-pan-zone-hint-line {
    position: absolute;
    left: 50%;
    top: 50%;
    width: min(260px, calc(100% - 32px));
    height: 1px;
    transform: translate(-50%, -0.5px);
    background: rgba(255, 255, 255, 0.28);
}

.progress-pan-zone-hint-label {
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.58);
    opacity: 0.42;
    font-size: 8px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.92);
    white-space: nowrap;
    transition: color 110ms ease, opacity 110ms ease;
}

.progress-pan-zone-hint-label--scrub {
    top: 25%;
}

.progress-pan-zone-hint-label--grab {
    top: 75%;
}

.progress-bar-container.is-viewport-zoomed.progress-hint-visible .progress-pan-zone-hint {
    opacity: 1;
    transition-delay: 140ms;
}

.progress-bar-container.scrub-hover .progress-pan-zone-hint-label--scrub,
.progress-bar-container.pan-hover .progress-pan-zone-hint-label--grab,
.progress-bar-container.pan-modifier .progress-pan-zone-hint-label--grab {
    color: rgba(255, 255, 255, 0.96);
    opacity: 1;
}

.progress-bar-container.is-compact-height .progress-pan-zone-hint-label {
    opacity: 0;
}

.progress-bar-container.is-compact-height.scrub-hover .progress-pan-zone-hint-label--scrub,
.progress-bar-container.is-compact-height.pan-hover .progress-pan-zone-hint-label--grab,
.progress-bar-container.is-compact-height.pan-modifier .progress-pan-zone-hint-label--grab {
    opacity: 1;
}

.progress-bar-container.is-compact-height .progress-pan-zone-hint-line {
    width: min(180px, calc(100% - 32px));
}

@media (prefers-reduced-motion: reduce) {
    .progress-pan-zone-hint,
    .progress-pan-zone-hint-label {
        transition: none;
    }
}

.time-signature-marker-hitbox {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 14px;
    transform: translateX(-50%);
    background: transparent;
    cursor: pointer;
    pointer-events: auto;
}

/* Playhead */
.playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #3891ff;
    box-shadow: 0 0 8px rgba(56, 145, 255, 0.6);
    z-index: 10;
    pointer-events: none;
    will-change: transform;
}

.progress-zoom-badge {
    position: absolute;
    left: 8px;
    bottom: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    height: 22px;
    padding: 0 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    background: rgba(16, 18, 23, 0.78);
    color: rgba(255, 255, 255, 0.86);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(10px);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    cursor: zoom-out;
    /* Keep the badge above static/moving timeline layers but below drag handles. */
    z-index: 12;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
}

.progress-zoom-badge[hidden] {
    display: none;
}

.progress-zoom-badge:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring), 0 4px 12px rgba(0, 0, 0, 0.22);
}

.progress-zoom-badge-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    color: rgba(56, 145, 255, 0.96);
    flex: 0 0 auto;
}

.progress-zoom-badge-icon svg {
    width: 12px;
    height: 12px;
    display: block;
    fill: currentColor;
}

.progress-zoom-badge-label {
    display: inline-block;
    min-width: 0;
    white-space: nowrap;
}

.progress-zoom-badge.is-pulsing {
    animation: var(--progress-zoom-badge-pulse-name, progress-zoom-badge-pulse-a) 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes progress-zoom-badge-pulse-a {
    0% {
        transform: scale(0.96);
        box-shadow: 0 0 0 rgba(56, 145, 255, 0);
    }
    38% {
        transform: scale(1.04);
        box-shadow: 0 0 0 6px rgba(56, 145, 255, 0.14);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
    }
}

@keyframes progress-zoom-badge-pulse-b {
    0% {
        transform: scale(0.96);
        box-shadow: 0 0 0 rgba(56, 145, 255, 0);
    }
    38% {
        transform: scale(1.04);
        box-shadow: 0 0 0 6px rgba(56, 145, 255, 0.14);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
    }
}

/* Resize Handle */
.timeline-resize-handle {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 6px;
    cursor: ns-resize;
    cursor: row-resize;
    z-index: 20;
    transition: background 0.1s;
}

.timeline-resize-handle:hover,
.timeline-resize-handle:focus {
    background: rgba(56, 145, 255, 0.3);
}

/* Loop staging preview (Shift+drag) and active loop region */
.loop-staging-overlay {
    position: absolute;
    top: 0;
    height: 100%;
    background: rgba(255, 255, 255, 0.25);
    border: 1px dashed rgba(255, 255, 255, 0.35);
    border-radius: 4px;
    display: none;
    pointer-events: none;
    z-index: 3;
}

.loop-overlay {
    position: absolute;
    top: 0;
    height: 100%;
    background: rgba(255, 165, 0, 0.4);
    border: 1px solid rgba(255, 165, 0, 0.5);
    border-radius: 4px;
    display: none;
    pointer-events: none;
    overflow: hidden;
    z-index: 3;
}

.loop-grab-strip {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 24px;
    background: rgba(255, 140, 0, 0.18);
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    cursor: grab;
    pointer-events: auto;
    z-index: 3;
    transition: background 0.12s ease;
}

.loop-grab-strip:hover {
    background: rgba(255, 140, 0, 0.32);
    box-shadow: inset 0 -1px 0 rgba(255, 200, 100, 0.5);
}

.loop-grab-strip:active {
    cursor: grabbing;
    background: rgba(255, 110, 0, 0.45);
    transition: none;
}

.loop-boundary-fill {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(255, 165, 0, 0.1);
    display: none;
    pointer-events: none;
}

.loop-handles {
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    display: none;
    pointer-events: none;
    z-index: 4;
}

.loop-handle {
    position: absolute;
    top: -4px;
    width: 8px;
    height: 16px;
    background: #ff8c00;
    border: 1px solid #ff6600;
    border-radius: 4px;
    cursor: ew-resize;
    pointer-events: all;
    transform: translateX(-50%);
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.loop-handle:hover {
    background: #ffa500;
    transform: translateX(-50%) scale(1.1);
}

.loop-handle:active {
    background: #ff6600;
}

.loop-handle.loop-start::before {
    content: 'A';
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: #ff8c00;
    font-weight: bold;
}

.loop-handle.loop-end::before {
    content: 'B';
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: #ff8c00;
    font-weight: bold;
}

/* ────────────────────────────────────────────────────────────
   ROLLING MIDI CAPTURE OVERLAY (Sketch Progress Buffer)
   The Capture button in the top bar swaps the normal progress
   bar fill/timeline for this overlay: a red-tinted canvas that
   visualises the 10-minute rolling MIDI capture, with HUD,
   playhead, write band, and pointer selection.
   ──────────────────────────────────────────────────────────── */
.sketch-progress-buffer {
    position: absolute;
    inset: 0;
    z-index: 8;
    background: linear-gradient(180deg, rgba(12, 20, 31, 0.97), rgba(9, 15, 25, 0.98));
    border-top: 1px solid rgba(90, 177, 255, 0.3);
    border-bottom: 1px solid rgba(90, 177, 255, 0.3);
    overflow: hidden;
    contain: layout paint style;
    cursor: crosshair;
    box-shadow: none;
    isolation: isolate;
}

.sketch-progress-buffer--audio {
    background:
        linear-gradient(180deg, rgba(5, 32, 37, 0.98), rgba(6, 18, 27, 0.99)),
        repeating-linear-gradient(90deg, rgba(126, 215, 196, 0.035) 0 1px, transparent 1px 10px);
    border-top-color: rgba(126, 215, 196, 0.54);
    border-bottom-color: rgba(126, 215, 196, 0.46);
    cursor: crosshair;
}

.sketch-progress-buffer--audio-active {
    box-shadow: inset 0 0 22px rgba(57, 196, 166, 0.12);
}

.sketch-progress-buffer[hidden] {
    display: none !important;
}

/* When the buffer overlay is up, hide the underlying timeline
   layers so the Capture surface is the only thing the user sees
   in the progress lane. The normal layers come back the instant
   we toggle off. */
.progress-bar-container--sketch-buffer .progress-bar-bg,
.progress-bar-container--sketch-buffer .progress-fill,
.progress-bar-container--sketch-buffer .timeline-canvas,
.progress-bar-container--sketch-buffer .timeline-labels,
.progress-bar-container--sketch-buffer .measure-markers,
.progress-bar-container--sketch-buffer .playhead {
    opacity: 0;
    pointer-events: none;
}

.progress-bar-container--sketch-buffer {
    background-color: rgb(22, 10, 12);
}

.sketch-progress-buffer__canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    z-index: 1;
}

.sketch-progress-buffer__write-band {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 20px;
    background: linear-gradient(90deg,
        rgba(86, 195, 255, 0) 0%,
        rgba(86, 195, 255, 0.08) 58%,
        rgba(86, 195, 255, 0.28) 100%);
    pointer-events: none;
    z-index: 3;
    will-change: transform;
}

.sketch-progress-buffer--audio .sketch-progress-buffer__write-band {
    width: 30px;
    background: linear-gradient(90deg,
        rgba(126, 215, 196, 0) 0%,
        rgba(126, 215, 196, 0.14) 50%,
        rgba(192, 255, 237, 0.5) 100%);
}

.sketch-progress-buffer--audio .sketch-progress-buffer__playhead {
    width: 3px;
    background: #b9fff0;
    box-shadow: -6px 0 12px rgba(126, 215, 196, 0.32);
}

.sketch-progress-buffer__playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #8ed9ff;
    box-shadow: -5px 0 8px rgba(86, 195, 255, 0.2);
    z-index: 4;
    pointer-events: none;
    will-change: transform;
}

.sketch-progress-buffer__selection {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
}

.sketch-progress-buffer__selection[hidden] {
    display: none;
}

.sketch-progress-buffer__selection-fill {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(255, 70, 92, 0.18);
    border-left: 1px solid rgba(255, 70, 92, 0.7);
    border-right: 1px solid rgba(255, 70, 92, 0.7);
    will-change: transform, width;
}

.sketch-progress-buffer__hud {
    position: absolute;
    top: 6px;
    left: 10px;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    z-index: 5;
    pointer-events: none;
    font-family: var(--font-mono);
    font-size: var(--font-sm);
    letter-spacing: 0.04em;
}

.sketch-progress-buffer__actions {
    position: absolute;
    top: 6px;
    right: 10px;
    z-index: 7;
    display: flex;
    align-items: center;
    gap: 4px;
}

.sketch-progress-buffer__action,
.sketch-progress-buffer__save {
    min-height: 26px;
    border: 1px solid rgba(142, 217, 255, 0.38);
    border-radius: var(--radius-sm);
    color: #d9f3ff;
    background: rgba(8, 20, 31, 0.84);
    font: 600 var(--font-xs) var(--font-sans);
    cursor: pointer;
}

.sketch-progress-buffer__action {
    min-width: 28px;
    padding: 0 7px;
    font-size: 16px;
}

.sketch-progress-buffer__mode {
    width: auto;
    font-size: var(--font-xs);
}

.sketch-progress-buffer__audition,
.sketch-progress-buffer__audio-export {
    width: auto;
    font-size: var(--font-xs);
}

.sketch-progress-buffer__mode.is-active {
    color: #07131e;
    background: #8ed9ff;
}

.sketch-progress-buffer__audio-source {
    min-height: 26px;
    border: 1px solid rgba(126, 215, 196, 0.42);
    border-radius: var(--radius-sm);
    color: #d9fff6;
    background: rgba(8, 20, 31, 0.92);
}

.sketch-progress-buffer__save {
    padding: 0 10px;
}

.sketch-progress-buffer__save:disabled {
    opacity: 0.45;
    cursor: default;
}

.sketch-progress-buffer__chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: rgba(255, 70, 92, 0.18);
    border: 1px solid rgba(255, 70, 92, 0.45);
    color: #ffd0d6;
    text-transform: uppercase;
    font-weight: 600;
}

.sketch-progress-buffer__status {
    color: rgba(255, 208, 214, 0.8);
}

.sketch-progress-buffer--audio .sketch-progress-buffer__chip {
    color: #d3fff1;
    background: rgba(126, 215, 196, 0.15);
    border-color: rgba(126, 215, 196, 0.52);
}

.sketch-progress-buffer--audio .sketch-progress-buffer__status {
    color: rgba(211, 255, 241, 0.88);
    font-weight: 700;
}

.sketch-progress-buffer__audio-hint {
    color: rgba(183, 233, 220, 0.72);
    font-size: var(--font-xs);
    letter-spacing: 0.02em;
}

.sketch-progress-buffer__legend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: rgba(216, 235, 247, 0.82);
}

.sketch-progress-buffer__legend i {
    width: 10px;
    height: 4px;
    border-radius: 1px;
}

.sketch-progress-buffer__legend-you {
    background: #f6b753;
}

.sketch-progress-buffer__legend-song {
    background: #70a5cf;
}

.sketch-progress-buffer__clip-label {
    color: rgba(255, 208, 214, 0.95);
    padding: 2px 6px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-sm);
}

.sketch-progress-buffer__clip-label[hidden] {
    display: none;
}

/* ────────────────────────────────────────────────────────────
   CARRIED CAPTURE CLIP
   The strip sets overflow:hidden AND contain:content, and paint
   containment also makes it a containing block for fixed-position
   descendants — so a carried clip drawn inside it is clipped to a
   46px band no matter how it is positioned. It lives on <body>
   instead, above every workspace surface and below modals.
   ──────────────────────────────────────────────────────────── */
.capture-carry-layer {
    --carry-song: 112, 165, 207;   /* matches the strip's Song legend */
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1400;          /* > utility dock 1201, sketch bar 1105; < modal 2000 */
    pointer-events: none;
    will-change: transform;
    transform: translate3d(-9999px, -9999px, 0);
}

.capture-carry-layer[hidden] {
    display: none;
}

.capture-carry-tile {
    /* D4: the carried material is ALWAYS the "you played this" amber. It never
       adopts the target lane's colour — that colour belongs to the landing
       zone, and a tile that changed hue per lane would stop meaning anything. */
    --carry-amber: 246, 183, 83;
    --carry-song: 112, 165, 207;   /* matches the strip's Song legend */
    width: 148px;
    border: 1px solid rgba(var(--carry-amber), 0.9);
    border-radius: var(--radius-sm);
    background: rgba(19, 15, 9, 0.86);
    overflow: hidden;
    transform: rotate(-1.5deg);
    filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.62));
    backdrop-filter: blur(3px);
}

.capture-carry-tile__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: 3px 6px;
    background: rgba(var(--carry-amber), 0.9);
    color: #16100a;
    font: 700 9px/1.3 var(--font-mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.capture-carry-tile__roll {
    display: block;
    width: 148px;
    height: 40px;
}

.capture-carry-tile__foot {
    padding: 3px 6px;
    font: 500 9px/1.35 var(--font-mono);
    color: rgba(255, 255, 255, 0.72);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

/* ── Grouped carry ─────────────────────────────────────────
   A selection holding both the song and your own playing becomes
   TWO clips, so it is carried as two offset cards. A single
   blended tile would hide the second clip until after release. */
.capture-carry-stack {
    position: relative;
}

.capture-carry-card {
    position: absolute;
    left: -14px;
    top: -13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    width: 148px;
    padding: 3px 6px;
    border: 1px solid rgba(var(--carry-song), 0.9);
    border-radius: var(--radius-sm);
    background: rgba(10, 20, 28, 0.94);
    color: #d5e9f7;
    font: 600 9px/1.4 var(--font-mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    transform: rotate(-3deg);
}

.capture-carry-card[hidden] {
    display: none;
}

.capture-carry-card__label {
    color: rgb(var(--carry-song));
}

.capture-carry-card__count {
    color: rgba(255, 255, 255, 0.55);
    text-transform: none;
    letter-spacing: 0.02em;
}

/* Grouped: shift the performance tile clear of the card stacked behind it. */
.capture-carry-layer--grouped .capture-carry-tile {
    margin-top: 6px;
    margin-left: 4px;
}

/* Song-only: the one carried clip IS the reference, so it wears song blue. */
.capture-carry-layer--reference-only .capture-carry-tile {
    border-color: rgba(var(--carry-song), 0.9);
}

.capture-carry-layer--reference-only .capture-carry-tile__head {
    background: rgba(var(--carry-song), 0.9);
    color: #06161f;
}

/* Accepting an existing lane: echo that lane's own tint on the border only,
   so the tile's identity colour still reads. */
.capture-carry-tile[style*="--carry-tint"] {
    border-color: rgba(var(--carry-tint), 0.95);
}

/* Pending: an accepted destination that has no track yet (new lane, new
   sketch, shelf slot). Neutral, never a guessed palette colour. */
.capture-carry-layer--pending .capture-carry-tile {
    border-style: dashed;
    border-color: rgba(255, 255, 255, 0.78);
}

.capture-carry-layer--blocked .capture-carry-tile {
    border-color: #ff6b6b;
    background: rgba(26, 10, 10, 0.88);
}

.capture-carry-layer--blocked .capture-carry-tile__head {
    background: #ff6b6b;
    color: #24070b;
}

.capture-carry-layer--busy .capture-carry-tile__foot {
    color: rgba(255, 255, 255, 0.92);
}

@media (prefers-reduced-motion: reduce) {
    /* Keep the offset and the shadow — they are what make the clip read as
       carried — and drop only the tilt. Nothing is removed, so nothing is
       learned by one group and not the other. */
    .capture-carry-tile {
        transform: none;
    }

    .capture-carry-card {
        transform: none;
        top: -16px;
    }
}

/* ────────────────────────────────────────────────────────────
   DROP SHELF — the visible destinations when no lane can accept.
   D1 removed the old "anything below the strip commits" fallback,
   so without this a carry on a practice song would have nowhere
   legal to land.
   ──────────────────────────────────────────────────────────── */
.capture-drop-shelf {
    position: fixed;
    left: 50%;
    /* Default anchor; the gesture overrides `top` at press so the shelf sits
       under the capture strip instead of on top of the piano keyboard. */
    bottom: 24px;
    transform: translateX(-50%);
    z-index: 1390;
    display: flex;
    gap: var(--space-2);
    padding: var(--space-2);
    background: rgba(10, 13, 18, 0.96);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.6);
}

.capture-drop-shelf[hidden] {
    display: none;
}

.capture-drop-shelf__slot {
    min-width: 152px;
    padding: 10px 12px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-md);
    color: var(--text-2);
    font: 600 var(--font-sm) var(--font-sans);
    text-align: center;
}

.capture-drop-shelf__slot small {
    display: block;
    margin-top: 3px;
    font: 400 9px/1.4 var(--font-mono);
    color: var(--text-3);
}

/* Armed shelf slot uses the neutral pending tint — no track exists yet. */
.capture-drop-shelf__slot--armed {
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.92);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

/* Source filter — D3 moved include-song-reference off the Shift key. */
.sketch-progress-buffer__sources {
    display: inline-flex;
    gap: 2px;
}

.sketch-progress-buffer__source {
    min-width: 34px;
    font-size: var(--font-xs);
}

.sketch-progress-buffer__source.is-active {
    color: #07131e;
    background: #8ed9ff;
}

.sketch-progress-buffer__carry-live {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* The source range stays visible while carrying, but steps back so it reads as
   provenance rather than competing with the carried clip. */
.sketch-progress-buffer--carrying .sketch-progress-buffer__selection-fill {
    background: rgba(255, 70, 92, 0.07);
    border-color: rgba(255, 70, 92, 0.55);
}

.sketch-progress-buffer--staged .sketch-progress-buffer__selection-fill {
    background: rgba(255, 70, 92, 0.22);
    border-width: 2px;
}

.sketch-progress-buffer--hover-staged {
    cursor: grab;
}

.sketch-progress-buffer--carrying {
    cursor: grabbing;
}

.sketch-progress-buffer--committed {
    animation: sketch-progress-buffer-commit 450ms ease-out;
}

@keyframes sketch-progress-buffer-commit {
    0% { box-shadow: inset 0 0 0 0 rgba(255, 70, 92, 0.6); }
    40% { box-shadow: inset 0 0 0 6px rgba(255, 70, 92, 0.55); }
    100% { box-shadow: inset 0 0 24px rgba(255, 70, 92, 0.18); }
}
