/* ==========================================================================
   YTDL - Pitch Black & White OLED + Solid Glass Material System
   Vercel Serverless Ready Edition
   ========================================================================== */

:root {
  --bg-pitch-black: #000000;
  --bg-obsidian: #080808;
  --bg-card: rgba(14, 14, 14, 0.82);
  --bg-glass-input: rgba(18, 18, 18, 0.88);
  --bg-glass-btn: rgba(26, 26, 26, 0.75);
  --bg-glass-btn-hover: rgba(40, 40, 40, 0.9);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.14);
  --border-focus: rgba(255, 255, 255, 0.4);

  --text-primary: #FFFFFF;
  --text-secondary: #A1A1AA;
  --text-muted: #71717A;
  --text-inverted: #000000;

  --accent-white: #FFFFFF;
  --accent-silver: #E4E4E7;
  --danger: #EF4444;

  --rim-specular: inset 0 1px 0 0 rgba(255, 255, 255, 0.14);
  --shadow-card: 0 16px 36px -12px rgba(0, 0, 0, 0.75);
  
  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

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

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

html {
  color-scheme: dark;
  background-color: var(--bg-pitch-black);
  font-family: var(--font-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: var(--bg-pitch-black);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Subtle Canvas Grid / Atmosphere */
.canvas-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: 
    radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.03) 0%, transparent 60%);
  background-size: 32px 32px, 100% 100%;
  pointer-events: none;
}

/* ==========================================================================
   Header / Navigation Bar
   ========================================================================== */
.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: var(--rim-specular);
}

.nav-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  cursor: pointer;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-obsidian);
  border: 1px solid var(--border-medium);
  box-shadow: var(--rim-specular);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

.brand-name {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.nav-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22C55E;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

/* ==========================================================================
   Main Content Layout
   ========================================================================== */
.main-container {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* Hero Section */
.hero-section {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.hero-title {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  color: var(--text-primary);
  line-height: 1.15;
}

.hero-subtitle {
  font-size: 1.05rem;
  color: var(--text-secondary);
  max-width: 580px;
  line-height: 1.5;
}

/* Input Glass Panel */
.input-glass-panel {
  width: 100%;
  max-width: 720px;
  margin-top: 16px;
  display: flex;
  flex-direction: row;
  gap: 10px;
  padding: 6px;
  border-radius: var(--radius-lg);
  background: var(--bg-glass-input);
  border: 1px solid var(--border-medium);
  box-shadow: var(--rim-specular), var(--shadow-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-glass-panel:focus-within {
  border-color: var(--border-focus);
  box-shadow: var(--rim-specular), 0 0 0 2px rgba(255, 255, 255, 0.15);
}

.input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  min-width: 0;
}

.input-icon {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

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

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

/* Buttons */
.btn-solid-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent-white);
  color: var(--text-inverted);
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 22px;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 2px 10px rgba(255, 255, 255, 0.12);
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  flex-shrink: 0;
  user-select: none;
}

.btn-solid-primary:hover {
  background: var(--accent-silver);
  transform: translateY(-1px);
}

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

.btn-solid-primary:focus-visible {
  outline: 2px solid var(--accent-white);
  outline-offset: 2px;
}

.glass-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg-glass-btn);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--rim-specular);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  user-select: none;
}

