:root {
  color-scheme: dark;
  --bg: #090c14;
  --panel: #101522;
  --panel-2: #171e2d;
  --text: #f5f3f8;
  --muted: #a7afc0;
  --accent: #ffb800;
  --accent-2: #ffd45f;
  --green: #62e6a7;
  --danger: #ff6b75;
  --line: rgba(255, 255, 255, .1);
  --sidebar: 248px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { min-height: 100vh; margin: 0; color: var(--text); background: radial-gradient(circle at 85% -10%, #252033 0, transparent 38%), var(--bg); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 20; width: var(--sidebar); padding: 28px 20px;
  display: flex; flex-direction: column; background: rgba(12, 16, 27, .94); border-right: 1px solid var(--line);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
}
.brand { display: flex; gap: 12px; align-items: center; color: var(--text); text-decoration: none; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; color: #151008; background: linear-gradient(135deg, var(--accent-2), #ff8f00); font-size: 25px; font-weight: 1000; box-shadow: 0 10px 30px rgba(255, 184, 0, .18); }
.brand-mark.large { width: 64px; height: 64px; border-radius: 20px; font-size: 38px; }
.brand strong { display: block; font-size: 21px; letter-spacing: -.5px; }
.brand small { color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: 2.2px; }
.nav-list { display: grid; gap: 8px; margin-top: 70px; }
.nav-item { width: 100%; min-height: 50px; padding: 0 14px; display: flex; align-items: center; gap: 14px; border: 0; border-radius: 14px; color: var(--muted); background: transparent; text-align: left; cursor: pointer; font-weight: 700; }
.nav-item span { width: 24px; color: currentColor; font-size: 25px; text-align: center; }
.nav-item:hover, .nav-item:focus-visible { color: var(--text); background: rgba(255,255,255,.055); outline: none; }
.nav-item.active { color: var(--accent-2); background: rgba(255,184,0,.1); }
.sidebar-footer { margin-top: auto; }
.connection-state { display: flex; align-items: center; gap: 8px; padding: 18px 14px 2px; color: var(--muted); font-size: 12px; }
.connection-state i { width: 8px; height: 8px; border-radius: 50%; background: #687083; }
.connection-state i.online { background: var(--green); box-shadow: 0 0 14px var(--green); }

.mobile-header, .bottom-nav { display: none; }
main { position: relative; min-height: 100vh; margin-left: var(--sidebar); padding: 46px clamp(28px, 4vw, 72px) 80px; }
.view { display: none; animation: appear .2s ease; }
.view.active { display: block; }
@keyframes appear { from { opacity: 0; transform: translateY(5px); } }
.page-heading { min-height: 74px; margin-bottom: 32px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.eyebrow { margin: 0 0 6px; color: var(--accent); text-transform: uppercase; letter-spacing: 2px; font-size: 11px; font-weight: 900; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(32px, 4vw, 52px); letter-spacing: -2px; }
h2 { margin: 0 0 12px; font-size: clamp(27px, 4vw, 44px); letter-spacing: -1.3px; }
h3 { margin: 0; font-size: 22px; }

button { border: 0; cursor: pointer; }
.primary-button, .secondary-button, .danger-button, .back-button { min-height: 46px; padding: 0 20px; border-radius: 13px; font-weight: 850; }
.secondary-button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.primary-button { color: #171008; background: linear-gradient(135deg, var(--accent-2), var(--accent)); }
.primary-button:hover { filter: brightness(1.08); }
.primary-button:disabled { opacity: .4; cursor: not-allowed; }
.secondary-button { color: var(--text); border: 1px solid var(--line); background: var(--panel-2); }
.danger-button { color: var(--danger); border: 1px solid rgba(255,107,117,.25); background: rgba(255,107,117,.08); }
.text-button { min-height: 42px; color: var(--muted); background: transparent; font-weight: 700; }
.wide { width: 100%; }
.icon-button { width: 44px; height: 44px; border-radius: 13px; color: var(--text); background: var(--panel-2); }

.hero { position: relative; min-height: clamp(350px, 50vw, 590px); margin-bottom: 52px; display: flex; align-items: flex-end; overflow: hidden; isolation: isolate; border: 1px solid var(--line); border-radius: 28px; background: var(--panel); box-shadow: 0 28px 80px rgba(0,0,0,.28); }
.hero-backdrop { position: absolute; inset: 0; z-index: -2; width: 100%; height: 100%; object-fit: cover; }
.hero::after { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(90deg, rgba(6,8,14,.98) 0%, rgba(6,8,14,.72) 45%, rgba(6,8,14,.12) 80%), linear-gradient(0deg, rgba(6,8,14,.9), transparent 55%); }
.hero-copy { width: min(680px, 80%); padding: clamp(28px, 5vw, 64px); }
.hero h2 { font-size: clamp(40px, 7vw, 78px); line-height: .95; }
.hero-meta, .detail-meta { display: flex; flex-wrap: wrap; gap: 9px 16px; color: var(--muted); font-weight: 650; }
.hero-overview { display: -webkit-box; max-width: 610px; margin: 20px 0 26px; overflow: hidden; color: #d7d9e0; line-height: 1.6; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.availability { color: var(--green); }

.media-section { margin: 0 0 48px; }
.section-heading { margin-bottom: 18px; display: flex; justify-content: space-between; align-items: end; }
.section-heading h2 { margin: 0; font-size: 27px; }
.media-row { display: grid; grid-auto-flow: column; grid-auto-columns: clamp(150px, 17vw, 215px); gap: 18px; overflow-x: auto; padding: 3px 3px 18px; scroll-snap-type: x proximity; scrollbar-width: thin; scrollbar-color: #394154 transparent; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 22px; }
.discover-filters { display: flex; gap: 10px; margin: -8px 0 30px; padding: 3px 2px 10px; overflow-x: auto; scrollbar-width: thin; }
.filter-chip { flex: 0 0 auto; min-height: 43px; padding: 0 18px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--panel); font-weight: 800; }
.filter-chip:hover, .filter-chip:focus-visible { color: var(--text); border-color: rgba(255,184,0,.6); outline: 0; }
.filter-chip.active { color: #171008; border-color: transparent; background: linear-gradient(135deg, var(--accent-2), var(--accent)); }
.advanced-filters { margin: -10px 0 28px; padding: 18px; display: grid; grid-template-columns: repeat(3, minmax(160px, 1fr)) auto; gap: 14px; align-items: end; border: 1px solid var(--line); border-radius: 18px; background: rgba(16,21,34,.78); }
.advanced-filters label { min-width: 0; display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 800; }
.advanced-filters select { width: 100%; min-height: 46px; }
.advanced-reset { min-height: 46px; }
.provider-attribution { grid-column: 1/-1; margin: -2px 0 0; color: var(--muted); font-size: 11px; }
.discover-grid-heading { margin: 0 0 20px; display: flex; align-items: baseline; justify-content: space-between; gap: 18px; }
.discover-grid-heading h2 { margin: 0; font-size: 27px; }
.discover-grid-heading span { color: var(--muted); font-weight: 700; }
.discover-grid { align-items: start; }
.media-card { position: relative; min-width: 0; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; color: var(--text); background: var(--panel); text-align: left; scroll-snap-align: start; box-shadow: 0 12px 28px rgba(0,0,0,.16); transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
.media-card:hover, .media-card:focus-visible { transform: translateY(-5px); border-color: rgba(255,184,0,.65); outline: 0; box-shadow: 0 18px 38px rgba(0,0,0,.34); }
.poster-wrap { position: relative; aspect-ratio: 2 / 3; overflow: hidden; background: linear-gradient(140deg, #242b3b, #111622); }
.poster-wrap img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s ease; }
.media-card:hover img { transform: scale(1.035); }
.poster-fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 18px; color: #7f899d; text-align: center; font-weight: 850; }
.available-dot { position: absolute; top: 10px; right: 10px; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; color: #07160f; background: var(--green); font-size: 13px; font-weight: 1000; box-shadow: 0 4px 14px rgba(0,0,0,.4); }
.card-copy { padding: 14px; }
.card-title { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 850; }
.card-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 7px; color: var(--muted); font-size: 13px; }
.empty-state { grid-column: 1/-1; min-height: 220px; display: grid; place-items: center; padding: 30px; border: 1px dashed var(--line); border-radius: 20px; color: var(--muted); text-align: center; }

.search-form { margin-bottom: 34px; display: grid; grid-template-columns: 1fr auto auto; gap: 12px; }
.search-box { min-height: 54px; display: flex; align-items: center; gap: 12px; padding: 0 18px; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); }
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,184,0,.12); }
.search-box span { color: var(--muted); font-size: 25px; }
.search-box input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 17px; }
select { min-height: 54px; padding: 0 42px 0 16px; border: 1px solid var(--line); border-radius: 15px; color: var(--text); background: var(--panel); }

dialog { padding: 0; color: var(--text); border: 1px solid var(--line); background: var(--panel); box-shadow: 0 30px 100px rgba(0,0,0,.65); }
dialog::backdrop { background: rgba(2,4,9,.78); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.sheet-dialog { width: min(520px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); padding: 34px; overflow: auto; border-radius: 26px; }
.pair-dialog form { display: grid; gap: 14px; }
.dialog-brand { margin-bottom: 6px; }
.pair-dialog p:not(.eyebrow):not(.form-error) { margin: 0 0 10px; color: var(--muted); line-height: 1.55; }
.pair-hint { padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.035); font-size: 13px; }
.pair-dialog label { color: #d8dbe3; font-size: 13px; font-weight: 800; }
.pair-code { width: 100%; height: 68px; padding: 0 18px; border: 1px solid var(--line); border-radius: 16px; outline: none; color: var(--text); background: #0a0e18; text-align: center; letter-spacing: 14px; font-size: 30px; font-weight: 900; }
.pair-code:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,184,0,.12); }
.form-error { min-height: 19px; margin: 0; color: var(--danger); font-size: 13px; }
.floating-close { position: absolute; top: 18px; right: 18px; z-index: 4; width: 44px; height: 44px; border-radius: 50%; color: var(--text); background: rgba(6,8,14,.78); font-size: 28px; backdrop-filter: blur(12px); }

.details-dialog { width: min(1100px, calc(100vw - 32px)); max-width: 1100px; max-height: calc(100dvh - 32px); overflow: auto; border-radius: 28px; }
.detail-backdrop { position: relative; min-height: 330px; overflow: hidden; background: #111622; }
.detail-backdrop > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .62; }
.detail-backdrop::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, var(--panel) 0, transparent 90%), linear-gradient(90deg, rgba(16,21,34,.86), transparent 70%); }
.detail-title { position: absolute; left: clamp(24px, 5vw, 58px); right: 70px; bottom: 22px; z-index: 1; }
.detail-title h2 { max-width: 780px; font-size: clamp(36px, 6vw, 68px); line-height: 1; }
.detail-body { padding: 28px clamp(24px, 5vw, 58px) 50px; }
.detail-overview { max-width: 850px; color: #c8cdd8; line-height: 1.65; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 24px 0 34px; }
.season-tools { margin: 36px 0 18px; display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.episode-list { display: grid; gap: 12px; }
.episode-card { width: 100%; min-height: 104px; padding: 12px; display: grid; grid-template-columns: 145px 1fr auto; gap: 16px; align-items: center; border: 1px solid var(--line); border-radius: 16px; color: var(--text); background: #0d121e; text-align: left; }
.episode-card:hover { border-color: rgba(255,184,0,.5); }
.episode-still { width: 145px; aspect-ratio: 16/9; overflow: hidden; border-radius: 10px; background: #242b3b; }
.episode-still img { width: 100%; height: 100%; object-fit: cover; }
.episode-copy strong { display: block; margin-bottom: 6px; }
.episode-copy p { display: -webkit-box; margin: 0; overflow: hidden; color: var(--muted); font-size: 13px; line-height: 1.4; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.play-glyph { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: #171008; background: var(--accent); }

.player-dialog { width: 100vw; height: 100dvh; max-width: none; max-height: none; border: 0; background: #000; }
.player-topbar { height: 62px; padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); display: flex; align-items: center; gap: 20px; background: #080a0f; }
.player-topbar strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.back-button { min-height: 40px; padding: 0 14px; background: #202431; }
.player-frame-wrap { height: calc(100dvh - 62px - env(safe-area-inset-top)); }
.player-frame-wrap iframe { width: 100%; height: 100%; border: 0; background: #000; }

.settings-dialog { position: relative; }
.settings-section { padding: 22px 0; border-top: 1px solid var(--line); }
.settings-section:first-of-type { margin-top: 28px; }
.settings-section h3 { margin-bottom: 10px; font-size: 18px; }
.settings-section p { margin: 7px 0 15px; color: var(--muted); line-height: 1.5; }
.settings-section button { margin: 4px 8px 4px 0; }
.share-code-dialog { position: relative; text-align: center; }
.share-code-dialog > p:not(.eyebrow):not(.generated-code) { color: var(--muted); }
.generated-code { margin: 26px 0 10px; color: var(--accent-2); font-size: clamp(42px, 12vw, 68px); font-weight: 950; letter-spacing: .18em; line-height: 1; }
.share-actions { margin-top: 26px; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

.loading-overlay { position: fixed; inset: 0 0 0 var(--sidebar); z-index: 30; display: grid; place-content: center; gap: 14px; background: rgba(9,12,20,.65); text-align: center; backdrop-filter: blur(4px); }
.spinner { width: 44px; height: 44px; margin: auto; border: 4px solid rgba(255,255,255,.12); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: calc(var(--sidebar) + (100vw - var(--sidebar))/2); bottom: 28px; z-index: 100; max-width: min(520px, calc(100vw - 30px)); padding: 13px 18px; border: 1px solid var(--line); border-radius: 13px; opacity: 0; pointer-events: none; color: var(--text); background: #202634; transform: translate(-50%, 20px); transition: .2s ease; box-shadow: 0 12px 30px rgba(0,0,0,.35); }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 800px) {
  :root { --sidebar: 0px; }
  body { padding-top: env(safe-area-inset-top); }
  .sidebar { display: none; }
  .mobile-header { position: sticky; top: 0; z-index: 20; height: 70px; padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); background: rgba(9,12,20,.9); backdrop-filter: blur(20px); }
  .brand.compact { gap: 9px; }
  .brand.compact .brand-mark { width: 38px; height: 38px; border-radius: 12px; font-size: 22px; }
  .brand.compact strong { font-size: 19px; }
  main { margin: 0; padding: 24px 16px calc(92px + env(safe-area-inset-bottom)); }
  .bottom-nav { position: fixed; inset: auto 0 0; z-index: 25; height: calc(68px + env(safe-area-inset-bottom)); padding: 6px 8px env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(5,1fr); border-top: 1px solid var(--line); background: rgba(9,12,20,.94); backdrop-filter: blur(22px); }
  .bottom-nav button { display: grid; place-items: center; gap: 1px; border-radius: 12px; color: var(--muted); background: transparent; font-size: 10px; font-weight: 750; }
  .bottom-nav button span { font-size: 23px; line-height: 1; }
  .bottom-nav button.active { color: var(--accent); background: rgba(255,184,0,.08); }
  .page-heading { min-height: 54px; margin-bottom: 22px; }
  .page-heading h1 { font-size: 33px; letter-spacing: -1.3px; }
  .hero { min-height: 480px; border-radius: 22px; }
  .hero::after { background: linear-gradient(0deg, rgba(6,8,14,.98) 0%, rgba(6,8,14,.58) 62%, rgba(6,8,14,.12) 100%); }
  .hero-copy { width: 100%; padding: 26px 22px; }
  .hero h2 { font-size: 43px; }
  .hero-overview { -webkit-line-clamp: 2; }
  .media-row { grid-auto-columns: 43vw; gap: 13px; margin-right: -16px; }
  .media-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 13px; }
  .discover-filters { margin-right: -16px; }
  .advanced-filters { grid-template-columns: 1fr 1fr; padding: 15px; }
  .advanced-reset { width: 100%; }
  .search-form { grid-template-columns: 1fr auto; }
  .search-box { grid-column: 1/-1; }
  .sheet-dialog { padding: 28px 22px; border-radius: 24px; }
  .details-dialog { width: 100vw; height: 100dvh; max-height: none; border: 0; border-radius: 0; }
  .detail-backdrop { min-height: 400px; }
  .detail-backdrop::after { background: linear-gradient(0deg, var(--panel) 0%, transparent 85%); }
  .detail-title h2 { font-size: 42px; }
  .episode-card { grid-template-columns: 100px 1fr auto; gap: 10px; }
  .episode-still { width: 100px; }
  .episode-copy p { display: none; }
  .loading-overlay { inset: 70px 0 68px; }
  .toast { left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); }
}

@media (max-width: 390px) {
  .media-grid { grid-template-columns: 1fr 1fr; }
  .card-copy { padding: 11px; }
  .search-form { grid-template-columns: 1fr; }
  .search-box { grid-column: auto; }
  .search-form select, .search-form .primary-button { width: 100%; }
  .advanced-filters { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
