:root {
  --bg: #0b0b0f;
  --bg-raised: #15151c;
  --bg-hover: #1e1e28;
  --line: rgba(255, 255, 255, .08);
  --text: #ececf1;
  --text-2: #a0a0ad;
  --text-3: #6b6b78;
  --accent: #e5a00d;
  --accent-hover: #f5b21e;
  --danger: #f87171;
  --radius: 10px;
  --gutter: clamp(16px, 4vw, 48px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { background: var(--bg); }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; min-height: 100vh; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ============================================================
   Buttons
   ============================================================ */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 20px; border-radius: 8px; font-weight: 600; font-size: .95rem; white-space: nowrap; transition: background .15s, transform .1s; }
.btn:active { transform: scale(.97); }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); color: #111; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: rgba(255, 255, 255, .1); color: var(--text); backdrop-filter: blur(8px); }
.btn-ghost:hover { background: rgba(255, 255, 255, .18); }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--text); transition: background .15s; }
.icon-btn:hover { background: rgba(255, 255, 255, .12); }
.icon-btn svg { width: 22px; height: 22px; }

/* ============================================================
   Top bar
   ============================================================ */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; height: 64px; padding: 0 var(--gutter); background: linear-gradient(to bottom, rgba(11, 11, 15, .95), rgba(11, 11, 15, .8)); backdrop-filter: blur(16px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; flex-shrink: 0; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; color: #111; }
.brand-mark svg { width: 16px; height: 16px; }
.nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 7px 12px; border-radius: 7px; color: var(--text-2); font-size: .92rem; font-weight: 500; white-space: nowrap; transition: color .15s, background .15s; }
.nav a:hover { color: var(--text); }
.nav a.on { color: var(--text); background: rgba(255, 255, 255, .08); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.search input { width: 220px; height: 36px; padding: 0 12px 0 34px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, .05); transition: width .2s, border-color .15s, background .15s; }
.search input:focus { outline: none; border-color: rgba(229, 160, 13, .6); background: rgba(255, 255, 255, .08); width: 280px; }
.avatar-btn { width: 34px; height: 34px; border-radius: 50%; overflow: hidden; background: var(--bg-hover); display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex-shrink: 0; }
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

/* Dropdown menus */
.menu { position: absolute; z-index: 40; min-width: 240px; padding: 6px; border-radius: 12px; background: #1b1b24; border: 1px solid var(--line); box-shadow: 0 16px 48px rgba(0, 0, 0, .5); }
.menu-label { padding: 8px 10px 4px; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 7px; text-align: left; font-size: .9rem; }
.menu-item:hover { background: rgba(255, 255, 255, .07); }
.menu-item .check { margin-left: auto; color: var(--accent); width: 16px; height: 16px; }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu-user { padding: 10px; }
.menu-user b { display: block; }
.menu-user span { color: var(--text-3); font-size: .82rem; }

/* ============================================================
   Views
   ============================================================ */
main { padding-bottom: 64px; }
.page { padding: 28px var(--gutter) 0; }
.page-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; }
.page-head .count { color: var(--text-3); font-size: .9rem; }
.page-head .filter { margin-left: auto; height: 36px; width: min(260px, 100%); padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, .05); }
.page-head .filter:focus { outline: none; border-color: rgba(229, 160, 13, .6); }

.row { margin-bottom: 36px; }
.row h2 { font-size: 1.15rem; font-weight: 650; margin: 0 var(--gutter) 12px; letter-spacing: -.01em; }
.rail { display: grid; grid-auto-flow: column; grid-auto-columns: 168px; gap: 14px; overflow-x: auto; padding: 4px var(--gutter) 12px; scroll-snap-type: x proximity; scroll-padding: 0 var(--gutter); scrollbar-width: none; }
.rail::-webkit-scrollbar { display: none; }
.rail.wide { grid-auto-columns: 300px; }
.rail > * { scroll-snap-align: start; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 24px 16px; }

