zz birthday mix chunk 3 of 5 (Claude, hidden, do not edit)
st $$=s=⟩[...document.querySelectorAll(s)];
const reduce=matchMedia('(prefers-reduced-motion: reduce)').matches;
const K='bkMix26';let st={agreed:false,name:'',code:'',body:'',mind:'',soul:'',cine:null};
try{st=Object.assign(st,JSON.parse(localStorage.getItem(K)||'{}'))}catch(e){}
const save=()=⟩{try{localStorage.setItem(K,JSON.stringify(st))}catch(e){}};
const esc=v=⟩String(v).replace(/[⟨⟩&"]/g,'');
let soundOn=true;
/* ---------- music library (Bacci Kid originals, Bunny CDN) ---------- */
const CDN='https://baccikid.b-cdn.net/01%20Bacci%20Music/';
const SONGS=[
{k:'T',name:'Bacci Kid theme',sub:'30 second loop, two layers',layers:[
{k:'b',name:'Bacci beat',sub:'instrumental',ic:'🥁',src:CDN+'01%20More%20Music/01%20Final%20Bacci%20Theme%20Song/Bacci%20Kid%20-%20Instrumental%20V2.mp3',on:true},
{k:'v',name:"Bacci's voice",sub:'vocals only',ic:'🎤',src:CDN+'01%20More%20Music/01%20Final%20Bacci%20Theme%20Song/Bacci%20Kid%20-%20Vocals%20Only.mp3',on:false}]},
{k:'S',name:'Sporty Quest',sub:'full song, teen and adult edition',layers:[
{k:'s',name:'Sporty Quest',sub:'full song',ic:'🏆',src:CDN+'01%20Sporty%20Quest%20Song/Sporty%20Quest_%20Teen%20%26%20Adult%20Edition%20-%20Champions%20of%20Emotional%20Intelligence.mp3',on:true,maybe:true}]}
];
const SFX=[{k:'1',name:'Sparkle',ic:'✦',c:'#ffd35c'},{k:'2',name:'Party horn',ic:'🎉',c:'#ff5fa2'},{k:'3',name:'Drum tap',ic:'🥁',c:'#5ee7ff'},{k:'4',name:'Whoosh',ic:'💨',c:'#8ff0c6'},{k:'5',name:'Candle blow',ic:'🕯️',c:'#ffb347'},{k:'6',name:'Cheer',ic:'🎈',c:'#b995ff'}];
/* ---------- audio ---------- */
let AC=null;function ac(){try{AC=AC||new (window.AudioContext||window.webkitAudioContext)();if(AC.state==='suspended'){const r=AC.resume();if(r&&r.catch)r.catch(()=⟩{})}}catch(e){}return AC}
function tone(f,d,v,type,slide){if(!soundOn)return;const c=ac();if(!c)return;try{const o=c.createOscillator(),g=c.createGain();o.type=type||'sine';o.frequency.setValueAtTime(f,c.currentTime);if(slide)o.frequency.exponentialRampToValueAtTime(slide,c.currentTime+d);g.gain.setValueAtTime(v,c.currentTime);g.gain.exponentialRampToValueAtTime(.0001,c.currentTime+d);o.connect(g).connect(c.destination);o.start();o.stop(c.currentTime+d)}catch(e){}}
function noise(d,v,hp){if(!soundOn)return;const c=ac();if(!c)return;try{const n=c.sampleRate*d,buf=c.createBuffer(1,n,c.sampleRate),ch=buf.getChannelData(0);for(let i=0;i⟨n;i++)ch[i]=(Math.random()*2-1)*(1-i/n);const s=c.createBufferSource();s.buffer=buf;const f=c.createBiquadFilter();f.type=hp?'highpass':'lowpass';f.frequency.value=hp?1800:900;const g=c.createGain();g.gain.setValueAtTime(v,c.currentTime);g.gain.exponentialRampToValueAtTime(.0001,c.currentTime+d);s.connect(f).connect(g).connect(c.destination);s.start()}catch(e){}}
const playSfx={1:()=⟩{[880,1320,1760].forEach((f,i)=⟩setTimeout(()=⟩tone(f,.5,.12),i*70))},2:()=⟩{tone(392,.35,.16,'sawtooth',523);setTimeout(()=⟩tone(523,.45,.16,'sawtooth',659),180)},3:()=⟩{tone(150,.22,.3,'sine',55);noise(.12,.18,false)},4:()=⟩noise(.5,.22,true),5:()=⟩noise(.7,.16,false),6:()=⟩{noise(.6,.14,true);[523,659,784].forEach((f,i)=⟩setTimeout(()=⟩tone(f,.35,.1,'triangle'),i*90))}};
const els={};let song=SONGS[0],playing=false,t0=0,raf=0,taps=[],timers=[],loopLen=30.36;
function audioFor(l){if(!els[l.k]){const a=new Audio();a.preload=l.maybe?'metadata':'none';a.src=l.src;a.loop=false;a.setAttribute('playsinline','');els[l.k]=a;a.addEventListener('error',()=⟩{l.err=true;renderLayers();status('One song is resting right now. The others are ready.')});if(l.maybe)a.addEventListener('loadedmetadata',()=⟩{l.ok=true;renderLayers()})}return els[l.k]}
function status(m){$('#mixStatus').textContent=m}
/* ---------- particles ---------- */
const cv=$('#fx'),g=cv.getContext('2d');let W=0,H=0,D=1,P=[],C=[],pal=['#ffd35c','#fff2c4','#ffb347'];
function rs(){D=Math.min(devicePixelRatio||1,2);W=cv.width=innerWidth*D;H=cv.height=innerHeight*D}rs();addEventListener('resize',rs);
function seed(){P=[];const n=reduce?0:(innerWidth⟨700?42:70);for(let i=0;i⟨n;i++)P.push(mk(true))}
function mk(any){return {x:Math.random()*W,y:any?Math.random()*H:H+10*D,r:(1+Math.random()*2.2)*D,vy:(-.12-Math.random()*.35)*D,vx:(Math.random()-.5)*.25*D,a:Math.random()*Math.PI*2,c:pal[Math.floor(Math.random()*pal.length)],tw:.5+Math.random()*2}}
function burst(n){if(reduce)return;for(let i=0;i⟨(n||70);i++)C.push({x:W/2+(Math.random()-.5)*W*.5,y:H*.3,vx:(Math.random()-.5)*9*D,vy:(-7-Math.random()*6)*D,r:(3+Math.random()*4)*D,c:['#ffd35c','#ff5fa2','#8ff0c6','#b995ff','#5ee7ff','#fff'][i%6],a:Math.random()*6,s:(Math.random()-.5)*.3,l:1})}
let last=0;function loop(t){raf2=requestAnimationFrame(loop);if(document.hidden)return;const dt=Math.min(40,t-last);last=t;g.clearRect(0,0,W,H);for(const p of P){p.y+=p.vy*dt/16;p.x+=p.vx*dt/16+Math.sin(t/900+p.a)*.15*D;if(p.y⟨-10*D){Object.assign(p,mk(false))}const al=.35+.65*Math.abs(Math.sin(t/1000*p.tw+p.a));g.globalAlpha=al;g.fillStyle=p.c;g.shadowColor=p.c;g.shadowBlur=8*D;g.beginPath();g.arc(p.x,p.y,p.r,0,6.283);g.fill()}g.shadowBlur=0;g.globalAlpha=1;C=C.filter(c=⟩c.y⟨H+20*D);for(const c of C){c.vy+=.28*D;c.x+=c.vx;c.y+=c.vy;c.a+=c.s;g.save();g.translate(c.x,c.y);g.rotate(c.a);g.fillStyle=c.c;g.fillRect(-c.r,-c.r/2,c.r*2,c.r);g.restore()}}
let raf2=0;seed();if(!reduce)requestAnimationFrame(loop);
/* ---------- parallax (pointer on desktop, tilt on phones) ---------- */
const stage=$('#stage');let tx=0,ty=0,cx=0,cy=0,tiltOK=false;
function setPx(){cx+=(tx-cx)*.06;cy+=(ty-cy)*.06;stage.style.setProperty('--px',cx.toFixed(2)+'px');stage.style.setProperty('--py',cy.toFixed(2)+'px');requestAnimationFrame(setPx)}if(!reduce)requestAnimationFrame(setPx);
addEventListener('pointermove',e=⟩{if(e.pointerType==='touch')return;tx=(e.clientX/innerWidth-.5)*-26;ty=(e.clientY/innerHeight-.5)*-16});
function tiltOn(){if(tiltOK)return;const go=()=⟩{tiltOK=true;addEventListener('deviceorientation',e=⟩{if(e.gamma==null)return;tx=Math.max(-18,Math.min(18,-e.gamma*.7));ty=Math.max(-14,Math.min(14,-(e.beta-40)*.4))})};try{if(typeof DeviceOrientationEvent!=='undefined'&&typeof DeviceOrientationEvent.requestPermission==='function'){DeviceOrientationEvent.requestPermission().then(r=⟩{if(r==='granted')go()}).catch(()=⟩{})}else if('DeviceOrientationEvent' in window){go()}}catch(e){}}
/* ---------- cinema backdrops ---------- */
const bigScreen=matchMedia('(min-width:900px)').matches;const saveData=navigator.connection&&navigator.connection.saveData;
let cine=st.cine==null?(bigScreen&&!saveData&&!reduce):!!st.cine;
function cineUI(){$('#cineBtn').setAttribute('aria-pressed',cine?'true':'false')}
function vidFor(id){const v=$('#'+id+' video');if(!v)return;if(cine){if(!v.getAttribute('src')){v.src=v.dataset.src;v.load()}const p=v.play();if(p&&p.catch)p.catch(()=⟩{});v.onplaying=()=⟩v.classList.add('ready')}else{try{v.pause()}catch(e){}v.classList.remove('ready')}}
function vidsOff(except){$$('.bg video').forEach(v=⟩{if(v.closest('.bg').id!==except){try{v.pause()}catch(e){}v.classList.remove('ready')}})}
$('#cineBtn').onclick=()=⟩{cine=!cine;st.cine=cine;save();cineUI();tone(cine?880:440,.2,.06);const on=$('.bg.on');if(on){vidFor(on.id)}if(!cine)vidsOff('')};
cineUI();
/* ---------- scenes ---------- */
const BG={arrive:'bgArrive',mix:'bgMix',cake:'bgCake',wish:'bgWish'};const PAL={arrive:['#ffd35c','#fff2c4','#ffb347'],mix:['#5ee7ff','#ff5fa2','#b995ff','#ffd35c'],cake:['#ffd35c','#ffc2d6','#fff'],wish:['#fff','#fff2c4','#ffd35c']};
let scene='arrive';
function go(id){if(id!=='arrive'&&!st.agreed){id='arrive'}if(id==='mix'&&!st.agreed)id='arrive';scene=id;$$('.scene').forEach(s=⟩s.classList.toggle('on',s.id==='s'+id[0].toUpperCase()+id.slice(1)));$$('.bg').forEach(b=⟩b.classList.toggle('on',b.id===BG[id]));vidsOff(BG[id]);vidFor(BG[id]);pal=PAL[id];P.forEach(p=⟩p.c=pal[Math.floor(Math.random()*pal.length)]);$$('.dock button[data-step]').forEach(b=⟩b.setAttribute('aria-current',b.dataset.step===id?'step':'false'));if(id==='wish')wishSummary();if(id!=='mix'&&playing)stop();closeSheets()}
$$('.dock button[data-step]').forEach(b=⟩b.onclick=()=⟩{if(!st.agreed){go('arrive');tone(440,.2,.06);$('#gate').animate([{transform:'scale(1)'},{transform:'scale(1.02)'},{transform:'scale(1)'}],{duration:350});return}go(b.dataset.step);tone(660,.15,.06)});
/* ---------- sheets ---------- */
function openSheet(id){$('#'+id).classList.add('on')}function closeSheets(){$$('.sheet').forEach(s=⟩s.classList.remove('on'))}
$$('[data-close]').forEach(b=⟩b.onclick=()=⟩{$('#'+b.dataset.close).classList.remove('on')});
$$('.sheet').forEach(s=⟩s.addEventListener('click',e=⟩{if(e.target===s)s.classList.remove('on')}));
$('#infoBtn').onclick=()=⟩{openSheet('shInfo');tone(600,.15,.05)};
$('#sndBtn').onclick=()=⟩{soundOn=!soundOn;$('#sndBtn').textContent=soundOn?'🔊':'🔈';$('#sndBtn').setAttribute('aria-pressed',soundOn);tone(880,.2,.06)};
/* ---------- agreement gate ---------- */
function showBack(){$('#gate').hidden=true;$('#back').hidden=false}
$('#agreeChk').onchange=()=⟩{$('#agreeBtn').disabled=!$('#agreeChk').checked};
$('#agreeBtn').onclick=()=⟩{st.agreed=true;st.agreedAt=new Date().toISOString();save();ac();tiltOn();tone(660,.3,.08);setTimeout(()=⟩tone(990,.4,.08),150);burst(90);showBack();setTimeout(()=⟩go('mix'),350)};
function reread(e){e.preventDefault();closeSheets();$('#back').hidden=true;$('#gate').hidden=false;$('#agreeChk').checked=true;$('#agreeBtn').disabled=false;go('arrive')}
$('#reread').onclick=reread;$('#reread2').onclick=reread;
$('#bkMix').onclick=()=⟩{tiltOn();go('mix')};$('#bkCake').onclick=()=⟩{tiltOn();go('cake')};$('#bkWish').onclick=()=⟩{tiltOn();go('wish')};
/* ---------- mixer render ---------- */
function renderSongs(){$('#songs').innerHTML=SONGS.map(s=⟩`⟨button class="pill" type="button" data-k="${s.k}" aria-pressed="${s===song}"⟩⟨b⟩${s.name}⟨/b⟩⟨span⟩${s.sub}⟨/span⟩⟨/button⟩`).join('');$$('#songs .pill').forEach(b=⟩b.onclick=()=⟩{const s=SONGS.find(x=⟩x.k===b.dataset.k);if(s===song)return;stop();song=s;taps=[];renderSongs();renderLayers();dots();tone(660,.2,.08)})}
function renderLayers(){$('#layers').innerHTML=song.layers.map(l=⟩`⟨button class="layer${l.err?' off':''}" type="button" data-k="${l.k}" aria-pressed="${l.on&&!l.err}" ${l.err?'disabled':''}⟩⟨span class="ic"⟩${l.ic}⟨/span⟩⟨span⟩⟨b⟩${l.name}⟨/b⟩⟨span⟩${l.err?'resting today':l.sub}⟨/span⟩⟨/span⟩⟨/button⟩`).join('');$$('#layers .layer').forEach(b=⟩b.onclick=()=⟩{const l=song.layers.find(x=⟩x.k===b.dataset.k);if(l.err)return;l.on=!l.on;b.setAttribute('aria-pressed',l.on);if(playing){const a=audioFor(l);if(l.on){try{a.currentTime=Math.min(cur(),Math.max(0,(a.duration||loopLen)-.2))}catch(e){}const p=a.play();if(p&&p.catch)p.catch(()=⟩{})}else a.pause()}tone(l.on?784:440,.15,.07)})}
function renderSfx(){$('#sfx').innerHTML=SFX.map(s=⟩`⟨button class="pad" type="button" data-k="${s.k}" style="--c:${s.c}"⟩⟨i class="rip"⟩⟨/i⟩⟨span class="ic"⟩${s.ic}⟨/span⟩⟨b⟩${s.name}⟨/b⟩⟨/button⟩`).join('');$$('#sfx .pad').forEach(b=⟩{const fire=()=⟩{hit(b);playSfx[b.dataset.k]();if(playing&&taps.length⟨40){taps.push([b.dataset.k,Math.round(cur()*4)/4]);dots()}};b.addEventListener('pointerdown',e=⟩{e.preventDefault();fire()});b.addEventListener('keydown',e=⟩{if(e.key==='Enter'||e.key===' '){e.preventDefault();fire()}})})}
function hit(b){b.classList.remove('hit');void b.offsetWidth;b.classList.add('hit');setTimeout(()=⟩b.classList.remove('hit'),260)}
function dots(){$('#dots').innerHTML=taps.map(t=⟩`⟨i class="dot" style="--a:${(t[1]/loopLen*360).toFixed(1)}deg"⟩⟨/i⟩`).join('')}
function cur(){return playing?((performance.now()-t0)/1000)%loopLen:0}
/* ---------- transport ---------- */
function activeLayers(){return song.layers.filter(l=⟩l.on&&!l.err)}
function play(){ac();const L=activeLayers();if(!L.length){status('Turn on at least one layer, then play.');return}const master=audioFor(L[0]);L.forEach(l=⟩{const a=audioFor(l);try{a.currentTime=0}catch(e){}const p=a.play();if(p&&p.catch)p.catch(()=⟩{status('Tap the record once more so your phone lets the music start.')})});playing=true;t0=performance.now();loopLen=(master.duration&&isFinite(master.duration)&&master.duration⟩1)?master.duration:30.36;master.onloadedmetadata=()=⟩{if(master.duration⟩1)loopLen=master.duration};master.onended=()=⟩{if(playing)restart()};$('#turn').classList.add('playing');$('#turnIc').textContent='■';$('#deckBig').textContent='Playing · 0s';scheduleTaps();tick();status('Tap the pads to add Bacci sounds. Every tap goes into your mix.');burst(60)}
function restart(){t0=performance.now();activeLayers().forEach(l=⟩{const a=audioFor(l);try{a.currentTime=0}catch(e){}const p=a.play();if(p&&p.catch)p.catch(()=⟩{})});clearTimers();scheduleTaps()}
function stop(){playing=false;cancelAnimationFrame(raf);clearTimers();Object.values(els).forEach(a=⟩{try{a.pause()}catch(e){}});$('#turn').classList.remove('playing');$('#turnIc').textContent='▶';$('#ringFg').style.strokeDashoffset=308;$('#deckBig').textContent='Tap the record to play';status(taps.length?'Stopped. Your mix has '+taps.length+' Bacci sounds in it. Keep my mix saves the code.':'Stopped.')}
function clearTimers(){timers.forEach(clearTimeout);timers=[]}
function scheduleTaps(){taps.forEach(t=⟩{timers.push(setTimeout(()=⟩{if(!playing)return;playSfx[t[0]]();const b=$(`#sfx .pad[data-k="${t[0]}"]`);if(b)hit(b)},t[1]*1000))})}
function tick(){if(!playing)return;const c=cur();$('#ringFg').style.strokeDashoffset=308-308*(c/loopLen);$('#deckBig').textContent='Playing · '+Math.floor(c)+'s';raf=requestAnimationFrame(tick)}
$('#turn').onclick=()=⟩{if(playing)stop();else play()};
$('#clearBtn').onclick=()=⟩{taps=[];dots();tone(440,.2,.06);status('Taps cleared. Play and tap again.')};
$('#keepBtn').onclick=()=⟩{openSheet('sh