/* ════════════════════════════════════════════════
   Design Tokens
   ════════════════════════════════════════════════ */
:root {
  --bg-dark: #070709;
  --card-bg: rgba(22, 22, 28, 0.65);
  --card-border: rgba(255, 255, 255, 0.08);

  --text-primary: #f5f5f7;
  --text-secondary: #86868b;
  --text-tertiary: #515154;

  --accent-blue: #2997ff;
  --accent-gradient: linear-gradient(135deg, #0071e3 0%, #2997ff 100%);
  --accent-gradient-hover: linear-gradient(135deg, #0077ed 0%, #47a3ff 100%);

  --status-downloading: #2997ff;
  --status-converting: #ff9f0a;
  --status-completed: #30d158;
  --status-failed: #ff453a;

  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;

  --font-heading: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ════════════════════════════════════════════════
   Reset & Base
   ════════════════════════════════════════════════ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2.5rem 1.25rem 3rem;
  overflow-x: hidden;
  position: relative;
}

/* ════════════════════════════════════════════════
   Ambient Glow
   ════════════════════════════════════════════════ */
.ambient-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(140px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.18;
}
.glow-top {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, #0071e3 0%, #5856d6 100%);
  top: -200px;
  left: 50%;
  transform: translateX(-50%);
}
.glow-bottom {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, #ff2d55 0%, #bf5af2 100%);
  bottom: -200px;
  right: 10%;
}

/* ════════════════════════════════════════════════
   App Shell
   ════════════════════════════════════════════════ */
.app-shell {
  width: 100%;
  max-width: 820px;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

/* ════════════════════════════════════════════════
   Navbar
   ════════════════════════════════════════════════ */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
  box-shadow: 0 4px 16px rgba(0, 113, 227, 0.4);
  flex-shrink: 0;
}

.brand-name {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #fff;
  white-space: nowrap;
}

.badge-pro {
  font-size: 0.6rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent-blue);
  border: 1px solid rgba(41, 151, 255, 0.3);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.05em;
}

.badge-ai {
  font-size: 0.75rem;
  font-weight: 600;
  color: #bf5af2;
  background: rgba(191, 90, 242, 0.12);
  border: 1px solid rgba(191, 90, 242, 0.25);
  padding: 0.28rem 0.75rem;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
}

.nav-tagline {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ════════════════════════════════════════════════
   Hero
   ════════════════════════════════════════════════ */
.hero-section {
  text-align: center;
  padding: 0.5rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
}

.hero-title {
  font-family: var(--font-heading);
  font-size: clamp(1.6rem, 5vw, 2.3rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.2;
  color: #fff;
}

.hero-title span {
  background: linear-gradient(135deg, #2997ff 0%, #9852ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-subtitle {
  font-size: clamp(0.85rem, 2.5vw, 1rem);
  color: var(--text-secondary);
  max-width: 520px;
  line-height: 1.55;
  font-weight: 400;
}

/* ════════════════════════════════════════════════
   Apple Cards (Glassmorphism)
   ════════════════════════════════════════════════ */
.apple-card {
  background: var(--card-bg);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.45);
}

/* ════════════════════════════════════════════════
   Input Card
   ════════════════════════════════════════════════ */
.input-card {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

/* The main URL input row */
.input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(10, 10, 14, 0.7);
  border: 1.5px solid var(--card-border);
  border-radius: var(--radius-pill);
  padding: 0.3rem 0.35rem 0.3rem 1rem;
  transition: border-color 0.25s, box-shadow 0.25s;
}

.input-group:focus-within {
  border-color: var(--accent-blue);
  box-shadow: 0 0 22px rgba(41, 151, 255, 0.22);
}

.input-icon {
  font-size: 1.15rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.input-group input {
  flex: 1;
  min-width: 0;          /* critical for flex truncation */
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.93rem;
}

.input-group input::placeholder {
  color: var(--text-tertiary);
}

/* ════════════════════════════════════════════════
   Pill Buttons
   ════════════════════════════════════════════════ */
.pill-btn {
  border: none;
  outline: none;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
  flex-shrink: 0;
}

.pill-btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.pill-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

.pill-btn.primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 16px rgba(0, 113, 227, 0.38);
}

.pill-btn.primary:hover {
  background: var(--accent-gradient-hover);
  box-shadow: 0 6px 22px rgba(41, 151, 255, 0.48);
  transform: translateY(-1px);
}

.pill-btn.primary:active {
  transform: scale(0.97);
}

/* ════════════════════════════════════════════════
   Alert Toast
   ════════════════════════════════════════════════ */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.86rem;
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
}

.alert-error {
  background: rgba(255, 69, 58, 0.12);
  border: 1px solid rgba(255, 69, 58, 0.25);
  color: #ff8078;
}

.hidden {
  display: none !important;
}

/* ════════════════════════════════════════════════
   Video Preview Card
   ════════════════════════════════════════════════ */
.video-preview-card {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1.25rem;
  background: rgba(14, 14, 18, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  margin-top: 0.25rem;
  animation: slideUp 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.media-preview-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  box-shadow: 0 8px 18px rgba(0,0,0,0.3);
  flex-shrink: 0;
}

.media-preview-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.time-tag {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  backdrop-filter: blur(6px);
}

.media-details {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-width: 0;   /* prevent overflow */
}

.media-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.media-channel {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ════════════════════════════════════════════════
   Format Controls
   ════════════════════════════════════════════════ */
.format-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.segmented-control {
  display: flex;
  background: rgba(0, 0, 0, 0.4);
  padding: 3px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.segment-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 500;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.segment-btn.active {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.select-icon {
  position: absolute;
  left: 10px;
  color: var(--text-secondary);
  font-size: 0.82rem;
  pointer-events: none;
  z-index: 1;
}

.select-wrapper select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--card-border);
  color: var(--text-primary);
  padding: 0.42rem 0.9rem 0.42rem 2rem;
  border-radius: var(--radius-pill);
  outline: none;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s;
  max-width: 100%;
}

.select-wrapper select:hover {
  background: rgba(255, 255, 255, 0.1);
}

.mp3-badge {
  font-size: 0.78rem;
  color: #30d158;
  background: rgba(48, 209, 88, 0.1);
  border: 1px solid rgba(48, 209, 88, 0.2);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

/* Download action button */
.download-action-btn {
  background: var(--accent-gradient);
  border: none;
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-pill);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 6px 18px rgba(0, 113, 227, 0.38);
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  width: 100%;
}

.download-action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(41, 151, 255, 0.48);
}

.download-action-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ════════════════════════════════════════════════
   Downloads Section
   ════════════════════════════════════════════════ */
.downloads-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.card-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: #fff;
}

.card-title i { color: var(--accent-blue); }

.status-counter {
  background: rgba(255, 255, 255, 0.07);
  font-size: 0.76rem;
  font-weight: 500;
  padding: 0.2rem 0.7rem;
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
}

.downloads-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.empty-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--text-tertiary);
  margin-bottom: 0.4rem;
}

