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

:root {
  --bg:           #080812;
  --surface:      rgba(255,255,255,0.045);
  --surface-2:    rgba(255,255,255,0.07);
  --border:       rgba(255,255,255,0.08);
  --border-2:     rgba(255,255,255,0.14);
  --accent-a:     #7c3aed;
  --accent-b:     #2563eb;
  --accent-grad:  linear-gradient(135deg, #7c3aed, #2563eb);
  --text:         #f0f0f8;
  --text-2:       #9ca3af;
  --text-3:       #6b7280;
  --green:        #10b981;
  --red:          #ef4444;
  --amber:        #f59e0b;
  --radius:       14px;
  --radius-sm:    8px;
  --shadow:       0 8px 32px rgba(0,0,0,0.5);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* ── Background orbs ── */
.bg-orbs {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden;
}
.bg-orbs::before,
.bg-orbs::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.35;
}
.bg-orbs::before {
  width: 700px; height: 700px;
  top: -200px; left: -150px;
  background: radial-gradient(circle, #7c3aed, transparent 70%);
}
.bg-orbs::after {
  width: 600px; height: 600px;
  bottom: -150px; right: -100px;
  background: radial-gradient(circle, #2563eb, transparent 70%);
}

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

.container { width: 100%; max-width: 900px; margin: 0 auto; padding: 0 20px; }
.container--wide { max-width: 1140px; }

/* ── Header ── */
header {
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 50;
  background: rgba(8,8,18,0.75);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.25rem; font-weight: 700; text-decoration: none; color: var(--text);
}
.logo-icon {
  width: 36px; height: 36px;
  background: var(--accent-grad);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.logo span { background: var(--accent-grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.header-badge {
  font-size: 0.7rem; font-weight: 600; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border-2);
  padding: 3px 10px; border-radius: 20px; letter-spacing: 0.05em;
}

/* ── Ad banner (top) ── */
.ad-banner {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
  text-align: center;
  min-height: 90px;
  display: flex; align-items: center; justify-content: center;
}
.ad-placeholder {
  color: var(--text-3); font-size: 0.75rem; letter-spacing: 0.05em;
}

/* ── Hero ── */
.hero {
  padding: 72px 0 56px;
  text-align: center;
}
.hero-label {
  display: inline-block;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: #a78bfa;
  background: rgba(124,58,237,0.12);
  border: 1px solid rgba(124,58,237,0.25);
  border-radius: 20px; padding: 4px 14px;
  margin-bottom: 24px;
}
.hero h1 {
  font-size: clamp(2rem, 5vw, 3.25rem);
  font-weight: 800; line-height: 1.15; letter-spacing: -0.02em;
  margin-bottom: 16px;
}
.hero h1 .grad {
  background: var(--accent-grad);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.hero p {
  color: var(--text-2); font-size: 1.05rem; max-width: 480px; margin: 0 auto 40px;
}

/* ── Search bar ── */
.search-wrap {
  max-width: 680px; margin: 0 auto;
}
.search-box {
  display: flex; align-items: center;
  background: var(--surface-2);
  border: 1.5px solid var(--border-2);
  border-radius: 16px;
  padding: 6px 6px 6px 20px;
  gap: 8px;
  transition: border-color .2s, box-shadow .2s;
}
.search-box:focus-within {
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124,58,237,0.15);
}
.search-box input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 0.95rem; font-family: inherit;
  min-width: 0;
}
.search-box input::placeholder { color: var(--text-3); }
.btn-fetch {
  flex-shrink: 0;
  background: var(--accent-grad);
  color: #fff; border: none; border-radius: 12px;
  padding: 11px 26px; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn-fetch:hover  { opacity: 0.88; }
.btn-fetch:active { transform: scale(0.97); }
.btn-fetch:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Spinner ── */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,0.15);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Alert ── */
.alert {
  display: flex; align-items: flex-start; gap: 12px;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  border-radius: var(--radius-sm); padding: 14px 16px;
  margin-top: 20px; font-size: 0.9rem;
  max-width: 680px; margin-left: auto; margin-right: auto;
}
.alert-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }

/* ── Results section ── */
#results { padding-bottom: 60px; }

/* ── Video info card ── */
.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px; margin-bottom: 28px;
  display: flex; gap: 20px; align-items: flex-start;
}
.video-thumb {
  flex-shrink: 0; width: 160px; border-radius: var(--radius-sm); overflow: hidden;
  aspect-ratio: 16/9; background: rgba(255,255,255,0.05);
}
.video-thumb 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: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 8px;
}
.video-sub {
  display: flex; flex-wrap: wrap; gap: 12px;
  color: var(--text-2); font-size: 0.82rem; margin-bottom: 10px;
}
.video-sub span { display: flex; align-items: center; gap: 4px; }
.video-sub svg { opacity: 0.6; }

/* ── Format tabs ── */
.tab-bar {
  display: flex; gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 20px;
  width: fit-content;
}
.tab-btn {
  background: none; border: none; color: var(--text-2);
  padding: 8px 18px; border-radius: 6px;
  font-size: 0.85rem; font-weight: 500; cursor: pointer;
  font-family: inherit; transition: background .15s, color .15s;
  display: flex; align-items: center; gap: 6px;
}
.tab-btn .count {
  background: var(--surface-2); border-radius: 20px;
  padding: 1px 7px; font-size: 0.73rem; color: var(--text-3);
}
.tab-btn.active {
  background: var(--accent-grad);
  color: #fff;
}
.tab-btn.active .count { background: rgba(255,255,255,0.2); color: #fff; }
.tab-btn:hover:not(.active) { background: var(--surface-2); color: var(--text); }

/* ── Format grid ── */
.format-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 12px;
}
.format-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  transition: border-color .2s, background .2s;
}
.format-card:hover {
  border-color: var(--border-2);
  background: var(--surface-2);
}
.format-header { display: flex; align-items: center; justify-content: space-between; }
.format-badge {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 6px;
}
.badge-4k  { background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3); }
.badge-2k  { background: rgba(168,85,247,0.15); color: #c084fc; border: 1px solid rgba(168,85,247,0.3); }
.badge-fhd { background: rgba(37,99,235,0.15);  color: #60a5fa; border: 1px solid rgba(37,99,235,0.3); }
.badge-hd  { background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3); }
.badge-sd  { background: rgba(107,114,128,0.15);color: #9ca3af; border: 1px solid rgba(107,114,128,0.3); }
.badge-audio { background: rgba(20,184,166,0.15); color: #2dd4bf; border: 1px solid rgba(20,184,166,0.3); }

.format-ext {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em;
  color: var(--text-3); text-transform: uppercase;
  background: var(--surface-2); padding: 3px 9px; border-radius: 6px;
}
.format-res {
  font-size: 1.15rem; font-weight: 700; color: var(--text);
}
.format-details {
  display: flex; flex-wrap: wrap; gap: 6px;
  font-size: 0.78rem; color: var(--text-2);
}
.detail-chip {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 8px;
}
.detail-chip.no-audio { color: #f87171; border-color: rgba(239,68,68,0.2); background: rgba(239,68,68,0.07); }
.format-size { font-size: 0.78rem; color: var(--text-3); }

.btn-dl {
  width: 100%; background: var(--accent-grad);
  color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 10px; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; font-family: inherit; text-align: center;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
}
.btn-dl:hover  { opacity: 0.85; }
.btn-dl:active { transform: scale(0.98); }
.btn-dl.is-loading { opacity: 0.9; pointer-events: none; }
.btn-dl .spinner { width: 16px; height: 16px; border-width: 2px; }

.empty-tab {
  grid-column: 1/-1;
  text-align: center; color: var(--text-3); font-size: 0.9rem;
  padding: 40px 20px;
}

/* ── Main content + sidebar layout ── */
.content-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}
@media (min-width: 1000px) {
  .content-layout { grid-template-columns: 1fr 300px; }
}
.sidebar {
  display: flex; flex-direction: column; gap: 20px;
}
.ad-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  min-height: 250px;
  display: flex; align-items: center; justify-content: center;
}
.ad-box-banner {
  min-height: 90px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 24px;
}

/* ── Footer ── */
footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 28px 0;
  text-align: center;
  color: var(--text-3);
  font-size: 0.8rem;
}
.footer-links { display: flex; justify-content: center; gap: 20px; margin-bottom: 10px; flex-wrap: wrap; }
.footer-links a { color: var(--text-2); text-decoration: none; transition: color .15s; }
.footer-links a:hover { color: var(--text); }

/* ── Util ── */
.hidden { display: none !important; }
.mt-4 { margin-top: 16px; }
.section-label {
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: 14px;
}

/* ── Download toast ── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 200;
  background: #10b981; color: #fff;
  border-radius: var(--radius-sm); padding: 14px 20px;
  font-size: 0.9rem; font-weight: 500;
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px;
  animation: slide-in .3s ease;
}
@keyframes slide-in { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast--error { background: var(--red); }
.toast--loading { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-2); }
.toast .spinner { width: 16px; height: 16px; border-width: 2px; }

/* ── Responsive ── */

/* Tablet: better touch targets */
@media (max-width: 768px) {
  .tab-btn { padding: 10px 14px; }
  .btn-dl { padding: 13px; }
}

/* Mobile */
@media (max-width: 600px) {
  /* Hero */
  .hero { padding: 40px 0 28px; }

  /* Search bar: stack vertically, prevent iOS zoom (font must be >= 16px) */
  .search-box {
    flex-direction: column;
    border-radius: var(--radius);
    padding: 12px;
    gap: 10px;
  }
  .search-box > svg { display: none; }
  .search-box input { font-size: 1rem; width: 100%; }
  .btn-fetch { width: 100%; justify-content: center; padding: 13px 26px; min-height: 44px; }

  /* Video card: stack thumbnail above metadata */
  .video-card { flex-direction: column; }
  .video-thumb { width: 100%; }
  .video-title { white-space: normal; }

  /* Tab bar: fill full width so tabs don't overflow */
  .tab-bar { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab-btn { flex: 1; justify-content: center; padding: 10px 6px; font-size: 0.75rem; white-space: nowrap; }
  .tab-btn .count { display: none; }

  /* Format grid: single column on narrow screens */
  .format-grid { grid-template-columns: 1fr; }

  /* Toast: span full width at bottom */
  .toast { left: 16px; right: 16px; bottom: 16px; width: auto; }
}

/* Very small screens (iPhone SE, etc.) */
@media (max-width: 380px) {
  .header-badge { display: none; }
  .container { padding: 0 14px; }
}
