:root {
  --tv-bg: #07080c;
  --tv-bg-2: #10141c;
  --tv-card: #161c26;
  --tv-line: rgba(255, 255, 255, .08);
  --tv-text: #f4f7fb;
  --tv-muted: #8b95a7;
  --tv-accent: #3b9eff;
  --tv-accent-2: #1d6fd6;
  --tv-ok: #22c55e;
  --tv-focus: #7dd3fc;
  --tv-radius: 16px;
  --tv-safe-b: env(safe-area-inset-bottom, 0px);
  --tv-safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--tv-bg);
  color: var(--tv-text);
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}
button, input { font-family: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.tv-app {
  height: 100%;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(59, 158, 255, .18), transparent 50%),
    radial-gradient(800px 400px at 100% 0%, rgba(99, 102, 241, .12), transparent 45%),
    var(--tv-bg);
}

.tv-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--tv-safe-t)) 16px 10px;
  border-bottom: 1px solid var(--tv-line);
  flex-shrink: 0;
}
.tv-top #tvSearchOpen { margin-left: auto; }
.tv-brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  flex-shrink: 0;
  line-height: 0;
}
.tv-brand img {
  display: block;
  height: 36px;
  width: auto;
  max-width: min(220px, 72vw);
}
.tv-search {
  flex: 1;
  min-width: 0;
  height: 44px;
  border: 1px solid var(--tv-line);
  background: rgba(255,255,255,.04);
  color: var(--tv-text);
  border-radius: 12px;
  padding: 0 14px 0 40px;
  font-size: 16px;
  outline: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238b95a7' viewBox='0 0 16 16'><path d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.656a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/></svg>");
  background-repeat: no-repeat;
  background-position: 14px 50%;
}
.tv-search-over {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  background: var(--tv-bg);
}
.tv-search-over[hidden] { display: none; }
.tv-search-over-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--tv-safe-t)) 12px 10px;
  border-bottom: 1px solid var(--tv-line);
  flex-shrink: 0;
}
.tv-search-over-body {
  flex: 1;
  overflow: auto;
  padding: 8px 12px calc(16px + var(--tv-safe-b));
}
.tv-search-hit {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: var(--tv-card);
  color: #fff;
  text-align: left;
  padding: 12px 12px;
  border-radius: 14px;
  margin-bottom: 8px;
}
.tv-search-hit b { display: block; }
.tv-search-hit span { color: var(--tv-muted); font-size: 13px; }
.tv-search:focus { border-color: var(--tv-accent); box-shadow: 0 0 0 3px rgba(59,158,255,.25); }
.tv-count { color: var(--tv-muted); font-size: 13px; white-space: nowrap; }
.tv-icon-btn {
  width: 44px; height: 44px;
  border: 1px solid var(--tv-line);
  background: rgba(255,255,255,.04);
  color: var(--tv-text);
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 18px;
}

