/* ==========================================================================
   Downlynk — design language
   ========================================================================== */

:root,
html[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0B1220;
  --surface: #121B2E;
  --surface-2: #182338;
  --text: #F4F6FA;
  --muted: #8C99B0;
  --muted-faint: #5c6a82;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.18);
  --coral: #FF4D5E;
  --coral-dim: #C93C49;
  --coral-soft: rgba(255, 77, 94, 0.14);
  --mint: #2BD4A6;
  --mint-dim: #17A480;
  --mint-soft: rgba(43, 212, 166, 0.14);
  --mint-ink: #06231B;
  --amber: #F2B84B;
  --amber-soft: rgba(242, 184, 75, 0.16);
  --danger: #FF6B6B;
  --danger-soft: rgba(255, 107, 107, 0.14);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

html[data-theme='light'] {
  color-scheme: light;
  --bg: #F4F5F2;
  --surface: #FFFFFF;
  --surface-2: #EFF1EE;
  --text: #12151A;
  --muted: #5a6360;
  --muted-faint: #838d89;
  --border: #DCE1DE;
  --border-strong: #C7CDC9;
  --coral: #DE3346;
  --coral-dim: #B72939;
  --coral-soft: rgba(222, 51, 70, 0.1);
  --mint: #12886F;
  --mint-dim: #0C6B57;
  --mint-soft: rgba(18, 136, 111, 0.1);
  --mint-ink: #ffffff;
  --amber: #A6690F;
  --amber-soft: rgba(166, 105, 15, 0.12);
  --danger: #C8392F;
  --danger-soft: rgba(200, 57, 47, 0.1);
  --shadow: 0 20px 45px rgba(20, 24, 26, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    radial-gradient(1100px 600px at 85% -10%, var(--mint-soft), transparent 60%),
    radial-gradient(900px 500px at -5% 110%, var(--coral-soft), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background 220ms ease, color 220ms ease;
}

.shell {
  width: min(1180px, 92%);
  margin-inline: auto;
}

h1,
h2,
.brand,
.video-title {
  font-family: 'Space Grotesk', sans-serif;
}

.mono {
  font-family: 'JetBrains Mono', monospace;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--coral);
  color: #fff;
  padding: 0.7rem 1rem;
  border-radius: 0 0 0.5rem 0;
  z-index: 999;
}

.skip-link:focus {
  left: 0;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--coral);
  outline-offset: 3px;
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 1.05rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.brand-logo {
  height: 36px;
  width: auto;
  flex: 0 0 auto;
  border-radius: 0.6rem;
  display: block;
}

.brand-word {
  color: var(--text);
}

@media (max-width: 480px) {
  .brand-logo {
    height: 30px;
  }
}

.theme-toggle {
  width: 3.4rem;
  height: 1.85rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0 0.4rem;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
}

.theme-toggle .bi-moon-stars {
  margin-right: auto;
}

.theme-toggle .bi-sun {
  margin-left: auto;
}

.theme-toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 50%;
  background: var(--coral);
  transition: transform 220ms cubic-bezier(.4, 0, .2, 1);
}

html[data-theme='light'] .theme-toggle-knob {
  transform: translateX(calc(3.4rem - 1.85rem - 2px));
}

/* ---------- Hero ---------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.9fr);
  gap: clamp(2rem, 4vw, 4rem);
  padding-block: clamp(2.5rem, 6vw, 4.5rem) clamp(2.5rem, 5vw, 4rem);
  align-items: start;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mint);
  font-weight: 600;
  margin: 0 0 1.1rem;
}

.eyebrow-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 0 4px var(--mint-soft);
}

.hero-title {
  font-size: clamp(2.2rem, 4.2vw, 3.1rem);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.02em;
}

.hero-title .accent {
  color: var(--coral);
}

.hero-subtitle {
  color: var(--muted);
  font-size: 1.02rem;
  max-width: 48ch;
  margin: 0.9rem 0 1.4rem;
}

.platform-strip {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0;
  margin: 0 0 1.5rem;
}

.platform-strip li {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  font-size: 0.8rem;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

.platform-strip i {
  color: var(--muted-faint);
}

/* ---------- Intake (URL bar) ---------- */

.intake {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 7px 7px 7px 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  transition: border-color 180ms ease, background 180ms ease;
}

.intake:focus-within {
  border-color: color-mix(in srgb, var(--coral) 55%, var(--border));
}

.intake.is-dragover {
  border-color: var(--coral);
  background: var(--coral-soft);
}

.intake-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  flex-wrap: wrap;
}

.intake-dots {
  display: flex;
  gap: 5px;
  margin-right: 2px;
}

.intake-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.intake-dot.r {
  background: #ff5f57;
}

.intake-dot.y {
  background: #febc2e;
}

