:root {
  --bg: #0b0b12;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f3f2f8;
  --muted: #9b9aae;
  --accent: #7c5cff;
  --accent-2: #ff5c9d;
  --accent-soft: rgba(124, 92, 255, 0.16);
  --success: #2fd38a;
  --danger: #ff5c6c;
  --radius: 18px;
  --shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.6);
  --glow-opacity: 0.55;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f5fb;
    --surface: rgba(255, 255, 255, 0.75);
    --surface-2: #ffffff;
    --border: rgba(20, 16, 50, 0.08);
    --border-strong: rgba(20, 16, 50, 0.18);
    --text: #16141f;
    --muted: #6b6980;
    --accent-soft: rgba(124, 92, 255, 0.1);
    --shadow: 0 30px 70px -30px rgba(40, 30, 90, 0.25);
    --glow-opacity: 0.28;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.6; }
a { color: var(--accent); }

/* Background glows */
.glow {
  position: fixed;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  filter: blur(120px);
  opacity: var(--glow-opacity);
  pointer-events: none;
  z-index: 0;
}
.glow-a { background: var(--accent); top: -220px; left: -160px; }
.glow-b { background: var(--accent-2); bottom: -260px; right: -180px; opacity: calc(var(--glow-opacity) * 0.6); }

.shell {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 16px 40px;
}

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.logo {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 8px 24px -6px var(--accent);
}

/* Hero */
.hero { text-align: center; margin: 64px 0 32px; }
.hero h1 {
  font-size: clamp(34px, 6vw, 54px);
  line-height: 1.05;
  letter-spacing: -0.035em;
  font-weight: 800;
  margin: 0 0 14px;
}
.accent {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p { color: var(--muted); font-size: 17px; margin: 0; }

/* URL search bar */
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 4px var(--accent-soft);
}
.search-icon { color: var(--muted); margin-left: 10px; }
.search input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 12px 4px;
}
.search input::placeholder { color: var(--muted); opacity: 0.7; }

.primary {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 14px;
  padding: 13px 22px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #9b6bff 50%, var(--accent-2));
  background-size: 200% 100%;
  box-shadow: 0 10px 28px -10px var(--accent);
  transition: transform 0.15s, background-position 0.4s, box-shadow 0.2s;
  white-space: nowrap;
}
.primary:hover:not(:disabled) { background-position: 100% 0; transform: translateY(-1px); }
.primary:active:not(:disabled) { transform: translateY(0); }

.ghost {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 500;
  white-space: nowrap;
  transition: border-color 0.2s, background 0.2s;
}
.ghost:hover { border-color: var(--border-strong); }

.spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.loading .spinner { display: block; }
.loading .label { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Alert */
.alert {
  margin-top: 16px;
  padding: 14px 18px;
  border-radius: 14px;
  background: rgba(255, 92, 108, 0.1);
  border: 1px solid rgba(255, 92, 108, 0.35);
  color: var(--danger);
  font-size: 14px;
  animation: rise 0.3s ease;
}

/* Cards */
.card {
  margin-top: 24px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  animation: rise 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

.media { display: flex; gap: 18px; align-items: flex-start; }
.thumb {
  position: relative;
  width: 240px;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
  flex-shrink: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.badge:empty { display: none; }
.meta { min-width: 0; flex: 1; }
.site {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 8px;
  border-radius: 6px;
}
.site:empty { display: none; }
.meta h2 {
  font-size: 19px;
  line-height: 1.3;
  margin: 10px 0 6px;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.muted { color: var(--muted); font-size: 14px; margin: 0; }

/* Skeleton */
.sk {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border-strong) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
  border-radius: 8px;
}
.line { height: 16px; margin: 6px 0 12px; }
.w80 { width: 80%; } .w40 { width: 40%; }
.block { height: 54px; margin-top: 22px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Tabs */
.tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 22px 0 16px;
  padding: 5px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.tab {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px;
  border: 0;
  background: transparent;
  font-weight: 600;
  color: var(--muted);
  transition: color 0.2s;
}
.tab small { font-size: 11px; font-weight: 700; opacity: 0.7; }
.tab.active { color: #fff; }
.tab-indicator {
  position: absolute;
  top: 5px;
  bottom: 5px;
  left: 5px;
  width: calc(50% - 5px);
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px -6px var(--accent);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.tabs[data-kind="audio"] .tab-indicator { transform: translateX(100%); }

/* Quality options */
.options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}
.option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  text-align: left;
  transition: border-color 0.2s, transform 0.15s, background 0.2s;
  animation: rise 0.3s ease backwards;
}
.option:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.option .q { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.option .tag {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 3px 6px;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}
.option .s { font-size: 13px; color: var(--muted); }

.big { width: 100%; margin-top: 18px; padding: 16px; font-size: 16px; border-radius: 14px; }

/* Progress */
.progress { margin-top: 22px; animation: rise 0.3s ease; }
.progress-head {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 10px;
}
#percent { font-variant-numeric: tabular-nums; }
.bar {
  height: 10px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
#bar-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 16px var(--accent);
  transition: width 0.4s ease;
}
.bar.indeterminate #bar-fill {
  width: 35% !important;
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
.progress-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* Done */
.done {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 22px;
  padding: 16px;
  border-radius: 14px;
  background: rgba(47, 211, 138, 0.08);
  border: 1px solid rgba(47, 211, 138, 0.3);
  animation: rise 0.35s ease;
}
.done > div:nth-child(2) { flex: 1; }
.done p { margin-top: 2px; }
.check {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  flex-shrink: 0;
  animation: pop 0.4s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.check svg { stroke-width: 3; }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } }

.foot { text-align: center; margin-top: 48px; font-size: 13px; }

[hidden] { display: none !important; }

@media (max-width: 600px) {
  .hero { margin: 40px 0 24px; }
  .search { flex-wrap: wrap; }
  .search input { flex-basis: calc(100% - 40px); }
  .search .ghost, .search .primary { flex: 1; }
  .media { flex-direction: column; }
  .thumb { width: 100%; }
  .done { flex-wrap: wrap; }
  .done .ghost { width: 100%; }
}

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