.glass-btn:hover {
  background: var(--bg-glass-btn-hover);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.glass-btn:focus-visible {
  outline: 2px solid var(--border-focus);
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.btn-compact {
  padding: 9px 16px;
  font-size: 0.84rem;
}

.btn-nano {
  padding: 4px 10px;
  font-size: 0.72rem;
  border-radius: var(--radius-sm);
}

/* Samples Row */
.samples-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.samples-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sample-chip {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  padding: 4px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sample-chip:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

/* Error Banner */
.error-banner {
  max-width: 720px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #FCA5A5;
  font-size: 0.88rem;
  text-align: left;
}

.error-icon {
  color: var(--danger);
  flex-shrink: 0;
  display: flex;
}

.error-text {
  flex: 1;
}

.error-dismiss {
  background: transparent;
  border: none;
  color: #FCA5A5;
  cursor: pointer;
  padding: 4px;
  display: flex;
}

/* ==========================================================================
   Loading State Panel
   ========================================================================== */
.loading-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 36px;
  border-radius: var(--radius-xl);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--rim-specular), var(--shadow-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

.loading-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.loading-step {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* ==========================================================================
   Results & Cards (Solid Glass)
   ========================================================================== */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.glass-card {
  border-radius: var(--radius-xl);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--rim-specular), var(--shadow-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* Media Overview Card */
.media-overview {
  padding: 24px;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  align-items: start;
}

.thumb-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #111111;
  border: 1px solid var(--border-subtle);
}

.video-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.thumb-wrapper:hover .video-thumb {
  transform: scale(1.02);
}

.duration-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.85);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.media-details {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  min-height: 100%;
}

.video-title {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-primary);
  letter-spacing: -0.015em;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Priority Actions Box */
.priority-actions-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.priority-label {
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.quick-actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ==========================================================================
   Formats Panel
   ========================================================================== */
.formats-panel {
  padding: 20px 24px;
}

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

.formats-nav {
  display: flex;
  gap: 6px;
  background: rgba(255, 255, 255, 0.03);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

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

.tab-btn.active {
  background: var(--bg-glass-btn-hover);
  color: var(--text-primary);
  box-shadow: var(--rim-specular);
}

.tab-count {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.tab-btn.active .tab-count {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.12);
}

.info-label {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Formats List */
.formats-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.format-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  transition: background 0.15s ease, border-color 0.15s ease;
  gap: 16px;
}

.format-row:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-medium);
}

.format-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.format-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.format-specs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.format-headline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

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

.ext-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.kind-badge {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.format-subtext {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.format-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ==========================================================================
   History Section
   ========================================================================== */
.history-section {
  border-radius: var(--radius-xl);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--rim-specular);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-medium);
}

.history-thumb {
  width: 44px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  background: #111;
  flex-shrink: 0;
}

.history-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.history-name {
  font-size: 0.8rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-time {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Footer
   ========================================================================== */
.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.9);
  padding: 24px;
}

.footer-container {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.footer-brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.footer-copy {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.footer-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.84rem;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.03);
  transition: all 0.15s ease;
}

.footer-link:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
  background: rgba(255, 255, 255, 0.08);
}

/* ==========================================================================
   Compiling Modal & Progress Bar (Solid Glass)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: 20px;
  animation: modalFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-card {
  max-width: 460px;
  width: 100%;
  background: rgba(14, 14, 14, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.2), 0 24px 60px rgba(0, 0, 0, 0.85);
  border-radius: var(--radius-xl);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: modalScaleUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScaleUp {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 16px;
}

.modal-icon-pulse {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  flex-shrink: 0;
  animation: iconPulse 2s infinite ease-in-out;
}

@keyframes iconPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.15);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.35);
  }
}

.modal-headings {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

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

.compile-progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.compile-progress-fill {
  height: 100%;
  background: #FFFFFF;
  border-radius: var(--radius-full);
  transition: width 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.4);
}

.compile-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.compile-percent {
  font-weight: 600;
  color: var(--text-primary);
}

.compile-status {
  color: var(--text-muted);
}

/* ==========================================================================
   Utility Classes & Responsiveness
   ========================================================================== */
.hidden {
  display: none !important;
}

@media (max-width: 768px) {
  .hero-title {
    font-size: 1.85rem;
  }

  .input-glass-panel {
    flex-direction: column;
    padding: 8px;
  }

  .btn-solid-primary {
    width: 100%;
  }

  .media-overview {
    grid-template-columns: 1fr;
  }

  .format-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .format-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
