:root{
  --primary:#7c5cff; --bg:#0b0b12; --surface:#15151f; --surface2:#1e1e2b;
  --text:#e7e7f0; --muted:#8b8ba7; --radius:16px; --tabbar-h:64px;
  --safe-top:env(safe-area-inset-top,0px); --safe-bottom:env(safe-area-inset-bottom,0px);
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;height:100%;background:var(--bg);color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
  overscroll-behavior:none}
body.noscroll{overflow:hidden}
img{display:block;max-width:100%}
button{font:inherit;color:inherit;border:none;background:none;cursor:pointer}
input,select{font:inherit}
.hidden{display:none!important}

/* screens */
.screen{position:fixed;inset:0;display:none;flex-direction:column}
.screen.active{display:flex}

/* splash */
#splash{align-items:center;justify-content:center}
.splash-inner{display:flex;flex-direction:column;align-items:center;gap:24px}
.logo{width:120px;height:120px;object-fit:contain;border-radius:24px}

/* spinner */
.spinner{width:34px;height:34px;border:3px solid rgba(255,255,255,.15);
  border-top-color:var(--primary);border-radius:50%;animation:spin .8s linear infinite;margin:40px auto}
@keyframes spin{to{transform:rotate(360deg)}}

/* login */
#login{align-items:center;justify-content:center;padding:24px}
.login-card{width:100%;max-width:360px;display:flex;flex-direction:column;align-items:center;gap:16px}
.login-card h1{margin:0 0 8px;font-size:28px;font-weight:700}
.login-card form{width:100%;display:flex;flex-direction:column;gap:12px}
.login-card input{background:var(--surface);border:1px solid #2a2a3c;border-radius:12px;
  padding:15px 16px;color:var(--text);outline:none}
