/* =============================================================================
   EARTHS Pro - Timeline v3 Styles
   After Effects-style timeline with tracks, clips, keyframes, and graph editor.
   Styles ONLY the inner elements built by renderer.js.
   Container (.timeline-panel) is styled in layout.css.
   ============================================================================= */

/* =============================================================================
   Timeline-Specific Variables
   ============================================================================= */
:root {
    --tl-track-height: 32px;
    --tl-prop-row-height: 22px;
    --tl-header-width: 200px;
    --tl-ruler-height: 24px;
    --tl-toolbar-height: 34px;

    /* Keyframe colors */
    --tl-kf-color: #00e5ff;
    --tl-kf-selected: #ffd740;
    --tl-kf-size: 9px;
    --tl-kf-prop-size: 7px;

    /* Playhead */
    --tl-playhead-color: #ff3d3d;
    --tl-playhead-width: 2px;

    /* Clip defaults */
    --tl-clip-radius: 4px;
    --tl-clip-min-opacity: 0.75;

    /* Track header background */
    --tl-header-bg: rgba(12, 12, 16, 0.92);
    --tl-header-bg-hover: rgba(20, 20, 26, 0.95);
    --tl-header-bg-selected: rgba(0, 229, 255, 0.08);
    --tl-header-border: rgba(255, 255, 255, 0.06);

    /* Lane background */
    --tl-lane-bg-even: rgba(255, 255, 255, 0.015);
    --tl-lane-bg-odd: transparent;
    --tl-lane-border: rgba(255, 255, 255, 0.04);

    /* Ruler */
    --tl-ruler-bg: rgba(10, 10, 14, 0.95);
    --tl-ruler-border: rgba(255, 255, 255, 0.08);
    --tl-ruler-tick-minor: rgba(255, 255, 255, 0.12);
    --tl-ruler-tick-major: rgba(255, 255, 255, 0.3);
    --tl-ruler-label: rgba(255, 255, 255, 0.45);

    /* Context menu */
    --tl-ctx-bg: rgba(18, 18, 24, 0.96);
    --tl-ctx-hover: rgba(255, 255, 255, 0.08);
    --tl-ctx-border: rgba(255, 255, 255, 0.1);

    /* Transitions */
    --tl-transition-fast: 0.1s ease;
    --tl-transition: 0.15s ease;
}


/* =============================================================================
   Resize Handle (top edge of timeline panel)
   ============================================================================= */
.tl-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: var(--resize-handle-size, 6px);
    cursor: ns-resize;
    background: transparent;
    z-index: 20;
    transition: background var(--tl-transition);
}

.tl-resize-handle:hover,
.tl-resize-handle.active {
    background: rgba(0, 229, 255, 0.35);
}


/* =============================================================================
   Toolbar
   ============================================================================= */
.tl-toolbar {
    display: flex;
    align-items: center;
    height: var(--tl-toolbar-height);
    min-height: var(--tl-toolbar-height);
    padding: 0 10px;
    gap: 6px;
    background: var(--tl-header-bg);
    border-bottom: 1px solid var(--tl-header-border);
    user-select: none;
    flex-shrink: 0;
    z-index: 5;
}


/* ---------------------------------------------------------------------------
   Toolbar Buttons (shared base)
   --------------------------------------------------------------------------- */
.tl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 24px;
    min-width: 24px;
    padding: 0 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    gap: 4px;
    transition: all var(--tl-transition);
    user-select: none;
}

.tl-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
}

.tl-btn:active {
    transform: scale(0.96);
    background: rgba(255, 255, 255, 0.14);
}

.tl-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* Small variant (zoom +/- / fit) */
.tl-btn.small {
    width: 22px;
    min-width: 22px;
    height: 22px;
    padding: 0;
    font-size: 12px;
    border-radius: 3px;
}

/* Danger variant (delete) */
.tl-btn.danger {
    color: var(--accent-danger);
    border-color: rgba(255, 85, 85, 0.2);
}

.tl-btn.danger:hover {
    background: rgba(255, 85, 85, 0.15);
    border-color: rgba(255, 85, 85, 0.35);
    color: #ff7777;
}

/* View toggle buttons */
.tl-btn.view {
    border-color: transparent;
    background: transparent;
    color: var(--text-muted);
    padding: 0 6px;
}

