:root {
  --bg: #0b0c10;
  --panel: #14161c;
  --panel-2: #1b1e27;
  --line: #262a35;
  --text: #f2f4f8;
  --muted: #8b93a7;
  --accent: #ff4d67;
  --accent-2: #7c5cff;
  --radius: 16px;
  --tg-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--tg-font);
  overscroll-behavior: none;
}

body { touch-action: manipulation; }

#app {
  display: flex;
  flex-direction: column;
  height: var(--tg-height, 100vh);
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: relative;
  flex: 0 0 auto;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--tg-top, 0px) + 8px) 12px 8px 12px;
  background: linear-gradient(180deg, rgba(11,12,16,.96), rgba(11,12,16,.78));
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.title-wrap { flex: 1; min-width: 0; }
.title { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { font-size: 11px; color: var(--muted); margin-top: 2px; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
}
.icon-btn.small { width: 30px; height: 30px; font-size: 13px; border-radius: 9px; }
.icon-btn:active { transform: scale(.96); }

/* -------------------------------------------------------------------- stage */

.stage-wrap {
  flex: 1 1 auto;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px 6px;
}

.stage {
  position: relative;
  height: 100%;
  width: 100%;
  max-height: 100%;
  margin: 0 auto;
  background: #000 center/contain no-repeat;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.stage.landscape { aspect-ratio: 16 / 9; }
.stage.square { aspect-ratio: 1 / 1; }
.stage.portrait45 { aspect-ratio: 4 / 5; }
.stage.portrait { aspect-ratio: 9 / 16; }

.stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  opacity: 1;
  transition: opacity .12s linear;
}
.stage video.blurred { object-fit: contain; filter: none; }
.stage .blur-bg {
  position: absolute; inset: -10%;
  background: center/cover no-repeat;
  filter: blur(28px) brightness(.55);
  transform: scale(1.15);
  z-index: 0;
}
.stage video { z-index: 1; }

.stage-empty {
  position: absolute; inset: 0; z-index: 3;
  display: grid; place-items: center; align-content: center; gap: 12px;
  background: rgba(10,11,15,.86); text-align: center; padding: 24px;
}
.stage-empty p { color: var(--muted); font-size: 13px; margin: 0; max-width: 220px; }
.empty-icon { font-size: 40px; }

.text-layer { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.overlay-text {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  white-space: pre-wrap;
  max-width: 92%;
  padding: 4px 8px;
  border-radius: 8px;
  text-shadow: 0 2px 8px rgba(0,0,0,.45);
}
.overlay-text.bg { background: rgba(0,0,0,.35); }
.overlay-text.dragging { outline: 2px dashed var(--accent); pointer-events: auto; }

.stage-bar {
  position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 4;
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px;
  background: rgba(12,13,18,.72);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  backdrop-filter: blur(8px);
}
.play {
  width: 34px; height: 34px; border-radius: 50%;
  border: none; background: var(--accent); color: #fff;
  font-size: 14px; cursor: pointer;
}
.time { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.scrub {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,.22);
  outline: none;
}
.scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  border: none;
}
.scrub::-moz-range-thumb { width: 12px; height: 12px; border: none; border-radius: 50%; background: var(--accent); }

/* ----------------------------------------------------------------- timeline */

.timeline {
  flex: 0 0 auto;
  padding: 4px 12px 6px;
}

.tl-head {
  display: flex; justify-content: space-between;
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 4px 2px 6px;
}
.tl-total { color: var(--text); letter-spacing: 0; text-transform: none; }

.tl-track {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px;
  min-height: 74px;
  scrollbar-width: none;
}
.tl-track::-webkit-scrollbar { display: none; }

.clip-card {
  position: relative;
  flex: 0 0 auto;
  width: 96px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid transparent;
  background: var(--panel);
  cursor: pointer;
}
.clip-card.selected { border-color: var(--accent); }
.clip-card img { width: 100%; height: 62px; object-fit: cover; display: block; background: #000; }
.clip-card .cap {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 6px; font-size: 10px; color: var(--muted);
}
.clip-card .idx {
  position: absolute; top: 4px; left: 4px;
  background: rgba(0,0,0,.6); border-radius: 6px;
  font-size: 10px; padding: 1px 5px;
}
.clip-card .speed {
  position: absolute; top: 4px; right: 4px;
  background: rgba(124,92,255,.85); border-radius: 6px;
  font-size: 10px; padding: 1px 5px;
}
.clip-card .tr {
  position: absolute; bottom: 22px; right: 4px;
  font-size: 10px; background: rgba(0,0,0,.6); border-radius: 6px; padding: 1px 5px;
}

.tl-add {
  flex: 0 0 auto;
  width: 92px;
  min-height: 74px;
  display: grid; place-items: center; gap: 2px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.tl-lane {
  display: flex; gap: 6px; overflow-x: auto; margin-top: 6px; min-height: 26px;
  scrollbar-width: none;
}
.tl-lane::-webkit-scrollbar { display: none; }
.lane-chip {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 11px; color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
.lane-chip.text { border-color: rgba(255,196,0,.4); }
.lane-chip.music { border-color: rgba(124,92,255,.5); }
.lane-chip.selected { outline: 1px solid var(--accent); }

/* -------------------------------------------------------------------- tools */

.tools {
  position: relative;
  flex: 0 0 auto;
  z-index: 15;
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 0;
  padding: 8px 6px calc(8px + max(env(safe-area-inset-bottom), var(--tg-bottom, 0px))) 6px;
  background: linear-gradient(0deg, rgba(11,12,16,.98), rgba(11,12,16,.8));
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.tools button {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 7px 2px;
  border: none; background: none;
  color: var(--muted); font-size: 17px;
  border-radius: 12px;
  cursor: pointer;
}
.tools button svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.tools button span { font-size: 10.5px; letter-spacing: .01em; }
.tools button:active { background: var(--panel); }
.tools button.active { color: var(--accent); }

/* ------------------------------------------------------------------- sheets */

.backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.55);
  opacity: 0; pointer-events: none;
  transition: opacity .18s ease;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--panel);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  transform: translateY(105%);
  /* без CSS-перехода: в фоновой вкладке он застревает на нулевом кадре и шторка остаётся за экраном */
  transition: none;
  max-height: 78vh;
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.show { transform: translateY(0) !important; }
.sheet-handle { width: 42px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 4px; }
.sheet-body { overflow-y: auto; padding: 10px 16px 20px; }

.sheet h3 { margin: 4px 0 12px; font-size: 15px; }
.sheet .row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.sheet .row label { font-size: 12px; color: var(--muted); flex: 0 0 84px; }
.sheet .row .value { font-size: 12px; color: var(--text); min-width: 46px; text-align: right; font-variant-numeric: tabular-nums; }
.sheet input[type=range] { flex: 1; accent-color: var(--accent); }
.sheet input[type=text], .sheet textarea, .sheet input[type=number] {
  width: 100%; padding: 10px 12px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 14px; font-family: inherit;
}
.sheet textarea { min-height: 72px; resize: vertical; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); font-size: 12px; cursor: pointer;
}
.chip.active { border-color: var(--accent); color: #fff; background: rgba(255,77,103,.18); }
.chip.swatch { width: 30px; height: 30px; padding: 0; border-radius: 50%; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: #ff6b7d; border-color: rgba(255,107,125,.4); }
.btn:active { transform: scale(.985); }
.btn.wide { width: 100%; margin-top: 12px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.section { margin: 14px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

.filters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.filter-card {
  border-radius: 12px; overflow: hidden; border: 2px solid transparent;
  background: #000; cursor: pointer; position: relative;
}
.filter-card img { width: 100%; height: 62px; object-fit: cover; display: block; }
.filter-card span { display: block; text-align: center; font-size: 10px; padding: 4px; color: var(--muted); }
.filter-card.active { border-color: var(--accent); }
.filter-card.active span { color: var(--text); }

.project-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 12px; border: 1px solid var(--line);
  margin-bottom: 8px; background: var(--panel-2); cursor: pointer;
}
.project-item.active { border-color: var(--accent); }
.project-item .pi-title { flex: 1; font-size: 13px; }
.project-item .pi-meta { font-size: 11px; color: var(--muted); }

.progress {
  height: 8px; border-radius: 4px; background: var(--panel-2);
  overflow: hidden; margin: 10px 0 6px;
}
.progress > i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .3s ease;
}
.stage-note { font-size: 12px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 20px);
  background: rgba(24,26,33,.96); border: 1px solid var(--line);
  color: var(--text); font-size: 12px;
  padding: 10px 14px; border-radius: 12px;
  max-width: 86vw; text-align: center;
  opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.result-video { width: 100%; border-radius: 12px; background: #000; margin-top: 8px; }

.hint { font-size: 11px; color: var(--muted); line-height: 1.45; }
.split { display: flex; gap: 8px; }
.split > * { flex: 1; }


/* --------------------------------------------------------- time-based timeline */

.tl-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.tl-scroll::-webkit-scrollbar { display: none; }

.tl-inner { position: relative; height: 92px; min-width: 100%; }

.tl-ruler {
  position: absolute; top: 0; left: 0; right: 0; height: 16px;
  border-bottom: 1px solid var(--line);
}
.tl-tick {
  position: absolute; top: 0; height: 16px;
  padding-left: 3px;
  font-size: 9px; line-height: 16px; color: var(--muted);
  border-left: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.tl-clips { position: absolute; top: 18px; left: 0; right: 0; height: 68px; }

.clip-block {
  position: absolute; top: 0; height: 68px;
  border-radius: 10px; overflow: hidden;
  background: var(--panel-2);
  border: 2px solid transparent;
  box-sizing: border-box;
  cursor: pointer;
}
.clip-block.selected { border-color: var(--accent); }
.clip-block img { width: 100%; height: 100%; object-fit: cover; opacity: .85; display: block; }
.clip-block .cb-idx {
  position: absolute; top: 3px; left: 4px;
  font-size: 9px; font-style: normal;
  background: rgba(0,0,0,.62); border-radius: 5px; padding: 0 4px;
}
.clip-block .cb-speed {
  position: absolute; top: 3px; right: 4px;
  font-size: 9px; background: rgba(124,92,255,.9); border-radius: 5px; padding: 0 4px;
}
.clip-block .cb-dur {
  position: absolute; bottom: 3px; right: 4px;
  font-size: 9px; font-weight: 500;
  background: rgba(0,0,0,.62); border-radius: 5px; padding: 0 4px;
}
.clip-block .cb-tr {
  position: absolute; bottom: 3px; left: 4px;
  font-size: 9px; background: rgba(0,0,0,.62); border-radius: 5px; padding: 0 4px;
}

.tl-add-inline {
  position: absolute; top: 18px; height: 68px; width: 46px;
  border: 1px dashed var(--line); border-radius: 10px;
  background: var(--panel); color: var(--muted);
  font-size: 20px; cursor: pointer;
}

.tl-playhead {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--accent);
  box-shadow: 0 0 6px rgba(255,77,103,.8);
  pointer-events: none;
  z-index: 3;
}
.tl-playhead::before {
  content: ''; position: absolute; top: -1px; left: -4px;
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 7px solid var(--accent);
}


/* ============================== v7: капкат-полировка ========================= */

.sheet {
  height: 38vh;
  max-height: 58vh;
  transition: transform .22s cubic-bezier(.2,.8,.2,1);
  touch-action: none;
}
.sheet.dragging { transition: none; }

body.sheet-open .stage-wrap { flex: 0 0 24vh; min-height: 110px; }
body.sheet-open .timeline { padding-bottom: 2px; }

/* таймлайн: кадры-миниатюры, ручки обрезки, зум */
.clip-block {
  background-repeat: repeat-x;
  background-position: left center;
  background-size: auto 100%;
}
.clip-block img { display: none; }
.clip-block.selected { border-color: var(--accent); }

.trim-handle {
  position: absolute; top: 0; bottom: 0; width: 16px;
  display: grid; place-items: center;
  background: rgba(255,77,103,.9);
  border-radius: 4px;
  cursor: ew-resize;
  z-index: 4;
}
.trim-handle::before {
  content: ''; width: 2px; height: 16px; border-radius: 1px;
  background: #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.15);
}
.trim-handle.left { left: -2px; }
.trim-handle.right { right: -2px; }

.tl-head .tl-tools { display: flex; gap: 6px; align-items: center; }
.tl-zoom {
  width: 26px; height: 22px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--panel);
  color: var(--text); font-size: 13px; line-height: 1;
  display: grid; place-items: center; cursor: pointer;
}

/* переходы плитками */
.tile-row {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px;
  scrollbar-width: none;
}
.tile-row::-webkit-scrollbar { display: none; }
.tile {
  flex: 0 0 auto; width: 64px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2); color: var(--text);
  padding: 0; overflow: hidden; cursor: pointer;
}
.tile .tile-art {
  height: 46px; width: 100%; display: grid; place-items: center;
  font-size: 18px; color: #fff;
  background: linear-gradient(135deg, #2a2f3a, #14161c);
  object-fit: cover;
}
.tile span { display: block; font-size: 9.5px; padding: 3px 2px 5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.active { border-color: var(--accent); }
.tile.active span { color: var(--text); }


/* ============================ v8: плотная капкат-верстка =================== */

.topbar { padding: calc(var(--tg-top, 0px) + 6px) 12px 6px 12px; gap: 8px; }
.title { font-size: 14px; }
.subtitle { font-size: 10.5px; margin-top: 1px; }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; font-size: 15px; }

.stage-wrap { padding: 4px 12px 2px; }
.stage { border-radius: 12px; }

.timeline { padding: 4px 12px 4px; }
.tl-head { margin: 0 2px 3px; font-size: 10px; letter-spacing: .06em; }
.tl-tools { gap: 4px; }
.tl-zoom { width: 24px; height: 20px; font-size: 12px; border-radius: 6px; }

.tl-inner { height: 78px; }
.tl-ruler { height: 14px; }
.tl-tick { height: 14px; line-height: 14px; font-size: 8.5px; padding-left: 2px; }
.tl-clips { top: 15px; height: 60px; }

.clip-block {
  height: 60px;
  border-radius: 7px;
  border: 1.5px solid rgba(255,255,255,.10);
}
.clip-block.selected {
  border-color: #fff;
  box-shadow: 0 0 0 1.5px var(--accent);
}
.clip-block .cb-idx, .clip-block .cb-dur, .clip-block .cb-speed, .clip-block .cb-tr {
  font-size: 8.5px; padding: 0 3px; border-radius: 4px;
}

.trim-handle {
  width: 13px; border-radius: 5px;
  background: var(--accent);
}
.trim-handle::before { width: 2px; height: 13px; }

.tl-add-inline { top: 15px; height: 60px; width: 38px; font-size: 17px; border-radius: 8px; }
.tl-playhead { width: 2px; background: #fff; box-shadow: 0 0 4px rgba(0,0,0,.6); }
.tl-playhead::before { border-top-color: #fff; border-left-width: 4px; border-right-width: 4px; border-top-width: 6px; left: -3px; }

.tl-lane { margin-top: 4px; min-height: 22px; }
.lane-chip { padding: 3px 9px; font-size: 10.5px; border-radius: 999px; }

.tools { padding: 6px 6px calc(6px + max(env(safe-area-inset-bottom), var(--tg-bottom, 0px))) 6px; }
.tools button { gap: 3px; padding: 5px 2px; }
.tools button svg { width: 23px; height: 23px; }
.tools button span { font-size: 10px; }

.sheet { border-radius: 18px 18px 0 0; }
.sheet-body { padding: 8px 14px 18px; }
.sheet h3 { font-size: 14.5px; margin: 2px 0 10px; }
.section { margin: 12px 0 4px; font-size: 10px; }
.chip { padding: 7px 11px; font-size: 11.5px; }


/* ====================== v10: многодорожечный таймлайн ====================== */

.tl-inner { height: 122px; }

.tl-lane-text, .tl-lane-music {
  position: absolute; left: 0; right: 0;
  display: block; margin: 0; min-height: 0; overflow: visible;
}
.tl-lane-text { top: 79px; height: 21px; }
.tl-lane-music { top: 103px; height: 17px; }

.tl-block {
  position: absolute; top: 0;
  display: flex; align-items: center; gap: 4px;
  padding: 0 6px;
  font-size: 9.5px;
  white-space: nowrap; overflow: hidden;
  border-radius: 5px;
  cursor: pointer;
  user-select: none;
}
.tl-block.text {
  height: 21px;
  background: rgba(255,212,0,.18);
  border: 1px solid rgba(255,212,0,.55);
  color: #ffdf6e;
}
.tl-block.music {
  height: 17px;
  background: rgba(124,92,255,.22);
  border: 1px solid rgba(124,92,255,.6);
  color: #cfc6ff;
}
.tl-block.dragging { opacity: .9; box-shadow: 0 4px 14px rgba(0,0,0,.45); z-index: 6; }
.tl-block.add {
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
  justify-content: center;
}


/* ============================== v11: стикеры =============================== */

.sticker-layer { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.stage-sticker {
  position: absolute; transform: translate(-50%, -50%);
  pointer-events: auto; cursor: grab;
  user-select: none; touch-action: none;
}
.stage-sticker.selected { outline: 2px dashed var(--accent); outline-offset: 2px; border-radius: 6px; }
.stage-sticker.dragging { cursor: grabbing; }

.tl-block.sticker {
  height: 21px;
  background: rgba(77,227,162,.16);
  border: 1px solid rgba(77,227,162,.55);
  color: #7ff0c2;
}


/* ====================== v12: ручки обрезки на дорожках ==================== */

.tl-block.selected { outline: 1.5px solid #fff; outline-offset: 1px; }

.block-handle {
  position: absolute; top: -1px; bottom: -1px; width: 11px;
  background: var(--accent); border-radius: 4px;
  z-index: 5;

  touch-action: none;
}
.block-handle::before {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 2px; height: 9px; margin: -4.5px 0 0 -1px;
  border-radius: 1px; background: #fff;
}
.block-handle.left { left: -4px; }
.block-handle.right { right: -4px; }


/* ============================== v16: кейфреймы ============================ */

.key-list { display: flex; flex-direction: column; gap: 6px; }

.key-row {
  display: flex; align-items: center; gap: 8px;
  background: #1b1e26; border-radius: 10px; padding: 2px 2px 2px 12px;
}
.key-row.active { box-shadow: inset 0 0 0 1.5px var(--accent); }

.key-label {
  flex: 1; text-align: left; background: none; border: 0; color: #e8ebf2;
  font-size: 13px; padding: 10px 0; font-variant-numeric: tabular-nums;
}

.key-del {
  width: 30px; height: 30px; border-radius: 8px; border: 0;
  background: #262a34; color: #9aa3b2; font-size: 13px;
}

.key-editor {
  margin-top: 10px; font-size: 12px; color: var(--accent);
  letter-spacing: .02em;
}


/* ============================== v18: PiP-слой ============================= */

.tl-lane-pip { height: 20px; }

.tl-lane-pip .tl-block.pip {
  background: linear-gradient(180deg, #3a5bff, #2a41c4);
  border-color: #5b78ff;
}

.pip-layer { position: absolute; inset: 0; pointer-events: none; }

.pip-layer video {
  position: absolute; transform: translate(-50%, -50%);
  border-radius: 6px; pointer-events: auto;
  box-shadow: 0 0 0 1.5px rgba(255,255,255,.12);
}
.pip-layer video.selected { box-shadow: 0 0 0 2px var(--accent); }


/* v21: обрезка клипа — заметная ручка и подсветка при перетаскивании */
.clip-block .trim-handle {
  width: 14px; z-index: 8; touch-action: none;
  display: flex; align-items: center; justify-content: center;
}
.clip-block .trim-handle.left { left: -7px; }
.clip-block .trim-handle.right { right: -7px; }
.clip-block.trimming { z-index: 9; box-shadow: 0 0 0 2px var(--accent); }
.clip-block .trim-handle::after {
  content: ''; width: 3px; height: 16px; border-radius: 2px;
  background: rgba(255,255,255,.9);
}


/* ========================== v25: галерея проектов ========================= */

.project-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px; margin-bottom: 12px;
}

.project-card {
  display: flex; flex-direction: column; gap: 4px; text-align: left;
  background: #1a1d24; border: 1px solid rgba(255,255,255,.06);
  border-radius: 12px; padding: 0 0 8px; overflow: hidden; color: #e8ebf2;
}
.project-card.active { box-shadow: inset 0 0 0 1.5px var(--accent); }
.project-card.new {
  align-items: center; justify-content: center; min-height: 116px;
  border-style: dashed; gap: 6px; padding: 12px;
}
.pc-plus { font-size: 26px; color: var(--accent); line-height: 1; }

.pc-cover {
  position: relative; width: 100%; aspect-ratio: 16 / 10; background: #23262f;
}
.pc-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pc-badge {
  position: absolute; right: 6px; bottom: 6px; padding: 2px 6px; border-radius: 6px;
  background: rgba(0,0,0,.65); font-size: 10px; color: #fff;
}

.pc-name {
  font-size: 12.5px; padding: 0 9px; margin-top: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pc-meta { font-size: 10.5px; color: var(--muted); padding: 0 9px; }


/* ============================ v27: статус сохранения ====================== */

.save-status {
  font-size: 10px; letter-spacing: .02em; margin-top: 1px;
  color: var(--muted); min-height: 12px;
}
.save-status.saving { color: #f0b429; }
.save-status.saved { color: #4ecb71; }
.save-status.error { color: #ff6b7d; }


/* ============================ v28: шаблоны ================================ */

.tpl-grid { display: flex; flex-direction: column; gap: 8px; }

.tpl-card {
  display: flex; flex-direction: column; gap: 3px; text-align: left;
  background: #1b1e26; border: 1px solid rgba(255,255,255,.07);
  border-radius: 12px; padding: 12px 14px; color: #e8ebf2;
}
.tpl-card b { font-size: 13.5px; font-weight: 600; }
.tpl-card span { font-size: 11px; color: var(--muted); }


/* ========================== v34: направляющие в кадре ===================== */

.align-guide { position: absolute; background: rgba(255,255,255,.55); pointer-events: none; z-index: 30; }
.align-guide.v { left: 50%; top: 0; bottom: 0; width: 1px; }
.align-guide.h { top: 50%; left: 0; right: 0; height: 1px; }

.overlay-text { cursor: move; touch-action: none; pointer-events: auto; }
.overlay-text.dragging { outline: 1px dashed rgba(255,255,255,.6); outline-offset: 4px; }

.text-layer { pointer-events: none; }


/* ================================ v36: метки ============================== */

.tl-markers { position: absolute; left: 0; right: 0; top: 0; height: 14px; pointer-events: none; }

.tl-marker {
  position: absolute; top: 0; width: 10px; height: 12px; padding: 0;
  transform: translateX(-1px);
  background: var(--accent); border: 0;
  clip-path: polygon(0 0, 100% 0, 100% 70%, 50% 100%, 0 70%);
  pointer-events: auto;
}

.tl-mark { font-size: 12px; }


/* ====================== v36b: узкие экраны (360×640 и меньше) ============= */

@media (max-width: 380px) {
  .topbar { gap: 6px; padding: calc(var(--tg-top, 0px) + 6px) 8px 6px 8px; }
  .title { font-size: 13.5px; }
  .subtitle { font-size: 10px; }
  .save-status { font-size: 9px; }
  .icon-btn { width: 30px; height: 30px; font-size: 14px; border-radius: 9px; }
  .tools { padding: 6px 2px calc(6px + max(env(safe-area-inset-bottom), var(--tg-bottom, 0px))) 2px; }
  .tools button { gap: 3px; padding: 5px 1px; font-size: 15px; }
  .tools button svg { width: 19px; height: 19px; }
  .tools button span { font-size: 9px; }
}

.tools { min-width: 0; }
.tools button { min-width: 0; }
.tools button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }


/* ================== v38: шторка без залипающего transition ================ */
/* в файле несколько блоков .sheet, последний возвращал transition .22s —
   в фоновой вкладке переход застревает на первом кадре и шторка остаётся за экраном */
.sheet { transition: none !important; }
.sheet.show { transform: translateY(0) !important; }
.sheet.dragging { transition: none !important; }


/* ==================== v41: полная адаптивность под телефон ================= */
/* 1. плеер: ползунок сжимается, время и кнопки не выдавливают панель */
.stage-bar { gap: 6px; padding: 4px 6px; left: 6px; right: 6px; }
.stage-bar .play { width: 32px; height: 32px; flex: 0 0 auto; }
.stage-bar .icon-btn.small { width: 26px; height: 26px; flex: 0 0 auto; }
.stage-bar .time { font-size: 10px; flex: 0 0 auto; }
.stage-bar .scrub { min-width: 0; }
#stage > video, .stage video { min-width: 0; }

/* 2. шапка: сжимается по содержимому */
.topbar { gap: 8px; min-width: 0; }
.topbar .title-wrap { flex: 1 1 auto; min-width: 0; }

/* 3. очень узкие экраны */
@media (max-width: 340px) {
  .topbar { gap: 4px; padding-left: 6px; padding-right: 6px; }
  .topbar .save-status { display: none; }
  .icon-btn { width: 28px; height: 28px; font-size: 13px; }
  .title { font-size: 12.5px; }
  .tools button span { font-size: 8px; }
  .tools button svg { width: 17px; height: 17px; }
  .stage-bar .time { font-size: 9px; letter-spacing: -.02em; }
  .stage-bar .icon-btn.small#btnResetPlayhead { display: none; }
}

/* 4. низкие экраны (SE и подобные): таймлайн компактнее, сцена выше */
@media (max-height: 700px) {
  .tl-clips, .clip-block { height: 54px; }
  .tl-lane { min-height: 22px; margin-top: 4px; }
  .tl-lane-text, .tl-lane-music, .tl-lane-pip { height: 18px; }
  .timeline { padding: 2px 10px 4px; }
  .tl-head { margin: 2px 2px 4px; }
}

/* 5. широкие, но низкие — не растягивать панели */
@media (min-width: 500px) {
  .sheet { max-width: 520px; left: 50%; transform: translate(-50%, 105%); }
  .sheet.show { transform: translate(-50%, 0) !important; }
}


/* ================== v42: жёсткая сетка, которая не может вылезти ========== */
html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

#app {
  display: grid !important;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  height: 100dvh !important;
  max-height: 100dvh;
  box-sizing: border-box;
  padding-top: var(--tg-top, 0px);
  padding-bottom: max(var(--tg-bottom, 0px), env(safe-area-inset-bottom));
  overflow: hidden;
}

.topbar { padding-top: 8px !important; }

.stage-wrap {
  min-height: 0 !important;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px 4px;
}

.stage {
  max-height: 100%;
  max-width: 100%;
  height: var(--stage-h, auto);
  width: auto;
  aspect-ratio: var(--stage-ratio, 9 / 16);
  min-height: 0;
}

.stage video { width: 100%; height: 100%; object-fit: contain; }

.timeline {
  flex: none;
  max-height: clamp(112px, 27dvh, 176px);
  overflow: hidden;
  padding: 2px 10px 4px;
}

.tools {
  flex: none;
  padding-bottom: max(env(safe-area-inset-bottom), 8px) !important;
}

.sheet {
  max-height: min(78dvh, calc(100dvh - 120px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}


/* ============= v43: схема как в FarmGram — контейнер по высоте Telegram ===== */
#app {
  position: fixed !important;
  inset: 0 !important;
  height: var(--app-h, 100dvh) !important;
  max-height: var(--app-h, 100dvh) !important;
  display: grid !important;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  padding: 0 !important;
  overflow: hidden;
  box-sizing: border-box;
}

/* инсеты применяем к крайним полосам, а не ко всему контейнеру */
.topbar { padding-top: calc(var(--app-top, 0px) + 6px) !important; }

.tools {
  padding-bottom: calc(max(var(--app-bottom, 0px), env(safe-area-inset-bottom)) + 6px) !important;
}

.timeline { max-height: clamp(108px, 26cqh, 168px); }


/* ==================== v44: надпись всегда внутри кадра ==================== */
.overlay-text {
  width: max-content;          /* без этого absolute-блок сжимается у края и текст встаёт колонкой */
  max-width: 92%;
  text-align: center;
  overflow-wrap: anywhere;
  line-height: 1.15;
}


/* =============== v46: линейка, мелкие блоки и зум не липнут к краям ======= */
/* первая подпись шкалы центрируется по нулю и половиной уезжает за край */
.tl-ruler { padding-left: 6px; }
.tl-tick { transform: translateX(0); }
.tl-ruler .tl-tick:first-child { padding-left: 3px; }

/* панель зума дышит и не прижата к правому краю */
.tl-head { padding-right: 8px; margin-right: 0; }
.tl-head .tl-tools { gap: 6px; }
.tl-zoom { min-width: 26px; }

/* короткие блоки на дорожке не превращаются в огрызок у края */
.tl-block { min-width: 46px; }
.lane-chip { min-width: 40px; }


/* ================= v48: читаемость таймлайна и подписей =================== */
.tl-tick { font-size: 10px; height: 18px; line-height: 18px; padding-left: 4px; }
.tl-clips { top: 19px; }

.tl-block { font-size: 11.5px !important; padding: 0 8px; }
.tl-block.music, .tl-block.text, .tl-block.sticker, .tl-block.pip {
  font-size: 11px !important; line-height: 1.15;
  display: flex; align-items: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.tl-lane-text, .tl-lane-music, .tl-lane-pip { height: 22px; }
.tl-lane { min-height: 24px; }

.subtitle { font-size: 11.5px; }
.project-meta, #projectMeta { font-size: 11.5px; }

/* короткий блок музыки/эффекта не теряется */
.tl-block.music { min-width: 64px; }


/* ============ v49: таймлайн не растягивает экран по горизонтали =========== */
.timeline, .tl-head, .tl-scroll, .tl-inner { min-width: 0; max-width: 100%; }
.tl-scroll { width: 100%; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
#app > section.timeline { width: 100%; }
.stage-wrap, .topbar, .tools { min-width: 0; max-width: 100%; }


/* ========= v52: надписи — по своей дорожке, как в CapCut =================== */
.tl-lane-text.tl-lanes-stack {
  display: flex; flex-direction: column; gap: 4px;
  height: auto; min-height: 0; overflow: visible;
}
.tl-lane-row { position: relative; height: 20px; min-height: 20px; }
.tl-lane-row .tl-block.text {
  position: absolute; top: 0; height: 20px; line-height: 20px;
  border-radius: 6px; padding: 0 6px; font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* кадр крупнее, как в CapCut (~55% высоты) */
.stage { --stage-fill: 1; }



/* ====== v56: дорожки в столбик, таймлайн скроллится и по вертикали ======= */
.tl-scroll { overflow: auto !important; -webkit-overflow-scrolling: touch; }
.tl-inner {
  display: flex !important;
  flex-direction: column;
  gap: 4px;
  height: auto !important;
  min-height: 96px;
  padding-bottom: 4px;
}
.tl-clips { position: relative !important; top: 0 !important; flex: 0 0 auto; }
.tl-lane, .tl-lane-row { position: relative !important; flex: 0 0 auto; margin: 0 !important; }
.tl-lane-text, .tl-lane-music, .tl-lane-pip { display: flex; flex-direction: column; gap: 4px; height: auto !important; }
.tl-ruler { position: relative !important; flex: 0 0 auto; }
.tl-playhead { position: absolute; top: 0; bottom: 0; }
.timeline { max-height: 42dvh; }


/* ===== v57: блок наложения показывает кадр исходника ===================== */
.tl-block.pip.with-thumb { color: transparent; padding: 0; }
.tl-block .blk-badge {
  position: absolute; left: 3px; bottom: 2px;
  font-size: 9px; line-height: 1; padding: 2px 4px; border-radius: 4px;
  background: rgba(0,0,0,.62); color: #fff;
}


/* высота блока наложения (иначе он схлопывается в 0) */
#pipTrack { position: relative; min-height: 24px; }
#pipTrack .tl-block.pip {
  position: absolute; top: 0; height: 24px; border-radius: 6px;
  overflow: hidden; border: 1px solid rgba(255,255,255,.14);
}


/* ===== v59: дорожки текста и звука гарантированно видимы ================== */
#textTrack, #musicTrack { position: relative; display: block; }
#textTrack { min-height: 22px; }
#musicTrack { min-height: 26px; }
#musicTrack .tl-block.music {
  position: absolute; top: 0; height: 24px; line-height: 24px;
  border-radius: 6px; padding: 0 8px; font-size: 11px;
}
#textTrack .tl-lane-row .tl-block.text { position: absolute; top: 0; height: 20px; line-height: 20px; }
.tl-inner { min-height: 130px; }


/* ===== v60: кадр занимает всю доступную зону (как 55-57% в CapCut) ======== */
.stage-wrap { align-items: center !important; justify-content: center !important; min-height: 0 !important; }
.stage {
  height: 100% !important;
  width: auto !important;
  max-height: 100% !important;
  max-width: 100% !important;
  aspect-ratio: var(--stage-ratio, 9 / 16) !important;
  flex: 0 1 auto !important;
}


/* ============================================================================
   v61: таймлайн — сетка «рельса + дорожка», иконки глаза/замка, слот «+»,
   таймкод с кадрами, кнопка «Закрыть». Старые absolute-правила нейтрализованы.
   ========================================================================== */
:root { --rail-w: 34px; --tl-video-h: 56px; --tl-small-h: 30px; --tl-text-h: 26px; }

/* ---------------------------------------------------------------- шапка */
.topbar { gap: 6px; padding: calc(var(--tg-top, 0px) + 6px) 10px 6px; }
.topbar .icon-btn { width: 34px; height: 34px; border-radius: 11px; font-size: 15px; }

.close-btn {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 4px;
  height: 34px; padding: 0 10px 0 8px;
  border: 1px solid var(--line); border-radius: 999px;
  background: rgba(255,255,255,.07);
  color: var(--text); font-size: 11.5px; font-weight: 600;
  cursor: pointer;
}
.close-btn svg {
  width: 13px; height: 13px;
  fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round;
}
.close-btn:active { transform: scale(.96); background: rgba(255,255,255,.13); }

.title-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.title-row .title { min-width: 0; }
.ver-chip {
  flex: 0 0 auto;
  font-size: 9.5px; font-weight: 700; letter-spacing: .02em;
  color: var(--muted); background: rgba(255,255,255,.08);
  border-radius: 5px; padding: 1px 4px;
}
.subtitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.export-btn { color: #fff; background: rgba(255,77,103,.92); border-color: transparent; }

/* ------------------------------------------------------------- зона кадра */
#app { height: var(--tg-height, 100dvh); }
.stage-wrap { flex: 1 1 auto !important; min-height: 0 !important; padding: 4px 10px 2px; }

/* ------------------------------------------------------------- таймлайн */
section.timeline {
  flex: 0 0 auto;
  display: flex; flex-direction: column;
  max-height: none !important;
  overflow: visible !important;
  padding-top: 2px;
  border-top: 1px solid var(--line);
}
.tl-head { padding: 4px 10px 3px; align-items: center; }
.tl-title { font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.tl-total { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.tl-scroll {
  padding: 0 8px 6px;
  max-height: 40dvh;
  overflow: auto !important;
}
.tl-inner {
  position: relative !important;
  display: flex; flex-direction: column; gap: 5px;
  height: auto !important; min-height: 0 !important;
  padding-bottom: 2px;
}

.tl-row { display: flex; align-items: stretch; }
.rail-spacer { flex: 0 0 var(--rail-w); width: var(--rail-w); }
.tl-ruler-wrap { position: relative; flex: 1 1 auto; min-width: 0; height: 15px; }
.tl-ruler {
  position: relative !important; top: 0 !important; left: 0 !important; right: auto !important;
  height: 15px !important; border-bottom: none !important; padding-left: 0 !important;
}
.tl-tick { height: 15px !important; line-height: 14px !important; font-size: 9px !important; padding-left: 3px !important; }
.tl-markers { position: absolute !important; inset: 0; pointer-events: none; z-index: 2; }
.tl-markers .tl-marker { pointer-events: auto; }

.tl-row-track { display: flex; align-items: stretch; }
.lane-rail {
  flex: 0 0 var(--rail-w); width: var(--rail-w);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  z-index: 4;
}
.lane-rail button {
  width: 26px; height: 13px;
  display: grid; place-items: center;
  border: 0; padding: 0; background: none;
  color: rgba(255,255,255,.5); cursor: pointer;
}
.lane-rail button svg {
  width: 12px; height: 12px;
  fill: none; stroke: currentColor; stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round;
}
.lane-rail button.off { color: var(--accent); }
.lane-rail button.off svg { stroke-width: 2.1; }
.lane-rail button:disabled { opacity: .28; cursor: default; }
.lane-rail button:active:not(:disabled) { transform: scale(.9); }

.tl-body { position: relative !important; flex: 1 1 auto; min-width: 0; width: auto !important; right: auto !important; }
.tl-body.tl-clips { top: 0 !important; height: var(--tl-video-h) !important; }
.tl-body.tl-clips .clip-block { height: var(--tl-video-h); }
.tl-body.tl-lane-pip { display: block !important; height: var(--tl-small-h) !important; min-height: var(--tl-small-h) !important; margin: 0 !important; overflow: hidden; }
.tl-body.tl-lane-pip .tl-block.pip { top: 0 !important; height: var(--tl-small-h) !important; }
.tl-body.tl-lane-text { display: flex !important; flex-direction: column; gap: 3px; height: auto !important; min-height: var(--tl-text-h) !important; margin: 0 !important; overflow: hidden; }
.tl-body.tl-lane-music { display: block !important; height: var(--tl-small-h) !important; min-height: var(--tl-small-h) !important; margin: 0 !important; overflow: hidden; }
.tl-body.tl-lane-music .tl-block.music { top: 0 !important; height: var(--tl-small-h) !important; line-height: calc(var(--tl-small-h) - 2px) !important; }
.tl-lane-row { height: var(--tl-text-h) !important; min-height: var(--tl-text-h) !important; }
.tl-lane-row .tl-block.text { height: var(--tl-text-h) !important; line-height: calc(var(--tl-text-h) - 2px) !important; }

/* слот «+» в конце дорожки */
.lane-add {
  position: absolute; top: 0; bottom: 0;
  display: grid; place-items: center;
  border: 1px dashed rgba(255,255,255,.24);
  border-radius: 8px;
  background: rgba(255,255,255,.04);
  color: var(--muted);
  font-size: 15px; line-height: 1; font-weight: 500;
  cursor: pointer; z-index: 2; padding: 0;
}
.lane-add:active { background: rgba(255,255,255,.12); color: var(--text); }
.tl-add-inline { display: none !important; }

/* состояния дорожек */
.tl-row-track.is-hidden .tl-body { opacity: .32; }
.tl-row-track.is-hidden .lane-rail button.eye { color: var(--accent); }
.tl-row-track.is-locked .tl-body .tl-block,
.tl-row-track.is-locked .tl-body .clip-block,
.tl-row-track.is-locked .tl-body .trim-handle { pointer-events: none !important; }
.tl-row-track.is-locked .lane-rail button.lock { color: #ffd400; }

.tl-playhead { z-index: 6; }

/* v61.1: снимаем остатки absolute-смещений у тел дорожек */
.tl-body, #clipTrack, #pipTrack, #textTrack, #musicTrack { top: 0 !important; left: 0 !important; }
.tl-row-track { align-items: flex-start; }
.tl-row-track .lane-rail { align-self: stretch; }

/* v61.2: таймлайн занимает свою ширину, а не жмётся к экрану */
.tl-inner { max-width: none !important; }
.tl-row-track { min-height: 0 !important; padding-bottom: 0 !important; gap: 0 !important; overflow: visible !important; }

/* v61.3: метаданные проекта в одну строку без обрезки */
.subtitle { font-size: 10.5px !important; line-height: 1.25; }

/* v61.4: рельса крупнее (палец), дорожки воздушнее, как в CapCut */
:root { --rail-w: 40px; --tl-small-h: 32px; --tl-text-h: 28px; }
.tl-inner { gap: 7px; }
.lane-rail { gap: 2px; }
.lane-rail button {
  width: 34px; height: 19px;
  border-radius: 6px;
  background: rgba(255,255,255,.055);
  color: rgba(255,255,255,.66);
}
.lane-rail button + button { margin-top: 1px; }
.lane-rail button svg { width: 15px; height: 15px; }
.lane-rail button.off { background: rgba(255,77,103,.16); }
.lane-rail button:disabled { background: rgba(255,255,255,.03); }
.tl-row-track { align-items: center !important; }
.tl-row-track .tl-body { align-self: stretch; }

/* v61.5: точные высоты рельсы под каждую дорожку */
:root { --tl-video-h: 58px; --tl-small-h: 32px; --tl-text-h: 30px; }
.lane-rail button { height: 14px; }
.lane-rail button svg { width: 13px; height: 13px; }
.tl-row-track[data-track="video"] .lane-rail button { height: 19px; }
.tl-row-track[data-track="video"] .lane-rail button svg { width: 16px; height: 16px; }
.tl-lane-row { height: var(--tl-text-h) !important; min-height: var(--tl-text-h) !important; }
.tl-lane-row .tl-block.text { height: var(--tl-text-h) !important; line-height: calc(var(--tl-text-h) - 2px) !important; }

/* v61.6: контраст иконок и цветовой край дорожки */
.lane-rail button { color: rgba(255,255,255,.82); background: rgba(255,255,255,.09); }
.lane-rail button svg { stroke-width: 2.1; }
.lane-rail button:disabled { color: rgba(255,255,255,.22); background: rgba(255,255,255,.04); }
.tl-row-track[data-track="video"] .tl-body { box-shadow: inset 2px 0 0 rgba(255,255,255,.16); }
.tl-row-track[data-track="pip"] .tl-body { box-shadow: inset 2px 0 0 rgba(103,184,255,.6); }
.tl-row-track[data-track="text"] .tl-body { box-shadow: inset 2px 0 0 rgba(255,212,0,.6); }
.tl-row-track[data-track="music"] .tl-body { box-shadow: inset 2px 0 0 rgba(124,92,255,.65); }

/* ===== v63: тип дорожки в рельсе + позиция в шапке таймлайна ============== */
:root { --rail-w: 48px; }

.lane-rail { flex-direction: column; justify-content: center; gap: 2px; }
.lane-type {
  width: 42px; height: 11px;
  display: grid; place-items: center;
  color: rgba(255,255,255,.45);
  pointer-events: none;
}
.lane-type svg {
  width: 12px; height: 12px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.tl-row-track[data-track="pip"] .lane-type { color: rgba(103,184,255,.75); }
.tl-row-track[data-track="text"] .lane-type { color: rgba(255,212,0,.75); }
.tl-row-track[data-track="music"] .lane-type { color: rgba(124,92,255,.85); }

.rail-btns { display: flex; gap: 2px; }
.lane-rail .rail-btns button {
  width: 20px; height: 15px;
  border-radius: 5px;
  background: rgba(255,255,255,.09);
  color: rgba(255,255,255,.8);
}
.lane-rail .rail-btns button svg { width: 12px; height: 12px; }
.tl-row-track[data-track="video"] .lane-rail .rail-btns button { width: 21px; height: 19px; }
.tl-row-track[data-track="video"] .lane-rail .rail-btns button svg { width: 15px; height: 15px; }

.tl-head { gap: 8px; }
.tl-clock {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10.5px; color: var(--text);
  font-variant-numeric: tabular-nums; letter-spacing: .01em;
}
.tl-clock .tl-sep { color: var(--muted); }
.tl-head .tl-tools { margin-left: 6px; }

/* v63.1: название проекта не обрезается — чуть плотнее шапка */
.topbar { gap: 5px; padding: calc(var(--tg-top, 0px) + 6px) 9px 6px; }
.topbar .icon-btn { width: 31px; height: 31px; }
.close-btn { height: 31px; padding: 0 9px 0 7px; }
.topbar { gap: 4px; }
.topbar .icon-btn { width: 30px; height: 30px; }

/* v63.2: таймлайн не съедает кадр — растёт до 40dvh и скроллит дорожки внутри */
section.timeline {
  flex: 0 1 auto !important;
  max-height: 40dvh !important;
  overflow: hidden !important;
}
.tl-scroll {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none !important;
  overflow: auto !important;
}
.stage-wrap { min-height: 44dvh !important; }
/* v98 (ревью): на низком экране (клавиатура открыта) 44dvh + таймлайн + меню не влезали
   в экран и низ кадра уходил под таймлайн. Оставляем кадру то, что реально свободно. */
.stage-wrap { min-height: min(44dvh, calc(100dvh - 356px)) !important; }

/* ===== v66: пузырёк времени при скрабе + индикация щипка =================== */
.tl-bubble {
  position: absolute; top: -1px; left: 0;
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 9.5px; line-height: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity .12s ease;
  z-index: 8;
  box-shadow: 0 2px 6px rgba(0,0,0,.45);
}
.tl-scroll.scrubbing .tl-bubble { opacity: 1; }
.tl-scroll.zooming .tl-bubble { opacity: 0; }
.tl-scroll.zooming { cursor: zoom-in; }
.tl-ruler-wrap { overscroll-behavior: contain; }

/* v69: иконка типа дорожки крупнее и контрастнее */
.lane-type { height: 13px; color: rgba(255,255,255,.62); }
.lane-type svg { width: 13px; height: 13px; }
.tl-row-track[data-track="video"] .lane-type { height: 16px; color: rgba(255,255,255,.7); }
.tl-row-track[data-track="video"] .lane-type svg { width: 16px; height: 16px; }
.tl-row-track[data-track="pip"] .lane-type { color: rgba(103,184,255,.85); }
.tl-row-track[data-track="text"] .lane-type { color: rgba(255,212,0,.85); }
.tl-row-track[data-track="music"] .lane-type { color: rgba(124,92,255,.95); }

/* v72: кадр не отдаёт жесты браузеру — иначе pointer/touch обрываются */
.stage { touch-action: none; -webkit-user-select: none; user-select: none; }
.stage * { -webkit-user-drag: none; }
.tl-scroll { overscroll-behavior: contain; }
.tl-scroll.zooming .clip-block, .tl-scroll.zooming .tl-block { pointer-events: none; }

/* ===== v74: выделение блока видно — рисуем внутрь, дорожка обрезает outline ==== */
.tl-block.selected,
.clip-block.selected {
  outline: none !important;
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 10px rgba(255,77,103,.35) !important;
  z-index: 6;
  filter: brightness(1.12);
}
.tl-body .tl-block.pip.selected,
.tl-body .tl-block.music.selected {
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 10px rgba(255,77,103,.4) !important;
}
/* ручки обрезки у поверх/звука — по краям выделенного блока */
.tl-block .block-handle { background: var(--accent); }
/* дорожки чуть выше: палец должен попадать */
:root { --tl-small-h: 34px; --tl-text-h: 30px; }


/* ===== v76: нижнее меню — горизонтальная прокрутка, как в CapCut ========== */
.tools {
  display: flex !important;
  flex-wrap: nowrap !important;
  gap: 2px !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  padding: 6px 6px calc(6px + max(env(safe-area-inset-bottom), var(--tg-bottom, 0px))) 6px !important;
  grid-template-columns: none !important;
}
.tools::-webkit-scrollbar { display: none; }
.tools button {
  flex: 0 0 60px !important;
  scroll-snap-align: start;
  padding: 6px 2px !important;
  gap: 4px !important;
}
.tools button svg { width: 21px; height: 21px; }
.tools button span { font-size: 10px !important; white-space: nowrap; }
.tools button.active {
  color: var(--accent);
  background: rgba(255,77,103,.12);
  border-radius: 12px;
}


/* ===== v79: наложение в кадре видно и масштабируется ручкой ================= */
.pip-layer { z-index: 3 !important; }
.text-layer { z-index: 4 !important; }
.sticker-layer { z-index: 4 !important; }
.stage-empty { z-index: 5 !important; }
.stage-bar { z-index: 6 !important; }

.pip-layer video.selected {
  box-shadow: 0 0 0 2px var(--accent), 0 0 12px rgba(255,77,103,.45) !important;
}
.pip-resize {
  position: absolute;
  right: -9px; bottom: -9px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
  pointer-events: auto;
  touch-action: none;
  cursor: nwse-resize;
  z-index: 2;
}
.pip-resize::after {
  content: '';
  position: absolute; inset: 5px;
  border-right: 1.5px solid #fff;
  border-bottom: 1.5px solid #fff;
}
.pip-resize.dragging { transform: scale(1.15); }


/* v79.1: наложение — обёртка с видео внутри, рамка и ручка видны */
.pip-layer .pip-item {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  border-radius: 6px;
  box-shadow: 0 0 0 1.5px rgba(255,255,255,.14);
  touch-action: none;
}
.pip-layer .pip-item video {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  pointer-events: none;
}
.pip-layer .pip-item.selected {
  box-shadow: 0 0 0 2px var(--accent), 0 0 12px rgba(255,77,103,.45);
}
.pip-layer .pip-item.pinching { box-shadow: 0 0 0 2px var(--accent); }

.pip-layer .pip-item video {
  position: static !important;
  transform: none !important;
  box-shadow: none !important;
  border: 0 !important;
}


/* v83: живой бейдж размер/угол в кадре */
.pinch-badge {
  position: absolute;
  left: 50%; top: 10px;
  transform: translateX(-50%);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(12,13,18,.86);
  border: 1px solid rgba(255,255,255,.14);
  color: #fff;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  pointer-events: none;
  transition: opacity .14s ease;
  z-index: 7;
}
.pinch-badge.show { opacity: 1; }


/* v84: битое наложение видно сразу — рамка и подпись вместо пустоты */
.pip-layer .pip-item.broken {
  box-shadow: 0 0 0 2px #ff4d67 !important;
  background: rgba(255,77,103,.12);
  min-width: 60px;
  min-height: 40px;
}
.pip-layer .pip-item.broken::after {
  content: 'нет файла';
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 10px; color: #ffd7dd;
}


/* v90: скрытые подсказки + шестерёнка в проектах */
body.no-hints .sheet .hint { display: none; }


/* v94: быстрые кнопки в шапке таймлайна */
.tl-quick { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.tl-ico {
  width: 26px; height: 22px; border-radius: 7px; border: 1px solid var(--border);
  background: rgba(255,255,255,.06); color: var(--foreground); font-size: 13px;
  line-height: 1; display: grid; place-items: center; padding: 0;
}
.tl-ico:active { background: rgba(255,255,255,.16); }
.tl-ico.on { color: var(--accent); border-color: var(--accent); }


/* v97 (ревью): зоны нажатия у мелких кнопок рельсы и шапки — не меньше 40 px */
.rail-btns button, .tl-zoom, .lane-add { position: relative; }
.rail-btns button::after, .tl-zoom::after {
  content: ''; position: absolute; inset: -9px; border-radius: 8px;
}


/* v98 (ревью L4): служебные подписи читаемее — не мельче 11/9.5 px */
.tools span { font-size: 11px; }
.tl-title, .tl-clock { font-size: 11px; }
.cb-idx { font-size: 9.5px; }


/* v102: поле описания для авто-монтажа */
.prompt-input {
  width: 100%;
  min-height: 62px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  padding: 10px 12px;
}
.prompt-input:focus { outline: none; border-color: var(--accent); }
