:root {
  --bg: #0c1016;
  --bg-elev: #141a22;
  --bg-row: #121820;
  --bg-row-alt: #171e28;
  --bg-panel: #10161e;
  --line: rgba(148, 168, 190, 0.14);
  --text: #e6edf5;
  --muted: #8b9cb0;
  --accent: #6ba3d4;
  --accent-deep: #4d8fc0;
  --accent-ink: #0b121a;
  --focus: #7eb3df;
  --danger: #e57373;
  --ok: #5bbf8d;
  --font-display: "Outfit", sans-serif;
  --font-body: "Source Sans 3", sans-serif;
  --safe-t: max(0.5rem, env(safe-area-inset-top));
  --safe-r: max(0.75rem, env(safe-area-inset-right));
  --safe-b: max(0.5rem, env(safe-area-inset-bottom));
  --safe-l: max(0.75rem, env(safe-area-inset-left));
  --topbar-h: 48px;
  --footer-h: 64px;
  --toolbar-h: 36px;
  --channel-w: 240px;
  --hour-w: 480px;
  --row-h: 46px;
  --focus-ring: 0 0 0 3px rgba(126, 179, 223, 0.45);
  --scroll-size: 10px;
  --scroll-track: rgba(12, 16, 22, 0.85);
  --scroll-thumb: rgba(110, 140, 170, 0.45);
  --scroll-thumb-hover: rgba(130, 170, 205, 0.7);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

*::-webkit-scrollbar {
  width: var(--scroll-size);
  height: var(--scroll-size);
}

*::-webkit-scrollbar-track {
  background: var(--scroll-track);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

body.guide-page {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

button,
input,
select,
a {
  font: inherit;
  color: inherit;
}

:focus {
  outline: none;
}

:focus-visible {
  box-shadow: var(--focus-ring);
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.03em;
  font-size: 1.1rem;
  white-space: nowrap;
}

.brand span {
  color: var(--accent);
}

.brand-link {
  text-decoration: none;
}

.topbar {
  min-height: var(--topbar-h);
  height: auto;
  flex: 0 0 auto;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: var(--safe-t) var(--safe-r) 0 var(--safe-l);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-height: var(--topbar-h);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.topbar-right {
  flex-shrink: 0;
}

.mode-nav {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  margin-left: 0.35rem;
}

.mode-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  white-space: nowrap;
  cursor: pointer;
  transition:
    color 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.mode-btn:hover,
.mode-btn:focus-visible {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.12);
  outline: none;
}

.mode-btn.is-active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
}

.mode-btn:focus-visible,
body.mode-nav-focus .mode-btn:focus {
  color: var(--text);
  border-color: var(--focus);
  box-shadow: var(--focus-ring);
  outline: none;
}

.library {
  position: relative;
  z-index: 2;
  padding: 0;
  height: calc(100vh - var(--topbar-h) - var(--safe-t));
  min-height: 0;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  /* Instant scroll — smooth CSS fights touch/wheel and feels laggy */
  scroll-behavior: auto;
}

.library-chrome {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0;
  padding: 0.75rem clamp(0.75rem, 2vw, 1.5rem) 0.65rem;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border-bottom: 1px solid var(--line);
}

.library-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
}

.library-search {
  flex: 1;
  max-width: 28rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.85rem;
  font: inherit;
}

.library-search:focus {
  outline: 2px solid rgba(120, 180, 255, 0.45);
  outline-offset: 1px;
}

.library-count {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.library-back {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  border-radius: 6px;
  padding: 0.45rem 0.75rem;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.library-back:focus-visible {
  outline: 2px solid rgba(120, 180, 255, 0.45);
  outline-offset: 1px;
}

.library-crumb {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.library-crumb strong {
  color: inherit;
  font-weight: 700;
}

.library-seasons {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0.15rem 0 0.1rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.library-seasons::-webkit-scrollbar {
  display: none;
}
.library-seasons[hidden] {
  display: none !important;
}

.library-season-btn {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.library-season-btn.is-active {
  border-color: rgba(120, 180, 255, 0.55);
  background: rgba(90, 140, 220, 0.22);
}

.library-season-btn:focus-visible {
  outline: 2px solid rgba(120, 180, 255, 0.45);
  outline-offset: 1px;
}

.library-badge {
  color: var(--muted);
  font-size: 0.78rem;
}

.library-grid {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  min-height: min-content;
  padding: 1rem clamp(0.75rem, 2vw, 1.5rem) 2.5rem;
}

.library-section {
  min-width: 0;
}

.library-section-title {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: rgba(230, 237, 245, 0.92);
}

.library-grid-inner {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 1rem 0.85rem;
}

.library-grid-inner--series {
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 1.15rem 1rem;
}

.library-grid-inner--movies,
.library-grid-inner--episodes {
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
}

.library-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  cursor: pointer;
  font: inherit;
  touch-action: pan-y;
}

.library-card--series .library-poster {
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  border-radius: 8px;
}

.library-card--series .library-title {
  font-weight: 800;
}

.library-card:focus-visible {
  outline: 2px solid rgba(120, 180, 255, 0.65);
  outline-offset: 3px;
  border-radius: 4px;
}

.library-poster {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 4px;
  background: #1a222e;
  display: block;
}

.library-poster-wrap {
  position: relative;
  display: block;
  width: 100%;
}

.library-poster-wrap .library-poster {
  width: 100%;
}

.library-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 0 0 4px 4px;
  overflow: hidden;
}

.library-progress-fill {
  display: block;
  height: 100%;
  background: #6ea8ff;
}

.library-poster-fallback {
  display: grid;
  place-items: center;
  font-size: 2.5rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.35);
}

.library-meta {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.library-title {
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.library-year {
  color: var(--muted);
  font-size: 0.78rem;
}

.library-empty {
  color: var(--muted);
  margin: 1rem clamp(0.75rem, 2vw, 1.5rem) 2rem;
  max-width: 28rem;
}

body.mode-library .guide {
  /* panel visibility via JS transitions */
}

/* Media: never show live miniplayer / PIP over the catalog */
body.mode-library.is-watching:not(.is-watching-full) .stage,
body.mode-library:not(.is-library-vod) .stage {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
body.mode-library .guide,
body.mode-home .guide {
  display: none !important;
}
body.mode-library .now-next,
body.mode-home .now-next {
  display: none !important;
}


.cat-rail {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  max-width: min(70vw, 900px);
  scrollbar-width: none;
}

.cat-rail::-webkit-scrollbar {
  display: none;
}

.cat-chip {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  white-space: nowrap;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.cat-chip:hover,
.cat-chip.active,
.cat-chip:focus-visible {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: none;
}

.clock {
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  font-family: var(--font-display);
}

.user-chip {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.text-link,
.tv-btn,
.btn-primary,
.btn-ghost {
  border: 0;
  cursor: pointer;
}

.text-link {
  background: none;
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.45rem;
  border-radius: 6px;
  font-weight: 600;
}

.text-link:hover,
.text-link:focus-visible {
  color: var(--accent);
}

.tv-btn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
  font-weight: 700;
  min-height: 40px;
}

.tv-btn:hover,
.tv-btn:focus-visible {
  border-color: var(--focus);
  color: var(--accent);
}

.icon-btn {
  min-width: 40px;
  padding-inline: 0.55rem;
  font-size: 1.25rem;
  line-height: 1;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: var(--accent-ink);
  font-weight: 800;
  border-radius: 8px;
  padding: 0.55rem 1.15rem;
  min-height: 44px;
  min-width: 110px;
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
}

/* Login */
.login-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  overflow: auto;
  background:
    radial-gradient(900px 500px at 20% 0%, rgba(80, 130, 180, 0.18), transparent 55%),
    var(--bg);
}

.login-atmosphere {
  display: none;
}

.login-panel {
  width: min(400px, 100%);
  padding: 1.5rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.login-panel h1 {
  margin: 0.7rem 0 0.2rem;
  font-family: var(--font-display);
  font-size: 1.8rem;
}

.login-sub {
  margin: 0 0 1rem;
  color: var(--muted);
}

.login-apk {
  margin: 1.1rem 0 0;
  text-align: center;
}

.login-apk a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.login-apk a:hover {
  text-decoration: underline;
}

.login-panel label {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-panel input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
  min-height: 44px;
}

.login-panel .btn-primary {
  width: 100%;
  margin-top: 0.25rem;
}

.form-error {
  color: var(--danger);
  margin: 0 0 0.75rem;
}

/* Guide — denser TV layout */
.guide {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.guide-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Single-scroller guide: sticky channel cell + programme track per row */
.guide-header {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  height: var(--toolbar-h);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
}
.guide-header .timeline-controls {
  position: sticky;
  left: 0;
  z-index: 40;
  flex: 0 0 var(--channel-w);
  width: var(--channel-w);
  box-sizing: border-box;
  height: var(--toolbar-h);
  border-right: 1px solid var(--line);
  background: #10161e;
  box-shadow: 6px 0 12px rgba(0, 0, 0, 0.35);
}
.guide-header .time-scale {
  position: relative;
  top: auto;
  flex: 0 0 auto;
  height: var(--toolbar-h);
  border-bottom: 0;
}
.epg-row {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  position: relative;
  height: var(--row-h);
  border-bottom: 1px solid var(--line);
  background: var(--bg-row);
}
.epg-row:nth-child(even) {
  background: var(--bg-row-alt);
}
.epg-row > .channel-row {
  position: sticky;
  left: 0;
  z-index: 30;
  flex: 0 0 var(--channel-w);
  width: var(--channel-w);
  height: var(--row-h);
  border-right: 1px solid var(--line);
  /* Opaque so programmes never show through while scrolling under sticky */
  background: #10161e;
  box-shadow: 6px 0 12px rgba(0, 0, 0, 0.35);
  isolation: isolate;
}
.epg-row > .channel-row.active,
.epg-row > .channel-row:focus-visible,
.epg-row > .channel-row.playing {
  background: #152032;
}
.epg-row-track {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  height: var(--row-h);
  overflow: hidden;
}
.epg-row-track .prog {
  z-index: 1;
}
.epg-row-track .prog.selected,
.epg-row-track .prog:focus-visible,
.epg-row-track .prog:hover {
  z-index: 2;
}

.channel-rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--bg-panel);
}

.timeline-controls {
  height: var(--toolbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: stretch;
  gap: 0.3rem;
  padding: 0 0.3rem;
  border-bottom: 1px solid var(--line);
}

.guide-category {
  flex: 1;
  min-width: 4.5rem;
  max-width: 100%;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0 0.35rem;
}

.channel-col { display: none !important; }

.channel-row {
  display: grid;
  grid-template-columns: 26px 26px 1fr;
  gap: 0.28rem;
  align-items: center;
  height: var(--row-h);
  width: 100%;
  padding: 0 0.3rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.channel-row:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

.channel-row.active,
.channel-row:focus-visible {
  background: rgba(107, 163, 212, 0.14);
  box-shadow: inset 3px 0 0 var(--focus);
}

.channel-row.playing {
  box-shadow: inset 3px 0 0 #6bcf8e;
}

.channel-row.active.playing,
.channel-row.playing:focus-visible {
  box-shadow: inset 3px 0 0 var(--focus), inset 6px 0 0 #6bcf8e;
}

.channel-row .num {
  color: var(--accent);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
  padding: 0;
  line-height: 1;
  text-align: right;
}

.channel-row img {
  width: 26px;
  height: 26px;
  object-fit: contain;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
}

.channel-row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 0.88rem;
}

/* Time headers + programme grid share one canvas so the now-line lines up */
.epg-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  background: var(--bg);
  min-width: 0;
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
}

.epg-canvas {
  position: relative;
  min-width: calc(var(--hour-w) * 4);
}

.time-scale {
  position: sticky;
  top: 0;
  z-index: 6;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--hour-w);
  height: var(--toolbar-h);
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.time-scale span {
  position: relative;
  padding-left: 0.4rem;
  border-left: 1px solid var(--line);
  line-height: var(--toolbar-h);
  box-sizing: border-box;
}

/* Tick every 5 minutes within each hour column */
.time-scale span::before {
  content: '';
  position: absolute;
  inset: 30% 0 30% 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to right,
    transparent 0,
    transparent calc(100% / 12 - 1px),
    rgba(140, 170, 210, 0.22) calc(100% / 12 - 1px),
    rgba(140, 170, 210, 0.22) calc(100% / 12)
  );
}

.epg-grid {
  position: relative;
  display: flex;
  flex-direction: column;
}

/* .epg-row defined above with flex + sticky channel */

.prog {
  position: absolute;
  top: 3px;
  bottom: 3px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 4px;
  background: var(--bg-elev);
  padding: 0.12rem 0.28rem;
  overflow: hidden;
  cursor: pointer;
  color: inherit;
  text-align: left;
  min-width: 0;
}

.prog:hover,
.prog.selected,
.prog:focus-visible {
  border-color: var(--focus);
  background: #1c314d;
  z-index: 2;
}

.prog.live {
  border-color: rgba(107, 163, 212, 0.55);
}

.prog .title {
  font-weight: 700;
  font-size: 0.78rem;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prog .time {
  color: var(--muted);
  font-size: 0.65rem;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Short blocks: drop times, tighter chrome so the title can breathe */
.prog.prog-short {
  padding: 0.08rem 0.18rem;
}

.prog.prog-short .time {
  display: none;
}

.prog.prog-short .title {
  font-size: 0.72rem;
}

.prog.prog-tiny {
  padding: 0.05rem 0.12rem;
}

.prog.prog-tiny .title {
  font-size: 0.68rem;
  letter-spacing: -0.01em;
}

.now-line {
  position: absolute;
  top: var(--toolbar-h);
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(107, 163, 212, 0.45);
  pointer-events: none;
  z-index: 7;
}

.now-next {
  height: var(--footer-h);
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  border-top: 1px solid var(--line);
  background: var(--bg-panel);
}

.nn-channel {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  min-width: 0;
}

.nn-channel img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
}

.nn-num {
  margin: 0;
  color: var(--accent);
  font-weight: 800;
  font-size: 0.8rem;
}

.nn-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nn-label {
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.65rem;
  font-weight: 800;
}

.nn-prog p:last-child {
  margin: 0.1rem 0 0;
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Stage player: mini (guide corner) or expanded overlay — same video element / playback path */
.stage {
  display: none;
  position: fixed;
  z-index: 40;
  background: #000;
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  transition:
    top 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    right 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    bottom 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    left 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    width 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    height 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    border-radius 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.28s ease,
    transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.38s ease;
}

.stage[hidden] {
  display: none !important;
}

body.is-watching .stage {
  display: block;
  position: fixed;
  top: calc(var(--safe-t) + var(--topbar-h) + 0.45rem);
  right: calc(var(--safe-r) + 0.65rem);
  left: auto;
  bottom: auto;
  width: min(380px, 46vw);
  aspect-ratio: 16 / 9;
  height: auto;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  background: #000;
  opacity: 1;
  transform: none;
}

body.is-watching-outro .stage {
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  pointer-events: none;
}

body.is-watching-full {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

body.is-watching-full .stage {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  margin: 0;
  aspect-ratio: auto;
  border-radius: 0;
  border: 0;
  box-shadow: none;
  z-index: 50;
  display: block;
  background: #000;
  overflow: hidden;
  opacity: 1;
  transform: none;
}

body.is-watching-full .stage-video-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
}

body.is-watching-full #player {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain !important;
  object-position: center center !important;
}

body.is-watching-full .topbar,
body.is-watching-full .guide,
body.is-watching-full .library,
body.is-watching-full .tv-home {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}

.topbar {
  transition: opacity 0.28s ease;
}

.guide,
.library,
.tv-home {
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.guide.is-panel-out,
.library.is-panel-out,
.tv-home.is-panel-out {
  opacity: 0 !important;
  transform: translateY(8px);
  pointer-events: none;
}

.guide.is-panel-in,
.library.is-panel-in,
.tv-home.is-panel-in {
  opacity: 1;
  transform: none;
}

.stage-video-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  display: grid;
  place-items: center;
  overflow: hidden;
}

body.is-watching .stage-video-wrap,
body.is-watching-full .stage-video-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

#player {
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  max-height: 100%;
  background: #000;
  object-fit: contain !important;
  object-position: center center;
  display: block;
  /* Force the video onto its own GPU compositing layer (fixes Android
     Chrome "audio but black video" when inside transformed/clipped ancestors). */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

body.is-watching:not(.is-watching-full) #player,
body.is-watching-full #player {
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain !important;
  object-position: center center;
}

.stage-osd {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.45rem 0.5rem 0.55rem;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.72) 0%, transparent 32%, transparent 58%, rgba(0, 0, 0, 0.82) 100%);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

body.is-watching-full .stage-osd {
  padding: calc(var(--safe-t) + 0.75rem) var(--safe-r) calc(var(--safe-b) + 0.75rem) var(--safe-l);
}

.stage-osd.is-visible {
  opacity: 1;
  /* Keep the layer non-interactive; only action buttons receive clicks/focus */
  pointer-events: none;
}

.stage-osd.is-visible .osd-top {
  pointer-events: auto;
}

.osd-bottom {
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.osd-bottom h2,
.osd-bottom p,
.osd-progress {
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

body.is-library-vod .vod-controls,
body.is-library-vod .osd-progress,
body.is-library-vod .vod-seek {
  pointer-events: auto;
  user-select: auto;
  -webkit-user-select: auto;
}

.vod-controls {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0.55rem 0 0.2rem;
}

body.is-library-vod .vod-controls:not([hidden]) {
  display: flex;
}

.vod-controls .tv-btn {
  min-width: 2.75rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(12, 18, 26, 0.72);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.vod-controls .tv-btn:focus-visible,
.vod-controls .tv-btn:hover {
  border-color: rgba(142, 184, 220, 0.75);
  background: rgba(30, 42, 56, 0.9);
}

#vod-playpause {
  min-width: 4.5rem;
  background: rgba(232, 241, 248, 0.92);
  color: #0b1520;
  border-color: transparent;
  font-weight: 800;
}

.vod-seek {
  display: none;
  width: 100%;
  max-width: 40rem;
  margin: 0.45rem 0 0.1rem;
  accent-color: #8eb8dc;
  height: 1.1rem;
  cursor: pointer;
}

body.is-library-vod .vod-seek:not([hidden]) {
  display: block;
}

body.is-library-vod .osd-progress-meta {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

body.is-library-vod .osd-progress-track {
  display: none;
}

body.is-library-vod .osd-progress-fill {
  transition: none;
}

/* Live TV: never show VOD transport */
body:not(.is-library-vod) .vod-controls,
body:not(.is-library-vod) .vod-seek {
  display: none !important;
}

.stage-video-wrap.is-osd-hidden {
  cursor: none;
}

body.is-watching:not(.is-watching-full) .stage-osd {
  display: none;
}

body.is-watching:not(.is-watching-full) .osd-hint {
  display: none;
}

body.is-watching:not(.is-watching-full) .osd-bottom h2 {
  font-size: 0.95rem;
}

body.is-watching:not(.is-watching-full) #expand-player {
  display: inline-flex;
}

body.is-watching-full #expand-player {
  display: none;
}

.osd-top {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.osd-bottom h2 {
  margin: 0.15rem 0;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.osd-bottom p {
  margin: 0;
  color: #d7e0ee;
}

.now-channel {
  color: var(--accent) !important;
  font-weight: 800;
  font-size: 0.85rem;
}

.osd-hint {
  margin-top: 0.35rem !important;
  color: var(--muted) !important;
  font-size: 0.85rem;
}

.osd-progress {
  margin-top: 0.45rem;
  max-width: 36rem;
}

.osd-progress-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
}

.osd-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #9ec9eb);
  transition: width 0.6s linear;
}

.osd-progress-meta {
  margin: 0.25rem 0 0 !important;
  font-size: 0.75rem !important;
  color: rgba(230, 237, 245, 0.65) !important;
  font-variant-numeric: tabular-nums;
}

.buffering-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  width: 3.25rem;
  height: 3.25rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(8, 12, 18, 0.55);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.buffering-badge[hidden] {
  display: none !important;
}

.buffering-spinner {
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.22);
  border-top-color: #8ab4f8;
  animation: buffering-spin 0.7s linear infinite;
}

@keyframes buffering-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .buffering-spinner {
    animation-duration: 1.4s;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 1rem);
  transform: translateX(-50%);
  background: rgba(8, 14, 26, 0.96);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  z-index: 80;
  font-weight: 600;
}

/* TV number-entry (zap) overlay */
.zap-osd {
  position: fixed;
  top: calc(var(--safe-t) + var(--topbar-h) + 0.75rem);
  left: calc(var(--safe-l) + 0.85rem);
  z-index: 85;
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem 0.6rem;
  border-radius: 12px;
  background: rgba(12, 16, 22, 0.92);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.zap-osd[hidden] {
  display: none !important;
}

.zap-label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.zap-digits {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  letter-spacing: 0.04em;
  min-width: 2ch;
}

@media (max-width: 900px) {
  :root {
    --channel-w: 132px;
    --hour-w: 220px;
    --row-h: 48px;
    --footer-h: auto;
    --toolbar-h: 40px;
    --topbar-h: 44px;
    --scroll-size: 6px;
  }

  html,
  body {
    font-size: 15px;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
  }

  .topbar-right {
    gap: 0.4rem;
  }

  .clock {
    font-size: 0.8rem;
  }

  .text-link {
    padding: 0.35rem 0.4rem;
    font-size: 0.82rem;
  }

  .mode-btn {
    padding: 0.32rem 0.6rem;
    font-size: 0.8rem;
  }

  .guide-body {
    display: flex;
  }

  .channel-row {
    grid-template-columns: 22px 1fr;
    gap: 0.35rem;
    padding: 0 0.35rem;
  }

  .channel-row img {
    display: none;
  }

  .channel-row .name {
    font-size: 0.8rem;
  }

  .guide-category {
    font-size: 0.68rem;
    height: 30px;
  }

  .epg-scroll,
  .guide-body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
  }

  .channel-row,
  .prog {
    touch-action: pan-x pan-y;
  }

  .prog {
    padding: 0.25rem 0.35rem;
  }

  .prog .title {
    font-size: 0.78rem;
  }

  .prog .time {
    font-size: 0.65rem;
  }

  body.is-watching .stage {
    top: auto;
    right: var(--safe-r);
    bottom: calc(var(--safe-b) + 4.75rem);
    left: auto;
    width: min(220px, 58vw);
    z-index: 45;
  }

  body.is-watching.is-watching-full .stage,
  body.is-watching-full .stage {
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    margin: 0 !important;
    aspect-ratio: auto !important;
    border-radius: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    z-index: 50 !important;
  }

  body.is-watching-full .stage-video-wrap {
    inset: 0;
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
  }

  body.is-watching:not(.is-watching-full) .stage-video-wrap {
    display: grid;
    place-items: center;
  }

  body.is-watching #player,
  body.is-watching-full #player {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    object-position: center center;
  }

  .time-scale span::before {
    display: none;
  }

  .now-next {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    gap: 0.45rem 0.65rem;
    height: auto;
    padding: 0.5rem var(--safe-r) calc(0.45rem + var(--safe-b)) var(--safe-l);
  }

  .now-next .nn-prog:last-of-type {
    display: none;
  }

  .now-next .btn-primary {
    grid-column: 1 / -1;
    min-height: 44px;
    width: 100%;
  }

  .nn-channel img {
    width: 32px;
    height: 32px;
  }

  .nn-name,
  .nn-prog p:last-child {
    font-size: 0.85rem;
  }

  .user-chip,
  .cat-rail {
    display: none;
  }

  .osd-hint {
    display: none;
  }
}

@media (max-width: 560px) {
  :root {
    --channel-w: 110px;
    --hour-w: 160px;
    --row-h: 46px;
  }

  .brand {
    font-size: 0.92rem;
  }

  .clock {
    display: none;
  }

  .topbar-right a[href='/apk'] {
    display: none;
  }

  .mode-btn {
    padding: 0.3rem 0.48rem;
    font-size: 0.76rem;
  }

  .channel-row {
    grid-template-columns: 20px 1fr;
  }

  .channel-row .num {
    font-size: 0.7rem;
  }

  body.is-watching .stage {
    width: min(168px, 46vw);
    bottom: calc(var(--safe-b) + 5.25rem);
  }

  .now-next {
    grid-template-columns: 1fr;
  }

  .now-next .nn-prog {
    display: none;
  }
}

@media (min-width: 1400px) {
  :root {
    --channel-w: 280px;
    --row-h: 52px;
    --hour-w: 560px;
    --topbar-h: 56px;
    --footer-h: 72px;
  }

  body {
    font-size: 18px;
  }
}

/* Installed PWA / standalone display */
@media (display-mode: standalone), (display-mode: fullscreen) {
  :root {
    --safe-t: max(0.75rem, env(safe-area-inset-top));
    --safe-b: max(0.75rem, env(safe-area-inset-bottom));
  }

  .topbar {
    padding-top: var(--safe-t);
  }
}

html.is-pwa .topbar a[href='/apk'] {
  display: none;
}

@media (orientation: landscape) and (max-height: 560px),
  (orientation: landscape) and (max-width: 960px) {
  body.is-watching.is-watching-full .stage,
  body.is-watching-full .stage {
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
  }

  body.is-watching-full .stage-video-wrap {
    display: grid;
    place-items: center;
  }

  body.is-watching-full #player {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    object-position: center center;
  }

  body.is-watching-full .stage-osd {
    padding: max(0.35rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right))
      max(0.35rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  .guide-body {
    display: flex;
  }

  body.is-watching:not(.is-watching-full) .stage {
    top: auto;
    bottom: calc(var(--safe-b) + 5.5rem);
  }
}

/* —— Leanback / Google TV–inspired Home —— */
.tv-home {
  position: relative;
  z-index: 2;
  padding: 1.25rem 0 3rem;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  height: calc(100vh - var(--topbar-h) - var(--safe-t));
  box-sizing: border-box;
  scroll-behavior: smooth;
}

.home-hero {
  margin: 0.35rem clamp(1rem, 3vw, 2.5rem) 1.5rem;
  max-width: 40rem;
}

.home-kicker {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.85rem;
  color: var(--accent);
}

.home-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.5rem, 3vw, 2.1rem);
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: rgba(230, 237, 245, 0.88);
}

