/* --- 5. Timeline --- */
.timeline-panel {
    height: var(--timeline-h);
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    position: relative;
    flex: none;
    overflow: hidden;
    min-height: 0;
    border-top: 1px solid var(--border);
    z-index: 60;
}

/* CRITICAL FIX: Remove transition from timeline-panel to prevent drag lag */
/* No transition on resize */

.timeline-header {
    padding: 7px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 44px;
    flex: none;
    overflow-x: auto;
    background: var(--bg-panel-alt);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    position: sticky;
    top: 0;
    z-index: 20;
}
.timeline-header::-webkit-scrollbar { height: 0; }

.timeline-scroll-area {
    flex: 1;
    overflow-x: auto;
    overflow-y: auto;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    direction: ltr;
    touch-action: pan-x pan-y;
}
.timeline-scroll-area::-webkit-scrollbar { height: 8px; width: 8px; }
.timeline-scroll-area::-webkit-scrollbar-track { background: var(--bg-dark); }
.timeline-scroll-area::-webkit-scrollbar-thumb { background: #3a3d46; border-radius: 4px; }

.tracks-wrapper {
    position: relative;
    min-width: 100%;
    padding-bottom: 50px;
    padding-top: 25px;
}

.timeline-ruler-area {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 25px;
    background: var(--bg-panel-alt);
    border-bottom: 1px solid var(--border);
    z-index: 90;
    cursor: pointer;
}
.timeline-ruler-area:hover { background: var(--bg-hover); }
.timeline-range-overlay {
    position: absolute;
    top: 0;
    height: 100%;
    background: var(--range-color);
    border-left: 1px solid var(--success);
    border-right: 1px solid var(--success);
    pointer-events: auto;
    z-index: 80;
    cursor: grab;
    user-select: none;
}
.timeline-range-overlay:active { cursor: grabbing; }
.timeline-range-overlay .range-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 8px;
    background: rgba(48, 164, 108, 0.2);
    border-left: 1px solid var(--success);
    border-right: 1px solid var(--success);
    cursor: col-resize;
    z-index: 81;
    user-select: none;
}
.timeline-range-overlay .range-handle.left { left: -4px; }
.timeline-range-overlay .range-handle.right { right: -4px; }

.frames-track {
    display: flex;
    align-items: flex-start;
    padding: 10px 0 0 0;
    height: 85px;
    position: relative;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 5px;
}
.frame {
    height: 65px;
    background: #0c0c0f;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    cursor: pointer;
    color: #fff;
    position: relative;
    font-size: 10px;
    flex-shrink: 0;
    user-select: none;
    overflow: hidden;
    padding-right: 10px;
    transition: border-color 0.1s;
}
.frame:hover { border-color: #4a4d56; }
.frame.selected {
    outline: 2px solid rgba(139, 92, 246, 0.95);
    outline-offset: -1px;
    box-shadow: 0 0 0 1px rgba(139,92,246,0.25);
    z-index: 2;
}
.frame.active {
    border: 2px solid var(--accent);
    outline: 2px solid #818cf8;
    outline-offset: -1px;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.5);
    z-index: 3;
}
/* Inner color stripe - sits above frame background color */
.frame .frame-inner-stripe {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: transparent;
    border-radius: 0 0 3px 3px;
    pointer-events: none;
    z-index: 10;
    transition: background 0.15s;
}
.frame.selected .frame-inner-stripe,
.frame.active .frame-inner-stripe {
    box-shadow: 0 0 0 2px rgba(139,92,246,0.5) inset;
}

/* ═══════════════════════════════════════════════════════════════
   v313: Segment dividers inside extended / tweened frames.
   Rendered by _createFrameElement() as a single overlay <div>
   with repeating-linear-gradient. Pointer-events:none so clicks
   still hit the parent frame. Sits BELOW the tween-slider and
   the frame-handle but ABOVE the background image.
   ═══════════════════════════════════════════════════════════════ */
.frame-segment-dividers {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 2;
    /* actual gradient set inline per-frame in _createFrameElement */
}
.frame.active .frame-segment-dividers {
    filter: brightness(1.35);
}

/* v313: GPU-accelerated playhead (transform instead of left) */
.playhead-line {
    will-change: transform;
    backface-visibility: hidden;
}

