:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface2: #181818;
  --border: #252525;
  --accent: #e8ff47;
  --accent2: #ff4757;
  --text: #f0f0f0;
  --muted: #666;
  --muted2: #444;
  --radius: 4px;
  --font-display: 'Syne', sans-serif;
  --font-mono: 'Space Mono', monospace;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Noise overlay ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* ── Header ── */
header {
  padding: 2rem 2rem 0;
  position: relative;
  z-index: 1;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.4rem, 3vw, 1.8rem);
  letter-spacing: -0.03em;
  text-decoration: none;
  color: var(--text);
}

.logo-badge {
  background: var(--accent);
  color: #000;
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 2px 6px;
  border-radius: 2px;
  text-transform: uppercase;
  vertical-align: super;
}

/* ── Main Layout ── */
main {
  max-width: 860px;
  margin: 0 auto;
  padding: 3rem 1.5rem 5rem;
  position: relative;
  z-index: 1;
}

/* ── Hero ── */
.hero {
  margin-bottom: 3rem;
  animation: fadeUp 0.6s ease both;
}

.hero h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 6vw, 3.8rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
  margin-bottom: 0.6rem;
}

.hero h1 span {
  color: var(--accent);
}

.hero p {
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.05em;
}

/* ── Input Card ── */
.input-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
  animation: fadeUp 0.6s 0.1s ease both;
}

.input-label {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.input-row {
  display: flex;
  gap: 0.75rem;
}

#url-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.75rem 1rem;
  outline: none;
  transition: border-color 0.2s;
}

#url-input:focus {
  border-color: var(--accent);
}

#url-input::placeholder { color: var(--muted2); }

.btn-fetch {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #000;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  padding: 0.75rem 1.5rem;
  transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-fetch:hover { opacity: 0.88; transform: translateY(-1px); }
.btn-fetch:active { transform: translateY(0); }
.btn-fetch:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Status / Error ── */
.status {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  margin-top: 0.75rem;
  min-height: 1.2em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.status.error { color: var(--accent2); }
.status.loading { color: var(--accent); }
.status.info { color: var(--muted); }

/* ── Loader dots ── */
.dots span {
  animation: blink 1.4s infinite;
  opacity: 0;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0; }
  40% { opacity: 1; }
}

/* ── Video Info Bar ── */
#video-info {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin-bottom: 1.5rem;
  flex-direction: row;
  gap: 1rem;
  align-items: center;
  animation: fadeUp 0.4s ease both;
}

#video-info.visible { display: flex; }

#video-thumbnail {
  width: 90px;
  height: 54px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.video-meta { flex: 1; min-width: 0; }

.video-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.25rem;
}

.video-sub {
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

/* ── Formats Section ── */
#formats-section {
  display: none;
  animation: fadeUp 0.4s ease both;
}

#formats-section.visible { display: block; }

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

.section-title {
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.filter-tabs {
  display: flex;
  gap: 4px;
}

.filter-tabs[hidden] {
  display: none;
}

.tab {
  background: none;
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  text-transform: uppercase;
  transition: all 0.15s;
}

.tab.active, .tab:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Format Grid ── */
#format-list {
  display: grid;
  gap: 0.5rem;
}

.format-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  display: grid;
  grid-template-columns: 1.5rem 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  transition: border-color 0.15s, background 0.15s;
}

.format-item:hover { border-color: var(--muted2); background: var(--surface2); }

.format-item.selected {
  border-color: var(--accent);
  background: rgba(232,255,71,0.05);
}

.format-radio {
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--muted2);
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
}

.format-item.selected .format-radio {
  border-color: var(--accent);
}

.format-radio::after {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.15s;
}

.format-item.selected .format-radio::after { opacity: 1; }

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

.format-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
}

.format-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.58rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 2px;
  border: 1px solid;
}

.tag-ext { color: #888; border-color: #333; }
.tag-va { color: #5fba7d; border-color: #2a4a35; }
.tag-vo { color: #e8a045; border-color: #4a3a1a; }
.tag-audio { color: #7b9cde; border-color: #2a3358; }

.format-size {
  font-size: 0.65rem;
  color: var(--muted);
  white-space: nowrap;
  font-family: var(--font-mono);
}

/* ── Download Bar ── */
#download-bar {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  margin: 2rem -1.5rem -5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  animation: slideUp 0.3s ease both;
  z-index: 10;
}

#download-bar.visible { display: flex; }

.download-selection-label {
  font-size: 0.7rem;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}

.download-selection-label strong {
  display: block;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-download {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #000;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  padding: 0.75rem 2rem;
  transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-download:hover { opacity: 0.85; transform: translateY(-1px); }
.btn-download:active { transform: translateY(0); }
.btn-download:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Progress Bar ── */
#progress-wrap {
  display: none;
  margin-top: 0.5rem;
}

#progress-wrap.visible { display: block; }

.progress-bar-outer {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-inner {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s;
  border-radius: 2px;
}

.progress-bar-inner.indeterminate {
  width: 40% !important;
  animation: slide 1.2s infinite;
}

@keyframes slide {
  0% { transform: translateX(-150%); }
  100% { transform: translateX(350%); }
}

.progress-text {
  font-size: 0.6rem;
  color: var(--muted);
  margin-top: 0.3rem;
  letter-spacing: 0.06em;
}

/* ── Animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ── Mobile ── */
@media (max-width: 540px) {
  header { padding: 1.25rem 1rem 0; }
  main { padding: 2rem 1rem 4rem; }

  .input-row { flex-direction: column; }
  .btn-fetch { width: 100%; }

  #video-info.visible {
    flex-direction: column;
    align-items: flex-start;
  }

  #video-thumbnail { width: 100%; height: auto; aspect-ratio: 16/9; }

  #download-bar {
    flex-direction: column;
    align-items: stretch;
    padding: 0.9rem 1rem;
    margin: 2rem -1rem -4rem;
  }

  .btn-download { width: 100%; text-align: center; }

  .filter-tabs { flex-wrap: wrap; }

  body::before { opacity: 0.015; }

  .hero,
  .input-card,
  #video-info,
  #formats-section,
  #download-bar {
    animation: none;
  }

  .format-item { grid-template-columns: 1.2rem 1fr; }

  .format-size {
    grid-column: 2 / -1;
    justify-self: start;
    white-space: normal;
  }

  .video-title,
  .format-label,
  .download-selection-label strong {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    word-break: break-word;
  }
}
