:root {
  --bg: #151112;
  --panel: #1d1819;
  --panel-2: #262021;
  --line: #322a2a;
  --text: #f3ece8;
  --muted: #8c827f;
  --accent: #d2a699;
  --accent-ink: #2a1b17;
  --accent-soft: rgba(210, 166, 153, 0.16);
  --danger: #e0786e;
  --radius: 16px;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; }
body { overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

.app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.boot { flex: 1; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- верх ---------- */
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px 6px; }
.icon-btn { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; color: var(--text); }
.icon-btn:active { background: var(--panel-2); }
.progress { flex: 1; display: grid; grid-auto-flow: column; gap: 4px; }
.progress span { height: 2px; border-radius: 2px; background: #4a4040; }
.progress span.on { background: var(--accent); }
.h1 { font-family: var(--serif); font-weight: 700; font-size: 21px; letter-spacing: .2px; margin: 4px 16px 10px; }
.header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 8px; }
.header .h1 { margin: 0; }
.pill-btn { background: var(--accent); color: var(--accent-ink); font-weight: 600; padding: 8px 16px; border-radius: 999px; }
.pill-btn:disabled { opacity: .5; }
.sub { color: var(--muted); font-size: 12px; }

/* ---------- превью ---------- */
.stage { display: flex; justify-content: center; padding: 4px 16px 12px; position: relative; }
.preview { position: relative; height: min(40vh, 520px); aspect-ratio: 9 / 16; border-radius: 14px; overflow: hidden; background: #0e0b0c; box-shadow: 0 10px 40px rgba(0,0,0,.45); }
.preview.compact { height: min(34vh, 420px); }
.preview img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: opacity .18s; }
.preview .badge { position: absolute; top: 8px; left: 8px; font-size: 10px; background: rgba(0,0,0,.55); padding: 3px 7px; border-radius: 8px; z-index: 3; }
.preview .loading { position: absolute; right: 8px; top: 8px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin .7s linear infinite; z-index: 3; opacity: 0; transition: opacity .2s; }
.preview.busy .loading { opacity: 1; }
.preview .placeholder { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; color: var(--muted); font-size: 12px; background: linear-gradient(110deg, #1a1516 30%, #241e1f 50%, #1a1516 70%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.ig { position: absolute; left: 0; right: 0; font-size: 9px; color: rgba(255,255,255,.75); padding: 4px 6px; z-index: 2; pointer-events: none; }
.ig.top { top: 0; height: 11%; border-bottom: 1px dashed rgba(255,255,255,.55); background: rgba(0,0,0,.25); }
.ig.bottom { bottom: 0; height: 17%; border-top: 1px dashed rgba(255,255,255,.35); background: rgba(0,0,0,.35); display: flex; align-items: flex-start; }
.preview .fs { position: absolute; right: 6px; bottom: 6px; z-index: 4; background: rgba(0,0,0,.45); }
.preview-full { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 50; display: grid; place-items: center; }
.preview-full img { height: 92vh; aspect-ratio: 9/16; object-fit: cover; border-radius: 14px; }

/* ---------- контролы ---------- */
.controls { padding: 0 16px; display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.label { font-weight: 600; }
.value { font-weight: 700; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--panel-2); border-radius: 999px; padding: 3px; }
.seg button { padding: 9px 8px; border-radius: 999px; font-weight: 600; color: var(--text); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { background: var(--panel-2); padding: 8px 13px; border-radius: 999px; font-weight: 600; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.chip small { font-weight: 500; opacity: .65; }
.cards { display: grid; grid-auto-flow: column; grid-auto-columns: calc((100% - 16px) / 3); gap: 8px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x mandatory; }
.cards::-webkit-scrollbar { display: none; }
.card { scroll-snap-align: start; background: var(--panel-2); border-radius: 12px; overflow: hidden; border: 2px solid transparent; text-align: center; padding: 0 0 6px; }
.card img { display: block; width: 100%; aspect-ratio: 2.2 / 1; object-fit: cover; background: #120e0f; }
.card.wide img { aspect-ratio: 2 / 1; }
.card span { display: block; font-size: 11px; font-weight: 600; margin-top: 5px; padding: 0 4px; }
.card.on { border-color: var(--accent); }
.slider { width: 100%; -webkit-appearance: none; appearance: none; height: 2px; background: linear-gradient(to right, var(--accent) var(--p, 50%), #4a4040 var(--p, 50%)); border-radius: 2px; margin: 10px 0 2px; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(210,166,153,.15); }
.slider::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--accent); }
.scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.toggle { width: 34px; height: 20px; border-radius: 999px; background: #4a4040; position: relative; flex: none; transition: background .2s; }
.toggle::after { content: ""; position: absolute; width: 14px; height: 14px; top: 3px; left: 3px; border-radius: 50%; background: #1a1516; transition: transform .2s; }
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(14px); }
.textarea { width: 100%; min-height: 76px; resize: vertical; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; outline: none; text-transform: uppercase; font-weight: 600; line-height: 1.35; }
.textarea:focus { border-color: var(--accent); }
.input { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; outline: none; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.4; }
.ghost { width: 100%; background: var(--panel-2); border-radius: 999px; padding: 11px; font-weight: 700; }
.danger { color: var(--danger); }

/* ---------- низ мастера ---------- */
.footer { margin-top: auto; padding: 14px 16px calc(14px + var(--safe-bottom)); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.footer.sticky { position: sticky; bottom: 0; z-index: 9; padding-top: 22px; background: linear-gradient(to bottom, transparent, var(--bg) 26px); }
.cta { width: 100%; background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 12px; font-weight: 700; }
.cta:disabled { opacity: .5; }
.link { color: var(--accent); font-size: 13px; font-weight: 600; }

/* ---------- продвинутый режим ---------- */
.sheet { flex: 1; background: var(--panel); border-radius: 18px 18px 0 0; padding: 14px 0 calc(78px + var(--safe-bottom)); margin-top: 6px; min-height: 40vh; }
.sheet .h2 { font-family: var(--serif); font-weight: 700; font-size: 18px; margin: 0 16px 12px; }
.tabbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 560px; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--panel); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-bottom)); z-index: 10; }
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); font-size: 10px; padding: 4px 0; position: relative; }
.tabbar button svg { width: 20px; height: 20px; }
.tabbar button.on { color: var(--accent); }
.tabbar button.on::before { content: ""; position: absolute; top: -7px; width: 18px; height: 2px; border-radius: 2px; background: var(--accent); }

/* ---------- правки ---------- */
.list { display: flex; flex-direction: column; gap: 6px; }
.phrase { display: flex; gap: 10px; align-items: flex-start; background: var(--panel-2); border-radius: 12px; padding: 10px 12px; text-align: left; width: 100%; }
.phrase .t { color: var(--muted); font-size: 11px; min-width: 34px; padding-top: 2px; font-variant-numeric: tabular-nums; }
.phrase .txt { flex: 1; line-height: 1.4; }
.phrase.removed .txt { text-decoration: line-through; color: var(--muted); }
.phrase.selected { outline: 2px solid var(--accent); }
.tag { font-size: 10px; background: var(--accent-soft); color: var(--accent); padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.cuts-switch { background: var(--panel-2); border-radius: 14px; padding: 10px 12px; }
.cuts-switch .hint { margin-top: 4px; }
.h3 { font-weight: 700; font-size: 15px; margin-top: 6px; }
.muted { color: var(--muted); }

/* ---------- вкладка «Кадры»: плеер фразы, дубли, все фразы ---------- */
.cuts-tab { gap: 12px; }
.clip-stage { position: sticky; top: 0; z-index: 5; background: var(--panel); margin: 0 -16px; padding: 4px 16px 10px; border-bottom: 1px solid var(--line); }
.clip { display: flex; gap: 12px; align-items: stretch; }
.clip-box { position: relative; height: min(30vh, 300px); aspect-ratio: 9 / 16; flex: none; border-radius: 14px; overflow: hidden; background: #0e0b0c; box-shadow: 0 8px 30px rgba(0,0,0,.4); cursor: pointer; }
.clip-box video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.clip-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 14px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.clip.has .clip-empty { display: none; }
.clip-box .loading { position: absolute; right: 8px; top: 8px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin .7s linear infinite; opacity: 0; transition: opacity .2s; }
.clip-box.busy .loading { opacity: 1; }
.clip-play { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 44px; height: 44px; border-radius: 50%; background: rgba(0,0,0,.5); display: grid; place-items: center; font-size: 16px; padding-left: 3px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.clip.has:not(.playing) .clip-box:not(.busy) .clip-play { opacity: 1; }
.clip-state { position: absolute; left: 8px; top: 8px; font-size: 10px; font-weight: 700; background: rgba(0,0,0,.55); padding: 3px 7px; border-radius: 8px; display: none; }
.clip.has .clip-state { display: block; }
.clip-state.out { background: rgba(224,120,110,.85); color: #fff; }
.clip-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; gap: 8px; }
.clip-label { font-weight: 700; font-size: 13px; line-height: 1.35; }
.clip-row { display: flex; align-items: center; gap: 8px; }
.clip-bar { flex: 1; height: 3px; border-radius: 3px; background: #4a4040; overflow: hidden; }
.clip-bar i { display: block; height: 100%; width: 0; background: var(--accent); }
.clip-left { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.clip-btn { width: 28px; height: 28px; border-radius: 50%; background: var(--panel-2); font-size: 15px; display: grid; place-items: center; flex: none; }
.clip:not(.has) .clip-row { opacity: .35; pointer-events: none; }
/* кнопка «Убрать из ролика / Вернуть в ролик» — под подписью справа от видео */
.clip { position: relative; }
.clip-meta { padding-bottom: 44px; }
.clip-act { position: absolute; right: 0; bottom: 0; background: var(--panel-2); border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 12px; color: var(--danger); }
.clip-act.restore { background: var(--accent); color: var(--accent-ink); }

.takes-block { display: flex; flex-direction: column; gap: 6px; }
.take-group { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.take-title { font-weight: 700; line-height: 1.35; }
.takes { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(150px, 46%); gap: 8px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x mandatory; padding: 4px 0 2px; }
.takes::-webkit-scrollbar { display: none; }
.take { scroll-snap-align: start; text-align: left; background: var(--panel-2); border: 2px solid transparent; border-radius: 14px; padding: 10px 11px; display: flex; flex-direction: column; gap: 6px; min-height: 96px; }
.take.on { border-color: var(--accent); }
.take.playing { box-shadow: inset 0 0 0 1px var(--accent-soft); background: #2d2526; }
.take-head { display: flex; align-items: center; font-size: 12px; }
.take-head span { color: var(--muted); }
.take-head .check { margin-left: auto; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; background: var(--accent); color: var(--accent-ink); opacity: 0; }
.take.on .take-head .check { opacity: 1; }
.take-txt { font-size: 12px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.take.all { justify-content: flex-start; }

.cuts-tab .phrase { cursor: pointer; align-items: center; }
.cuts-tab .phrase .t { display: flex; flex-direction: column; gap: 1px; }
.cuts-tab .phrase .t small { font-size: 10px; opacity: .8; }
.cuts-tab .phrase .txt .tag { margin-left: 6px; vertical-align: 1px; text-decoration: none; display: inline-block; }
.cuts-tab .phrase.removed { opacity: .72; }
/* слова фразы — по нажатию вырезаются (зачёркнуты, приглушены) и возвращаются */
.cuts-tab .phrase .txt .w { border-radius: 5px; padding: 1px 1px; cursor: pointer; transition: background .15s, color .15s; }
.cuts-tab .phrase .txt .w:active { background: var(--accent-soft); }
.cuts-tab .phrase .txt .w.cut { text-decoration: line-through; text-decoration-color: var(--danger); color: var(--muted); background: rgba(224,120,110,.12); }
.cuts-tab .phrase .t .pl { font-size: 9px; color: var(--accent); margin-bottom: 1px; }
.phrase-act { flex: none; font-size: 11px; font-weight: 700; padding: 6px 10px; border-radius: 999px; background: var(--panel); color: var(--muted); }
.phrase-act.restore { background: var(--accent-soft); color: var(--accent); }
.words { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.word { background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 2px 4px; min-width: 2ch; outline: none; }
.word:focus { border-color: var(--accent); background: var(--panel); }
.word.changed { color: var(--accent); }
.sound { display: flex; align-items: center; justify-content: space-between; background: var(--panel-2); border-radius: 12px; padding: 10px 12px; }
.sound.removed span { color: var(--muted); text-decoration: line-through; }
.preset { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 12px; padding: 10px 12px; }
.preset b { flex: 1; font-weight: 600; }
.preset button { font-size: 12px; font-weight: 600; color: var(--accent); padding: 4px 6px; }
.locked { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 32px; gap: 10px; }
.locked .h1 { margin: 0; }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: #2d2526; padding: 10px 16px; border-radius: 12px; z-index: 60; font-weight: 600; box-shadow: 0 6px 24px rgba(0,0,0,.4); }

/* ---------- палитра из дашборда ---------- */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0 6px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); font-size: 11px; color: var(--muted); }
.swatch.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.swatch.auto { background: var(--panel-2); }

/* горизонтальные ленты: с компьютера — колесо, перетаскивание и стрелки по краям */
.hs { position: relative; }
.hs > .cards, .hs > .chips.scroll { cursor: default; }
.hs > .dragging { scroll-snap-type: none; cursor: grabbing; user-select: none; }
.hs > .dragging * { pointer-events: none; }
.hs-btn { display: none; position: absolute; top: 50%; transform: translateY(-50%); z-index: 3; width: 32px; height: 32px;
  border-radius: 50%; border: 0; background: rgba(20, 20, 24, .72); color: #fff; font-size: 22px; line-height: 30px;
  text-align: center; padding: 0; box-shadow: 0 2px 8px rgba(0, 0, 0, .35); cursor: pointer; }
.hs-btn.prev { left: -6px; }
.hs-btn.next { right: -6px; }
@media (hover: hover) and (pointer: fine) {
  .hs.can-prev > .hs-btn.prev, .hs.can-next > .hs-btn.next { display: block; }
  .hs > .cards, .hs > .chips.scroll { cursor: grab; }
}