.tl-btn.view:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.06);
}

.tl-btn.view.active {
    color: var(--accent-primary);
    background: rgba(0, 229, 255, 0.1);
    border-color: rgba(0, 229, 255, 0.2);
}


/* ---------------------------------------------------------------------------
   Transport Controls
   --------------------------------------------------------------------------- */
.tl-transport {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-right: 10px;
    border-right: 1px solid var(--tl-header-border);
    margin-right: 4px;
}

.tl-time {
    font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
    font-size: 11px;
    color: var(--accent-primary);
    padding: 2px 8px;
    background: rgba(0, 229, 255, 0.06);
    border: 1px solid rgba(0, 229, 255, 0.12);
    border-radius: 3px;
    letter-spacing: 0.04em;
    min-width: 70px;
    text-align: center;
}

.tl-select {
    height: 22px;
    padding: 0 6px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color var(--tl-transition);
}

.tl-select:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

.tl-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px rgba(0, 229, 255, 0.15);
}

.tl-select option {
    background: #1a1a1e;
    color: #ffffff;
}


/* ---------------------------------------------------------------------------
   Zoom Controls
   --------------------------------------------------------------------------- */
.tl-zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 6px;
    border-right: 1px solid var(--tl-header-border);
    margin-right: 4px;
}

/* Range slider (zoom) */
.tl-zoom-controls input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 3px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.tl-zoom-controls input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-primary);
    border: none;
    cursor: pointer;
    box-shadow: 0 0 4px rgba(0, 229, 255, 0.4);
    transition: transform var(--tl-transition-fast);
}

.tl-zoom-controls input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.tl-zoom-controls input[type="range"]::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-primary);
    border: none;
    cursor: pointer;
    box-shadow: 0 0 4px rgba(0, 229, 255, 0.4);
}


/* ---------------------------------------------------------------------------
   View Toggle
   --------------------------------------------------------------------------- */
.tl-view-toggle {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 6px;
    border-right: 1px solid var(--tl-header-border);
    margin-right: 4px;
}


/* ---------------------------------------------------------------------------
   Work Area Controls
   --------------------------------------------------------------------------- */
.tl-work-area-controls {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 0 6px;
    border-left: 1px solid var(--tl-header-border);
    margin-left: 4px;
}

.tl-wa-range {
    font-size: 10px;
    color: var(--tl-accent);
    white-space: nowrap;
    min-width: 0;
    padding: 0 4px;
}

.tl-work-area-controls .tl-btn.small.active {
    background: var(--tl-accent);
    color: #000;
}

/* ---------------------------------------------------------------------------
   Spacer & Selection Info
   --------------------------------------------------------------------------- */
.tl-spacer {
    flex: 1;
}

.tl-selection-info {
    font-size: 10px;
    color: var(--text-muted);
    padding: 0 6px;
}


/* =============================================================================
   Body (Split Pane: Headers + Lanes)
   ============================================================================= */
.tl-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}


/* =============================================================================
   Track Headers (Left Pane)
   ============================================================================= */
.tl-track-headers {
    width: var(--tl-header-width);
    min-width: var(--tl-header-width);
    max-width: var(--tl-header-width);
    background: var(--tl-header-bg);
    border-right: 1px solid var(--panel-border);
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    z-index: 3;
    /* Reserve space at top matching ruler height */
    padding-top: var(--tl-ruler-height);
}

/* Hide scrollbar on headers (synced via JS) */
.tl-track-headers::-webkit-scrollbar {
    width: 0;
    display: none;
}

.tl-track-headers {
    scrollbar-width: none;  /* Firefox */
    -ms-overflow-style: none;
}


/* ---------------------------------------------------------------------------
   Individual Track Header
   --------------------------------------------------------------------------- */
.tl-track-header {
    display: flex;
    align-items: center;
    height: var(--tl-track-height);
    padding: 0 8px;
    gap: 6px;
    border-bottom: 1px solid var(--tl-lane-border);
    cursor: default;
    user-select: none;
    transition: background var(--tl-transition-fast);
}

.tl-track-header:hover {
    background: var(--tl-header-bg-hover);
}

