:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8b93a3;
  --accent: #5b8cff;
  --accent-2: #3f6fe0;
  --ok: #3fb67a;
  --warn: #e0a83f;
  --err: #e5534b;
  --yts: #6ac045;
  --avistaz: #d9534f;
  --unionfansub: #b07cff;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }

header.top { display: flex; align-items: center; gap: 24px; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--panel); position: sticky; top: 0; z-index: 5; }
header.top .brand { font-weight: 700; letter-spacing: .2px; }
header.top nav { display: flex; gap: 16px; flex: 1; }
header.top nav a { color: var(--muted); }
header.top nav a.active { color: var(--text); }
header.top form { margin: 0; }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }
h2 { font-size: 16px; margin: 32px 0 12px; }
h2:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.btn { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #3a4150; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.link { background: none; border: none; color: var(--muted); padding: 4px 6px; }
.btn.link:hover { color: var(--text); }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.done { background: transparent; border-color: var(--ok); color: var(--ok); }

input[type=text], input[type=password], input[type=url], input[type=search], select, textarea {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }

.searchbar { display: flex; gap: 8px; align-items: stretch; }
.searchbar input { flex: 1; font-size: 16px; padding: 10px 14px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg button { background: none; border: none; padding: 0 14px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); }

.filters { display: flex; gap: 16px; align-items: center; margin: 14px 0 8px; flex-wrap: wrap; }
.filters label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.banner { border: 1px solid var(--border); border-left: 3px solid var(--warn); background: var(--panel); border-radius: var(--radius); padding: 8px 12px; margin: 8px 0; }
.banner.err { border-left-color: var(--err); }
.banner.ok { border-left-color: var(--ok); }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; background: var(--panel-2); user-select: none; }
th.sort { cursor: pointer; }
th.sort.asc::after { content: " ▲"; } th.sort.desc::after { content: " ▼"; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.title { word-break: break-word; }
td.title .sub { color: var(--muted); font-size: 12px; }
.seeds { color: var(--ok); } .leech { color: var(--muted); }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.badge.yts { color: var(--yts); } .badge.avistaz { color: var(--avistaz); } .badge.unionfansub { color: var(--unionfansub); }
.status { font-size: 12px; white-space: nowrap; }
.status.downloading { color: var(--accent); } .status.seeding, .status.done, .status.completed { color: var(--ok); } .status.missing { color: var(--warn); }

.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; min-width: 90px; }
.bar > div { height: 100%; background: var(--accent); }
.bar.full > div { background: var(--ok); }

.empty { padding: 32px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--border); border-radius: var(--radius); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; z-index: 20; }
.modal-bg.open { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: min(460px, calc(100vw - 32px)); }
.modal h3 { margin: 0 0 4px; font-size: 16px; }
.modal .t { color: var(--muted); font-size: 12px; margin-bottom: 16px; word-break: break-word; }
.catlist { display: grid; gap: 8px; margin-bottom: 16px; }
.catlist label { display: flex; gap: 10px; align-items: center; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; }
.catlist label:has(input:checked) { border-color: var(--accent); background: var(--panel-2); }
.catlist .ty { margin-left: auto; color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.actions .msg { margin-right: auto; font-size: 12px; }

/* settings */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; display: flex; align-items: center; gap: 10px; }
.card h3 .grow { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.test-result { font-size: 12px; margin-left: 8px; }
.test-result.ok { color: var(--ok); } .test-result.err { color: var(--err); }
.toggle { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; font-weight: normal; color: var(--muted); cursor: pointer; }
.cats td { padding: 6px 8px; }
.cats input, .cats select { padding: 6px 8px; }
.savebar { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--border); display: flex; gap: 12px; align-items: center; }

/* auth */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px; width: min(380px, 100%); }
.auth h1 { font-size: 20px; margin: 0 0 6px; }
.auth p { color: var(--muted); margin: 0 0 18px; }
.auth .field { margin-bottom: 14px; }
.auth .btn { width: 100%; padding: 10px; }
.auth .error { color: var(--err); margin-bottom: 14px; }

/* result cards */
.filters .grow { flex: 1; }
select.compact { width: auto; padding: 4px 8px; }
#results { display: grid; gap: 14px; }
.tcard { display: grid; grid-template-columns: 132px 1fr; gap: 18px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.cover { position: relative; width: 132px; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden; background: linear-gradient(145deg, #232836, #161a22); border: 1px solid var(--border); align-self: start; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .25s; }
.cover.loaded img { opacity: 1; }
.cover .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: 700; color: #3a4152; letter-spacing: 1px; }
.cover.loaded .ph { display: none; }
.tbody { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.thead h3 { margin: 2px 0 6px; font-size: 18px; line-height: 1.25; }
.thead .year { color: var(--muted); font-weight: 400; }
.tmeta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); white-space: nowrap; }
.chip.q2160p, .chip.q4k { border-color: #b58cff; color: #cdb3ff; }
.chip.q1080p { border-color: #5b8cff; color: #9db8ff; }
.chip.q720p { border-color: #3fb67a; color: #7fd3a8; }
.opts { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.opt { display: grid; grid-template-columns: 104px minmax(0, 1fr) 84px 112px auto; gap: 12px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--bg); }
.opt:last-child { border-bottom: none; }
.opt:hover { background: #12151b; }
.opt .badge { justify-self: start; }
.opt-main { min-width: 0; }
.opt-q { display: flex; gap: 6px; align-items: center; min-height: 18px; }
.opt-name { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opt-name a { color: var(--muted); }
.opt-name a:hover { color: var(--text); }
.opt-size { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.opt-peers { text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbody > .btn.link { align-self: flex-start; padding-left: 0; }
@media (max-width: 760px) {
  .tcard { grid-template-columns: 84px 1fr; gap: 12px; }
  .cover { width: 84px; }
  .opt { grid-template-columns: 1fr auto; grid-template-areas: "main btn" "meta btn"; row-gap: 4px; }
  .opt .badge { display: none; }
  .opt-main { grid-area: main; }
  .opt-size, .opt-peers { grid-area: meta; text-align: left; }
  .opt-peers { justify-self: end; }
  .opt .btn { grid-area: btn; }
}
.spinner.small-spin { width: 10px; height: 10px; border-width: 2px; vertical-align: -1px; }
