/* Mode Toggle (Timeline/Keyframe) */
.mode-toggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.mode-btn {
  padding: 6px 12px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  transition: background 0.15s, color 0.15s;
}
.mode-btn:hover {
  background: rgba(255,255,255,0.05);
}
.mode-btn.active {
  background: rgba(120,180,255,0.15);
  color: var(--accent);
}

/* Keyframe Toggle Button (K) */
.keyframe-toggle {
  width: 20px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 4px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.keyframe-toggle:hover {
  background: rgba(255,255,255,0.08);
}
.keyframe-toggle.active {
  background: rgba(120,180,255,0.2);
  border-color: var(--accent);
  color: var(--accent);
}

/* Keyframe Editor View */
#keyframeViewport {
  --keyframe-sticky-header-height: 33px;
  position: relative;
  flex: 1 1 auto;
  overflow: auto;
  overscroll-behavior: contain;
  background: rgba(0,0,0,0.20);
}
#keyframeRulerCanvas {
  position: sticky;
  top: var(--keyframe-sticky-header-height);
  left: 0;
  z-index: 19;
  display: block;
  width: 100%;
  height: 28px;
  pointer-events: auto;
  background: #11141c;
}
#keyframeWaveCanvas {
  position: sticky;
  top: calc(var(--keyframe-sticky-header-height) + 28px);
  left: 0;
  z-index: 19;
  display: block;
  width: 100%;
  height: 50px;
  border-bottom: 1px solid var(--line2);
  cursor: pointer;
}
#keyframeTracksContainer {
  position: relative;
  min-height: 200px;
}
.keyframe-track {
  position: relative;
  height: 120px;
  border-bottom: 1px solid var(--line2);
  display: flex;
  transition: background 0.12s, box-shadow 0.12s;
}
.keyframe-track.selected {
  background: rgba(120,180,255,0.08);
  box-shadow: inset 0 0 0 1px rgba(120,180,255,0.35);
}
.keyframe-track.selected .keyframe-track-label {
  background: linear-gradient(180deg, rgba(120,180,255,0.15) 0%, rgba(120,180,255,0.08) 20%, rgba(120,180,255,0.05) 100%);
  color: var(--text);
}
.keyframe-track-label {
  position: sticky;
  left: 0;
  z-index: 7;
  width: 100px;
  box-sizing: border-box;
  padding: 6px 8px;
  font-size: 10px;
  color: var(--muted);
  background: linear-gradient(180deg, rgba(255,255,255,0.06) 0%, rgba(255,255,255,0.02) 20%, rgba(255,255,255,0.02) 100%);
  border-right: 1px solid var(--line2);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  overflow: hidden;
}
.keyframe-track-label:hover {
  background: linear-gradient(180deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.04) 20%, rgba(255,255,255,0.03) 100%);
}
.keyframe-track-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.keyframe-track-title-row {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.keyframe-track-title-row .keyframe-track-name {
  flex: 1;
  min-width: 0;
}
.keyframe-track-drag-handle {
  color: rgba(255,255,255,0.38);
  cursor: grab;
  flex: 0 0 auto;
  font-size: 13px;
  line-height: 1;
  user-select: none;
}
.keyframe-track-drag-handle:active {
  cursor: grabbing;
}
.keyframe-track.dragging {
  opacity: 0.45;
}
.keyframe-track.drop-before {
  box-shadow: inset 0 2px 0 var(--accent);
}
.keyframe-track.drop-after {
  box-shadow: inset 0 -2px 0 var(--accent);
}
.curve-type-buttons {
  display: flex;
  gap: 2px;
}
.curve-type-btn {
  width: 18px;
  height: 16px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  transition: all 0.15s;
}
.curve-type-btn:hover {
  background: rgba(255,255,255,0.1);
}
.curve-type-btn.active {
  background: rgba(120,180,255,0.25);
  border-color: var(--accent);
  color: var(--accent);
}
.track-delete-btn {
  width: 18px;
  height: 16px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: transparent;
  font-size: 10px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  opacity: 0.5;
  margin-left: 4px;
}
.track-delete-btn:hover {
  background: rgba(255,100,100,0.2);
  border-color: #f66;
  opacity: 1;
}

/* LFO Controls */
.lfo-btn {
  width: 24px;
  height: 16px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 8px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  transition: all 0.15s;
  margin-left: 2px;
}
.lfo-btn:hover {
  background: rgba(255,200,100,0.15);
}
.lfo-btn.active {
  background: rgba(255,180,50,0.3);
  border-color: var(--gold);
  color: var(--gold);
}
.lfo-controls {
  display: none;
  gap: 3px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.lfo-controls.visible {
  display: flex;
}
.lfo-controls select {
  height: 16px;
  padding: 0 2px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: rgba(0,0,0,0.3);
  color: var(--text);
  font-size: 8px;
  cursor: pointer;
}
.lfo-controls select:focus {
  outline: none;
  border-color: var(--gold);
}
.lfo-slider-wrap {
  display: flex;
  align-items: center;
  gap: 2px;
}
.lfo-slider-wrap label {
  font-size: 7px;
  color: var(--muted);
  min-width: 14px;
}
.lfo-slider-wrap input[type="range"] {
  width: 32px;
  height: 10px;
  -webkit-appearance: none;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  cursor: pointer;
}
.lfo-slider-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 8px;
  height: 10px;
  background: var(--gold);
  border-radius: 2px;
  cursor: pointer;
}

.keyframe-track-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0) 20%);
}
.keyframe-track-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.keyframe-diamond {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--accent);
  transform: rotate(45deg);
  cursor: pointer;
  z-index: 2;
  margin-left: -5px;
  margin-top: -5px;
}
.keyframe-diamond:hover {
  background: var(--gold);
}
.keyframe-diamond.selected {
  background: var(--gold);
  box-shadow: 0 0 6px var(--gold);
}
.keyframe-value-tooltip {
  position: fixed;
  z-index: 10020;
  padding: 4px 7px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 4px;
  background: rgba(8, 11, 19, 0.96);
  box-shadow: 0 5px 18px rgba(0,0,0,0.38);
  color: var(--text);
  font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%) translateY(-2px);
  transition: opacity 90ms ease, transform 90ms ease;
}
.keyframe-value-tooltip.visible {
  opacity: 1;
  transform: translate(-50%, -100%) translateY(-4px);
}
.keyframe-marquee {
  position: absolute;
  border: 1px solid var(--accent);
  background: rgba(120,180,255,0.15);
  pointer-events: none;
  z-index: 5;
}
#keyframeEmpty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 20px;
}
#keyframePlayhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--bad);
  pointer-events: none;
  z-index: 10;
  left: 100px;
}

