=== GRID / SCROLL / AUTOLOAD ===
281:.timeScroll{display:flex;min-width:8640px}
283:.grid36Wrap{overflow:hidden;background:rgba(15,20,25,.88)}
322:.prog36.focusProg{outline:2px solid rgba(0,210,255,.95)!important;box-shadow:0 0 16px rgba(0,210,255,.75)!important;border-radius:8px!important;z-index:20!important;background:rgba(25,32,40,.92)!important}
488:    <div class="timeScroll" id="timeScroll">
495:<section class="grid36Wrap" id="grid36Wrap">
598:    if(k === 'ArrowLeft'){
601:            const gw=document.getElementById('grid36Wrap');
602:            const tw=document.getElementById('timeScroll');
603:            if(gw && gw.scrollLeft > 0){ gw.scrollLeft = Math.max(0, gw.scrollLeft - 420); if(tw) tw.style.transform='translateX(-'+gw.scrollLeft+'px)'; return; }
611:    if(k === 'ArrowRight'){
614:            const gw=document.getElementById('grid36Wrap');
615:            const tw=document.getElementById('timeScroll');
616:            if(gw){ gw.scrollLeft += 420; if(tw) tw.style.transform='translateX(-'+gw.scrollLeft+'px)'; }
657:setTimeout(setFocus, 500);
677:setTimeout(function(){
707:document.addEventListener('DOMContentLoaded',function(){
764:            setTimeout(abrirFullscreenActual,250);
777:        setTimeout(abrirFullscreenActual,250);
789:  function syncProgGlow(){
790:    document.querySelectorAll('.prog36.focusProg').forEach(function(x){
791:      x.classList.remove('focusProg');
800:    if(prog) prog.classList.add('focusProg');
804:    setTimeout(syncProgGlow, 60);
808:    setTimeout(syncProgGlow, 60);
811:  setTimeout(syncProgGlow, 600);

=== FINAL JS 530-840 ===
</section>

    </main>
</div>

<script>
let zone = 2;
let idx = [0,0,0,0,0];

function groups(){
    return [
        Array.from(document.querySelectorAll('.side .navFocus')),
        Array.from(document.querySelectorAll('.cats .cat')),
        Array.from(document.querySelectorAll('.row36')),
        Array.from(document.querySelectorAll('.videoBox')),
        Array.from(document.querySelectorAll('.refreshEpg'))
    ].map(a=>a.filter(e=>e && e.offsetParent !== null));
}

function setFocus(){
    const g = groups();
    g.flat().forEach(e=>e.classList.remove('focus'));

    if(!g[zone] || !g[zone].length) return;

    idx[zone] = Math.max(0, Math.min(idx[zone], g[zone].length - 1));

    const el = g[zone][idx[zone]];
    if(!el) return;

    el.classList.add('focus');
    el.setAttribute('tabindex','0');
    el.focus({preventScroll:true});
    el.scrollIntoView({block:'nearest', inline:'nearest'});
}

function enterItem(){
    const g = groups();
    const el = g[zone] && g[zone][idx[zone]];
    if(!el) return;

    if(zone === 3){
        const v=document.getElementById('mainVideo');
        if(v){
            v.muted=false;
            v.volume=1.0;
            if(v.requestFullscreen) v.requestFullscreen();
            else if(v.webkitRequestFullscreen) v.webkitRequestFullscreen();
        }
        return;
    }

    if(el.classList.contains('row') && typeof quickPlay === 'function'){
        quickPlay(el);
        return;
    }

    if(el.href){
        window.location.href = el.href;
        return;
    }

    el.click();
}

document.addEventListener('keydown',function(e){
    const k = e.key;

    if(k === 'ArrowLeft'){
        e.preventDefault();
        if(zone === 2){
            const gw=document.getElementById('grid36Wrap');
            const tw=document.getElementById('timeScroll');
            if(gw && gw.scrollLeft > 0){ gw.scrollLeft = Math.max(0, gw.scrollLeft - 420); if(tw) tw.style.transform='translateX(-'+gw.scrollLeft+'px)'; return; }
        }
        if(zone === 4){ zone = 3; setFocus(); return; }
        zone = Math.max(0, zone - 1);
        setFocus();
        return;
    }

    if(k === 'ArrowRight'){
        e.preventDefault();
        if(zone === 2){
            const gw=document.getElementById('grid36Wrap');
            const tw=document.getElementById('timeScroll');
            if(gw){ gw.scrollLeft += 420; if(tw) tw.style.transform='translateX(-'+gw.scrollLeft+'px)'; }
            return;
        }
        if(zone === 3){ zone = 4; setFocus(); return; }
        zone = Math.min(4, zone + 1);
        setFocus();
        return;
    }

    if(k === 'ArrowUp'){
        e.preventDefault();
        if(zone === 2){
            if(idx[zone] <= 0){
                zone = 3;
                setFocus();
                return;
            }
            idx[zone]--;
            setFocus();
            return;
        }
        idx[zone]--;
        setFocus();
        return;
    }

    if(k === 'ArrowDown'){
        e.preventDefault();
        if(zone === 3 || zone === 4){ zone = 2; setFocus(); return; }
        idx[zone]++;
        setFocus();
        return;
    }

    if(k === 'Enter'){
        e.preventDefault();
        enterItem();
        return;
    }
}, true);

setTimeout(setFocus, 500);
</script>

<script>
function quickPlay(row){
    const video=document.getElementById('mainVideo');
    const title=document.getElementById('channelTitle');
    if(!row || !video) return false;

    const url=row.getAttribute('data-play');
    const name=row.getAttribute('data-name') || 'Canal';

    if(!url) return false;

    document.querySelectorAll('.row').forEach(r=>r.classList.remove('active'));
    row.classList.add('active');

    if(title) title.textContent=name;

/* FOCO_PLAYER_AUTOMATICO_FINAL */
setTimeout(function(){
    document.querySelectorAll('.focus').forEach(function(x){x.classList.remove('focus');});
    var box=document.querySelector('.videoBox');
    if(box){
        box.classList.add('focus');
        box.setAttribute('tabindex','0');
        box.focus();
    }
},250);

    video.muted = false;
    video.volume = 1.0;
    if(video.src !== url){
        video.src = url;
    }
    video.play().catch(()=>{});

    return true;
}

document.addEventListener('click',function(e){
    const row=e.target.closest('.row');
    if(row){
        e.preventDefault();
        quickPlay(row);
    }
},true);
</script>

<script>
document.addEventListener('DOMContentLoaded',function(){
    const v=document.getElementById('mainVideo');
    if(v){
        v.muted=false;
        v.volume=1.0;
        v.addEventListener('dblclick',function(){
            if(v.requestFullscreen) v.requestFullscreen();
            else if(v.webkitRequestFullscreen) v.webkitRequestFullscreen();
        });
    }
});
</script>

<script>
let lastRow = null;
let lastTime = 0;

function abrirFullscreenActual(){
    const v=document.getElementById('mainVideo');
    const focused=document.querySelector('.focus.row');
    const active=document.querySelector('.row.active');

    let url = "";

    if(focused && focused.getAttribute('data-play')) url = focused.getAttribute('data-play');
    else if(active && active.getAttribute('data-play')) url = active.getAttribute('data-play');
    else if(v && v.currentSrc) url = v.currentSrc;
    else if(v && v.src) url = v.src;

    if(!url) return;

    if(window.PuntozAndroid && PuntozAndroid.abrirFullscreen){
        PuntozAndroid.abrirFullscreen(url);
        return;
    }

    if(v.requestFullscreen) v.requestFullscreen();
    else if(v.webkitRequestFullscreen) v.webkitRequestFullscreen();
}

document.addEventListener('keydown',function(e){
    if(e.key !== 'Enter') return;

    const el=document.querySelector('.focus');

    if(el && el.classList.contains('videoBox')){
        e.preventDefault();
        abrirFullscreenActual();
        return;
    }

    if(el && el.classList.contains('row')){
        const now=Date.now();

        if(lastRow === el && (now-lastTime) < 700){
            e.preventDefault();
            if(typeof quickPlay === 'function') quickPlay(el);
            setTimeout(abrirFullscreenActual,250);
            return;
        }

        lastRow = el;
        lastTime = now;
    }
},true);

document.addEventListener('dblclick',function(e){
    const row=e.target.closest('.row');
    if(row){
        if(typeof quickPlay === 'function') quickPlay(row);
        setTimeout(abrirFullscreenActual,250);
    }
},true);
</script>





<script>
/* GLOW PROGRAMA SIGUE AL CANAL NAVEGADO */
(function(){
  function syncProgGlow(){
    document.querySelectorAll('.prog36.focusProg').forEach(function(x){
      x.classList.remove('focusProg');
    });

    var row = document.querySelector('.row36.focus');
    if(!row) return;

    var prog = row.querySelector('.prog36.nowProg');
    if(!prog) prog = row.querySelector('.prog36');

    if(prog) prog.classList.add('focusProg');
  }

  document.addEventListener('keydown', function(){
    setTimeout(syncProgGlow, 60);
  }, true);

  document.addEventListener('click', function(){
    setTimeout(syncProgGlow, 60);
  }, true);

  setTimeout(syncProgGlow, 600);
})();
</script>


</body>
</html>
