*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #2e2e2e;
  --text: #f1f1f1;
  --text-muted: #8a8a8a;
  --red: #ff4444;
  --red-dark: #cc0000;
  --green: #22c55e;
  --green-dark: #16a34a;
  --accent: #3b82f6;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
}
.header-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-icon { width: 28px; height: 28px; flex-shrink: 0; }
.logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

/* Main */
.main {
  flex: 1;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  padding: 32px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

/* URL Card */
.input-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.input-row {
  display: flex;
  gap: 10px;
}
.url-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
.url-input:focus { border-color: var(--accent); }
.url-input::placeholder { color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--red-dark); }

.btn-download {
  width: 100%;
  background: var(--red);
  color: #fff;
  padding: 14px;
  font-size: 1rem;
  margin-top: 16px;
}
.btn-download:hover { background: var(--red-dark); }

.btn-success {
  background: var(--green);
  color: #fff;
  padding: 14px 28px;
  font-size: 1rem;
}
.btn-success:hover { background: var(--green-dark); }

.btn-ghost {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  margin-top: 8px;
}
.btn-ghost:hover { color: var(--text); }

/* Spinner */
.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Error */
.error-msg {
  color: #f87171;
  font-size: 0.85rem;
  margin-top: 8px;
}

/* Info Card */
.video-info {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}
.thumbnail {
  width: 120px;
  height: 68px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background: var(--surface2);
}
.video-meta { flex: 1; min-width: 0; }
.video-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 4px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.video-uploader { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 2px; }
.video-duration { font-size: 0.82rem; color: var(--text-muted); }

/* Playlist badge */
.playlist-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Playlist preview */
.playlist-preview {
  list-style: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  max-height: 220px;
  overflow-y: auto;
}
.playlist-preview::-webkit-scrollbar { width: 6px; }
.playlist-preview::-webkit-scrollbar-track { background: transparent; }
.playlist-preview::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.playlist-preview li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.playlist-preview li:last-child { border-bottom: none; }
.playlist-num { color: var(--text-muted); font-size: 0.75rem; min-width: 20px; }
.playlist-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.playlist-dur { color: var(--text-muted); font-size: 0.75rem; }

/* Options */
.options-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.option-group { display: flex; flex-direction: column; gap: 6px; }
.option-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

/* Toggle */
.toggle-group {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.toggle-btn {
  padding: 9px 18px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.toggle-btn.active {
  background: var(--red);
  color: #fff;
}
.toggle-btn:not(.active):hover { background: var(--border); color: var(--text); }

/* Select */
.select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
  min-width: 140px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8a8a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
.select:focus { border-color: var(--accent); }
.select option { background: var(--surface2); }

/* Progress Card */
.progress-card { text-align: center; }
.progress-label {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.progress-bar-track {
  background: var(--surface2);
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--red), #ff6b6b);
  border-radius: 99px;
  transition: width 0.4s ease;
}
.progress-pct {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Done Card */
.done-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}
.done-icon { margin-bottom: 4px; }
.done-title { font-size: 1.1rem; font-weight: 700; }

/* Footer */
.footer {
  text-align: center;
  padding: 20px 16px;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* Helpers */
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 480px) {
  .card { padding: 16px; }
  .input-row { flex-direction: column; }
  .btn-primary { width: 100%; }
  .video-info { flex-direction: column; }
  .thumbnail { width: 100%; height: 180px; }
  .options-row { flex-direction: column; }
  .select, .toggle-group { width: 100%; }
}
