:root {
  --bg: #090e1b;
  --surface: #111829;
  --card: #141d32;
  --stroke: rgba(255, 255, 255, 0.09);
  --text: #f4f6fb;
  --dim: rgba(255, 255, 255, 0.6);
  --accent: #2e7aff;
  --accent2: #29c7ff;
  --gold: #ffc740;
  --danger: #ff5a6a;
  --grad: linear-gradient(135deg, var(--accent2), var(--accent));
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
img { display: block; }
a { color: inherit; text-decoration: none; }

/* ---------- Shell ---------- */
.shell { max-width: 1200px; margin: 0 auto; padding: calc(var(--safe-top) + 10px) 16px calc(var(--safe-bottom) + 84px); }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.logo { font-weight: 800; font-size: 22px; letter-spacing: -0.02em; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--stroke);
  border-radius: 12px; padding: 0 12px; height: 40px; min-width: 0;
}
.search input { flex: 1; background: none; border: 0; outline: 0; min-width: 0; font-size: 16px; }
.search svg { flex: none; opacity: 0.6; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--surface); border: 1px solid var(--stroke); flex: none; }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 14px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 13px; border-radius: 999px; background: var(--surface); border: 1px solid var(--stroke);
  font-size: 13px; font-weight: 600; white-space: nowrap; color: var(--dim);
}
.chip.on { background: var(--grad); color: #fff; border-color: transparent; }
.chip .tag { font-size: 10px; opacity: 0.7; margin-left: 4px; }

.section-title { font-size: 18px; font-weight: 700; margin: 18px 0 10px; display: flex; align-items: center; justify-content: space-between; }
.section-title small { font-size: 13px; color: var(--dim); font-weight: 500; }

/* ---------- Grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 14px 10px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px 14px; } }
.card { position: relative; cursor: pointer; min-width: 0; }
.poster { position: relative; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; background: var(--card); border: 1px solid var(--stroke); }
.poster img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s; }
.card:hover .poster img { transform: scale(1.04); }
.badge { position: absolute; left: 6px; top: 6px; font-size: 10px; font-weight: 700; padding: 3px 6px; border-radius: 6px; background: rgba(0,0,0,.6); backdrop-filter: blur(6px); }
.badge.eps { left: auto; right: 6px; }
.progress-strip { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255,255,255,.2); }
.progress-strip i { display: block; height: 100%; background: var(--accent2); }
.card .t { font-size: 13px; font-weight: 600; margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .s { font-size: 11px; color: var(--dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row { display: grid; grid-auto-flow: column; grid-auto-columns: 112px; gap: 10px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.row::-webkit-scrollbar { display: none; }

.empty, .loading, .error { text-align: center; color: var(--dim); padding: 40px 10px; }
.error { color: var(--danger); }
.spinner { width: 28px; height: 28px; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent2); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.sentinel { height: 60px; display: grid; place-items: center; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around;
  padding: 8px 8px calc(var(--safe-bottom) + 8px); background: rgba(9, 14, 27, .88); backdrop-filter: blur(16px);
  border-top: 1px solid var(--stroke);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--dim); padding: 2px 18px; }
.tabbar a.on { color: var(--accent2); }

/* ---------- Detail ---------- */
.detail-hero { position: relative; margin: calc(-10px - var(--safe-top)) -16px 0; padding: calc(var(--safe-top) + 56px) 16px 16px; overflow: hidden; }
.detail-hero .bgimg { position: absolute; inset: 0; background-size: cover; background-position: center; filter: blur(30px) brightness(.45); transform: scale(1.2); }
.detail-hero .inner { position: relative; display: flex; gap: 16px; align-items: flex-end; }
.detail-hero .poster { width: 120px; flex: none; }
.detail-hero h1 { font-size: 21px; line-height: 1.2; margin: 0 0 6px; }
.detail-hero .meta { color: var(--dim); font-size: 13px; }
.back { position: absolute; top: calc(var(--safe-top) + 10px); left: 16px; z-index: 2; }
.actions { display: flex; gap: 10px; margin: 16px 0; }
.btn { height: 44px; padding: 0 18px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; background: var(--surface); border: 1px solid var(--stroke); }
.btn.primary { background: var(--grad); border: 0; flex: 1; color: #fff; }
.btn.on { color: var(--gold); }
.intro { color: rgba(255,255,255,.82); font-size: 14px; white-space: pre-line; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tags span { font-size: 11px; padding: 3px 8px; border-radius: 6px; background: var(--surface); color: var(--dim); }
.eps { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; }
.ep { height: 44px; border-radius: 10px; background: var(--surface); border: 1px solid var(--stroke); font-weight: 600; position: relative; }
.ep.watched { color: var(--dim); }
.ep.current { border-color: var(--accent2); color: var(--accent2); }
.ep.locked { opacity: .4; }

/* ---------- Library / settings ---------- */
.list-item { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--stroke); }
.list-item .poster { width: 64px; flex: none; border-radius: 8px; }
.list-item .info { flex: 1; min-width: 0; }
.list-item .info .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .info .s { font-size: 12px; color: var(--dim); }
.seg { display: flex; background: var(--surface); border-radius: 10px; padding: 3px; margin-bottom: 8px; }
.seg button { flex: 1; padding: 8px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--dim); }
.seg button.on { background: var(--card); color: var(--text); }
.setting { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--stroke); gap: 12px; }
.setting select { background: var(--surface); color: var(--text); border: 1px solid var(--stroke); border-radius: 8px; padding: 6px 8px; font: inherit; }
.text-btn { color: var(--accent2); font-weight: 600; }
.danger { color: var(--danger); }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login img { width: 84px; height: 84px; border-radius: 20px; margin: 0 auto; }
.login input { height: 48px; border-radius: 12px; border: 1px solid var(--stroke); background: var(--surface); padding: 0 14px; font-size: 16px; outline: 0; }

