<!-- SOLID BIG ISLAND — the game shell · part 4 -->
tyle.setProperty('--p',(f*100)+'%')}

  $('#play').onclick=toggle; $('#next').onclick=()=>next(false); $('#prev').onclick=prev;
  $('#shuf').onclick=()=>{shuffle=!shuffle;$('#shuf').setAttribute('aria-pressed',shuffle);try{localStorage.setItem('sbi_shuffle',shuffle?'1':'0')}catch(e){}};
  $('#top').onclick=()=>{if(cur<0)return; const li=document.getElementById('s'+songs[cur].n); if(li){if(li.hidden){q.value='';filter('')} li.scrollIntoView({behavior:'smooth',block:'center'})}};
  audio.addEventListener('play',()=>icon(true)); audio.addEventListener('pause',()=>icon(false));
  audio.addEventListener('ended',()=>next(true));
  audio.addEventListener('timeupdate',()=>{ if(seeking)return; const d=audio.duration||songs[cur]?.dur||0; $('#cur').textContent=fmt(audio.currentTime); if(d)setSeek(audio.currentTime/d) });
  audio.addEventListener('loadedmetadata',()=>{$('#dur').textContent=fmt(audio.duration)});
  audio.addEventListener('error',()=>{ if(cur<0)return; $('#status').textContent='Could not load this track, skipping…'; setTimeout(()=>next(true),1500) });
  const sk=$('#seek');
  sk.addEventListener('input',()=>{seeking=true; const d=audio.duration||songs[cur]?.dur||0; $('#cur').textContent=fmt(sk.value/1000*d); sk.style.setProperty('--p',(sk.value/10)+'%')});
  sk.addEventListener('change',()=>{const d=audio.duration||0; if(d)audio.currentTime=sk.value/1000*d; seeking=false});
  if('mediaSession' in navigator){const ms=navigator.mediaSession;
    ms.setActionHandler('play',()=>audio.play()); ms.setActionHandler('pause',()=>audio.pause());
    ms.setActionHandler('nexttrack',()=>next(false)); ms.setActionHandler('previoustrack',prev);
    try{ms.setActionHandler('seekto',e=>{audio.currentTime=e.seekTime})}catch(e){}}
  document.addEventListener('keydown',e=>{if(e.target===q)return; if(e.code==='Space'){e.preventDefault();toggle()}});
  window.SBI={get cur(){return cur},get visible(){return visible},audio,next,load};
})();
</script>
</body>
</html>


