:root {
  --bg: #0d0f12;
  --panel: #161a20;
  --panel-2: #1d222a;
  --line: #2a313b;
  --text: #e8ecf1;
  --muted: #8b95a3;
  --accent: #4fb3ff;
  --accent-2: #2d8fe0;
  --brand: #ffc531;
  --danger: #ff6b6b;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: rgba(22, 26, 32, .92);
  backdrop-filter: blur(8px);
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: .5px; white-space: nowrap; }
a.brand { color: inherit; text-decoration: none; }
.logo { color: var(--brand); }
.tabs { display: flex; gap: 2px; }
.tab {
  background: none; border: 0; padding: 7px; cursor: pointer; color: var(--muted); border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center; transition: color .15s, background .15s;
}
.tab svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand); background: var(--panel-2); }
.filter {
  margin-left: auto; width: min(320px, 40vw); padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); outline: none;
}
.filter:focus { border-color: var(--accent); }
.btn {
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.ghost { background: transparent; }

/* layout */
.layout { max-width: 1500px; margin: 0 auto; padding: 18px; }
.player-section { margin-bottom: 28px; }
.stage {
  position: relative; width: 100%; aspect-ratio: 16 / 9; max-height: calc(100vh - 150px);
  background: #000; border-radius: var(--radius); overflow: hidden; user-select: none;
}
.stage:fullscreen { max-height: none; border-radius: 0; aspect-ratio: auto; }
video { width: 100%; height: 100%; display: block; background: #000; }

.subs {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 9%;
  width: 90%; text-align: center; pointer-events: none;
  font-size: clamp(16px, 2.6vw, 34px); line-height: 1.25; font-weight: 600;
  white-space: pre-line; color: #fff;
  text-shadow: 0 0 4px #000, 0 0 4px #000, 1px 1px 2px #000, -1px -1px 2px #000;
  transition: bottom .2s;
}
.stage.show-controls .subs { bottom: calc(9% + 60px); }

.spinner {
  position: absolute; top: 50%; left: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px;
  border: 4px solid rgba(255,255,255,.2); border-top-color: var(--brand); border-radius: 50%;
  animation: spin .8s linear infinite; pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.errorbox {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  max-width: 80%; max-height: 70%; overflow: auto; padding: 14px 16px;
  background: rgba(30, 10, 10, .92); border: 1px solid var(--danger); border-radius: 8px;
  font-family: ui-monospace, Menlo, monospace; font-size: 12px; white-space: pre-wrap;
}

/* controls */
.controls {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 14px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,.85));
  opacity: 0; transition: opacity .2s;
}
.stage.show-controls .controls { opacity: 1; }
.stage:not(.show-controls) { cursor: none; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.icon {
  background: none; border: 0; cursor: pointer; font-size: 18px; width: 34px; height: 34px;
  border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
}
.icon:hover { background: rgba(255,255,255,.12); }
.time { font-variant-numeric: tabular-nums; font-size: 13px; white-space: nowrap; }
.volume { width: 80px; accent-color: var(--accent); }
.sel { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.sel select {
  background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.18); border-radius: 6px;
  padding: 4px 6px; max-width: 170px; color: var(--text); font-size: 12px;
}

.seek { position: relative; height: 18px; display: flex; align-items: center; cursor: pointer; margin-bottom: 4px; }
.seek-track { position: relative; width: 100%; height: 4px; background: rgba(255,255,255,.22); border-radius: 2px; transition: height .1s; }
.seek:hover .seek-track { height: 6px; }
.seek-buffered { position: absolute; inset: 0 auto 0 0; background: rgba(255,255,255,.3); border-radius: 2px; }
.seek-fill { position: absolute; inset: 0 auto 0 0; background: var(--brand); border-radius: 2px; }
.seek-thumb {
  position: absolute; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px;
  background: #fff; border-radius: 50%; opacity: 0; transition: opacity .1s;
}
.seek:hover .seek-thumb { opacity: 1; }
.seek-tip {
  position: absolute; bottom: 20px; transform: translateX(-50%); padding: 2px 6px;
  background: rgba(0,0,0,.85); border-radius: 4px; font-size: 12px; pointer-events: none;
  font-variant-numeric: tabular-nums;
}

/* info */
.info { margin-top: 12px; }
.info-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.info h2 { font-size: 17px; margin: 4px 0 8px; word-break: break-word; }
.info p { margin: 8px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 3px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: 12px; }
.chip.warn { border-color: #b8862b; color: #f3c46b; }
.chip.ok { border-color: #2e7d4f; color: #7fdca4; }

/* library grid */
.grid {
  display: grid; gap: 18px 14px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.card {
  display: block; padding: 0; border: 0; background: none; text-align: left; cursor: pointer;
  border-radius: var(--radius);
}
.card:disabled { cursor: default; }
.thumb {
  position: relative; aspect-ratio: 2 / 3; border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(110deg, var(--panel) 30%, var(--panel-2) 50%, var(--panel) 70%) 0 0 / 300% 100%;
  animation: shimmer 1.6s linear infinite;
  outline: 2px solid transparent; outline-offset: 2px; transition: outline-color .15s, transform .15s;
}
.thumb.loaded, .thumb.failed { animation: none; background: var(--panel); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .3s; }
.thumb.loaded img { opacity: 1; }
.thumb.failed::after { content: "▶"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; color: var(--line); }
.card:hover:not(:disabled) .thumb, .card:focus-visible .thumb { outline-color: var(--brand); transform: translateY(-2px); }
.card.playing .thumb { outline-color: var(--brand); }
@keyframes shimmer { to { background-position: -300% 0; } }
.badge {
  position: absolute; right: 6px; bottom: 6px; padding: 1px 6px; border-radius: 4px;
  background: rgba(0,0,0,.75); font-size: 11px; font-variant-numeric: tabular-nums;
}
.badge.quality { right: auto; left: 6px; top: 6px; bottom: auto; font-weight: 600; }
.card .title {
  margin-top: 8px; font-size: 15px; font-weight: 600; line-height: 1.3; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .sub { color: var(--muted); font-size: 13px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card:disabled .thumb { opacity: .45; }
.libmsg { text-align: center; padding: 40px 0; white-space: pre-line; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .filter { order: 3; width: 100%; margin-left: 0; }
  .layout { padding: 10px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 14px 10px; }
  .card .title { font-size: 13px; }
  .card .sub { font-size: 12px; }
  .sel span { display: none; }
  .volume { display: none; }
}

/* continue watching */
.row-title { font-size: 16px; font-weight: 700; margin: 0 0 12px; }
.continue { margin-bottom: 28px; }
.hrow {
  display: grid; grid-auto-flow: column; grid-auto-columns: 160px; gap: 14px;
  overflow-x: auto; padding: 4px 4px 8px; margin: -4px -4px 0; scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.hrow .card { scroll-snap-align: start; position: relative; }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255,255,255,.25); }
.progress > span { display: block; height: 100%; background: var(--brand); }
.hrow .badge { bottom: 10px; }
.remove {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0,0,0,.7); color: #fff; font-size: 14px; line-height: 1;
  opacity: 0; transition: opacity .15s; cursor: pointer;
}
.card:hover .remove, .remove:focus-visible { opacity: 1; }
@media (hover: none) { .remove { opacity: .85; } }
.info-actions { display: flex; gap: 8px; flex-shrink: 0; }
@media (max-width: 720px) { .hrow { grid-auto-columns: 110px; gap: 10px; } }

/* login */
.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(255, 197, 49, .10), transparent 60%), var(--bg); }
.login-wrap { width: 100%; padding: 16px; display: flex; justify-content: center; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px 28px 28px; box-shadow: 0 20px 60px rgba(0, 0, 0, .45); }
.login-brand { font-size: 34px; text-align: center; }
.login-sub { text-align: center; margin: 6px 0 22px; }
.login-field { position: relative; display: block; }
.login-field input { width: 100%; padding: 12px 44px 12px 14px; font-size: 16px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: var(--radius); outline: none; transition: border-color .15s; }
.login-field input:focus { border-color: var(--brand); }
.login-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0;
  padding: 6px; cursor: pointer; color: var(--muted); display: flex; }
.login-eye:hover { color: var(--text); }
.login-eye svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.login-err { color: var(--danger); min-height: 20px; margin: 8px 2px 6px; font-size: 13px; }
.login-btn { width: 100%; padding: 12px; font-size: 16px; font-weight: 700; border: 0; border-radius: var(--radius);
  background: var(--brand); color: #1a1400; cursor: pointer; transition: filter .15s, opacity .15s; }
.login-btn:hover { filter: brightness(1.08); }
.login-btn:disabled { opacity: .6; cursor: default; }
.shake { animation: shake .35s; }
/* 3D cinema behind the sign-in card */
.login-scene { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; z-index: 0; opacity: 0; transition: opacity 1.2s ease; }
.scene-on .login-scene { opacity: 1; }
.login-page .login-wrap { position: relative; z-index: 1; }
.scene-on.login-page { place-items: end center; }
@media (min-width: 700px) { .scene-on.login-page { place-items: center; padding-top: 34vh; } }
.scene-on .login-wrap { padding-bottom: max(6vh, 24px); }
.scene-on .login-card { background: rgba(16, 18, 26, .62); border-color: rgba(255, 255, 255, .12);
  backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), 0 0 0 1px rgba(255, 197, 49, .06) inset; transition: opacity .5s, transform .5s; }
.scene-on .login-card .login-field input { background: rgba(0, 0, 0, .35); }
.entering .login-card { opacity: 0; transform: translateY(16px) scale(.98); pointer-events: none; }
.entering::after { content: ''; position: fixed; inset: 0; z-index: 5; background: #0b0c10; animation: fadeIn .7s ease 1.3s both; pointer-events: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* library: Movies / TV Shows switch */
.libbar { display: flex; align-items: center; margin: 0 0 16px; }
.seg { display: inline-flex; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; flex-wrap: wrap; }
.seg-btn { background: none; border: 0; color: var(--muted); padding: 7px 16px; border-radius: 999px; cursor: pointer; font-weight: 600; transition: color .15s, background .15s; }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--brand); color: #1a1400; }
.seg-btn .count { font-weight: 500; opacity: .65; font-size: 12px; margin-left: 2px; }
.seg-btn .count:empty { display: none; }
#libGrid > div + div { margin-top: 28px; }

/* show page */
.show-head { display: flex; gap: 22px; align-items: flex-end; margin-bottom: 22px; }
.show-poster { width: 180px; flex: none; }
.show-meta h2 { font-size: 28px; margin: 12px 0 4px; line-height: 1.15; }
.show-meta p { margin: 0 0 14px; }
.show-back { padding: 6px 12px; }
.btn.show-resume { background: var(--brand); color: #1a1400; border: 0; font-weight: 700; padding: 9px 18px; border-radius: var(--radius); cursor: pointer; }
.seasons { margin-bottom: 14px; border-radius: 14px; }
.eps { display: flex; flex-direction: column; gap: 6px; }
.ep { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 12px 14px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; transition: border-color .15s, background .15s; }
.ep:hover:not(.disabled), .ep:focus-visible { border-color: var(--brand); background: var(--panel-2); }
.ep.playing { border-color: var(--brand); }
.ep.disabled { opacity: .5; cursor: default; }
.ep-vers { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.ep-ver { font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); cursor: pointer; }
.ep-ver:hover:not(:disabled) { color: var(--text); border-color: var(--brand); }
.ep-ver.main { color: var(--text); }
.ep-ver.playing { background: var(--brand); color: #1a1400; border-color: var(--brand); }
.ep-ver:disabled { opacity: .5; cursor: default; }
.ep-num { width: 30px; flex: none; text-align: center; font-size: 20px; font-weight: 700; color: var(--muted); }
.ep.playing .ep-num { color: var(--brand); }
.ep-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ep-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ep-meta { color: var(--muted); font-size: 12.5px; }
.ep-progress { display: block; height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 4px; max-width: 260px; }
.ep-progress > span { display: block; height: 100%; background: var(--brand); }
.ep-play { color: var(--muted); font-size: 14px; flex: none; }
.ep:hover .ep-play { color: var(--brand); }
@media (max-width: 720px) {
  .show-head { gap: 14px; }
  .show-poster { width: 110px; }
  .show-meta h2 { font-size: 20px; }
  .ep { padding: 10px; gap: 10px; }
  .ep-num { width: 22px; font-size: 16px; }
}
.versions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.versions .muted { font-size: 12.5px; margin-right: 4px; }

/* discover */
.discovering #librarySection, .disc-detail #continueSection { display: none !important; }
.discovering #continueSection { margin-bottom: 22px; }
#discoverBtn.active { color: var(--brand); }
.drow { margin-bottom: 26px; }
.drow .hrow { min-height: 60px; }
.dcard .thumb img { opacity: 1; }
.badge.inlib, .hrow .badge.inlib { background: var(--brand); color: #1a1400; top: 6px; bottom: auto; }
.dhero { display: flex; gap: 22px; align-items: flex-end; margin: -6px -18px 22px; padding: 70px 18px 18px;
  background-size: cover; background-position: center 20%; border-radius: 0 0 14px 14px; }
.doverview { max-width: 720px; line-height: 1.55; margin: 0 0 14px; color: #cfd6df; }
.rels { margin-top: 8px; }
.eps .rels { margin: 4px 0 12px 36px; }
.rels-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.rels-head .row-title { margin: 0; }
.rels-filters { display: flex; gap: 8px; align-items: center; }
.chipbtn { background: var(--panel); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: 13px; }
.chipbtn.on { background: var(--brand); color: #1a1400; border-color: var(--brand); }
.rels-q { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; font-size: 13px; }
.rels-list { display: flex; flex-direction: column; gap: 6px; }
.rel { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.rel-badge { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; }
.rel-badge.instant { background: rgba(255, 197, 49, .16); color: var(--brand); }
.rel-badge.dl { background: var(--panel-2); color: var(--muted); }
.rel-body { flex: 1; min-width: 0; }
.rel-title { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.rel-meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.rel-btn { flex: none; white-space: nowrap; }
.btn.primary { background: var(--brand); color: #1a1400; border-color: var(--brand); font-weight: 700; }
.rel-err { color: var(--danger); font-size: 13px; margin: -2px 0 4px 52px; }
.rels-more { align-self: center; margin-top: 6px; }
@media (max-width: 720px) {
  .dhero { padding-top: 40px; gap: 14px; }
  .doverview { font-size: 13.5px; }
  .eps .rels { margin-left: 0; }
  .rel { gap: 10px; padding: 9px 10px; }
  .rel-btn { padding: 6px 10px; }
}

/* phone bottom bar */
.bottomnav { display: none; }
.bn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 720px) {
  .bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: rgba(22, 26, 32, .96); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .bn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0 7px;
    background: none; border: 0; color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .bn.active { color: var(--brand); }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  #discoverBtn { display: none; } /* lives in the bottom bar on phones */
  .dhero { margin: -10px -10px 18px; padding: 36px 10px 14px; flex-direction: column; align-items: flex-start; }
  .dhero .show-poster { width: 120px; }
  .rels-head { flex-direction: column; align-items: flex-start; }
  .seasons { overflow-x: auto; flex-wrap: nowrap; max-width: 100%; scrollbar-width: none; }
  .seasons .seg-btn { white-space: nowrap; }
}
/* fullscreen-ish player on phones shouldn't sit under the bar */
@media (max-width: 720px) and (orientation: landscape) { .bottomnav { display: none; } body { padding-bottom: 0; } }
.discovering #kindTabs .tab.active { color: var(--muted); background: none; } /* on Discover, no library source is "current" */
.hrow .badge.quality { bottom: auto; } /* quality tag stays a small pill at the top-left */