.tl-track-header.selected {
    background: var(--tl-header-bg-selected);
    box-shadow: inset 3px 0 0 var(--accent-primary);
}

.tl-track-header.dragging {
    opacity: 0.5;
    background: rgba(0, 229, 255, 0.05);
}


/* Collapse arrow */
.tl-track-collapse {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    font-size: 8px;
    color: var(--text-muted);
    cursor: pointer;
    transition: transform var(--tl-transition), color var(--tl-transition);
    flex-shrink: 0;
}

.tl-track-collapse:hover {
    color: var(--text-secondary);
}

.tl-track-collapse.expanded {
    transform: rotate(90deg);
}

/* Track color indicator */
.tl-track-icon {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 4px currentColor;
}

/* Track name */
.tl-track-name {
    flex: 1;
    font-size: 11px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: var(--tl-track-height);
}

/* Track toggle buttons container */
.tl-track-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
    flex-shrink: 0;
}

/* V / L / S / M toggle buttons */
.tl-track-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: var(--text-muted);
    font-size: 9px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--tl-transition-fast);
}

.tl-track-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
}

/* Visibility off: dim/struck */
.tl-track-btn.off {
    color: rgba(255, 255, 255, 0.15);
}

/* Lock/Solo/Mute active */
.tl-track-btn.on {
    color: var(--accent-primary);
    background: rgba(0, 229, 255, 0.1);
}

/* Bigger track-row buttons (prev / next keyframe nav). The default
   .tl-track-btn is 18x18 (and the .tl-v2 .tl-track-actions .tl-action
   override even smaller at 16x16) which is too cramped for triangle
   glyphs. The compound selector below matches BOTH legacy and v2 paths
   so the bigger size always wins. */
.tl-track-btn.tl-track-btn-big,
.tl-v2 .tl-track-actions .tl-action.tl-track-btn-big {
    width: 28px;
    height: 22px;
    font-size: 14px;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    margin: 0 1px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tl-track-btn.tl-track-btn-big:hover,
.tl-v2 .tl-track-actions .tl-action.tl-track-btn-big:hover {
    background: rgba(0, 229, 255, 0.22);
    color: var(--accent-primary);
}
.tl-track-btn.tl-track-btn-big:active,
.tl-v2 .tl-track-actions .tl-action.tl-track-btn-big:active {
    background: rgba(0, 229, 255, 0.38);
}


/* ---------------------------------------------------------------------------
   Property Sub-Header (expanded track)
   --------------------------------------------------------------------------- */
.tl-property-header {
    display: flex;
    align-items: center;
    height: var(--tl-prop-row-height);
    padding: 0 8px;
    border-bottom: 1px solid var(--tl-lane-border);
    background: rgba(0, 0, 0, 0.15);
}

.tl-prop-indent {
    width: 28px;
    flex-shrink: 0;
}

.tl-prop-name {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* =============================================================================
   Lanes Wrapper (Right Pane - Scrollable)
   ============================================================================= */
.tl-lanes-wrapper {
    flex: 1;
    overflow: auto;
    position: relative;
    min-width: 0;
}

/* Scrollbar styling */
.tl-lanes-wrapper::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.tl-lanes-wrapper::-webkit-scrollbar-track {
    background: transparent;
}

.tl-lanes-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.tl-lanes-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

.tl-lanes-wrapper::-webkit-scrollbar-corner {
    background: transparent;
}


/* =============================================================================
   Time Ruler
   ============================================================================= */
.tl-ruler {
    position: sticky;
    top: 0;
    height: var(--tl-ruler-height);
    min-height: var(--tl-ruler-height);
    background: var(--tl-ruler-bg);
    border-bottom: 1px solid var(--tl-ruler-border);
    z-index: 4;
    display: flex;
    align-items: flex-end;
    user-select: none;
    cursor: pointer;
    overflow: hidden;
}

/* Tick marks */
.tl-ruler-tick {
    position: absolute;
    bottom: 0;
    width: 1px;
}

.tl-ruler-tick.minor {
    height: 6px;
    background: var(--tl-ruler-tick-minor);
}

.tl-ruler-tick.major {
    height: 12px;
    background: var(--tl-ruler-tick-major);
}

/* Time label on major ticks */
.tl-ruler-label {
    position: absolute;
    bottom: 13px;
    left: 3px;
    font-size: 9px;
    font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
    color: var(--tl-ruler-label);
    white-space: nowrap;
    pointer-events: none;
}


/* =============================================================================
   Track Lanes (Clip & Keyframe Area)
   ============================================================================= */
.tl-track-lanes {
    position: relative;
    min-height: 100%;
}


/* ---------------------------------------------------------------------------
   Individual Track Lane
   --------------------------------------------------------------------------- */
.tl-track-lane {
    position: relative;
    height: var(--tl-track-height);
    border-bottom: 1px solid var(--tl-lane-border);
    box-sizing: border-box;
}

.tl-track-lane:nth-child(even) {
    background: var(--tl-lane-bg-even);
}

.tl-track-lane:nth-child(odd) {
    background: var(--tl-lane-bg-odd);
}


/* ---------------------------------------------------------------------------
   Property Sub-Lane
   --------------------------------------------------------------------------- */
.tl-prop-lane {
    position: relative;
    height: var(--tl-prop-row-height);
    border-bottom: 1px solid var(--tl-lane-border);
    background: rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
}


/* =============================================================================
   Playhead
   ============================================================================= */
.tl-playhead-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: var(--tl-playhead-width);
    background: var(--tl-playhead-color);
    z-index: 10;
    pointer-events: none;
    box-shadow: 0 0 6px rgba(255, 61, 61, 0.5),
                0 0 12px rgba(255, 61, 61, 0.2);
}

/* Playhead top marker (triangle) */
.tl-playhead-line::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--tl-playhead-color);
    filter: drop-shadow(0 0 3px rgba(255, 61, 61, 0.6));
}


