:root {
  --bg: #0e1014;
  --surface: #161920;
  --surface-2: #1e222c;
  --surface-3: #272c38;
  --border: #2a2f3b;
  --text: #e9ecf2;
  --muted: #8e95a4;
  --accent: #7c9cff;
  --accent-ink: #0b0d12;
  --danger: #ff7a7a;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h1 { font-size: 26px; margin: 4px 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 28px 0 12px; display: flex; align-items: baseline; gap: 12px; }
h2 a { font-size: 13px; color: var(--accent); font-weight: 500; }
button { font: inherit; color: inherit; cursor: pointer; }
select, input { font: inherit; color: inherit; }

/* Layout */
.app { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 2px;
  padding: 18px 12px; background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 12px 20px; font-weight: 700; font-size: 18px; color: var(--accent); }
.brand span { color: var(--text); }
.nav { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav svg { width: 20px; height: 20px; }
.nav:hover { background: var(--surface-2); color: var(--text); }
.nav.active { background: var(--surface-3); color: var(--text); }
.nav.active svg { color: var(--accent); }
.sidebar-foot { margin-top: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; color: var(--muted); }
.sync-status strong { color: var(--text); font-weight: 600; }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-align: left; font-size: 12.5px; }
.link:disabled { color: var(--muted); cursor: default; }
.toggle { display: flex; gap: 8px; align-items: center; cursor: pointer; }

main { padding: 0 32px 64px; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 10; padding: 16px 0 14px; background: linear-gradient(var(--bg) 75%, transparent); }
.search { display: flex; align-items: center; gap: 10px; max-width: 640px; padding: 0 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; }
.search:focus-within { border-color: var(--accent); }
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; padding: 11px 0; background: none; border: 0; outline: 0; }