.empty-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  max-width: 300px;
  line-height: 1.45;
}

/* ════════════════════════════════════════════════
   Download Item Card
   ════════════════════════════════════════════════ */
.download-item {
  background: rgba(14, 14, 18, 0.6);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  animation: slideUp 0.28s ease;
}

.download-item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.download-item-title {
  font-weight: 600;
  font-size: 0.88rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
  line-height: 1.4;
}

.download-item-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

/* Pill Badges */
.pill-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.22rem 0.65rem;
  border-radius: var(--radius-pill);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.pill-badge.preparing {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.pill-badge.downloading {
  background: rgba(41, 151, 255, 0.15);
  color: var(--status-downloading);
  border: 1px solid rgba(41, 151, 255, 0.3);
}

.pill-badge.converting {
  background: rgba(255, 159, 10, 0.15);
  color: var(--status-converting);
  border: 1px solid rgba(255, 159, 10, 0.3);
}

.pill-badge.completed {
  background: rgba(48, 209, 88, 0.15);
  color: var(--status-completed);
  border: 1px solid rgba(48, 209, 88, 0.3);
}

.pill-badge.failed {
  background: rgba(255, 69, 58, 0.15);
  color: var(--status-failed);
  border: 1px solid rgba(255, 69, 58, 0.3);
}

/* Cancel Button */
.cancel-download-btn {
  background: rgba(255, 69, 58, 0.1);
  color: var(--status-failed);
  border: 1px solid rgba(255, 69, 58, 0.22);
  padding: 0.22rem 0.6rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  transition: background 0.18s;
  white-space: nowrap;
}

.cancel-download-btn:hover {
  background: rgba(255, 69, 58, 0.22);
}

/* Progress Bar */
.progress-track {
  width: 100%;
  height: 5px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: var(--radius-pill);
  width: 0%;
  transition: width 0.3s ease;
  box-shadow: 0 0 8px rgba(41, 151, 255, 0.45);
}

/* Meta Row */
.download-meta-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.77rem;
  color: var(--text-secondary);
}

