:root {
  --bg: #0a0a0c;
  --bg2: #111116;
  --bg3: #18181f;
  --bg4: #1f1f28;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);
  --text: #f0eff5;
  --muted: #6b6a7a;
  --muted2: #9998aa;
  --accent: #7c6af7;
  --accent2: #5e4ee0;
  --accent-glow: rgba(124,106,247,0.15);
  --green: #3ecf8e;
  --green-glow: rgba(62,207,142,0.15);
  --amber: #f5a623;
  --red: #f56565;
  --radius: 10px;
  --radius-lg: 16px;
  --sel-color: #3ecf8e;
  --sel-glow: rgba(62,207,142,0.18);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
  padding-bottom: 120px;
}

/* ─── Header ─── */
header {
  border-bottom: 1px solid var(--border);
  padding: 0 clamp(1rem, 4vw, 2.5rem);
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10,10,12,0.92);
  backdrop-filter: blur(12px);
}

.logo {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; }

.badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(124,106,247,0.3);
  letter-spacing: 0.3px;
}

/* ─── Main layout ─── */
main { padding: clamp(1.5rem, 4vw, 3rem) clamp(1rem, 4vw, 2.5rem); max-width: 1100px; margin: 0 auto; }

/* ─── Setup card ─── */
.setup-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(1.25rem, 3vw, 2rem);
  margin-bottom: 2rem;
}
.setup-card h2 {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 1.25rem;
  color: var(--text);
}

.fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted2);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}
.field input,
.field textarea,
.field select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.field input::placeholder,
.field textarea::placeholder { color: var(--muted); }
.field input:focus,
.field textarea:focus,
.field select:focus { border-color: var(--accent); }
.field input[type="password"] { letter-spacing: 1px; }
.field textarea { resize: vertical; min-height: 130px; font-size: 14px; line-height: 1.6; }

/* ─── Run button ─── */
.run-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 13px 24px;
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius);
  font-family: 'Syne', sans-serif; font-weight: 600; font-size: 15px;
  cursor: pointer; transition: background 0.2s, transform 0.1s;
  margin-top: 1rem; letter-spacing: 0.2px;
}
.run-btn:hover { background: var(--accent2); }
.run-btn:active { transform: scale(0.99); }
.run-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.run-btn svg { width: 18px; height: 18px; }

/* ─── Progress ─── */
#progress-section { margin-bottom: 2rem; display: none; }
.progress-bar-wrap { background: var(--bg3); border-radius: 20px; height: 4px; overflow: hidden; margin-bottom: 10px; }
.progress-bar-fill { height: 100%; background: var(--accent); border-radius: 20px; transition: width 0.4s ease; width: 0%; }
.progress-label { font-size: 13px; color: var(--muted2); }

/* ─── Results ─── */
#results { display: none; }
.results-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1.5rem;
}
.results-title { font-family: 'Syne', sans-serif; font-weight: 700; font-size: 22px; }
.stats-row { display: flex; gap: 12px; flex-wrap: wrap; }
.stat-pill {
  font-size: 12px; padding: 4px 10px; border-radius: 20px;
  border: 1px solid var(--border2); color: var(--muted2);
}
.stat-pill span { font-weight: 600; color: var(--text); }

/* ─── Sentence blocks ─── */
.sentence-block {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); margin-bottom: 1.5rem;
  overflow: hidden; animation: fadeUp 0.35s ease both;
}

@keyframes fadeUp { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:translateY(0); } }

.sentence-header {
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 12px;
}
.sentence-num {
  min-width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-glow); border: 1px solid rgba(124,106,247,0.3);
  color: var(--accent); font-family: 'Syne', sans-serif; font-weight: 700; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 1px;
}
.sentence-text { font-size: 15px; line-height: 1.6; color: var(--text); flex: 1; }

/* ─── Keyword toolbar ─── */
.kw-toolbar {
  padding: 10px 1.25rem 12px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.kw-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.7px; white-space: nowrap; flex-shrink: 0; }
.kw-chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.kw-chip {
  font-size: 11px; padding: 4px 10px; border-radius: 20px;
  background: var(--bg4); color: var(--muted2); border: 1px solid var(--border);
  cursor: pointer; transition: background 0.15s, color 0.15s, border-color 0.15s;
  user-select: none; white-space: nowrap;
}
.kw-chip:hover { background: var(--bg3); color: var(--text); border-color: var(--border2); }
.kw-chip.active { background: var(--accent-glow); color: var(--accent); border-color: rgba(124,106,247,0.4); font-weight: 500; }

