/* ═══════════ VARIABLES ═══════════ */
:root {
  --bg: #08080D;
  --surface: #0F0F17;
  --surface2: #161622;
  --border: #1E1E2E;
  --accent: #00FFD1;
  --accent2: #7B61FF;
  --text: #E8E8ED;
  --muted: #6B6B80;
  --danger: #FF4466;
  --radius: 14px;
  --font: 'Outfit', sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

/* ═══════════ RESET ═══════════ */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font); overflow-x: hidden; min-height: 100vh;
}
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
button { cursor: pointer; font-family: var(--font); }
input { font-family: var(--font); }

/* ═══════════ SCREENS ═══════════ */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; }

/* ═══════════ UPLOAD ═══════════ */
#upload-screen {
  flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 20px;
}
.logo { display: flex; align-items: center; gap: 10px; margin-bottom: 36px; }
.logo svg { color: var(--accent); }
.logo-text { font-size: 28px; font-weight: 800; color: #fff; letter-spacing: -1px; }
.logo-badge {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #000; font-size: 10px; font-weight: 700; padding: 3px 8px;
  border-radius: 5px; text-transform: uppercase; letter-spacing: 1px;
}

.hero-title {
  font-size: clamp(28px, 5vw, 42px); font-weight: 800; color: #fff;
  text-align: center; line-height: 1.15; letter-spacing: -1.5px; margin-bottom: 12px;
}
.hero-title span {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.hero-sub {
  color: var(--muted); text-align: center; font-size: 16px;
  margin-bottom: 36px; line-height: 1.5; max-width: 480px;
}

/* Tabs */
.tab-bar { display: flex; gap: 4px; background: var(--surface); border-radius: 12px; padding: 4px; margin-bottom: 24px; }
.tab-btn {
  padding: 10px 24px; border: none; border-radius: 10px; background: transparent;
  color: var(--muted); font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; transition: all .2s;
}
.tab-btn.active { background: var(--surface2); color: #fff; }
.tab-btn:hover { color: #fff; }

/* Dropzone */
.dropzone {
  width: 100%; max-width: 520px; border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 56px 24px; display: flex; flex-direction: column; align-items: center;
  cursor: pointer; transition: all .25s; background: var(--surface);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: rgba(0,255,209,0.03); }
.dropzone.has-file { border-color: var(--accent); border-style: solid; }
.drop-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.drop-text { font-size: 17px; font-weight: 600; color: #fff; margin-bottom: 6px; }
.drop-sub { font-size: 13px; color: var(--muted); }
.file-name { color: var(--accent); font-weight: 600; font-size: 15px; }
.file-change { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* YouTube input */
.yt-input {
  width: 100%; max-width: 520px; display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; transition: border-color .2s;
}
.yt-input:focus-within { border-color: var(--accent2); }
.yt-input input {
  flex: 1; background: transparent; border: none; color: #fff; font-size: 15px; outline: none;
}
.yt-input input::placeholder { color: var(--muted); }

/* Settings */
.settings-section { width: 100%; max-width: 520px; margin-top: 20px; }
.settings-toggle {
  background: none; border: none; color: var(--muted); font-size: 13px;
  display: flex; align-items: center; gap: 6px; padding: 4px 0;
}
.settings-toggle:hover { color: var(--text); }
.settings-panel {
  display: none; margin-top: 12px; padding: 16px; background: var(--surface);
  border-radius: 12px; border: 1px solid var(--border);
}
.settings-panel.open { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.settings-panel label {
  font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px;
}
.settings-panel input {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; color: #fff; font-size: 13px; outline: none;
}
.settings-panel input:focus { border-color: var(--accent); }
.api-key-input { grid-column: 1 / -1; }

/* Go button */
.go-btn {
  margin-top: 28px; padding: 16px 48px; border-radius: var(--radius); border: none;
  background: linear-gradient(135deg, var(--accent), #00C4A0); color: #000;
  font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 10px;
  transition: all .2s; letter-spacing: -0.3px;
}
.go-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 30px rgba(0,255,209,0.2); }
.go-btn:disabled { opacity: 0.4; pointer-events: none; }

.features { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 24px; }
.feat-tag { background: var(--surface); color: var(--muted); font-size: 12px; padding: 6px 14px; border-radius: 20px; }

/* ═══════════ PROCESSING ═══════════ */
#processing-screen { flex-direction: column; align-items: center; justify-content: center; padding: 40px; }
.process-glow {
  position: fixed; width: 400px; height: 400px; border-radius: 50%;
  background: radial-gradient(circle, rgba(0,255,209,0.06) 0%, transparent 70%);
  top: 30%; left: 50%; transform: translate(-50%,-50%); pointer-events: none;
}
.progress-wrap { width: 100%; max-width: 440px; margin-top: 36px; display: flex; align-items: center; gap: 16px; }
.progress-track { flex: 1; height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.progress-bar {
  height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 3px; transition: width .6s ease; width: 0%;
}
.progress-pct { color: var(--accent); font-family: var(--mono); font-weight: 600; font-size: 22px; min-width: 52px; }
.progress-label { color: var(--muted); font-size: 14px; margin-top: 16px; min-height: 20px; }
.pipeline-steps { display: flex; gap: 24px; margin-top: 36px; }
.p-step {
  display: flex; align-items: center; gap: 6px; font-size: 12px;
  color: var(--muted); opacity: 0.3; transition: opacity .4s;
}
.p-step.active { opacity: 1; }
.p-step-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); transition: background .4s; }
.p-step.active .p-step-dot { background: var(--accent); }
.error-msg { color: var(--danger); font-size: 14px; margin-top: 16px; max-width: 500px; text-align: center; }

/* ═══════════ CLIPS LIST ═══════════ */
#clips-screen { flex-direction: column; padding: 24px; max-width: 1000px; margin: 0 auto; width: 100%; }
.clips-header { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.clips-header h2 { font-size: 24px; font-weight: 700; color: #fff; letter-spacing: -0.5px; }
.clips-subhead { color: var(--muted); font-size: 13px; }

.back-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  color: var(--muted); padding: 8px; display: flex; transition: all .2s;
}
.back-btn:hover { color: #fff; border-color: #444; }

.dl-all-btn {
  margin-left: auto; padding: 10px 20px; border-radius: 10px; border: 1px solid var(--border);
  background: transparent; color: #fff; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; transition: all .2s;
}
.dl-all-btn:hover { border-color: var(--accent); color: var(--accent); }

.clip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.clip-card {
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); cursor: pointer; transition: all .25s;
}
.clip-card:hover { border-color: #333; transform: translateY(-2px); box-shadow: 0 8px 30px rgba(0,0,0,0.3); }
.clip-thumb {
  height: 150px; background: linear-gradient(135deg, var(--surface2), var(--bg));
  position: relative; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.clip-thumb-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; z-index: 0;
}
.clip-play {
  color: #fff; opacity: 0.6; transition: opacity .2s; z-index: 1;
  background: rgba(0,0,0,0.45); width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.clip-card:hover .clip-play { opacity: 1; background: rgba(0,0,0,0.65); }
.clip-dur {
  position: absolute; bottom: 8px; right: 8px; background: rgba(0,0,0,0.75);
  color: #fff; font-size: 11px; font-family: var(--mono); padding: 3px 8px; border-radius: 4px;
}
.clip-score {
  position: absolute; top: 10px; right: 10px;
  background: linear-gradient(135deg, var(--accent), #00C4A0);
  color: #000; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 6px;
}
.clip-info { padding: 16px; }
.clip-rank { color: var(--accent); font-size: 11px; font-weight: 700; font-family: var(--mono); margin-bottom: 4px; }
.clip-title { color: #fff; font-size: 16px; font-weight: 700; margin-bottom: 6px; letter-spacing: -0.3px; }
.clip-hook { color: var(--muted); font-size: 13px; margin-bottom: 6px; line-height: 1.4; }
.clip-why { color: var(--accent2); font-size: 12px; margin-bottom: 8px; }
.clip-time { color: #333; font-size: 11px; font-family: var(--mono); }

/* ═══════════ EDITOR ═══════════ */
#editor-screen { flex-direction: column; height: 100vh; overflow: hidden; }
.editor-header {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.editor-clip-num { color: var(--accent); font-size: 12px; font-weight: 700; font-family: var(--mono); }
.editor-clip-title { color: #fff; font-size: 15px; font-weight: 600; margin-left: 8px; }
.header-actions { margin-left: auto; display: flex; gap: 8px; }

.preview-btn {
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: #fff; font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 6px; transition: all .2s;
}
.preview-btn:hover { border-color: #444; }

.export-btn {
  padding: 8px 16px; border-radius: 8px; border: none;
  background: linear-gradient(135deg, var(--accent), #00C4A0); color: #000;
  font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 6px;
}
.export-btn:hover { box-shadow: 0 4px 16px rgba(0,255,209,0.2); }

.editor-body { flex: 1; display: flex; overflow: hidden; }

/* Video panel */
.video-panel {
  flex: 0 0 360px; display: flex; flex-direction: column; align-items: center;
  padding: 24px; border-right: 1px solid var(--border); overflow-y: auto;
}
.phone-mock {
  width: 220px; background: #000; border-radius: 28px; padding: 10px 8px;
  border: 2px solid #1A1A1A; position: relative;
}
.phone-notch { width: 60px; height: 6px; background: #1A1A1A; border-radius: 3px; margin: 0 auto 8px; }
.phone-screen {
  width: 100%; aspect-ratio: 9/16; border-radius: 18px; overflow: hidden;
  position: relative; background: var(--bg);
}
.video-el { width: auto; height: 100%; background: #111; }

/* Превью шаблона в редакторе клипа */
.clip-container {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  overflow: hidden; z-index: 2;
}
.tpl-layers-below, .tpl-layers-above {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.tpl-layers-below { z-index: 1; background: #000; }
.tpl-layers-above { z-index: 3; }
.tpl-preview-layer {
  position: absolute; overflow: hidden;
}
.tpl-preview-layer > img, .tpl-preview-layer > video {
  width: 100%; height: 100%; object-fit: fill; display: block;
}

.sub-overlay {
  position: absolute; left: 50%; transform: translateX(-50%);
  padding: 6px 14px; border-radius: 6px; text-align: center;
  max-width: 88%; font-weight: 700; z-index: 2; pointer-events: none;
  transition: all .15s;
}

.play-btn-overlay {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 48px; height: 48px; border-radius: 50%; background: rgba(0,0,0,0.55);
  border: 2px solid rgba(255,255,255,0.25); color: #fff;
  display: flex; align-items: center; justify-content: center; z-index: 3; transition: all .2s;
}
.play-btn-overlay:hover { background: rgba(0,0,0,0.7); border-color: rgba(255,255,255,0.5); }

/* Timeline */
.timeline {
  width: 100%; display: flex; align-items: center; gap: 8px;
  margin-top: 20px; padding: 0 8px;
}
.time-label { color: var(--muted); font-size: 11px; font-family: var(--mono); min-width: 52px; }
.time-track {
  flex: 1; height: 6px; background: var(--surface2); border-radius: 3px;
  position: relative; cursor: pointer;
}
.time-fill {
  height: 100%; background: var(--accent); border-radius: 3px;
  position: absolute; top: 0; left: 0; pointer-events: none;
}
.time-head {
  width: 14px; height: 14px; border-radius: 50%; background: var(--accent);
  position: absolute; top: -4px; transform: translateX(-50%);
  box-shadow: 0 0 10px rgba(0,255,209,0.35); pointer-events: none;
}

/* Right panel */
.right-panel { flex: 1; display: flex; flex-direction: column; padding: 20px; overflow-y: auto; gap: 20px; }
.section-title {
  font-size: 13px; font-weight: 700; color: #fff; text-transform: uppercase;
  letter-spacing: 1px; display: flex; align-items: center; gap: 8px;
}
.sub-count { background: var(--surface2); color: var(--muted); font-size: 11px; padding: 2px 10px; border-radius: 10px; }

/* Style presets */
.preset-row { display: flex; gap: 6px; flex-wrap: wrap; }
.preset-btn {
  width: 68px; height: 62px; border-radius: 10px; background: var(--surface);
  border: 2px solid var(--border); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; transition: all .2s;
  flex-shrink: 0;
}
.preset-btn:hover { border-color: #444; }
.preset-btn.active { border-color: var(--accent); box-shadow: 0 0 12px rgba(0,255,209,0.1); }
.preset-label { font-size: 12px; font-weight: 700; }
.preset-name { font-size: 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* Animation buttons */
.anim-row { display: flex; gap: 6px; flex-wrap: wrap; }
.anim-btn {
  padding: 6px 10px; border-radius: 8px; background: var(--surface);
  border: 1px solid var(--border); color: var(--muted); font-size: 11px;
  transition: all .15s; white-space: nowrap;
}
.anim-btn:hover { border-color: #444; color: var(--text); }
.anim-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(0,255,209,0.05); }

/* Controls */
.controls-grid { display: flex; flex-direction: column; gap: 14px; }
.ctrl-row { display: flex; align-items: center; gap: 12px; }
.ctrl-label { font-size: 12px; color: var(--muted); min-width: 70px; }
.ctrl-val { font-size: 12px; color: var(--muted); font-family: var(--mono); min-width: 40px; }
input[type=range] { flex: 1; accent-color: var(--accent); }
.color-picks { display: flex; gap: 6px; }
.color-dot {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; transition: all .15s;
}
.color-dot.active { border-color: #fff; box-shadow: 0 0 0 2px var(--bg), 0 0 12px currentColor; }

.pos-btn {
  padding: 6px 14px; border-radius: 6px; background: var(--surface);
  border: 1px solid var(--border); color: var(--muted); font-size: 12px; transition: all .2s;
}
.pos-btn.active { border-color: var(--accent); color: var(--accent); }

.color-any {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border);
  cursor: pointer; padding: 0; background: transparent; flex-shrink: 0;
}
.color-any::-webkit-color-swatch-wrapper { padding: 0; }
.color-any::-webkit-color-swatch { border: none; border-radius: 50%; }
.color-any::-moz-color-swatch { border: none; border-radius: 50%; }

.save-btn {
  padding: 8px 14px; border-radius: 8px; background: var(--surface);
  border: 1px solid var(--border); color: var(--muted); font-size: 13px; font-weight: 500;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: all .2s;
}
.save-btn:hover { color: #fff; border-color: #444; }
.save-btn.dirty {
  background: #3a2e15; border-color: #e0a64a; color: #ffc774;
}
.save-btn.dirty:hover { background: #453718; }

/* Subtitle list */
.sub-list { display: flex; flex-direction: column; gap: 4px; }
.sub-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; background: var(--surface); border: 1px solid transparent;
  cursor: pointer; transition: all .15s;
}
.sub-item:hover { background: var(--surface2); }
.sub-item.active { border-color: var(--accent); background: rgba(0,255,209,0.04); }
.sub-time { color: var(--muted); font-size: 11px; font-family: var(--mono); min-width: 52px; }
.sub-text { flex: 1; font-size: 13px; color: var(--text); }
.sub-edit-input {
  flex: 1; background: var(--bg); border: 1px solid var(--accent); border-radius: 4px;
  padding: 4px 8px; color: #fff; font-size: 13px; outline: none; font-family: var(--font);
}
.sub-edit-btn { background: none; border: none; color: var(--muted); display: flex; padding: 4px; }
.sub-edit-btn:hover { color: var(--accent); }

/* ═══════════ BATCH EXPORT ═══════════ */
.clips-header-actions { margin-left: auto; display: flex; gap: 8px; }

.batch-export-toggle {
  padding: 10px 20px; border-radius: 10px; border: none;
  background: linear-gradient(135deg, var(--accent2), #6246EA); color: #fff;
  font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; transition: all .2s;
}
.batch-export-toggle:hover { box-shadow: 0 4px 16px rgba(123,97,255,0.3); transform: translateY(-1px); }

.batch-panel {
  display: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px; margin-bottom: 24px;
  animation: batchSlideIn .3s ease;
}
.batch-panel.open { display: block; }

@keyframes batchSlideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.batch-panel-header { margin-bottom: 20px; }
.batch-panel-title { font-size: 18px; font-weight: 700; color: #fff; }
.batch-panel-desc { display: block; font-size: 13px; color: var(--muted); margin-top: 4px; }

.batch-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.batch-section { display: flex; flex-direction: column; gap: 12px; }
.batch-section-title {
  font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase;
  letter-spacing: 0.8px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}

.batch-preset-row { display: flex; gap: 6px; flex-wrap: wrap; }
.batch-preset-btn {
  padding: 6px 12px; border-radius: 8px; background: var(--surface2);
  border: 1px solid var(--border); color: var(--muted); font-size: 11px;
  font-weight: 600; cursor: pointer; transition: all .15s;
}
.batch-preset-btn:hover { border-color: #444; color: var(--text); }
.batch-preset-btn.active { border-color: var(--accent); color: var(--accent); }

.batch-progress {
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border);
}
.batch-progress-label {
  color: var(--muted); font-size: 13px; margin-top: 8px; text-align: center;
}

.batch-actions {
  display: flex; align-items: center; gap: 12px; margin-top: 20px;
  padding-top: 16px; border-top: 1px solid var(--border);
}
.batch-go-btn {
  flex: 1; padding: 14px 24px; border-radius: 12px; border: none;
  background: linear-gradient(135deg, var(--accent), #00C4A0); color: #000;
  font-size: 15px; font-weight: 700; display: flex; align-items: center;
  justify-content: center; gap: 8px; transition: all .2s;
}
.batch-go-btn:hover { box-shadow: 0 6px 24px rgba(0,255,209,0.2); transform: translateY(-1px); }
.batch-go-btn:disabled { opacity: 0.5; pointer-events: none; }
.batch-cancel-btn {
  padding: 14px 24px; border-radius: 12px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); font-size: 14px; transition: all .2s;
}
.batch-cancel-btn:hover { border-color: #444; color: var(--text); }

/* ═══════════ RESPONSIVE ═══════════ */
@media (max-width: 768px) {
  .editor-body { flex-direction: column; }
  .video-panel { flex: none; border-right: none; border-bottom: 1px solid var(--border); padding: 16px; }
  .phone-mock { width: 160px; }
  .clip-grid { grid-template-columns: 1fr; }
  .settings-panel.open { grid-template-columns: 1fr; }
  .pipeline-steps { flex-wrap: wrap; gap: 12px; }
  .batch-grid { grid-template-columns: 1fr; }
  .clips-header-actions { flex-wrap: wrap; }
}