:root {
  --bg: #f5f6f8; --card: #fff; --text: #1b1f27; --muted: #6b7280; --line: #e3e6eb;
  --accent: #4f7cff; --accent-text: #fff; --ok: #12805c; --err: #c4362b; --warn: #b26a00;
  --pill-wanted: #fde8e6; --pill-downloading: #e3ecff; --pill-downloaded: #e1f5ec; --pill-upcoming: #eef0f3;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a; --card: #1b1e26; --text: #e6e8ee; --muted: #9098a8; --line: #2a2e39;
    --accent: #6b8fff; --ok: #3fcf98; --err: #ff7a6e; --warn: #f0b04d;
    --pill-wanted: #3a2222; --pill-downloading: #1f2b4a; --pill-downloaded: #183528; --pill-upcoming: #262a33;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
h3 { margin: 0; }
code { font-size: .85em; background: var(--line); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
.muted { color: var(--muted); } .small, small { font-size: .85rem; } .err { color: var(--err); } .ok { color: var(--ok); }
.nowrap { white-space: nowrap; }

header.top { display: flex; align-items: center; gap: 1.5rem; padding: .7rem 1.25rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: .5rem; }
nav { display: flex; gap: .25rem; flex-wrap: wrap; align-items: center; }
nav a { color: var(--muted); padding: .3rem .6rem; border-radius: 6px; }
nav a.on, nav a:hover { color: var(--text); background: var(--bg); text-decoration: none; }
main { max-width: 1200px; margin: 0 auto; padding: 1.25rem 16px 4rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1rem; }
.flash { background: var(--pill-downloading); border-radius: var(--radius); padding: .7rem 1rem; margin-bottom: 1rem; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin: .5rem 0; }
.row.between { justify-content: space-between; margin: .2rem 0; } .small-gap { gap: .3rem; margin: .3rem 0; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid2 > .card { margin-bottom: 0; } .grid2 { margin-bottom: 1rem; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }
form.inline { display: inline; }
.form label { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .8rem; font-weight: 500; }
.form label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
.form .row input { flex: 1; }

input, select, button, .btn { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 7px; padding: .45rem .7rem; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: 1rem; height: 1rem; }
button, .btn { cursor: pointer; display: inline-block; background: var(--bg); white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--err); }
button.small, .btn.small { padding: .15rem .55rem; font-size: .82rem; }
button.link { background: none; border: none; color: var(--muted); padding: .3rem .6rem; }
button.icon { background: none; border: none; padding: 0 .2rem; color: var(--accent); font-size: 1rem; }
button:disabled, .busy { opacity: .6; pointer-events: none; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
table.compact td { padding: .3rem .4rem; }
.tablewrap { overflow-x: auto; }
tr.unmon td { opacity: .5; }
tr.rejected td { color: var(--muted); }
tr.grabbed td { background: var(--pill-downloading); }
td.note { font-size: .85rem; max-width: 420px; }
td.rname { word-break: break-word; min-width: 260px; }
.events tr.error td:last-child { color: var(--err); } .events tr.warning td:last-child { color: var(--warn); }

.pill { display: inline-block; padding: 0 .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--pill-upcoming); }
.pill.wanted, .pill.failed { background: var(--pill-wanted); color: var(--err); }
.pill.downloading { background: var(--pill-downloading); color: var(--accent); }
.pill.downloaded, .pill.done { background: var(--pill-downloaded); color: var(--ok); }
.pill.upcoming { color: var(--muted); }

.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin: .3rem 0; }
.bar i { display: block; height: 100%; background: var(--accent); }
.bar.full i { background: var(--ok); }
.dl { padding: .5rem 0; border-bottom: 1px solid var(--line); } .dl:last-child { border-bottom: none; }
.dl .name { font-weight: 500; word-break: break-word; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1rem; }
@media (max-width: 600px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1.1rem; color: var(--text); }
.stat b { display: block; font-size: 1.8rem; } .stat span { color: var(--muted); }
.stat:hover { border-color: var(--accent); text-decoration: none; }

.posters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
.poster { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; color: var(--text); }
.poster:hover { border-color: var(--accent); text-decoration: none; }
.poster img, .poster .noimg { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; background: var(--line); }
.poster .noimg { display: flex; align-items: center; justify-content: center; padding: 1rem; text-align: center; color: var(--muted); }
.poster .meta { padding: .5rem .6rem .7rem; font-size: .9rem; }

.searchbar { display: flex; gap: .5rem; margin-bottom: 1rem; } .searchbar input { flex: 1; }
.result, .hero { display: flex; gap: 1rem; }
.result img { width: 90px; border-radius: 6px; align-self: flex-start; }
.hero img { width: 160px; border-radius: 8px; align-self: flex-start; }
@media (max-width: 600px) { .hero { flex-direction: column; } .hero img { width: 120px; } }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

details.season > summary { display: flex; align-items: baseline; gap: .8rem; cursor: pointer; list-style: none; }
details.season > summary::-webkit-details-marker { display: none; }
details.season > summary h2 { margin: 0; }
details.season > summary::before { content: "▸"; color: var(--muted); } details.season[open] > summary::before { content: "▾"; }
details.help { margin-top: .5rem; } details.help summary { cursor: pointer; color: var(--accent); }

body.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: .8rem; }
.login-card h1 { display: flex; align-items: center; gap: .5rem; font-size: 1.3rem; }
.login-card label { display: flex; flex-direction: column; gap: .3rem; }

/* tabs + discover */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .5rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input.grow { flex: 1 1 220px; min-width: 0; }
.dgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
@media (max-width: 480px) { .dgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; } }
.dcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.dposter { position: relative; display: block; }
.dposter img, .dposter .noimg { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; background: var(--line); }
.dposter .noimg { display: flex; align-items: center; justify-content: center; text-align: center; padding: .8rem; color: var(--muted); }
.rating { position: absolute; top: .4rem; left: .4rem; background: rgba(0,0,0,.72); color: #ffd666; font-size: .75rem; font-weight: 600; padding: 1px 6px; border-radius: 6px; }
.badge { position: absolute; left: .4rem; right: .4rem; bottom: .4rem; text-align: center; font-size: .75rem; font-weight: 600; padding: 2px 6px; border-radius: 6px; background: rgba(0,0,0,.75); color: #fff; }
.badge.downloaded { background: rgba(18,128,92,.92); }
.badge.downloading { background: rgba(79,124,255,.92); }
.badge.wanted { background: rgba(178,106,0,.92); }
.dmeta { padding: .5rem .6rem .7rem; display: flex; flex-direction: column; gap: .3rem; flex: 1; }
.dmeta b { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dmeta .btn, .dmeta button { margin-top: auto; text-align: center; }
.addrow { display: flex; gap: .3rem; margin-top: auto; }
.addrow button { flex: 1; padding-left: .3rem; padding-right: .3rem; }
.more { text-align: center; margin: 1.5rem 0; }
.addrow { flex-wrap: wrap; }
.addrow .btn { flex-basis: 100%; text-align: center; }
.seasonpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: .4rem; margin: .8rem 0; }
.seasonpick.compact { flex-basis: 100%; grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr)); margin: .2rem 0; }
.seasonpick[hidden] { display: none; }
.seasonopt { display: flex; gap: .5rem; align-items: flex-start; padding: .45rem .6rem; border: 1px solid var(--line, #8884); border-radius: 8px; cursor: pointer; }
.seasonopt span { display: flex; flex-direction: column; }
.seasonopt:has(input:checked) { border-color: var(--accent, #4a8); }
label.check { display: flex; gap: .5rem; align-items: center; }