/* =============================================================================
   Clips
   ============================================================================= */
.tl-clip {
    position: absolute;
    top: 3px;
    height: calc(var(--tl-track-height) - 6px);
    border-radius: var(--tl-clip-radius);
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    overflow: hidden;
    transition: filter var(--tl-transition-fast),
                box-shadow var(--tl-transition-fast);
    /* Default color - overridden inline per track */
    background: linear-gradient(
        180deg,
        rgba(60, 140, 200, 0.85) 0%,
        rgba(40, 100, 160, 0.7) 100%
    );
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.tl-clip:hover,
.tl-clip.hovered {
    filter: brightness(1.15);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4),
                0 0 8px rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

.tl-clip:active {
    filter: brightness(1.05);
}

/* Clip label */
.tl-clip-label {
    padding: 0 8px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    z-index: 1;
}


/* ---------------------------------------------------------------------------
   Trim Handles
   --------------------------------------------------------------------------- */
.tl-clip-trim-handle {
    position: absolute;
    top: 0;
    width: 6px;
    height: 100%;
    cursor: ew-resize;
    background: transparent;
    z-index: 2;
    transition: background var(--tl-transition-fast);
}

.tl-clip-trim-handle.left {
    left: 0;
    border-radius: var(--tl-clip-radius) 0 0 var(--tl-clip-radius);
}

.tl-clip-trim-handle.right {
    right: 0;
    border-radius: 0 var(--tl-clip-radius) var(--tl-clip-radius) 0;
}

.tl-clip:hover .tl-clip-trim-handle,
.tl-clip.hovered .tl-clip-trim-handle {
    background: rgba(255, 255, 255, 0.15);
}

.tl-clip-trim-handle:hover {
    background: rgba(255, 255, 255, 0.3) !important;
}


/* ---------------------------------------------------------------------------
   Transition Overlays (fade in/out)
   --------------------------------------------------------------------------- */
.tl-transition-in,
.tl-transition-out {
    position: absolute;
    top: 0;
    width: 20px;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.tl-transition-in {
    left: 0;
    background: linear-gradient(
        90deg,
        rgba(0, 0, 0, 0.4) 0%,
        transparent 100%
    );
    border-radius: var(--tl-clip-radius) 0 0 var(--tl-clip-radius);
}

.tl-transition-out {
    right: 0;
    background: linear-gradient(
        270deg,
        rgba(0, 0, 0, 0.4) 0%,
        transparent 100%
    );
    border-radius: 0 var(--tl-clip-radius) var(--tl-clip-radius) 0;
}


/* =============================================================================
   Keyframes
   ============================================================================= */

/* Container for keyframes within a clip */
.tl-clip-keyframes {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 3;
}

/* Diamond keyframe marker */
.tl-kf {
    position: absolute;
    width: var(--tl-kf-size);
    height: var(--tl-kf-size);
    background: var(--tl-kf-color);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transform: rotate(45deg);
    top: 50%;
    margin-top: calc(var(--tl-kf-size) / -2);
    margin-left: calc(var(--tl-kf-size) / -2);
    cursor: pointer;
    pointer-events: all;
    z-index: 5;
    transition: background var(--tl-transition-fast),
                border-color var(--tl-transition-fast),
                box-shadow var(--tl-transition-fast),
                transform var(--tl-transition-fast);
    box-shadow: 0 0 3px rgba(0, 229, 255, 0.4);
}

.tl-kf:hover {
    transform: rotate(45deg) scale(1.25);
    box-shadow: 0 0 6px rgba(0, 229, 255, 0.6);
    border-color: rgba(255, 255, 255, 0.5);
}

.tl-kf.selected {
    background: var(--tl-kf-selected);
    border-color: rgba(255, 215, 64, 0.7);
    box-shadow: 0 0 6px rgba(255, 215, 64, 0.5),
                0 0 12px rgba(255, 215, 64, 0.2);
}

.tl-kf.selected:hover {
    box-shadow: 0 0 8px rgba(255, 215, 64, 0.7),
                0 0 16px rgba(255, 215, 64, 0.3);
}

/* Property-level keyframe (smaller) */
.tl-kf.prop {
    width: var(--tl-kf-prop-size);
    height: var(--tl-kf-prop-size);
    margin-top: calc(var(--tl-kf-prop-size) / -2);
    margin-left: calc(var(--tl-kf-prop-size) / -2);
    background: var(--tl-kf-color);
    opacity: 0.8;
}

.tl-kf.prop:hover {
    opacity: 1;
}

.tl-kf.prop.selected {
    background: var(--tl-kf-selected);
    opacity: 1;
}


/* =============================================================================
   Work Area Overlay
   ============================================================================= */
.tl-work-area {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(0, 229, 255, 0.03);
    border-left: 1px solid rgba(0, 229, 255, 0.15);
    border-right: 1px solid rgba(0, 229, 255, 0.15);
    pointer-events: none;
    z-index: 1;
}


/* =============================================================================
   Reorder Indicator
   ============================================================================= */
.tl-reorder-indicator {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-primary);
    box-shadow: 0 0 6px var(--accent-primary);
    z-index: 20;
    pointer-events: none;
}


/* =============================================================================
   Context Menu
   ============================================================================= */
.tl-context-menu {
    position: fixed;
    min-width: 160px;
    /* No overflow clamp on the main menu: setting overflow-y:auto would clip
       the absolutely-positioned submenu children (because overflow-x gets
       promoted from visible to auto implicitly). Submenus do their own
       viewport-scroll via .tl-context-submenu. */
    padding: 4px 0;
    background: var(--tl-ctx-bg);
    border: 1px solid var(--tl-ctx-border);
    border-radius: 6px;
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5),
                0 0 1px rgba(255, 255, 255, 0.1);
    z-index: 10000;
    user-select: none;
    animation: tl-ctx-appear 0.1s ease-out;
}