/* Cards */
.card { display: block; min-width: 0; text-align: left; width: 100%; }
.card .art { position: relative; aspect-ratio: 2 / 3; border-radius: var(--radius); overflow: hidden; background: var(--bg-raised); box-shadow: 0 2px 10px rgba(0, 0, 0, .3); transition: transform .2s ease, box-shadow .2s ease; }
.card.wide .art { aspect-ratio: 16 / 9; }
.card .art img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .3s; }
.card .art img.ok { opacity: 1; }
.card .art .ph { position: absolute; inset: 0; display: grid; place-items: center; padding: 12px; text-align: center; color: var(--text-3); font-size: .85rem; }
.card .art::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06); pointer-events: none; }
.card .hover { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .35); opacity: 0; transition: opacity .2s; }
.card .hover span { width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #111; display: grid; place-items: center; transform: scale(.85); transition: transform .2s; }
.card .hover svg { width: 22px; height: 22px; margin-left: 2px; }
.card:hover .art { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(0, 0, 0, .5); }
.card:hover .hover { opacity: 1; }
.card:hover .hover span { transform: scale(1); }
.card .badge { position: absolute; top: 8px; right: 8px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: #111; font-size: .72rem; font-weight: 700; display: grid; place-items: center; }
.card .t { margin-top: 8px; font-size: .9rem; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .s { font-size: .8rem; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prog { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0, 0, 0, .55); }
.prog i { display: block; height: 100%; background: var(--accent); }

.more { display: flex; justify-content: center; margin-top: 28px; }
.empty { color: var(--text-3); text-align: center; padding: 64px 16px; }

/* Skeleton loading */
.skel { background: linear-gradient(90deg, var(--bg-raised) 0%, var(--bg-hover) 50%, var(--bg-raised) 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; border-radius: var(--radius); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ============================================================
   Detail
   ============================================================ */
.hero { position: relative; min-height: 520px; display: flex; align-items: flex-end; padding: 120px var(--gutter) 40px; overflow: hidden; }
.hero-bg { position: absolute; inset: 0; background-size: cover; background-position: center 20%; opacity: 0; transition: opacity .5s; }
.hero-bg.ok { opacity: 1; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, var(--bg) 2%, rgba(11, 11, 15, .75) 40%, rgba(11, 11, 15, .25) 100%), linear-gradient(to right, rgba(11, 11, 15, .9) 0%, rgba(11, 11, 15, 0) 70%); }
.hero-inner { position: relative; z-index: 1; display: flex; gap: 32px; align-items: flex-end; max-width: 1100px; }
.hero-poster { width: 210px; flex-shrink: 0; aspect-ratio: 2 / 3; border-radius: 12px; overflow: hidden; background: var(--bg-raised); box-shadow: 0 20px 50px rgba(0, 0, 0, .6); }
.hero-poster img { width: 100%; height: 100%; object-fit: cover; }
.hero-poster.wide { width: 340px; aspect-ratio: 16 / 9; }
.eyebrow { color: var(--accent); font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.eyebrow a:hover { text-decoration: underline; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 3rem); font-weight: 750; letter-spacing: -.025em; line-height: 1.08; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 12px; color: var(--text-2); font-size: .92rem; }
.meta .pill { padding: 1px 7px; border: 1px solid rgba(255, 255, 255, .25); border-radius: 4px; font-size: .78rem; font-weight: 600; }
.tagline { margin-top: 14px; font-style: italic; color: var(--text-2); }
.summary { margin-top: 12px; max-width: 680px; color: #cfcfd8; line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.summary.open { -webkit-line-clamp: unset; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 22px; }
.resume-note { color: var(--text-2); font-size: .85rem; }

.seasons { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.season-pill { padding: 7px 14px; border-radius: 18px; background: var(--bg-raised); border: 1px solid var(--line); font-size: .88rem; font-weight: 550; transition: background .15s; }
.season-pill:hover { background: var(--bg-hover); }
.season-pill.on { background: var(--text); color: #111; border-color: var(--text); }

.episodes { display: flex; flex-direction: column; gap: 4px; max-width: 1100px; }
.ep { display: grid; grid-template-columns: 220px 1fr auto; gap: 18px; align-items: center; padding: 10px; border-radius: 12px; text-align: left; width: 100%; transition: background .15s; }
.ep:hover { background: var(--bg-raised); }
.ep .art { position: relative; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: var(--bg-raised); }
.ep .art img { width: 100%; height: 100%; object-fit: cover; }
.ep .art .hover { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .35); opacity: 0; transition: opacity .2s; }
.ep:hover .art .hover { opacity: 1; }
.ep .art .hover svg { width: 34px; height: 34px; color: #fff; }
.ep h3 { font-size: .98rem; font-weight: 600; }
.ep h3 .n { color: var(--text-3); font-weight: 500; margin-right: 6px; }
.ep p { color: var(--text-2); font-size: .86rem; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ep .dur { color: var(--text-3); font-size: .85rem; white-space: nowrap; }
.ep .watched { color: var(--accent); }

/* ============================================================
   Sign in
   ============================================================ */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 20% 0%, rgba(229, 160, 13, .14), transparent 60%), radial-gradient(900px 500px at 100% 100%, rgba(80, 90, 255, .1), transparent 60%), var(--bg); }
.signin-card { width: min(420px, 100%); text-align: center; }
.signin-card .brand-mark { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 22px; }
.signin-card .brand-mark svg { width: 32px; height: 32px; }
.signin-card h1 { font-size: 1.9rem; font-weight: 750; letter-spacing: -.02em; }
.signin-card p { color: var(--text-2); margin: 10px 0 28px; }
.signin-card .btn { height: 48px; padding: 0 28px; font-size: 1rem; }
.signin-card .err { color: var(--danger); margin-top: 18px; font-size: .9rem; }
.signin-card .wait { color: var(--text-2); margin-top: 18px; font-size: .9rem; }
.signin-foot { margin-top: 40px; font-size: .8rem; color: var(--text-3); }
.signin-foot a { color: var(--text-2); }

/* ============================================================
   Player
   ============================================================ */
.player { position: fixed; inset: 0; z-index: 100; background: #000; user-select: none; }
.player .screen { position: absolute; inset: 0; display: grid; place-items: center; }
.player .screen canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.player.idle { cursor: none; }
.player .chrome { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; opacity: 1; transition: opacity .35s; pointer-events: none; }
.player.idle .chrome { opacity: 0; }
.player .chrome > * { pointer-events: auto; }
.p-top { display: flex; align-items: center; gap: 14px; padding: 18px 24px 60px; background: linear-gradient(to bottom, rgba(0, 0, 0, .75), transparent); }
.p-top .titles { min-width: 0; }
.p-top .titles b { display: block; font-size: 1.05rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-top .titles span { color: var(--text-2); font-size: .85rem; }
.p-bottom { padding: 60px 24px 16px; background: linear-gradient(to top, rgba(0, 0, 0, .85), transparent); }
.p-center { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .15); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.big-play { width: 84px; height: 84px; border-radius: 50%; background: rgba(0, 0, 0, .55); backdrop-filter: blur(6px); display: grid; place-items: center; pointer-events: auto; transition: transform .15s, background .15s; }
.big-play:hover { transform: scale(1.06); background: rgba(229, 160, 13, .9); color: #111; }
.big-play svg { width: 38px; height: 38px; margin-left: 4px; }
.p-msg { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); padding: 10px 16px; border-radius: 8px; background: rgba(20, 20, 26, .92); font-size: .9rem; max-width: min(560px, 90vw); text-align: center; pointer-events: none; }
.p-msg.err { color: var(--danger); }

.seek { position: relative; height: 18px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.seek-track { position: relative; width: 100%; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .22); transition: height .15s; }
.seek:hover .seek-track, .seek.drag .seek-track { height: 6px; }
.seek-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: inherit; background: var(--accent); }
.seek-knob { position: absolute; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; background: var(--accent); transform: scale(0); transition: transform .15s; }
.seek:hover .seek-knob, .seek.drag .seek-knob { transform: scale(1); }
.seek-tip { position: absolute; bottom: 22px; padding: 3px 7px; border-radius: 5px; background: rgba(20, 20, 26, .95); font-size: .78rem; font-variant-numeric: tabular-nums; transform: translateX(-50%); pointer-events: none; opacity: 0; transition: opacity .1s; }
.seek:hover .seek-tip, .seek.drag .seek-tip { opacity: 1; }
.p-controls { display: flex; align-items: center; gap: 4px; margin-top: 8px; }
.p-time { font-size: .88rem; font-variant-numeric: tabular-nums; color: var(--text-2); margin-left: 10px; }
.p-time b { color: var(--text); font-weight: 500; }
.p-spacer { flex: 1; }
.vol { display: flex; align-items: center; }
.vol input { width: 0; opacity: 0; transition: width .2s, opacity .2s; accent-color: var(--accent); }
.vol:hover input, .vol input:focus { width: 90px; opacity: 1; margin: 0 6px; }
.p-stats { font-size: .78rem; color: var(--text-3); font-variant-numeric: tabular-nums; margin-right: 8px; }
.p-settings { position: relative; }
.p-settings .menu { bottom: 50px; right: 0; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; padding: 12px 18px; border-radius: 10px; background: #23232d; border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, .5); font-size: .9rem; max-width: min(520px, calc(100vw - 32px)); }
.toast.err { border-color: rgba(248, 113, 113, .4); color: var(--danger); }

/* ============================================================
   Small screens
   ============================================================ */
@media (max-width: 760px) {
  .topbar { gap: 12px; height: auto; min-height: 56px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .brand span { display: none; }
  .nav { order: 3; width: 100%; }
  .search input, .search input:focus { width: 150px; }
  .rail { grid-auto-columns: 130px; }
  .rail.wide { grid-auto-columns: 240px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 18px 12px; }
  .hero { min-height: 0; padding-top: 140px; }
  .hero-inner { flex-direction: column; align-items: flex-start; gap: 18px; }
  .hero-poster { width: 130px; }
  .hero-poster.wide { width: 100%; max-width: 360px; }
  .ep { grid-template-columns: 130px 1fr; gap: 12px; }
  .ep .dur { display: none; }
  .p-top { padding: 12px 12px 40px; }
  .p-bottom { padding: 40px 12px 10px; }
  .p-stats, .vol input { display: none; }
}

/* Jellyfin sign-in */
.pw-form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; width: 100%; }
.pw-form input { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.14); color: inherit; border-radius: 10px; padding: 12px 14px; font: inherit; font-size: 16px; }
.qc-code { font-size: 44px; font-weight: 800; letter-spacing: .18em; margin: 6px 0 8px; font-variant-numeric: tabular-nums; }