.home-sub {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.home-launcher-banner {
  margin: 0.75rem clamp(1rem, 3vw, 2.5rem) 0;
  max-width: 36rem;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 180, 80, 0.35);
  background: rgba(40, 28, 12, 0.85);
  color: #f0d9b0;
  font-size: 0.9rem;
  line-height: 1.35;
}

.home-rows {
  display: flex;
  flex-direction: column;
  gap: 1.65rem;
}

.home-row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
  padding: 0 clamp(1rem, 3vw, 2.5rem);
}

.home-row-more {
  font-size: 0.85rem;
  white-space: nowrap;
}

.home-row-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.home-rail {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.65rem clamp(1rem, 3vw, 2.5rem) 1rem;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: clamp(1rem, 3vw, 2.5rem);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.home-rail::-webkit-scrollbar {
  display: none;
}

.home-tile {
  flex: 0 0 auto;
  width: 9.5rem;
  scroll-snap-align: start;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  cursor: pointer;
  font: inherit;
  border-radius: 10px;
  outline: none;
}

.home-tile:focus-visible {
  outline: none;
  z-index: 3;
}

.home-tile-poster {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 10px;
  background: #1a222e;
  display: block;
}

.home-tile-poster.is-channel {
  aspect-ratio: 16 / 10;
  object-fit: contain;
  padding: 0.75rem;
  background: #121a24;
}

.home-tile-poster.is-app {
  aspect-ratio: 1 / 1;
  object-fit: contain;
  padding: 0.85rem;
  background: #161e28;
}

.home-tile-poster.is-action {
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  font-size: 1.75rem;
  font-weight: 800;
  background: linear-gradient(145deg, #1a2736 0%, #121a24 100%);
  color: rgba(230, 237, 245, 0.85);
}

body.mode-home {
  background:
    radial-gradient(ellipse 70% 50% at 12% -10%, rgba(80, 120, 180, 0.22), transparent 55%),
    radial-gradient(ellipse 50% 40% at 88% 8%, rgba(40, 70, 120, 0.14), transparent 50%),
    var(--bg);
}

body.mode-home .tv-home {
  padding-top: 0.85rem;
}

body.mode-home .home-hero {
  margin-bottom: 1.25rem;
}

body.mode-home .home-kicker {
  font-size: 0.95rem;
  letter-spacing: 0.08em;
}

/* Circular apps */
body.mode-home .home-tile--app {
  width: 6.75rem;
  text-align: center;
}

body.mode-home .home-tile--app .home-tile-poster {
  width: 5.75rem;
  height: 5.75rem;
  margin: 0 auto;
  border-radius: 50%;
  aspect-ratio: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

body.mode-home .home-tile--app:focus-visible {
  transform: scale(1.08);
}

body.mode-home .home-tile--app:focus-visible .home-tile-poster {
  outline: 3px solid #fff;
  outline-offset: 4px;
  transform: none;
}

body.mode-home .home-tile--app .home-tile-meta {
  margin-top: 0.55rem;
  text-align: center;
}

body.mode-home .home-tile--app .home-tile-name {
  font-size: 0.78rem;
  -webkit-line-clamp: 1;
}

/* Watch cards */
body.mode-home .home-tile--watch {
  width: min(22rem, 42vw);
}

body.mode-home .home-tile--watch .home-tile-poster {
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 0.3rem;
  padding: 1.1rem 1.2rem;
  background:
    linear-gradient(180deg, transparent 20%, rgba(0, 0, 0, 0.72) 100%),
    linear-gradient(135deg, #1e4d7a 0%, #12304f 55%, #0c1826 100%);
}

body.mode-home .home-tile--watch[data-action='media'] .home-tile-poster {
  background:
    linear-gradient(180deg, transparent 20%, rgba(0, 0, 0, 0.72) 100%),
    linear-gradient(135deg, #2a4a5e 0%, #163042 55%, #0e1a24 100%);
}

body.mode-home .home-watch-glyph {
  font-size: 1.5rem;
  font-weight: 800;
}

body.mode-home .home-watch-label {
  font-size: 1.15rem;
  font-weight: 700;
}

body.mode-home .home-watch-sub {
  font-size: 0.85rem;
  color: rgba(230, 237, 245, 0.72);
}

body.mode-home .home-tile--watch:focus-visible {
  transform: scale(1.05);
}

body.mode-home .home-tile--watch:focus-visible .home-tile-poster {
  outline: 3px solid #fff;
  outline-offset: 4px;
  transform: none;
}

/* System chips */
body.mode-home .home-tile--chip {
  width: auto;
  min-width: 8.5rem;
}

body.mode-home .home-tile--chip .home-tile-poster {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: auto;
  min-height: 3.25rem;
  aspect-ratio: auto;
  padding: 0.55rem 1rem 0.55rem 0.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

body.mode-home .home-chip-glyph {
  flex: 0 0 auto;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 800;
  background: rgba(107, 163, 212, 0.18);
  color: var(--accent);
}

body.mode-home .home-tile--chip .home-tile-meta {
  margin: 0;
}

body.mode-home .home-tile--chip:focus-visible {
  transform: scale(1.04);
}

body.mode-home .home-tile--chip:focus-visible .home-tile-poster {
  outline: 3px solid #fff;
  outline-offset: 3px;
  transform: none;
}

.home-tile-fallback {
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.35);
}

.home-tile-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-top: 0.4rem;
  min-width: 0;
}

.home-tile-name {
  font-weight: 700;
  font-size: 0.88rem;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.home-tile-sub {
  color: var(--muted);
  font-size: 0.75rem;
}

.home-tile-progress {
  margin-top: 0.35rem;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.home-tile-progress > span {
  display: block;
  height: 100%;
  background: #6ea8ff;
}

.home-empty {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
  padding: 0.5rem clamp(1rem, 3vw, 2.5rem);
}

body.mode-home .guide,
body.mode-home .library {
  /* panel visibility via JS transitions */
}

body.is-tv-shell .topbar-right .text-link[href='/apk'],
body.is-tv-shell #logout-btn {
  display: none;
}

.mode-btn-secondary {
  color: var(--muted);
  opacity: 0.95;
}

.mode-nav .mode-btn-secondary {
  margin-left: 0.35rem;
}

.next-ep-banner {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 5rem);
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: rgba(12, 18, 28, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  max-width: min(32rem, calc(100vw - 2rem));
}

.next-ep-banner[hidden] {
  display: none !important;
}

.next-ep-banner p {
  margin: 0;
  font-size: 0.95rem;
}

/* —— Motion polish —— */
.home-tile,
.library-card {
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), outline-offset 0.15s ease;
}

.home-tile:focus-visible,
.library-card:focus-visible {
  transform: scale(1.04);
  z-index: 2;
}

.home-tile-poster,
.library-poster {
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.home-tile:focus-visible .home-tile-poster,
.library-card:focus-visible .library-poster {
  transform: scale(1.02);
}

@media (prefers-reduced-motion: reduce) {
  .stage,
  .guide,
  .library,
  .tv-home,
  .mode-btn,
  .home-tile,
  .library-card,
  .home-tile-poster,
  .library-poster,
  .toast,
  .stage-osd {
    transition: none !important;
  }

  .home-tile:focus-visible,
  .library-card:focus-visible,
  .home-tile:focus-visible .home-tile-poster,
  .library-card:focus-visible .library-poster {
    transform: none;
  }

  body.is-watching-outro .stage {
    opacity: 0;
    transform: none;
  }
}



@media (prefers-reduced-motion: reduce) {
  .tv-home,
  .library,
  .home-rail,
  .panel-media.is-active {
    scroll-behavior: auto !important;
    scroll-snap-type: none;
  }
}


/* Guide-only: no single-channel now/next strip under the EPG */
.now-next {
  display: none !important;
}


/* —— Android TV launcher refresh —— */
body.mode-home {
  color-scheme: dark;
  background:
    radial-gradient(ellipse 68% 42% at 18% 0%, rgba(44, 104, 168, 0.22), transparent 72%),
    radial-gradient(ellipse 46% 38% at 88% 12%, rgba(62, 81, 133, 0.14), transparent 72%),
    #080d15;
}

body.mode-home .tv-home {
  padding: clamp(1rem, 2.4vh, 2rem) 0 3rem;
  height: calc(100dvh - var(--topbar-h) - var(--safe-t));
}

body.mode-home .home-hero {
  position: relative;
  isolation: isolate;
  max-width: none;
  margin: 0 clamp(2rem, 5vw, 5rem) 1.6rem;
  padding: clamp(1.4rem, 3vh, 2.3rem) clamp(1.5rem, 3vw, 3rem);
  overflow: hidden;
  border: 1px solid rgba(179, 211, 255, 0.12);
  border-radius: 1.5rem;
  background: linear-gradient(105deg, rgba(24, 42, 65, 0.94), rgba(16, 27, 43, 0.72) 55%, rgba(18, 27, 42, 0.34));
  box-shadow: 0 18px 56px rgba(0, 0, 0, 0.18);
}

body.mode-home .home-hero::after {
  position: absolute;
  z-index: -1;
  top: -8rem;
  right: 3%;
  width: 24rem;
  height: 24rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(84, 153, 226, 0.2), transparent 70%);
  content: '';
  pointer-events: none;
}

body.mode-home .home-kicker {
  margin-bottom: 0.65rem;
  color: #a9cfff;
  font-size: 0.78rem;
  letter-spacing: 0.15em;
}

body.mode-home .home-title {
  max-width: 52rem;
  color: #f5f8fc;
  font-size: clamp(2.2rem, 4vw, 3.5rem);
  font-weight: 650;
  letter-spacing: -0.045em;
  line-height: 1.04;
}

body.mode-home .home-sub {
  margin-top: 0.8rem;
  color: rgba(219, 230, 244, 0.7);
  font-size: clamp(0.95rem, 1.35vw, 1.12rem);
}

body.mode-home .home-rows {
  gap: clamp(1.3rem, 2.4vh, 2rem);
}

body.mode-home .home-row-head {
  align-items: center;
  margin-bottom: 0.2rem;
  padding-inline: clamp(2rem, 5vw, 5rem);
}

body.mode-home .home-row-title {
  color: #eef4fc;
  font-size: clamp(1.05rem, 1.45vw, 1.3rem);
  font-weight: 650;
  letter-spacing: -0.015em;
}

body.mode-home .home-rail {
  gap: clamp(1rem, 1.6vw, 1.5rem);
  padding: 0.8rem clamp(2rem, 5vw, 5rem) 1.15rem;
}

body.mode-home .home-tile {
  border-radius: 1rem;
}

body.mode-home .home-tile--watch {
  width: min(25rem, 36vw);
}

body.mode-home .home-tile--watch .home-tile-poster {
  min-height: 9.5rem;
  border: 1px solid rgba(210, 229, 255, 0.12);
  border-radius: 1.15rem;
  padding: 1.3rem 1.5rem;
  background: linear-gradient(145deg, #244f7a, #162e4b 62%, #111d2e);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
}

body.mode-home .home-tile--watch[data-action='media'] .home-tile-poster {
  background: linear-gradient(145deg, #38576d, #20394c 62%, #132433);
}

body.mode-home .home-watch-glyph {
  color: #c9e3ff;
  font-size: 1.35rem;
}

body.mode-home .home-watch-label {
  font-size: 1.3rem;
  letter-spacing: -0.02em;
}

body.mode-home .home-watch-sub {
  color: rgba(239, 246, 255, 0.7);
}

body.mode-home .home-tile--app {
  width: 7.5rem;
}

body.mode-home .home-tile--app .home-tile-poster {
  width: 6rem;
  height: 6rem;
  border: 1px solid rgba(229, 239, 252, 0.14);
  background: #172230;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
}

body.mode-home .home-tile-name {
  color: #f0f4fa;
  font-size: 0.94rem;
}

body.mode-home .home-tile-sub {
  color: rgba(207, 220, 237, 0.65);
  font-size: 0.82rem;
}

body.mode-home .home-tile-poster:not(.is-app):not(.is-action) {
  border-radius: 0.95rem;
}

body.mode-home .home-tile-progress {
  height: 4px;
  margin-top: -4px;
  position: relative;
  z-index: 1;
}

body.mode-home .home-tile:focus-visible {
  transform: scale(1.055);
  z-index: 4;
}

body.mode-home .home-tile:focus-visible .home-tile-poster {
  outline: 3px solid #c7e3ff;
  outline-offset: 4px;
  box-shadow: 0 0 0 7px rgba(111, 177, 239, 0.18), 0 18px 40px rgba(0, 0, 0, 0.42);
}

body.mode-home .home-tile--app:focus-visible .home-tile-poster,
body.mode-home .home-tile--watch:focus-visible .home-tile-poster {
  outline-offset: 5px;
  transform: none;
}

@media (max-width: 800px) {
  body.mode-home .home-hero {
    margin-inline: 1.25rem;
  }
  body.mode-home .home-row-head,
  body.mode-home .home-rail {
    padding-inline: 1.25rem;
  }
  body.mode-home .home-tile--watch {
    width: min(20rem, 72vw);
  }
}


.home-live-progress {
  position: relative;
  z-index: 1;
  height: 4px;
  margin-top: -4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}
.home-live-progress > span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #65b5ff, #b7ddff);
  transition: width 0.25s ease;
}
.home-tile--channel .home-tile-meta { gap: 0.25rem; }
.home-tile--channel .home-live-now { color: rgba(226, 236, 249, 0.78); }
.home-tile--channel .home-live-next { color: rgba(177, 195, 217, 0.58); }
.home-load-error {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  width: fit-content;
  margin: 0 clamp(2rem, 5vw, 5rem) 1rem;
  padding: 0.7rem 0.85rem 0.7rem 1rem;
  border: 1px solid rgba(255, 190, 115, 0.22);
  border-radius: 0.9rem;
  color: #f2d4aa;
  background: rgba(67, 45, 22, 0.36);
}
.home-load-retry {
  padding: 0.35rem 0.7rem;
  border: 1px solid rgba(255, 220, 175, 0.26);
  border-radius: 999px;
  color: #fff0dc;
  background: rgba(255, 255, 255, 0.07);
  font: inherit;
  cursor: pointer;
}
.home-load-retry:focus-visible { outline: 2px solid #c7e3ff; outline-offset: 2px; }
@media (max-width: 800px) {
  .home-load-error { margin-inline: 1.25rem; }
}

/* Unified touch layout for web and Android launcher media screens. */
.library-grid-inner--episodes {
  grid-template-columns: minmax(0, 1fr);
  gap: 0.45rem;
}
.library-grid-inner--continue {
  display: flex;
  gap: 0.85rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 0.15rem 0 0.8rem;
  scroll-snap-type: x proximity;
}
.library-grid-inner--continue > .library-card {
  flex: 0 0 9.25rem;
  scroll-snap-align: start;
}
.library-episode-row {
  min-width: 0;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface, rgba(255,255,255,0.045));
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: pan-y;
}
.library-episode-row:focus-visible {
  outline: 2px solid var(--accent, #8ab4f8);
  outline-offset: 2px;
  background: var(--surface-2, rgba(255,255,255,0.08));
}
.library-episode-code {
  flex: 0 0 4.2rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.library-episode-main {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}
.library-episode-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 0.93rem;
  font-weight: 650;
}
.library-episode-sub {
  color: var(--muted);
  font-size: 0.76rem;
}
.library-episode-progress {
  flex: 0 0 4rem;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,0.18);
}
.library-episode-progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent, #8ab4f8);
}
.library-grid-inner--continue .library-poster {
  border-radius: 10px;
}
@media (max-width: 700px) {
  .library {
    height: calc(100dvh - var(--topbar-h) - var(--safe-t));
    scroll-padding-top: 0.5rem;
    padding-bottom: var(--safe-b);
  }
  .library-chrome {
    gap: 0.4rem;
    padding: 0.65rem max(1rem, env(safe-area-inset-left)) 0.6rem;
  }
  .library-toolbar { gap: 0.5rem; }
  .library-search {
    min-width: 0;
    min-height: 44px;
    padding-inline: 0.7rem;
  }
  .library-count { font-size: 0.74rem; }
  .library-back { min-height: 44px; padding-inline: 0.7rem; }
  .library-seasons { gap: 0.5rem; padding-bottom: 0.2rem; }
  .library-season-btn {
    min-height: 40px;
    padding: 0.48rem 0.9rem;
    border-radius: 999px;
  }
  .library-grid {
    gap: 1.2rem;
    padding: 0.85rem max(1rem, env(safe-area-inset-left)) calc(var(--safe-b) + 2rem);
  }
  .library-section-title { margin-bottom: 0.65rem; }
  .library-grid-inner,
  .library-grid-inner--series,
  .library-grid-inner--movies {
    grid-template-columns: repeat(auto-fill, minmax(min(38vw, 8.5rem), 1fr));
    gap: 0.8rem 0.65rem;
  }
  .library-grid-inner--episodes { grid-template-columns: minmax(0, 1fr); }
  .library-grid-inner--continue > .library-card { flex-basis: 8.25rem; }
  .library-poster { border-radius: 10px; }
  .library-episode-row { min-height: 58px; gap: 0.55rem; padding-inline: 0.7rem; }
  .library-episode-code { flex-basis: 3.5rem; font-size: 0.72rem; }
  .library-episode-title { font-size: 0.88rem; }
  .library-episode-progress { flex-basis: 2.5rem; }
}
@media (max-width: 380px) {
  .library-grid-inner--series,
  .library-grid-inner--movies { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .library-episode-code { flex-basis: 3rem; }
  .library-episode-progress { flex-basis: 1.8rem; }
}
