/* ---------------------------------------------------------------
   Toolskits
   Idea: the colour bars of a video test pattern. Each quality tier owns
   one bar colour (chips, progress, done state) so colour carries meaning.
   Progress is drawn as film frames. Everything uses logical properties so
   the layout flips cleanly for Persian (RTL).
---------------------------------------------------------------- */

@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  --bg: #edf0f5;
  --surface: #ffffff;
  --ink: #151a2e;
  --muted: #566080;
  --line: #d3d9e6;
  --primary: #2b3de0;
  --primary-ink: #ffffff;
  --danger: #b3261e;
  --ok: #1b7f4b;
  --focus: #2b3de0;

  --q360: #e8b800;
  --q480: #0a9cbd;
  --q720: #1fa35b;
  --q1080: #d6338e;
  --qaudio: #3b5bff;

  --radius: 8px;
  --font: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d111f;
    --surface: #151a2c;
    --ink: #e8ebf7;
    --muted: #9aa5c6;
    --line: #2a3350;
    --primary: #8c9bff;
    --primary-ink: #0d111f;
    --danger: #ff8a80;
    --ok: #5fd69a;
    --focus: #8c9bff;

    --q360: #ffd84a;
    --q480: #35c8e8;
    --q720: #43d486;
    --q1080: #ff6bb5;
    --qaudio: #7c8dff;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.ico { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

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

a { color: inherit; }
.link { color: var(--primary); text-underline-offset: 3px; }

/* ---------- identity: colour bars ---------- */
.bars {
  height: 6px;
  background: linear-gradient(90deg,
    var(--q360) 0 20%, var(--q480) 20% 40%, var(--q720) 40% 60%,
    var(--q1080) 60% 80%, var(--qaudio) 80% 100%);
}

.mark { width: 34px; height: 20px; }
.mark .b1 { fill: var(--q360); }
.mark .b2 { fill: var(--q480); }
.mark .b3 { fill: var(--q720); }
.mark .b4 { fill: var(--q1080); }
.mark .b5 { fill: var(--qaudio); }

/* ---------- top bar ---------- */
.brand { display: inline-flex; align-items: center; gap: 0.6rem; text-decoration: none; font-weight: 800; font-size: 1.15rem; }

.badge-on {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.3rem 0.6rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
  color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--surface));
}
.badge-on::before { content: ""; width: 0.45rem; height: 0.45rem; border-radius: 50%; background: var(--ok); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 2.5rem; padding: 0.45rem 1rem;
  font: inherit; font-weight: 600; line-height: 1.2; text-decoration: none;
  border: 1px solid transparent; border-radius: var(--radius); cursor: pointer;
  background: transparent; color: var(--ink);
}
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: var(--line); }
.btn.ghost:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.btn.small { min-height: 2rem; padding: 0.2rem 0.75rem; font-size: 0.9rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: progress; }

.icon-btn {
  display: inline-grid; place-items: center; width: 2.25rem; height: 2.25rem;
  border: 0; border-radius: var(--radius); background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 8%, transparent); }

main { max-width: 68rem; margin-inline: auto; padding: 0 1.25rem 3rem; }

/* ---------- hero + search ---------- */
.hero { padding-block: clamp(1.5rem, 5vw, 3.5rem) 1.5rem; max-width: 46rem; }
h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(2rem, 6.2vw, 3.6rem);
  font-weight: 800;
  line-height: 1.12;
  text-wrap: balance;
}
/* Negative tracking would break Persian letter joining, so Latin only. */
h1:lang(en) { letter-spacing: -0.025em; }
.lead { margin: 0 0 1.75rem; color: var(--muted); font-size: 1.1rem; max-width: 38rem; }

.search {
  position: relative; display: flex; gap: 0.5rem;
  padding: 0.4rem; background: var(--surface);
  border: 2px solid var(--ink); border-radius: 12px;
}
.search:focus-within { border-color: var(--primary); }
.search .lead-ico { position: absolute; inset-inline-start: 1.1rem; top: 50%; translate: 0 -50%; color: var(--muted); width: 1.3rem; height: 1.3rem; }
.search input {
  flex: 1; min-width: 0; height: 3rem;
  padding-inline: 2.9rem 0.5rem;
  font: inherit; font-size: 1.05rem; color: var(--ink);
  background: transparent; border: 0; outline: 0;
}
.search input::placeholder { color: var(--muted); }
.search .btn { min-height: 3rem; padding-inline: 1.5rem; }

/* ---------- results: a list, not a card grid ---------- */
.status { margin: 1.5rem 0 0; color: var(--muted); }
.status[data-kind="error"] { color: var(--danger); font-weight: 600; }

