/* AIO Downloader — design tokens first, components after. */
:root {
    --bg: #eef1f5; --surface: #fff; --surface-2: #f6f8fb; --ink: #0e1726; --muted: #596479; --line: #dbe0e9;
    --accent: #2f54eb; --accent-ink: #fff; --accent-soft: #e7ecfd; --ok: #0d8a5e; --ok-soft: #dff5ec; --danger: #c62e3e; --danger-soft: #fbe6e8;
    --r-s: 8px; --r-m: 12px; --r-l: 16px;
    --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
    --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg:#0a101c; --surface:#121a2b; --surface-2:#0f1626; --ink:#e8ecf4; --muted:#8e99b0; --line:#232d44; --accent:#7f9aff; --accent-ink:#0a101c; --accent-soft:#1a2547; --ok:#4cd49c; --ok-soft:#10301f; --danger:#ff7283; --danger-soft:#38151b; color-scheme:dark; } }
:root[data-theme="dark"] { --bg:#0a101c; --surface:#121a2b; --surface-2:#0f1626; --ink:#e8ecf4; --muted:#8e99b0; --line:#232d44; --accent:#7f9aff; --accent-ink:#0a101c; --accent-soft:#1a2547; --ok:#4cd49c; --ok-soft:#10301f; --danger:#ff7283; --danger-soft:#38151b; color-scheme:dark; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, ul { margin: 0; padding: 0; }
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: .5rem; z-index: 50; background: var(--accent); color: var(--accent-ink); padding: .5rem 1rem; border-radius: var(--r-s); }
.skip-link:focus { left: .5rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.2em; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-inner, main { width: 100%; max-width: 760px; margin: 0 auto; padding-inline: 1rem; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 60px; }
main { padding-block: 0 4rem; }
.brand { white-space: nowrap; display: inline-flex; align-items: center; gap: .6rem; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: -.01em; }
.logo { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--r-s); background: var(--accent); color: var(--accent-ink); }
.logo .icon { width: 18px; height: 18px; }
.tabs { display: flex; align-items: center; gap: .25rem; }
.tab, .icon-btn { display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 .85rem; border: 0; border-radius: var(--r-s); background: none; color: var(--muted); font: 500 .94rem var(--font); cursor: pointer; text-decoration: none; }
.tab:hover, .icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.tab[aria-current="page"] { color: var(--ink); background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--accent); border-radius: var(--r-s) var(--r-s) 0 0; }
.icon-btn { width: 36px; padding: 0; margin-left: .25rem; border: 1px solid var(--line); }

/* Hero */
.hero { padding: clamp(2.5rem, 8vw, 4.5rem) 0 1.75rem; }
.hero h1 { max-width: 15em; font-size: clamp(1.9rem, 5.2vw, 2.9rem); line-height: 1.1; letter-spacing: -.03em; font-weight: 750; text-wrap: balance; }
.lead { max-width: 34em; margin-top: 1rem; color: var(--muted); font-size: 1.06rem; }
body.has-results .hero { padding: 1.75rem 0 1.1rem; }
body.has-results .hero h1 { font-size: 1.35rem; letter-spacing: -.02em; }
body.has-results .lead, body.has-results .help { display: none; }

/* Search */
.search { display: flex; align-items: center; gap: .5rem; padding: .45rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: 0 1px 2px rgba(14,23,38,.04); transition: border-color .15s, box-shadow .15s; }
.search:focus-within { border-color: var(--accent); box-shadow: var(--ring); }
.lead-icon { width: 20px; height: 20px; margin-left: .6rem; color: var(--muted); }
.search input[type="text"] { flex: 1; min-width: 0; height: 44px; padding: 0 .25rem; border: 0; border-radius: 0; background: none; color: var(--ink); font: 400 1rem var(--font); outline: none; box-shadow: none; }
.search input::placeholder { color: var(--muted); opacity: .8; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; height: 40px; padding: 0 1rem; border: 1px solid var(--line); border-radius: var(--r-m); background: var(--surface); color: var(--ink); font: 600 .92rem var(--font); cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .08s; }
.btn:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--ink) 25%, var(--line)); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.search .btn.primary { height: 44px; min-width: 96px; border-radius: var(--r-m); }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); font-weight: 500; }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible, .tab:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Settings */
.settings { margin-top: .75rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); }
.settings > summary { display: flex; align-items: center; gap: .6rem; padding: .7rem 1rem; list-style: none; cursor: pointer; font-weight: 600; font-size: .94rem; }
.settings > summary::-webkit-details-marker { display: none; }
.summary-value { margin-left: auto; color: var(--muted); font-weight: 400; font-size: .88rem; text-align: right; }
.chev { color: var(--muted); transition: transform .2s; }
.settings[open] .chev { transform: rotate(180deg); }
.options-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; padding: 0 1rem 1rem; }
fieldset { margin: 0; min-width: 0; display: flex; flex-direction: column; gap: .7rem; padding: .9rem 1rem 1rem; border: 1px solid var(--line); border-radius: var(--r-m); background: var(--surface-2); }
legend { padding: 0 .35rem; font-weight: 650; font-size: .88rem; }
.seg-field { grid-column: 1 / -1; background: none; border: 0; padding: 0; }
.seg-field legend { padding: 0 0 .4rem; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--line); border-radius: var(--r-m); background: var(--surface-2); width: fit-content; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span { display: block; padding: .4rem 1.1rem; border-radius: 9px; color: var(--muted); font-size: .92rem; font-weight: 550; }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(14,23,38,.12), 0 0 0 1px var(--line); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; color: var(--muted); font-weight: 500; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
input[type="text"], select { width: 100%; height: 40px; padding: 0 .75rem; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--surface); color: var(--ink); font: 400 .95rem var(--font); }
input[type="text"]:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.check { display: flex; align-items: flex-start; gap: .55rem; font-size: .92rem; line-height: 1.4; cursor: pointer; }
.check.small { align-items: center; color: var(--muted); font-size: .88rem; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 1rem; height: 1rem; margin: .12rem 0 0; flex: none; }
small { color: var(--muted); font-size: .82rem; }