.login-card input:focus{border-color:var(--primary)}
.error{color:#ff6b81;font-size:14px;text-align:center;min-height:18px}

/* buttons */
.btn{background:var(--surface2);border-radius:12px;padding:14px 18px;font-weight:600;text-align:center}
.btn.primary{background:var(--primary);color:#fff}
.btn.block{width:100%}
.btn:active{transform:scale(.98)}

/* main app layout */
.topbar{display:flex;align-items:center;justify-content:space-between;
  padding:calc(var(--safe-top) + 10px) 16px 10px;background:var(--bg);position:sticky;top:0;z-index:5}
.topbar-title{font-weight:700;font-size:18px}
.icon-btn{font-size:20px;padding:8px;border-radius:10px}
.view{flex:1;overflow-y:auto;-webkit-overflow-scrolling:touch;
  padding:8px 12px calc(var(--tabbar-h) + var(--safe-bottom) + 16px)}

/* bottom tab bar */
.tabbar{position:fixed;left:0;right:0;bottom:0;height:calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom:var(--safe-bottom);display:flex;background:rgba(20,20,31,.92);
  backdrop-filter:blur(12px);border-top:1px solid #24243440;z-index:6}
.tab{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;
  gap:3px;font-size:11px;color:var(--muted)}
.tab .ti{font-size:20px;line-height:1}
.tab.active{color:var(--primary)}

/* category chips */
.chips{display:flex;gap:8px;overflow-x:auto;padding:6px 2px 12px;scrollbar-width:none}
.chips::-webkit-scrollbar{display:none}
.chip{white-space:nowrap;background:var(--surface);padding:8px 14px;border-radius:999px;
  font-size:13px;color:var(--muted)}
.chip.active{background:var(--primary);color:#fff}

/* live rows */
.row{display:flex;align-items:center;gap:12px;padding:10px 8px;border-radius:12px}
.row:active{background:var(--surface)}
.row-ico{width:46px;height:46px;border-radius:10px;overflow:hidden;background:var(--surface2);flex:none}
.row-ico img{width:100%;height:100%;object-fit:contain}
.row-main{flex:1;min-width:0}
.row-title{font-weight:600;font-size:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.row-sub{font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.fav{font-size:20px;color:#3a3a4c;padding:6px}
.fav.on{color:#ffce54}
.fav.big{position:absolute;top:12px;right:12px;font-size:26px;background:rgba(0,0,0,.4);border-radius:50%;width:44px;height:44px}

/* poster grid */
.grid{display:grid;grid-template-columns:repeat(3,1fr);gap:10px}
@media(min-width:520px){.grid{grid-template-columns:repeat(4,1fr)}}
@media(min-width:720px){.grid{grid-template-columns:repeat(6,1fr)}}
.card:active{transform:scale(.97)}
.card-img{aspect-ratio:2/3;border-radius:12px;overflow:hidden;background:var(--surface2)}
.card-img img{width:100%;height:100%;object-fit:cover}
.card-t{font-size:12px;margin-top:6px;line-height:1.3;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.sec{font-size:15px;margin:16px 2px 8px}
.empty{text-align:center;color:var(--muted);padding:40px 20px}

/* search */
.search-wrap{padding-top:6px}
.search{width:100%;background:var(--surface);border:1px solid #2a2a3c;border-radius:12px;
  padding:13px 16px;color:var(--text);outline:none;margin-bottom:8px}
.search:focus{border-color:var(--primary)}

/* bottom sheet (detail) */
.sheet{position:fixed;left:0;right:0;bottom:0;max-height:88vh;background:var(--surface);
  border-radius:22px 22px 0 0;transform:translateY(100%);transition:transform .28s ease;
  z-index:20;overflow-y:auto;padding:0 18px calc(28px + var(--safe-bottom))}
.sheet.open{transform:translateY(0)}
.sheet-grab{width:40px;height:4px;border-radius:2px;background:#3a3a4c;margin:10px auto 4px}
.sheet-close{position:absolute;top:12px;right:14px;font-size:18px;background:var(--surface2);
  border-radius:50%;width:34px;height:34px;z-index:2}
.sheet-hero{position:relative;border-radius:16px;overflow:hidden;margin-top:6px}
.sheet-hero img{width:100%;max-height:240px;object-fit:cover}
.sheet-title{margin:14px 0 4px;font-size:22px}
.sheet-meta{color:var(--muted);font-size:13px}
.sheet-actions{display:flex;gap:10px;align-items:center;margin:14px 0}
.sheet-plot{color:#c9c9dd;font-size:14px;line-height:1.5}
.select{background:var(--surface2);border-radius:10px;padding:12px 14px;color:var(--text);border:1px solid #2a2a3c}

/* episodes */
.eplist{display:flex;flex-direction:column;gap:2px;margin-top:8px}
.ep{display:flex;align-items:center;gap:12px;padding:12px 10px;border-radius:10px}
.ep:active{background:var(--surface2)}
.ep-n{width:26px;color:var(--muted);font-size:13px;text-align:center}
.ep-t{flex:1;font-size:14px}
.ep-play{color:var(--primary)}

/* player overlay */
.player{position:fixed;inset:0;background:#000;z-index:40;display:none;flex-direction:column}
.player.open{display:flex}
.player-bar{display:flex;align-items:center;gap:10px;padding:calc(var(--safe-top) + 8px) 12px 8px;
  background:linear-gradient(to bottom,rgba(0,0,0,.7),transparent);position:absolute;top:0;left:0;right:0;z-index:2}
.player-bar .icon-btn{font-size:26px;color:#fff}
.player-title{flex:1;font-size:15px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.player-stage{flex:1;display:flex;align-items:center;justify-content:center}
#video{width:100%;height:100%;background:#000}
.player-error{position:absolute;bottom:40px;left:0;right:0;text-align:center;color:#ff6b81;
  padding:12px;display:none}
.player-error.show{display:block}

/* top logo */
.top-logo{width:28px;height:28px;border-radius:7px;object-fit:contain;margin-right:10px}
.topbar{gap:2px}

/* drill-down subheader (back + category name) */
.subheader{display:none;align-items:center;gap:6px;padding:2px 8px 8px;position:sticky;top:0;background:var(--bg);z-index:4}
.subheader.show{display:flex}
.back-btn{font-size:26px;line-height:1;padding:2px 10px 6px;color:var(--primary)}
.sub-title{font-size:17px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* category list */
.catlist{display:flex;flex-direction:column;gap:2px}
.catrow{display:flex;align-items:center;justify-content:space-between;width:100%;text-align:left;
  background:var(--surface);padding:16px 16px;border-radius:12px}
.catrow:active{background:var(--surface2)}
.catrow-name{font-size:15px;font-weight:600}
.chev{color:var(--muted);font-size:22px;line-height:1}

/* item list wrapper */
.list{display:flex;flex-direction:column;gap:2px}

/* settings */
.settings{display:flex;flex-direction:column;gap:14px;padding-top:6px}
.set-card{background:var(--surface);border-radius:14px;padding:6px 14px}
.set-row{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 0;border-bottom:1px solid #24243430}
.set-row:last-child{border-bottom:none}
.set-row span{color:var(--muted);font-size:14px}
.set-row b{font-size:14px;text-align:right}
.set-row b.trunc{max-width:60%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.set-links{display:flex;gap:10px;padding:12px 0}
.set-link{flex:1;text-align:center;background:var(--surface2);border-radius:10px;padding:12px;
  color:var(--text);text-decoration:none;font-weight:600;font-size:14px}
.set-ver{text-align:center;color:var(--muted);font-size:12px;margin-top:4px}

/* episode external-open button */
.ep-ext{width:34px;height:34px;border-radius:8px;background:var(--surface2);color:var(--primary);font-size:16px;flex:none}
.ep-ext:active{opacity:.7}

/* external-player chooser dialog */
.ext-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.55);z-index:60;display:none;
  align-items:center;justify-content:center;padding:24px}
.ext-backdrop.open{display:flex}
.ext-card{width:100%;max-width:360px;background:var(--surface);border-radius:18px;padding:18px;
  display:flex;flex-direction:column;gap:10px;max-height:80vh;overflow-y:auto}
.ext-title{margin:2px 0 8px;font-size:17px}
.ext-btn{background:var(--surface2);border-radius:12px;padding:15px 16px;font-weight:600;text-align:center;font-size:15px}
.ext-btn:active{transform:scale(.98)}
.ext-btn.cancel{background:transparent;color:var(--muted)}
.ext-hint{color:var(--muted);font-size:12px;line-height:1.45;margin:6px 2px 0}
