/* ============================================
   MediaDownloader — Premium Dark Mode Design
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* --- CSS Custom Properties --- */
:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.6);
  --bg-glass: rgba(255, 255, 255, 0.04);
  --bg-glass-hover: rgba(255, 255, 255, 0.08);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-1: #8b5cf6;
  --accent-2: #06b6d4;
  --accent-3: #a855f7;
  --gradient-main: linear-gradient(135deg, #8b5cf6 0%, #06b6d4 100%);
  --gradient-warm: linear-gradient(135deg, #f472b6 0%, #8b5cf6 100%);
  --gradient-success: linear-gradient(135deg, #10b981 0%, #06b6d4 100%);

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(139, 92, 246, 0.3);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px rgba(139, 92, 246, 0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Animated Background --- */
.bg-pattern {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-pattern::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background:
    radial-gradient(ellipse 600px 600px at 20% 30%, rgba(139, 92, 246, 0.08) 0%, transparent 70%),
    radial-gradient(ellipse 500px 500px at 80% 70%, rgba(6, 182, 212, 0.06) 0%, transparent 70%),
    radial-gradient(ellipse 400px 400px at 50% 50%, rgba(168, 85, 247, 0.04) 0%, transparent 70%);
  animation: bgDrift 20s ease-in-out infinite alternate;
}

@keyframes bgDrift {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(-3%, -3%) rotate(2deg); }
}

/* --- Layout --- */
.app-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

/* --- Header --- */
.app-header {
  width: 100%;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  background: rgba(10, 14, 26, 0.7);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--gradient-main);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  box-shadow: 0 0 16px rgba(139, 92, 246, 0.3);
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  background: var(--gradient-main);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.65rem;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* --- Hero Section --- */
.hero {
  text-align: center;
  margin-top: 3rem;
  margin-bottom: 2.5rem;
  animation: fadeInUp 0.6s var(--transition-slow);
}

.hero h1 {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 0.75rem;
}

.hero h1 .gradient-text {
  background: var(--gradient-main);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  font-size: 1.05rem;
  color: var(--text-secondary);
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.65;
}

/* --- Search Bar --- */
.search-section {
  width: 100%;
  margin-bottom: 2rem;
  animation: fadeInUp 0.6s var(--transition-slow) 0.1s backwards;
}

.search-bar {
  display: flex;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.search-bar:focus-within {
  border-color: var(--border-accent);
  box-shadow: var(--shadow-glow);
}

.search-bar input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 1rem 1.25rem;
  font-size: 0.95rem;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
}

.search-bar input::placeholder {
  color: var(--text-muted);
}

.search-btn {
  padding: 0.85rem 1.5rem;
  background: var(--gradient-main);
  border: none;
  color: white;
  font-weight: 600;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  white-space: nowrap;
}

.search-btn:hover {
  opacity: 0.9;
  transform: scale(1.02);
}

.search-btn:active {
  transform: scale(0.98);
}

.search-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.search-btn .btn-icon {
  font-size: 1.1rem;
}

/* --- Error Message --- */
.error-message {
  display: none;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.65rem 1rem;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 0.85rem;
  animation: shakeX 0.4s ease;
}

.error-message.visible {
  display: flex;
}

.error-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

/* --- Supported Platforms --- */
.platforms {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.platform-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: color var(--transition-fast);
}

.platform-tag:hover {
  color: var(--text-secondary);
}

.platform-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-1);
  opacity: 0.6;
}

/* --- Video Preview Card --- */
.preview-card {
  display: none;
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 2rem;
  animation: fadeInUp 0.5s var(--transition-slow);
}

.preview-card.visible {
  display: block;
}

.preview-thumbnail-wrapper {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  background: var(--bg-secondary);
}

.preview-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-slow);
}

.preview-card:hover .preview-thumbnail {
  transform: scale(1.03);
}

.preview-duration {
  position: absolute;
  bottom: 0.75rem;
  right: 0.75rem;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.preview-info {
  padding: 1.25rem;
}

.preview-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

.preview-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.preview-meta-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* --- Download Options Panel --- */
.download-panel {
  display: none;
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 2rem;
  animation: fadeInUp 0.5s var(--transition-slow) 0.1s backwards;
}

.download-panel.visible {
  display: block;
}

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-subtle);
}

.tab-btn {
  flex: 1;
  padding: 0.85rem 1rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  position: relative;
  transition: color var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.tab-btn.active {
  color: var(--text-primary);
}

.tab-btn::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) scaleX(0);
  width: 60%;
  height: 2px;
  background: var(--gradient-main);
  border-radius: 2px;
  transition: transform var(--transition-normal);
}

.tab-btn.active::after {
  transform: translateX(-50%) scaleX(1);
}

.tab-btn:hover {
  color: var(--text-secondary);
}

.tab-icon {
  font-size: 1.1rem;
}

/* Tab Content */
.tab-content {
  display: none;
  padding: 1.25rem;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

.format-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* Format Selector */
.format-selector {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.format-chip {
  padding: 0.45rem 1rem;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.format-chip.active,
.format-chip:hover {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--border-accent);
  color: var(--accent-1);
}

/* Quality Grid */
.quality-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}

.quality-card {
  padding: 0.9rem 1rem;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.quality-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--gradient-main);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.quality-card:hover {
  border-color: var(--border-accent);
  transform: translateY(-1px);
}

.quality-card.selected {
  border-color: var(--accent-1);
  background: rgba(139, 92, 246, 0.1);
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.1);
}

.quality-card.selected::before {
  opacity: 0.05;
}