/* Help */
.help { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1.25rem; margin-top: 2.25rem; padding-top: 1.75rem; border-top: 1px solid var(--line); }
.help-item { display: flex; gap: .85rem; align-items: flex-start; }
.help-icon { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: var(--r-m); background: var(--accent-soft); color: var(--accent); }
.help-item h3 { font-size: .96rem; font-weight: 650; }
.help-item p { margin-top: .15rem; color: var(--muted); font-size: .9rem; }

/* Results */
.block-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin-bottom: .85rem; }
h2 { font-size: 1.1rem; font-weight: 700; letter-spacing: -.01em; }
.results-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem 1rem; margin: 2rem 0 .9rem; }
.results-head h2 { overflow-wrap: anywhere; }
.count, .meta { color: var(--muted); font-size: .88rem; }
.card { display: grid; grid-template-columns: 170px 1fr; gap: 1rem; align-items: center; padding: .75rem; margin-bottom: .6rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); }
.card.has-pick { grid-template-columns: auto 170px 1fr; }
.thumb-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: var(--r-m); overflow: hidden; background: var(--bar, var(--surface-2)); }
.thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.duration { position: absolute; right: 6px; bottom: 6px; padding: 1px 6px; border-radius: 6px; background: rgba(8,12,22,.82); color: #fff; font-size: .75rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.card-body { min-width: 0; display: flex; flex-direction: column; gap: .25rem; }
.title { color: var(--ink); font-weight: 600; line-height: 1.35; text-decoration: none; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
a.title:hover { color: var(--accent); text-decoration: underline; }
.job .title { display: block; }
.card-actions .btn { min-width: 132px; }
.playlist-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1rem; margin: 2rem 0 .9rem; }
.playlist-head .actions { gap: .75rem; }
.pick { display: flex; align-items: center; padding-left: .25rem; }
.pick input { width: 1.15rem; height: 1.15rem; margin: 0; }
.empty { padding: 2rem 1rem; border: 1px dashed var(--line); border-radius: var(--r-l); text-align: center; color: var(--muted); }

/* Queue + history */
.block { margin-top: 2.5rem; padding: 1.1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.job-list { list-style: none; display: flex; flex-direction: column; gap: .6rem; }
.job { display: grid; gap: .55rem; padding: .8rem .9rem; border: 1px solid var(--line); border-radius: var(--r-m); background: var(--surface-2); }
.job-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.job-top > div:first-child { min-width: 0; }
.job-status { display: flex; align-items: center; gap: .45rem; margin-top: .1rem; color: var(--muted); font-size: .86rem; }
.job-status::before { content: ""; width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--accent); }
.job[data-status="queued"] .job-status::before { background: var(--muted); }
.job[data-status="done"] .job-status { color: var(--ok); }
.job[data-status="done"] .job-status::before { background: var(--ok); }
.job[data-status="error"] .job-status, .job[data-status="cancelled"] .job-status { color: var(--danger); }
.job[data-status="error"] .job-status::before, .job[data-status="cancelled"] .job-status::before { background: var(--danger); }
#history-list .job-status::before { display: none; }
.bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.fill { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .25s ease; }
.job[data-status="done"] .fill { background: var(--ok); }
.job[data-status="error"] .fill { background: var(--danger); }
.hint { color: var(--muted); font-size: .9rem; margin: .25rem 0 1rem; }
li.hint { padding: 1.25rem 0; text-align: center; }

.spinner { width: 28px; height: 28px; margin: 2rem auto; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); width: max-content; max-width: min(92vw, 480px); padding: .7rem 1rem; border-radius: var(--r-m); background: var(--ink); color: var(--bg); font-size: .92rem; z-index: 30; box-shadow: 0 8px 28px rgba(0,0,0,.25); }
.toast.error { background: var(--danger); color: #fff; }

/* Admin page reuses the same parts */
.panel { margin-top: 1.25rem; padding: 1.1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); }
.panel h2 { margin-bottom: .75rem; }

