/**
 * TransportBar Component Styles
 * Professional transport controls with progress bar, scrubbing, and loop controls
 */

.transport-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    /* Remove fixed calculation, let it grow */
    height: auto;
    z-index: 1000;
    background: transparent;
    color: #fff;
    user-select: none;
    contain: layout paint style;
    isolation: isolate;
}

/* Main panel container (buttons and controls) */
.topbar-panel {
    width: 100%;
    min-height: 60px;
    /* FIXED: Decouple from dynamic variable to prevent resize feedback loop */
    height: auto;
    background: var(--glass-surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 6px 14px;
    gap: 10px;
    flex-wrap: wrap;
    row-gap: 8px;
    transition: background 0.3s ease, border-color 0.3s ease;
    position: relative;
    z-index: 20;
}

/* Primary Row Wrapper */
.topbar-primary-row {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 8px 10px;
    flex-wrap: wrap;
}

/* File Ops Group (Back, Load, Upload) - Keep horizontal */
.topbar-brand {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    margin-right: 8px;
}

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

.file-ops-group {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.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;
    letter-spacing: 0;
    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::-webkit-scrollbar {
    display: none;
}

/* Panel sections */
.panel-left,
.panel-center,
.panel-drawer,
.panel-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 0 0 auto;
    max-width: 100%;
    min-width: 0;
}

/* Panel Ordering (Desktop Default) */
.panel-left {
    order: 1;
}

.topbar-status-panel {
    order: 2;
    margin: 0 var(--space-3);
}

.panel-center {
    order: 3;
}

.panel-drawer {
    order: 4;
}

.panel-right {
    order: 5;
}

/* Panel Center: Main Transport (Play/Stop) - Always visible, prioritized */
.panel-center {
    justify-content: center;
    flex: 0 0 auto;
    margin: 0 var(--space-3);
}

.sketch-record-button {
    color: #ff6f7d;
    transition: background 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}

.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.
   The button lives in the top bar in all modes; sketch mode bumps its accent
   so the rolling-buffer affordance stands out next to the lane controls. */
.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);
}

.panel-drawer {
    /* Secondary controls (Pitch, Speed, Input) */
    flex: 1 1 100%;
    width: 100%;
    justify-content: flex-start;
    align-items: center;
    gap: var(--space-2);
    padding: 6px 0 0;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-wrap: wrap;
    background: transparent;
}

.panel-right {
    flex: 0 0 auto;
    justify-content: flex-end;
    max-width: 100%;
    /* margin-left: auto; REMOVED: Drawer takes the space now */
}

/* Updated Status Panel (In Flow) */
.topbar-status-panel {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 1;
    /* Ensure above bg */
    flex: 0 0 auto;
}

.musical-position-display {
    /* Fixed top-bar footprint: bar/beat/sixteenth/signature text plus five gaps, padding, borders, and badge chrome. */
    --musical-position-inline-size: calc(34ch + (var(--space-2) * 6) + (var(--space-4) * 2) + 24px);
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 7px var(--space-4);
    border-radius: var(--radius-lg);
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
    font-size: var(--font-lg);
    font-family: var(--font-mono);
    font-weight: 600;
    letter-spacing: 0;
    color: var(--text-1);
    transition: opacity 150ms ease, background var(--dur-base) var(--ease-out),
        border-color var(--dur-base) var(--ease-out);
    white-space: nowrap;
    inline-size: var(--musical-position-inline-size);
    flex: 0 0 var(--musical-position-inline-size);
}

.musical-position-display.inactive {
    opacity: 0.5;
    background: transparent;
    border-color: transparent;
}

.musical-position-display .pos-separator {
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.8em;
    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: 9ch;
}

.musical-position-display .pos-beat {
    inline-size: 7ch;
}

.musical-position-display .pos-sixteenth {
    inline-size: 4ch;
}

.musical-position-display .pos-bpm {
    inline-size: 7ch;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--text-2);
}

