// MilkShader — frosted-glass mercury, cream base + caramel blobs.
// Locked v3 / C3 Milk. Pure ambient wallpaper, light-mode.
// Reacts to mouse + click + press.

const MILK_FRAG = `
  float metaball(vec2 p, vec2 c, float r) {
    return r*r / dot(p-c, p-c);
  }
  void main() {
    vec2 res = u_resolution;
    vec2 uv = (gl_FragCoord.xy - 0.5*res) / res.y;
    vec2 m  = (u_mouseSmooth - 0.5*res) / res.y;
    vec2 cp = (u_click - 0.5*res) / res.y;

    float t = u_time * 0.2;
    float field = 0.0;
    for (int i = 0; i < 4; i++) {
      float fi = float(i);
      float a = t * (0.3 + fi*0.05) + fi * 2.3;
      float r = 0.5 + 0.15*sin(t*0.45 + fi*1.5);
      vec2 c = vec2(cos(a)*r*1.1, sin(a*1.0)*r*0.7);
      c = mix(c, m, 0.20 / (length(c - m) + 0.7));
      field += metaball(uv, c, 0.30);
    }
    float soft = smoothstep(0.6, 1.8, field);

    vec3 bg = vec3(0.94, 0.90, 0.85);
    bg -= vec3(0.05, 0.06, 0.08) * exp(-length(uv-vec2(0.0,0.2))*1.1) * 0.4;
    vec3 body = mix(vec3(0.78, 0.55, 0.32), vec3(0.92, 0.72, 0.50), smoothstep(-0.5, 0.5, uv.y));

    vec3 col = mix(bg, body, soft * 0.7);
    float bloomR = exp(-length(uv-cp)*3.0) * exp(-u_clickAge*1.5) * 0.25;
    col += bloomR * vec3(0.6, 0.35, 0.15);
    col -= u_pressed * 0.05 * vec3(0.3, 0.4, 0.5) * soft;
    col *= 1.0 - 0.18 * smoothstep(0.7, 1.4, length(uv*vec2(1.0, 1.2)));
    float grain = fract(sin(dot(gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453);
    col += (grain - 0.5) * 0.018;
    gl_FragColor = vec4(col, 1.0);
  }
`;

window.MILK_FRAG = MILK_FRAG;