/* ---------- Player ---------- */
.player { position: fixed; inset: 0; z-index: 50; background: #000; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.player video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.player.fill video { object-fit: cover; }
.player .layer { position: absolute; inset: 0; transition: opacity .25s; }
.player.hide-ui .layer.ui { opacity: 0; pointer-events: none; }
.player .shade-top, .player .shade-bottom { position: absolute; left: 0; right: 0; pointer-events: none; }
.player .shade-top { top: 0; height: 140px; background: linear-gradient(rgba(0,0,0,.65), transparent); }
.player .shade-bottom { bottom: 0; height: 220px; background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.player .top { position: absolute; top: calc(var(--safe-top) + 8px); left: 8px; right: 8px; display: flex; align-items: center; gap: 8px; }
.player .top .title { flex: 1; min-width: 0; }
.player .top .title b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .top .title span { font-size: 12px; color: var(--dim); }
.pbtn { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: rgba(0,0,0,.35); backdrop-filter: blur(8px); flex: none; }
.player .bottom { position: absolute; left: 12px; right: 12px; bottom: calc(var(--safe-bottom) + 12px); }
.player .bar { position: relative; height: 22px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.player .bar .track { position: absolute; left: 0; right: 0; height: 4px; border-radius: 2px; background: rgba(255,255,255,.25); overflow: hidden; }
.player .bar .buf { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(255,255,255,.3); }
.player .bar .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent2); }
.player .bar .knob { position: absolute; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: #fff; box-shadow: 0 0 6px rgba(0,0,0,.5); }
.player .times { display: flex; justify-content: space-between; font-size: 12px; color: var(--dim); margin-top: 2px; font-variant-numeric: tabular-nums; }
.player .controls { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; gap: 6px; }
.player .controls .group { display: flex; gap: 6px; align-items: center; }
.player .pill { height: 34px; padding: 0 12px; border-radius: 17px; background: rgba(0,0,0,.35); backdrop-filter: blur(8px); font-size: 13px; font-weight: 700; }
.player .center { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; gap: 28px; align-items: center; }
.player .center .big { width: 68px; height: 68px; border-radius: 50%; background: rgba(0,0,0,.4); backdrop-filter: blur(8px); display: grid; place-items: center; }
.player .status { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; max-width: 80%; pointer-events: none; }
.player .status.err { pointer-events: auto; }
.player .status p { margin: 10px 0; color: rgba(255,255,255,.85); }
.player .toast { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); background: rgba(0,0,0,.6); padding: 8px 14px; border-radius: 10px; font-weight: 700; font-size: 14px; pointer-events: none; transition: opacity .2s; }
.player .via { position: absolute; right: 12px; top: calc(var(--safe-top) + 62px); font-size: 11px; color: var(--dim); }
.player .slide { transition: transform .25s ease; }
.menu {
  position: absolute; left: 8px; right: 8px; bottom: calc(var(--safe-bottom) + 8px); max-height: 60%; overflow: auto; z-index: 3;
  background: rgba(20, 29, 50, .96); backdrop-filter: blur(20px); border-radius: 16px; border: 1px solid var(--stroke); padding: 8px;
}
@media (min-width: 700px) { .menu { left: auto; width: 360px; } }
.menu h3 { margin: 6px 10px 8px; font-size: 14px; color: var(--dim); }
.menu button.opt { display: flex; width: 100%; justify-content: space-between; padding: 12px 10px; border-radius: 10px; font-weight: 600; }
.menu button.opt.on { color: var(--accent2); }
.menu .eps { padding: 4px; }
.player video::cue { background: rgba(0,0,0,.55); font-size: 18px; }

@media (min-width: 700px) {
  .player video { max-width: 100%; }
}
/* On wide screens keep the controls on the vertical video instead of the whole window. */
@media (min-aspect-ratio: 3/4) {
  .player .layer.ui { left: 50%; right: auto; width: min(100vw, 56.25dvh); transform: translateX(-50%); }
}

/* ---------- v2: filters, networks, sheets, accounts ---------- */
.topbar .filter-btn { position: relative; }
.topbar .filter-btn .dot { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.chips.genres { margin-top: -6px; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
.chip.icon { display: grid; place-items: center; padding: 6px 10px; }
.chip.err { border-color: rgba(255, 90, 106, .5); }
.chip .mini-spin { display: inline-block; width: 10px; height: 10px; margin-left: 6px; border: 2px solid rgba(255,255,255,.2); border-top-color: var(--accent2); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
.poster-text { position: absolute; inset: 0; display: grid; place-items: center; padding: 10px; text-align: center; font-weight: 700; font-size: 13px; background: linear-gradient(160deg, #1b2a4a, #0e1424); }
.badge.new { top: auto; bottom: 6px; background: var(--accent); }
.badge.mature { top: auto; bottom: 6px; left: auto; right: 6px; background: rgba(255, 90, 106, .85); }
.badge.done { top: 30px; background: rgba(41, 199, 255, .85); color: #000; }
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 10px; border-radius: 12px; background: rgba(46, 122, 255, .15); border: 1px solid rgba(46, 122, 255, .35); font-size: 13px; }
.banner span { flex: 1; }
.banner.subtle { background: var(--surface); border-color: var(--stroke); color: var(--dim); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.danger, .text-btn.danger { color: var(--danger); }
.section-title .text-btn { font-size: 13px; display: inline-flex; gap: 4px; align-items: center; }
.link-row { display: flex; justify-content: space-between; gap: 12px; margin: 4px 0 10px; font-size: 14px; }
.group-title { margin: 26px 0 4px; font-size: 13px; font-weight: 700; color: var(--accent2); text-transform: uppercase; letter-spacing: .06em; }
.setting small { display: block; color: var(--dim); font-size: 12px; margin-top: 2px; }
.setting > span:first-child { flex: 1; }
.setting .btns { display: flex; gap: 8px; }
.setting input[type=checkbox], .net-row input[type=checkbox] { width: 44px; height: 26px; appearance: none; -webkit-appearance: none; background: rgba(255,255,255,.15); border-radius: 13px; position: relative; cursor: pointer; flex: none; transition: background .2s; }
.setting input[type=checkbox]::after, .net-row input[type=checkbox]::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.setting input[type=checkbox]:checked, .net-row input[type=checkbox]:checked { background: var(--accent); }
.setting input[type=checkbox]:checked::after, .net-row input[type=checkbox]:checked::after { transform: translateX(18px); }
input[type=checkbox]:disabled { opacity: .4; }
.hint { color: var(--dim); font-size: 12px; margin: 6px 0; }
.label { margin: 18px 0 8px; font-size: 12px; font-weight: 700; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }

.sheet-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 88dvh; display: flex; flex-direction: column; background: var(--surface); border-radius: 20px 20px 0 0; border: 1px solid var(--stroke); padding-bottom: var(--safe-bottom); }
@media (min-width: 700px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 20px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; font-size: 17px; }
.sheet-body { overflow: auto; padding: 0 16px 20px; }
.sheet-body .opts .opt, .menu .opt { display: flex; width: 100%; justify-content: space-between; padding: 11px 10px; border-radius: 10px; font-weight: 600; }
.sheet-body .opt.on { color: var(--accent2); background: var(--card); }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; }
.sheet-actions.top { margin: 8px 0 0; }
.net-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--stroke); }
.net-row .net-name { flex: 1; min-width: 0; cursor: pointer; }
.net-row .net-name small { display: block; color: var(--dim); font-size: 11px; }
.net-row .net-name small.err { color: var(--danger); }
.net-row .circle { color: var(--dim); }
.net-row .circle.on { color: var(--accent); }
.net-row .star { color: var(--dim); }
.net-row .star.on { color: var(--gold); }

.player .status .row-btns { display: flex; gap: 10px; justify-content: center; }

.remote { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; flex-direction: column; padding: calc(var(--safe-top) + 8px) 8px calc(var(--safe-bottom) + 8px); gap: 8px; }
.remote-bar { display: flex; align-items: center; gap: 8px; }
.remote-title { flex: 1; min-width: 0; }
.remote-title b { display: block; font-size: 15px; }
.remote-title span { font-size: 12px; color: var(--dim); }
.remote-hint { font-size: 13px; color: var(--dim); padding: 0 4px; }
.remote-stage { flex: 1; min-height: 0; display: flex; align-items: flex-start; justify-content: center; position: relative; overflow: hidden; }
.remote-stage img { max-width: 100%; max-height: 100%; width: auto; height: auto; border-radius: 10px; border: 1px solid var(--stroke); cursor: pointer; touch-action: pan-y; }
.remote-stage .spinner { position: absolute; top: 40%; left: 50%; margin-left: -14px; }
.remote-stage.ready .spinner { display: none; }
.remote-type { display: flex; gap: 6px; }
.remote-type input { flex: 1; min-width: 0; height: 44px; border-radius: 12px; border: 1px solid var(--stroke); background: var(--surface); padding: 0 12px; font-size: 16px; outline: 0; }
.remote-type .btn { padding: 0 12px; }
.poster .badge:not(.eps) { max-width: calc(100% - 52px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.poster .badge.new, .poster .badge.done { max-width: none; }
.tap-dot { position: fixed; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%; background: rgba(41, 199, 255, .5); border: 2px solid var(--accent2); pointer-events: none; animation: tap .6s ease-out forwards; z-index: 61; }
@keyframes tap { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }
.remote-stage.closed img { display: none; }
.remote-stage .closed-msg { padding: 40px 16px; }