.speed-text,
.size-text,
.eta-text {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

/* Save device button */
.save-device-btn {
  background: rgba(48, 209, 88, 0.14);
  color: #30d158;
  border: 1px solid rgba(48, 209, 88, 0.28);
  padding: 0.45rem 1rem;
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  transition: all 0.18s;
  white-space: nowrap;
}

.save-device-btn:hover {
  background: rgba(48, 209, 88, 0.25);
  transform: translateY(-1px);
}

/* ════════════════════════════════════════════════
   Spin animation
   ════════════════════════════════════════════════ */
.spin-icon {
  animation: spin 1.4s linear infinite;
  display: inline-block;
}

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

/* ════════════════════════════════════════════════
   Footer
   ════════════════════════════════════════════════ */
.app-footer {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-tertiary);
  padding: 1.25rem 0 0.25rem;
  line-height: 1.5;
}

.ai-footer-tag {
  font-size: 0.73rem;
  color: #bf5af2;
  margin-top: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  opacity: 0.85;
}

/* ════════════════════════════════════════════════
   RESPONSIVE — Tablet (≤ 640px)
   ════════════════════════════════════════════════ */
@media (max-width: 640px) {
  body {
    padding: 1.5rem 1rem 2.5rem;
  }

  .app-shell {
    gap: 1.25rem;
  }

  /* Navbar */
  .nav-tagline { display: none; }

  .brand-name {
    font-size: 1.05rem;
  }

  /* Hero */
  .hero-section {
    padding: 0.25rem 0;
    gap: 0.5rem;
  }

  /* Input group — stack vertically */
  .input-group {
    flex-wrap: wrap;
    border-radius: var(--radius-lg);
    padding: 0.6rem;
    gap: 0.5rem;
  }

  .input-icon {
    display: none;   /* clean look on mobile */
  }

  .input-group input {
    width: 100%;
    font-size: 0.9rem;
    padding: 0.1rem 0;
  }

  .pill-btn {
    flex: 1;
    padding: 0.6rem 0.8rem;
    font-size: 0.82rem;
  }

  /* Video Preview — stack thumbnail above details */
  .video-preview-card {
    grid-template-columns: 1fr;
    gap: 0.9rem;
    padding: 0.9rem;
  }

  .media-preview-container {
    width: 100%;
    max-width: 100%;
  }

  .media-details {
    gap: 0.6rem;
  }

  .media-title {
    font-size: 0.95rem;
  }

  /* Format controls — wrap nicely */
  .format-controls {
    gap: 0.5rem;
  }

  .segmented-control {
    width: 100%;
  }

  .segment-btn {
    flex: 1;
    justify-content: center;
    padding: 0.45rem 0.5rem;
    font-size: 0.8rem;
  }

  .select-wrapper {
    width: 100%;
  }

  .select-wrapper select {
    width: 100%;
    font-size: 0.82rem;
  }

  .mp3-badge {
    width: 100%;
    justify-content: center;
    font-size: 0.8rem;
  }

  /* Cards */
  .apple-card {
    padding: 1.1rem;
    border-radius: var(--radius-lg);
  }

  /* Download item */
  .download-item {
    padding: 0.85rem 0.9rem;
  }

  .download-item-top {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .download-item-title {
    font-size: 0.84rem;
    /* On mobile title can wrap */
    white-space: normal;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .download-item-actions {
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .download-meta-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }

  .save-device-btn {
    width: 100%;
    justify-content: center;
    padding: 0.55rem 1rem;
  }
}

/* ════════════════════════════════════════════════
   RESPONSIVE — Very small (≤ 380px)
   ════════════════════════════════════════════════ */
@media (max-width: 380px) {
  body {
    padding: 1.25rem 0.75rem 2rem;
  }

  .brand-name { font-size: 0.95rem; }
  .badge-pro  { display: none; }

  .apple-card {
    padding: 0.9rem;
    border-radius: var(--radius-md);
  }

  .pill-btn {
    padding: 0.55rem 0.65rem;
    font-size: 0.8rem;
  }
}
