function sapToggleAudio(id, btn){
const a = document.getElementById(id);
// pause others
document.querySelectorAll('audio').forEach(x => { if(x!==a) x.pause(); });
if(a.paused){ a.play(); } else { a.pause(); }
}
// ===== Sapientify: Numbered Vocab Tabs (JS) =====
(function(){
// tab switching
document.addEventListener('click', function(e){
const btn = e.target.closest('.sap-step[data-target]');
if(!btn) return;
const wrap = btn.closest('.sap-tabs');
const targetSel = btn.getAttribute('data-target');
const target = wrap.querySelector(targetSel);
if(!target) return;
// update buttons
wrap.querySelectorAll('.sap-step').forEach(b=>{
b.classList.toggle('is-active', b===btn);
b.setAttribute('aria-selected', b===btn ? 'true' : 'false');
});
// update panels
wrap.querySelectorAll('.sap-tab').forEach(p=>{
if(p===target){ p.hidden=false; p.classList.add('is-active'); }
else{ p.hidden=true; p.classList.remove('is-active'); }
});
});
// play/pause audio inside the example cell
document.addEventListener('click', function(e){
const aBtn = e.target.closest('.sap-audio-btn[data-audio]');
if(!aBtn) return;
const id = aBtn.getAttribute('data-audio');
const audio = document.getElementById(id);
if(!audio) return;
if(audio.paused){ audio.play(); }
else{ audio.pause(); }
});
})();