/* Submenus (e.g. the 36-preset Easing list on a keyframe right-click).
   Positioned absolutely relative to the fixed parent menu. Bounded to the
   viewport and scrollable so the list can never disappear into the taskbar. */
.tl-context-submenu {
    position: absolute;
    min-width: 180px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 0;
    background: var(--tl-ctx-bg);
    border: 1px solid var(--tl-ctx-border);
    border-radius: 6px;
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5),
                0 0 1px rgba(255, 255, 255, 0.1);
    z-index: 10001;
    user-select: none;
    animation: tl-ctx-appear 0.1s ease-out;
}

/* Custom thin scrollbars for both menu and submenu so long easing lists look
   native on Windows / macOS. */
.tl-context-menu::-webkit-scrollbar,
.tl-context-submenu::-webkit-scrollbar {
    width: 8px;
}
.tl-context-menu::-webkit-scrollbar-thumb,
.tl-context-submenu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}
.tl-context-menu::-webkit-scrollbar-thumb:hover,
.tl-context-submenu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}
.tl-context-menu::-webkit-scrollbar-track,
.tl-context-submenu::-webkit-scrollbar-track {
    background: transparent;
}

/* Arrow indicator on parent items that open a submenu */
.tl-context-item.has-submenu {
    position: relative;
}

