:root {
  --bg: #05080c;
  --bg2: #0a1017;
  --panel: #0e1620;
  --line: #17222e;
  --txt: #e7f1f7;
  --dim: #7c8fa0;
  --teal: #2bf5c4;
  --blue: #1ea0ff;
  --grad: linear-gradient(135deg, #2bf5c4, #1ea0ff);
  --nav-h: 62px;
  --top-h: 58px;
  --sn-w: 232px;
  --cat-w: 268px;
}

/**
 * The hidden attribute must win over component display rules. Without this,
 * any author rule setting display (.player uses flex) silently defeats the
 * UA stylesheet's [hidden] { display: none } and the element stays visible.
 */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--txt);
  font-family: 'Sora', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body::before {
  content: '';
  /* z-index -1 keeps this behind content WITHOUT forcing .app to create a
     stacking context. A positive z-index on .app would trap every descendant
     (drawer, topbar, tabbar) at that one level, and anything appended to
     <body> outside it would paint over the lot. */
  position: fixed; inset: 0; pointer-events: none; z-index: -1;
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(43,245,196,.09), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(30,160,255,.09), transparent 60%);
}
button, input { font-family: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #1c2937; border-radius: 8px; }

.brand {
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  letter-spacing: .14em;
  font-size: 15px;
  white-space: nowrap;
}
.brand span {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ------------------------------------------------------------- gate */
.is-gate { display: grid; place-items: center; min-height: 100dvh; }
.gate { width: 100%; padding: 24px; }
.gate-card {
  max-width: 380px; margin: 0 auto; text-align: center;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 24px;
}
.gate-brand { font-family: 'Space Mono', monospace; font-weight: 700; letter-spacing: .18em; font-size: 22px; }
.gate-brand span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.gate-sub { color: var(--dim); font-size: 13px; margin: 8px 0 22px; }
.gate input {
  width: 100%; padding: 14px 16px; border-radius: 12px; text-align: center;
  background: #060b11; border: 1px solid var(--line); font-size: 20px;
  font-family: 'Space Mono', monospace; letter-spacing: .3em; outline: none;
}
.gate input:focus { border-color: var(--teal); }
.gate button {
  width: 100%; margin-top: 14px; padding: 14px; border-radius: 12px;
  background: var(--grad); color: #04121a; font-weight: 700; font-size: 15px;
}
.gate input[type="url"],
.gate input[type="text"],
.gate input[type="password"]:not(#pin) {
  text-align: left; font-family: 'Sora', sans-serif;
  font-size: 15px; letter-spacing: normal; margin-top: 10px;
}
.gate-portal { display: grid; }
.gate button[disabled] { opacity: .6; }
.gate-alt {
  width: 100%; margin-top: 10px; padding: 11px; border-radius: 12px;
  background: transparent; border: 1px solid var(--line);
  color: var(--dim); font-size: 13px;
}
.gate-alt:hover { color: var(--teal); border-color: rgba(43,245,196,.4); }
.gate-err { color: #ff6b81; font-size: 13px; min-height: 18px; margin-top: 12px; }
.gate-step[hidden] { display: none !important; }
.gate-div {
  font-family: 'Space Mono', monospace; font-size: 10px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--dim);
  margin: 18px 0 2px; padding-top: 14px; border-top: 1px solid var(--line);
  text-align: left;
}
.gate-recent { margin-top: 6px; }
.gate-recent-t {
  font-family: 'Space Mono', monospace; font-size: 10px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--dim); margin-bottom: 8px;
}
.gate-chip {
  display: inline-block; margin: 0 6px 6px 0; padding: 6px 12px;
  border-radius: 999px; border: 1px solid var(--line);
  background: #060b11; color: var(--dim); font-size: 12px;
}
.gate-chip:hover { color: var(--teal); border-color: rgba(43,245,196,.4); }

/* -------------------------------------------------------------- app */
.app { min-height: 100dvh; }
.sidenav { display: none; }

.main { display: flex; flex-direction: column; min-height: 100dvh; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--top-h); flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px; padding-top: env(safe-area-inset-top);
  background: rgba(5,8,12,.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.iconbtn {
  width: 38px; height: 38px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center; color: var(--dim);
  border: 1px solid var(--line); background: var(--panel);
}
.iconbtn:hover { color: var(--teal); }
.searchwrap { position: relative; flex: 1 1 auto; min-width: 0; }
.searchwrap i {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--dim); font-size: 13px;
}
.searchwrap input {
  width: 100%; padding: 10px 12px 10px 34px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 14px; outline: none;
}
.searchwrap input:focus { border-color: var(--blue); }

.body { flex: 1 1 auto; display: block; min-height: 0; }

/* categories: off-canvas on mobile */
.catcol {
  position: fixed; z-index: 60; inset: 0 auto 0 0;
  width: min(84vw, 320px);
  background: var(--bg2); border-right: 1px solid var(--line);
  transform: translateX(-102%); transition: transform .22s ease;
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.catcol.open { transform: none; }
.catcol-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 10px;
  font-family: 'Space Mono', monospace; font-size: 11px;
  letter-spacing: .16em; text-transform: uppercase; color: var(--dim);
}
.catlist { overflow-y: auto; padding: 0 10px 24px; flex: 1 1 auto; }
.catitem {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  width: 100%; text-align: left; padding: 11px 12px; border-radius: 10px;
  font-size: 13.5px; color: var(--dim); line-height: 1.25;
}
.catitem:hover { background: #101b26; color: var(--txt); }
.catitem.active { background: rgba(43,245,196,.1); color: var(--teal); }
.scrim {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6);
  backdrop-filter: blur(2px);
}

.content { padding: 14px 12px calc(var(--nav-h) + 28px); }
.contenthead { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.contenthead h1 { font-size: 19px; margin: 0; font-weight: 600; }
.count { font-family: 'Space Mono', monospace; font-size: 11px; color: var(--dim); }

.grid { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.posters { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden; text-align: left;
  display: flex; flex-direction: column; position: relative;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: rgba(43,245,196,.45); transform: translateY(-2px); }
.card .thumb {
  aspect-ratio: 16 / 9; background: #060b11;
  display: grid; place-items: center; overflow: hidden;
}
.grid.posters .card .thumb { aspect-ratio: 2 / 3; }
.card .thumb img { width: 100%; height: 100%; object-fit: contain; }
.grid.posters .card .thumb img { object-fit: cover; }
.card .cap { padding: 8px 9px 10px; }
.card .nm {
  font-size: 12.5px; line-height: 1.3; font-weight: 500;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .sub { font-family: 'Space Mono', monospace; font-size: 10px; color: var(--dim); margin-top: 4px; }
.card .fav {
  position: absolute; top: 6px; right: 6px; width: 30px; height: 30px;
  border-radius: 8px; background: rgba(4,8,12,.72); color: var(--dim);
  display: grid; place-items: center; font-size: 12px;
}
.card .fav.on { color: var(--teal); }

.empty { text-align: center; color: var(--dim); padding: 60px 20px; font-size: 14px; }
.skel { background: var(--panel); border-radius: 12px; aspect-ratio: 16/9; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: .45 } 50% { opacity: .85 } }

/* tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(8,12,18,.94); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--dim); font-size: 10px; letter-spacing: .02em;
}
.tabbtn i { font-size: 17px; }
.tabbtn.active { color: var(--teal); }

/* -------------------------------------------------------- settings */
.settings { display: grid; gap: 12px; max-width: 760px; }
.setrow {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; display: flex; justify-content: space-between;
  align-items: center; gap: 14px; font-size: 14px;
}
.setrow small { display: block; color: var(--dim); font-size: 12px; margin-top: 3px; }
.setrow .val { font-family: 'Space Mono', monospace; font-size: 12px; color: var(--teal); text-align: right; }
.btn {
  padding: 9px 14px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: var(--grad); color: #04121a; white-space: nowrap;
}
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--txt); }

.advanced { margin-top: 4px; }
.advanced > summary {
  cursor: pointer; list-style: none; padding: 12px 4px;
  font-family: 'Space Mono', monospace; font-size: 10.5px;
  letter-spacing: .16em; text-transform: uppercase; color: #4d5e6d;
}
.advanced > summary::-webkit-details-marker { display: none; }
.advanced > summary::before { content: '+ '; }
.advanced[open] > summary::before { content: '- '; }
.advanced > summary:hover { color: var(--dim); }

.shufbtn {
  font-family: 'Space Mono', monospace; font-size: 10.5px; letter-spacing: .06em;
  color: var(--teal); border: 1px solid rgba(43,245,196,.35);
  border-radius: 999px; padding: 3px 11px; background: transparent;
}
.shufbtn:hover { background: rgba(43,245,196,.1); }

.xhint { color: var(--dim); font-size: 12px; line-height: 1.5; margin: -2px 2px 4px; }

.fld {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  background: #060b11; border: 1px solid var(--line);
  color: var(--txt); font-size: 15px; outline: none;
}
.fld:focus { border-color: var(--teal); }
.btn.sm { padding: 6px 11px; font-size: 12px; }
.userlist { margin-top: 14px; display: grid; gap: 8px; }
.userrow {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: #0a121a; border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 13px; font-size: 13.5px;
}
.userrow small { display: block; color: var(--dim); font-size: 11.5px; margin-top: 3px; }
.userat { display: flex; gap: 6px; flex-shrink: 0; }
.tagadmin {
  font-family: 'Space Mono', monospace; font-size: 9.5px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--teal);
  border: 1px solid rgba(43,245,196,.35); border-radius: 999px; padding: 1px 7px;
  margin-left: 6px; vertical-align: middle;
}
@media (max-width: 520px) {
  .userrow { flex-direction: column; align-items: stretch; }
  .userat { justify-content: flex-end; }
}

