let ctx;
function context(){ctx ||= new (window.AudioContext||window.webkitAudioContext)();return ctx;}
function tone(freq,duration=.12,type='sine',delay=0,volume=.08){
  try{
    const c=context(); const o=c.createOscillator(); const g=c.createGain();
    o.type=type;o.frequency.value=freq;g.gain.value=volume;o.connect(g);g.connect(c.destination);
    const start=c.currentTime+delay;g.gain.setValueAtTime(volume,start);g.gain.exponentialRampToValueAtTime(.001,start+duration);
    o.start(start);o.stop(start+duration);
  }catch{}
}
export function playClick(){tone(420,.07,'sine',0,.035)}
export function playTryAgain(){tone(220,.12,'triangle',0,.045);tone(180,.12,'triangle',.1,.035)}
export function playSuccess(){tone(523,.12,'sine',0,.06);tone(659,.12,'sine',.1,.06);tone(784,.18,'sine',.2,.06)}
