.timeline {
  grid-area: timeline;
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(244, 241, 235, 0.045), transparent 36px),
    color-mix(in srgb, var(--paper-raised) 94%, #000);
  border-top: 1px solid var(--line);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 -12px 32px rgba(0, 0, 0, 0.22);
}

.timeline-resize {
  position: absolute;
  left: 0;
  right: 0;
  top: -4px;
  height: 8px;
  cursor: ns-resize;
  z-index: 6;
}

.timeline-bar {
  height: 40px;
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 0 var(--s4);
  color: var(--ink-soft);
  font-size: var(--text-xs);
  font-weight: 600;
  border-bottom: 1px solid rgba(244, 241, 235, 0.06);
}

.timeline-bar .btn {
  height: 28px;
  padding: 0 10px;
  font-size: var(--text-xs);
}

#btn-snap {
  color: #C9A890;
  border-color: rgba(201, 168, 144, 0.24);
  background: linear-gradient(180deg, #2a2622 0%, #1e1b18 100%);
}

#btn-fit {
  color: #9BB8C9;
  border-color: rgba(155, 184, 201, 0.22);
  background: linear-gradient(180deg, #24282c 0%, #1a1d20 100%);
}

.timeline-bar .btn[aria-pressed="true"] {
  color: var(--on-accent);
  border-color: var(--btn-accent-edge);
  background: var(--btn-accent-face);
  box-shadow: var(--btn-accent-hilite), inset 0 0 0 1px rgba(212, 120, 74, 0.2);
}

.zoom-label {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-left: auto;
}

.zoom-label input { accent-color: var(--accent); width: 120px; }

.timeline-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(244, 241, 235, 0.28) transparent;
}

.timeline-canvas { position: relative; min-height: 100%; }

.ruler-row,
.track {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
}

.gutter,
.track-label {
  position: sticky;
  left: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--paper-raised) 88%, #000);
}

.track-label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding-left: 10px;
  padding-right: 4px;
  font-size: var(--text-xs);
  color: var(--ink-soft);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid rgba(244, 241, 235, 0.07);
}

.track-name {
  font-weight: 650;
  letter-spacing: 0.02em;
}

.track-resize {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -3px;
  height: 6px;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: ns-resize;
  z-index: 2;
}

.track-resize:hover,
.track-resize:focus-visible {
  background: rgba(196, 98, 45, 0.35);
}

.track-tools { display: flex; gap: 2px; }

.track-tools button {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-faint);
  display: grid;
  place-items: center;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

.track-tools button:hover {
  color: var(--ink-soft);
  background: rgba(244, 241, 235, 0.06);
  border-color: var(--btn-edge-soft);
}

.track-tools button:active {
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.35);
}

.track-tools button svg {
  width: 13px;
  height: 13px;
}

.track-tools button[aria-pressed="true"] {
  color: var(--accent);
  background: rgba(212, 120, 74, 0.16);
  border-color: rgba(212, 120, 74, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 210, 170, 0.1);
}

.track.is-locked .track-lane,
.track.is-hidden .track-lane { opacity: 0.45; }

.ruler {
  position: relative;
  height: 32px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  background: rgba(0, 0, 0, 0.12);
}

.tick {
  position: absolute;
  top: 0;
  height: 100%;
  transform: translateX(-0.5px);
}

.tick i {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 8px;
  background: rgba(244, 241, 235, 0.28);
}

.tick b {
  position: absolute;
  left: 6px;
  top: 8px;
  font-weight: 500;
  font-size: 11px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.track-lane {
  position: relative;
  height: 48px;
  border-bottom: 1px solid rgba(244, 241, 235, 0.07);
  background-color: rgba(0, 0, 0, 0.14);
  background-image: linear-gradient(to right, rgba(244, 241, 235, 0.045) 1px, transparent 1px);
  background-size: 80px 100%;
}

.track[data-track-row="audio"] .track-lane {
  background-image:
    linear-gradient(to right, rgba(244, 241, 235, 0.045) 1px, transparent 1px),
    linear-gradient(to bottom, transparent 49%, rgba(244, 241, 235, 0.07) 50%, transparent 51%);
}

.track-lane.is-drop { background-color: rgba(196, 98, 45, 0.1); }
.track-lane.is-reject { background-color: rgba(156, 59, 50, 0.1); }

.lane-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 0;
  pointer-events: none;
  color: var(--ink-faint);
  font-size: 11px;
  letter-spacing: 0.02em;
}

.lane-hint-icon {
  display: grid;
  place-items: center;
  opacity: 0.55;
  color: var(--ink-soft);
}