@keyframes tl-ctx-appear {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(-4px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.tl-context-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--tl-transition-fast),
                color var(--tl-transition-fast);
    white-space: nowrap;
}

.tl-context-item:hover {
    background: var(--tl-ctx-hover);
    color: var(--text-primary);
}

.tl-context-item:active {
    background: rgba(255, 255, 255, 0.12);
}

/* Keyboard shortcut hint on the right */
.tl-context-item .shortcut {
    margin-left: auto;
    font-size: 10px;
    color: var(--text-muted);
    padding-left: 20px;
}

.tl-context-separator {
    height: 1px;
    margin: 4px 8px;
    background: var(--tl-ctx-border);
    border: none;
}


/* =============================================================================
   Graph Editor
   ============================================================================= */
.tl-graph-editor {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: rgba(8, 8, 12, 0.6);
    border-top: 1px solid var(--tl-header-border);
    /* Vertical flex so the toolbar sits on top and canvas fills the rest */
    display: flex;
    flex-direction: column;
}

.tl-graph-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    padding: 4px 10px;
    height: 32px;
    background: rgba(20, 20, 26, 0.6);
    border-bottom: 1px solid var(--tl-header-border);
    font-size: 11px;
    color: var(--text-secondary);
    user-select: none;
}

.tl-graph-toolbar label {
    color: var(--text-muted);
    font-size: 11px;
    margin-right: 2px;
}

.tl-graph-toolbar select {
    height: 22px;
    padding: 0 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 11px;
    cursor: pointer;
    outline: none;
    min-width: 120px;
}

.tl-graph-toolbar select:hover {
    background: rgba(255, 255, 255, 0.1);
}

.tl-graph-toolbar select:focus {
    border-color: var(--accent-primary);
}

.tl-graph-toolbar .tl-graph-toolbar-hint {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 10px;
    font-style: italic;
    opacity: 0.8;
}

.tl-graph-canvas-wrap {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.tl-graph-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}


/* =============================================================================
   Global User-Select & Drag Prevention
   ============================================================================= */
.tl-toolbar,
.tl-track-headers,
.tl-ruler,
.tl-track-lanes {
    -webkit-user-select: none;
    user-select: none;
}

.tl-track-lanes img,
.tl-track-headers img {
    -webkit-user-drag: none;
    user-drag: none;
    pointer-events: none;
}


/* =============================================================================
   Responsive Adjustments
   ============================================================================= */
@media (max-width: 768px) {
    :root {
        --tl-header-width: 140px;
        --tl-toolbar-height: 30px;
    }

    .tl-toolbar {
        gap: 4px;
        padding: 0 6px;
    }

    .tl-btn {
        height: 22px;
        padding: 0 5px;
        font-size: 10px;
    }

    .tl-btn.small {
        width: 20px;
        min-width: 20px;
        height: 20px;
    }

    .tl-time {
        min-width: 60px;
        font-size: 10px;
    }

    .tl-zoom-controls input[type="range"] {
        width: 50px;
    }

    .tl-track-name {
        font-size: 10px;
    }

    .tl-clip-label {
        font-size: 9px;
    }
}

/* =====================================================================
 * TIMELINE V2 — New pro palette for Task 12 renderer rewrite
 * These rules are scoped to #timeline-panel.tl-v2 so they coexist with
 * the legacy rules above until the renderer rewrite lands in Task 12.
 * ===================================================================== */

