:root {
  color-scheme: dark;
  --bg: #0d1011;
  --header: #101415;
  --surface: #171c1e;
  --surface-2: #1d2426;
  --surface-3: #242d30;
  --border: #303a3d;
  --border-soft: #222a2c;
  --text: #f4f7f7;
  --muted: #9ba8ab;
  --primary: #f05a24;
  --primary-hover: #ff6b32;
  --mint: #20b486;
  --mint-soft: #14352e;
  --ok: #34c98f;
  --danger: #ff6b6b;
  --warn: #f0b44c;
  --focus: #72d8bb;
  --placeholder: #717e81;
  --hover-border: #465255;
  --progress-track: #090c0d;
  --radius: 8px;
  --max: 760px;
  --max-wide: 960px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7f6;
  --header: #ffffff;
  --surface: #ffffff;
  --surface-2: #edf2f0;
  --surface-3: #e2eae7;
  --border: #cfd9d6;
  --border-soft: #dfe6e4;
  --text: #17201e;
  --muted: #62716e;
  --primary: #df4e19;
  --primary-hover: #c94414;
  --mint: #087d63;
  --mint-soft: #dcefe9;
  --ok: #087b57;
  --danger: #c73a42;
  --warn: #9b6500;
  --focus: #087d63;
  --placeholder: #84918e;
  --hover-border: #9aa9a5;
  --progress-track: #dbe3e1;
  --shadow: 0 16px 38px rgba(24, 43, 38, 0.1);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  overflow-x: hidden;
}
button, input, select { font: inherit; }
button { letter-spacing: 0; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: fixed;
  left: -999px;
  top: 8px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
}
.skip-link:focus { left: 8px; }

/* Header */
.site-header {
  position: relative;
  z-index: 40;
  background: transparent;
}
.site-header-inner {
  width: min(var(--max-wide), 100%);
  margin: 0 auto;
  padding: 20px 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}