@media (max-width: 640px) {
    .card { grid-template-columns: 124px 1fr; gap: .75rem; align-items: start; }
    .card.has-pick { grid-template-columns: auto 104px 1fr; }
    .card-actions { grid-column: 1 / -1; }
    .card.has-pick .card-actions { grid-column: auto; }
    .title { font-size: .95rem; }
    .tab { padding: 0 .6rem; }
    .card-actions .btn { width: 100%; }
    .search { flex-wrap: wrap; padding: .6rem; }
    .lead-icon { display: none; }
    .search input[type="text"] { flex: 1 1 100%; height: 44px; padding: 0 .4rem; }
    .search .btn { flex: 1; }
    .search .btn.primary { min-width: 0; }
    .summary-value { display: none; }
    .chev { margin-left: auto; }
    .job-top { flex-direction: column; align-items: stretch; }
    .topbar-inner { min-height: 56px; }
}
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } .chev, .fill, .btn { transition: none; } }
@media (max-width: 440px) { .brand span:last-child { display: none; } }

/* Per-video choices */
.choices { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin-top: .45rem; }
.choices .seg span { padding: .3rem .85rem; font-size: .88rem; }
.choice-select { width: auto; min-width: 0; max-width: 100%; height: 36px; font-size: .9rem; }
.note { color: var(--muted); font-size: .84rem; }
.card { align-items: start; }
.card-actions { align-self: center; }
.playlist-tools { display: flex; flex-direction: column; align-items: flex-end; gap: .6rem; }
.playlist-tools .choices { margin: 0; justify-content: flex-end; }
@media (max-width: 640px) {
    .choice-select { flex: 1 1 100%; }
    .playlist-tools { align-items: stretch; width: 100%; }
    .playlist-tools .choices { justify-content: flex-start; }
}

.meta .note { font-size: inherit; }
.pick-row { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: .6rem; }
.pick-row .choices { flex: 1 1 300px; flex-wrap: wrap; margin: 0; min-width: 0; }
.pick-row .choice-select { flex: 1 1 12rem; min-width: 10rem; max-width: 100%; }
.pick-row .subs .choice-select { flex: 0 1 auto; min-width: 8rem; }
.pick-row .btn { min-width: 132px; }
@media (max-width: 640px) { .card { grid-template-columns: 112px 1fr; } .card.has-pick { grid-template-columns: auto 96px 1fr; } .pick-row .choices { flex-wrap: wrap; flex-basis: 100%; } .pick-row .btn { width: 100%; } }

/* ---- v8: preview, subtitles, show more, server panel, paused ---- */
.thumb-wrap .preview-btn { position: absolute; inset: auto auto 6px 6px; width: 2rem; height: 2rem; border: 0; border-radius: 50%; background: rgba(0,0,0,.65); color: #fff; font-size: .8rem; cursor: pointer; opacity: 0; transition: opacity .15s; }
.thumb-wrap:hover .preview-btn, .thumb-wrap:focus-within .preview-btn { opacity: 1; }
@media (hover: none) { .thumb-wrap .preview-btn { opacity: 1; } }
.thumb-wrap .player { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; }
.player-close { position: absolute; top: 4px; right: 4px; width: 1.7rem; height: 1.7rem; border: 0; border-radius: 50%; background: rgba(0,0,0,.7); color: #fff; font-size: 1.1rem; line-height: 1; cursor: pointer; z-index: 2; }
.card:has(.player) { grid-template-columns: minmax(260px, 340px) 1fr; }
.subs { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.subs[hidden], .subs-pick[hidden] { display: none; }
.subs-pick { position: relative; font-size: .88rem; }
.subs-pick summary { cursor: pointer; color: var(--muted); padding: .3rem .5rem; border: 1px solid var(--line); border-radius: var(--r-m); max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subs-list { position: absolute; z-index: 5; margin-top: .25rem; max-height: 14rem; min-width: 14rem; overflow: auto; padding: .5rem .65rem; display: grid; gap: .3rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); box-shadow: 0 6px 20px rgba(14,23,38,.18); }
.item-choice { margin-top: .35rem; }
.item-choice:empty { display: none; }
.more { display: flex; justify-content: center; margin: .8rem 0 1.2rem; }
.server-info { display: flex; flex-wrap: wrap; gap: .6rem 1.4rem; margin: 0 0 .9rem; font-size: .86rem; color: var(--muted); }
.meter-item { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .5rem; }
.meter { width: 90px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter .fill { height: 100%; background: var(--accent); }
.meter .fill.warn { background: var(--danger); }
.job[data-status="paused"] .job-status::before { background: #d4a017; }

/* ---- v8.2 ---- */
.player-clip { position: absolute; top: 4px; left: 4px; display: flex; gap: 4px; z-index: 2; }
.btn.small { padding: .2rem .55rem; font-size: .78rem; min-height: 0; }
.filter { min-width: 11rem; height: 36px; }
.card[hidden] { display: none; }
.subs-pick summary:focus-visible, .preview-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 110px; margin: .5rem 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; }
#disk-alert:not(:empty) { color: var(--danger); font-weight: 600; }
