:root {
  --bg: #0f0f14;
  --bg-2: #17171f;
  --bg-3: #20202b;
  --line: #2a2a37;
  --text: #ecebf3;
  --muted: #9a99ab;
  --accent: #ff6b6b;
  --accent-2: #ffb36b;
  --ok: #5ad19a;
  --radius: 12px;
  --side: 340px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
input { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
svg { fill: currentColor; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg-3); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #444457; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; color: #1a0f0f; font-weight: 600; }
.btn.lg { padding: 12px 24px; font-size: 16px; }
.icon-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border: 0; background: transparent; border-radius: 10px; cursor: pointer; flex: none; }
.icon-btn:hover { background: rgba(255,255,255,.08); }
.icon-btn svg { width: 22px; height: 22px; }
.chip { border: 1px solid rgba(255,255,255,.18); background: rgba(0,0,0,.25); border-radius: 999px; padding: 4px 11px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip:hover { background: rgba(255,255,255,.1); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; letter-spacing: .5px; white-space: nowrap; }
.brand.big { font-size: 28px; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 0 12px var(--accent); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 20% 0%, #2a1620, transparent), radial-gradient(900px 500px at 100% 100%, #1d1a2e, transparent), var(--bg); }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; border-radius: 20px; background: rgba(23,23,31,.85); border: 1px solid var(--line); }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input, .chat-form input { padding: 11px 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); outline: none; }
.login-card input:focus, .chat-form input:focus { border-color: var(--accent); }
.error { color: var(--accent); min-height: 1.5em; margin: 0; font-size: 14px; }

/* topbar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 10px 20px; padding-top: max(10px, env(safe-area-inset-top)); background: rgba(15,15,20,.86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid rgba(255,255,255,.05); }
.search { flex: 1; max-width: 520px; display: flex; align-items: center; gap: 8px; padding: 0 12px; height: 38px; border-radius: 999px; background: var(--bg-3); border: 1px solid transparent; }
.search:focus-within { border-color: var(--line); }
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); }
.room-pill { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px; background: var(--bg-3); font-size: 14px; white-space: nowrap; }
.room-pill.live { background: linear-gradient(135deg, rgba(255,107,107,.25), rgba(255,179,107,.25)); }
.dots { display: inline-flex; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); margin-right: -2px; border: 2px solid var(--bg-3); }

main { padding: 18px 20px 120px; max-width: 1500px; margin: 0 auto; }
h1, h2, h3 { margin: 0; }
.section { margin: 18px 0 30px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head h2 { font-size: 19px; }
.libs { display: flex; flex-wrap: wrap; gap: 8px; }
.libs a { padding: 8px 15px; border-radius: 999px; background: var(--bg-3); border: 1px solid var(--line); font-size: 14px; }
.libs a:hover, .libs a.on { background: var(--text); color: var(--bg); }

.row { display: grid; grid-auto-flow: column; grid-auto-columns: 150px; gap: 14px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: thin; scroll-snap-type: x proximity; }
.row .card { scroll-snap-align: start; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px 14px; }
.card { display: flex; flex-direction: column; gap: 7px; min-width: 0; cursor: pointer; }
.poster { position: relative; aspect-ratio: 2/3; border-radius: 10px; overflow: hidden; background: linear-gradient(135deg, #23232e, #1a1a22); }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.card:hover .poster img { transform: scale(1.04); }
.poster .noimg { position: absolute; inset: 0; display: grid; place-items: center; padding: 10px; text-align: center; color: var(--muted); font-size: 13px; }
.badge { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.65); padding: 1px 7px; border-radius: 6px; font-size: 12px; }
.card-title { font-size: 14px; line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-meta { font-size: 12px; color: var(--muted); margin-top: -4px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 4px 0 18px; }
.toolbar h1 { font-size: 24px; margin-right: auto; }
.load-more { display: flex; justify-content: center; padding: 26px; color: var(--muted); }
.skeleton { background: linear-gradient(90deg, #1d1d26 25%, #262632 50%, #1d1d26 75%); background-size: 200% 100%; animation: sk 1.3s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* detail */
.hero { position: relative; margin: -18px -20px 0; padding: 40px 20px 26px; min-height: 360px; display: flex; gap: 26px; align-items: flex-end; overflow: hidden; }
.hero-bg { position: absolute; inset: 0; background-size: cover; background-position: center 25%; opacity: .45; filter: saturate(1.1); }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, var(--bg) 4%, rgba(15,15,20,.55) 60%, rgba(15,15,20,.3)), linear-gradient(90deg, rgba(15,15,20,.85), transparent 70%); }
.hero > *:not(.hero-bg) { position: relative; z-index: 1; }
.hero .poster { width: 200px; flex: none; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.hero-info { display: flex; flex-direction: column; gap: 10px; max-width: 760px; min-width: 0; }
.hero-info h1 { font-size: 32px; line-height: 1.2; }
.meta-line { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 14px; }
.overview { color: #cfcedb; font-size: 14.5px; max-height: 7.5em; overflow: auto; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.seasons { display: flex; gap: 8px; flex-wrap: wrap; margin: 22px 0 14px; }
.ep-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.ep { display: flex; flex-direction: column; gap: 6px; cursor: pointer; border-radius: 12px; }
.ep-thumb { position: relative; aspect-ratio: 16/9; border-radius: 10px; overflow: hidden; background: linear-gradient(135deg, #23232e, #1a1a22); }
.ep-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ep-thumb .play-ico { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; transition: opacity .2s; background: rgba(0,0,0,.35); }
.ep:hover .play-ico { opacity: 1; }
.play-ico svg { width: 46px; height: 46px; }
.ep-title { font-size: 14px; }
.ep-ov { font-size: 12.5px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.people { display: flex; flex-wrap: wrap; gap: 6px; }
.people span { font-size: 12.5px; background: var(--bg-3); padding: 3px 9px; border-radius: 999px; color: #cfcedb; }

/* room */
.room { position: fixed; inset: 0; z-index: 40; display: grid; grid-template-columns: 1fr var(--side); background: #07070a; }
.room-stage-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage { position: relative; flex: 1; min-height: 0; background: #000; display: grid; place-items: center; overflow: hidden; user-select: none; -webkit-user-select: none; }
.stage video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.stage.idle { cursor: none; }
.subs { position: absolute; left: 4%; right: 4%; bottom: 7%; text-align: center; pointer-events: none; font-size: calc(clamp(16px, 2.6vw, 40px) * var(--subscale, 1)); line-height: 1.32; font-weight: 600; color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 1px 4px #000, 1px 1px 2px #000; transition: bottom .2s; white-space: pre-line; }
.subs .cue { display: block; }
.subs .cue.top { position: absolute; top: -78vh; left: 0; right: 0; }
.stage:not(.idle) .subs { bottom: max(7%, 92px); }
.stage-msg { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.72); padding: 8px 16px; border-radius: 999px; font-size: 14px; display: flex; align-items: center; gap: 8px; max-width: 90%; text-align: center; }
.spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.tap-play { position: absolute; padding: 14px 26px; border-radius: 999px; border: 0; font-weight: 600; font-size: 16px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a0f0f; cursor: pointer; box-shadow: 0 10px 40px rgba(255,107,107,.4); }
.empty-stage { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); background: radial-gradient(600px 300px at 50% 40%, #1b1520, #000); }
.empty-icon { font-size: 44px; }

.controls { position: absolute; left: 0; right: 0; bottom: 0; padding: 30px 14px 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: linear-gradient(0deg, rgba(0,0,0,.85), rgba(0,0,0,.5) 60%, transparent); transition: opacity .25s; }
.stage.idle .controls, .stage.idle .stage-msg.soft { opacity: 0; pointer-events: none; }
.ctrl-row { display: flex; align-items: center; gap: 4px; }
.ctrl-row .spacer { flex: 1; }
.time { font-size: 13px; font-variant-numeric: tabular-nums; margin-left: 6px; white-space: nowrap; }
#volume { width: 90px; accent-color: var(--accent); }
.i-pause { display: none; }
.playing .i-pause { display: block; }
.playing .i-play { display: none; }
.seek { position: relative; height: 18px; cursor: pointer; margin: 0 2px 2px; touch-action: none; }
.seek::before, .seek-buf, .seek-fill { content: ""; position: absolute; left: 0; top: 7px; height: 4px; border-radius: 4px; }
.seek::before { right: 0; background: rgba(255,255,255,.2); }
.seek-buf { background: rgba(255,255,255,.35); width: 0; }
.seek-fill { background: linear-gradient(90deg, var(--accent), var(--accent-2)); width: 0; }
.seek-fill::after { content: ""; position: absolute; right: -6px; top: -4px; width: 12px; height: 12px; border-radius: 50%; background: #fff; transform: scale(0); transition: transform .15s; }
.seek:hover .seek-fill::after, .seek.drag .seek-fill::after { transform: scale(1); }
.seek:hover::before, .seek:hover .seek-buf, .seek:hover .seek-fill { top: 6px; height: 6px; }
.seek-peer { position: absolute; top: 2px; width: 3px; height: 14px; margin-left: -1.5px; border-radius: 2px; background: var(--ok); display: none; }
.seek-hover { position: absolute; bottom: 22px; transform: translateX(-50%); background: rgba(0,0,0,.85); padding: 2px 8px; border-radius: 6px; font-size: 12px; display: none; white-space: nowrap; }
.seek:hover .seek-hover, .seek.drag .seek-hover { display: block; }

.settings { position: absolute; right: 12px; bottom: 76px; width: min(330px, calc(100% - 24px)); max-height: calc(100% - 100px); overflow: auto; background: rgba(20,20,27,.96); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 12px; z-index: 3; }
.set-title { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.opt { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.opt:hover { background: rgba(255,255,255,.07); }
.opt.on { background: rgba(255,107,107,.18); color: #ffd0c0; }
.opt small { color: var(--muted); margin-left: 6px; }
.opt.off { opacity: .45; cursor: not-allowed; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 5px; cursor: pointer; }
.seg button.on { background: var(--text); color: var(--bg); }

.now { padding: 12px 18px; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid rgba(255,255,255,.05); }
.now-title { font-weight: 600; font-size: 16px; }
.now-sub { font-size: 13px; }

.side { display: flex; flex-direction: column; min-height: 0; background: var(--bg-2); border-left: 1px solid var(--line); }
.side-tabs { display: flex; gap: 4px; padding: 10px 10px 0; padding-top: max(10px, env(safe-area-inset-top)); }
.side-tabs button { flex: 1; padding: 8px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; color: var(--muted); }
.side-tabs button.active { background: var(--bg-3); color: var(--text); }
.members { display: flex; flex-direction: column; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.member { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #1a0f0f; flex: none; }
.member .st { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.member .st.warn { color: var(--accent-2); }
.tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { font-size: 14px; word-break: break-word; }
.msg b { font-weight: 600; margin-right: 6px; }
.msg.sys { color: var(--muted); font-size: 12.5px; text-align: center; }
.chat-form { display: flex; gap: 8px; padding: 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; }
.eps-list { overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.eps-list .opt { display: flex; gap: 10px; align-items: center; }
.eps-list img { width: 92px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; flex: none; background: var(--bg-3); }
.room-back { position: absolute; top: 10px; left: 10px; z-index: 4; background: rgba(0,0,0,.5); border-radius: 999px; padding: 6px 13px; font-size: 14px; transition: opacity .25s; }
.stage.idle .room-back { opacity: 0; }

/* mini player */
.mini-expand { display: none; }
.room.mini { inset: auto 16px 16px auto; width: 340px; height: auto; grid-template-columns: 1fr; border-radius: 14px; overflow: hidden; box-shadow: 0 18px 50px rgba(0,0,0,.6); border: 1px solid var(--line); }
.room.mini .side, .room.mini .controls, .room.mini .settings, .room.mini .room-back, .room.mini .tap-play { display: none; }
.room.mini .stage { aspect-ratio: 16/9; flex: none; }
.room.mini .now { padding: 8px 12px; }
.room.mini .now-title { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room.mini .now-sub { font-size: 12px; }
.room.mini .subs { font-size: 13px; bottom: 6%; }
.room.mini .mini-expand { display: block; position: absolute; inset: 0; border: 0; background: transparent; cursor: pointer; z-index: 5; }
.room.mini .stage-msg { font-size: 12px; top: 6px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: #2b2b38; border: 1px solid #3a3a4a; padding: 10px 18px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 100; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

:fullscreen .stage, .stage:fullscreen { width: 100vw; height: 100vh; }

@media (max-width: 900px) {
  .room { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .room-stage-wrap { flex: none; }
  .stage { flex: none; aspect-ratio: 16/9; padding-top: env(safe-area-inset-top); }
  .stage:fullscreen { aspect-ratio: auto; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .side-tabs { padding-top: 10px; }
  .now { padding: 8px 14px; }
  #volume, #btn-mute { display: none; }
}
@media (max-width: 640px) {
  .topbar { padding: 8px 16px; gap: 10px; flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  main { padding: 12px 16px 120px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 14px 10px; }
  .row { grid-auto-columns: 112px; gap: 10px; }
  .hero { margin: -12px -16px 0; padding: 24px 16px 18px; flex-direction: column; align-items: flex-start; gap: 16px; min-height: 0; }
  .hero .poster { width: 130px; }
  .hero-info h1 { font-size: 24px; }
  .ep-grid { grid-template-columns: 1fr; }
  .room.mini { width: 220px; right: 10px; bottom: 10px; }
  .controls { padding: 24px 6px 4px; }
  .ctrl-row { gap: 0; }
  .icon-btn { width: 34px; height: 34px; }
  #btn-back, #btn-fwd { display: none; }
  .time { font-size: 12px; }
  .chip { padding: 3px 8px; font-size: 12px; }
}

/* Keep throughput visible without covering playback controls or subtitles. */
.connection-speed { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; z-index: 4; padding: 4px 8px; border-radius: 6px; color: #fff; background: rgba(0,0,0,.55); font-size: 12px; font-variant-numeric: tabular-nums; pointer-events: none; }
.room.mini .connection-speed { display: none; }

#source-select { max-width: 160px; color: var(--text); background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 7px; }
@media (max-width: 640px) { #source-select { max-width: 120px; } }