.tv-groups {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px 12px;
  scrollbar-width: none;
  flex-shrink: 0;
}
.tv-groups::-webkit-scrollbar { display: none; }
.tv-chip {
  flex: 0 0 auto;
  border: 1px solid var(--tv-line);
  background: var(--tv-card);
  color: var(--tv-text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}
.tv-chip.is-on, .tv-chip:focus-visible {
  background: linear-gradient(180deg, var(--tv-accent), var(--tv-accent-2));
  border-color: transparent;
  color: #fff;
}

.tv-main {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 16px 88px;
}
.tv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.tv-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--tv-card);
  border: 1px solid var(--tv-line);
  border-radius: var(--tv-radius);
  padding: 10px;
  text-align: left;
  color: inherit;
  min-height: 72px;
}
.tv-card.is-fav { box-shadow: inset 0 0 0 1px rgba(34,197,94,.35); }
.tv-logo {
  width: 52px; height: 52px; flex-shrink: 0;
  border-radius: 12px;
  background: #0b0f16;
  object-fit: contain;
  display: grid; place-items: center;
  font-weight: 800; color: var(--tv-accent);
}
.tv-logo img { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; }
.tv-meta { min-width: 0; flex: 1; }
.tv-name {
  display: block;
  font-weight: 800;
  font-size: 15px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tv-sub { color: var(--tv-muted); font-size: 12px; margin-top: 2px; }
.tv-star {
  border: 0; background: transparent; color: var(--tv-muted);
  font-size: 18px; padding: 4px;
}
.tv-star.is-on { color: #fbbf24; }

.tv-empty, .tv-boot {
  padding: 48px 16px;
  text-align: center;
  color: var(--tv-muted);
}

.tv-setup {
  align-self: center;
  width: min(460px, calc(100% - 24px));
  margin: max(24px, 8vh) auto 0;
  padding: 22px 16px 28px;
  background: rgba(16,20,28,.86);
  border: 1px solid var(--tv-line);
  border-radius: 24px;
  box-shadow: 0 24px 80px rgba(0,0,0,.45);
}
.tv-setup .tv-brand {
  display: flex;
  margin: 0 auto 14px;
}
.tv-setup .tv-brand img {
  height: 48px;
  max-width: min(260px, 100%);
}
.tv-setup-lead {
  color: var(--tv-muted);
  margin: 0 0 16px;
  text-align: center;
  font-size: 15px;
  line-height: 1.4;
}
.tv-pin {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 2.4vw, 12px);
  width: 100%;
  margin: 0 0 16px;
}
.tv-pin input {
  flex: 1 1 0;
  min-width: 0;
  width: auto;
  max-width: 52px;
  aspect-ratio: 1;
  height: auto;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(59,158,255,.45);
  background: #0b0f16;
  color: var(--tv-text);
  font-size: clamp(18px, 5vw, 24px);
  font-weight: 800;
  text-align: center;
  caret-color: var(--tv-accent);
}
.tv-pin input:focus {
  outline: none;
  border-color: var(--tv-accent);
  box-shadow: 0 0 0 3px rgba(59,158,255,.28);
}
.tv-setup h1 { margin: 8px 0 6px; font-size: 28px; }
.tv-setup p { color: var(--tv-muted); margin: 0 0 18px; line-height: 1.45; }
.tv-setup .tv-sub { margin-top: 14px; text-align: center; }
.tv-setup .tv-sub a { color: #7dd3fc; }
.tv-btn {
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--tv-accent), var(--tv-accent-2));
  color: #fff;
  font-weight: 800;
  font-size: 16px;
}
.tv-error { color: #fca5a5; min-height: 1.3em; margin: 8px 0 0; font-size: 14px; }
.tv-setup .tv-error { color: #f87171; }

.tv-player {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #000;
  display: none;
}
.tv-player.is-on { display: block; }
.tv-player video {
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
}
.tv-osd {
  position: absolute;
  inset: 0;
  display: flex;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
  background: linear-gradient(180deg, transparent 55%, rgba(0,0,0,.72) 100%);
}
.tv-osd.is-on { opacity: 1; }
.tv-osd.is-list {
  background: linear-gradient(90deg, rgba(0,0,0,.82) 0%, rgba(0,0,0,.2) 42%, transparent 58%),
              linear-gradient(180deg, rgba(0,0,0,.45) 0%, transparent 22%, transparent 70%, rgba(0,0,0,.7) 100%);
}
.tv-osd-side {
  display: none;
  width: min(380px, 46vw);
  flex-direction: column;
  padding: calc(16px + var(--tv-safe-t)) 10px 20px 16px;
  min-height: 0;
  pointer-events: auto;
}
.tv-osd.is-list .tv-osd-side { display: flex; }
.tv-osd-cats {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 10px;
  flex-shrink: 0;
}
.tv-osd-cats .tv-chip {
  flex-shrink: 0;
  height: 34px;
  padding: 0 12px;
  font-size: 13px;
}
.tv-osd-list {
  flex: 1;
  overflow: auto;
  min-height: 0;
}
.tv-osd-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: #fff;
  text-align: left;
  padding: 8px 10px;
  border-radius: 12px;
  margin-bottom: 4px;
}
.tv-osd-item.is-on { background: rgba(59,158,255,.28); }
.tv-osd-item .tv-logo { width: 40px; height: 40px; }
.tv-osd-foot {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(18px + var(--tv-safe-b));
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  pointer-events: auto;
}
.tv-osd.is-on .tv-osd-foot { display: flex; }
.tv-osd.is-list .tv-osd-foot { left: min(380px, 46vw); }
.tv-now-name { font-size: 28px; font-weight: 800; text-shadow: 0 2px 12px #000; }
.tv-now-epg { color: #fff; margin-top: 6px; font-size: 16px; font-weight: 700; text-shadow: 0 2px 10px #000; }
.tv-now-epg span { color: var(--tv-accent); margin-right: 8px; }
.tv-now-sub { color: #cbd5e1; margin-top: 4px; }
.tv-card .tv-epg { display: block; color: var(--tv-accent); font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.tv-arch {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.tv-arch[hidden] { display: none; }
.tv-arch-box {
  width: min(560px, 100%);
  max-height: min(78vh, 720px);
  background: var(--tv-bg-2);
  border: 1px solid var(--tv-line);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tv-arch-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--tv-line);
}
.tv-arch-title { font-weight: 800; font-size: 18px; }
.tv-arch-top button {
  height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--tv-line);
  background: rgba(255,255,255,.06);
  color: #fff;
  font-weight: 700;
}
.tv-arch-hours {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px;
}
.tv-arch-hours button {
  flex-shrink: 0;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--tv-line);
  background: rgba(255,255,255,.05);
  color: #fff;
  font-weight: 700;
}
.tv-arch-hours button.is-on { background: rgba(59,158,255,.28); border-color: var(--tv-accent); }
.tv-arch-list { overflow: auto; padding: 8px 12px 20px; }
.tv-arch-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  border: 0;
  background: transparent;
  color: #fff;
  text-align: left;
  padding: 12px 10px;
  border-radius: 12px;
}
.tv-arch-item:hover, .tv-arch-item:focus-visible { background: rgba(59,158,255,.22); }
.tv-arch-item b { font-size: 15px; }
.tv-arch-item span { color: var(--tv-muted); font-size: 13px; }
.tv-osd-tools { display: flex; gap: 8px; }
.tv-osd-tools button {
  height: 48px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.45);
  color: #fff;
  font-weight: 700;
}

.tv-dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-around;
  padding: 8px 8px calc(8px + var(--tv-safe-b));
  background: rgba(7,8,12,.92);
  border-top: 1px solid var(--tv-line);
  backdrop-filter: blur(16px);
  z-index: 20;
}
.tv-dock button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--tv-muted);
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 700;
}
.tv-dock button i { display: block; font-size: 20px; margin-bottom: 2px; }
.tv-dock button.is-on { color: var(--tv-accent); }