/* Controls */
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.btn.fav-on svg { fill: #ffc857; stroke: #ffc857; }
.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; border: 0; background: transparent; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.icon-btn svg { width: 22px; height: 22px; }
select {
  padding: 8px 30px 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  appearance: none; max-width: 100%;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: transparent; font-size: 13px; color: var(--muted); }
.chip:hover { color: var(--text); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 16px; }
.grid.live { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.shelf { display: grid; grid-auto-flow: column; grid-auto-columns: 150px; gap: 16px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: thin; }
.card { display: block; min-width: 0; cursor: pointer; }
.poster {
  position: relative; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border); transition: transform .15s, border-color .15s;
}
.card:hover .poster { transform: translateY(-2px); border-color: var(--accent); }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card.live .poster { aspect-ratio: 16 / 10; background: #fff1; }
.card.live .poster img { object-fit: contain; padding: 14%; }
.placeholder { width: 100%; height: 100%; display: grid; place-items: center; padding: 10px; text-align: center; font-weight: 700; color: var(--muted); font-size: 15px; line-height: 1.2; }
.badge { position: absolute; top: 6px; font-size: 10.5px; font-weight: 700; padding: 2px 6px; border-radius: 4px; background: rgba(0, 0, 0, .72); letter-spacing: .02em; }
.badge.q { right: 6px; }
.badge.v { left: 6px; color: var(--muted); }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0, 0, 0, .6); }
.progress i { display: block; height: 100%; background: var(--accent); }
.card-fav {
  position: absolute; right: 6px; bottom: 8px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0, 0, 0, .7); color: #fff; cursor: pointer;
  opacity: 0; transition: opacity .15s, transform .15s;
}
.card-fav svg { width: 16px; height: 16px; }
.card:hover .card-fav, .card-fav:focus-visible, .card-fav.on { opacity: 1; }
.card-fav:hover { transform: scale(1.1); }
.card-fav.on svg { fill: #ffc857; stroke: #ffc857; }
@media (hover: none) { .card-fav { opacity: 1; } }
.card .title { margin-top: 8px; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Ratings */
.score { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; vertical-align: -1px; }
.score .imdb { background: #f5c518; color: #000; font-size: 9px; font-weight: 800; line-height: 12px; padding: 0 3px; border-radius: 2px; letter-spacing: .02em; }
.tomato { width: 12px; height: 12px; stroke: none; flex: none; }
.meta .score .imdb { font-size: 10.5px; line-height: 15px; padding: 0 4px; }
.meta .tomato { width: 15px; height: 15px; }
a.score:hover { color: var(--text); }
.ratings-status { margin-top: 4px; font-size: 11.5px; }
.awards { display: flex; align-items: center; gap: 6px; margin: -6px 0 12px; font-size: 13.5px; color: #d9c27a; }
.awards:empty { display: none; }
.trophy { width: 16px; height: 16px; flex: none; }

/* Home selection */
.selection { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 28px 0 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.selection.on { border-color: #7c9cff66; }
.selection select:disabled { opacity: .45; }
.switch { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; margin-right: 6px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 36px; height: 20px; border-radius: 999px; background: var(--surface-3); position: relative; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); background: var(--accent-ink); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.notice.slim { padding: 8px 0 0; font-size: 13.5px; }

/* Versions filter on the title page */
.versions-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 24px; }
.version-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; font-size: 13.5px; color: var(--muted); }
.version-filter select { padding-top: 5px; padding-bottom: 5px; font-size: 13.5px; }
.version-filter select:disabled, .version-filter input:disabled + * { opacity: .45; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.switch.small { font-weight: 500; gap: 8px; margin: 0; }
.switch.small span { width: 30px; height: 17px; }
.switch.small span::after { width: 11px; height: 11px; }
.switch.small input:checked + span::after { transform: translateX(13px); }
.variants tr.dimmed td { opacity: .5; }

.more { display: grid; place-items: center; padding: 28px; color: var(--muted); }
.empty, .notice { padding: 40px 0; color: var(--muted); }
.notice.error { color: var(--danger); }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Entry page */
.hero { position: relative; margin: 0 -32px; padding: 28px 32px 32px; overflow: hidden; }
.hero-bg { position: absolute; inset: 0; background-size: cover; background-position: center 20%; opacity: .22; filter: blur(2px); }
.hero-bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 30%, var(--bg)), linear-gradient(90deg, var(--bg), transparent 70%); }
.hero-inner { position: relative; display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 32px; align-items: start; }
.hero-inner.live { grid-template-columns: 210px minmax(0, 1fr); }
.hero .poster { width: 210px; }
.hero.live .poster { aspect-ratio: 16 / 10; background: #fff1; }
.hero.live .poster img { object-fit: contain; padding: 14%; }
.hero h1 { font-size: 32px; margin: 0 0 8px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.meta .pill { padding: 1px 7px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; font-weight: 700; color: var(--text); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 8px; }
.plot { max-width: 760px; color: #cfd3dc; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13.5px; margin-top: 14px; max-width: 760px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.variants { width: 100%; border-collapse: collapse; font-size: 14px; }
.variants td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.variants tr:hover td { background: var(--surface); }
.variants .raw { color: var(--muted); font-size: 12.5px; }
.variants .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--surface-3); color: #cfd3dc; }
.tag.q { background: #7c9cff26; color: var(--accent); }
.variants .go { text-align: right; white-space: nowrap; }

.season-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; align-items: center; }
.episodes { display: flex; flex-direction: column; gap: 2px; }
.episode { display: grid; grid-template-columns: 44px 120px minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 10px; border-radius: 8px; }
.episode:hover { background: var(--surface); }
.episode .num { color: var(--muted); font-size: 18px; font-weight: 700; text-align: center; }
.episode .thumb { width: 120px; aspect-ratio: 16 / 9; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.episode .thumb img { width: 100%; height: 100%; object-fit: cover; }
.episode .ep-title { font-weight: 600; }
.episode .ep-plot { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.episode .ep-actions { display: flex; gap: 6px; }
.episode.current .num { color: var(--accent); }

/* Player */
.player { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; flex-direction: column; }
.player[hidden] { display: none; }
.player-bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: #0b0c10; border-bottom: 1px solid #1c1f27; }
.player-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.player-title strong, .player-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-title span { font-size: 12.5px; color: var(--muted); }
.player-bar select { max-width: 280px; }
.player-stage { position: relative; flex: 1; min-height: 0; }
/* Pinned to the stage: a 4K video must not grow the page past the window (its controls would be off screen). */
.player video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.player-msg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(520px, 90vw);
  padding: 22px 24px; border-radius: var(--radius); background: rgba(22, 25, 32, .96); border: 1px solid var(--border); text-align: center;
}
.player-msg p { margin: 0 0 14px; color: #cfd3dc; }
.player-msg .actions { justify-content: center; margin: 0; }
.player-msg .spinner { margin: 0 auto 12px; }

/* TV guide */
.guide { --guide-channel: 190px; position: relative; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.guide-row { display: grid; grid-template-columns: var(--guide-channel) minmax(0, 1fr); border-top: 1px solid var(--border); min-height: 64px; }
.guide-row:first-child { border-top: 0; }
.guide-head { min-height: 34px; background: var(--surface-2); }
.guide-channel {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 0; border-right: 1px solid var(--border);
  background: var(--surface-2); text-align: left; min-width: 0;
}
button.guide-channel:hover { background: var(--surface-3); }
.guide-now { font-size: 12.5px; font-weight: 700; color: var(--accent); }
.guide-logo { flex: none; width: 44px; height: 30px; display: grid; place-items: center; border-radius: 4px; background: #fff1; overflow: hidden; }
.guide-logo img { max-width: 90%; max-height: 90%; object-fit: contain; }
.guide-logo .placeholder { font-size: 10px; padding: 2px; }
.guide-label { display: flex; flex-direction: column; min-width: 0; }
.guide-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.guide-home { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.guide-track { position: relative; min-width: 0; overflow: hidden; }
.guide-mark { position: absolute; top: 9px; transform: translateX(4px); font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.guide-mark.hour { color: var(--text); font-weight: 600; }
.guide-mark::before { content: ""; position: absolute; left: -4px; top: -9px; height: 34px; border-left: 1px solid var(--border); }
.guide-program {
  position: absolute; top: 6px; bottom: 6px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); text-align: left; overflow: hidden; display: flex; flex-direction: column; justify-content: center; min-width: 0;
}
.guide-program:hover { border-color: var(--accent); z-index: 1; }
.guide-program.live { background: #7c9cff1f; border-color: #7c9cff66; }
.guide-program.past { opacity: .5; }
.guide-progress { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); }
.guide-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.guide-time { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.guide-empty { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 13px; color: var(--muted); }
.guide-nowline { position: absolute; top: 0; bottom: 0; width: 2px; background: #ff6b6b; pointer-events: none; z-index: 2; }
.guide-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.guide-foot label { display: inline-flex; align-items: center; gap: 8px; }
.guide-foot select { padding-top: 4px; padding-bottom: 4px; font-size: 12.5px; }
@media (max-width: 820px) {
  .guide { overflow-x: auto; }
  .guide-row { min-width: 760px; }
  .guide { --guide-channel: 130px; }
}

/* Sign-in page */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px; padding: 28px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.login .brand { padding: 0 0 12px; }
.login label { font-size: 13px; color: var(--muted); }
.login input { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); outline: 0; }
.login input:focus { border-color: var(--accent); }
.login .btn { justify-content: center; margin-top: 6px; }
.login-error { margin: 4px 0 0; color: var(--danger); font-size: 13.5px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200;
  padding: 10px 18px; border-radius: 8px; background: var(--surface-3); border: 1px solid var(--border); box-shadow: 0 8px 30px #0008;
}

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 6px 10px; }
  .brand span, .nav span { display: none; }
  .sidebar-foot { display: none; }
  main { padding: 0 16px 48px; }
  .topbar { top: 54px; }
  .hero { margin: 0 -16px; padding: 20px 16px; }
  .hero-inner, .hero-inner.live { grid-template-columns: 110px minmax(0, 1fr); gap: 16px; }
  .hero .poster { width: 110px; }
  .hero h1 { font-size: 22px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 16px 10px; }
  .episode { grid-template-columns: 32px minmax(0, 1fr) auto; }
  .episode .thumb { display: none; }
  .variants .raw { display: none; }
}
