:root {
  --bg: #0f0f12;
  --bg-2: #18181d;
  --bg-3: #23232a;
  --line: #2e2e37;
  --text: #f2f2f5;
  --muted: #a1a1ad;
  --accent: #7c5cff;
  --accent-2: #9b84ff;
  --ok: #3ecf8e;
  --warn: #f5a524;
  --err: #ff5a5f;
  --radius: 10px;
  --card-w: 260px;
  --pad: clamp(16px, 4vw, 56px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; overflow-x: hidden; }
body.no-scroll { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-2); }
.hidden { display: none !important; }
code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg-3); padding: 1px 6px; border-radius: 5px; word-break: break-all; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 8px; padding: 10px 20px; font-weight: 600; background: var(--bg-3); transition: background .15s, transform .1s; white-space: nowrap; }
.btn:hover { background: #2f2f38; }
.btn:active { transform: scale(.98); }
.btn.primary { background: #fff; color: #000; }
.btn.primary:hover { background: #dcdce2; }
.btn.accent { background: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent-2); }
.btn.ghost { background: rgba(255,255,255,.12); backdrop-filter: blur(6px); }
.btn.ghost:hover { background: rgba(255,255,255,.22); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; width: 38px; height: 38px; border-radius: 50%; display: inline-grid; place-items: center; color: var(--text); position: relative; flex: none; }
.icon-btn:hover { background: rgba(255,255,255,.1); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- nav ---------- */
.nav { position: fixed; inset: 0 0 auto 0; z-index: 30; display: flex; align-items: center; gap: 16px; padding: 12px var(--pad); background: linear-gradient(to bottom, rgba(15,15,18,.95), rgba(15,15,18,0)); transition: background .2s; }
.nav.solid { background: rgba(15,15,18,.97); box-shadow: 0 1px 0 var(--line); }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: -.02em; color: var(--text); text-decoration: none; flex: none; }
.logo svg { width: 26px; height: 26px; }
.nav .spacer { flex: 1; }
.search { display: flex; align-items: center; gap: 6px; background: rgba(0,0,0,.45); border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; height: 38px; width: min(280px, 40vw); }
.search svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.search input[type=search] { border: 0; outline: 0; background: transparent; width: 100%; min-width: 0; padding: 0; border-radius: 0; }
.badge { position: absolute; top: 2px; right: 0; min-width: 17px; height: 17px; border-radius: 9px; background: var(--accent); font-size: 11px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }

/* ---------- hero ---------- */
.hero { position: relative; min-height: min(72vh, 640px); display: flex; align-items: flex-end; padding: 120px var(--pad) 48px; overflow: hidden; }
.hero-bg { position: absolute; inset: 0; background: radial-gradient(circle at 70% 30%, hsl(var(--hue, 260) 50% 30%), var(--bg) 70%); }
.hero-bg img { width: 100%; height: 100%; object-fit: cover; opacity: .75; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to right, rgba(15,15,18,.92) 0%, rgba(15,15,18,.5) 45%, rgba(15,15,18,0) 75%), linear-gradient(to top, var(--bg) 0%, rgba(15,15,18,0) 40%); }
.hero-content { position: relative; z-index: 1; max-width: 640px; }
.hero h1 { font-size: clamp(30px, 5vw, 60px); line-height: 1.05; margin: 0 0 12px; letter-spacing: -.02em; text-shadow: 0 2px 20px rgba(0,0,0,.5); }
.hero .meta { color: #d6d6de; margin-bottom: 20px; }
.hero .actions { display: flex; gap: 12px; flex-wrap: wrap; }
.empty-hero { min-height: 60vh; display: grid; place-items: center; text-align: center; padding: 120px var(--pad) 40px; }
.empty-hero h1 { margin: 0 0 8px; }
.empty-hero p { color: var(--muted); margin: 0 0 20px; }

/* ---------- rows ---------- */
#rows { padding-bottom: 60px; position: relative; z-index: 2; margin-top: -24px; }
.row { margin: 8px 0 26px; }
.row h3 { margin: 0 var(--pad) 10px; font-size: 19px; font-weight: 700; }
.row-wrap { position: relative; }
.track { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x proximity; padding: 6px var(--pad) 14px; scroll-padding: 0 var(--pad); scrollbar-width: none; }
.track::-webkit-scrollbar { display: none; }
.arrow { position: absolute; top: 6px; bottom: 14px; width: calc(var(--pad) - 4px); min-width: 36px; border: 0; background: rgba(15,15,18,.7); z-index: 3; opacity: 0; transition: opacity .2s; font-size: 30px; color: #fff; }
.arrow.left { left: 0; } .arrow.right { right: 0; }
.row-wrap:hover .arrow { opacity: 1; }
@media (hover: none) { .arrow { display: none; } }

.card { flex: none; width: var(--card-w); border: 0; padding: 0; background: transparent; text-align: left; scroll-snap-align: start; border-radius: var(--radius); transition: transform .2s; }
.card:hover, .card:focus-visible { transform: scale(1.04); outline: none; }
.card:focus-visible .thumb { box-shadow: 0 0 0 3px var(--accent); }
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: linear-gradient(135deg, hsl(var(--hue) 45% 28%), hsl(calc(var(--hue) + 40) 50% 14%)); }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb .fallback { position: absolute; inset: 0; display: flex; align-items: flex-end; padding: 12px; font-weight: 800; font-size: 18px; line-height: 1.15; text-shadow: 0 1px 8px rgba(0,0,0,.6); }
.thumb .tag { position: absolute; top: 8px; left: 8px; z-index: 1; background: rgba(0,0,0,.7); border-radius: 5px; padding: 2px 7px; font-size: 11.5px; font-weight: 700; letter-spacing: .02em; }
.thumb .dl-overlay { position: absolute; inset: 0; z-index: 1; background: rgba(0,0,0,.55); display: grid; place-items: center; text-align: center; font-weight: 700; font-size: 14px; }
.thumb .dl-overlay small { display: block; font-weight: 500; color: #ddd; font-size: 12px; }
.bar { height: 4px; background: rgba(255,255,255,.18); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.thumb .bar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; border-radius: 0; }
.card-info { padding: 8px 2px 0; }
.card-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { color: var(--muted); font-size: 13px; }

.grid-view { padding: 90px var(--pad) 60px; }
.grid-view h2 { margin: 0 0 18px; font-size: 20px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--card-w), 1fr)); gap: 22px 12px; }
.grid .card { width: auto; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.7); overflow-y: auto; padding: 40px 16px; }
#detail.enter, #addModal, #confirm { animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: relative; max-width: 900px; margin: 0 auto; background: var(--bg-2); border-radius: 14px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
/* animate only when a dialog opens, not when its content refreshes */
#detail.enter .sheet, #addModal .sheet, #confirm .sheet { animation: rise .2s; }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
.sheet > .close { position: absolute; top: 12px; right: 12px; z-index: 5; background: rgba(0,0,0,.6); }
.backdrop { position: relative; aspect-ratio: 16 / 7.5; background: linear-gradient(135deg, hsl(var(--hue) 45% 26%), hsl(calc(var(--hue) + 40) 50% 12%)); }
.backdrop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.backdrop::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, var(--bg-2) 2%, rgba(24,24,29,0) 65%); }
.backdrop-content { position: absolute; left: 28px; right: 28px; bottom: 22px; z-index: 1; }
.title-line { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.title-line h2 { margin: 0; font-size: clamp(22px, 3.6vw, 36px); line-height: 1.1; text-shadow: 0 2px 12px rgba(0,0,0,.6); }
.rename-form { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.rename-form input { flex: 1; min-width: 200px; }
.sheet-body { padding: 6px 28px 28px; }
.meta-line { color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 16px; }
.meta-line .pill { color: var(--ok); font-weight: 600; }
.dl-box { background: var(--bg-3); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 18px; }
.dl-box .row-line { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; margin-bottom: 8px; color: var(--muted); }
.dl-box .row-line b { color: var(--text); }

.ep-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0 12px; flex-wrap: wrap; }
.ep-head h3 { margin: 0; font-size: 20px; }
select, input[type=text], input[type=url], input[type=password], input[type=search] { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; outline: none; min-width: 0; }
select:focus, input:focus { border-color: var(--accent); }
.episodes { list-style: none; margin: 0; padding: 0; }
.ep { display: grid; grid-template-columns: 34px 160px 1fr; gap: 14px; align-items: center; padding: 14px 10px; border-bottom: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.ep:hover, .ep:focus-visible { background: var(--bg-3); outline: none; }
.ep.current { background: rgba(124,92,255,.12); }
.ep .num { font-size: 22px; color: var(--muted); text-align: center; }
.ep .thumb { --hue: 250; }
.ep .thumb .play-ico { position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; opacity: 0; transition: opacity .15s; background: rgba(0,0,0,.35); }
.ep:hover .thumb .play-ico { opacity: 1; }
.ep .play-ico svg { width: 34px; height: 34px; }
.ep-title { font-weight: 600; word-break: break-word; }
.ep-sub { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; align-items: center; gap: 2px 10px; flex-wrap: wrap; }
.ep-sub .done { color: var(--ok); }
.ep-sub .warn { color: var(--warn); }

/* ---------- player ---------- */
.player { position: fixed; inset: 0; z-index: 80; background: #000; }
.player video { width: 100%; height: 100%; background: #000; }
.player-top { position: absolute; inset: 0 0 auto 0; display: flex; align-items: center; gap: 12px; padding: 14px 18px 40px; background: linear-gradient(to bottom, rgba(0,0,0,.8), rgba(0,0,0,0)); transition: opacity .3s; }
.player.idle .player-top { opacity: 0; pointer-events: none; }
.player.idle { cursor: none; }
.pt-title { flex: 1; min-width: 0; }
.pt-title b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pt-title span { color: #ccc; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.upnext { position: absolute; right: 24px; bottom: 90px; background: rgba(20,20,24,.95); border: 1px solid var(--line); border-radius: 12px; padding: 16px; width: min(340px, calc(100vw - 48px)); }
.upnext .lbl { color: var(--muted); font-size: 13px; }
.upnext .nm { font-weight: 700; margin: 4px 0 12px; }
.upnext .btns { display: flex; gap: 8px; }
.player-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; pointer-events: none; }
.player-msg > div { background: rgba(20,20,24,.95); border-radius: 12px; padding: 22px 26px; width: min(460px, 100%); pointer-events: auto; overflow: hidden; }
.player-msg .btn { white-space: normal; max-width: 100%; justify-content: center; }
.pt-title span { max-width: 100%; }

/* ---------- drawer ---------- */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 60; background: var(--bg-2); border-left: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: -20px 0 60px rgba(0,0,0,.5); animation: slide .2s; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 12px 20px; border-bottom: 1px solid var(--line); gap: 10px; }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-body { overflow-y: auto; padding: 12px 16px 24px; flex: 1; }
.job { background: var(--bg-3); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.job-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.job-name { font-weight: 700; word-break: break-word; }
.job-src { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0 10px; }
.job-stats { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.state { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 5px; background: rgba(255,255,255,.08); flex: none; }
.state.downloading, .state.finishing, .state.metadata { color: var(--accent-2); }
.state.done { color: var(--ok); }
.state.error { color: var(--err); }
.state.paused, .state.queued { color: var(--warn); }
.job-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.job .err { color: var(--err); font-size: 13px; margin-top: 6px; word-break: break-word; }
.empty { color: var(--muted); text-align: center; padding: 40px 10px; }

/* ---------- forms ---------- */
.form-sheet { max-width: 520px; padding: 26px; }
.form-sheet h2 { margin: 0 0 4px; }
.form-sheet .sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.field input { width: 100%; }
.field small { color: var(--muted); display: block; margin-top: 6px; font-size: 12.5px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: -4px 0 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.file-pick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-pick .fname { color: var(--muted); font-size: 13px; word-break: break-all; }
.form-error { color: var(--err); font-size: 14px; margin: 0 0 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Movies / Courses switch ---------- */
.sections { display: flex; gap: 4px; margin-left: 18px; }
.sections a { color: var(--muted); text-decoration: none; font-weight: 600; padding: 7px 12px; border-radius: 8px; }
.sections a:hover { color: var(--text); background: rgba(255,255,255,.06); }
.sections a.active { color: var(--text); background: rgba(255,255,255,.1); }
body.view-courses .movie-search, body.view-course .movie-search { display: none !important; }
.muted { color: var(--muted); }
.link-btn.plain { color: var(--accent-2); text-decoration: none; font-weight: 600; }
.link-btn.plain:hover { color: var(--text); text-decoration: underline; }

/* ---------- pages (courses) ---------- */
.page { padding: calc(88px + env(safe-area-inset-top)) var(--pad) 60px; max-width: 1180px; margin: 0 auto; }
.page-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: clamp(26px, 4vw, 36px); letter-spacing: -.02em; }
.course-tools { display: flex; gap: 10px; margin-bottom: 22px; }
.search.big { flex: 1; width: auto; height: 46px; background: var(--bg-2); border-radius: 10px; padding: 0 14px; }
.search.big svg { width: 18px; height: 18px; }
.search.big input[type=search] { border: 0; outline: 0; background: transparent; width: 100%; padding: 0; font-size: 15.5px; }
.course-tools select { height: 46px; border-radius: 10px; background: var(--bg-2); }
.empty-state { text-align: center; padding: 60px 16px; color: var(--muted); }
.empty-state h2 { color: var(--text); margin: 0 0 8px; }
.empty-state .btn { margin-top: 12px; }

.course-list { display: flex; flex-direction: column; gap: 12px; }
.course-row { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px 16px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px 12px 12px; transition: border-color .15s, background .15s; }
.course-row:hover { border-color: #3d3d48; background: #1c1c22; }
.cr-open { display: grid; grid-template-columns: 220px 1fr; gap: 18px; align-items: center; border: 0; background: none; padding: 0; text-align: left; min-width: 0; }
.cr-thumb { border-radius: 10px; }
.cr-thumb .fallback { font-size: 15px; }
.done-tag { background: rgba(62,207,142,.9) !important; color: #06281a; }
.cr-main { min-width: 0; }
.cr-title { margin: 0 0 4px; font-size: 18px; line-height: 1.25; word-break: break-word; }
.cr-meta { color: var(--muted); font-size: 13.5px; margin-bottom: 10px; }
.cr-prog { display: flex; align-items: center; gap: 12px; font-size: 13.5px; color: var(--muted); }
.cr-prog .bar { flex: 1; max-width: 320px; height: 6px; border-radius: 3px; }
.cr-prog .bar > i, .ch-prog .bar > i { background: linear-gradient(90deg, var(--accent), var(--ok)); }
.cr-prog b { color: var(--text); }
.cr-next { margin-top: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.course-row .dl-box { margin: 4px 0 0; padding: 10px 12px; }
.cr-hits { grid-column: 1 / -1; list-style: none; margin: 4px 0 0; padding: 8px 0 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.cr-hits button { width: 100%; display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 8px 10px; border-radius: 8px; text-align: left; }
.cr-hits button:hover { background: var(--bg-3); }
.cr-hits .hit-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-hits small { color: var(--muted); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-hits .more button { color: var(--accent-2); font-weight: 600; }
.hit-check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #4a4a55; display: grid; place-items: center; flex: none; }
.hit-check svg { width: 12px; height: 12px; opacity: 0; }
.hit-check.on { background: var(--ok); border-color: var(--ok); color: #06281a; }
.hit-check.on svg { opacity: 1; }

/* course page */
.course-page { max-width: 1000px; padding-top: 0; }
.course-head { position: relative; margin: 0 calc(var(--pad) * -1); padding: calc(88px + env(safe-area-inset-top)) var(--pad) 28px; overflow: hidden; border-radius: 0 0 18px 18px; }
.ch-bg { position: absolute; inset: 0; background: linear-gradient(135deg, hsl(var(--hue) 45% 22%), hsl(calc(var(--hue) + 40) 50% 10%)); }
.ch-bg img { width: 100%; height: 100%; object-fit: cover; opacity: .35; filter: blur(2px); transform: scale(1.03); }
.course-head::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, var(--bg) 0%, rgba(15,15,18,.6) 55%, rgba(15,15,18,.35) 100%); }
.ch-inner { position: relative; z-index: 1; }
.back-link { display: inline-block; color: var(--muted); text-decoration: none; font-weight: 600; margin-bottom: 14px; padding: 4px 0; }
.back-link:hover { color: var(--text); }
.course-head .title-line h1 { margin: 0; font-size: clamp(24px, 4vw, 38px); line-height: 1.12; letter-spacing: -.02em; word-break: break-word; }
.ch-meta { color: #cfcfd8; margin: 6px 0 16px; }
.ch-prog { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; color: #cfcfd8; font-size: 14.5px; flex-wrap: wrap; }
.ch-prog .bar { flex: 1; min-width: 180px; max-width: 460px; height: 8px; border-radius: 4px; }
.ch-prog b { color: var(--text); }
.ch-next { color: #cfcfd8; font-size: 14px; margin: -6px 0 14px; word-break: break-word; }
.ch-next b { color: var(--text); font-weight: 600; }
.ch-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.ch-actions .btn.primary { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.course-head .dl-box { margin: 18px 0 0; max-width: 560px; }
.csections { padding-top: 18px; }
.csec { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 12px; overflow: hidden; }
.csec-head { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; }
.csec-toggle { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 10px 8px; text-align: left; font-weight: 700; font-size: 16px; border-radius: 8px; }
.csec-toggle:hover { background: rgba(255,255,255,.04); }
.csec-toggle svg { width: 18px; height: 18px; flex: none; color: var(--muted); transition: transform .2s; }
.csec.collapsed .csec-toggle svg { transform: rotate(-90deg); }
.csec-name { min-width: 0; word-break: break-word; }
.icon-btn.small { width: 34px; height: 34px; color: var(--muted); }
.icon-btn.small svg { width: 17px; height: 17px; }
.icon-btn.small:hover { color: var(--text); }
.csec-count { font-size: 12.5px; font-weight: 700; color: var(--muted); background: var(--bg-3); border-radius: 20px; padding: 3px 10px; flex: none; }
.csec-count.done { color: #06281a; background: var(--ok); }
.csec .link-btn.plain { font-size: 13px; white-space: nowrap; flex: none; }
.sec-rename { padding: 10px 14px; margin: 0; }
.csec.collapsed .lessons { display: none; }
.lessons { list-style: none; margin: 0; padding: 0 0 6px; border-top: 1px solid var(--line); }
.lesson { display: grid; grid-template-columns: auto 26px 1fr auto; align-items: center; gap: 12px; padding: 10px 12px 10px 14px; cursor: pointer; border-bottom: 1px solid rgba(46,46,55,.5); }
.lesson:last-child { border-bottom: 0; }
.lesson:hover, .lesson:focus-visible { background: var(--bg-3); outline: none; }
.lesson.current { background: rgba(124,92,255,.1); box-shadow: inset 3px 0 0 var(--accent); }
.check { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #4a4a55; background: transparent; display: grid; place-items: center; padding: 0; color: transparent; transition: background .15s, border-color .15s, transform .1s; flex: none; }
.check svg { width: 16px; height: 16px; }
.check:hover { border-color: var(--ok); color: rgba(62,207,142,.6); }
.check:active { transform: scale(.9); }
.check.on { background: var(--ok); border-color: var(--ok); color: #06281a; }
.l-num { color: var(--muted); font-size: 13.5px; text-align: right; font-variant-numeric: tabular-nums; }
.l-main { min-width: 0; }
.l-title { font-weight: 600; word-break: break-word; line-height: 1.35; }
.lesson.watched .l-title { color: var(--muted); }
.l-sub { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.l-sub:empty { display: none; }
.l-bar { display: inline-block; width: 80px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.15); overflow: hidden; }
.l-bar > i { display: block; height: 100%; background: var(--accent); }
.up-next { color: var(--accent-2); font-weight: 700; }
.l-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.lesson:hover .l-actions, .lesson:focus-within .l-actions { opacity: 1; }
@media (hover: none) { .l-actions { opacity: 1; } }

/* add form: Movies / Courses choice */
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 7px 14px; border-radius: 7px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg input:checked + span { background: var(--accent); color: #fff; }
.seg input:focus-visible + span { box-shadow: 0 0 0 2px var(--accent-2); }

/* download queue priority */
.queue-ctl { display: flex; align-items: center; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.queue-ctl > span { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-right: auto; }
.queue-ctl .btn { padding: 5px 11px; }
.job.is-queued { border: 1px solid rgba(245,165,36,.25); }

@media (max-width: 700px) {
  .page { padding: calc(70px + env(safe-area-inset-top)) 16px 24px; }
  .course-tools { flex-direction: column; }
  .course-tools select { height: 42px; }
  .course-row { grid-template-columns: 1fr; padding: 12px; gap: 10px; }
  .cr-open { grid-template-columns: 112px 1fr; gap: 12px; align-items: start; }
  .cr-title { font-size: 15.5px; }
  .cr-meta { font-size: 12.5px; margin-bottom: 8px; }
  .cr-prog { font-size: 12.5px; gap: 8px; }
  .cr-play { width: 100%; justify-content: center; padding: 10px; }
  .course-page { padding-top: 0; }
  .course-head { margin: 0 -16px; padding: calc(64px + env(safe-area-inset-top)) 16px 22px; border-radius: 0; }
  .ch-actions .btn.primary { width: 100%; justify-content: center; padding: 13px; }
  .ch-actions .btn.ghost { flex: 1; justify-content: center; }
  .csec-head { flex-wrap: wrap; padding: 4px 8px 8px 4px; }
  .csec-toggle { flex-basis: calc(100% - 90px); font-size: 15px; }
  .csec .link-btn.plain { margin-left: auto; padding: 4px 6px; }
  .lesson { grid-template-columns: auto 1fr auto; gap: 10px; padding: 10px 8px 10px 10px; }
  .l-num { display: none; }
  .l-title { font-size: 14.5px; }
  .l-actions .icon-btn.small { width: 32px; height: 32px; }
  .check { width: 32px; height: 32px; }
  .queue-ctl .btn { flex: none; }
}

/* ---------- storage ---------- */
body.view-storage .movie-search { display: none !important; }
#storageBtn { color: var(--text); text-decoration: none; }
#storageBtn.active { background: rgba(255,255,255,.12); }
.disk-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; margin-bottom: 18px; }
.disk-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: rgba(255,255,255,.1); }
.disk-bar i { display: block; height: 100%; }
.disk-bar .lib { background: var(--accent); }
.disk-bar .other { background: #6b6b78; }
.disk-bar.low { box-shadow: 0 0 0 1px var(--err); }
.disk-legend { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 12px; font-size: 14px; color: var(--muted); }
.disk-legend b { color: var(--text); margin-left: 4px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.dot.lib { background: var(--accent); } .dot.other { background: #6b6b78; } .dot.free { background: rgba(255,255,255,.15); }
.disk-total { margin-top: 8px; font-size: 13.5px; color: var(--muted); }
.disk-total .warn { color: var(--err); font-weight: 600; }
.storage-tools { align-items: center; }
.storage-tools .seg { margin-right: auto; }
.st-list { display: flex; flex-direction: column; gap: 8px; }
.st-row { display: grid; grid-template-columns: 1fr 200px auto; gap: 16px; align-items: center; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 10px 10px 10px; }
.st-open { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: center; border: 0; background: none; padding: 0; text-align: left; min-width: 0; }
.st-open:disabled { cursor: default; opacity: .85; }
.st-thumb { border-radius: 8px; }
.st-thumb .fallback { font-size: 12px; padding: 8px; }
.st-main { min-width: 0; }
.st-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-sub { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin: 4px 0 6px; }
.chip { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: var(--bg-3); color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.chip.movie { color: #f5b544; } .chip.course { color: var(--accent-2); }
.bar.thin { height: 4px; max-width: 240px; }
.bar.thin > i { background: var(--ok); }
.st-size { text-align: right; }
.st-size b { font-size: 15px; }
.bar.size { height: 6px; margin: 6px 0 4px; }
.bar.size > i { background: var(--accent); }
.st-size small { color: var(--muted); font-size: 12px; }
.drawer-storage { display: block; padding: 12px 20px 14px; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; }
.drawer-storage:empty { display: none; }
.drawer-storage:hover { background: rgba(255,255,255,.03); }
.drawer-storage .disk-bar { height: 8px; }
.disk-mini { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px; color: var(--muted); }
.disk-mini b { color: var(--text); }
.disk-mini .go { color: var(--accent-2); font-weight: 600; }
@media (max-width: 700px) {
  .storage-tools { flex-direction: column; align-items: stretch; }
  .storage-tools .seg { margin-right: 0; display: flex; }
  .storage-tools .seg label { flex: 1; text-align: center; }
  .st-row { grid-template-columns: 1fr auto; gap: 8px 10px; }
  .st-open { grid-template-columns: 84px 1fr; gap: 10px; }
  .st-size { grid-column: 1 / -1; grid-row: 2; text-align: left; display: flex; align-items: center; gap: 10px; }
  .st-size .bar.size { flex: 1; margin: 0; }
  .disk-card { padding: 14px; }
}

.disk-warn { background: rgba(255,90,95,.12); border: 1px solid rgba(255,90,95,.4); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; font-size: 13.5px; line-height: 1.5; }
.disk-warn b { color: var(--err); }

/* ---------- delete & confirm ---------- */
.btn.danger-fill { background: var(--err); color: #fff; }
.btn.danger-fill:hover { background: #ff7579; }
.icon-btn.danger:hover { color: var(--err); background: rgba(255,90,95,.14); }
.link-btn { border: 0; background: none; padding: 0; color: var(--muted); text-decoration: underline; font: inherit; }
.link-btn:hover { color: var(--err); }
#confirm { z-index: 95; display: grid; place-items: center; }
#confirm.hidden { display: none; }
.sheet.confirm-sheet { width: min(440px, 100%); padding: 24px; margin: 0; }
.confirm-sheet h3 { margin: 0 0 8px; font-size: 19px; word-break: break-word; }
.confirm-sheet p { color: var(--muted); margin: 0 0 22px; word-break: break-word; }
@media (max-width: 700px) {
  #confirm { place-items: end stretch; }
  .sheet.confirm-sheet { width: 100%; min-height: 0; border-radius: 18px 18px 0 0; padding: 22px 18px calc(18px + env(safe-area-inset-bottom)); }
}

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; background: #fff; color: #000; padding: 10px 18px; border-radius: 8px; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.4); max-width: calc(100vw - 32px); }
.toast.err { background: var(--err); color: #fff; }

/* ---------- login ---------- */
.login { min-height: 100vh; min-height: 100svh; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); background: radial-gradient(circle at 30% 20%, #2a1f5c, var(--bg) 60%); }
.login form { width: min(380px, 100%); background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; padding: 32px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.login .logo { margin-bottom: 24px; font-size: 22px; }
.login .logo svg { width: 30px; height: 30px; }
.login h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: -.01em; }
.login .sub { margin: 0 0 22px; color: var(--muted); font-size: 14.5px; }
.pw-field { position: relative; display: block; margin-bottom: 14px; }
.pw-field input { width: 100%; height: 50px; padding: 0 50px 0 14px; font-size: 16px; border-radius: 10px; }
.pw-field .icon-btn { position: absolute; right: 5px; top: 5px; width: 40px; height: 40px; color: var(--muted); }
.pw-field .icon-btn.on { color: var(--accent-2); }
.login .form-error { margin-top: -4px; }
.login .btn { width: 100%; justify-content: center; height: 50px; font-size: 16px; border-radius: 10px; }
body.login-page { padding-bottom: 0 !important; }
@media (max-width: 700px) {
  .login { place-items: stretch; align-content: center; background: radial-gradient(circle at 50% 0%, #2a1f5c, var(--bg) 70%); }
  .login form { width: 100%; background: transparent; border: 0; box-shadow: none; padding: 0 4px; }
  .login .logo { justify-content: center; margin-bottom: 36px; font-size: 26px; }
  .login .logo svg { width: 40px; height: 40px; }
  .login h1, .login .sub { text-align: center; }
  .login h1 { font-size: 28px; }
}

/* ---------- touch devices ---------- */
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
.nav { padding-top: calc(12px + env(safe-area-inset-top)); }
.player-top { padding-top: calc(14px + env(safe-area-inset-top)); }
.tabbar, .mobile-only, .touch-only { display: none; }
@media (hover: none) {
  .touch-only { display: inline-grid; }
  .card:hover { transform: none; }
  .card:active { transform: scale(.97); }
  .ep .thumb .play-ico { opacity: 1; background: transparent; }
  .ep .play-ico svg { width: 30px; height: 30px; }
}

/* ---------- phones ---------- */
@media (max-width: 700px) {
  :root { --card-w: 42vw; --tabbar-h: 58px; }
  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .desktop-only { display: none !important; }
  input, select, textarea { font-size: 16px !important; } /* stops iOS zooming into fields */

  /* top bar: logo + sign out; search slides in when the Search tab is used */
  .nav { gap: 8px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); padding-bottom: 10px; }
  .nav .search { display: none; }
  body.searching .nav { background: rgba(15,15,18,.97); }
  body.searching .nav .logo, body.searching .nav .spacer, body.searching #logoutBtn { display: none; }
  body.searching .nav .search { display: flex; flex: 1; width: auto; height: 42px; }
  body.searching #searchClose { display: inline-grid; }

  /* bottom tab bar */
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; background: rgba(18,18,22,.96); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .tabbar button { flex: 1; height: var(--tabbar-h); border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 600; position: relative; }
  .tabbar button svg { width: 23px; height: 23px; }
  .tabbar button.active { color: var(--text); }
  .tabbar button.active svg { color: var(--accent-2); }
  .tabbar .badge { top: 5px; right: calc(50% - 24px); }

  /* home */
  .hero { min-height: 72vh; min-height: 72svh; padding: 96px 16px 32px; justify-content: center; text-align: center; }
  .hero::after { background: linear-gradient(to top, var(--bg) 3%, rgba(15,15,18,.55) 45%, rgba(15,15,18,.15) 100%); }
  .hero-content { width: 100%; }
  .hero h1 { font-size: 32px; }
  .hero .meta { margin-bottom: 16px; }
  .hero .actions { justify-content: center; flex-wrap: nowrap; }
  .hero .actions .btn { flex: 1; max-width: 200px; justify-content: center; padding: 12px 14px; }
  .empty-hero .btn { width: 100%; justify-content: center; }
  #rows { margin-top: 0; padding-bottom: 24px; }
  .row { margin: 4px 0 20px; }
  .row h3 { font-size: 17px; margin-bottom: 8px; }
  .track { gap: 8px; padding-bottom: 8px; }
  .card-title { font-size: 14px; }
  .card-meta { font-size: 12px; }
  .thumb .fallback { font-size: 15px; padding: 10px; }
  .thumb .tag { font-size: 10.5px; top: 6px; left: 6px; }
  .grid-view { padding: calc(80px + env(safe-area-inset-top)) 16px 24px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 8px; }

  /* title page becomes a full-screen page */
  .overlay { padding: 0; }
  .sheet { border-radius: 0; min-height: 100%; max-width: none; padding-bottom: env(safe-area-inset-bottom); }
  .sheet > .close { position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 10px; width: 40px; height: 40px; }
  .backdrop { aspect-ratio: 4 / 3; }
  .backdrop-content { left: 16px; right: 16px; bottom: 16px; }
  .title-line h2 { font-size: 26px; }
  .backdrop .actions .btn { width: 100%; justify-content: center; padding: 13px; }
  .sheet-body { padding: 8px 16px 28px; }
  .meta-line { font-size: 14px; }
  .ep-head select { width: 100%; }
  .ep { grid-template-columns: 124px 1fr; gap: 12px; padding: 10px 4px; }
  .ep .num { display: none; }
  .ep-title { font-size: 14.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .ep-sub { font-size: 12.5px; }
  .ep-sub a { padding: 6px 0; }

  /* add form & downloads */
  .form-sheet { padding: calc(22px + env(safe-area-inset-top)) 16px 24px; }
  .form-sheet > .close { top: calc(12px + env(safe-area-inset-top)); }
  .form-actions .btn { flex: 1; justify-content: center; padding: 13px; }
  .drawer { width: 100vw; border-left: 0; z-index: 44; padding-top: env(safe-area-inset-top); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); box-shadow: none; }
  .drawer #drawerClose { display: none; }
  .job-actions .btn { flex: 1; justify-content: center; padding: 9px 10px; }
  .toast { bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); }

  /* player */
  .player-top { padding: calc(8px + env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 30px max(8px, env(safe-area-inset-left)); gap: 2px; }
  .pt-title b { font-size: 15px; }
  .upnext { left: 12px; right: 12px; width: auto; bottom: calc(80px + env(safe-area-inset-bottom)); }
}
@media (max-width: 700px) and (orientation: landscape) {
  .hero { min-height: 100vh; min-height: 100svh; }
  .backdrop { aspect-ratio: 16 / 7; }
}