/* Keyframe Editor Header */
#keyframeHeader {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--line2);
  position: sticky;
  top: 0;
  z-index: 20;
}
#keyframeHeader label {
  font-size: 10px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.kf-lane-hint {
  margin-left: auto;
  min-width: 0;
  overflow: hidden;
  color: rgba(255,255,255,0.42);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kf-snap-btn {
  height: 20px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.kf-snap-btn:hover {
  background: rgba(255,255,255,0.1);
}
.kf-snap-btn.active {
  background: rgba(120,180,255,0.25);
  border-color: var(--accent);
  color: var(--accent);
}
.kf-grid-select {
  height: 20px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-size: 10px;
  cursor: pointer;
}
.kf-grid-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Easing Context Menu */
.easing-menu {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 0;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.easing-option {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}
.easing-option:hover {
  background: rgba(120,180,255,0.15);
}
.easing-option.active {
  color: var(--accent);
}

#hud{
  display: none; /* Debug HUD - hidden in production */
  position:absolute;
  left:12px; bottom:12px;
  padding:10px 12px;
  border:1px solid var(--line);
  border-radius:14px;
  background: rgba(8,10,14,.45);
  backdrop-filter: blur(8px);
  color: rgba(255,255,255,.84);
  font-size:12px;
  line-height:1.25;
  white-space:pre;
  pointer-events:none;
}
#editor{
  flex: 1 1 auto;
  min-height: 340px;
  display:flex;
  flex-direction:column;
  background: linear-gradient(180deg, rgba(16,21,33,1), rgba(10,12,18,1));
  overflow: hidden;
  contain: strict;
  isolation: isolate;
}
#editorBar{
  display:flex;
  align-items:center;
  height: 52px;
  min-height: 52px;
  padding: 0 16px;
  box-sizing: border-box;
  border-bottom:1px solid var(--line);
  background: linear-gradient(rgba(255,255,255,.03), rgba(255,255,255,.03)), rgba(16,21,33,1);
  flex-shrink: 0;
}
#editorBar .editorbar-left{
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}
#editorBar .editorbar-center{
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
#editorBar .editorbar-right{
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: flex-end;
}
/* Add Assets dropdown */
.add-assets-menu{
  position: relative;
  display: inline-flex;
}
.add-assets-dropdown{
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 140px;
  display: none;
  z-index: 1000;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  padding: 6px 0;
}
.add-assets-menu.open .add-assets-dropdown{
  display: block;
}
.add-assets-item{
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 14px;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}
.add-assets-item:hover{
  background: rgba(255,255,255,.08);
}
.add-assets-item .icon{
  display: inline-block;
  width: 18px;
  text-align: center;
  opacity: 0.7;
}
/* Zoom control */
.zoom-control{
  display: flex;
  align-items: center;
  gap: 8px;
}
.zoom-icon{
  color: var(--muted);
}
.zoom-slider-wrapper{
  position: relative;
  width: 120px;
  height: 20px;
  display: flex;
  align-items: center;
}
.zoom-slider-wrapper input[type="range"]{
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  outline: none;
  margin: 0;
}
.zoom-slider-wrapper input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance: none;
  appearance: none;
  width: 36px;
  height: 18px;
  background: transparent;
  cursor: pointer;
  border: none;
}
.zoom-slider-wrapper input[type="range"]::-moz-range-thumb{
  width: 36px;
  height: 18px;
  background: transparent;
  cursor: pointer;
  border: none;
}
.zoom-thumb{
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(80,140,200,0.9);
  color: #fff;
  font-size: 9px;
  font-weight: 600;
  padding: 3px 6px;
  border-radius: 3px;
  pointer-events: none;
  white-space: nowrap;
  min-width: 36px;
  text-align: center;
  z-index: 1;
}
.zoom-slider-wrapper:hover .zoom-thumb{
  background: rgba(100,160,220,1);
}
label.small{display:flex;gap:8px;align-items:center;color:var(--muted);font-size:12px;}
input[type="range"]{width:140px;}
input[type="number"]{
  width:72px;
  padding:7px 8px;
  border-radius:10px;
  border:1px solid var(--line);
  background: rgba(255,255,255,.05);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}