.intake-dot.g {
  background: #28c840;
}

.intake-input {
  flex: 1 1 220px;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.92rem;
  padding: 10px 0;
}

.intake-input::placeholder {
  color: var(--muted-faint);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.7rem 1rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease, box-shadow 150ms ease;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-fetch {
  border: none;
  background: var(--coral);
  color: #fff;
  box-shadow: 0 8px 18px var(--coral-soft);
}

.btn-fetch:hover {
  background: var(--coral-dim);
}

.btn-clear:hover {
  background: var(--border);
}

.drop-hint {
  display: none;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  margin: 0.3rem 0.2rem 0;
  font-size: 0.78rem;
  color: var(--coral);
  font-family: 'JetBrains Mono', monospace;
}

.intake.is-dragover .drop-hint {
  display: flex;
}

.paste-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 12px;
}

.paste-hint kbd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 7px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.76rem;
  color: var(--text);
}

.detect-row {
  margin-top: 1.1rem;
  min-height: 2rem;
}

.detect-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-family: 'JetBrains Mono', monospace;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}

.detect-badge.is-valid {
  border-color: color-mix(in srgb, var(--mint) 45%, var(--border));
  background: var(--mint-soft);
  color: var(--mint);
}

.detect-badge.is-unknown {
  border-color: color-mix(in srgb, var(--amber) 45%, var(--border));
  background: var(--amber-soft);
  color: var(--amber);
}

.detect-badge.is-invalid {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
  background: var(--danger-soft);
  color: var(--danger);
}

.scan-indicator {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.scan-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
}

.scan-bars span {
  width: 3px;
  background: var(--coral);
  border-radius: 2px;
  animation: scanBar 900ms ease-in-out infinite;
}

.scan-bars span:nth-child(1) {
  height: 30%;
  animation-delay: 0ms
}

.scan-bars span:nth-child(2) {
  height: 60%;
  animation-delay: 80ms
}

.scan-bars span:nth-child(3) {
  height: 100%;
  animation-delay: 160ms
}

.scan-bars span:nth-child(4) {
  height: 45%;
  animation-delay: 240ms
}

.scan-bars span:nth-child(5) {
  height: 80%;
  animation-delay: 320ms
}

.scan-bars span:nth-child(6) {
  height: 55%;
  animation-delay: 400ms
}

.scan-bars span:nth-child(7) {
  height: 35%;
  animation-delay: 480ms
}

@keyframes scanBar {

  0%,
  100% {
    transform: scaleY(.4);
    opacity: .55
  }

  50% {
    transform: scaleY(1);
    opacity: 1
  }
}

.trust-row {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0;
  margin: 1.6rem 0 0;
}

.trust-row li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  padding: 7px 13px;
  border-radius: 100px;
}

.trust-row i {
  color: var(--mint);
  font-size: 0.85rem;
}

/* ---------- Preview / video card ---------- */

.hero-panel {
  position: relative;
}

.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow);
}

#previewCard.video-card {
  animation: cardIn 320ms cubic-bezier(.16, 1, .3, 1);
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(10px)
  }

  to {
    opacity: 1;
    transform: translateY(0)
  }
}

.video-thumb {
  position: relative;
  border-radius: 13px;
  overflow: hidden;
  aspect-ratio: 16/9;
  background: var(--surface-2);
}

.preview-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.play-btn {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.2rem;
  pointer-events: none;
}

.duration-badge {
  position: absolute;
  bottom: 9px;
  right: 9px;
  background: rgba(0, 0, 0, 0.65);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 6px;
  color: #fff;
}

.quality-badge {
  position: absolute;
  top: 9px;
  left: 9px;
  background: var(--mint-soft);
  border: 1px solid color-mix(in srgb, var(--mint) 55%, transparent);
  color: var(--mint);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 6px;
  letter-spacing: 0.03em;
}

.video-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.channel-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex: 0 0 34px;
  background: linear-gradient(145deg, var(--mint), var(--mint-dim));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--mint-ink);
  font-weight: 700;
  font-size: 0.85rem;
}

.video-meta-text {
  min-width: 0;
}

.video-title {
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.video-sub {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 2px;
}

.quality-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  font-weight: 600;
  margin: 16px 0 8px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.download-type-head {
  font-size: 0.82rem;
  font-weight: 600;
  margin: 16px 0 8px;
}

.download-type-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.type-chip {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
}

.type-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.type-chip.active {
  background: var(--coral-soft);
  border-color: color-mix(in srgb, var(--coral) 55%, var(--border));
  color: var(--text);
}

.quality-note {
  font-weight: 400;
  color: var(--muted-faint);
  font-size: 0.76rem;
  font-family: 'JetBrains Mono', monospace;
}

.format-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}