.kw-custom-wrap {
  display: flex; align-items: center;
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: 20px; overflow: hidden; transition: border-color 0.2s; flex-shrink: 0;
}
.kw-custom-wrap:focus-within { border-color: var(--accent); }
.kw-custom-input {
  background: transparent; border: none; outline: none;
  color: var(--text); font-family: 'DM Sans', sans-serif; font-size: 12px;
  padding: 5px 12px; width: 150px; min-width: 90px;
}
.kw-custom-input::placeholder { color: var(--muted); }
.kw-search-btn {
  background: var(--accent); border: none; color: #fff;
  padding: 5px 11px; cursor: pointer; font-size: 12px;
  font-family: 'DM Sans', sans-serif; font-weight: 500;
  transition: background 0.15s; display: flex; align-items: center; gap: 4px; white-space: nowrap;
}
.kw-search-btn:hover { background: var(--accent2); }
.kw-search-btn svg { width: 12px; height: 12px; }

/* ─── Active keyword banner ─── */
.active-kw-banner {
  display: none; padding: 7px 1.25rem;
  background: var(--accent-glow); border-bottom: 1px solid rgba(124,106,247,0.15);
  font-size: 12px; color: var(--muted2); align-items: center; gap: 8px;
}
.active-kw-banner.visible { display: flex; }
.active-kw-banner strong { color: var(--accent); font-weight: 500; }
.active-kw-banner .clear-kw {
  margin-left: auto; font-size: 11px; color: var(--muted); cursor: pointer;
  border: 1px solid var(--border2); border-radius: 20px; padding: 2px 8px;
  transition: color 0.15s; white-space: nowrap; flex-shrink: 0;
}
.active-kw-banner .clear-kw:hover { color: var(--text); }

/* ─── Clips grid ─── */
.clips-grid {
  padding: 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.clip-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
  position: relative; cursor: pointer;
}
.clip-card:hover { border-color: var(--border2); }
.clip-card.selected {
  border-color: var(--sel-color);
  box-shadow: 0 0 0 1px var(--sel-color), inset 0 0 0 1000px var(--sel-glow);
}

.sel-check {
  position: absolute; top: 8px; left: 8px; z-index: 10;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,0.55); border: 2px solid rgba(255,255,255,0.45);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  pointer-events: none;
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: 10px; color: transparent;
}
.clip-card.selected .sel-check {
  background: var(--sel-color); border-color: var(--sel-color); color: #0a0a0c;
}

/* ─── Video player ─── */
.video-wrap {
  position: relative; width: 100%; padding-bottom: 56.25%;
  background: #000;
}
.video-wrap video {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%; object-fit: cover; pointer-events: none;
}
.play-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.28); transition: opacity 0.2s;
}
.play-overlay svg { width: 34px; height: 34px; }
.video-wrap.playing .play-overlay { opacity: 0; }
.video-wrap.playing:hover .play-overlay { opacity: 1; }

.play-btn {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; cursor: pointer;
}