input[type="checkbox"]{transform: translateY(1px);}
select{
  padding:7px 8px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,0.2);
  background: #1a1d24;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  max-width: 240px;
}
select option {
  background: #1a1d24;
  color: #e0e0e0;
}
#timelineViewport{
  --timeline-track-header-width: 188px;
  position:relative;
  flex: 1 1 auto;
  overflow-x: auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(0,0,0,.20);
}
#timelineContent{
  position:relative;
  min-height: 100%;
  overflow: visible;
}
#rulerCanvas{
  position:relative;
  display:block;
  margin-left: var(--timeline-track-header-width);
  pointer-events:auto;
  height:28px;
  will-change: transform;
}
#waveCanvas{
  display:block;
  width:100%;
  height:100%;
  pointer-events:auto;
  cursor: pointer;
}
#tracks{
  position:relative;
  min-height: 200px;
  overflow: visible;
}
.trackRow{
  position:relative;
  height: 80px;
  border-bottom: 1px solid var(--line2);
  overflow: hidden;
  contain: paint layout;
}
#tracks.loop-range-visible .track-content::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--timeline-loop-left, 0px);
  width: var(--timeline-loop-width, 0px);
  box-sizing: border-box;
  background: rgba(255, 160, 82, 0.055);
  border-left: 1px solid rgba(255, 174, 92, 0.16);
  border-right: 1px solid rgba(255, 174, 92, 0.16);
  box-shadow:
    inset 8px 0 14px -14px rgba(255, 176, 100, 0.34),
    inset -8px 0 14px -14px rgba(255, 176, 100, 0.34);
  pointer-events: none;
  z-index: 4;
}
.trackLabel{
  position:absolute;
  left:10px;
  top:8px;
  color: rgba(255,255,255,.5);
  font-size:11px;
  pointer-events:none;
  z-index: 5;
}
.seg{
  position:absolute;
  top: 4px;
  height: calc(100% - 8px);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 8px 20px rgba(0,0,0,.35);
  overflow:hidden;
  cursor: grab;
  contain: layout style;
}
.seg .title{
  position:absolute;
  left:8px; right:8px; top:6px;
  font-size:11px;
  color: rgba(0,0,0,.85);
  text-shadow: 0 1px 0 rgba(255,255,255,.18);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  pointer-events:none;
}
.seg .meta{
  position:absolute;
  left:8px; right:8px; bottom:6px;
  font-size:10px;
  color: rgba(0,0,0,.65);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  pointer-events:none;
}
.handle{
  position:absolute;
  top:0; bottom:0;
  width:8px;
  background: transparent;
  cursor: ew-resize;
}
.handle.left{left:0;}
.handle.right{right:0;}
.seg.selected{
  outline: 2px solid rgba(120,180,255,.9);
  outline-offset: 2px;
}
#playhead{
  position:absolute;
  left: var(--timeline-track-header-width);
  top:0;
  width:2px;
  height: 100%;
  background: rgba(255,255,255,.85);
  box-shadow: 0 0 0 1px rgba(0,0,0,.35), 0 0 18px rgba(120,180,255,.35);
  pointer-events:none;
  z-index: 100;
}
#wavePlayhead {
  display: none; /* Hidden - #playhead covers all tracks including audio */
}
#keyframeWavePlayhead {
  position: sticky;
  left: 100px;
  top: var(--keyframe-sticky-header-height);
  width: 2px;
  height: 78px; /* ruler (28px) + waveform (50px) */
  margin-top: -78px; /* Pull up to overlap ruler+wave */
  background: var(--bad);
  box-shadow: 0 0 0 1px rgba(0,0,0,.35), 0 0 12px rgba(255,100,100,.4);
  pointer-events: none;
  z-index: 50;
}
#inspector{
  flex: 0 0 auto;
  border-top:1px solid var(--line);
  background: rgba(255,255,255,.03);
  padding: 10px 12px;
  display:none;
  gap: 14px;
  align-items:center;
  flex-wrap:wrap;
}
#inspector.debug-visible{
  display:flex;
}
.kv{
  display:flex; flex-direction:column; gap:6px;
  color: var(--muted);
  font-size:12px;
}
.kv b{color:var(--text); font-size:12px;}
.warn{color: var(--bad);}
.ok{color: var(--good);}
#startOverlay{
  position:fixed;
  inset:0;
  display:grid;
  place-items:center;
  background: #000;
  z-index: 100;
}
#startBgCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 1;
  z-index: 0;
}
#startCard {
  z-index: 1;
}
#startCard{
  width: min(1200px, 92vw);
  position: relative;
  border-radius: 20px;
  padding: 1px;
  background: linear-gradient(135deg, 
    rgba(100,140,180,0.3) 0%, 
    rgba(60,80,120,0.15) 50%,
    rgba(100,140,180,0.2) 100%);
  box-shadow: 
    0 25px 80px rgba(0,0,0,.7),
    0 8px 32px rgba(0,0,0,.4);
}
#startCardInner{
  background: linear-gradient(145deg, 
    rgba(15,22,35,0.95) 0%,
    rgba(10,16,28,0.98) 100%);
  border-radius: 19px;
  padding: 16px;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 32px;
  overflow: hidden;
}
#startCard::before{
  content: '';
  position: absolute;
  inset: 1px;
  border-radius: 19px;
  background: linear-gradient(180deg, 
    rgba(255,255,255,0.03) 0%, 
    transparent 30%);
  pointer-events: none;
}