.format-chip {
  flex: 1 1 auto;
  min-width: 92px;
  text-align: center;
  font-size: 0.76rem;
  font-family: 'JetBrains Mono', monospace;
  padding: 8px 6px;
  border-radius: 9px;
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  transition: all 150ms ease;
  background: transparent;
}

.format-chip:hover {
  border-color: var(--border-strong);
}

.format-chip.active {
  background: var(--coral-soft);
  border-color: color-mix(in srgb, var(--coral) 55%, var(--border));
  color: var(--text);
}

.format-chip strong {
  display: block;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 0.82rem;
  margin-bottom: 1px;
}

.download-block {
  margin-top: 2px;
}

.meter {
  height: 0.45rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--coral), var(--mint));
  transition: width 320ms ease;
}

.meter-text {
  margin: 0.45rem 0 0.9rem;
  font-size: 0.78rem;
  color: var(--muted-faint);
  font-family: 'JetBrains Mono', monospace;
}

.download-progress-details {
  margin: -0.55rem 0 0.9rem;
  font-size: 0.74rem;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

.btn-download {
  width: 100%;
  background: var(--mint);
  border: none;
  color: var(--mint-ink);
  font-weight: 700;
  font-size: 1rem;
  padding: 15px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 12px 26px var(--mint-soft);
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.btn-download:hover {
  transform: translateY(-2px);
  background: var(--mint-dim);
}

.btn-download:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-cancel {
  width: 100%;
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-weight: 700;
  font-size: 0.92rem;
  padding: 13px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
}

.btn-cancel:hover {
  background: var(--danger-soft);
}

.secure-line {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted-faint);
  margin: 10px 0 0;
}

/* ---------- Empty state ---------- */

.preview-empty {
  text-align: center;
  color: var(--muted-faint);
  position: relative;
  overflow: hidden;
  min-height: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.preview-empty i {
  font-size: 1.8rem;
}

.preview-empty p {
  max-width: 26ch;
  margin: 0;
  font-size: 0.92rem;
}

.empty-rings {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.empty-rings span {
  position: absolute;
  border: 1px solid var(--border);
  border-radius: 50%;
  animation: ringGrow 3.6s ease-out infinite;
}

.empty-rings span:nth-child(1) {
  animation-delay: 0s;
}

.empty-rings span:nth-child(2) {
  animation-delay: 1.2s;
}

.empty-rings span:nth-child(3) {
  animation-delay: 2.4s;
}

@keyframes ringGrow {
  0% {
    width: 60px;
    height: 60px;
    opacity: .6
  }

  100% {
    width: 340px;
    height: 340px;
    opacity: 0
  }
}

/* ---------- Footer ---------- */

.footer-strip {
  border-top: 1px solid var(--border);
  padding-block: 1.4rem;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 0.78rem;
  color: var(--muted-faint);
}

.footer-inner nav a {
  color: var(--muted-faint);
  margin-left: 16px;
  text-decoration: none;
}

.footer-inner nav a:hover {
  color: var(--muted);
}

.footer-brand {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  color: var(--text);
}

/* ---------- Toasts ---------- */

.toast-container {
  position: fixed;
  top: 1.2rem;
  right: 1.2rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: min(360px, calc(100vw - 2.4rem));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  border-radius: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  color: var(--text);
  transform: translateX(120%);
  opacity: 0;
  transition: transform 260ms cubic-bezier(.16, 1, .3, 1), opacity 260ms ease;
}

.toast.is-visible {
  transform: translateX(0);
  opacity: 1;
}

.toast.toast-success i {
  color: var(--mint);
}

.toast.toast-error i {
  color: var(--danger);
}

.toast.toast-info i {
  color: var(--coral);
}

/* ---------- Utility ---------- */
.d-none {
  display: none !important;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 767px) {

  /* Intake bar: input on its own row, three buttons in one horizontal row below */
  .intake {
    padding: 6px;
  }

  .intake-row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    align-items: stretch;
  }

  .intake-dots {
    display: none;
  }

  .intake-input {
    flex: 1 1 100%;
    /* forces full-width row for the input */
    min-width: 0;
    font-size: 0.84rem;
    padding: 10px 6px;
  }

  /* All three buttons share one row equally */
  .intake-row .btn {
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
    padding: 0.6rem 0.5rem;
    font-size: 0.82rem;
    gap: 0.3rem;
    border-radius: 8px;
  }

  .footer-inner {
    flex-direction: column;
  }

  .footer-inner nav a:first-child {
    margin-left: 0;
  }
}

/* Extra-small screens (320px–380px): tighter spacing for three buttons */
@media (max-width: 380px) {
  .intake-row .btn {
    padding: 0.5rem 0.25rem;
    font-size: 0.74rem;
    gap: 0.2rem;
  }

  .intake-row .btn i {
    font-size: 0.78rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}