const layer=document.querySelector('.launch-layer'),pieces=[...document.querySelectorAll('.piece')],wrap=document.querySelector('.brand-wrap'),status=document.querySelector('#status'); let slow=true,run=0;const active=[]; async function play(){const current=++run;active.splice(0).forEach(a=>a.cancel());layer.style.opacity='1';layer.style.pointerEvents='auto';const reduced=matchMedia('(prefers-reduced-motion:reduce)').matches;const rate=slow?3:1;status.textContent=slow?'正在慢速预览动作细节…':'正在播放品牌显现…';const offsets=['translate(0,-7px)','translate(-5px,5px)','translate(5px,3px)'];const animations=pieces.map((piece,i)=>{const a=piece.animate([{opacity:reduced?1:.15,transform:reduced?'none':offsets[i]},{opacity:1,transform:'translate(0,0)'}],{duration:(reduced?0:620)*rate,delay:(reduced?0:i*65)*rate,easing:'cubic-bezier(.2,.7,.2,1)',fill:'both'});active.push(a);return a.finished.catch(()=>{})});const name=document.querySelector('.brand-name');const a=name.animate([{opacity:reduced?1:0,transform:reduced?'none':'translateY(3px)'},{opacity:1,transform:'none'}],{duration:(reduced?0:260)*rate,delay:(reduced?0:400)*rate,easing:'ease-out',fill:'both'});active.push(a);await Promise.all([...animations,a.finished.catch(()=>{})]);if(current!==run)return;await new Promise(r=>setTimeout(r,(reduced?0:180)*rate));if(current!==run)return;status.textContent='页面已准备好,柔和进入';const exit=layer.animate([{opacity:1},{opacity:0}],{duration:(reduced?0:180)*rate,easing:'ease-out',fill:'forwards'});active.push(exit);await exit.finished.catch(()=>{});if(current===run){layer.style.pointerEvents='none';status.textContent='已进入会话 · 再次打开前台不重播'}} document.querySelector('#replay').addEventListener('click',play);document.querySelector('#slow').addEventListener('click',e=>{slow=!slow;e.currentTarget.setAttribute('aria-pressed',String(slow));play()});document.querySelector('#dark').addEventListener('change',e=>{document.body.classList.toggle('dark-phones',e.target.checked);play()}); window.previewLaunch=play;