/* ─────────────────────────────────────────────────────────────────────────────
   YTFetch — style.css
   Design system: "Signal Red on Carbon"
   - Display: Space Grotesk (bold, geometric, confident)
   - Mono: Space Mono (itags, badges)
   - Palette: deep carbon bg + signal-red accent + off-white text
   - Signature element: the glowing fetch bar with a scan-line shimmer
   ───────────────────────────────────────────────────────────────────────────── */

/* ── Tokens ─────────────────────────────────────────────────────────────────── */
:root {
  --bg:          #0e0e10;
  --bg-card:     #16161a;
  --bg-elevated: #1e1e24;
  --border:      #2a2a32;
  --border-hover:#3f3f50;
  --accent:      #e63950;
  --accent-dim:  #c02d43;
  --accent-glow: rgba(230, 57, 80, 0.22);
  --text-primary:   #f0f0f4;
  --text-secondary: #8f8fa8;
  --text-muted:     #5c5c72;
  --badge-video: #2563eb;
  --badge-audio: #16a34a;
  --radius-sm:  6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition: 180ms cubic-bezier(0.4,0,0.2,1);
  --font-main: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'Space Mono', 'Courier New', monospace;
}

[data-theme="light"] {
  --bg:          #f4f4f7;
  --bg-card:     #ffffff;
  --bg-elevated: #eaeaef;
  --border:      #d8d8e4;
  --border-hover:#b0b0c4;
  --text-primary:   #14141c;
  --text-secondary: #555568;
  --text-muted:     #9090a8;
  --accent-glow: rgba(230, 57, 80, 0.12);
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
img { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text-primary);
}
.logo-icon { font-size: 1.25rem; }
.logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.logo-text::after {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  background: var(--accent);
  border-radius: 50%;
  margin-left: 3px;
  vertical-align: top;
  margin-top: 4px;
}
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 1rem;
  transition: border-color var(--transition), color var(--transition);
  display: grid;
  place-items: center;
}
.theme-toggle:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

/* ── Main ───────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 20px 80px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* ── Hero ───────────────────────────────────────────────────────────────────── */
.hero { text-align: center; }
.hero-title {
  font-size: clamp(2rem, 6vw, 3.2rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.03em;
}
.hero-accent {
  color: var(--accent);
  position: relative;
}
.hero-sub {
  margin-top: 12px;
  color: var(--text-secondary);
  font-size: 1.05rem;
}

/* ── Search ─────────────────────────────────────────────────────────────────── */
.search-section { display: flex; flex-direction: column; gap: 10px; }
.search-box {
  display: flex;
  gap: 0;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.search-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 0 16px;
  min-width: 0;
}
.search-prefix {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: nowrap;
  user-select: none;
  display: none; /* hidden on mobile */
}
@media (min-width: 540px) { .search-prefix { display: inline; } }
.search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-primary);
  padding: 16px 8px;
  min-width: 0;
}
.search-input::placeholder { color: var(--text-muted); }
.search-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0 24px;
  border-radius: 0 calc(var(--radius-lg) - 1px) calc(var(--radius-lg) - 1px) 0;
  transition: background var(--transition);
  white-space: nowrap;
  min-width: 100px;
  justify-content: center;
}
.search-btn:hover { background: var(--accent-dim); }
.search-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.search-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Spinner ────────────────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.btn-spinner,
.dl-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;
  flex-shrink: 0;
}

/* ── Error banner ───────────────────────────────────────────────────────────── */
.error-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(230,57,80,0.1);
  border: 1px solid rgba(230,57,80,0.4);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  color: #ff6b7a;
  font-size: 0.9rem;
}
.error-icon { font-size: 1rem; flex-shrink: 0; }

/* ── Video card ─────────────────────────────────────────────────────────────── */
.video-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* Meta row */
.video-meta {
  display: flex;
  gap: 20px;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}
.thumbnail-wrap {
  position: relative;
  flex-shrink: 0;
  width: 160px;
}
.thumbnail {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
}
.duration-badge {
  position: absolute;
  bottom: 5px;
  right: 5px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 4px;
}
.video-details {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
}
.video-title {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.4;
  word-break: break-word;
}
.video-author {
  color: var(--text-secondary);
  font-size: 0.875rem;
}
.video-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tag {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
  padding: 2px 8px;
}

@media (max-width: 500px) {
  .video-meta { flex-direction: column; }
  .thumbnail-wrap { width: 100%; }
}

/* ── Formats section ────────────────────────────────────────────────────────── */
.formats-section { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.formats-heading {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.formats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}
.format-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 10px;
  background: var(--bg-elevated);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  text-align: center;
}
.format-card:hover {
  border-color: var(--border-hover);
  background: color-mix(in srgb, var(--bg-elevated) 80%, var(--accent) 20%);
}
.format-card.selected,
.format-card[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: color-mix(in srgb, var(--bg-elevated) 70%, var(--accent) 30%);
}
.fc-icon { font-size: 1.4rem; line-height: 1; }
.fc-quality {
  font-weight: 700;
  font-size: 1rem;
}
.fc-type {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}
.fc-size {
  font-size: 0.72rem;
  color: var(--text-secondary);
}
.fc-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  margin-top: 2px;
}
.fc-badge--video { background: rgba(37,99,235,0.2); color: #60a5fa; }
.fc-badge--audio { background: rgba(22,163,74,0.2); color: #4ade80; }

.audio-row { display: flex; }
.audio-row .audio-card { flex: 1; flex-direction: row; justify-content: flex-start; gap: 12px; }
.audio-row .audio-card .fc-quality { font-size: 0.95rem; }

/* ── Download button ────────────────────────────────────────────────────────── */
.download-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: calc(100% - 40px);
  margin: 0 20px 20px;
  padding: 15px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  transition: background var(--transition), opacity var(--transition);
}
.download-btn:hover:not(:disabled) { background: var(--accent-dim); }
.download-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.dl-icon { font-size: 1.2rem; font-weight: 900; }

/* ── Legal note ─────────────────────────────────────────────────────────────── */
.legal-note {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 0 20px 16px;
  line-height: 1.5;
}

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

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

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
