:root {
  --bg: #0f1419;
  --surface: #1a222c;
  --surface-2: #232e3a;
  --surface-3: #2b3947;
  --border: #2c3947;
  --text: #e6edf3;
  --text-dim: #8b98a5;
  --accent: #2ea6ff;
  --accent-hover: #1e8fe0;
  --success: #2ecc71;
  --danger: #e74c3c;
  --video: #2f6f9f;
  --video-2: #3a6ea5;
  --audio: #2f9f6f;
  --image: #9f7f2f;
  --text-clip: #7a5cf0;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand-mark { font-size: 18px; }
.header-right { display: flex; align-items: center; gap: 10px; }
.privacy-badge {
  font-size: 12px; color: var(--success);
  background: rgba(46,204,113,.1); border: 1px solid rgba(46,204,113,.3);
  padding: 5px 10px; border-radius: 999px;
}
#langBtn { min-width: 40px; font-weight: 700; }

/* ---------- Мини-справка ---------- */
.help-overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.help-overlay.hidden { display: none; }
.help-modal {
  position: relative; width: min(680px, 100%); max-height: 85vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.help-close {
  position: absolute; top: 12px; right: 14px; width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-dim);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.help-close:hover { color: var(--text); }
.help-modal h2 { margin: 0 0 14px; font-size: 20px; }
.help-modal h3 { margin: 18px 0 6px; font-size: 15px; }
.help-modal p { margin: 6px 0; font-size: 13.5px; line-height: 1.55; color: var(--text-dim); }
.help-modal ul { margin: 6px 0; padding-left: 20px; }
.help-modal li { font-size: 13.5px; line-height: 1.55; color: var(--text-dim); margin: 3px 0; }
.help-modal b { color: var(--text); }

.app { display: flex; flex-direction: column; height: calc(100vh - 49px); }

/* ---------- Кнопки ---------- */
.btn {
  border: none; border-radius: 8px; padding: 8px 14px;
  font-size: 14px; font-weight: 600; cursor: pointer; color: var(--text);
  background: var(--surface-2); transition: background .15s, opacity .15s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-danger { background: rgba(231,76,60,.15); color: #ff8f84; }
.btn-danger:hover:not(:disabled) { background: rgba(231,76,60,.3); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-icon { width: 38px; height: 34px; padding: 0; font-size: 15px; }

/* ---------- Верхняя зона ---------- */
.stage { display: flex; flex: 1; min-height: 0; }

.pool {
  width: 210px; flex-shrink: 0; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; background: var(--surface);
}
.pool-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px;
}
.pool-head span { flex: 1; }
.pool-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.pool-list.dragover { outline: 2px dashed var(--accent); outline-offset: -6px; }
.pool-empty { color: var(--text-dim); font-size: 13px; line-height: 1.5; padding: 8px; }
.pool-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  cursor: grab; user-select: none;
}
.pool-item:active { cursor: grabbing; }
.pool-thumb {
  width: 40px; height: 30px; border-radius: 5px; object-fit: cover;
  background: #000; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.pool-meta { min-width: 0; flex: 1; }
.pool-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pool-sub { font-size: 11px; color: var(--text-dim); }
.pool-del {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--border);
  background: transparent; color: var(--text-dim); font-size: 16px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .12s;
}
.pool-item:hover .pool-del { opacity: 1; }
.pool-del:hover { background: rgba(231,76,60,.2); color: #ff8f84; border-color: rgba(231,76,60,.4); }

.preview-area { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #0a0e12; }
.canvas-box { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 12px; }
#canvas { max-width: 100%; max-height: 100%; background: #000; border-radius: 8px; box-shadow: 0 4px 24px rgba(0,0,0,.4); }
.transport {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  border-top: 1px solid var(--border); background: var(--surface);
}
.time { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text-dim); }
.spacer { flex: 1; }
.zoom { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.zoom input { width: 110px; }
.export-fmt select {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 8px; font-size: 13px;
}

.inspector { width: 240px; flex-shrink: 0; border-left: 1px solid var(--border); background: var(--surface); padding: 14px; overflow-y: auto; }
.insp-empty { color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.insp-body h3 { margin: 0 0 14px; font-size: 15px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; color: var(--text-dim); }
.field select { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px; font-size: 14px; }
.field input[type="range"] { width: 100%; }
.field textarea { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px; font-size: 14px; resize: vertical; font-family: inherit; }
.text-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.text-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.text-inline select { padding: 5px 6px; font-size: 13px; }
.text-inline input[type="color"] { width: 28px; height: 24px; padding: 0; border: 1px solid var(--border); border-radius: 5px; background: none; cursor: pointer; }
.insp-actions { flex-direction: row; gap: 8px; }
.insp-hint { font-size: 12px; color: var(--text-dim); line-height: 1.5; }

/* ---------- Экспорт ---------- */
.export-bar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--surface-2); border-top: 1px solid var(--border); }
.export-track { flex: 1; height: 8px; background: var(--surface); border-radius: 999px; overflow: hidden; }
.export-fill { height: 100%; width: 0%; background: var(--accent); transition: width .2s; }
#exportText { font-size: 13px; color: var(--text-dim); white-space: nowrap; }

/* ---------- Таймлайн ---------- */
/* Высота = линейка 28 + 5 дорожек×56 + border-top 1 = 309; иначе нижняя дорожка (Аудио 2) обрезалась */
.tl { height: 309px; display: flex; border-top: 1px solid var(--border); background: var(--surface); }
.tl-labels { width: 96px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--surface); }
.tl-corner { height: 28px; border-bottom: 1px solid var(--border); }
.tl-label {
  height: 56px; display: flex; align-items: center; padding: 0 10px;
  font-size: 12px; color: var(--text-dim); border-bottom: 1px solid var(--border);
}
.tl-label .dot { width: 8px; height: 8px; border-radius: 2px; margin-right: 7px; }
.tl-label.video .dot { background: var(--video); }
.tl-label.audio .dot { background: var(--audio); }
.tl-label.text .dot { background: var(--text-clip); }
.tl-label .mag { margin-left: 4px; font-size: 11px; }

.tl-scroll { flex: 1; overflow-x: auto; overflow-y: hidden; position: relative; }
.tl-content { position: relative; height: 100%; min-width: 100%; }

.ruler { height: 28px; position: relative; border-bottom: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
.ruler .tick { position: absolute; top: 0; height: 100%; border-left: 1px solid var(--border); padding-left: 4px; font-size: 10px; color: var(--text-dim); line-height: 28px; }

.lane {
  height: 56px; position: relative; border-bottom: 1px solid var(--border);
  background: repeating-linear-gradient(90deg, transparent, transparent 59px, rgba(255,255,255,.02) 59px, rgba(255,255,255,.02) 60px);
}
.lane.dragover { background: rgba(46,166,255,.08); }
.lane.audio { background-color: rgba(46,159,111,.04); }
.lane.text { background-color: rgba(122,92,240,.05); }
.lane.magnetic { background-color: rgba(46,166,255,.05); }

.clip {
  position: absolute; top: 5px; height: 46px; border-radius: 6px; overflow: hidden;
  background: var(--video); border: 1px solid rgba(255,255,255,.15); cursor: grab;
  user-select: none; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.clip.audio { background: var(--audio); }
.clip.image { background: var(--image); }
.clip.text { background: var(--text-clip); }
.clip.selected { outline: 2px solid #fff; z-index: 3; }

/* Плёнка (раскадровка) внутри клипа */
.clip-thumbs {
  position: absolute; inset: 0; z-index: 0; display: flex; overflow: hidden;
  background: #14202b;
}
.clip-thumbs.cover { background-size: cover; background-position: center; }
.clip-thumbs.pending {
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.05) 0, rgba(255,255,255,.05) 6px, transparent 6px, transparent 12px);
}
.thumb-tile {
  height: 100%; flex: 0 0 auto; background-size: cover; background-position: center;
  border-right: 1px solid rgba(0,0,0,.28);
}

/* Осциллограмма внутри аудиоклипа */
.clip-wave {
  position: absolute; inset: 0; z-index: 0; overflow: hidden;
}
.clip-wave canvas { display: block; }
.clip-wave.pending {
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.06) 0, rgba(255,255,255,.06) 6px, transparent 6px, transparent 12px);
}

.clip-label {
  position: relative; z-index: 1; padding: 3px 8px; font-size: 11px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,.6), rgba(0,0,0,0));
  text-shadow: 0 1px 2px rgba(0,0,0,.85);
}
.clip-fx {
  position: absolute; z-index: 1; bottom: 3px; left: 6px; font-size: 10px; opacity: .95;
  pointer-events: none; text-shadow: 0 1px 2px rgba(0,0,0,.85);
}
.clip-handle { position: absolute; z-index: 2; top: 0; width: 9px; height: 100%; cursor: ew-resize; background: rgba(0,0,0,.3); }
.clip-handle.l { left: 0; } .clip-handle.r { right: 0; }
.clip-handle:hover { background: rgba(255,255,255,.4); }

/* Дорожка-приёмник при перетаскивании клипа между рядами */
.lane.drop-target { background: rgba(46,166,255,.1); box-shadow: inset 0 0 0 2px rgba(46,166,255,.55); }

/* Маркер перехода на стыке двух клипов */
.trans-marker {
  position: absolute; top: 50%; z-index: 4; transform: translate(-50%, -50%);
  width: 20px; height: 20px; border-radius: 5px; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #0f1419; background: #ffd76a;
  box-shadow: 0 1px 4px rgba(0,0,0,.5); border: 1px solid rgba(0,0,0,.3);
}

.playhead { position: absolute; top: 0; left: 0; width: 2px; height: 100%; background: #ff4d4d; z-index: 5; pointer-events: none; }
.playhead-grip {
  position: absolute; top: 0; left: -6px; width: 14px; height: 14px;
  background: #ff4d4d; border-radius: 0 0 4px 4px; pointer-events: auto; cursor: ew-resize;
}

.hidden { display: none !important; }

@media (max-width: 820px) {
  .pool, .inspector { display: none; }
}
