/* ══════════════════════════════════════
   Timeline v3 — Tracks + Graph Editor
   ══════════════════════════════════════ */

#timeline {
  min-height: var(--timeline-min-height);
  max-height: 50vh;
  height: var(--timeline-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  flex-grow: 0;
  overflow: hidden;
}

/* ── Controls Bar ── */
#timeline-controls {
  height: 36px;
  display: flex;
  align-items: center;
  padding: 0 var(--space-lg);
  gap: var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-tertiary);
  flex-shrink: 0;
}

.tl-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.tl-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.tl-btn.active { color: var(--accent-primary); background: var(--accent-primary-glow); }

.tl-btn--play { width: 32px; height: 32px; color: var(--accent-primary); }
.tl-btn--play:hover { background: var(--accent-primary-glow); }
.tl-btn--play.playing { color: var(--accent-danger); }

.tl-time-display {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  padding: 0 var(--space-md);
  min-width: 120px;
}

.tl-time-display #tl-current-time { color: var(--text-primary); font-weight: 500; }
.tl-time-sep { color: var(--text-muted); margin: 0 2px; }

.tl-frame-display {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 2px;
}
.tl-frame-display input { width: 50px; font-size: var(--fs-xs); }
.tl-frame-sep { color: var(--text-muted); }

.tl-duration-selector, .tl-fps-selector {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.tl-fps-selector { margin-left: auto; }
.tl-duration-selector input { width: 45px; font-size: var(--fs-xs); text-align: center; }
.tl-fps-selector select { width: 55px; font-size: var(--fs-xs); }

/* ── Tracks Area ── */
#timeline-tracks {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  cursor: col-resize;
}

#timeline-ruler {
  height: 24px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 5;
}

#ruler-canvas { width: 100%; height: 100%; }

#timeline-playhead {
  position: absolute;
  top: 0;
  left: 100px;
  width: 2px;
  height: 100%;
  background: var(--playhead-color);
  z-index: 10;
  pointer-events: none;
}

#timeline-playhead::before {
  content: '';
  position: absolute;
  top: 0;
  left: -5px;
  width: 12px;
  height: 12px;
  background: var(--playhead-color);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

#timeline-keyframes { padding: 0; }

/* ── Track Group ── */
.track-group { border-bottom: 1px solid var(--border-subtle); }
.track-group.selected { background: rgba(124, 106, 246, 0.03); }

.track-group-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  height: 26px;
  padding: 0 var(--space-md);
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast);
}

.track-group-header:hover { background: var(--bg-hover); }

.track-group-header.selected {
  background: rgba(124, 106, 246, 0.12);
  border-left: 3px solid var(--accent-primary) !important;
}

.track-expand-btn { width: 16px; text-align: center; font-size: 8px; color: var(--text-muted); cursor: pointer; }
.track-group-icon { font-size: 12px; }
.track-group-name { font-size: var(--fs-sm); font-weight: 600; color: var(--text-primary); flex: 1; }
.track-group-count { font-size: var(--fs-xs); color: var(--text-muted); font-family: var(--font-mono); }

/* ── Individual Track ── */
.keyframe-track {
  display: flex;
  height: 22px;
  border-bottom: 1px solid rgba(30, 30, 48, 0.5);
  transition: background var(--transition-fast);
}

.keyframe-track:hover { background: rgba(255, 255, 255, 0.015); }

.keyframe-track.track-selected {
  background: rgba(124, 106, 246, 0.08);
}

.track-label-area {
  width: 100px;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 4px 0 20px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  flex-shrink: 0;
  cursor: pointer;
}

.track-label-area:hover { background: var(--bg-hover); }

.track-color-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }

