:root {
  --bg: #121212;
  --bg-2: #1a1a1a;
  --bg-3: #242424;
  --line: #2e2e2e;
  --text: #ececec;
  --muted: #9a9a9a;
  --accent: #f59e0b;
  --accent-ink: #111;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 8px;
  --sidebar: 232px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.spinner { width: 34px; height: 34px; border: 3px solid #ffffff22; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg-3); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #2c2c2c; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.lg { padding: 11px 20px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--line); background: #0d0d0d; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 80px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.check { display: flex; gap: 10px; align-items: center; margin: 8px 0; cursor: pointer; }
.error { color: var(--danger); margin: 8px 0; }
.ok { color: var(--ok); }

/* ---------- auth card ---------- */
.auth { width: 100%; max-width: 400px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 700; margin-bottom: 20px; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; }
.logo::after { content: ""; border-left: 12px solid #111; border-top: 8px solid transparent; border-bottom: 8px solid transparent; margin-left: 3px; }
.auth .switch { margin-top: 16px; text-align: center; }
.auth .switch a { color: var(--accent); cursor: pointer; }
.code-input { font-family: ui-monospace, Menlo, monospace; font-size: 22px; letter-spacing: .2em; text-align: center; text-transform: uppercase; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: #0e0e0e; border-right: 1px solid var(--line);
  padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar .brand { font-size: 18px; margin: 4px 8px 18px; }
.sidebar .brand .logo { width: 28px; height: 28px; }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 10px 6px; font-weight: 700; }
.nav { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: #cfcfcf; }
.nav:hover { background: var(--bg-3); }
.nav.active { background: var(--bg-3); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.sidebar .spacer { flex: 1; }
.account { display: flex; align-items: center; gap: 10px; padding: 10px; border-top: 1px solid var(--line); margin-top: 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #333; display: grid; place-items: center; font-weight: 700; flex: none; }
.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 12px 28px;
  background: linear-gradient(#121212f2, #121212d9); backdrop-filter: blur(8px); border-bottom: 1px solid #ffffff0a; }
.topbar .search { max-width: 420px; }
.topbar .title { font-size: 18px; font-weight: 650; flex: 1; }
.menu-btn { display: none; }
.page { padding: 24px 28px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; flex: 1; }

/* ---------- media ---------- */
.shelf { margin-bottom: 34px; }
.shelf h2 { font-size: 18px; margin-bottom: 12px; display: flex; align-items: baseline; gap: 10px; }
.row { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; }
.row::-webkit-scrollbar { height: 8px; } .row::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 18px; }
.card { width: 150px; flex: none; cursor: pointer; scroll-snap-align: start; }
.grid .card { width: auto; }
.poster { position: relative; aspect-ratio: 2/3; border-radius: var(--radius); overflow: hidden; background: var(--bg-3); }
.poster img, .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster .ph { position: absolute; inset: 0; display: grid; place-items: center; padding: 10px; text-align: center; font-weight: 600; color: var(--muted); }
.card:hover .poster, .card:hover .thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.card .t { margin-top: 7px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wide { width: 280px; }
.thumb { position: relative; aspect-ratio: 16/9; border-radius: var(--radius); overflow: hidden; background: var(--bg-3); }
.bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: #000a; }
.bar i { display: block; height: 100%; background: var(--accent); }
.badge { position: absolute; top: 6px; right: 6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--accent);
  color: #111; font-weight: 700; font-size: 12px; display: grid; place-items: center; }
.watched { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; }
.watched::after { content: ""; width: 8px; height: 4px; border-left: 2px solid #111; border-bottom: 2px solid #111; transform: rotate(-45deg) translate(1px, -1px); }

/* ---------- detail ---------- */
.hero { position: relative; min-height: 460px; display: flex; align-items: flex-end; margin: -24px -28px 24px; padding: 40px 28px 28px; overflow: hidden; }
.hero .bg { position: absolute; inset: 0; background-size: cover; background-position: center top; }
.hero .bg::after { content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, #121212 0%, #121212cc 35%, #12121233 70%), linear-gradient(0deg, #121212 0%, transparent 45%); }
.hero .content { position: relative; display: flex; gap: 28px; align-items: flex-end; max-width: 1100px; }
.hero .poster { width: 200px; flex: none; box-shadow: 0 10px 40px #000a; }
.hero .logo-img { max-width: 420px; max-height: 140px; display: block; margin-bottom: 10px; }
.hero h1 { font-size: 36px; line-height: 1.1; margin-bottom: 8px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; color: #cfcfcf; margin: 8px 0 12px; }
.pill { border: 1px solid #ffffff55; border-radius: 4px; padding: 1px 6px; font-size: 12px; font-weight: 600; }
.overview { max-width: 720px; color: #d6d6d6; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.episodes { display: grid; gap: 4px; }
.episode { display: grid; grid-template-columns: 220px 1fr; gap: 16px; padding: 8px; border-radius: 8px; cursor: pointer; }
.episode:hover { background: var(--bg-2); }
.episode .thumb { width: 220px; }
.episode .play-ov { position: absolute; inset: 0; display: none; place-items: center; background: #0006; }
.episode:hover .play-ov { display: grid; }
.play-ov span { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; }
.play-ov span::after { content: ""; border-left: 14px solid #111; border-top: 9px solid transparent; border-bottom: 9px solid transparent; margin-left: 4px; }
.files { margin-top: 30px; display: grid; gap: 8px; }
.file { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.file code { font-size: 12px; word-break: break-all; }

/* ---------- tables & panels ---------- */
.panel { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.panel h2 { font-size: 16px; margin-bottom: 12px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.s-ready { color: var(--ok); } .s-resolving, .s-replacing { color: #60a5fa; } .s-unplayable { color: var(--accent); } .s-failed { color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 18px; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: #000b; display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: 100%; max-width: 520px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 22px; max-height: 90vh; overflow: auto; }
.modal h2 { margin-bottom: 16px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- player ---------- */
.player { position: fixed; inset: 0; z-index: 100; background: #000; }
.player video { width: 100%; height: 100%; background: #000; }
.player .top { position: absolute; inset: 0 0 auto 0; display: flex; align-items: flex-start; gap: 14px; padding: 18px 22px 40px;
  background: linear-gradient(#000c, transparent); transition: opacity .25s; }
.player.idle .top { opacity: 0; pointer-events: none; }
.player .top .ttl { flex: 1; }
.player .top h2 { font-size: 18px; }
.player .wait { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; gap: 12px; }
.player .wait > div { display: grid; gap: 12px; justify-items: center; }
.player select { width: auto; padding: 6px 8px; background: #000a; }
.upnext { position: absolute; right: 30px; bottom: 90px; background: #1a1a1aee; border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; gap: 12px; align-items: center; max-width: 420px; }
.upnext .thumb { width: 150px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #2a2a2a; border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; z-index: 200; box-shadow: 0 8px 30px #0008; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; left: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .shell.open .sidebar { transform: none; }
  .menu-btn { display: inline-flex; }
  .page { padding: 16px; } .topbar { padding: 10px 16px; }
  .hero { margin: -16px -16px 20px; padding: 30px 16px 20px; min-height: 380px; }
  .hero .poster { display: none; }
  .hero h1 { font-size: 28px; }
  .episode { grid-template-columns: 130px 1fr; } .episode .thumb { width: 130px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 16px 12px; }
  .card { width: 120px; } .wide { width: 230px; }
  .kv { grid-template-columns: 1fr; }
}