/* ---------------------------------------------------------- player */
.player {
  position: fixed; inset: 0; z-index: 100; background: #000;
  display: flex; flex-direction: column;
}
.player-stage { position: relative; background: #000; flex: 0 0 auto; }
.player-stage video { width: 100%; aspect-ratio: 16/9; display: block; background: #000; }
.player-overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0,0,0,.45); pointer-events: none;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(43,245,196,.25); border-top-color: var(--teal);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }
.player-close {
  position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 8px;
  width: 38px; height: 38px; border-radius: 10px;
  background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center;
}
.player-info { flex: 1 1 auto; overflow-y: auto; padding: 14px 14px 40px; background: var(--bg); }
.pi-head { display: flex; flex-direction: column; gap: 10px; }
.pi-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.pi-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  padding: 8px 12px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--dim);
}
.pill.on { color: var(--teal); border-color: rgba(43,245,196,.45); }
.pi-meta { margin-top: 14px; font-size: 13px; color: var(--dim); line-height: 1.55; }
.epgrow { border-left: 2px solid var(--line); padding: 6px 0 6px 10px; margin-bottom: 8px; }
.epgrow.now { border-color: var(--teal); color: var(--txt); }
.epgrow b { display: block; font-weight: 600; font-size: 13px; }
.epgrow span { font-family: 'Space Mono', monospace; font-size: 11px; }