/* Time Signature Badge */
.time-signature-display {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--border-default);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    font-size: var(--font-sm);
    color: var(--text-2);
    margin-left: var(--space-2);
    inline-size: calc(5ch + 12px);
    min-width: calc(5ch + 12px);
    font-variant-numeric: tabular-nums;
}

/* 
 * CONTROL GROUPS 
 */
.control-group {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-lg);
    padding: var(--space-1) var(--space-2);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.control-group-label {
    font-size: var(--font-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-3);
    margin: 0 var(--space-2);
    pointer-events: none;
}

.song-control-group {
    flex: 0 1 auto;
    min-width: 0;
    gap: 6px;
}

.song-control-group .ui-select {
    height: 28px;
    min-width: 0;
    max-width: 132px;
    font-size: var(--font-sm);
}

.song-instrument-select {
    width: 128px;
}

.song-preset-select {
    width: 116px;
}

.song-control-group .song-level {
    flex: 0 0 76px;
    width: 76px;
}

.song-level-value {
    min-width: 42px;
    font-size: var(--font-xs);
    text-align: right;
    white-space: nowrap;
}

/* Wait Button Special State */
.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); }
}

/* 
 * TRANSPOSE & PITCH CONTROLS 
 */
.pitch-control {
    display: flex;
    align-items: center;
    gap: 2px;
}

.pitch-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-default);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-2);
    border-radius: var(--radius-sm);
    font-size: var(--font-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--dur-base) var(--ease-out),
                color var(--dur-base) var(--ease-out),
                border-color var(--dur-base) var(--ease-out);
    padding: 0;
}

.pitch-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border-color: var(--border-strong);
}

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

.pitch-display {
    min-width: 32px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-md);
    font-weight: 600;
    color: var(--text-1);
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    margin: 0 2px;
    cursor: pointer;
    font-variant-numeric: tabular-nums;
}

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

.pitch-display.nonzero {
    color: var(--accent);
    background: rgba(56, 145, 255, 0.12);
}

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

/* 
 * SPEED CONTROLS 
 */
.speed-control-group {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    background: var(--surface-2);
    border-radius: var(--radius-pill);
    padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1);
}

.tempo-control {
    display: flex;
    align-items: center;
    gap: 1px;
}

.tempo-btn {
    width: var(--control-h-sm);
    height: var(--control-h-sm);
    border-radius: 50%;
    border: none;
    background: var(--border-default);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-lg);
    transition: background var(--dur-base) var(--ease-out);
}

.tempo-btn:hover {
    background: var(--border-strong);
}

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

.tempo-display {
    min-width: 45px;
    text-align: center;
    font-size: var(--font-md);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--text-1);
    cursor: pointer;
    user-select: none;
    touch-action: none;
}

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

/* Visual Speed Slider (Zoom) */
.zoom-control {
    display: flex;
    align-items: center;
    gap: 8px;
    --range-width: 60px;
}