.frame span {
    position: absolute;
    bottom: 2px;
    right: 12px;
    background: rgba(0, 0, 0, 0.65);
    padding: 0 3px;
    border-radius: 3px;
    pointer-events: none;
}
.frame .duration-badge {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 9px;
    background: rgba(0, 0, 0, 0.55);
    padding: 1px 3px;
    border-radius: 3px;
    color: #fff;
    pointer-events: none;
}

.frame-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 15px;
    z-index: 5;
    cursor: col-resize;
    opacity: 0;
    transition: opacity 0.15s;
}
.frame:hover .frame-handle {
    opacity: 1;
    background: rgba(255, 255, 255, 0.06);
}
.f-handle-right { right: 8px; }

.frame-tween-slider {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 12px;
    background: rgba(0, 0, 0, 0.5);
    border-left: 1px solid var(--border);
    z-index: 10;
    cursor: ns-resize;
}
.frame-tween-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--tween-color);
    pointer-events: none;
    transition: height 0.1s;
}
.frame-tween-slider:hover { background: rgba(0, 0, 0, 0.3); }

.generic-track {
    min-height: 40px;
    border-top: 1px solid var(--border);
    background: var(--bg-dark);
    position: relative;
    margin: 0;
    overflow: hidden;
    display: flex;
}
.audio-track { height: 60px; }
.audio-track.track-selected {
    background: linear-gradient(90deg, rgba(245, 158, 11, 0.14) 0%, rgba(245, 158, 11, 0.08) 100%);
    border-top-color: rgba(245, 158, 11, 0.55);
    box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.3);
}
.media-track {
    height: 45px;
    background: rgba(15, 17, 20, 0.8);
    border-bottom: 1px solid rgba(42, 45, 53, 0.5);
}

.track-content {
    position: relative;
    height: 100%;
    flex: 1;
}

.timeline-clip {
    position: absolute;
    top: 5px;
    height: calc(100% - 10px);
    border-radius: var(--radius-sm);
    cursor: move;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 10px;
    text-shadow: 0 0 2px #000;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    transition: border-color 0.15s;
}
.audio-clip {
    background: rgba(212, 160, 23, 0.3);
    border-color: var(--audio-bg);
}
.media-clip {
    background: rgba(217, 70, 168, 0.3);
    border-color: var(--media-bg);
    top: 4px;
    height: 36px;
}

/* Effect tracks */
.effect-track {
    height: 40px;
    background: rgba(15, 15, 30, 0.6);
    border-bottom: 1px solid rgba(42, 42, 58, 0.5);
}
.effect-clip {
    background: rgba(139, 92, 246, 0.2);
    border-color: rgba(139, 92, 246, 0.5);
    top: 4px;
    height: 32px;
}
.effect-clip:hover {
    background: rgba(139, 92, 246, 0.3);
}
.effect-clip.selected {
    border-color: #a78bfa;
    box-shadow: 0 0 6px rgba(139, 92, 246, 0.35);
    background: rgba(139, 92, 246, 0.35);
}

.timeline-clip.selected {
    border-color: #fff;
    box-shadow: 0 0 4px rgba(255, 255, 255, 0.3);
    z-index: 10;
}
.audio-clip.selected {
    border-color: #fff !important;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.45), 0 0 8px rgba(251, 191, 36, 0.45);
    outline: 1px solid rgba(255,255,255,0.35);
    z-index: 12;
}
.audio-clip.selected canvas {
    opacity: 0.95;
}
.audio-clip canvas {
    width: 100%;
    height: 100%;
    opacity: 0.7;
    box-shadow: none;
    pointer-events: none;
}
.audio-track-delete-empty {
    position: absolute;
    right: 6px;
    top: 6px;
    z-index: 15;
    border: 1px solid rgba(239, 68, 68, 0.45);
    background: rgba(25, 25, 25, 0.9);
    color: #fca5a5;
    font-size: 10px;
    line-height: 1.2;
    padding: 2px 6px;
    border-radius: 6px;
    cursor: pointer;
}
.audio-track-delete-empty:hover {
    background: rgba(127, 29, 29, 0.85);
    color: #fff;
}

.clip-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 15px;
    background: rgba(255, 255, 255, 0.05);
    cursor: ew-resize;
    z-index: 20;
}
.clip-handle:hover { background: rgba(255, 255, 255, 0.2); }
.handle-left { left: 0; }
.handle-right { right: 0; }
.clip-name {
    position: absolute;
    top: 2px;
    left: 14px;
    font-size: 9px;
    pointer-events: none;
    white-space: nowrap;
    max-width: calc(100% - 30px);
    overflow: hidden;
    text-overflow: ellipsis;
}