.clip {
  position: absolute;
  top: 8px;
  height: 36px;
  border-radius: 7px;
  border: 1px solid rgba(244, 241, 235, 0.16);
  color: #fbf9f6;
  display: flex;
  align-items: center;
  padding: 0 12px;
  overflow: visible;
  user-select: none;
  touch-action: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 40%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.12), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.1)),
    var(--clip-tone, #5c4a32);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 2px 6px rgba(0, 0, 0, 0.22);
  transition: box-shadow var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}

.clip:hover {
  border-color: rgba(244, 241, 235, 0.28);
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 6px 14px rgba(0, 0, 0, 0.28);
}

.clip-video {
  --clip-tone: #7a4e35;
}

.clip-image {
  --clip-tone: #3f5b4a;
}

.clip-audio {
  --clip-tone: #4e5f78;
}

.clip-text {
  --clip-tone: #6a5a48;
}

.clip.is-selected {
  border-color: rgba(251, 249, 246, 0.42);
  box-shadow:
    inset 0 0 0 1px rgba(251, 249, 246, 0.5),
    0 0 0 1px var(--accent),
    0 0 18px rgba(212, 120, 74, 0.22),
    0 6px 16px rgba(0, 0, 0, 0.32);
  z-index: 2;
  transform: none;
}

.clip-keys {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 1px;
  height: 12px;
  pointer-events: none;
  z-index: 3;
}

.clip-key {
  position: absolute;
  top: 1px;
  width: 9px;
  height: 9px;
  margin-left: -4.5px;
  border: 1px solid rgba(18, 17, 16, 0.55);
  border-radius: 1px;
  padding: 0;
  transform: rotate(45deg);
  pointer-events: auto;
  cursor: ew-resize;
  background: #fbf9f6;
}

.clip-key-x,
.clip-key-y { background: #6ec8ff; }
.clip-key-scale { background: #f0b429; }
.clip-key-rotation { background: #c792ea; }
.clip-key-opacity { background: #fbf9f6; }
.clip-key-volume { background: #7dcea0; }

.clip-key.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  z-index: 4;
}

.timeline.is-dragging .clip {
  box-shadow: none;
  transform: none;
  transition: none;
}

.clip.is-magnet { box-shadow: inset 0 0 0 1px var(--accent); }

.snap-guide {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 1px;
  background: var(--accent);
  opacity: 0.8;
  z-index: 3;
  pointer-events: none;
}

.snap-guide[hidden] { display: none; }

.clip-name {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  border-radius: inherit;
}

.clip-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
}

.clip-handle-end { right: 0; }
.clip-handle:not(.clip-handle-end) { left: 0; }

.clip-handle::after {
  content: "";
  position: absolute;
  top: 22%;
  bottom: 22%;
  width: 2px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.28);
  opacity: 0;
}

.clip-handle:not(.clip-handle-end)::after { left: 2px; }
.clip-handle-end::after { right: 2px; }
.clip:hover .clip-handle::after,
.clip.is-selected .clip-handle::after { opacity: 1; }

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  margin-left: -1px;
  background: linear-gradient(180deg, #f0a06e 0%, var(--accent) 18%, var(--accent-press) 100%);
  z-index: 4;
  pointer-events: none;
  box-shadow:
    0 0 0 1px rgba(196, 98, 45, 0.28),
    0 0 12px rgba(212, 120, 74, 0.35);
}

.playhead::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -6px;
  width: 14px;
  background: linear-gradient(90deg, transparent, rgba(212, 120, 74, 0.12), transparent);
  pointer-events: none;
}

.playhead-hit {
  position: absolute;
  top: 2px;
  left: -9px;
  width: 18px;
  height: 18px;
  border: 0;
  padding: 0;
  background: transparent;
  pointer-events: auto;
  cursor: ew-resize;
}

.playhead-hit::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 10px;
  height: 10px;
  background: linear-gradient(135deg, #f0a06e, var(--accent-press));
  border-radius: 2px;
  transform: rotate(45deg);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 1px 3px rgba(0, 0, 0, 0.4),
    0 0 10px rgba(212, 120, 74, 0.35);
}

@media (max-height: 700px) {
  .timeline-bar { height: 36px; }
}

html[data-theme="light"] .timeline {
  box-shadow: 0 -8px 20px rgba(28, 27, 25, 0.06);
}

html[data-theme="light"] .track-lane,
html[data-theme="light"] .ruler {
  background-color: rgba(28, 27, 25, 0.03);
}

html[data-theme="light"] .clip-name {
  text-shadow: none;
  color: #fff;
}
