(() => { const search=document.querySelector('#wc-search'); if(!search) return; const focus=document.querySelector('#wc-focus'), expanded=new Set(); function update() { let total=0; for(const section of document.querySelectorAll('[data-wc-section]')) { const cards=[...section.querySelectorAll('[data-wc-story]')]; const matches=cards.filter(card=>search.value.toLowerCase().trim().split(/\s+/).every(q=>card.dataset.query.includes(q))&&(focus.value==='all'||card.dataset.preparation==='true')); cards.forEach(card=>card.hidden=true); matches.forEach((card,index)=>card.hidden=!expanded.has(section)&&index>=6); section.querySelector('[data-wc-lane-count]').textContent=`${matches.length} stories`; section.querySelector('[data-wc-empty]').hidden=matches.length>0; section.querySelector('[data-wc-more]').hidden=matches.length<=6||expanded.has(section); total+=matches.length; } document.dispatchEvent(new Event('world-cup-filtered')); document.querySelector('#wc-count').textContent=`${total} matching stories`; } for(const button of document.querySelectorAll('[data-wc-more]')) button.addEventListener('click',()=>{expanded.add(button.closest('[data-wc-section]'));update();}); search.addEventListener('input',()=>{expanded.clear();update();}); focus.addEventListener('change',()=>{expanded.clear();update();}); update(); })();