.tv-help {
  position: fixed;
  right: 16px;
  bottom: calc(78px + var(--tv-safe-b));
  color: var(--tv-muted);
  font-size: 12px;
  display: none;
}

.tv-chno-toast {
  position: fixed;
  right: 24px;
  top: 24px;
  font-size: 56px;
  font-weight: 800;
  text-shadow: 0 4px 18px #000;
  z-index: 50;
  display: none;
}

.tv-nav:focus-visible, .tv-card:focus-visible, .tv-chip:focus-visible, .tv-icon-btn:focus-visible, .tv-osd-item:focus-visible, .tv-btn:focus-visible {
  outline: 3px solid var(--tv-focus);
  outline-offset: 2px;
}

@media (min-width: 700px) {
  .tv-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1100px) {
  .tv-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tv-dock { display: none; }
  .tv-main { padding-bottom: 24px; }
  .tv-help { display: block; }
}
body.is-tv .tv-chip, body.is-tv .tv-card, body.is-tv .tv-icon-btn, body.is-tv .tv-search {
  min-height: 52px;
}
body.is-tv .tv-card { min-height: 84px; }
body.is-tv .tv-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
body.is-tv .tv-dock { display: none; }
body.is-tv .tv-help { display: block; }
body.is-tv .tv-main { padding-bottom: 28px; }

.tv-paywall {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    radial-gradient(900px 420px at 50% 0%, rgba(59,158,255,.2), transparent 55%),
    var(--tv-bg);
}
.tv-paywall[hidden] { display: none; }
.tv-paywall-card {
  width: min(440px, 100%);
  background: rgba(16,20,28,.92);
  border: 1px solid var(--tv-line);
  border-radius: 24px;
  padding: 22px 16px 26px;
  text-align: center;
}
.tv-paywall-card .tv-brand { margin: 0 auto 12px; }
.tv-paywall-video {
  display: block;
  width: 100%;
  max-height: 220px;
  margin: 0 0 14px;
  border-radius: 14px;
  background: #000;
  object-fit: contain;
}
.tv-paywall-card h1 {
  margin: 0 0 8px;
  font-size: 24px;
}
.tv-paywall-card p {
  color: var(--tv-muted);
  margin: 0 0 16px;
  line-height: 1.45;
}
.tv-paywall-card .tv-btn { text-decoration: none; display: grid; place-items: center; }
.tv-paywall-card .tv-sub a { color: #7dd3fc; }

@media (max-width: 699px) {
  .tv-setup {
    margin: max(12px, env(safe-area-inset-top)) auto 0;
    padding: 18px 12px 22px;
  }
  .tv-setup .tv-brand img { height: 40px; }
  .tv-pin { gap: 6px; }
  .tv-pin input { max-width: 48px; }
  .tv-osd.is-list .tv-osd-side {
    width: min(340px, 86vw);
    max-width: none;
    padding-right: 12px;
    background: rgba(7, 8, 12, .94);
  }
  .tv-osd.is-list .tv-osd-foot { display: none; }
  .tv-osd-foot {
    left: 12px;
    right: 12px;
    flex-direction: column;
    align-items: stretch;
  }
  .tv-now-name { font-size: 20px; }
  .tv-osd-tools { width: 100%; }
  .tv-osd-tools button { flex: 1; height: 44px; }
  .tv-grid { grid-template-columns: 1fr; }
}
@media (max-width: 380px) {
  .tv-pin input { max-width: 42px; font-size: 18px; }
}
body.is-tv .tv-setup {
  width: min(560px, calc(100% - 48px));
  padding: 32px 28px 36px;
}
body.is-tv .tv-setup .tv-brand img { height: 56px; }
body.is-tv .tv-setup-lead { font-size: 20px; }
body.is-tv .tv-pin { gap: 14px; }
body.is-tv .tv-pin input {
  max-width: 72px;
  font-size: 32px;
  border-width: 3px;
}
body.is-tv .tv-btn { height: 64px; font-size: 22px; }
body.is-tv .tv-paywall-card { width: min(640px, 90vw); padding: 32px; }
body.is-tv .tv-paywall-card h1 { font-size: 32px; }
