:root {
  --bg: #141414;
  --bg2: #1f1f1f;
  --bg3: #2b2b2b;
  --text: #f2f2f2;
  --muted: #9a9a9a;
  --red: #e50914;
  --green: #46d369;
  --radius: 10px;
  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { min-height: 100vh; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; color: inherit; }
img { display: block; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
#login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
#login .logo { color: var(--red); font-weight: 800; font-size: 34px; letter-spacing: 1px; margin-bottom: 6px; }
#login p.sub { color: var(--muted); margin: 0 0 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input { width: 100%; background: var(--bg3); border: 1px solid #3a3a3a; border-radius: 8px; padding: 13px 14px; font-size: 16px; }
.field input:focus { outline: 2px solid var(--red); border-color: transparent; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 20px; border-radius: 8px; font-weight: 700; font-size: 16px; }
.btn.primary { background: var(--red); color: #fff; }
.btn.light { background: #fff; color: #000; }
.btn.grey { background: rgba(109, 109, 110, 0.7); color: #fff; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.6; }
.error { color: #ff6b6b; font-size: 14px; min-height: 20px; margin: 4px 0 12px; }
.note { color: var(--muted); font-size: 12px; margin-top: 18px; line-height: 1.5; }

/* ---------- Shell ---------- */
#app { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 12px); }
header.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: calc(10px + var(--safe-t)) 16px 10px; background: linear-gradient(#000c, #0000); backdrop-filter: blur(8px); }
header.top .brand { color: var(--red); font-weight: 800; font-size: 22px; letter-spacing: 1px; }
header.top .spacer { flex: 1; }
header.top .nav { display: none; gap: 18px; }
header.top .nav button { color: #d0d0d0; font-size: 15px; padding: 6px 2px; }
header.top .nav button.on { color: #fff; font-weight: 700; }
.iconbtn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; }

nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: #0d0d0df2; border-top: 1px solid #262626; padding-bottom: var(--safe-b); backdrop-filter: blur(10px); }
nav.tabs button { flex: 1; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; }
nav.tabs button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav.tabs button.on { color: #fff; }

@media (min-width: 900px) {
  nav.tabs { display: none; }
  header.top .nav { display: flex; }
  #app { padding-bottom: 40px; }
}

main { min-height: 60vh; }
.page { padding: 0 0 20px; }
.pad { padding: 0 16px; }
h2.title { font-size: 20px; margin: 18px 16px 10px; }
.empty { color: var(--muted); padding: 40px 24px; text-align: center; line-height: 1.5; }
.spinner { width: 28px; height: 28px; border: 3px solid #333; border-top-color: var(--red); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Hero ---------- */
.hero { position: relative; height: 62vh; min-height: 380px; max-height: 560px; margin-top: -58px; display: flex; align-items: flex-end; overflow: hidden; }
.hero .bg { position: absolute; inset: 0; background-size: cover; background-position: center top; filter: saturate(1.1); }
.hero .bg.blur { filter: blur(22px) brightness(0.6); transform: scale(1.15); }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, var(--bg) 4%, #14141400 55%), linear-gradient(to bottom, #0009, #0000 30%); }
.hero .info { position: relative; z-index: 2; padding: 0 16px 22px; width: 100%; }
.hero h1 { font-size: 30px; margin: 0 0 6px; text-shadow: 0 2px 12px #000a; }
.hero .meta { color: #d6d6d6; font-size: 14px; margin-bottom: 14px; }
.hero .actions { display: flex; gap: 10px; }
.hero .poster-fg { position: absolute; z-index: 2; left: 50%; top: 84px; transform: translateX(-50%); width: 140px; aspect-ratio: 2/3; object-fit: cover; border-radius: 8px; box-shadow: 0 8px 30px #000a; }
@media (min-width: 700px) { .hero .poster-fg { left: auto; right: 16px; top: auto; bottom: 22px; transform: none; width: 170px; } .hero h1 { font-size: 40px; } }

/* ---------- Rows & cards ---------- */
.row { margin: 4px 0 8px; }
.row h3 { margin: 14px 16px 8px; font-size: 17px; font-weight: 700; }
.rail { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 6px; scroll-snap-type: x proximity; scroll-padding: 0 16px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.rail::-webkit-scrollbar { display: none; }
.card { flex: 0 0 auto; width: 112px; scroll-snap-align: start; text-align: left; display: flex; flex-direction: column; justify-content: flex-start; align-self: flex-start; padding: 0; }
.card .ph { width: 100%; aspect-ratio: 2/3; border-radius: 6px; background: var(--bg3); object-fit: cover; }
.card .nm { font-size: 12px; margin-top: 5px; color: #d0d0d0; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
@media (min-width: 700px) { .card { width: 150px; } }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px 8px; padding: 0 16px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); } }
.grid .card { width: auto; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px; scrollbar-width: none; position: sticky; top: calc(54px + var(--safe-t)); z-index: 10; background: linear-gradient(var(--bg) 70%, #1400); }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; padding: 7px 14px; border-radius: 999px; background: var(--bg3); color: #ddd; font-size: 14px; white-space: nowrap; }
.chip.on { background: #fff; color: #000; font-weight: 700; }
.chip small { opacity: 0.6; margin-left: 4px; }
.search { margin: 4px 16px 0; }
.search input { width: 100%; background: var(--bg3); border: 0; border-radius: 8px; padding: 11px 14px; font-size: 16px; }

/* ---------- Sports ---------- */
.game { margin: 0 16px 10px; background: var(--bg2); border-radius: var(--radius); padding: 12px; }
.game .teams { display: flex; align-items: center; gap: 12px; }
.game .logos { display: flex; flex-direction: column; gap: 6px; }
.game .logos img { width: 30px; height: 30px; object-fit: contain; }
.game .names { flex: 1; min-width: 0; }
.game .names div { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game .names div.away { color: #cfcfcf; font-weight: 500; }
.game .status { text-align: right; font-size: 12px; color: var(--muted); }
.game .status .live { color: #fff; background: var(--red); border-radius: 4px; padding: 2px 6px; font-weight: 700; font-size: 11px; display: inline-block; margin-bottom: 4px; }
.game .feeds { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.game .feeds .btn { padding: 8px 14px; font-size: 14px; border-radius: 6px; }
.game .nofeed { margin-top: 10px; color: var(--muted); font-size: 13px; }
.game.dim { opacity: 0.65; }
.day { margin: 18px 16px 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; font-weight: 700; }
.badge { font-size: 10px; border: 1px solid #fff8; border-radius: 3px; padding: 0 4px; margin-left: 6px; }

/* ---------- Live TV ---------- */
.seg { display: flex; margin: 12px 16px; background: var(--bg3); border-radius: 8px; padding: 3px; }
.seg button { flex: 1; padding: 8px; border-radius: 6px; font-size: 14px; color: #ccc; }
.seg button.on { background: #555; color: #fff; font-weight: 700; }
.chan { display: flex; align-items: center; gap: 12px; padding: 10px 16px; width: 100%; text-align: left; border-bottom: 1px solid #202020; }
.chan .lg { width: 48px; height: 48px; border-radius: 8px; background: var(--bg3); object-fit: contain; flex: 0 0 auto; display: grid; place-items: center; font-weight: 700; color: var(--muted); }
.chan .tx { flex: 1; min-width: 0; }
.chan .tx b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chan .tx span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chan .tx span.now { color: #cfcfcf; }
.chan .idtag { font-size: 11px; color: #777; }
.grouphead { margin: 16px 16px 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; font-weight: 700; }

/* ---------- Sheet ---------- */
#sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: #000a; }
#sheet .panel { background: var(--bg2); width: 100%; max-width: 760px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding-bottom: calc(20px + var(--safe-b)); animation: up 0.2s ease-out; position: relative; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 900px) { #sheet { align-items: center; } #sheet .panel { border-radius: 14px; max-height: 88vh; } }
#sheet .close { position: absolute; top: 10px; right: 10px; z-index: 5; background: #000a; width: 34px; height: 34px; border-radius: 50%; font-size: 18px; }
.sh-head { position: relative; min-height: 190px; display: flex; align-items: flex-end; }
.sh-head .bg { position: absolute; inset: 0; background-size: cover; background-position: center top; }
.sh-head::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, var(--bg2) 2%, #1f1f1f00 70%); }
.sh-head .tt { position: relative; z-index: 2; padding: 0 16px 8px; }
.sh-head h2 { margin: 0; font-size: 24px; }
.sh-body { padding: 0 16px; }
.sh-body .meta { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }
.sh-body p { line-height: 1.5; color: #d8d8d8; font-size: 14px; }
.sh-body .actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
select.season { background: var(--bg3); border: 0; border-radius: 8px; padding: 10px 12px; font-size: 15px; color: #fff; margin: 8px 0; }
.ep { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid #2c2c2c; width: 100%; text-align: left; }
.ep .n { width: 26px; color: var(--muted); text-align: center; flex: 0 0 auto; }
.ep .t { flex: 1; min-width: 0; }
.ep .t b { display: block; font-size: 14px; font-weight: 600; }
.ep .t span { color: var(--muted); font-size: 12px; }
.ep .pl { font-size: 18px; }
.kv { color: var(--muted); font-size: 12px; word-break: break-all; margin-top: 8px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 18px); transform: translateX(-50%); background: #fff; color: #000; padding: 10px 16px; border-radius: 8px; z-index: 80; font-size: 14px; font-weight: 600; max-width: 90vw; }
@media (min-width: 900px) { #toast { bottom: 30px; } }
