:root {
  --bg: #14121a; --panel: #1e1b27; --panel2: #292534; --line: #353043;
  --text: #f1eef7; --muted: #a39db3; --accent: #ff6f91; --accent2: #b28dff;
  --ok: #5fd39a; --err: #ff8a80; --r: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1 { font-size: 1.5rem; margin: .2em 0 .3em; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 0 0 .6em; }
a { color: inherit; text-decoration: none; }
p { margin: .5em 0; }
.muted { color: var(--muted); } .small { font-size: .82rem; } .error { color: var(--err); }
.pad { padding: 1em 0; }
[hidden] { display: none !important; }

#top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: rgba(20, 18, 26, .92);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.1rem; background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
#jobpill { font-size: .8rem; background: var(--panel2); padding: 4px 10px; border-radius: 99px; color: var(--accent2); }
main { max-width: 1000px; margin: 0 auto; padding: 16px; }
section { margin: 0 0 28px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }

#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: space-around;
  background: rgba(30, 27, 39, .96); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
#tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); padding: 4px 18px; min-width: 88px; }
#tabs a.on { color: var(--accent); }
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

button, .btn, select, input, textarea { font: inherit; color: inherit; }
button, .btn {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
  cursor: pointer; display: inline-block; min-height: 44px;
}
button:disabled { opacity: .5; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #2a0b14; font-weight: 600; }
button.icon { background: none; border: none; min-width: 44px; padding: 8px; font-size: 1.2rem; color: var(--muted); }
button.link { background: none; border: none; padding: 0; min-height: 0; color: var(--accent2); text-decoration: underline; }
button.danger { color: var(--err); }
input, select, textarea {
  width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; vertical-align: middle; accent-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
.section-head select { width: auto; min-height: 36px; padding: 4px 8px; font-size: .85rem; }
.form { display: grid; gap: 10px; margin: 10px 0; }
.field { display: grid; gap: 4px; } .field > span { font-size: .82rem; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.login, .empty { max-width: 380px; margin: 12vh auto 0; display: grid; gap: 12px; text-align: center; }
.login h1 { font-size: 2rem; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0; scrollbar-width: none; }
.chips button { white-space: nowrap; border-radius: 99px; padding: 6px 14px; min-height: 36px; font-size: .88rem; color: var(--muted); }
.chips button.on { background: var(--accent2); border-color: var(--accent2); color: #1a1030; font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px 12px; }
.row { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x proximity; }
.row .card { flex: 0 0 200px; scroll-snap-align: start; }
.card { display: block; min-width: 0; }
.poster { position: relative; aspect-ratio: 16/9; border-radius: var(--r); overflow: hidden; background: var(--panel2); }
.poster img, .ep-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.noposter { height: 100%; display: grid; place-items: center; font-size: 2rem; font-weight: 700; color: var(--muted); background: linear-gradient(135deg, #3a2740, #262040); }
.badge { position: absolute; top: 6px; left: 6px; background: var(--accent); color: #2a0b14; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.bar { height: 4px; background: rgba(255, 255, 255, .15); }
.poster .bar { position: absolute; left: 0; right: 0; bottom: 0; }
.bar i { display: block; height: 100%; background: var(--ok); }
.bar.big { height: 8px; border-radius: 99px; overflow: hidden; flex: 1; }
.card-title { font-weight: 600; margin-top: 6px; font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.back { color: var(--muted); display: inline-block; padding: 4px 0 8px; }
.progress { display: flex; align-items: center; gap: 12px; margin-top: 10px; font-size: .88rem; color: var(--muted); }
.notes { background: var(--panel); border-radius: var(--r); padding: 10px 12px; white-space: pre-wrap; }
.eps { list-style: none; padding: 0; margin: 20px 0; }
.ep { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); }
.ep.next { background: var(--panel); border-radius: var(--r); border-bottom-color: transparent; }
.ep-main { flex: 1; min-width: 0; display: flex; gap: 12px; align-items: center; text-align: left; background: none; border: none; padding: 8px 4px; border-radius: var(--r); }
.ep-thumb { position: relative; flex: 0 0 112px; aspect-ratio: 16/9; border-radius: 8px; overflow: hidden; background: var(--panel2); }
.dur { position: absolute; right: 4px; bottom: 4px; background: rgba(0, 0, 0, .75); font-size: .7rem; padding: 1px 5px; border-radius: 4px; }
.ep-text { min-width: 0; }
.ep-label { font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ep-title { font-size: .84rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ep.seen .ep-thumb, .ep.seen .ep-text { opacity: .5; }
.tag { font-size: .7rem; font-weight: 600; background: var(--panel2); color: var(--accent2); padding: 1px 7px; border-radius: 99px; white-space: nowrap; }
.tag.new { background: var(--accent); color: #2a0b14; } .tag.file { color: var(--ok); }
.check { flex: 0 0 40px; width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 50%; color: transparent; border: 2px solid var(--line); background: none; font-weight: 700; }
.check[aria-pressed=true] { background: var(--ok); border-color: var(--ok); color: #0c2a1c; }

.sources ul, .jobs, .picklist, .preview { list-style: none; padding: 0; margin: 0; }
.sources li, .jobs li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.jobs li { display: block; }
.picklist li { border-bottom: 1px solid var(--line); } .picklist label { display: block; padding: 12px 0; cursor: pointer; }
.picklist { margin-bottom: 14px; max-height: 55vh; overflow-y: auto; }
.preview li { padding: 5px 0; font-size: .9rem; } .preview { margin-bottom: 12px; }
.hint { background: var(--panel); border-left: 3px solid var(--accent2); padding: 10px 12px; border-radius: 6px; }

.dlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 16px; width: min(440px, calc(100vw - 24px)); max-height: 88vh; }
.dlg.wide { width: min(1100px, 100vw); max-width: 100vw; padding: 10px; }
.dlg::backdrop { background: rgba(0, 0, 0, .7); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.dlg-head h2 { margin: 0; overflow-wrap: anywhere; }
.sheet { display: grid; gap: 8px; } .sheet button { text-align: left; }
.player video { width: 100%; max-height: 78vh; background: #000; border-radius: 10px; display: block; }

#toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 20; margin: 0 auto; max-width: 480px;
  background: #3a3350; border-radius: var(--r); padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
}
#toast button { min-height: 36px; padding: 6px 12px; background: var(--accent); border: none; color: #2a0b14; font-weight: 600; white-space: nowrap; }

@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .ep-thumb { flex-basis: 150px; }
}

h3 { font-size: .95rem; margin: 18px 0 6px; }
.dlg.find { overflow-y: auto; padding: 16px; width: min(640px, calc(100vw - 16px)); }
.found { list-style: none; padding: 0; margin: 0 0 12px; }
.found li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.found label { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; flex: 1; }
.found label input { flex: 0 0 20px; margin-top: 2px; }
.found li.have { opacity: .5; }
.found .tag { margin-left: 6px; }
.found label .tag { margin-left: 0; }
details summary { cursor: pointer; color: var(--accent2); padding: 10px 0; }