.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 8px;
  object-fit: cover;
}
.brand-text { display: grid; min-width: 0; line-height: 1.2; }
.brand-text strong { font-size: 15px; font-weight: 750; }
.brand-sub { margin-top: 3px; color: var(--muted); font-size: 11px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.browser-shortcuts {
  margin-left: 2px;
  padding-left: 10px;
  display: flex;
  align-items: center;
  gap: 5px;
  border-left: 1px solid var(--border-soft);
}
.browser-icon-link {
  width: 34px;
  height: 34px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  text-decoration: none;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.browser-icon-link img {
  width: 23px;
  height: 23px;
  display: block;
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.browser-icon-link::after {
  content: attr(data-label);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: 60;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -4px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.browser-icon-link:hover,
.browser-icon-link:focus-visible {
  transform: translateY(-2px);
  background: var(--surface-2);
  border-color: var(--border);
}
.browser-icon-link.firefox:hover,
.browser-icon-link.firefox:focus-visible { box-shadow: 0 7px 18px rgba(255, 103, 31, 0.2); }
.browser-icon-link.chrome:hover,
.browser-icon-link.chrome:focus-visible { box-shadow: 0 7px 18px rgba(33, 150, 83, 0.18); }
.browser-icon-link:hover img,
.browser-icon-link:focus-visible img { transform: scale(1.12) rotate(-5deg); }
.browser-icon-link.chrome:hover img,
.browser-icon-link.chrome:focus-visible img { transform: scale(1.12) rotate(5deg); }
.browser-icon-link:hover::after,
.browser-icon-link:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}
.theme-toggle {
  min-width: 42px;
  min-height: 30px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--hover-border); }
.theme-toggle-track {
  width: 30px;
  height: 20px;
  display: block;
  position: relative;
}
.theme-toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: transparent;
  transition: transform 0.18s ease, background 0.18s ease;
}
:root[data-theme="light"] .theme-toggle-knob {
  transform: translateX(10px);
  border-color: var(--primary);
  background: var(--primary);
}
.offline-pill {
  padding: 4px 8px;
  border: 1px solid #683536;
  border-radius: 999px;
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
}
.account { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 50;
  width: min(260px, 85vw);
  padding: 6px;
  display: grid;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.menu a, .menu button {
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu a:hover, .menu button:hover { background: var(--surface-2); }
.menu-email {
  padding: 7px 10px 9px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
  border-bottom: 1px solid var(--border-soft);
}

/* Loading */
.view-center {
  min-height: calc(100vh - 58px);
  display: grid;
  place-items: center;
  padding: 24px;
}
.loading-card { display: grid; justify-items: center; gap: 8px; }
.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--border);
  border-top-color: var(--mint);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Main converter */
.main {
  width: min(var(--max-wide), 100%);
  margin: 0 auto;
  padding: 0 20px 48px;
  position: relative;
}
.hero { padding: 36px 0 8px; }
.hero-inner { width: min(var(--max), 100%); margin: 0 auto; }
.intro { margin-bottom: 24px; text-align: center; }
.pro-label {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--mint);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
}
.hero h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1.1;
  font-weight: 780;
  letter-spacing: 0;
}
.lede { margin: 9px 0 0; color: var(--muted); font-size: 16px; }

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  margin-bottom: 10px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--header);
}
.mode-tab {
  min-height: 40px;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.mode-tab:hover { color: var(--text); }
.mode-tab[aria-selected="true"] { background: var(--surface-3); color: var(--text); }

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.composer { padding: 18px; }
.mode-hint { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.field { display: grid; gap: 6px; margin: 0 0 12px; color: var(--muted); font-size: 12px; }
.field > span { font-weight: 700; }
.field.inline { min-width: 132px; margin: 0; }
input[type="url"], input[type="email"], input[type="text"], select {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--header);
  color: var(--text);
  font-size: 15px;
}
input::placeholder { color: var(--placeholder); }
input:hover, select:hover { border-color: var(--hover-border); }
input:focus, select:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.composer-actions {
  display: grid;
  grid-template-columns: 150px minmax(180px, 1fr);
  gap: 10px;
  align-items: end;
}
.btn {
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 720;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--hover-border); background: var(--surface-3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { min-height: 48px; border-color: var(--primary); background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { border-color: var(--primary-hover); background: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.btn.full { width: 100%; }
.disclaimer { margin-top: 12px !important; }

/* Sign in and pricing */
.auth-gate { margin-top: 12px; padding: 18px; border-color: #3d494c; }
.auth-copy { margin-bottom: 14px; }
.auth-copy h2 { margin: 0 0 3px; font-size: 18px; }
.auth-copy p { margin: 0; }
.subscribe {
  margin-top: 18px;
  padding-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--border);
}
.subscribe > div:first-child { display: grid; gap: 2px; }
.subscribe strong { font-size: 13px; }
.subscribe span { color: var(--muted); font-size: 12px; }
.subscribe-actions { display: flex; gap: 8px; }
.auth-links { display: flex; justify-content: center; gap: 10px; }

/* Banners and work areas */
.banner, .workspace-block { width: min(var(--max), 100%); margin: 14px auto 0; }
.banner {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 13px;
}
.banner.ok { border-color: #245c49; background: #122a23; color: var(--ok); }
.banner.err { border-color: #673638; background: #2a1719; color: var(--danger); }
.playlist-panel { padding: 16px; }
.queue-section { padding-top: 10px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-head.sticky {
  position: sticky;
  top: 0;
  z-index: 15;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
}
.select-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.check { display: inline-flex; align-items: center; gap: 7px; margin-right: auto; color: var(--muted); font-size: 13px; }
.playlist-items, .queue-list { max-width: 100%; min-width: 0; list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.playlist-items li, .queue-item {
  min-width: 0;
  padding: 10px;
  display: grid;
  grid-template-columns: auto 56px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.playlist-items li { grid-template-columns: auto 56px minmax(0, 1fr); }
.thumb { width: 56px; height: 42px; object-fit: cover; border-radius: 5px; background: var(--header); }
.meta, .progress-meta, .item-actions { max-width: 100%; min-width: 0; }
.meta .title, .meta .sub, .meta .stage-line {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  unicode-bidi: plaintext;
}
.meta .title { font-size: 13px; font-weight: 700; }
.meta .sub, .meta .stage-line { margin-top: 2px; color: var(--muted); font-size: 11px; }
.item-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.pill {
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: capitalize;
}
.pill.downloading, .pill.converting { border-color: #684225; color: #ff9469; }
.pill.completed { border-color: #245c49; color: var(--ok); }
.pill.failed, .pill.cancelled { border-color: #673638; color: var(--danger); }
.progress { height: 5px; margin-top: 7px; overflow: hidden; border-radius: 99px; background: var(--progress-track); }
.progress > i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--mint); transition: width 0.35s ease; }
.progress-meta { margin-top: 4px; display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 10px; }
.pct-label { color: var(--text); font-weight: 750; font-variant-numeric: tabular-nums; }

.status { min-height: 1.2em; margin: 9px 0 0; color: var(--muted); font-size: 12px; }
.status.err { color: var(--danger); }
.status.ok { color: var(--ok); }
.fine { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.fine a, .site-footer a { color: var(--muted); }
.fine a:hover, .site-footer a:hover { color: var(--text); }
.muted { color: var(--muted); font-size: 12px; }
.empty {
  margin: 0;
  padding: 22px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.site-footer {
  width: min(var(--max-wide), 100%);
  margin: 0 auto;
  padding: 4px 20px 24px;
  display: flex;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 640px) {
  .site-header-inner { padding: 14px 14px 0; }
  .brand-mark { width: 34px; height: 34px; flex-basis: 34px; }
  .brand-sub { display: none; }
  .main { padding: 0 12px 36px; }
  .hero { padding-top: 24px; }
  .intro { margin-bottom: 18px; }
  .pro-label { margin-bottom: 7px; }
  .hero h1 { font-size: 32px; }
  .lede { font-size: 14px; }
  .mode-tab { min-height: 38px; padding: 7px 5px; }
  .composer, .auth-gate, .playlist-panel { padding: 12px; }
  .composer-actions { grid-template-columns: minmax(112px, 0.8fr) minmax(0, 1.2fr); }
  .field.inline { min-width: 0; }
  .quality-field span { font-size: 11px; }
  .btn { padding-inline: 11px; }
  .subscribe { align-items: stretch; flex-direction: column; }
  .subscribe-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .browser-shortcuts { margin-left: 0; padding-left: 2px; gap: 2px; border-left: 0; }
  .browser-icon-link { width: 31px; height: 31px; }
  .browser-icon-link img { width: 21px; height: 21px; }
  .panel-head.sticky { top: 0; }
  .queue-section { max-width: 100%; min-width: 0; overflow: hidden; }
  .playlist-items li { grid-template-columns: auto 48px minmax(0, 1fr); }
  .queue-item {
    max-width: 100%;
    grid-template-columns: 48px minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    align-items: start;
    overflow: hidden;
  }
  .thumb { width: 48px; height: 36px; }
  .queue-item > .thumb { grid-column: 1; grid-row: 1 / span 2; }
  .queue-item > .meta { grid-column: 2; grid-row: 1; }
  .queue-item > .pill { grid-column: 2; grid-row: 2; justify-self: start; margin-top: 5px; }
  .queue-item > .item-actions { grid-column: 1 / -1; grid-row: 3; justify-content: flex-start; }
  .item-actions .btn { max-width: 100%; }
  .site-footer { padding: 2px 14px 24px; }
}

@media (max-width: 370px) {
  .composer-actions { grid-template-columns: 1fr; }
  .subscribe-actions { grid-template-columns: 1fr; }
  .header-actions { gap: 4px; }
  .brand-text strong { font-size: 13px; }
  .hero h1 { font-size: 29px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
