/* TV layout correction. Every rule is scoped to TV; touch layouts retain their styles. */
html[data-device-mode="tv"]{
  --tv-edge:clamp(24px,3.8vw,80px);
  --tv-edge-y:clamp(14px,2.8vh,34px);
  --tv-gap:clamp(10px,1.6vh,20px);
  --tv-body:clamp(14px,min(1.14vw,2.2vh),25px);
  --tv-small:clamp(11px,min(.84vw,1.65vh),18px);
  --tv-heading:clamp(26px,min(2.65vw,5vh),54px);
}
/* Flow rows keep the header, complete category bar and body from overlapping. */
html[data-device-mode="tv"] #screen-home.is-active,
html[data-device-mode="tv"] #screen-library.is-active,
html[data-device-mode="tv"] #screen-tv.is-active{
  display:grid;padding:var(--tv-edge-y) var(--tv-edge);gap:var(--tv-gap);
  grid-template-rows:auto minmax(0,1fr) auto;
}
html[data-device-mode="tv"] #screen-library.is-active,
html[data-device-mode="tv"] #screen-tv.is-active{grid-template-rows:auto auto minmax(0,1fr) auto}
html[data-device-mode="tv"] :is(#screen-home,#screen-library,#screen-tv) .help-strip{
  position:relative;inset:auto;grid-row:-2;min-height:24px;height:auto;padding:6px 12px;
  width:100%;font-size:var(--tv-small);border-radius:10px;gap:3vw;
}
html[data-device-mode="tv"] .home-header{
  position:relative;inset:auto;grid-row:1;margin:0;width:100%;min-width:0;gap:20px;
}
html[data-device-mode="tv"] .brand-inline img{
  width:clamp(42px,6.4vh,70px);height:clamp(42px,6.4vh,70px);flex-shrink:0;
}
html[data-device-mode="tv"] .brand-inline strong{font-size:clamp(18px,min(1.6vw,3vh),32px)}
html[data-device-mode="tv"] .brand-inline span,
html[data-device-mode="tv"] .home-account span{font-size:var(--tv-small)}
html[data-device-mode="tv"] .home-account strong{font-size:var(--tv-body)}
html[data-device-mode="tv"] .home-content{
  position:relative;inset:auto;grid-row:2;width:100%;max-width:none;min-height:0;padding:6px;
  display:flex;flex-direction:column;justify-content:center;gap:var(--tv-gap);overflow:auto;
}
html[data-device-mode="tv"] .home-content>.eyebrow{font-size:var(--tv-small);flex-shrink:0}
html[data-device-mode="tv"] .home-content h1{font-size:var(--tv-heading);line-height:1.12;margin:0;flex-shrink:0}
html[data-device-mode="tv"] .home-content>p{
  font-size:var(--tv-body);line-height:1.4;margin:0;width:100%;max-width:72ch;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;flex-shrink:0;
}
html[data-device-mode="tv"] .home-stats{margin:0;gap:8px;flex-wrap:wrap;flex-shrink:0}
html[data-device-mode="tv"] .home-stats span{font-size:var(--tv-small);padding:6px 10px;line-height:1.2}
html[data-device-mode="tv"] .home-menu{
  width:100%;margin:0;display:grid;grid-template-columns:repeat(4,minmax(0,1fr));
  grid-template-rows:repeat(2,minmax(0,1fr));gap:var(--tv-gap);
  height:clamp(210px,40vh,430px);min-height:0;flex:0 0 auto;padding:4px;
}
html[data-device-mode="tv"] .home-option{
  height:100%;min-height:0;min-width:0;display:flex;flex-direction:column;align-items:flex-start;
  justify-content:center;gap:clamp(8px,1.2vh,14px);padding:clamp(12px,1.8vh,22px);
  border-radius:clamp(12px,1.6vw,24px);overflow:hidden;
}
html[data-device-mode="tv"] .home-option img{
  position:static;inset:auto;display:block;width:clamp(26px,4vh,46px);height:clamp(26px,4vh,46px);
  min-height:clamp(26px,4vh,46px);object-fit:contain;flex:0 0 auto;transform:none;margin:0;
}
html[data-device-mode="tv"] .home-option>div{min-width:0;width:100%;flex:0 0 auto}
html[data-device-mode="tv"] .home-option strong{font-size:clamp(16px,min(1.35vw,2.7vh),28px);line-height:1.2}
html[data-device-mode="tv"] .home-option span{
  font-size:var(--tv-small);line-height:1.35;margin-top:6px;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
}
html[data-device-mode="tv"] .home-option:after{right:12px;top:10px;font-size:var(--tv-small)}
html[data-device-mode="tv"] .home-option.is-focused{transform:none;outline-offset:2px}
html[data-device-mode="tv"] :is(.library-screen,.tv-screen) .ui-back{
  position:absolute;top:var(--tv-edge-y);right:var(--tv-edge);margin:0;
  min-height:clamp(40px,5.2vh,58px);padding:8px 16px;font-size:var(--tv-small);
}
html[data-device-mode="tv"] :is(.library-screen .library-header,.tv-screen .tv-header){
  position:relative;inset:auto;grid-row:1;margin:0;width:100%;min-width:0;
  padding-right:clamp(116px,9vw,180px);gap:18px;align-items:center;
}
html[data-device-mode="tv"] :is(.library-header,.tv-header) h1{
  font-size:var(--tv-heading);line-height:1.08;margin:6px 0 0;max-width:100%;
}
html[data-device-mode="tv"] :is(.library-screen,.tv-screen) .eyebrow{font-size:var(--tv-small)}
html[data-device-mode="tv"] .library-actions{padding-right:0;gap:10px;flex-shrink:0}
html[data-device-mode="tv"] .round-action{width:clamp(40px,5.8vh,62px);height:clamp(40px,5.8vh,62px);font-size:clamp(23px,3.2vh,36px)}
html[data-device-mode="tv"] #tv-network-state{
  margin:0;max-width:48%;font-size:var(--tv-small);padding:8px 12px;white-space:nowrap;
  overflow:hidden;text-overflow:ellipsis;
}
html[data-device-mode="tv"] :is(.library-tabs,.tv-categories){
  position:relative;inset:auto;grid-row:2;width:100%;height:auto;min-height:0;
  display:flex;align-items:center;gap:10px;padding:6px;overflow-x:auto;overflow-y:hidden;
  scrollbar-width:none;scroll-padding-inline:6px;
}
html[data-device-mode="tv"] :is(.library-tabs,.tv-categories)::-webkit-scrollbar{display:none}
html[data-device-mode="tv"] .tab{
  flex:0 0 auto;min-height:clamp(38px,5.2vh,56px);height:auto;
  padding:10px 16px;font-size:var(--tv-small);line-height:1.2;white-space:nowrap;
}
html[data-device-mode="tv"] .tab.is-focused{transform:none;outline-offset:2px}
html[data-device-mode="tv"] :is(.library-stage,.tv-layout){
  position:relative;inset:auto;grid-row:3;width:100%;height:100%;min-width:0;min-height:0;
  display:grid;grid-template-columns:minmax(0,28%) minmax(0,1fr);gap:clamp(14px,2vw,36px);
}
html[data-device-mode="tv"] .library-hero{
  min-width:0;min-height:0;height:100%;padding:clamp(14px,2.4vh,28px);
  display:grid;grid-template-rows:auto auto minmax(0,1fr) auto auto;
  gap:clamp(8px,1.4vh,16px);overflow:hidden;align-content:stretch;
}
html[data-device-mode="tv"] .lib-meta{font-size:var(--tv-small);line-height:1.2}
html[data-device-mode="tv"] .library-hero h2{
  font-size:clamp(20px,min(1.9vw,3.7vh),40px);line-height:1.16;margin:0;
  display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden;
}
html[data-device-mode="tv"] .library-hero p{
  font-size:var(--tv-body);line-height:1.5;margin:0;max-height:none;min-height:0;overflow:auto;
}
html[data-device-mode="tv"] .hero-tags{margin:0;gap:6px;min-width:0;flex-wrap:wrap}
html[data-device-mode="tv"] .hero-tags span{
  font-size:var(--tv-small);padding:6px 8px;max-width:100%;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
html[data-device-mode="tv"] :is(.library-hero,.tv-info) .hero-actions{
  margin:0;gap:8px;display:grid;grid-template-columns:1fr 1fr;min-width:0;
}
html[data-device-mode="tv"] :is(.library-hero,.tv-info) .hero-actions button{
  width:100%;min-width:0;min-height:clamp(40px,5.6vh,60px);padding:10px 8px;
  font-size:var(--tv-small);line-height:1.25;
}
html[data-device-mode="tv"] .library-stage>main{
  display:flex;flex-direction:column;min-height:0;min-width:0;height:100%;overflow:hidden;
}
html[data-device-mode="tv"] #library-grid{
  height:auto;min-height:0;flex:1;overflow-y:auto;overflow-x:hidden;padding:6px;
  grid-template-columns:repeat(5,minmax(0,1fr));grid-auto-rows:max-content;
  gap:clamp(10px,1vw,18px);align-content:start;align-items:start;
}
html[data-device-mode="tv"] #library-grid .poster-card{height:auto;min-height:min-content}
html[data-device-mode="tv"] .poster-info{min-height:clamp(50px,7vh,76px);padding:10px}
html[data-device-mode="tv"] .poster-info strong{font-size:var(--tv-small);line-height:1.3}
html[data-device-mode="tv"] .poster-info span{font-size:var(--tv-small);margin-top:5px}
html[data-device-mode="tv"] .page-indicator{
  flex-shrink:0;margin:0;padding:6px;font-size:var(--tv-small);line-height:1.3;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
html[data-device-mode="tv"] .tv-layout{grid-template-columns:minmax(0,36%) minmax(0,1fr)}
html[data-device-mode="tv"] .tv-channel-list{min-width:0;min-height:0;height:100%;padding:10px;overflow-y:auto}
html[data-device-mode="tv"] .channel-row{
  min-height:clamp(58px,9.2vh,106px);height:auto;padding:10px;gap:12px;margin-bottom:8px;
}
html[data-device-mode="tv"] .channel-row img{width:clamp(44px,6.8vh,78px);height:clamp(32px,5.5vh,62px);object-fit:contain;flex-shrink:0}
html[data-device-mode="tv"] .channel-row>div:last-child{min-width:0}
html[data-device-mode="tv"] .channel-row strong{font-size:var(--tv-body);line-height:1.25;overflow-wrap:anywhere}
html[data-device-mode="tv"] .channel-row span,
html[data-device-mode="tv"] .channel-row .num{font-size:var(--tv-small)}
html[data-device-mode="tv"] .tv-info{
  height:100%;min-height:0;min-width:0;padding:clamp(14px,2.4vh,28px);
  display:grid;grid-template-rows:auto auto auto minmax(0,1fr) auto;
  gap:clamp(8px,1.4vh,16px);overflow:hidden;
}
html[data-device-mode="tv"] .tv-info-top{min-height:0;align-items:center;gap:12px}
html[data-device-mode="tv"] .tv-logo-wrap{height:clamp(40px,7vh,84px);min-width:0}
html[data-device-mode="tv"] .tv-logo-wrap img{max-height:100%;max-width:clamp(120px,15vw,300px);object-fit:contain}
html[data-device-mode="tv"] .live-pill{font-size:var(--tv-small);padding:8px 12px;flex-shrink:0}
html[data-device-mode="tv"] .tv-info h2{
  font-size:clamp(23px,min(2.25vw,4.3vh),46px);line-height:1.15;margin:0;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
}
html[data-device-mode="tv"] .tv-info p{
  font-size:var(--tv-body);margin:0;line-height:1.4;max-width:none;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
}
html[data-device-mode="tv"] .epg-panel{min-height:0;gap:12px;margin:0;align-self:stretch}
html[data-device-mode="tv"] .epg-panel>div{
  min-height:0;min-width:0;padding:clamp(10px,1.8vh,22px);display:flex;
  flex-direction:column;justify-content:center;overflow:hidden;
}
html[data-device-mode="tv"] .epg-panel span,
html[data-device-mode="tv"] .epg-panel small{font-size:var(--tv-small);line-height:1.3}
html[data-device-mode="tv"] .epg-panel strong{
  font-size:var(--tv-body);line-height:1.3;margin:8px 0;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
}
@media(max-height:650px){
  html[data-device-mode="tv"] .home-option{flex-direction:row;align-items:center;gap:12px;padding:14px}
  html[data-device-mode="tv"] .home-option>div{width:auto;flex:1}
  html[data-device-mode="tv"] .home-option:after{font-size:10px;top:5px;right:8px}
  html[data-device-mode="tv"] .library-hero h2{-webkit-line-clamp:2}
}
@media(max-height:500px){
  html[data-device-mode="tv"] .home-content>.eyebrow,
  html[data-device-mode="tv"] .home-content>p,
  html[data-device-mode="tv"] .home-option span{display:none}
  html[data-device-mode="tv"] .home-menu{height:210px}
  html[data-device-mode="tv"] .tv-info p{display:none}
  html[data-device-mode="tv"] .tv-info{grid-template-rows:auto auto minmax(0,1fr) auto}
  html[data-device-mode="tv"] .tv-logo-wrap{height:36px}
  html[data-device-mode="tv"] .epg-panel strong{margin:5px 0;font-size:14px}
}
