:root {
  --bg: #0f0f13;
  --bg2: #17171d;
  --bg3: #22222b;
  --line: #2b2b36;
  --text: #f2f2f5;
  --muted: #9d9dab;
  --accent: #ff6a3d;
  --link: #8cbcff;
  --radius: 12px;
  --top: 56px;
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; -webkit-tap-highlight-color: transparent; padding-bottom: env(safe-area-inset-bottom); }
body.has-mini { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
body.noscroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:disabled { cursor: default; }
svg { width: 1.25em; height: 1.25em; flex: none; display: block; }
code { background: var(--bg3); padding: 1px 6px; border-radius: 6px; font-size: .92em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- thanh tren ---------- */
.top {
  position: sticky; top: 0; z-index: 30; height: var(--top);
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: rgba(15, 15, 19, .94); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: -.02em; flex: none; }
.brand .logo { width: 30px; height: 30px; }
.search {
  flex: 1; max-width: 640px; margin: 0 auto; display: flex; height: 40px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); padding: 0 16px; font-size: 16px; }
.search input::placeholder { color: #7c7c8a; }
.search button { width: 52px; display: grid; place-items: center; background: var(--bg3); color: var(--muted); }
.search button svg { width: 20px; height: 20px; }
body.locked .search, body.restricted .search { visibility: hidden; }
.who { flex: none; }
.who[hidden] { display: none; }
.who-btn {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff;
  font-weight: 800; font-size: 16px; display: grid; place-items: center;
}

/* ---------- popup ---------- */
.pop {
  position: absolute; z-index: 60; background: #1e1e26; border: 1px solid var(--line); border-radius: 12px;
  padding: 6px; box-shadow: 0 12px 32px rgba(0, 0, 0, .5); max-width: calc(100vw - 16px);
}
.pop-title { font-size: 13px; color: var(--muted); padding: 8px 10px 6px; }
.pop-title small { font-size: 12px; }
.pop-item, .pop-link {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border-radius: 8px;
  font-size: 14px; cursor: pointer; text-align: left;
}
.pop-item:hover, .pop-link:hover { background: var(--bg3); }
.pop-item input { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; flex: none; }
.pop-item span { flex: 1; }
.pop-item small { font-size: 11px; color: var(--muted); background: var(--bg3); padding: 2px 6px; border-radius: 6px; }
.pop-link { border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; margin-top: 4px; color: var(--text); }
.pop-link svg { width: 18px; height: 18px; color: var(--muted); }
.pop-title + .pop-link { border-top: 0; margin-top: 0; border-radius: 8px; }

/* ---------- quan ly gia dinh ---------- */
.manage > p { max-width: 760px; line-height: 1.55; margin: 0 0 18px; }
.fam { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.fam-card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.fam-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.fam-av { width: 44px; height: 44px; font-size: 18px; flex: none; background: var(--accent); color: #fff; }
.fam-who { flex: 1; min-width: 0; }
.fam-who b { display: block; font-size: 16px; }
.fam-who small { color: var(--muted); font-size: 12px; }
.fam-add { display: flex; gap: 8px; margin-bottom: 10px; }
.fam-add input {
  flex: 1; min-width: 0; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  color: var(--text); padding: 0 12px; font-size: 15px; outline: 0;
}
.fam-add input:focus { border-color: var(--accent); }
.fam-subs { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.fam-subs li { display: flex; align-items: center; gap: 10px; padding: 4px 2px; }
.fam-subs a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.fam-sav { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none; font-size: 13px; }
.fam-del { width: 32px; height: 32px; color: var(--muted); }
.fam-del svg { width: 18px; height: 18px; }
.fam-del:hover { color: #ff8080; background: var(--bg3); }

/* ---------- bo cuc chung ---------- */
.view { max-width: 1500px; margin: 0 auto; padding: 16px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 12px; }
.sec-head h2 { font-size: 18px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 22px 16px; }
.hrow {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 260px); gap: 14px;
  overflow-x: auto; padding-bottom: 8px; margin-bottom: 22px; scrollbar-width: thin;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 16px;
  border-radius: 999px; background: var(--text); color: #111; font-weight: 650; font-size: 14px; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn.ghost, .sub-btn.on { background: var(--bg3); color: var(--text); }
.btn:disabled { opacity: .6; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 999px; background: var(--bg3); font-size: 14px; font-weight: 550;
}
.chip svg { width: 18px; height: 18px; }
.chip.on { background: var(--accent); color: #fff; }
.more-btn { display: flex; margin: 26px auto 8px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); cursor: pointer; user-select: none; white-space: nowrap; }
.toggle input { accent-color: var(--accent); width: 17px; height: 17px; margin: 0; }
.av-ph { display: grid; place-items: center; font-weight: 700; background: var(--bg3); color: var(--text); border-radius: 50%; }

/* ---------- the video ---------- */
.card { display: block; min-width: 0; }
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: var(--bg3); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge {
  position: absolute; right: 6px; bottom: 6px; background: rgba(0, 0, 0, .82); color: #fff;
  font-size: 12px; font-weight: 650; padding: 2px 6px; border-radius: 6px; font-variant-numeric: tabular-nums;
}
.badge.live { background: #e0352b; }
.prog { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, .3); }
.prog i { display: block; height: 100%; background: var(--accent); }
.c-body { padding: 10px 2px 0; }
.c-title {
  font-size: 15px; line-height: 1.35; margin: 0 0 6px; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.c-meta { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.c-ch[data-ch]:hover { color: var(--text); }
.sk .thumb, .sk-line {
  background: linear-gradient(90deg, var(--bg2), var(--bg3), var(--bg2)); background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}
.sk-line { height: 12px; border-radius: 6px; margin: 10px 0; }
.sk-line.short { width: 55%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- trang chu ---------- */
.subs-row { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 18px; scrollbar-width: thin; }
.sub-chip { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 78px; flex: none; font-size: 12px; text-align: center; }
.sub-av { width: 62px; height: 62px; border-radius: 50%; object-fit: cover; background: var(--bg3); font-size: 22px; }
.sub-chip span:last-child { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.empty { max-width: 620px; margin: 40px auto; text-align: center; line-height: 1.6; }
.empty h2 { font-size: 24px; margin-bottom: 8px; }
.tips { list-style: none; padding: 0; margin: 24px 0 0; text-align: left; display: grid; gap: 10px; }
.tips li { display: flex; gap: 12px; align-items: flex-start; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; }
.tips svg { width: 22px; height: 22px; color: var(--accent); margin-top: 1px; }
.err-box { max-width: 560px; margin: 32px auto; text-align: center; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.err-box p { margin: 0 0 16px; line-height: 1.5; }
.err-box .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- kenh ---------- */
.ch-head { display: flex; align-items: center; gap: 16px; padding: 8px 0 18px; flex-wrap: wrap; }
.ch-av { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; background: var(--bg3); flex: none; font-size: 32px; }
.ch-info { flex: 1; min-width: 180px; }
.ch-info h1 { margin: 0 0 4px; font-size: 24px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 10px 16px; color: var(--muted); font-weight: 650; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.on { color: var(--text); border-color: var(--text); }

/* ---------- trang xem ---------- */
.watch { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 24px; align-items: start; }
.w-title { font-size: 20px; line-height: 1.3; margin: 14px 0 12px; font-weight: 700; word-break: break-word; }
.w-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.w-ch { display: flex; align-items: center; gap: 10px; min-width: 0; margin-right: auto; }
.w-av { width: 40px; height: 40px; flex: none; }
.w-ch b { display: block; }
.w-ch small { display: block; color: var(--muted); font-size: 12px; }
.w-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.w-descbox { background: var(--bg2); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; line-height: 1.55; }
.w-stats { font-weight: 650; margin-bottom: 6px; }
.w-desc { white-space: pre-wrap; word-break: break-word; color: #d8d8e0; }
.w-desc.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.w-desc a, .ts { color: var(--link); }
.link-btn { font-weight: 700; margin-top: 8px; }
.chapters { display: flex; gap: 8px; overflow-x: auto; margin: 6px 0 10px; padding-bottom: 4px; }
.chap { flex: none; background: var(--bg3); color: var(--text); border-radius: 10px; padding: 8px 10px; font-size: 13px; display: flex; gap: 8px; max-width: 260px; text-align: left; }
.chap span { color: var(--accent); font-variant-numeric: tabular-nums; }
.w-side { position: sticky; top: calc(var(--top) + 16px); }
.w-queue.has { background: var(--bg2); border-radius: var(--radius); overflow: hidden; }
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.q-head h3 { margin: 0 0 2px; font-size: 16px; }
.q-list { list-style: none; margin: 0; padding: 6px; max-height: calc(100vh - var(--top) - 120px); overflow: auto; position: relative; }
.q-item { display: flex; gap: 10px; padding: 6px; border-radius: 10px; }
.q-item:hover { background: var(--bg3); }
.q-item.on { background: var(--bg3); box-shadow: inset 3px 0 0 var(--accent); }
.q-thumb { position: relative; width: 150px; flex: none; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: var(--bg3); }
.q-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.q-thumb .badge { font-size: 11px; right: 4px; bottom: 4px; }
.q-txt { min-width: 0; }
.q-txt b { font-size: 14px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.q-txt small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---------- trinh phat ---------- */
.player {
  position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); overflow: hidden;
  user-select: none; -webkit-user-select: none; touch-action: manipulation; color: #fff;
}
.player video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.player .poster { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .25s; pointer-events: none; }
.player.show-poster .poster { opacity: 1; }
.player.listen .poster { filter: brightness(.5); }
.p-listen {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); display: none; align-items: center; gap: 8px;
  background: rgba(0, 0, 0, .6); padding: 6px 12px; border-radius: 999px; font-size: 13px; white-space: nowrap; max-width: 92%;
}
.p-listen svg { width: 18px; height: 18px; color: var(--accent); }
.player.listen .p-listen { display: flex; }
.p-surface { position: absolute; inset: 0; }
.p-big {
  position: absolute; left: 50%; top: 50%; width: 68px; height: 68px; margin: -34px 0 0 -34px; border-radius: 50%;
  background: rgba(0, 0, 0, .55); display: grid; place-items: center; transition: opacity .2s;
}
.p-big svg { width: 34px; height: 34px; }
.player.playing:not(.touch) .p-big, .player.playing.idle .p-big, .player.loading .p-big { opacity: 0; pointer-events: none; }
.p-spin {
  position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .25); border-top-color: #fff; animation: spin .8s linear infinite; display: none; pointer-events: none;
}
.player.loading .p-spin { display: block; }
.p-status {
  position: absolute; left: 0; right: 0; top: calc(50% + 36px); text-align: center; font-size: 14px;
  color: #ddd; text-shadow: 0 1px 4px #000; display: none; pointer-events: none;
}
.player.fetching .p-status { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }
.p-bar {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 28px 8px 4px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .78)); transition: opacity .25s;
}
.player.idle .p-bar { opacity: 0; pointer-events: none; }
.player.idle { cursor: none; }
.p-seek {
  -webkit-appearance: none; appearance: none; display: block; width: calc(100% - 8px); margin: 0 4px; height: 18px;
  background: transparent; cursor: pointer; --p: 0%; --b: 0%;
}
.p-seek::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--p), rgba(255, 255, 255, .5) var(--p) var(--b), rgba(255, 255, 255, .22) var(--b));
}
.p-seek::-moz-range-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--p), rgba(255, 255, 255, .5) var(--p) var(--b), rgba(255, 255, 255, .22) var(--b));
}
.p-seek::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); margin-top: -5px; border: 0; }
.p-seek::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 0; }
.p-row { display: flex; align-items: center; gap: 2px; }
.pb { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: #fff; flex: none; }
.pb svg { width: 24px; height: 24px; }
.pb:hover:not(:disabled) { background: rgba(255, 255, 255, .12); }
.pb:disabled { opacity: .35; }
.p-txt { width: auto; min-width: 40px; padding: 0 8px; font-size: 13px; font-weight: 700; border-radius: 8px; }
.p-txt svg { width: 20px; height: 20px; }
.p-time { font-size: 13px; color: #e2e2e8; margin-left: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.p-grow { flex: 1; }
.p-menu {
  position: absolute; right: 8px; bottom: 58px; min-width: 210px; max-height: calc(100% - 68px); overflow: auto;
  background: rgba(24, 24, 31, .97); border: 1px solid var(--line); border-radius: 12px; padding: 6px; z-index: 5;
}
.pm-title { font-size: 12px; color: var(--muted); padding: 8px 10px 4px; text-transform: uppercase; letter-spacing: .05em; }
.pm-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 9px 10px; border-radius: 8px; font-size: 14px; text-align: left; }
.pm-item:hover { background: var(--bg3); }
.pm-item.on { color: var(--accent); }
.pm-item svg { width: 18px; height: 18px; }
.p-flash {
  position: absolute; top: 50%; transform: translateY(-50%); padding: 10px 16px; background: rgba(0, 0, 0, .6);
  border-radius: 999px; font-weight: 700; opacity: 0; pointer-events: none;
}
.p-flash.l { left: 12%; }
.p-flash.r { right: 12%; }
.p-flash.show { animation: flash .65s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }
.player:fullscreen { border-radius: 0; aspect-ratio: auto; width: 100%; height: 100%; }
.player:-webkit-full-screen { border-radius: 0; aspect-ratio: auto; width: 100%; height: 100%; }
.player.fake-fs { position: fixed; inset: 0; z-index: 100; border-radius: 0; aspect-ratio: auto; width: 100vw; height: 100vh; height: 100dvh; }

/* ---------- mini player ---------- */
.mini {
  position: fixed; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 40;
  display: flex; align-items: center; gap: 2px; padding: 6px; max-width: 560px; margin: 0 auto; overflow: hidden;
  background: rgba(30, 30, 38, .97); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.mini[hidden] { display: none; }
.mini-open { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; text-align: left; }
.mini-open img { width: 96px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; flex: none; background: var(--bg3); }
.mini-txt { min-width: 0; }
.mini-txt b, .mini-txt small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-txt b { font-size: 14px; }
.mini-txt small { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mini-prog { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--accent); width: 0; }

/* ---------- khac ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 16px);
  background: #2c2c37; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0;
  pointer-events: none; transition: opacity .2s, transform .2s; z-index: 200; max-width: 90vw; text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.login { min-height: calc(100vh - var(--top) - 60px); display: grid; place-items: center; }
.login form { width: min(360px, 100%); background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0; }
.login p { margin: 0; }
.login input { height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); padding: 0 14px; font-size: 16px; outline: 0; }
.login input:focus { border-color: var(--accent); }
.login .btn { height: 46px; font-size: 16px; }
.login .err { color: #ff8080; min-height: 1.3em; font-size: 14px; }

/* ---------- man hinh nho ---------- */
@media (max-width: 1000px) {
  .watch { grid-template-columns: 1fr; gap: 16px; }
  .w-side { position: static; }
  .q-list { max-height: none; }
}
@media (max-width: 700px) {
  body[data-route="watch"] .view { padding: 0 0 16px; }
  body[data-route="watch"] .player:not(.fake-fs) { border-radius: 0; }
  .w-slot { position: sticky; top: var(--top); z-index: 20; }
  .w-info, .w-side { padding: 0 12px; }
  .w-title { font-size: 18px; }
}
@media (max-width: 600px) {
  .top { padding: 0 10px; gap: 10px; }
  .brand span { display: none; }
  .view { padding: 12px; }
  .grid { gap: 20px; }
  .p-back, .p-fwd { display: none; }
  .pb { width: 38px; height: 38px; }
  .q-thumb { width: 128px; }
}
@media (hover: none) {
  .pb:hover:not(:disabled) { background: none; }
}