.zoom-icon {
    opacity: 0.5;
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.metronome-control-group {
    gap: var(--space-1);
    padding-right: var(--space-2);
}

.metronome-toggle-button {
    min-width: 46px;
    height: 28px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
}

.metronome-toggle-button.active {
    background: rgba(56, 145, 255, 0.3);
    border-color: rgba(56, 145, 255, 0.55);
    color: #fff;
}

.metronome-level {
    width: 86px;
    flex: 0 0 86px;
}

.metronome-level-value {
    min-width: 50px;
    text-align: right;
    font-size: var(--font-xs);
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.metronome-subdivision-group {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-default);
    background: rgba(255, 255, 255, 0.04);
}

.metronome-subdivision-button {
    height: 24px;
    min-width: 38px;
    border: none;
    border-radius: calc(var(--radius-pill) - 2px);
    background: transparent;
    color: var(--text-3);
    font-size: var(--font-xs);
    font-weight: 600;
    letter-spacing: 0.2px;
    cursor: pointer;
    transition: background var(--dur-base) var(--ease-out),
                color var(--dur-base) var(--ease-out);
}

.metronome-subdivision-button:hover {
    color: var(--text-2);
}

.metronome-subdivision-button.active {
    background: rgba(56, 145, 255, 0.28);
    color: #fff;
}

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

/* Menu Toggle (Hidden by Default) */
.menu-toggle {
    display: none;
    margin-left: 8px;
}

/* Responsive */
/* Keep single-row desktop until space is genuinely constrained. */
@media (max-width: 1100px) {
    .topbar-brand-logo {
        height: 42px;
        max-width: min(34vw, 200px);
    }

    .topbar-panel {
        flex-wrap: wrap;
        padding: 6px 12px;
        row-gap: 8px;
        column-gap: 10px;
        align-items: center;
    }

    .topbar-primary-row {
        display: flex;
        width: 100%;
        align-items: center;
        flex-wrap: wrap;
        gap: 8px 10px;
    }

    .panel-left,
    .topbar-status-panel,
    .panel-center,
    .panel-right {
        order: initial;
        margin: 0;
    }

    .topbar-status-panel {
        margin-left: auto;
    }

    .panel-drawer {
        flex: 1 1 100%;
        width: 100%;
        padding: 8px 0 0;
        border-left: none;
        background: transparent;
        position: static;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 8px;
    }

    .control-group-label {
        display: none;
    }
}

/* Tablet / small laptop compaction. */
@media (max-width: 700px) {
    .topbar-brand {
        display: none;
    }

    .dev-identity-strip {
        max-width: 112px;
        padding: 0 8px;
    }

    .dev-identity-strip__label {
        display: none;
    }

    .topbar-panel {
        padding: 6px 10px;
        gap: 8px;
    }

    .panel-center {
        min-width: auto;
    }

    .musical-position-display {
        --musical-position-inline-size: calc(28ch + (var(--space-2) * 5) + (var(--space-3) * 2) + 22px);
        inline-size: min(100%, var(--musical-position-inline-size));
        flex: 0 1 auto;
        padding: 6px var(--space-3);
        font-size: var(--font-md);
    }

    .musical-position-display .pos-bar { inline-size: 7ch; }
    .musical-position-display .pos-beat { inline-size: 6ch; }
    .musical-position-display .pos-sixteenth { inline-size: 3ch; }

    .time-signature-display {
        margin-left: var(--space-1);
        inline-size: auto;
        min-width: 44px;
    }

    .loop-wrapper,
    .song-control-group,
    .loop-controls,
    .panel-right {
        flex-wrap: wrap;
        max-width: 100%;
        min-width: 0;
        row-gap: 6px;
    }

    .metronome-control-group {
        flex-wrap: wrap;
        row-gap: 4px;
    }

    .metronome-level {
        flex: 1 1 110px;
        width: auto;
        min-width: 88px;
    }
}

/* Phone layout: enforce tidy two-row header, then drawer controls. */
@media (max-width: 500px) {
    .topbar-panel {
        padding: 6px 8px;
        row-gap: 6px;
    }

    .topbar-primary-row {
        display: flex;
        width: 100%;
        flex-wrap: wrap;
        align-items: stretch;
        gap: 6px;
    }

    .panel-left,
    .topbar-status-panel,
    .panel-center,
    .panel-right {
        width: 100%;
        margin: 0;
    }

    .panel-left { justify-content: flex-start; }
    .panel-left { flex-wrap: wrap; }
    .topbar-status-panel { justify-content: center; }
    .panel-center { justify-content: center; }
    .panel-right { justify-content: flex-start; }

    .musical-position-display {
        inline-size: 100%;
        justify-content: center;
    }

    .control-group {
        padding: var(--space-1);
        gap: 6px;
    }

    .song-control-group .ui-select {
        max-width: none;
    }

    .song-instrument-select,
    .song-preset-select {
        flex: 1 1 120px;
        width: auto;
    }

    .panel-drawer {
        padding-top: 6px;
        gap: 6px;
    }

    .loop-wrapper {
        padding-left: 0;
        border-left: none;
    }
}

@keyframes slide-down {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 
 * LOOP CONTROLS 
 */
.loop-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding-left: var(--space-3);
    border-left: 1px solid var(--border-default);
    flex-wrap: wrap;
    max-width: 100%;
    min-width: 0;
}

.loop-bars-group {
    display: flex;
    gap: 2px;
}

.loop-bars-input {
    width: 4ch;
    text-align: center;
}

.loop-bar-btn {
    height: var(--control-h-sm);
    min-width: var(--control-h-sm);
    padding: 0 var(--space-1);
    font-size: var(--font-sm);
    border-radius: var(--radius-sm);
    border: none;
    background: var(--border-default);
    color: var(--text-2);
    cursor: pointer;
    transition: background var(--dur-base) var(--ease-out),
                color var(--dur-base) var(--ease-out);
    font-variant-numeric: tabular-nums;
}

.loop-bar-btn:hover {
    background: var(--border-strong);
    color: #fff;
}

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

.snap-segmented {
    display: flex;
    align-items: center;
    gap: 6px;
}

.snap-title {
    font-size: var(--font-xs);
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.snap-segment-track {
    display: inline-flex;
    align-items: center;
    padding: 2px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-default);
    background: rgba(255, 255, 255, 0.04);
}

.snap-segment-btn {
    height: 24px;
    min-width: 52px;
    border: none;
    border-radius: calc(var(--radius-pill) - 2px);
    background: transparent;
    color: var(--text-3);
    font-size: var(--font-xs);
    font-weight: 600;
    letter-spacing: 0.2px;
    cursor: pointer;
    transition: background var(--dur-base) var(--ease-out),
                color var(--dur-base) var(--ease-out);
}

.snap-segment-btn:hover {
    color: var(--text-2);
}

.snap-segment-btn.active {
    background: rgba(56, 145, 255, 0.28);
    color: #fff;
}

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

.snap-segmented.disabled {
    opacity: 0.55;
}

.snap-segment-btn.disabled {
    cursor: not-allowed;
}


/* 
 * PROGRESS BAR (Below Topbar)
 */
.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-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;
}

