@import url("https://fonts.googleapis.com/css2?family=Ubuntu:wght@300;400;500;700&display=swap");

/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:            #1a171b;
  --surface:       #221e24;
  --surface-hover: #2a2530;
  --surface-hi:    #312d34;
  --border:        #3a3540;
  --text:          #f5f1f9;
  --text-muted:    #79747b;
  --text-dim:      #55515a;
  --accent:        #6b69f2;
  --accent-hover:  #5956f0;
  --green:         #00c853;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 4px 24px rgba(0,0,0,0.5);
  --transition:    0.2s ease;
}

html { font-size: 16px; }

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

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px 80px;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 0 32px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo svg { width: 36px; height: 36px; flex-shrink: 0; }

.logo-text {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.logo-text span { color: var(--accent); }

/* ── URL input ────────────────────────────────────────────────────────────── */
.url-section { margin-bottom: 24px; }

.url-box {
  display: flex;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px 6px 16px;
  transition: border-color var(--transition);
}

.url-box:focus-within { border-color: var(--accent); }

.url-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.95rem;
  min-width: 0;
}

.url-box input::placeholder { color: var(--text-dim); }

.btn-fetch {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 22px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), opacity var(--transition);
}

.btn-fetch:hover { background: var(--accent-hover); }
.btn-fetch:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

/* ── Video card ───────────────────────────────────────────────────────────── */
#videoCard {
  display: flex;
  gap: 16px;
  padding: 16px;
  align-items: flex-start;
}

.thumbnail-wrap {
  flex-shrink: 0;
  width: 200px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  aspect-ratio: 16/9;
}

.thumbnail-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-meta {
  flex: 1;
  min-width: 0;
}

.video-title {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-details {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.video-details span { display: flex; align-items: center; gap: 4px; }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Playlist section ─────────────────────────────────────────────────────── */
#playlistSection { padding: 0; }

.playlist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.playlist-title {
  font-size: 1rem;
  font-weight: 600;
}

.playlist-count {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.select-all-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.select-all-label input { cursor: pointer; accent-color: var(--accent); }

.playlist-list {
  max-height: 360px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.playlist-item:last-child { border-bottom: none; }
.playlist-item:hover { background: var(--surface-hover); }

.playlist-item input[type="checkbox"] {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}

.playlist-thumb {
  flex-shrink: 0;
  width: 80px;
  aspect-ratio: 16/9;
  border-radius: 4px;
  overflow: hidden;
  background: #000;
}

.playlist-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.playlist-item-info { flex: 1; min-width: 0; }

.playlist-item-title {
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-item-duration {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Options panel ────────────────────────────────────────────────────────── */
#optionsPanel { padding: 20px; }

.options-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.option-group { display: flex; flex-direction: column; gap: 6px; }

.option-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

#qualitySelect {
  background: var(--surface-hi);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 32px 8px 12px;
  font-size: 0.9rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23aaa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-width: 140px;
  transition: border-color var(--transition);
}

#qualitySelect:focus { outline: none; border-color: var(--accent); }

.format-toggle {
  display: flex;
  background: var(--surface-hi);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.fmt-btn {
  flex: 1;
  padding: 8px 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.fmt-btn.active {
  background: var(--accent);
  color: #fff;
}

.fmt-btn:not(.active):hover { background: var(--surface-hover); color: var(--text); }

/* ── Download button ──────────────────────────────────────────────────────── */
.btn-download {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  letter-spacing: 0.3px;
}

.btn-download:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-download:active { transform: translateY(0); }
.btn-download:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Progress section ─────────────────────────────────────────────────────── */
#progressSection { padding: 20px; }

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.88rem;
}

.progress-stage { color: var(--text-muted); }
.progress-pct { font-weight: 700; color: var(--text); }

.progress-track {
  width: 100%;
  height: 6px;
  background: var(--surface-hi);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s ease;
  position: relative;
}

.progress-fill::after {
  content: "";
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0%   { left: -100%; }
  100% { left: 200%; }
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ── Download ready ───────────────────────────────────────────────────────── */
#downloadReady { padding: 20px; }

.download-ready-content {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.done-icon {
  width: 44px; height: 44px;
  background: rgba(0, 200, 83, 0.15);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.done-icon svg { color: var(--green); }

.done-text strong { display: block; font-size: 0.95rem; margin-bottom: 2px; }
.done-text span { font-size: 0.82rem; color: var(--text-muted); word-break: break-all; }

.btn-save {
  width: 100%;
  padding: 13px;
  background: var(--green);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
  letter-spacing: 0.3px;
}

.btn-save:hover { opacity: 0.9; transform: translateY(-1px); }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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

/* ── Toast notifications ──────────────────────────────────────────────────── */
#toastContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  background: var(--surface-hi);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  max-width: 340px;
  word-break: break-word;
  pointer-events: all;
  box-shadow: var(--shadow);
  animation: slideIn 0.25s ease;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.toast.error { border-left: 3px solid var(--accent); }
.toast.success { border-left: 3px solid var(--green); }
.toast.info { border-left: 3px solid #3ea6ff; }

.toast-icon { flex-shrink: 0; margin-top: 1px; }
.toast-msg { flex: 1; line-height: 1.4; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateX(20px); }
}

/* ── Platform badge & notice ─────────────────────────────────────────────── */
.platform-badge {
  display: inline-block;
  background: var(--accent);
  color: #000;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.platform-notice {
  background: var(--surface-hi);
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
  line-height: 1.4;
}

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

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #videoCard { flex-direction: column; }
  .thumbnail-wrap { width: 100%; }
  .options-row { flex-direction: column; }
  .btn-fetch { padding: 10px 14px; font-size: 0.85rem; }
}