:root {
    /* Dimensions */
    --tl-toolbar-height: 44px;
    --tl-ruler-height: 30px;
    --tl-folder-row-height: 30px;
    --tl-track-height: 40px;
    --tl-track-pinned-height: 44px;
    --tl-prop-row-height: 26px;
    --tl-header-width: 240px;
    --tl-search-height: 28px;
    --tl-color-bar-width: 4px;

    /* Palette */
    --tl-bg-panel: #0b0b11;
    --tl-bg-header: #15151d;
    --tl-bg-header-hover: #1d1d27;
    --tl-bg-header-selected: #00e5ff14;
    --tl-bg-folder: #11111a;
    --tl-bg-lane-even: #0e0e14;
    --tl-bg-lane-odd: #0b0b11;
    --tl-grid: #222230;
    --tl-text-primary: #e6e6f0;
    --tl-text-secondary: #7f7f8e;
    --tl-text-disabled: #4a4a56;
    --tl-accent: #00e5ff;
    --tl-playhead: #ff3d55;
    --tl-kf-selected: #ffd740;
    --tl-rec: #ff1744;
    --tl-rec-glow: rgba(255,23,68,0.35);
}

#timeline-panel.tl-v2 {
    background: var(--tl-bg-panel);
    color: var(--tl-text-primary);
    display: flex;
    flex-direction: column;
}

.tl-v2 .tl-toolbar {
    height: var(--tl-toolbar-height);
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: var(--tl-bg-header);
    border-bottom: 1px solid var(--tl-grid);
    gap: 16px;
}

.tl-v2 .tl-toolbar-left,
.tl-v2 .tl-toolbar-center,
.tl-v2 .tl-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tl-v2 .tl-toolbar-center {
    flex: 1;
    justify-content: center;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    color: var(--tl-text-secondary);
}

.tl-v2 .tl-rec-button {
    width: 34px; height: 34px;
    border-radius: 50%;
    border: 2px solid var(--tl-text-secondary);
    background: transparent;
    color: var(--tl-text-secondary);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px;
    transition: all 150ms ease;
}
.tl-v2 .tl-rec-button.armed {
    background: var(--tl-rec);
    border-color: var(--tl-rec);
    color: white;
    box-shadow: 0 0 14px var(--tl-rec-glow);
}
.tl-v2 .tl-rec-button:hover { transform: scale(1.05); }

.tl-v2 .tl-undo-btn, .tl-v2 .tl-redo-btn {
    width: 30px; height: 30px;
    border: 1px solid var(--tl-grid);
    background: transparent;
    color: var(--tl-text-primary);
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
}
.tl-v2 .tl-undo-btn:disabled, .tl-v2 .tl-redo-btn:disabled {
    color: var(--tl-text-disabled);
    cursor: default;
    opacity: 0.5;
}

.tl-v2 .tl-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.tl-v2 .tl-header-panel {
    width: var(--tl-header-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--tl-grid);
    background: var(--tl-bg-panel);
}

.tl-v2 .tl-search {
    height: var(--tl-search-height);
    padding: 4px 8px;
    border-bottom: 1px solid var(--tl-grid);
}
.tl-v2 .tl-search input {
    width: 100%; height: 100%;
    background: var(--tl-bg-header);
    border: 1px solid var(--tl-grid);
    color: var(--tl-text-primary);
    padding: 0 8px;
    font-size: 11px;
    border-radius: 3px;
}