.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(40, 12, 16, 0.96) 0%,
        rgba(28, 10, 14, 0.96) 100%);
    border-top: 1px solid rgba(255, 70, 92, 0.35);
    border-bottom: 1px solid rgba(255, 70, 92, 0.35);
    overflow: hidden;
    contain: layout paint style;
    cursor: crosshair;
    box-shadow: inset 0 0 24px rgba(255, 70, 92, 0.18);
    isolation: isolate;
}

.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: 24px;
    background: linear-gradient(90deg,
        rgba(255, 70, 92, 0) 0%,
        rgba(255, 70, 92, 0.32) 70%,
        rgba(255, 70, 92, 0.55) 100%);
    pointer-events: none;
    z-index: 3;
    will-change: transform;
}

.sketch-progress-buffer__playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #ff4661;
    box-shadow: 0 0 10px rgba(255, 70, 92, 0.75);
    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__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__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;
}

.sketch-progress-buffer__drag-ghost {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(255, 70, 92, 0.25);
    border: 1px dashed rgba(255, 200, 210, 0.8);
    pointer-events: none;
    z-index: 6;
    will-change: transform, width;
}

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

.sketch-progress-buffer__ghost-meta {
    position: absolute;
    top: 4px;
    left: 6px;
    font-family: var(--font-mono);
    font-size: var(--font-xs);
    color: #ffd0d6;
    background: rgba(0, 0, 0, 0.35);
    padding: 1px 5px;
    border-radius: var(--radius-sm);
}

.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); }
}