.quality-resolution {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.15rem;
  position: relative;
  z-index: 1;
}

.quality-tag {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  background: var(--gradient-main);
  border-radius: 3px;
  margin-left: 0.3rem;
  vertical-align: middle;
  letter-spacing: 0.04em;
}

.quality-size {
  font-size: 0.78rem;
  color: var(--text-muted);
  position: relative;
  z-index: 1;
}

/* --- Progress Section --- */
.progress-section {
  display: none;
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 2rem;
  animation: fadeInUp 0.5s var(--transition-slow);
}

.progress-section.visible {
  display: block;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.progress-label {
  font-size: 0.9rem;
  font-weight: 600;
}

.progress-percentage {
  font-size: 0.9rem;
  font-weight: 700;
  background: var(--gradient-main);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.progress-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--gradient-main);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 40px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  animation: shimmer 1.5s infinite;
}

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

/* --- Download Button --- */
.download-action {
  display: none;
  width: 100%;
  margin-bottom: 2rem;
  animation: fadeInUp 0.5s var(--transition-slow);
}

.download-action.visible {
  display: block;
}

.download-btn {
  width: 100%;
  padding: 1rem;
  background: var(--gradient-main);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  transition: all var(--transition-fast);
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.25);
  position: relative;
  overflow: hidden;
}

.download-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.5s ease, height 0.5s ease;
}

.download-btn:hover::before {
  width: 300px;
  height: 300px;
}

.download-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 30px rgba(139, 92, 246, 0.35);
}

.download-btn:active {
  transform: translateY(0);
}

.download-btn .btn-icon {
  font-size: 1.2rem;
  position: relative;
  z-index: 1;
}

.download-btn span {
  position: relative;
  z-index: 1;
}

/* --- Process Button (Start Download) --- */
.process-btn-wrapper {
  display: none;
  width: 100%;
  margin-bottom: 2rem;
  animation: fadeInUp 0.5s var(--transition-slow);
}

.process-btn-wrapper.visible {
  display: block;
}

.process-btn {
  width: 100%;
  padding: 1rem;
  background: var(--gradient-success);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  transition: all var(--transition-fast);
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.25);
  position: relative;
  overflow: hidden;
}

.process-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 30px rgba(16, 185, 129, 0.35);
}

.process-btn:active {
  transform: translateY(0);
}

.process-btn .btn-icon {
  font-size: 1.2rem;
}

/* --- Terms & Conditions --- */
.terms-section {
  width: 100%;
  margin-top: 1rem;
  margin-bottom: 2rem;
}

.terms-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.terms-toggle:hover {
  background: var(--bg-glass-hover);
  border-color: var(--border-accent);
}

.terms-toggle-icon {
  transition: transform var(--transition-normal);
  font-size: 0.8rem;
}

.terms-toggle.open .terms-toggle-icon {
  transform: rotate(180deg);
}

.terms-body {
  display: none;
  padding: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.75;
  animation: fadeIn 0.3s ease;
}

.terms-body.open {
  display: block;
}

.terms-body h4 {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-top: 1rem;
  margin-bottom: 0.4rem;
}

.terms-body h4:first-child {
  margin-top: 0;
}

.terms-body ul {
  padding-left: 1.25rem;
  margin-bottom: 0.5rem;
}

.terms-body ul li {
  margin-bottom: 0.25rem;
}

/* --- Footer --- */
.app-footer {
  width: 100%;
  padding: 1.5rem;
  text-align: center;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.78rem;
}

.footer-brand {
  background: var(--gradient-main);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 600;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 0.5rem;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-links a:hover {
  color: var(--text-secondary);
}

/* --- Loading Shimmer (skeleton) --- */
.shimmer-wrapper {
  display: none;
  width: 100%;
  margin-bottom: 2rem;
}

.shimmer-wrapper.visible {
  display: block;
}

.shimmer-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.shimmer-thumbnail {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: linear-gradient(90deg, var(--bg-secondary) 25%, rgba(255,255,255,0.04) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: shimmerSlide 1.5s infinite;
}

.shimmer-content {
  padding: 1.25rem;
}

.shimmer-line {
  height: 14px;
  background: linear-gradient(90deg, var(--bg-secondary) 25%, rgba(255,255,255,0.04) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: shimmerSlide 1.5s infinite;
  border-radius: 4px;
  margin-bottom: 0.6rem;
}

.shimmer-line.short {
  width: 60%;
}

/* --- Rate Limit Warning --- */
.rate-limit-warning {
  display: none;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.65rem 1rem;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.2);
  border-radius: var(--radius-sm);
  color: #fcd34d;
  font-size: 0.85rem;
}

.rate-limit-warning.visible {
  display: flex;
}

/* --- Animations --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(200%); }
}

@keyframes shimmerSlide {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes shakeX {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes bounceIn {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.05); }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .hero h1 {
    font-size: 1.85rem;
  }

  .hero p {
    font-size: 0.95rem;
  }

  .main-content {
    padding: 1.25rem 1rem;
  }

  .search-btn span {
    display: none;
  }

  .search-btn {
    padding: 0.85rem 1rem;
  }

  .quality-grid {
    grid-template-columns: 1fr;
  }

  .platforms {
    gap: 1rem;
  }
}

@media (max-width: 480px) {
  .hero h1 {
    font-size: 1.55rem;
  }

  .app-header {
    padding: 0.85rem 1rem;
  }

  .logo-text {
    font-size: 1.05rem;
  }

  .header-badge {
    display: none;
  }
}

@media (min-width: 1024px) {
  .main-content {
    padding: 3rem 1rem;
  }
}

/* --- Utility --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