.audio-controls-panel {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-panel);
}
.audio-clip-properties { display: none; }
.audio-clip-properties.open { display: block; }

/* Camera Track Styles â†’ see "Camera Track Additional Styles" section below */
/* Effect Keyframe Dots (camera-like circular style, bottom-aligned inside clip) */
.effect-kf-dot {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #60a5fa;
    border: 2px solid #fff;
    bottom: 2px;
    top: auto;
    transform: translate(-50%, 0);
    cursor: pointer;
    z-index: 25;
    transition: transform 0.1s, background 0.1s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.effect-kf-dot:hover {
    background: #93c5fd;
    transform: translate(-50%, 0) scale(1.3);
}
.effect-kf-dot.selected {
    background: #fbbf24;
    width: 12px;
    height: 12px;
    border: 2px solid #fff;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
    transform: translate(-50%, 0) scale(1.4);
}

.camera-handle-dot {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fbbf24;
    border: 1px solid #fff;
    transform: translate(-50%, -50%);
    cursor: grab;
    z-index: 30;
    transition: background 0.1s;
}
.camera-handle-dot:hover {
    background: #f59e0b;
    box-shadow: 0 0 4px rgba(251, 191, 36, 0.7);
}
.camera-handle-dot:active {
    cursor: grabbing;
}
.camera-handle-line {
    position: absolute;
    height: 1px;
    background: rgba(251, 191, 36, 0.5);
    transform-origin: 0 50%;
    pointer-events: none;
    z-index: 24;
}

.playhead-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--danger);
    pointer-events: none;
    z-index: 100;
    display: block;
    left: 0;
    box-shadow: 0 0 4px rgba(229, 72, 77, 0.6);
}
.playhead-head {
    position: absolute;
    top: -5px;
    left: -6px;
    width: 14px;
    height: 14px;
    background: var(--danger);
    border-radius: 50%;
    cursor: ew-resize;
    pointer-events: auto;
}
.playhead-head:hover { transform: scale(1.15); }

/* --- 6. Resizers & Overlays --- */

/* CRITICAL FIX: Resizers must have NO transition for smooth dragging */
.resizer-v {
    width: 6px;
    background: var(--bg-dark);
    cursor: col-resize;
    z-index: 20;
    flex: none;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    /* NO transition here - prevents drag lag */
}
.resizer-h {
    height: 6px;
    background: var(--bg-dark);
    cursor: row-resize;
    z-index: 20;
    flex: none;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    /* NO transition here - prevents drag lag */
}
.resizer-v:hover, .resizer-h:hover, .resizer-active {
    background: var(--accent);
}

/* CRITICAL FIX: During active resize, disable ALL transitions */
body.resizing * {
    transition: none !important;
}
body.resizing .panel,
body.resizing .timeline-panel,
body.resizing .viewport {
    transition: none !important;
    will-change: auto !important;
}

.overlay-info {
    position: absolute;
    top: 15px;
    left: 15px;
    background: rgba(15, 17, 20, 0.8);
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    pointer-events: none;
    color: var(--text-main);
    font-size: 11px;
    border: 1px solid var(--border);
}

#loadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 17, 20, 0.92);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    backdrop-filter: blur(4px);
}

#exportCanvas {
    position: fixed;
    top: 0;
    left: 0;
    z-index: -100;
    opacity: 0;
    pointer-events: none;
}

.playback-controls {
    display: flex;
    gap: 5px;
    align-items: center;
}
.loop-checkbox {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 11px;
}

/* Performance Monitor - positioned below zoom % inside viewport */
#perfMonitor {
    position: absolute;
    top: 65px;
    left: 15px;
    background: rgba(15, 17, 20, 0.92);
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: var(--radius-md);
    color: var(--success);
    font-family: 'Consolas', 'Fira Code', monospace;
    font-size: 11px;
    z-index: 100;
    pointer-events: none;
    display: none;
    min-width: 120px;
}
#perfMonitor div {
    margin-bottom: 2px;
    display: flex;
    justify-content: space-between;
}
#perfMonitor span {
    color: var(--text-bright);
    font-weight: bold;
}