.tl-v2 .tl-header-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.tl-v2 .tl-folder {
    background: var(--tl-bg-folder);
}
.tl-v2 .tl-folder-header {
    height: var(--tl-folder-row-height);
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 10px;
    color: var(--tl-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    user-select: none;
    transition: background 150ms ease;
}
.tl-v2 .tl-folder-header:hover { background: var(--tl-bg-header-hover); }
.tl-v2 .tl-folder-caret { display: inline-block; width: 12px; transition: transform 150ms ease; }
.tl-v2 .tl-folder.tl-collapsed .tl-folder-body { display: none; }
.tl-v2 .tl-folder.tl-collapsed .tl-folder-caret { transform: rotate(-90deg); }

/* hq98: "MAP LABELS" super-group — a heavier tier above the per-type folders.
   A left accent bar + tinted header visually segregate the editable map
   furniture from the user's content tracks. */
.tl-v2 .tl-group {
    background: var(--tl-bg-folder);
    border-top: 1px solid rgba(38, 166, 154, 0.35);
    box-shadow: inset 2px 0 0 0 rgba(38, 166, 154, 0.55);
}
.tl-v2 .tl-group-header {
    height: 32px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 10px;
    font-weight: 600;
    color: #7fd6cc;
    background: rgba(38, 166, 154, 0.10);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    user-select: none;
    transition: background 150ms ease;
}
.tl-v2 .tl-group-header:hover { background: rgba(38, 166, 154, 0.18); }
.tl-v2 .tl-group.tl-collapsed .tl-group-body { display: none; }
.tl-v2 .tl-group.tl-collapsed .tl-folder-caret { transform: rotate(-90deg); }

.tl-v2 .tl-track-header {
    height: var(--tl-track-height);
    display: flex;
    align-items: center;
    padding: 0 8px 0 0;
    background: var(--tl-bg-header);
    border-bottom: 1px solid var(--tl-grid);
    position: relative;
    cursor: pointer;
}
.tl-v2 .tl-track-header:hover { background: var(--tl-bg-header-hover); }
.tl-v2 .tl-track-header.selected { background: var(--tl-bg-header-selected); }

.tl-v2 .tl-color-bar {
    width: var(--tl-color-bar-width);
    height: 100%;
    margin-right: 6px;
}
.tl-v2 .tl-caret { width: 14px; color: var(--tl-text-secondary); font-size: 10px; }
.tl-v2 .tl-type-icon { margin: 0 6px; font-size: 13px; }
.tl-v2 .tl-track-name { flex: 1; font-size: 12px; color: var(--tl-text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-v2 .tl-track-actions { display: flex; gap: 4px; }
.tl-v2 .tl-track-actions .tl-action {
    width: 16px; height: 16px; font-size: 11px;
    color: var(--tl-text-secondary); cursor: pointer;
    background: transparent; border: none;
}
.tl-v2 .tl-track-actions .tl-action.on { color: var(--tl-accent); }

.tl-v2 .tl-prop-row {
    height: var(--tl-prop-row-height);
    display: flex;
    align-items: center;
    padding: 0 8px 0 36px;
    background: var(--tl-bg-folder);
    font-size: 10px;
    color: var(--tl-text-secondary);
    border-bottom: 1px solid var(--tl-grid);
}
.tl-v2 .tl-stopwatch {
    display: inline-block;
    width: 14px; height: 14px;
    line-height: 14px;
    text-align: center;
    color: var(--tl-text-secondary);
    cursor: pointer;
    font-size: 12px;
    margin-right: 6px;
}
.tl-v2 .tl-stopwatch.on { color: var(--tl-accent); }
.tl-v2 .tl-prop-row .tl-prop-name { flex: 1; }
.tl-v2 .tl-prop-row .tl-prop-value {
    font-variant-numeric: tabular-nums;
    color: var(--tl-text-primary);
}

.tl-v2 .tl-lanes-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.tl-v2 .tl-ruler {
    height: var(--tl-ruler-height);
    background: var(--tl-bg-header);
    border-bottom: 1px solid var(--tl-grid);
    position: relative;
}
.tl-v2 .tl-lanes-scroll {
    flex: 1; position: relative;
    overflow: auto;
}
.tl-v2 .tl-lane {
    height: var(--tl-track-height);
    border-bottom: 1px solid var(--tl-grid);
    position: relative;
}
.tl-v2 .tl-lane:nth-child(even) { background: var(--tl-bg-lane-even); }
.tl-v2 .tl-lane:nth-child(odd)  { background: var(--tl-bg-lane-odd); }

.tl-v2 .tl-clip {
    position: absolute;
    top: 4px; bottom: 4px;
    border-radius: 6px;
    background: linear-gradient(to bottom, currentColor, currentColor);
    opacity: 0.85;
    border-top: 1px solid rgba(255,255,255,0.18);
    cursor: grab;
    overflow: hidden;
}
.tl-v2 .tl-clip-name {
    padding: 2px 6px;
    font-size: 10px;
    color: white;
    text-shadow: 0 1px 1px rgba(0,0,0,0.4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tl-v2 .tl-playhead-line {
    position: absolute;
    top: 0; bottom: 0;
    width: 1px;
    background: var(--tl-playhead);
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 0 3px var(--tl-playhead);
}
.tl-v2.tl-rec-armed .tl-playhead-line {
    box-shadow: 0 0 10px var(--tl-rec-glow), 0 0 3px var(--tl-rec);
}