/* ─── Clip info ─── */
.clip-info { padding: 10px 12px; }
.clip-kw { font-size: 12px; font-weight: 500; color: var(--text); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clip-source { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 3px; }
.clip-source.pexels  { color: #05a081; }
.clip-source.pixabay { color: #2ec4b6; }
.clip-meta { font-size: 11px; color: var(--muted); margin-bottom: 10px; }

.clip-actions { display: flex; gap: 6px; }
.btn-dl {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 5px;
  padding: 7px 8px; background: var(--accent); color: #fff; border: none;
  border-radius: 7px; font-family: 'DM Sans', sans-serif; font-size: 11px; font-weight: 500;
  cursor: pointer; transition: background 0.2s; text-decoration: none;
}
.btn-dl:hover { background: var(--accent2); }
.btn-dl svg { width: 12px; height: 12px; flex-shrink: 0; }
.btn-ext {
  padding: 7px 9px; background: var(--bg4); color: var(--muted2);
  border: 1px solid var(--border2); border-radius: 7px; font-size: 11px;
  cursor: pointer; transition: color 0.2s; display: flex; align-items: center;
  text-decoration: none; flex-shrink: 0;
}
.btn-ext:hover { color: var(--text); }

/* ─── States ─── */
.no-clips { padding: 2rem 1.25rem; text-align: center; color: var(--muted); font-size: 13px; }
.loading-clips { padding: 1.5rem 1.25rem; display: flex; align-items: center; gap: 10px; color: var(--muted2); font-size: 13px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; flex-shrink: 0; }

@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  background: rgba(245,101,101,0.08); border: 1px solid rgba(245,101,101,0.25);
  border-radius: var(--radius); padding: 12px 16px; color: #fc9696;
  font-size: 13px; margin-bottom: 1rem; display: none;
}

/* ─── Hero ─── */
.hero { text-align: center; padding: 3rem 1rem 2rem; }
.hero h1 { font-family: 'Syne', sans-serif; font-weight: 800; font-size: clamp(28px,5vw,44px); letter-spacing: -1px; margin-bottom: 0.75rem; line-height: 1.15; }
.hero h1 em { color: var(--accent); font-style: normal; }
.hero p { color: var(--muted2); font-size: 16px; max-width: 500px; margin: 0 auto 2rem; line-height: 1.6; }

.how-steps { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; margin-bottom: 3rem; }
.how-step { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1rem 1.25rem; text-align: left; width: 160px; flex-shrink: 0; }
.how-step-num { font-family: 'Syne', sans-serif; font-size: 11px; font-weight: 700; color: var(--accent); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; }
.how-step p { font-size: 13px; color: var(--muted2); line-height: 1.5; }

/* ─── Selection tray ─── */
#selection-tray {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: rgba(17,17,22,0.97);
  border-top: 1px solid var(--sel-color);
  backdrop-filter: blur(16px);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
  padding: 0 clamp(1rem,4vw,2.5rem);
}
#selection-tray.visible { transform: translateY(0); }

.tray-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 0;
  flex-wrap: wrap;
}
.tray-count {
  display: flex; align-items: center; gap: 8px;
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: 16px;
}
.tray-count-badge {
  background: var(--sel-color); color: #0a0a0c;
  font-size: 13px; font-weight: 700;
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.tray-list {
  flex: 1; display: flex; gap: 6px; flex-wrap: wrap; overflow: hidden;
  max-height: 54px;
}
.tray-chip {
  font-size: 11px; padding: 3px 9px; border-radius: 20px;
  background: var(--green-glow); color: var(--green);
  border: 1px solid rgba(62,207,142,0.25);
  white-space: nowrap; max-width: 160px;
  overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 5px;
}
.tray-chip-num {
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: 10px;
  background: var(--sel-color); color: #0a0a0c;
  width: 16px; height: 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.tray-chip-x {
  cursor: pointer; opacity: 0.6; flex-shrink: 0;
  font-size: 13px; line-height: 1;
  transition: opacity 0.15s;
}
.tray-chip-x:hover { opacity: 1; }

.tray-actions { display: flex; gap: 8px; flex-shrink: 0; margin-left: auto; }
.tray-clear {
  padding: 9px 16px; background: transparent;
  border: 1px solid var(--border2); border-radius: var(--radius);
  color: var(--muted2); font-family: 'DM Sans', sans-serif; font-size: 13px;
  cursor: pointer; transition: color 0.2s, border-color 0.2s;
}
.tray-clear:hover { color: var(--text); border-color: var(--text); }
.tray-dl-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 18px; background: var(--sel-color); color: #0a0a0c;
  border: none; border-radius: var(--radius);
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: 13px;
  cursor: pointer; transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
}
.tray-dl-btn:hover { opacity: 0.9; }
.tray-dl-btn:active { transform: scale(0.98); }
.tray-dl-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.tray-dl-btn svg { width: 15px; height: 15px; }

/* ─── ZIP overlay ─── */
#zip-overlay {
  display: none; position: fixed; inset: 0; z-index: 500;
  background: rgba(10,10,12,0.88); backdrop-filter: blur(8px);
  align-items: center; justify-content: center;
}
#zip-overlay.visible { display: flex; }
.zip-modal {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius-lg); padding: 2rem 2.5rem;
  text-align: center; min-width: 280px;
}
.zip-modal h3 { font-family: 'Syne', sans-serif; font-weight: 700; font-size: 18px; margin-bottom: 0.5rem; }
.zip-modal p { color: var(--muted2); font-size: 13px; margin-bottom: 1.25rem; }
.zip-progress-wrap { background: var(--bg3); border-radius: 20px; height: 5px; overflow: hidden; margin-bottom: 10px; }
.zip-progress-fill { height: 100%; background: var(--sel-color); border-radius: 20px; transition: width 0.3s ease; width: 0%; }
.zip-progress-label { font-size: 12px; color: var(--muted2); }

/* ─── Responsive ─── */
@media (max-width: 600px) {
  .clips-grid { grid-template-columns: 1fr 1fr; gap: 0.75rem; }
  .clip-info { padding: 8px 10px; }
  .btn-dl span { display: none; }
  header { height: 52px; }
  .hero h1 { font-size: 26px; }
  .kw-custom-input { width: 100px; }
  .tray-list { display: none; }
  .tray-count { font-size: 14px; }
}
@media (max-width: 400px) {
  .clips-grid { grid-template-columns: 1fr; }
  .kw-toolbar { flex-direction: column; align-items: flex-start; }
}