.episodes { margin-top: 18px; display: grid; gap: 8px; }
.seasonsel { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.ep {
  display: flex; gap: 10px; align-items: center; text-align: left;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font-size: 13px; width: 100%;
}
.ep .n { font-family: 'Space Mono', monospace; color: var(--teal); font-size: 12px; min-width: 30px; }

/* ----------------------------------------------------------- sheet */
/* Above .player (100): the sheet is launched from inside the player, so a
   lower z-index hides it behind a fullscreen black overlay and the button
   appears to do nothing. */
.sheet { position: fixed; inset: 0; z-index: 150; background: rgba(3,6,10,.94); overflow-y: auto; }
.sheet-inner { max-width: 900px; margin: 0 auto; padding: 20px 16px 60px; position: relative; }
.sheet-close {
  position: sticky; top: 10px; float: right; width: 38px; height: 38px;
  border-radius: 10px; background: var(--panel); border: 1px solid var(--line); color: var(--txt);
}
.detail-top { display: grid; gap: 14px; }
.detail-top img { width: 140px; border-radius: 12px; border: 1px solid var(--line); }
.detail-top h2 { margin: 0 0 6px; font-size: 20px; }
.detail-top p { color: var(--dim); font-size: 13.5px; line-height: 1.6; margin: 8px 0 0; }

/* ----------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 20px); z-index: 200;
  background: #101b26; border: 1px solid var(--line); color: var(--txt);
  padding: 10px 16px; border-radius: 999px; font-size: 13px;
}

.only-mobile { display: inline-flex; }

/* ======================================================= breakpoints */
@media (min-width: 480px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.posters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 768px) {
  .content { padding: 18px 20px calc(var(--nav-h) + 30px); }
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
  .grid.posters { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .contenthead h1 { font-size: 22px; }
  .player { flex-direction: row; }
  .player-stage { flex: 1 1 62%; display: grid; place-items: center; }
  .player-stage video { aspect-ratio: 16/9; max-height: 100dvh; }
  .player-info { flex: 1 1 38%; max-width: 460px; border-left: 1px solid var(--line); }
  .detail-top { grid-template-columns: 180px 1fr; align-items: start; }
  .detail-top img { width: 100%; }
}

@media (min-width: 1024px) {
  .app { display: grid; grid-template-columns: var(--sn-w) 1fr; }
  .tabbar { display: none; }
  .only-mobile { display: none !important; }

  .sidenav {
    display: flex; flex-direction: column; gap: 6px;
    padding: 20px 14px; border-right: 1px solid var(--line);
    background: var(--bg2); position: sticky; top: 0; height: 100dvh;
  }
  .sidenav .brand { font-size: 17px; padding: 4px 10px 18px; }
  .navlist { display: grid; gap: 4px; }
  .navbtn {
    display: flex; align-items: center; gap: 12px; width: 100%;
    padding: 11px 12px; border-radius: 10px; color: var(--dim); font-size: 14px;
  }
  .navbtn i { width: 18px; text-align: center; }
  .navbtn:hover { background: #101b26; color: var(--txt); }
  .navbtn.active { background: rgba(43,245,196,.1); color: var(--teal); }
  .sidefoot {
    margin-top: auto; font-family: 'Space Mono', monospace;
    font-size: 10.5px; color: var(--dim); line-height: 1.7; padding: 12px 10px 0;
    border-top: 1px solid var(--line);
  }

  .body { display: grid; grid-template-columns: var(--cat-w) 1fr; align-items: start; }
  .catcol {
    position: sticky; top: var(--top-h); transform: none; width: auto;
    height: calc(100dvh - var(--top-h)); border-right: 1px solid var(--line);
    inset: auto;
  }
  .scrim { display: none; }
  .content { padding: 22px 26px 60px; }
  .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .grid.posters { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .toast { bottom: 26px; }
}

@media (min-width: 1440px) {
  .grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .grid.posters { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .content { padding: 26px 34px 70px; }
}

@media (min-width: 1920px) {
  .grid { grid-template-columns: repeat(9, minmax(0, 1fr)); }
  .grid.posters { grid-template-columns: repeat(10, minmax(0, 1fr)); }
}