.list { list-style: none; margin: 1.5rem 0 0; padding: 0; border-block-start: 1px solid var(--line); }

.row {
  display: grid;
  grid-template-columns: 10.5rem minmax(0, 1fr) minmax(0, 22rem);
  gap: 0.5rem 1.25rem; align-items: center;
  padding-block: 1rem; border-block-end: 1px solid var(--line);
}

.thumb {
  position: relative; aspect-ratio: 16 / 9; overflow: hidden;
  border-radius: 6px; background: color-mix(in srgb, var(--ink) 10%, var(--surface));
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.missing img { visibility: hidden; }
.dur {
  position: absolute; inset-block-end: 4px; inset-inline-end: 4px;
  padding: 0 0.4rem; border-radius: 4px; font-size: 0.78rem; font-weight: 600; line-height: 1.5;
  background: rgb(10 12 28 / 0.82); color: #fff; font-variant-numeric: tabular-nums;
}

.info { min-width: 0; }
.title {
  margin: 0; font-size: 1.02rem; font-weight: 700; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.meta { margin: 0.25rem 0 0; display: flex; flex-wrap: wrap; gap: 0.15rem 1rem; color: var(--muted); font-size: 0.9rem; }

/* ---------- quality chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  --c: var(--q360);
  display: inline-flex; align-items: center; gap: 0.45rem;
  min-height: 2.25rem; padding: 0.25rem 0.8rem;
  font: inherit; font-size: 0.92rem; font-weight: 700; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.chip::before { content: ""; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--c); }
.chip:hover { border-color: var(--c); background: color-mix(in srgb, var(--c) 14%, var(--surface)); }
.chip[data-q="360"]   { --c: var(--q360); }
.chip[data-q="480"]   { --c: var(--q480); }
.chip[data-q="720"]   { --c: var(--q720); }
.chip[data-q="1080"]  { --c: var(--q1080); }
.chip[data-q="audio"] { --c: var(--qaudio); }

/* ---------- job state inside a row ---------- */
.job[data-q="360"], .done[data-q="360"]     { --c: var(--q360); }
.job[data-q="480"], .done[data-q="480"]     { --c: var(--q480); }
.job[data-q="720"], .done[data-q="720"]     { --c: var(--q720); }
.job[data-q="1080"], .done[data-q="1080"]   { --c: var(--q1080); }
.job[data-q="audio"], .done[data-q="audio"] { --c: var(--qaudio); }

.job-label { margin: 0 0 0.4rem; font-size: 0.92rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.job-pause { margin-top: 0.6rem; }

/* Film frames: a segmented bar; the fill is masked by the same pattern. */
.strip {
  --seg: 9px; --gap: 3px;
  height: 14px; border-radius: 2px; overflow: hidden;
  background: color-mix(in srgb, var(--ink) 14%, transparent);
  -webkit-mask: repeating-linear-gradient(90deg, #000 0 var(--seg), transparent var(--seg) calc(var(--seg) + var(--gap)));
          mask: repeating-linear-gradient(90deg, #000 0 var(--seg), transparent var(--seg) calc(var(--seg) + var(--gap)));
}
.strip > i {
  display: block; height: 100%; width: var(--p, 0%);
  background: var(--c, var(--primary)); transition: width 0.45s ease;
}
.strip.indeterminate > i { width: 35%; animation: sweep 1.3s ease-in-out infinite alternate; }
@keyframes sweep { from { transform: translateX(0); } to { transform: translateX(185%); } }
[dir="rtl"] .strip.indeterminate > i { animation-name: sweep-rtl; }
@keyframes sweep-rtl { from { transform: translateX(0); } to { transform: translateX(-185%); } }

.done { display: flex; flex-direction: column; align-items: flex-start; gap: 0.4rem; }
.done .btn.primary { background: var(--c); color: #0d111f; }
.done-info { margin: 0; display: flex; flex-wrap: wrap; gap: 0 0.9rem; color: var(--muted); font-size: 0.88rem; font-variant-numeric: tabular-nums; }

.fail { display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; }
.fail-msg { margin: 0; display: flex; gap: 0.5rem; align-items: flex-start; color: var(--danger); font-size: 0.92rem; font-weight: 600; }
.fail-msg .ico { margin-block-start: 0.2em; }
.note-inline { margin: 0; color: var(--muted); font-size: 0.92rem; }

/* ---------- plans ---------- */
.plans { padding-block-start: 3.5rem; }
.plans h2 { margin: 0 0 1rem; font-size: 1.5rem; font-weight: 800; }
.table-wrap { overflow-x: auto; }
.plans-table { width: 100%; max-width: 40rem; border-collapse: collapse; }
.plans-table th, .plans-table td { padding: 0.7rem 0.9rem; text-align: start; border-block-end: 1px solid var(--line); }
.plans-table thead th { font-weight: 800; border-block-end: 2px solid var(--ink); }
.plans-table thead th.current { color: var(--primary); }
.plans-table tbody th { font-weight: 500; color: var(--muted); }
.plans-table td { font-variant-numeric: tabular-nums; font-weight: 600; }
.note { margin: 0.9rem 0 0; color: var(--muted); font-size: 0.95rem; }

.footer { max-width: 68rem; margin-inline: auto; padding: 1.5rem 1.25rem 2.5rem; color: var(--muted); font-size: 0.9rem; border-block-start: 1px solid var(--line); }
.footer p { margin: 0; }

/* ---------- dialogs ---------- */
dialog {
  width: min(26rem, calc(100% - 2rem)); padding: 1.25rem 1.4rem 1.4rem;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
}
dialog::backdrop { background: rgb(8 10 24 / 0.6); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-block-end: 0.75rem; }
.dlg-head h2 { margin: 0; font-size: 1.25rem; font-weight: 800; }
.dlg-actions { display: flex; gap: 0.5rem; justify-content: space-between; margin-block-start: 1.25rem; flex-wrap: wrap; }

.tabs { display: flex; gap: 0; margin-block-end: 1rem; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tabs button {
  flex: 1; padding: 0.55rem 0.5rem; font: inherit; font-weight: 600; color: var(--muted);
  background: transparent; border: 0; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--surface); }

.field { display: block; margin-block-end: 0.9rem; }
.field span { display: block; margin-block-end: 0.3rem; font-size: 0.92rem; font-weight: 600; }
.field input {
  width: 100%; height: 2.75rem; padding-inline: 0.75rem; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
}
.field input:focus { outline: 3px solid var(--focus); outline-offset: 1px; border-color: transparent; }
/* username/password are Latin: keep them left-to-right even on the RTL page */
.field input { direction: ltr; text-align: start; }
[dir="rtl"] .field input { text-align: right; }

.hint { margin: 0 0 0.9rem; color: var(--muted); font-size: 0.88rem; }
.error { margin: 0 0 0.9rem; color: var(--danger); font-weight: 600; font-size: 0.92rem; }

.acct-user { display: flex; align-items: center; gap: 0.6rem; margin-block-end: 0.4rem; }
.badge { padding: 0.1rem 0.6rem; border-radius: 999px; font-size: 0.8rem; font-weight: 700; background: var(--ink); color: var(--surface); }
.sub { margin: 1rem 0 0.6rem; font-size: 1rem; font-weight: 700; }
.meter { margin-block-end: 0.9rem; }
.meter-head { display: flex; justify-content: space-between; gap: 1rem; margin-block-end: 0.3rem; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.meter-head .val { color: var(--muted); }
.meter .strip > i { background: var(--primary); }

/* ---------- small screens ---------- */
@media (max-width: 47.99rem) {
  .row { grid-template-columns: 7rem minmax(0, 1fr); }
  .row .slot { grid-column: 1 / -1; }
  .search .btn { padding-inline: 1rem; }
}

@media (max-width: 30rem) {
  .btn .ico + span { max-width: 7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #signin-btn .ico, #lang-btn .ico { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .strip > i { transition: none; }
  .strip.indeterminate > i { animation: none; width: 100%; opacity: 0.45; }
}

/* ---------- manual theme switch (overrides the OS preference) ---------- */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #edf0f5; --surface: #ffffff; --ink: #151a2e; --muted: #566080; --line: #d3d9e6;
  --primary: #2b3de0; --primary-ink: #ffffff; --danger: #b3261e; --ok: #1b7f4b; --focus: #2b3de0;
  --q360: #e8b800; --q480: #0a9cbd; --q720: #1fa35b; --q1080: #d6338e; --qaudio: #3b5bff;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d111f; --surface: #151a2c; --ink: #e8ebf7; --muted: #9aa5c6; --line: #2a3350;
  --primary: #8c9bff; --primary-ink: #0d111f; --danger: #ff8a80; --ok: #5fd69a; --focus: #8c9bff;
  --q360: #ffd84a; --q480: #35c8e8; --q720: #43d486; --q1080: #ff6bb5; --qaudio: #7c8dff;
}
.theme-btn { padding: .45rem .6rem; }
.theme-btn svg { inline-size: 1.15rem; block-size: 1.15rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
body, .topbar, .row, .chip { transition: background-color .25s, color .25s, border-color .25s; }

/* ---------- all-qualities panel (main page) ---------- */
.chip[data-q="144"], .chip[data-q="240"] { --c: var(--q360); }
.chip[data-q="1440"], .chip[data-q="2160"], .chip[data-q="4320"] { --c: var(--q1080); }
.chip-more { --c: var(--primary); border-style: dashed; }
.qpanel { display: grid; gap: .8rem; animation: qp-in .25s ease both; }
.qhead { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.qgroup h4 { margin: 0 0 .4rem; font-size: .85rem; color: var(--muted); font-weight: 600; }
.qpills { display: flex; flex-wrap: wrap; gap: .4rem; }
.qpill { --c: var(--primary); display: inline-flex; align-items: center; gap: .4rem; padding: .4rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font: inherit; font-size: .88rem; cursor: pointer; transition: background .15s, border-color .15s, transform .1s; }
.qpill::before { content: ""; inline-size: .6rem; block-size: .6rem; border-radius: 50%; background: var(--c); }
.qpill small { color: var(--muted); font-size: .75rem; }
.qpill:hover { border-color: var(--c); }
.qpill:active { transform: scale(.97); }
.qpill[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, var(--surface)); font-weight: 600; }
.qpill[aria-pressed="true"]::before { content: "✓"; display: grid; place-items: center; inline-size: 1rem; block-size: 1rem; font-size: .7rem; color: #fff; }
.qnote { margin: .4rem 0 0; color: var(--muted); font-size: .8rem; }
.qline { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .4rem .8rem; padding: .5rem 0; border-block-start: 1px solid var(--line); }
.qline:first-child { border-block-start: 0; }
.qline .qlabel { font-weight: 600; font-variant-numeric: tabular-nums; }
.qline .qstatus { color: var(--muted); font-size: .85rem; }
.qline .strip { grid-column: 1 / -1; }
.qline.err .qstatus { color: var(--danger); }
@keyframes qp-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .qpanel { animation: none; } }

/* ---------- download table (all qualities) ---------- */
.qwrap { overflow-x: auto; border: 1px solid var(--ink); border-radius: 4px; background: var(--surface); }
.qtable { inline-size: 100%; border-collapse: collapse; font-size: .95rem; }
.qtable td, .qtable th { padding: .55rem .8rem; border-block-start: 1px solid var(--line); text-align: start; vertical-align: middle; }
.qtable tr:first-child th { border-block-start: 0; }
.qsec th { background: color-mix(in srgb, var(--ink) 6%, var(--surface)); font-size: .95rem; }
.qsec th .qico { margin-inline-end: .5rem; }
.qico { inline-size: 1.05rem; block-size: 1.05rem; vertical-align: -.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.qn { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .5rem; min-block-size: 2.6rem; }
.qname .qico { inline-size: .95rem; block-size: .95rem; color: var(--muted); }
.qlabel { font-weight: 700; font-variant-numeric: tabular-nums; }
.qbadge { padding: .05rem .45rem; border-radius: 4px; background: var(--ok); color: var(--primary-ink); font-size: .72rem; font-weight: 600; white-space: nowrap; }
.qsize { inline-size: 6.5rem; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.qact { inline-size: 11.5rem; text-align: end; }
.qdl { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; inline-size: 100%; padding: .55rem .8rem; border: 0; border-radius: 6px; background: var(--ok); color: var(--primary-ink); font: inherit; font-size: .9rem; font-weight: 600; text-decoration: none; cursor: pointer; box-shadow: 0 2px 6px rgb(0 0 0 / .18); transition: filter .15s, transform .1s; }
.qdl:hover { filter: brightness(1.08); }
.qdl:active { transform: translateY(1px); }
.qdl:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.qdl .ico { inline-size: 1.05rem; block-size: 1.05rem; }
.qdl.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); box-shadow: none; margin-block-start: .35rem; }
.qact .qstatus { display: block; margin-block-end: .3rem; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.qact.err .qstatus { color: var(--danger); }
.qact .strip { inline-size: 100%; }
@media (max-width: 560px) { .qsize { display: none; } .qact { inline-size: 9rem; } }

/* the table needs the full row width, not the narrow button column */
.row:has(.qpanel) .slot { grid-column: 1 / -1; }

/* =====================================================================
   Home page v2: guide, search feedback, usage, downloads panel, toasts
   ===================================================================== */
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- header: compact on phones ---------- */
.tray-btn .count { min-inline-size: 1.25rem; padding-inline: 0.35rem; border-radius: 999px; background: var(--ink); color: var(--surface); font-size: 0.75rem; font-weight: 700; line-height: 1.25rem; text-align: center; font-variant-numeric: tabular-nums; }
.tray-btn.has-active .count { background: var(--primary); color: var(--primary-ink); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--primary) 25%, transparent); } }


/* ---------- hero gets out of the way once you search ---------- */
.hero h1 { transition: font-size 0.25s ease; }
body.searched .hero { padding-block: 1rem 0.5rem; }
body.searched .hero h1 { font-size: clamp(1.4rem, 3.4vw, 2rem); margin-block-end: 0.4rem; }
body.searched .hero .lead { display: none; }
body.searched .journey .jt small { display: none; }

/* ---------- search box feedback ---------- */
.search .clear-btn { align-self: center; color: var(--muted); }
.spin { display: none; inline-size: 1em; block-size: 1em; border-radius: 50%; border: 2px solid currentColor; border-inline-end-color: transparent; animation: spin 0.7s linear infinite; }
.is-busy .spin { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.search-hint { display: flex; align-items: center; gap: 0.5rem; margin: 0.65rem 0.25rem 0; color: var(--muted); font-size: 0.92rem; }
.search-hint[data-kind="error"] { color: var(--danger); font-weight: 600; }
.search-hint[data-kind="busy"]::before { content: ""; inline-size: 0.9em; block-size: 0.9em; border-radius: 50%; border: 2px solid currentColor; border-inline-end-color: transparent; animation: spin 0.7s linear infinite; }

.recent { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-block-start: 0.8rem; }
.recent-label { margin-inline-end: 0.2rem; color: var(--muted); font-size: 0.85rem; }
.recent-chip { max-inline-size: 15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0.25rem 0.75rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font: inherit; font-size: 0.88rem; cursor: pointer; }
.recent-chip:hover { border-color: var(--primary); }
.recent-clear, .link-btn { padding: 0.25rem 0.4rem; border: 0; background: none; color: var(--muted); font: inherit; font-size: 0.82rem; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link-btn { color: var(--primary); font-size: 0.88rem; }

/* ---------- the 3-step guide ---------- */
.journey { list-style: none; margin: 1.25rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; }
.journey li { --c: var(--q360); display: flex; align-items: center; gap: 0.65rem; min-inline-size: 0; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: color-mix(in srgb, var(--surface) 55%, transparent); transition: background 0.25s, border-color 0.25s, color 0.25s; }
.journey li[data-s="2"] { --c: var(--q480); }
.journey li[data-s="3"] { --c: var(--q720); }
.jn { flex: none; display: grid; place-items: center; inline-size: 1.8rem; block-size: 1.8rem; border-radius: 50%; border: 2px solid var(--line); background: var(--surface); font-weight: 800; font-size: 0.9rem; color: var(--muted); transition: background 0.25s, border-color 0.25s; }
.jt { display: grid; min-inline-size: 0; }
.jt strong { color: var(--ink); font-size: 0.95rem; }
.jt small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.78rem; }
.journey li.is-now { color: var(--ink); border-color: var(--c); background: color-mix(in srgb, var(--c) 11%, var(--surface)); }
.journey li.is-now .jn { border-color: var(--c); background: var(--c); color: #0d111f; }
.journey li.is-done .jn { border-color: var(--ok); background: var(--ok); color: transparent; position: relative; }
.journey li.is-done .jn::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--primary-ink); font-size: 0.95rem; }

/* ---------- usage meters / sign-in nudge ---------- */
.usage { display: grid; gap: 0.6rem; margin-block-start: 1rem; padding: 0.8rem 1rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.u-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.u-meters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem; }
.u-meter { --c: var(--q720); display: grid; gap: 0.3rem; }
.u-meter[data-level="warn"] { --c: var(--q360); }
.u-meter[data-level="full"] { --c: var(--danger); }
.u-text { font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.u-note { margin: 0; color: var(--muted); font-size: 0.82rem; }
.u-note.is-full { color: var(--danger); font-weight: 600; }
.usage.nudge { grid-template-columns: 1fr auto; align-items: center; gap: 0.8rem 1rem; background: color-mix(in srgb, var(--primary) 7%, var(--surface)); border-color: color-mix(in srgb, var(--primary) 35%, var(--line)); }
.nudge-text p { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.9rem; }
.nudge-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* ---------- loading skeletons + empty/error states ---------- */
@keyframes shimmer { to { background-position: -200% 0; } }
.sk { border-radius: 6px; background: linear-gradient(90deg, color-mix(in srgb, var(--ink) 8%, var(--surface)) 30%, color-mix(in srgb, var(--ink) 15%, var(--surface)) 50%, color-mix(in srgb, var(--ink) 8%, var(--surface)) 70%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; }
.sk-line { block-size: 1rem; margin-block: 0.5rem; }
.sk-line.short { inline-size: 55%; }
.state-card { display: flex; align-items: center; gap: 1rem; padding: 1.25rem 0.25rem; border-block-end: 1px solid var(--line); }
.state-ico { flex: none; display: grid; place-items: center; inline-size: 2.6rem; block-size: 2.6rem; border-radius: 50%; background: color-mix(in srgb, var(--ink) 8%, var(--surface)); color: var(--muted); }
.state-card.error .state-ico { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }
.state-body { flex: 1; min-inline-size: 0; }
.state-body strong { display: block; }
.state-body p { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.92rem; }

/* ---------- result rows: grouped options with size hints ---------- */
.row { grid-template-columns: 10.5rem minmax(0, 1fr) minmax(0, 26rem); }
.opts { display: grid; gap: 0.55rem; }
.opt-group { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.6rem; }
.opt-label { flex: none; min-inline-size: 3.3rem; color: var(--muted); font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.chip small { color: var(--muted); font-size: 0.74rem; font-weight: 500; }
.chip.is-rec { box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 32%, transparent); }
.chip.is-over { opacity: 0.55; border-style: dashed; cursor: not-allowed; }
.chip.is-over small { color: var(--danger); }
@media (pointer: coarse) { .chip, .btn.small { min-block-size: 2.75rem; } }
@media (max-width: 47.99rem) { .row { grid-template-columns: 7rem minmax(0, 1fr); } }

/* ---------- download progress inside a row ---------- */
.job-steps { display: flex; flex-wrap: wrap; gap: 0.2rem 0.8rem; margin: 0 0 0.5rem; padding: 0; list-style: none; color: var(--muted); font-size: 0.78rem; }
.job-steps li { display: inline-flex; align-items: center; gap: 0.35rem; }
.job-steps li::before { content: ""; inline-size: 0.55rem; block-size: 0.55rem; border-radius: 50%; background: var(--line); }
.job-steps li.on { color: var(--ink); font-weight: 700; }
.job-steps li.on::before { background: var(--c, var(--primary)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c, var(--primary)) 25%, transparent); }
.job-steps li.past::before { background: var(--ok); }
.job-meta { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.8rem; }
.done-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }

/* ---------- plans: tucked away until wanted ---------- */
.plans { padding-block-start: 2.5rem; }
.plans summary { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.85rem 1rem; list-style: none; cursor: pointer; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.plans summary::-webkit-details-marker { display: none; }
.plans summary h2 { margin: 0; font-size: 1.1rem; }
.plans .chev, .tray-toggle .chev { transition: transform 0.2s; }
.plans[open] summary .chev { transform: rotate(180deg); }
.plans > :not(summary) { margin-block-start: 1rem; }

/* ---------- downloads panel ---------- */
.tray { position: fixed; inset-block-end: 1rem; inset-inline-end: 1rem; z-index: 50; display: flex; flex-direction: column; inline-size: min(25rem, calc(100vw - 2rem)); max-block-size: min(30rem, 62vh); overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 16px 44px rgb(0 0 0 / 0.24); }
.tray-head { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0.5rem 0.3rem 0.75rem; border-block-end: 1px solid var(--line); }
.tray-toggle { flex: 1; display: flex; align-items: center; gap: 0.5rem; min-inline-size: 0; padding: 0.45rem 0; border: 0; background: none; color: inherit; font: inherit; text-align: start; cursor: pointer; }
.tray-sum { margin-inline-start: auto; color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.tray.collapsed .tray-list { display: none; }
.tray.collapsed .tray-head { border-block-end: 0; }
.tray.collapsed .chev { transform: rotate(180deg); }
.tray-list { display: grid; gap: 0.4rem; margin: 0; padding: 0.4rem 0.5rem 0.5rem; list-style: none; overflow: auto; }
.tray-item { --c: var(--primary); display: grid; gap: 0.35rem; padding: 0.6rem 0.7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); animation: pop 0.25s ease both; }
.tray-item[data-q="360"] { --c: var(--q360); } .tray-item[data-q="480"] { --c: var(--q480); } .tray-item[data-q="720"] { --c: var(--q720); } .tray-item[data-q="1080"] { --c: var(--q1080); } .tray-item[data-q="audio"] { --c: var(--qaudio); }
.ti-main { display: flex; align-items: baseline; gap: 0.5rem; min-inline-size: 0; }
.ti-title { flex: 1; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.92rem; }
.ti-q { flex: none; padding: 0.05rem 0.5rem; border-radius: 999px; background: color-mix(in srgb, var(--c) 24%, var(--surface)); font-size: 0.74rem; font-weight: 700; }
.ti-status { display: flex; flex-wrap: wrap; gap: 0 0.8rem; margin: 0; color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.tray-item[data-state="failed"] .ti-text, .tray-item[data-state="expired"] .ti-text { color: var(--danger); }
.ti-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.ti-x { margin-inline-start: auto; padding-inline: 0.5rem; }
.tray-item[data-state="done"] .btn.primary { background: var(--c); color: #0d111f; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (max-width: 47.99rem) {
  .tray { inset-inline: 0.5rem; inset-block-end: 0.5rem; inline-size: auto; max-block-size: 55vh; }
  .journey { gap: 0.35rem; }
  .journey li { padding: 0.45rem 0.5rem; gap: 0.45rem; }
  .jt small { display: none; }
  .u-meters { grid-template-columns: 1fr; }
  .usage.nudge { grid-template-columns: 1fr; }
  body { padding-block-end: 4.5rem; } /* room so the panel never covers the last result */
}

/* ---------- toasts ---------- */
.toasts { position: fixed; inset-inline-start: 1rem; inset-block-end: 1rem; z-index: 60; display: grid; gap: 0.5rem; inline-size: min(24rem, calc(100vw - 2rem)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 0.7rem 0.7rem 1rem; border-radius: 12px; border-inline-start: 4px solid var(--primary); background: var(--ink); color: var(--surface); box-shadow: 0 10px 28px rgb(0 0 0 / 0.28); animation: pop 0.25s ease both; transition: opacity 0.2s, transform 0.2s; }
.toast.ok { border-inline-start-color: var(--q720); }
.toast.error { border-inline-start-color: #ff6b61; }
.toast.leaving { opacity: 0; transform: translateY(6px); }
.toast-text { flex: 1; font-size: 0.92rem; overflow-wrap: anywhere; }
.toast-act { padding: 0.2rem 0.4rem; border: 0; background: none; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
.toast-x { padding: 0.25rem; border: 0; background: none; color: inherit; opacity: 0.7; cursor: pointer; }
@media (max-width: 47.99rem) { .toasts { inset-block: 4rem auto; inset-inline: 0.75rem; inline-size: auto; } }

@media (prefers-reduced-motion: reduce) {
  .sk, .spin, .search-hint::before, .tray-btn.has-active .count, .tray-item, .toast { animation: none; }
  .hero h1, .journey li, .jn { transition: none; }
}

/* ---------- after a search: usage + guide shrink to slim strips so results come first ---------- */
body.searched .journey { margin-block-start: 0.75rem; }
body.searched .journey li { padding-block: 0.4rem; }
body.searched .usage:not(.nudge) { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 1.25rem; margin-block-start: 0.7rem; padding: 0.5rem 0.85rem; }
body.searched .usage:not(.nudge) .u-head { flex: none; }
body.searched .usage:not(.nudge) .u-head .link-btn { display: none; }
body.searched .usage:not(.nudge) .u-meters { flex: 1 1 18rem; }
body.searched .usage:not(.nudge) .u-note:not(.is-full) { display: none; }
body.searched .usage:not(.nudge) .u-note.is-full { flex: 1 1 100%; }

/* slim Downloads bar: progress fills behind its title */
.tray.collapsed .tray-head { background-image: linear-gradient(to right, color-mix(in srgb, var(--q720) 32%, transparent) var(--tp, 0%), transparent var(--tp, 0%)); }
:root[dir="rtl"] .tray.collapsed .tray-head { background-image: linear-gradient(to left, color-mix(in srgb, var(--q720) 32%, transparent) var(--tp, 0%), transparent var(--tp, 0%)); }
.tray.collapsed { inline-size: min(19rem, calc(100vw - 2rem)); }
body.has-tray main { padding-block-end: 4rem; }

/* phones: the account button keeps its icon, the name stays available to screen readers */
@media (max-width: 30rem) {
  #account-btn #account-name { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .top-actions { flex: none; }
  .topbar .brand span { font-size: 1.05rem; }
}

/* phones: tighter guide, slimmer usage strip, notifications above the Downloads bar */
@media (max-width: 30rem) {
  .jn { inline-size: 1.5rem; block-size: 1.5rem; font-size: 0.8rem; }
  .jt strong { font-size: 0.86rem; }
  .journey li { gap: 0.35rem; padding-inline: 0.4rem; }
}
@media (max-width: 47.99rem) {
  body.searched .usage:not(.nudge) .u-head { display: none; }
  body.searched .usage:not(.nudge) .u-meters { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
  body.searched .usage:not(.nudge) .u-text { font-size: 0.8rem; }
  .toasts { inset-block: auto 4.6rem; }
}

/* =============================================================================
   Cancel buttons
   ============================================================================= */
.job-cancel { margin-top: 0.6rem; margin-inline-start: 0.4rem; }
.job-cancel:disabled, .ti-cancel:disabled { opacity: 0.6; cursor: progress; }
.cancelled { gap: 0.5rem; }
.cancelled-msg { margin: 0; color: var(--muted); font-size: 0.92rem; font-weight: 600; }
.qcancel { display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem; inline-size: 100%; margin-block-start: 0.4rem; padding: 0.35rem 0.6rem; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--ink); font: inherit; font-size: 0.82rem; cursor: pointer; transition: background 0.15s, border-color 0.15s, color 0.15s; }
.qcancel:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }
.qcancel:disabled { opacity: 0.55; cursor: progress; }
.qcancel:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.qcancel .ico { inline-size: 0.9rem; block-size: 0.9rem; }
.ti-cancel { margin-inline-start: auto; }
.ti-cancel:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }

/* =============================================================================
   "Ready" highlight: a finished download changes colour and its Save button pulses
   until the user clicks it, so it cannot be missed in a long list.
   ============================================================================= */
@keyframes ready-flash { 0% { background: color-mix(in srgb, var(--ok) 55%, var(--surface)); } 100% { background: color-mix(in srgb, var(--ok) 16%, var(--surface)); } }
@keyframes ready-ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 65%, transparent); } 70%, 100% { box-shadow: 0 0 0 10px transparent; } }
@keyframes ready-pop { 0% { transform: scale(0.95); } 55% { transform: scale(1.04); } 100% { transform: scale(1); } }

/* all-qualities table */
.qrow.is-ready > td { background: color-mix(in srgb, var(--ok) 16%, var(--surface)); animation: ready-flash 1.4s ease-out 1; }
.qrow.is-ready > td:first-child { box-shadow: inset 5px 0 0 var(--ok); }
html[dir="rtl"] .qrow.is-ready > td:first-child { box-shadow: inset -5px 0 0 var(--ok); }
.qrow.is-ready .qlabel { color: var(--ok); }
.qrow.is-ready.seen > td { background: color-mix(in srgb, var(--ok) 8%, var(--surface)); }
.qready { animation: ready-pop 0.5s ease both; }
.qdl.ready { box-shadow: 0 3px 10px color-mix(in srgb, var(--ok) 45%, transparent); }
.qdl.ready.attn, .done .btn.attn, .tray-item[data-state="done"] .btn.attn { animation: ready-ring 1.5s ease-out infinite; }

/* quick buttons (360p / 720p / MP3 ...) */
.done.ready { inline-size: 100%; padding: 0.7rem 0.8rem; border: 1px solid color-mix(in srgb, var(--ok) 55%, var(--line)); border-radius: 10px; background: color-mix(in srgb, var(--ok) 14%, var(--surface)); animation: ready-flash 1.4s ease-out 1, ready-pop 0.5s ease both; }
.done.ready.seen { border-color: var(--line); background: color-mix(in srgb, var(--ok) 7%, var(--surface)); }
.done.ready .done-info > span:first-child { color: var(--ok); font-weight: 700; }

/* the whole result row also gets a green frame until the file was saved */
.row:has(.done.ready:not(.seen)), .row:has(.qrow.is-ready:not(.seen)) { border-color: var(--ok); box-shadow: 0 0 0 1px var(--ok), 0 8px 22px color-mix(in srgb, var(--ok) 22%, transparent); }

/* Downloads panel */
.tray-item[data-state="done"] { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--bg)); box-shadow: 0 0 0 1px var(--ok); animation: ready-flash 1.4s ease-out 1, pop 0.25s ease both; }
.tray-item[data-state="done"].seen { box-shadow: none; border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.tray-item[data-state="done"] .ti-text { color: var(--ok); font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  .qrow.is-ready > td, .qready, .done.ready, .tray-item[data-state="done"], .qdl.ready.attn, .done .btn.attn { animation: none !important; }
}