.track-label {
  font-size: 10px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* Per-track keyframe toggle button */
.track-kf-btn {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-muted);
  border-radius: 2px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.track-kf-btn:hover {
  color: var(--keyframe-color);
  background: rgba(245, 166, 35, 0.15);
  transform: scale(1.2);
}

.track-bar-area {
  flex: 1;
  position: relative;
  background: var(--bg-primary);
}

.track-interp-range { position: absolute; top: 0; height: 100%; pointer-events: none; }

/* ── Keyframe Diamonds ── */
.keyframe-diamond {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  width: 8px;
  height: 8px;
  background: var(--kf-color, var(--keyframe-color));
  border-radius: 1px;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  z-index: 5;
}

.keyframe-diamond:hover {
  transform: translate(-50%, -50%) rotate(45deg) scale(1.4);
  box-shadow: 0 0 8px var(--kf-color, var(--keyframe-color));
}

.keyframe-diamond.selected {
  box-shadow: 0 0 0 2px white, 0 0 12px var(--kf-color, var(--keyframe-color));
}

/* ══════════════════════════════════════
   GRAPH EDITOR (Speed Editor)
   ══════════════════════════════════════ */

#graph-editor-container {
  border-top: 1px solid var(--border-bright);
  background: #0d0d14;
  display: flex;
  flex-direction: column;
  min-height: 130px;
  max-height: 200px;
  height: 160px;
  flex-shrink: 0;
  animation: slideUp 0.2s ease;
}

#graph-editor-container.hidden { display: none; }

#graph-editor-header {
  display: flex;
  align-items: center;
  padding: 4px var(--space-lg);
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-subtle);
  gap: var(--space-md);
  flex-shrink: 0;
}

.graph-title {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.graph-presets {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}

.graph-presets::-webkit-scrollbar { display: none; }

.graph-preset-btn {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.graph-preset-btn:hover {
  background: var(--accent-primary-glow);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.preset-icon { font-size: 12px; }
.preset-name { font-size: 9px; }

.graph-manual-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  margin-left: auto;
}

.graph-manual-btn:hover {
  border-color: var(--accent-warning);
  color: var(--accent-warning);
}

.graph-manual-btn.active {
  background: rgba(245, 166, 35, 0.15);
  border-color: var(--accent-warning);
  color: var(--accent-warning);
  box-shadow: 0 0 8px rgba(245, 166, 35, 0.2);
}

#graph-editor-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#graph-editor-sidebar {
  width: 120px;
  min-width: 120px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}

.ge-sidebar-group {
  border-bottom: 1px solid var(--border-subtle);
}

.ge-sidebar-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  cursor: pointer;
  user-select: none;
}

.ge-sidebar-header:hover { background: var(--bg-hover); }

.ge-sidebar-header .ge-icon { font-size: 10px; }

.ge-sidebar-track {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px 2px 16px;
  font-size: 9px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast);
  border-left: 3px solid transparent;
}

.ge-sidebar-track:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.ge-sidebar-track.active {
  background: rgba(124, 106, 246, 0.1);
  border-left-color: var(--accent-primary);
  color: var(--text-primary);
}

.ge-sidebar-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

#graph-editor-canvas {
  flex: 1;
  min-width: 0;
  cursor: crosshair;
}

/* ── Context Menu ── */
.kf-context-menu,
.map-context-menu {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  min-width: 200px;
  padding: var(--space-sm) 0;
  animation: fadeIn var(--transition-fast);
  max-height: 400px;
  overflow-y: auto;
}

.ctx-item {
  padding: 6px 14px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.ctx-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.ctx-item.active { color: var(--accent-primary); }
.ctx-delete:hover { background: rgba(231, 76, 60, 0.15); color: var(--accent-danger); }
.ctx-graph:hover { background: rgba(124, 106, 246, 0.15); color: var(--accent-primary); }

.ctx-divider { height: 1px; background: var(--border-subtle); margin: var(--space-sm) 0; }
.ctx-label { padding: 4px 14px; font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Marquee Selection ── */
.timeline-marquee {
  position: fixed;
  border: 1px solid var(--accent-primary);
  background: rgba(124, 106, 246, 0.12);
  pointer-events: none;
  z-index: 10000;
  border-radius: 2px;
  display: none;
}

/* ── Selected keyframes enhanced glow ── */
.keyframe-diamond.selected {
  box-shadow: 0 0 0 2px white, 0 0 14px var(--kf-color, var(--keyframe-color));
  transform: translate(-50%, -50%) rotate(45deg) scale(1.25);
}
