g(2,4),16);
      const b = parseInt(h.substring(4,6),16);
      return `rgba(${r}, ${g}, ${b}, ${a})`;
    }

    function generatePalette(n, scheme = 'vibrant', base = '#6b76ff') {
      n = Math.max(1, n|0);
      const {h, s, l} = hexToHsl(base);
      const arr = [];
      for (let i=0;i<n;i++) {
        let hh = (h + i * (360 / n)) % 360;
        let ss = s, ll = l;
        if (scheme === 'pastel') { ss = clamp(s*0.45, 20, 60); ll = clamp(l*1.2, 55, 80); }
        else if (scheme === 'cool') { hh = (h