:root {
  color-scheme: dark;
  --ink: #f5f5f7;
  --muted: #a7a9b4;
  --glass: rgba(37, 39, 53, .78);
  --focus: #fff;
  --accent: #76a9ff;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  color: var(--ink);
  background: #0b0d16;
}
body::before {
  content: "";
  position: fixed;
  inset: -12%;
  background:
    radial-gradient(ellipse at 18% 15%, #232942 0, transparent 36%),
    radial-gradient(ellipse at 75% 15%, #17314f 0, transparent 35%),
    radial-gradient(ellipse at 27% 82%, #302136 0, transparent 38%),
    radial-gradient(ellipse at 80% 75%, #132e36 0, transparent 35%),
    #0b0d16;
  filter: blur(50px);
  pointer-events: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; }
button:disabled { opacity: .55; }
[hidden] { display: none !important; }
.nav-item:focus-visible, .nav-item:focus { outline: none; box-shadow: inset 0 0 0 3px var(--focus); }
p { margin: 0; }
h1, h2 { margin: 0; }
.tv-container { position: relative; height: 100%; display: flex; flex-direction: column; }
.tv-sidebar { flex: none; padding: 24px 20px 0; z-index: 3; }
#sidebar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 2px;
  width: max-content;
  max-width: 100%;
  margin: auto;
  padding: 5px;
  overflow-x: auto;
  border-radius: 100px;
  background: var(--glass);
  backdrop-filter: blur(28px);
  box-shadow: 0 14px 38px #0005;
  scrollbar-width: none;
}
#sidebar::-webkit-scrollbar { display: none; }
.tab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  gap: 8px;
  min-height: 50px;
  padding: 10px 18px;
  border-radius: 100px;
  background: transparent;
  color: #d5d6de;
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
}
.tab-btn svg { width: 18px; height: 18px; fill: currentColor; opacity: .8; }
.tab-btn[aria-current="page"] { background: #f5f5f7; color: #161821; box-shadow: 0 6px 20px #0005; }
.tab-btn[aria-current="page"]:focus { box-shadow: inset 0 0 0 3px #353844; }
.tab-btn:hover:not([aria-current="page"]) { background: #ffffff25; }
.tv-main { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 28px clamp(24px, 5vw, 96px) 0; }
.tv-main > header { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#backRow { flex: none; }
#back { min-height: 38px; padding: 8px 16px; border-radius: 10px; background: #ffffff22; font-size: 15px; font-weight: 650; line-height: 1; transition: background .15s ease, color .15s ease, box-shadow .15s ease; }
#back:focus { background: #fff; color: #10151b; outline: none; box-shadow: 0 0 0 3px rgba(255, 255, 255, .4), 0 8px 24px rgba(0, 0, 0, .5); }
body[data-view="episodes"] #status { display: none; }
#status { color: var(--muted); font-size: 14px; min-height: 20px; margin-bottom: 18px; }
.scroll-area, .episodes { min-height: 0; scrollbar-width: none; }
.scroll-area::-webkit-scrollbar, .episodes::-webkit-scrollbar { display: none; }
.scroll-area { overflow: auto; }
#content { flex: 1; overflow-x: hidden; padding: 4px 5px 42px; }
#content > * { animation: content-in .18s ease-out; }
@keyframes content-in { from { opacity: 0; transform: translateY(6px); } }
.grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 32px 22px; align-items: start; }
.poster { min-width: 0; display: flex; flex-direction: column; gap: 5px; padding: 0; border-radius: 14px; background: transparent; text-align: left; }
.poster-image { position: relative; width: 100%; aspect-ratio: 2 / 3; overflow: hidden; border-radius: 8px; background: #252936; transition: transform .15s ease; }
.poster:focus-visible, .poster:focus { box-shadow: none; }
.poster:focus .poster-image { transform: scale(1.02); }
.poster:focus .poster-image::after { content: ""; position: absolute; inset: 0; border: 3px solid var(--focus); border-radius: inherit; pointer-events: none; }
.poster-image img { display: block; width: 100%; height: 100%; object-fit: cover; }
.poster-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 18px; font-weight: 700; }
.poster-meta { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); font-size: 14px; }
.bookmark { position: absolute; top: 8px; right: 8px; display: grid; place-items: center; width: 30px; height: 32px; border-radius: 8px; color: #fff; background: #1119; }
.progress, .watch-track { position: absolute; bottom: 0; left: 0; right: 0; height: 5px; background: #1b253655; }
.progress { right: auto; background: #fff; }
.watch-track > span { display: block; height: 100%; background: #fff; }
.watch-badge { position: absolute; left: 8px; bottom: 12px; padding: 4px 8px; border-radius: 7px; color: #fff; background: #1a2539bf; font-size: 12px; font-weight: 700; }
.group-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; }
.group-card { width: clamp(190px, 18vw, 270px); min-height: 110px; display: flex; align-items: center; gap: 14px; padding: 16px; overflow: hidden; border-radius: 16px; background: #ffffff16; text-align: left; transition: transform .15s ease; }
.group-card:focus { transform: scale(1.015); }
.group-icon { flex: 0 0 78px; width: 78px; height: 64px; object-fit: contain; }
.group-copy { min-width: 0; display: flex; flex: 1; flex-direction: column; align-items: flex-start; gap: 4px; }
.group-copy strong, .group-copy small { width: 100%; overflow: hidden; text-overflow: ellipsis; }
.group-copy strong { font-size: 20px; }
.group-copy small { color: var(--muted); white-space: nowrap; }
.group-card.no-icon .group-copy { align-items: center; text-align: center; }
.profile-initial { display: grid; flex: 0 0 62px; place-items: center; width: 62px; height: 62px; border-radius: 50%; background: var(--profile-color, #6b96c6); color: white; font-size: 22px; }
.more { width: 100%; margin-top: 24px; padding: 14px; border-radius: 12px; background: #ffffff20; font-size: 15px; font-weight: 650; text-align: center; transition: background .15s ease, color .15s ease; }
.more:focus { background: #fff; color: #10151b; outline: none; box-shadow: 0 0 0 3px rgba(255, 255, 255, .4); }
.episodes .more { flex: none; margin: 8px 0 16px; }
#searchWrap { width: min(100%, 860px); display: flex; align-items: center; gap: 14px; margin: 0 auto 12px; padding: 10px 14px; border-radius: 14px; background: #ffffff12; }
#searchWrap label { flex: 0 0 auto; font-size: 16px; font-weight: 700; }
#searchInput { flex: 1; min-width: 0; padding: 11px 15px; border: 1px solid #ffffff35; border-radius: 10px; background: #ffffff16; }
body[data-view="search"] #status { width: min(100%, 860px); margin: 0 auto 14px; }
.playlist { display: grid; grid-template-columns: minmax(260px, 28%) minmax(0, 1fr); gap: clamp(24px, 3.5vw, 56px); align-items: start; }
.playlist-aside { display: flex; flex-direction: column; align-items: flex-start; gap: 22px; min-width: 0; }
.playlist-back { min-height: 40px; padding: 9px 16px; border-radius: 10px; background: #ffffff0d; color: #c4c6d2; font-size: 14px; font-weight: 650; }
.playlist-intro { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.playlist-eyebrow { color: var(--muted); font-size: 14px; font-weight: 700; }
.playlist-title { font-size: clamp(30px, 2.8vw, 48px); line-height: 1.1; letter-spacing: -.035em; }
.playlist-meta { color: var(--muted); font-size: 17px; }
.playlist-description { max-width: 62ch; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; font-size: 16px; line-height: 1.5; color: #c4c6d2; }
.playlist-cover { width: min(100%, 280px); max-height: 420px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 8px; box-shadow: 0 18px 40px #0006; }
.playlist-detail, .seasons button, .actions button { padding: 13px 20px; border-radius: 10px; background: #ffffff27; color: white; font-weight: 650; }
.playlist-detail { margin-top: 16px; background: #fff; color: #10151b; }
.playlist-detail:focus, .seasons button[aria-pressed="true"]:focus { box-shadow: inset 0 0 0 3px #353844; }
.playlist > section { min-width: 0; }
.seasons { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.seasons button[aria-pressed="true"] { background: #fff; color: #15191f; }
.episodes { display: flex; flex-direction: column; gap: 10px; }
.episode { position: relative; isolation: isolate; overflow: hidden; flex: none; min-width: 0; display: flex; align-items: center; gap: 20px; padding: 12px 16px; border-radius: 8px; background: #ffffff12; text-align: left; transition: background .15s ease, transform .15s ease; }
.episode::before { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--watch-progress, 0%); background: var(--profile-color, #76a9ff); opacity: .12; pointer-events: none; }
.episode > * { position: relative; z-index: 1; }
.episode-state { display: grid; place-items: center; flex: 0 0 48px; height: 32px; margin-left: auto; color: var(--profile-color, #76a9ff); font-size: 13px; font-weight: 700; }
.is-watched .episode-state { flex-basis: 32px; margin-inline: 8px; border: 1px solid currentColor; border-radius: 50%; font-size: 18px; }
.episode:focus { background: #ffffff26; outline: none; box-shadow: inset 0 0 0 2px var(--focus); transform: translateX(2px); }
.episode-thumb {
  position: relative;
  width: clamp(112px, 12vw, 180px);
  flex: none;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  overflow: hidden;
  background: #252936;
}
.episode-thumb.is-sprite {
  background-size: 1200% 600%;
  background-repeat: no-repeat;
  background-color: #111;
  transition: filter .15s ease;
}
.episode:focus .episode-thumb.is-sprite {
  filter: brightness(1.1);
}
.episode-thumb img, .episode img {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  background: #252936;
}
.episode-info { display: flex; flex: 1; flex-direction: column; justify-content: center; gap: 6px; min-width: 0; }
.episode-title-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.episode-title-row strong { min-width: 0; }
.episode strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 18px; font-weight: 650; }
.episode small { color: var(--muted); font-size: 14px; }
.episode-subtitle-status { flex: none; max-width: 130px; color: #b8c7df; font-size: 12px; font-weight: 650; white-space: nowrap; }
.episode-subtitle-status[hidden] { display: none; }
.episode-subtitle-status[data-state="ready"] { color: #5ee0b0; }
.episode-subtitle-status[data-state="error"] { color: #ffb2a4; }
.episode { -webkit-touch-callout: none; user-select: none; touch-action: pan-y; }
.subtitle-actions { width: min(440px, 92vw); margin: auto; padding: 28px; border-radius: 18px; box-shadow: 0 24px 70px #0009; }
.subtitle-actions h2 { margin-bottom: 8px; }
.subtitle-episode, .subtitle-action-status { color: var(--muted); line-height: 1.5; margin-bottom: 20px; }
.subtitle-actions button { display: block; width: 100%; padding: 14px; border-radius: 10px; margin-top: 10px; }
.subtitle-actions button:disabled { opacity: .5; }
@media (max-width: 760px) {
  .subtitle-actions { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 20px 20px 0 0; padding-bottom: max(28px, env(safe-area-inset-bottom)); }
  .episode-subtitle-status { font-size: 10px; max-width: 85px; }
}
@media (min-width: 761px) {
  body[data-view="episodes"] #content { overflow: hidden; scrollbar-width: none; }
  body[data-view="episodes"] #content::-webkit-scrollbar,
  body[data-view="episodes"] .episodes::-webkit-scrollbar { display: none; }
  body[data-view="episodes"] .playlist { height: 100%; align-items: stretch; }
  body[data-view="episodes"] .playlist-aside { position: sticky; top: 0; align-self: start; max-height: 100%; overflow-y: auto; scrollbar-width: none; }
  body[data-view="episodes"] .playlist-aside::-webkit-scrollbar { display: none; }
  body[data-view="episodes"] .playlist > section { height: 100%; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  body[data-view="episodes"] .episodes { flex: 1; min-height: 0; overflow-y: auto; padding-right: 2px; scrollbar-width: none; }
}
dialog { color: var(--ink); border: 0; background: #20232e; }
dialog::backdrop { background: #10182799; backdrop-filter: blur(8px); }
#login { width: min(420px, 90vw); margin: auto; padding: 30px; border-radius: 20px; box-shadow: 0 24px 70px #0009; }
#login form { display: flex; flex-direction: column; gap: 13px; }
#login h1 { font-size: 32px; }
#login p { color: var(--muted); }
#login input { width: 100%; padding: 12px; border: 1px solid #ffffff35; border-radius: 10px; background: #ffffff13; }
#login button { margin-top: 8px; padding: 13px; border-radius: 10px; }
#loginError { color: #ff9a92 !important; }
.primary { color: #fff; background: #3567b5 !important; }
.tv-modal { width: 100%; height: 100%; max-width: 100%; max-height: 100%; background: transparent; }
.modal-box { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 94vw); display: flex; flex-direction: column; gap: 16px; padding: 55px 30px 30px; background: #20232e; box-shadow: -16px 0 45px #0009; }
.modal-close { position: absolute; top: 14px; right: 18px; padding: 8px 13px; border-radius: 8px; background: #ffffff20; }
#detailImage { width: 160px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 12px; align-self: center; }
#detailTitle { font-size: 26px; }
#detailMeta, #detailDescription { color: var(--muted); }
.actions { display: flex; flex-direction: column; gap: 9px; }
#player { position: fixed; inset: 0; width: 100%; height: 100%; max-width: 100%; max-height: 100%; padding: 0; background: black; }
#playerFrame { width: 100%; height: 100%; border: 0; }
#notice { position: fixed; bottom: 22px; left: 50%; z-index: 10; transform: translateX(-50%); padding: 10px 16px; border-radius: 10px; background: #1e293be6; color: #fff; pointer-events: none; }
#notice:empty { display: none; }
@media (max-width: 1050px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } .tab-btn { padding-inline: 13px; } }
@media (max-width: 760px) {
  .tv-sidebar { padding: 16px 10px 0; }
  #sidebar { width: 100%; justify-content: flex-start; }
  .tab-btn { min-height: 42px; padding: 8px 12px; font-size: 13px; }
  .tab-btn svg { display: none; }
  .tv-main { padding: 20px 16px 0; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 14px; }
  .episode { gap: 12px; }
  .episode-thumb { width: 88px; }
  .poster-title, .episode strong { font-size: 15px; }
  .episode strong { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: normal; }
  .episode-state { flex-basis: 40px; font-size: 12px; }
  .is-watched .episode-state { margin-inline: 4px; }
  .playlist { grid-template-columns: 1fr; }
  .playlist-aside { align-items: flex-start; }
  .playlist-intro { align-self: stretch; }
  .playlist-cover { width: min(170px, 60%); max-height: 255px; }
  .playlist-title { font-size: 32px; }
  #searchWrap { gap: 10px; padding: 9px 11px; }
  #searchWrap label { font-size: 14px; }
  .group-grid { gap: 12px; }
  .group-card { width: min(100%, 300px); min-height: 92px; padding: 13px; }
}
@media (max-width: 420px) { .poster-meta { font-size: 12px; } }
@media (max-height: 600px) and (min-width: 800px) {
  .tv-sidebar { padding: 10px 16px 0; }
  #sidebar { padding: 3px; }
  .tab-btn { min-height: 40px; }

  #back { min-height: 30px; padding: 5px 9px; font-size: 12px; }
  .tab-btn { padding: 7px 10px; font-size: 13px; }
  .tab-btn svg { width: 15px; height: 15px; }
  .tv-main { padding: 14px 24px 0; }
  #status { min-height: 16px; margin-bottom: 9px; font-size: 12px; }
  #content { padding-bottom: 12px; }
  #searchWrap { gap: 9px; margin-bottom: 8px; padding: 7px 10px; border-radius: 11px; }
  #searchWrap label { font-size: 12px; }
  #searchInput { padding: 8px 10px; font-size: 12px; }
  body[data-view="search"] #status { margin-bottom: 8px; }
  .grid { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 17px 13px; }
  .group-grid { gap: 10px; }
  .group-card { width: 164px; min-height: 70px; gap: 9px; padding: 10px; border-radius: 11px; }
  .group-icon { flex-basis: 48px; width: 48px; height: 40px; }
  .profile-initial { flex-basis: 42px; width: 42px; height: 42px; font-size: 16px; }
  .group-copy { gap: 2px; }
  .group-copy strong { font-size: 12px; }
  .group-copy small { font-size: 11px; }
  .poster-title { font-size: 13px; }
  .poster-meta { font-size: 11px; }
  .playlist { grid-template-columns: minmax(230px, 28%) minmax(0, 1fr); gap: 20px; }
  .playlist-aside { gap: 10px; }
  .playlist-cover { width: 100px; max-height: 150px; }
  .playlist-intro { gap: 6px; }
  .playlist-eyebrow, .playlist-meta { font-size: 11px; }
  .playlist-title { font-size: 25px; }
  .playlist-description { font-size: 12px; line-height: 1.35; -webkit-line-clamp: 2; }
  .playlist-detail { margin-top: 4px; padding: 7px 11px; font-size: 12px; }
  .seasons { gap: 6px; margin-bottom: 8px; }
  .seasons button { padding: 7px 11px; font-size: 12px; }
  .episodes { gap: 6px; }
  .episode { gap: 10px; padding: 5px; }
  .episode-thumb { width: 100px; }
  .episode strong { font-size: 13px; }
  .episode small { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }

#subnav {
  display: flex; align-items: center; gap: 4px; flex: none;
  width: max-content; max-width: 100%; margin: 0 auto 18px; padding: 4px;
  overflow-x: auto; border-radius: 100px; background: var(--glass);
  scrollbar-width: none;
}
#subnav::-webkit-scrollbar { display: none; }
#subnav .tab-btn { min-height: 40px; padding: 8px 18px; border-radius: 100px; font-size: 14px; }
#subnav #back { background: transparent; color: #d5d6de; line-height: 1.4; }
#subnav #back:focus { background: #fff; color: #161821; }
@media (max-height: 600px) and (min-width: 800px) {
  #subnav { margin-bottom: 10px; padding: 3px; }
  #subnav .tab-btn { min-height: 32px; padding: 6px 12px; font-size: 12px; }
}

#searchSubmit { flex: none; min-height: 42px; padding: 10px 20px; border-radius: 8px; font-weight: 650; }

.context-chevron { opacity: .6; font-size: 17px; }
.profile-context, .source-context { padding-inline: clamp(8px, 1vw, 14px); }
.youtube-category { min-width: 0; width: clamp(190px, 18vw, 270px); }
.youtube-playlist .poster-image { aspect-ratio: 16 / 9; }
.youtube-category .group-card { width: 100%; }
.youtube-category-form { max-width: 560px; margin: 0 auto; padding: 24px; border-radius: 16px; background: var(--glass); }
.youtube-category-form label { display: block; margin-bottom: 20px; }
.youtube-category-form input { display: block; width: 100%; min-height: 48px; margin-top: 8px; padding: 12px; border: 1px solid #ffffff30; border-radius: 8px; background: #0b0d1680; }
.category-error { margin-top: 16px; color: #fda4af; }

/* Library membership replaces the poster beside the episode list. */
.content-profiles { width: 100%; margin-top: 8px; }
.membership-heading { margin: 0 0 12px; font-size: 14px; font-weight: 650; color: var(--muted); }
.membership-hint { margin: 8px 0 14px; font-size: 14px; color: var(--muted); }
.membership-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.profile-membership { display: flex; align-items: center; gap: 10px; min-height: 48px; width: 100%; padding: 7px 10px; border: 1px solid transparent; border-radius: 10px; background: #ffffff06; text-align: left; }
.profile-membership .profile-initial { width: 32px; height: 32px; flex-basis: 32px; font-size: 12px; }
.profile-membership strong { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 15px; font-weight: 650; }
.membership-check { color: var(--profile-color); font-size: 14px; }
.membership-action { flex: none; margin-left: auto; color: var(--muted); font-size: 13px; }
.profile-membership[aria-pressed="true"] { border-color: #ffffff20; background: #ffffff0f; }
.profile-membership[aria-pressed="true"] .membership-action { color: var(--ink); }
.profile-membership:hover { background: #ffffff18; }
.profile-membership:focus { box-shadow: inset 0 0 0 2px white; }
.profile-membership:disabled { opacity: .55; }
.resume-label { font-size: 13px; color: #c4c6d2; line-height: 1.4; }
@media (max-width: 900px), (max-height: 600px) {
  .profile-membership { padding: 8px; gap: 8px; }
  .profile-membership strong, .membership-heading { font-size: 14px; }
  .membership-hint { font-size: 12px; }
  .profile-membership .profile-initial { width: 32px; height: 32px; flex-basis: 32px; font-size: 12px; }
}

/* Compact profile/provider lists keep the current screen underneath. */
.context-picker { position: fixed; margin: 0; width: min(290px, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 12px; border: 1px solid #ffffff24; border-radius: 14px; background: #202333f5; color: var(--ink); box-shadow: 0 16px 50px #0008; }
.context-picker::backdrop { background: #0003; backdrop-filter: none; }
.context-picker h2 { padding: 4px 8px 10px; font-size: 15px; color: var(--muted); }
.context-options { max-height: min(55vh, 360px); overflow-y: auto; padding: 2px; }
.context-option { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 8px; background: transparent; text-align: left; font-size: 15px; }
.context-option[aria-pressed=true] { background: #ffffff12; }
.context-option:hover { background: #ffffff20; }
.context-check { flex: none; color: var(--profile-color); }
