MAX_PUFFS = 16000;
    const puffs = [];

    function rand(a,b){ return a + Math.random()*(b-a); }
    function rint(a,b){ return Math.floor(rand(a,b+1)); }

    function addPuff(p){
      if (puffs.length > MAX_PUFFS) puffs.splice(0, Math.floor(MAX_PUFFS*0.15));
      puffs.push(p);
    }

    function spawnBrush(x,y) {
      const s = state.size * DPR;
      const baseAlpha = state.softness;
      if (state.shape === 'puff') {
        addPuff({x,y,r: s*rand(0.8,1.1), a: baseAlpha*rand(0.85,1), type:'circ