{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ray-marched-resin-pebble-toast-notifications-that-drop-onto-a-sunlit-stone-ledge-rock-to-rest-and-get-flicked-off-the-edge","type":"registry:block","title":"Ray-Marched Resin Pebble Toast Notifications That Drop onto a Sunlit Stone Ledge, Rock to Rest and Get Flicked off the Edge","description":"Free React toasts cast as resin pebbles in a WebGL shader. Each drops on a sunlit ledge, rocks still, and is flicked off when dismissed.","dependencies":[],"files":[{"path":"components/we-inc/ray-marched-resin-pebble-toast-notifications-that-drop-onto-a-sunlit-stone-ledge-rock-to-rest-and-get-flicked-off-the-edge.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\ntype Kind = \"success\" | \"warning\" | \"error\";\ntype Toast = { id: number; kind: Kind; title: string; body: string };\n\n// What each kind is cast in, what it says and which mark is printed beside the word.\nconst KINDS: Record<Kind, { label: string; resin: [number, number, number]; css: string; ink: string }> = {\n  success: { label: \"Done\", resin: [0.42, 0.74, 0.5], css: \"#8fcf9f\", ink: \"#1d4a2c\" },\n  warning: { label: \"Check\", resin: [0.98, 0.6, 0.24], css: \"#f6b26b\", ink: \"#6a3510\" },\n  error: { label: \"Failed\", resin: [0.96, 0.32, 0.33], css: \"#f08a86\", ink: \"#6b1616\" },\n};\n// The demo feed. The first three are already on the ledge when the page opens.\nconst FEED: Omit<Toast, \"id\">[] = [\n  { kind: \"success\", title: \"Saved\", body: \"The spring menu draft for Larkspur Kitchen is safe.\" },\n  { kind: \"warning\", title: \"Card due\", body: \"The card ending 4417 runs out on 30 November.\" },\n  { kind: \"error\", title: \"Not sent\", body: \"The invoice to orders@tallowmere.example bounced back.\" },\n  { kind: \"success\", title: \"Published\", body: \"New opening hours are live on the site.\" },\n  { kind: \"warning\", title: \"Heavy\", body: \"hero.jpg is 9 MB and will crawl on a phone.\" },\n  { kind: \"error\", title: \"Offline\", body: \"Connection lost. Your edits wait here until it is back.\" },\n  { kind: \"success\", title: \"Invited\", body: \"Ines Barrow can now edit the gallery page.\" },\n];\nconst START = 4; // pebbles on the ledge at load\nconst MAX = 4; // more than this and the oldest is flicked off the end\nconst FONT = '\"Inter Tight\", \"Inter\", ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif';\nconst SERIF = '\"Iowan Old Style\", \"Palatino Linotype\", Palatino, \"Book Antiqua\", Georgia, serif';\n\n// Pebble half sizes (x across, y height, z depth), the ledge's front edge, the wall behind.\nconst RAD = [0.6, 0.25, 0.35];\nconst STEP = 1.33;\nconst LZ = 5.0;\nconst BACK = -2.7; // the far edge they are flicked over\nconst N = 5;\nconst ROWS = 8;\n\nconst VERT = `#version 300 es\nin vec2 aPos; void main(){ gl_Position = vec4(aPos, 0.0, 1.0); }`;\n\nconst TONE = `\nvec3 curve(vec3 x){ return clamp(x * (2.51 * x + 0.03) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0); }\nvec3 tone(vec3 x){ x *= 0.78; float m = max(max(x.r, x.g), max(x.b, 1e-4)); vec3 h = x * (curve(vec3(m)).r / m); return pow(mix(curve(x), h, 0.4), vec3(1.0 / 2.2)); }\n`;\n\nconst SCENE = `#version 300 es\nprecision highp float;\nout vec4 outC;\nuniform vec2 uRes; uniform vec4 uJit; uniform float uSeed; uniform vec3 uCam; uniform vec3 uTgt; uniform float uFoc; uniform vec2 uShift; uniform float uFocus; uniform float uDirect; uniform float uT;\nuniform vec3 uP[5]; uniform mat3 uR[5]; uniform vec3 uA[5]; uniform vec4 uK[5];\nuniform sampler2D uTex;\nconst vec3 RAD = vec3(${RAD.join(\", \")});\nconst float TOP = 0.165;\nuniform float LZ;\nconst float WZ = ${BACK.toFixed(2)};\nconst vec3 L = vec3(-0.42, 0.7, -0.58);\nconst vec3 SUNC = vec3(1.0, 0.9, 0.76) * 3.4;\n${TONE}\nfloat h21(vec2 p){ vec3 q = fract(vec3(p.xyx) * 0.1031); q += dot(q, q.yzx + 33.33); return fract((q.x + q.y) * q.z); }\nfloat n2(vec2 x){ vec2 i = floor(x); vec2 f = fract(x); f = f * f * (3.0 - 2.0 * f);\n  return mix(mix(h21(i), h21(i + vec2(1.0, 0.0)), f.x), mix(h21(i + vec2(0.0, 1.0)), h21(i + vec2(1.0, 1.0)), f.x), f.y); }\nfloat fbm(vec2 p){ float a = 0.5, s = 0.0; for (int i = 0; i < 4; i++) { s += a * n2(p); p = p * 2.03 + vec2(1.7, 9.2); a *= 0.5; } return s; }\nfloat smin(float a, float b, float k){ float h = max(k - abs(a - b), 0.0) / k; return min(a, b) - h * h * k * 0.25; }\nfloat smax(float a, float b, float k){ return -smin(-a, -b, k); }\nfloat sdEll(vec3 p, vec3 r){ float k0 = length(p / r); float k1 = length(p / (r * r)); return k0 * (k0 - 1.0) / k1; }\n// A cast lozenge: an ellipsoid with its top ground flat so a message can be printed on it.\nfloat sdPeb(vec3 q){ return smax(sdEll(q, RAD), q.y - TOP, 0.07); }\nfloat mapP(vec3 p, out int id){\n  float d = 1e5; id = -1;\n  for (int i = 0; i < 5; i++) {\n    if (uK[i].x < 0.5) continue;\n    vec3 o = p - uP[i]; float b = length(o) - 0.64;\n    float di = b > 0.45 ? b : sdPeb(o * uR[i]);\n    if (di < d) { d = di; id = i; }\n  }\n  return d;\n}\nfloat mapS(vec3 p){ int k; return mapP(p, k); }\nvec2 range(vec3 ro, vec3 rd, float R){\n  float t0 = 1e9, t1 = -1.0;\n  for (int i = 0; i < 5; i++) {\n    if (uK[i].x < 0.5) continue;\n    vec3 oc = ro - uP[i]; float b = dot(oc, rd); float h = b * b - dot(oc, oc) + R * R;\n    if (h > 0.0) { h = sqrt(h); t0 = min(t0, -b - h); t1 = max(t1, -b + h); }\n  }\n  return vec2(max(t0, 0.0), t1);\n}\nfloat marchP(vec3 ro, vec3 rd, out int id){\n  id = -1; vec2 r = range(ro, rd, 0.66); if (r.y < r.x) return -1.0;\n  float t = r.x;\n  for (int i = 0; i < 90; i++) { int k; float d = mapP(ro + rd * t, k); if (d < 0.0004 * (1.0 + t * 0.15)) { id = k; return t; } t += d; if (t > r.y) break; }\n  return -1.0;\n}\nvec3 nrmP(vec3 p){ vec2 e = vec2(0.0008, -0.0008); return normalize(e.xyy * mapS(p + e.xyy) + e.yyx * mapS(p + e.yyx) + e.yxy * mapS(p + e.yxy) + e.xxx * mapS(p + e.xxx)); }\nfloat shadowP(vec3 ro, vec3 rd, float k){\n  vec2 r = range(ro, rd, 0.95); if (r.y < 0.0 || r.y < r.x) return 1.0;\n  float res = 1.0; float t = max(r.x, 0.01);\n  for (int i = 0; i < 30; i++) { float h = mapS(ro + rd * t); res = min(res, k * h / t); t += clamp(h, 0.015, 0.2); if (res < 0.002 || t > r.y) break; }\n  return clamp(res, 0.0, 1.0);\n}\n// The pebble as a plain ellipsoid, solved exactly: how far a ray travels inside, and how close it passes to the middle.\nvec3 chord(int i, vec3 ro, vec3 rd, float grow){\n  vec3 r = RAD * grow;\n  vec3 o = ((ro - uP[i]) * uR[i]) / r; vec3 d = (rd * uR[i]) / r;\n  float a = dot(d, d); float b = dot(o, d); float c = dot(o, o) - 1.0; float h = b * b - a * c;\n  if (h < 0.0) return vec3(0.0, 9.0, 0.0);\n  h = sqrt(h); float t0 = (-b - h) / a; float t1 = (-b + h) / a;\n  if (t1 < 0.0) return vec3(0.0, 9.0, 0.0);\n  return vec3(t1 - max(t0, 0.0), dot(o, o) - b * b / a, t1);\n}\nvec3 sigOf(vec3 alb){ return (1.0 - alb) * 3.2 + 0.3; }\n// Sun that has come through resin: tinted, dimmed by scattering, and gathered to a bright core where the lens is thickest.\nvec3 through(vec3 g){\n  vec3 T = vec3(1.0); float any = 0.0;\n  for (int i = 0; i < 5; i++) {\n    if (uK[i].x < 0.5) continue;\n    vec3 c = chord(i, g, L, 1.1);\n    if (c.x > 0.0) {\n      // the lens only gathers light to a point close underneath; from higher up the colour spreads thin\n      float near = exp(-max(c.z - 0.9, 0.0) * 1.1);\n      any = 1.0; T *= mix(vec3(0.62), exp(-sigOf(uA[i]) * c.x * 1.1) * (0.3 + 1.5 * exp(-c.y * 10.0) + 0.35 * exp(-c.y * 3.0)) * mix(vec3(1.0), uA[i], 0.35), near);\n    }\n  }\n  return any > 0.5 ? T : vec3(0.3);\n}\nfloat leaves(vec3 p){\n  vec3 u = normalize(cross(L, vec3(0.0, 1.0, 0.0))); vec3 v = cross(u, L);\n  vec2 w = vec2(dot(p, u), dot(p, v)) * 0.9 + vec2(sin(uT * 0.45) * 0.12, cos(uT * 0.31) * 0.06);\n  float f = fbm(w * 1.4 + vec2(3.0, 1.0)) + 0.18 * fbm(w * 5.0);\n  float lit = smoothstep(0.5, 0.6, f);\n  float reach = clamp((-p.z - 0.5 + p.x * 0.2) * 0.6, 0.0, 1.0);\n  return mix(1.0, 0.16 + 0.84 * lit, reach * 0.9);\n}\nvec3 sky(vec3 n){ return mix(vec3(0.62, 0.54, 0.45), vec3(0.58, 0.68, 0.86), n.y * 0.5 + 0.5) * 0.52; }\nvec3 stoneAlb(vec2 w){\n  float strata = fbm(vec2(w.x * 0.3, w.y * 5.0));\n  float fine = n2(w * 70.0);\n  vec3 a = vec3(0.8, 0.69, 0.55) * (0.86 + 0.22 * strata) * (0.95 + 0.07 * fine);\n  float pit = fbm(vec2(w.x * 3.0, w.y * 26.0) + 7.0);\n  a *= 1.0 - 0.2 * smoothstep(0.66, 0.74, pit) - 0.06 * smoothstep(0.6, 0.66, pit);\n  a = mix(a, vec3(0.88, 0.8, 0.68), 0.25 * smoothstep(0.55, 0.75, fbm(w * 0.8 + 2.0)));\n  return a;\n}\nfloat aoP(vec3 p, vec3 n){\n  float o = 0.0; float s = 1.0;\n  for (int i = 1; i <= 4; i++) { float h = 0.03 + 0.09 * float(i); o += (h - min(mapS(p + n * h), h)) * s; s *= 0.7; }\n  return clamp(1.0 - 2.2 * o, 0.0, 1.0);\n}\nvec3 bounce(vec3 g, vec3 n){\n  vec3 b = vec3(0.0);\n  for (int i = 0; i < 5; i++) {\n    if (uK[i].x < 0.5) continue;\n    vec3 v = uP[i] - g; float d2 = dot(v, v);\n    b += uA[i] * max(dot(n, v) * inversesqrt(d2), 0.0) * 0.5 / (1.0 + d2 * 5.0);\n  }\n  return b * SUNC * 0.5;\n}\nvec3 shadeLedge(vec3 g, int face, vec3 rd){\n  vec3 n = face == 0 ? vec3(0.0, 1.0, 0.0) : vec3(0.0, 0.0, 1.0);\n  // a rounded nose along the front edge catches the sun as one bright line\n  if (face == 0) n = normalize(mix(n, vec3(0.0, 0.0, 1.0), smoothstep(LZ - 0.07, LZ, g.z) * 0.85));\n  else n = normalize(mix(n, vec3(0.0, 1.0, 0.0), smoothstep(-0.07, 0.0, g.y) * 0.85));\n  vec2 w = face == 0 ? g.xz : vec2(g.x, g.y * 0.6 + 3.0);\n  vec3 alb = stoneAlb(w);\n  float tooth = n2(g.xz * 180.0 + g.y * 40.0);\n  n = normalize(n + vec3(tooth - 0.5, 0.0, n2(g.zx * 180.0) - 0.5) * 0.04);\n  float sh = 1.0; vec3 tr = vec3(1.0); float ao = 1.0;\n  if (face == 0) { sh = shadowP(g + n * 0.002, L, 11.0); if (sh < 0.999) tr = through(g); ao = aoP(g, vec3(0.0, 1.0, 0.0)); }\n  float dap = leaves(g);\n  vec3 sun = SUNC * max(dot(n, L), 0.0) * dap * mix(tr, vec3(1.0), sh);\n  float wallAO = 1.0;\n  vec3 col = alb * (sun + sky(n) * ao * wallAO + bounce(g, n) * ao);\n  // honed stone: a soft sheen, no mirror\n  float f = 0.03 + 0.4 * pow(1.0 - clamp(dot(-rd, n), 0.0, 1.0), 5.0);\n  col += f * vec3(0.95, 0.92, 0.88) * 0.8 * ao;\n  if (face == 1) col *= mix(0.5, 1.0, smoothstep(-1.6, 0.0, g.y));\n  return col;\n}\nvec3 shadeWall(vec3 g){\n  vec3 n = vec3(0.0, 0.0, 1.0);\n  float m = fbm(g.xy * 1.3) * 0.6 + fbm(g.xy * 9.0) * 0.4;\n  vec3 alb = vec3(0.9, 0.82, 0.74) * (0.93 + 0.1 * m);\n  n = normalize(n + vec3(n2(g.xy * 40.0) - 0.5, n2(g.yx * 40.0) - 0.5, 0.0) * 0.06);\n  float ao = 0.55 + 0.45 * smoothstep(0.0, 0.5, g.y);\n  return alb * (SUNC * max(dot(n, L), 0.0) * leaves(g) + sky(n) * ao);\n}\n// Beyond the ledge: a sunny garden far out of focus, pale leaves and the bright gaps between them.\nvec3 garden(vec3 rd){\n  vec2 w = vec2(atan(rd.x, -rd.z) * 2.4, rd.y * 4.0);\n  vec3 c = mix(vec3(0.62, 0.72, 0.5), vec3(1.0, 0.96, 0.86), smoothstep(-0.55, 0.1, rd.y));\n  float f = fbm(w * 1.1 + 4.0);\n  c = mix(c, vec3(0.42, 0.55, 0.36), smoothstep(0.4, 0.7, f) * 0.6);\n  c = mix(c, vec3(0.98, 0.9, 0.74), smoothstep(0.55, 0.8, fbm(w * 0.7 + 9.0)) * 0.5);\n  float b = 0.0;\n  for (int i = 0; i < 12; i++) {\n    vec2 o = vec2(h21(vec2(float(i), 3.1)) * 5.0 - 2.5, -1.9 + h21(vec2(float(i), 7.7)) * 1.0);\n    float rr = 0.07 + 0.07 * h21(vec2(float(i), 1.3));\n    b += smoothstep(rr, rr - 0.02, length(w - o)) * (0.5 + 0.5 * h21(vec2(float(i), 5.5)));\n  }\n  return c * 1.2 + vec3(1.0, 0.96, 0.84) * b * 0.22;\n}\nvec3 envR(vec3 p, vec3 r){\n  // seen in a slightly soft coat, so the line where stone meets garden is a blur, not a seam\n  vec3 stone = vec3(0.8, 0.7, 0.57) * (SUNC * L.y * 0.85 + sky(vec3(0.0, 1.0, 0.0)));\n  vec3 g = garden(vec3(r.x, max(r.y, 0.02), r.z)) * 1.3;\n  vec3 c = mix(stone, g, smoothstep(-0.22, 0.25, r.y));\n  // and a broad bright sky panel high behind the ledge\n  c += vec3(1.0, 0.97, 0.9) * 2.2 * smoothstep(0.55, 0.85, dot(r, normalize(vec3(-0.2, 0.75, -0.6))));\n  return c;\n}\nvec3 shadePeb(vec3 p, vec3 n, vec3 rd, int id){\n  vec3 q = (p - uP[id]) * uR[id]; vec3 nl = n * uR[id];\n  vec3 alb = uA[id]; vec3 sig = sigOf(alb);\n  // tiny casting flaws: a soft orange peel and the odd pinhole bubble just under the skin\n  vec3 gn = n;\n  n = normalize(n + (vec3(n2(q.xz * 26.0), n2(q.zy * 26.0 + 3.0), n2(q.yx * 26.0 + 7.0)) - 0.5) * 0.035);\n  float ndv = clamp(dot(-rd, n), 0.0, 1.0);\n  float sh = mix(shadowP(p + gn * 0.02, L, 5.0), 1.0, 0.25) * leaves(p);\n  float ndl = (dot(n, L) + 0.45) / 1.45;\n  // light that came in on the sunny side and is still travelling when it reaches this point\n  float dsun = chord(id, p - n * 0.006, L, 1.0).z;\n  vec3 dv = refract(rd, n, 1.0 / 1.5);\n  float dview = chord(id, p - n * 0.006, dv, 1.0).z;\n  float ground = smoothstep(-0.02, 0.3, p.y - (q.y < 0.0 ? 0.0 : -1.0)) ;\n  float ao = mix(0.35, 1.0, smoothstep(0.0, 0.26, p.y)) * aoP(p, n);\n  if (p.z > LZ) ao = 1.0;\n  vec3 diff = alb * (SUNC * max(ndl, 0.0) * sh * 0.5 + sky(n) * ao + vec3(0.8, 0.69, 0.55) * SUNC * L.y * 0.22 * max(-n.y, 0.0) * ao);\n  vec3 sss = alb * SUNC * exp(-sig * (dsun + 0.15)) * 0.9 * mix(1.0, sh, 0.5) * (0.55 + 0.45 * (1.0 - ndv));\n  // cast resin is never perfectly even: a slow cloud of denser pigment drifts through it\n  float cloud = fbm(q.xz * 3.2 + q.y * 2.0 + float(id) * 3.7);\n  vec3 body = (diff + sss * (0.75 + 0.5 * cloud)) * mix(vec3(1.0), exp(-sig * dview * 0.5), 0.6) * (0.94 + 0.12 * cloud);\n  // light that wraps round the thin rim reads as a soft glow on the edge facing the sun\n  body += mix(alb, vec3(1.0), 0.3) * SUNC * 0.42 * pow(1.0 - ndv, 3.0) * max(dot(rd, L), 0.0) * smoothstep(-0.2, 0.4, dot(gn, L)) * sh;\n  // the message, pad printed on the flat top in the deepest shade of the resin\n  if (nl.y > 0.4 && abs(q.x) < 0.5 && abs(q.z) < 0.25) {\n    vec2 uv = vec2(q.x + 0.5, (uK[id].y + q.z * 2.0 + 0.5) / ${ROWS}.0);\n    float ink = smoothstep(0.18, 0.62, texture(uTex, uv).r) * smoothstep(0.4, 0.7, nl.y);\n    vec3 inkC = alb * alb * alb * 0.07 + 0.004;\n    body = mix(body, inkC * (SUNC * max(ndl, 0.0) * sh * 0.5 + sky(n) * 1.5), ink);\n  }\n  float f = 0.035 + 0.6 * pow(1.0 - ndv, 5.0);\n  vec3 r = reflect(rd, n);\n  vec3 refl = envR(p + n * 0.01, r) * mix(0.4, 1.0, ao);\n  float spec = pow(max(dot(r, L), 0.0), 600.0) * 30.0 + pow(max(dot(r, L), 0.0), 40.0) * 0.9;\n  return body * (1.0 - f) + f * refl + SUNC * spec * sh * 0.25;\n}\nvoid main(){\n  vec2 fc = gl_FragCoord.xy + uJit.xy;\n  vec2 uv = (fc - 0.5 * uRes) / uRes.y - uShift;\n  vec3 fw = normalize(uTgt - uCam); vec3 rt = normalize(cross(fw, vec3(0.0, 1.0, 0.0))); vec3 up = cross(rt, fw);\n  vec3 rd = normalize(fw * uFoc + rt * uv.x + up * uv.y);\n  vec3 ro = uCam;\n  vec3 fp = ro + rd * (uFocus / dot(rd, fw));\n  ro += rt * uJit.z + up * uJit.w; rd = normalize(fp - ro);\n  int id; float tp = marchP(ro, rd, id);\n  float ts = 1e9; int face = -1;\n  if (rd.y < 0.0) { float t = -ro.y / rd.y; vec3 g = ro + rd * t; if (g.z < LZ && g.z > WZ) { ts = t; face = 0; } }\n  if (rd.z < 0.0) {\n    float t = (LZ - ro.z) / rd.z; vec3 g = ro + rd * t; if (g.y < 0.0 && t < ts) { ts = t; face = 1; }\n    t = (WZ - ro.z) / rd.z; g = ro + rd * t; if (g.y < 0.0 && t < ts && rd.y < 0.0) { ts = t; face = 3; }\n  }\n  vec3 col;\n  if (tp > 0.0 && tp < ts && id >= 0) { vec3 p = ro + rd * tp; col = shadePeb(p, nrmP(p), rd, id); }\n  else if (face == 0 || face == 1) col = shadeLedge(ro + rd * ts, face, rd);\n  else if (face == 3) col = garden(rd) * 0.55;\n  else col = garden(rd);\n  col = min(col, vec3(30.0));\n  if (uDirect > 0.5) col = tone(col);\n  outC = vec4(col, 1.0);\n}\n`;\n\nconst POST = `#version 300 es\nprecision highp float;\nout vec4 outC;\nuniform sampler2D uAcc; uniform vec2 uRes; uniform float uGrain; uniform vec2 uCentre;\n${TONE}\nfloat h21(vec2 p){ vec3 q = fract(vec3(p.xyx) * 0.1031); q += dot(q, q.yzx + 33.33); return fract((q.x + q.y) * q.z); }\nvoid main(){\n  vec2 uv = gl_FragCoord.xy / uRes;\n  vec3 c = texture(uAcc, uv).rgb;\n  vec3 b = vec3(0.0);\n  for (int i = 0; i < 16; i++) {\n    float a = float(i) * 2.39996; float r = sqrt((float(i) + 0.5) / 16.0);\n    vec3 s = texture(uAcc, uv + vec2(cos(a), sin(a)) * r * 0.025 * vec2(uRes.y / uRes.x, 1.0)).rgb;\n    b += min(max(s - 2.2, 0.0), vec3(10.0)) * (1.0 - 0.6 * r);\n  }\n  c += b * 0.012;\n  vec2 q = (uv - uCentre) * vec2(uRes.x / uRes.y, 1.0);\n  c *= 1.0 - 0.16 * smoothstep(0.35, 1.25, length(q));\n  c = tone(c);\n  c += (h21(gl_FragCoord.xy + uGrain * 91.7) - 0.5) * 0.014;\n  outC = vec4(c, 1.0);\n}\n`;\n\n// Small marks drawn beside each word so the kind is never told by colour alone.\nfunction mark(g: CanvasRenderingContext2D, kind: Kind, cx: number, cy: number, s: number) {\n  g.save();\n  g.translate(cx, cy);\n  g.strokeStyle = \"#fff\"; g.fillStyle = \"#fff\"; g.lineWidth = s * 0.15; g.lineCap = \"round\"; g.lineJoin = \"round\";\n  if (kind === \"success\") {\n    g.beginPath(); g.arc(0, 0, s * 0.5, 0, Math.PI * 2); g.stroke();\n    g.beginPath(); g.moveTo(-s * 0.22, s * 0.01); g.lineTo(-s * 0.05, s * 0.18); g.lineTo(s * 0.25, -s * 0.16); g.stroke();\n  } else if (kind === \"warning\") {\n    g.beginPath(); g.moveTo(0, -s * 0.5); g.lineTo(s * 0.52, s * 0.42); g.lineTo(-s * 0.52, s * 0.42); g.closePath(); g.stroke();\n    g.beginPath(); g.moveTo(0, -s * 0.14); g.lineTo(0, s * 0.12); g.stroke();\n    g.beginPath(); g.arc(0, s * 0.27, s * 0.055, 0, Math.PI * 2); g.fill();\n  } else {\n    g.beginPath(); g.arc(0, 0, s * 0.5, 0, Math.PI * 2); g.stroke();\n    g.beginPath(); g.moveTo(-s * 0.18, -s * 0.18); g.lineTo(s * 0.18, s * 0.18); g.moveTo(s * 0.18, -s * 0.18); g.lineTo(-s * 0.18, s * 0.18); g.stroke();\n  }\n  g.restore();\n}\nfunction paintRow(g: CanvasRenderingContext2D, row: number, t: Toast) {\n  const W = 1024, H = 512, y0 = row * H;\n  g.fillStyle = \"#000\"; g.fillRect(0, y0, W, H);\n  g.textBaseline = \"middle\"; g.textAlign = \"left\"; g.fillStyle = \"#fff\";\n  let size = 178;\n  const set = () => { g.font = `800 ${size}px ${FONT}`; try { (g as unknown as { letterSpacing: string }).letterSpacing = `${-size * 0.035}px`; } catch { /* older canvas */ } };\n  set();\n  const icon = size * 0.72, gap = size * 0.2, room = 740;\n  while (g.measureText(t.title).width + icon + gap > room && size > 80) { size -= 6; set(); }\n  const ic = size * 0.72;\n  const total = g.measureText(t.title).width + ic + size * 0.2;\n  const x = W / 2 - total / 2, cy = y0 + H / 2 - size * 0.02;\n  mark(g, t.kind, x + ic / 2, cy, ic);\n  g.fillText(t.title, x + ic + size * 0.2, cy + size * 0.04);\n}\n\ntype Peb = { id: number; row: number; kind: Kind; x: number; y: number; z: number; vx: number; vy: number; vz: number; p: number; r: number; wp: number; wr: number; yaw: number; mode: \"drop\" | \"rest\" | \"off\"; wait: number; off: number };\ntype Api = { add: (t: Toast) => void; remove: (id: number) => void; touch: () => void };\n\n// No WebGL or reduced motion: the same ledge as a still, made from soft CSS shapes.\nfunction Still({ toasts }: { toasts: Toast[] }) {\n  return (\n    <div aria-hidden=\"true\" className=\"absolute inset-0 overflow-hidden\">\n      <div className=\"absolute inset-0\" style={{ background: \"linear-gradient(176deg, #dfe6d2 0%, #d3dcc4 24%, #efe4d4 24.4%, #f3e8d9 60%, #eadbc6 100%)\" }} />\n      <div className=\"absolute inset-x-0 top-[24%] h-[40%] opacity-70\" style={{ background: \"radial-gradient(28% 40% at 70% 20%, rgba(120,100,80,0.18), transparent 70%), radial-gradient(20% 30% at 88% 46%, rgba(120,100,80,0.14), transparent 70%)\" }} />\n      <div className=\"absolute left-1/2 top-[30%] flex -translate-x-1/2 items-end gap-3 sm:gap-6 lg:left-[67%] lg:top-[40%]\">\n        {toasts.slice(0, MAX).map((t, i) => (\n          <div key={t.id} className=\"relative h-[54px] w-[78px] sm:h-[86px] sm:w-[150px]\" style={{ transform: `translateY(${i * 10}px) rotate(${(i % 2 ? 1 : -1) * 4}deg)` }}>\n            <div className=\"absolute left-[8%] top-[62%] h-[70%] w-[96%] rounded-[50%] blur-[6px]\" style={{ background: `radial-gradient(60% 60% at 50% 40%, ${KINDS[t.kind].css}, rgba(120,90,60,0.28) 70%, transparent)`, transform: \"translate(8px, 10px)\" }} />\n            <div className=\"absolute inset-0 grid place-items-center rounded-[50%]\" style={{ background: `radial-gradient(80% 70% at 40% 28%, #ffffffcc 0%, ${KINDS[t.kind].css} 42%, ${KINDS[t.kind].css} 70%, ${KINDS[t.kind].ink}66 100%)`, boxShadow: \"inset 0 -8px 16px rgba(0,0,0,0.1), inset 0 3px 5px rgba(255,255,255,0.75)\" }}>\n              <span className=\"-mt-3 text-[11px] font-extrabold tracking-[-0.02em] sm:text-[17px]\" style={{ color: KINDS[t.kind].ink }}>{t.title}</span>\n            </div>\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n}\n\nlet nextId = 1;\nconst make = (k: number): Toast => ({ id: nextId++, ...FEED[k % FEED.length] });\nconst INITIAL: Toast[] = [make(0), make(1), make(2), make(3)];\n\nexport default function PebbleToastLedge() {\n  const stage = useRef<HTMLDivElement>(null);\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const [toasts, setToasts] = useState<Toast[]>(INITIAL);\n  const [shown, setShown] = useState<\"wait\" | \"gl\" | \"still\">(\"wait\");\n  const [said, setSaid] = useState({ polite: \"\", urgent: \"\" });\n  const list = useRef<Toast[]>(INITIAL);\n  const feed = useRef(START);\n  const api = useRef<Api | null>(null);\n  const panel = useRef<HTMLDivElement>(null);\n  const refocus = useRef(false);\n  // when the focused notice goes, hand focus to the next dismiss button (or the drop buttons) so the keyboard is never lost\n  useEffect(() => {\n    if (!refocus.current) return;\n    refocus.current = false;\n    panel.current?.querySelector<HTMLButtonElement>(\"button\")?.focus();\n  }, [toasts]);\n\n  const commit = (next: Toast[]) => { list.current = next; setToasts(next); };\n  const announce = (t: Toast) => setSaid(t.kind === \"error\" ? { polite: \"\", urgent: `${KINDS[t.kind].label}: ${t.title}. ${t.body}` } : { polite: `${KINDS[t.kind].label}: ${t.title}. ${t.body}`, urgent: \"\" });\n\n  const dismiss = (id: number, fromUser = true) => {\n    if (fromUser) api.current?.touch();\n    if (panel.current?.contains(document.activeElement)) refocus.current = true;\n    api.current?.remove(id);\n    commit(list.current.filter((t) => t.id !== id));\n  };\n  const push = (t: Toast, fromUser = true) => {\n    if (fromUser) api.current?.touch();\n    let next = [t, ...list.current];\n    if (next.length > MAX) { const old = next[next.length - 1]; api.current?.remove(old.id); next = next.slice(0, MAX); }\n    api.current?.add(t);\n    commit(next);\n    announce(t);\n  };\n  const pushKind = (kind: Kind) => {\n    for (let i = 0; i < FEED.length; i++) {\n      const k = feed.current++ % FEED.length;\n      if (FEED[k].kind === kind) { push(make(k)); return; }\n    }\n  };\n\n  useEffect(() => {\n    const box = stage.current, cv = canvas.current;\n    if (!box || !cv) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const gl = cv.getContext(\"webgl2\", { antialias: false, alpha: false, powerPreference: \"high-performance\" });\n    if (!gl) { setShown(\"still\"); return; }\n    const canAcc = !!gl.getExtension(\"EXT_color_buffer_float\") || !!gl.getExtension(\"EXT_color_buffer_half_float\");\n    const info = gl.getExtension(\"WEBGL_debug_renderer_info\");\n    const software = /swiftshader|llvmpipe|software|basic render/i.test(info ? String(gl.getParameter(info.UNMASKED_RENDERER_WEBGL)) : \"\");\n    const calm = reduce || software;\n\n    const compile = (type: number, src: string) => {\n      const sh = gl.createShader(type); if (!sh) return null;\n      gl.shaderSource(sh, src); gl.compileShader(sh);\n      return gl.getShaderParameter(sh, gl.COMPILE_STATUS) ? sh : null;\n    };\n    const link = (frag: string) => {\n      const v = compile(gl.VERTEX_SHADER, VERT), f = compile(gl.FRAGMENT_SHADER, frag), p = gl.createProgram();\n      if (!v || !f || !p) return null;\n      gl.attachShader(p, v); gl.attachShader(p, f); gl.bindAttribLocation(p, 0, \"aPos\"); gl.linkProgram(p);\n      return gl.getProgramParameter(p, gl.LINK_STATUS) ? p : null;\n    };\n    const scene = link(SCENE), post = canAcc ? link(POST) : null;\n    if (!scene || (canAcc && !post)) { setShown(\"still\"); return; }\n    const su = Object.fromEntries([\"uRes\", \"uJit\", \"uSeed\", \"uCam\", \"uTgt\", \"uFoc\", \"uShift\", \"uFocus\", \"uDirect\", \"uT\", \"uP\", \"uR\", \"uA\", \"uK\", \"uTex\", \"LZ\"].map((n) => [n, gl.getUniformLocation(scene, n)]));\n    const pu = post ? Object.fromEntries([\"uAcc\", \"uRes\", \"uGrain\", \"uCentre\"].map((n) => [n, gl.getUniformLocation(post, n)])) : {};\n\n    const quad = gl.createBuffer();\n    gl.bindBuffer(gl.ARRAY_BUFFER, quad);\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n    gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n\n    // The printing plates: one row of the atlas per pebble.\n    const atlas = document.createElement(\"canvas\"); atlas.width = 1024; atlas.height = 512 * ROWS;\n    const ag = atlas.getContext(\"2d\");\n    const tex = gl.createTexture();\n    const upload = () => {\n      gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, tex);\n      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, atlas);\n      gl.generateMipmap(gl.TEXTURE_2D);\n      const aniso = gl.getExtension(\"EXT_texture_filter_anisotropic\");\n      if (aniso) gl.texParameterf(gl.TEXTURE_2D, aniso.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(8, gl.getParameter(aniso.MAX_TEXTURE_MAX_ANISOTROPY_EXT)));\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n    };\n\n    const acc = canAcc ? gl.createTexture() : null;\n    const fbo = canAcc ? gl.createFramebuffer() : null;\n    let W = 0, H = 0, scale = 1, cssW = 1, cssH = 1;\n    const s = { hold: 0, count: 0, fresh: true, frame: 0, slow: 0, visible: true, raf: 0, last: 0, t0: 0, touched: false, demoAt: 0, demoStep: 0, first: true, time: 0, dip: 0, dipV: 0, px: 0, py: 0, sx: 0, sy: 0 };\n    const pebs: Peb[] = [];\n\n    const size = () => {\n      const r = box.getBoundingClientRect();\n      cssW = Math.max(1, r.width); cssH = Math.max(1, r.height);\n      const dpr = Math.min(software ? 1 : 1.5, window.devicePixelRatio || 1) * scale;\n      const k = Math.min(1, Math.sqrt(9e5 / (cssW * cssH * dpr * dpr)));\n      const w = Math.max(2, Math.round(cssW * dpr * k)), h = Math.max(2, Math.round(cssH * dpr * k));\n      if (w === W && h === H) return;\n      W = w; H = h; cv.width = W; cv.height = H;\n      if (acc && fbo) {\n        gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, acc);\n        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, W, H, 0, gl.RGBA, gl.HALF_FLOAT, null);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n        gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);\n        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, acc, 0);\n        gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n      }\n      s.count = 0; s.fresh = true;\n    };\n    const halton = (i: number, b: number) => { let f = 1, r = 0; while (i > 0) { f /= b; r += f * (i % b); i = Math.floor(i / b); } return r; };\n\n    // Where the lens is, worked out once a frame and shared by the shader and the click test.\n    const view = () => {\n      const wide = cssW >= 1024, aspect = cssW / cssH;\n      const fx = wide ? 0.645 : 0.5, fy = wide ? 0.47 : 0.74;\n      const half = wide ? Math.min(0.96 - fx, fx - 0.36) * aspect : 0.47 * aspect;\n      const az = wide ? 0.24 : 0.6, el = (wide ? 0.44 : 0.52) - s.sy * 0.02;\n      const foc = 2.6;\n      const need = wide ? 2.5 : 2.6 * Math.cos(az) + 0.6;\n      const dist = Math.min(30, Math.max(8, (need * foc) / half));\n      const tgt = [0, 0.1, 0.45];\n      const a = az + s.sx * 0.03;\n      const cam = [tgt[0] + dist * Math.sin(a) * Math.cos(el), tgt[1] + dist * Math.sin(el), tgt[2] + dist * Math.cos(a) * Math.cos(el)];\n      return { cam, tgt, foc, dist, shift: [(fx - 0.5) * aspect, (fy - 0.5) + s.dip], aspect, centre: [fx, fy] };\n    };\n\n    const rot = (yaw: number, p: number, r: number) => {\n      const cy = Math.cos(yaw), sy = Math.sin(yaw), cp = Math.cos(p), sp = Math.sin(p), cr = Math.cos(r), sr = Math.sin(r);\n      // Ry * Rx * Rz, written column by column\n      const rz = [[cr, -sr, 0], [sr, cr, 0], [0, 0, 1]];\n      const rx = [[1, 0, 0], [0, cp, -sp], [0, sp, cp]];\n      const ry = [[cy, 0, sy], [0, 1, 0], [-sy, 0, cy]];\n      const mul = (A: number[][], B: number[][]) => A.map((row) => [0, 1, 2].map((j) => row[0] * B[0][j] + row[1] * B[1][j] + row[2] * B[2][j]));\n      const m = mul(ry, mul(rx, rz));\n      return [m[0][0], m[1][0], m[2][0], m[0][1], m[1][1], m[2][1], m[0][2], m[1][2], m[2][2]];\n    };\n    const support = (p: number, r: number) => Math.sqrt((RAD[1] * Math.cos(r) * Math.cos(p)) ** 2 + (RAD[0] * Math.sin(r)) ** 2 + (RAD[2] * Math.sin(p)) ** 2);\n    const slotX = (k: number) => -STEP * 1.5 + k * STEP;\n    const restZ = 0.3;\n\n    const P = new Float32Array(N * 3), R = new Float32Array(N * 9), A = new Float32Array(N * 3), K = new Float32Array(N * 4);\n    const draw = (alpha: number, sample: number) => {\n      const v = view();\n      P.fill(0); K.fill(0);\n      pebs.slice(0, N).forEach((b, i) => {\n        if (b.wait > 0) return;\n        P.set([b.x, b.y, b.z], i * 3);\n        R.set(rot(b.yaw, b.p, b.r), i * 9);\n        A.set(KINDS[b.kind].resin, i * 3);\n        K.set([1, b.row, 0, 0], i * 4);\n      });\n      const jx = sample ? halton(sample, 2) - 0.5 : 0, jy = sample ? halton(sample, 3) - 0.5 : 0;\n      const la = halton(sample, 5) * Math.PI * 2, lr = sample ? Math.sqrt(halton(sample, 7)) * 0.03 * (v.dist / 10) : 0;\n      gl.useProgram(scene);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, canAcc ? fbo : null);\n      gl.viewport(0, 0, W, H);\n      if (canAcc && alpha < 1) { gl.enable(gl.BLEND); gl.blendColor(0, 0, 0, alpha); gl.blendFunc(gl.CONSTANT_ALPHA, gl.ONE_MINUS_CONSTANT_ALPHA); } else gl.disable(gl.BLEND);\n      gl.uniform2f(su.uRes, W, H);\n      gl.uniform4f(su.uJit, canAcc ? jx : 0, canAcc ? jy : 0, canAcc ? Math.cos(la) * lr : 0, canAcc ? Math.sin(la) * lr : 0);\n      gl.uniform1f(su.uSeed, sample ? (sample * 0.61803) % 1 : 0);\n      gl.uniform3f(su.uCam, v.cam[0], v.cam[1], v.cam[2]); gl.uniform3f(su.uTgt, v.tgt[0], v.tgt[1], v.tgt[2]);\n      gl.uniform1f(su.uFoc, v.foc); gl.uniform2f(su.uShift, v.shift[0], v.shift[1]);\n      gl.uniform1f(su.LZ, cssW >= 1024 ? LZ : LZ * 1.8); gl.uniform1f(su.uFocus, v.dist); gl.uniform1f(su.uDirect, canAcc ? 0 : 1); gl.uniform1f(su.uT, s.time);\n      gl.uniform3fv(su.uP, P); gl.uniformMatrix3fv(su.uR, false, R); gl.uniform3fv(su.uA, A); gl.uniform4fv(su.uK, K);\n      gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, tex); gl.uniform1i(su.uTex, 0);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n      if (canAcc && post) {\n        gl.bindFramebuffer(gl.FRAMEBUFFER, null); gl.disable(gl.BLEND); gl.useProgram(post);\n        gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, acc);\n        gl.uniform1i(pu.uAcc, 1); gl.uniform2f(pu.uRes, W, H);\n        gl.uniform1f(pu.uGrain, calm ? 1 : s.frame % 64);\n        gl.uniform2f(pu.uCentre, v.centre[0], v.centre[1]);\n        gl.drawArrays(gl.TRIANGLES, 0, 3);\n      }\n    };\n\n    // Slot order follows the list: newest on the left, everyone else moves along.\n    const order = () => {\n      const alive = pebs.filter((b) => b.mode !== \"off\");\n      const ids = list.current.map((t) => t.id);\n      alive.sort((a, b) => ids.indexOf(a.id) - ids.indexOf(b.id));\n      return alive;\n    };\n    const spawn = (t: Toast, settled: boolean, k: number) => {\n      if (ag) { paintRow(ag, t.id % ROWS, t); upload(); }\n      const rnd = Math.sin(t.id * 91.7) * 0.5 + 0.5;\n      const b: Peb = { id: t.id, row: t.id % ROWS, kind: t.kind, x: slotX(k), y: settled ? RAD[1] : 5.2, z: restZ + (rnd - 0.5) * 0.12, vx: 0, vy: 0, vz: 0, p: settled ? 0 : 0.1 * (rnd - 0.3), r: settled ? 0 : -0.16 + 0.08 * rnd, wp: 0, wr: 0, yaw: (rnd - 0.5) * 0.3, mode: settled ? \"rest\" : \"drop\", wait: settled ? 0 : 0.3, off: 0 };\n      pebs.push(b);\n    };\n    INITIAL.forEach((t, k) => spawn(t, true, k));\n\n    const add = (t: Toast) => {\n      spawn(t, reduce, 0);\n      s.count = 0; wake();\n    };\n    const remove = (id: number) => {\n      const b = pebs.find((x) => x.id === id);\n      if (!b) return;\n      if (reduce) pebs.splice(pebs.indexOf(b), 1);\n      else { b.mode = \"off\"; b.off = 0; b.vz = 1.3; b.wp += 1.2; s.hold = 0.22; }\n      s.count = 0; wake();\n    };\n    api.current = { add, remove, touch: () => { s.touched = true; } };\n\n    const physics = (dt: number) => {\n      const slots = order();\n      let moving = false;\n      const h = dt / 4;\n      for (let step = 0; step < 4; step++) {\n        // the stack waits a beat for a flicked pebble to clear before it shuffles along\n        if (s.hold > 0) s.hold -= h;\n        slots.forEach((b, k) => {\n          if (b.wait > 0) { b.wait -= h; moving = true; return; }\n          if (s.hold > 0) return;\n          const tx = slotX(k);\n          const ax = 74 * (tx - b.x) - 12 * b.vx;\n          b.vx += ax * h; b.x += b.vx * h;\n          // friction at the contact tips the pebble against the way it slides\n          b.wr += (-ax * 0.11) * h;\n        });\n        for (const b of pebs) {\n          if (b.wait > 0) continue;\n          if (b.mode === \"off\") {\n            b.off += h;\n            // a little wind-up toward the lens, then the flick away over the far edge\n            if (b.off > 0.13 && b.vz > 0) b.vz = -7.2;\n            b.z += b.vz * h;\n          }\n          const over = b.z > BACK + 0.04;\n          const ys = over ? support(b.p, b.r) : -99;\n          b.vy -= 17 * h; b.y += b.vy * h;\n          if (b.y <= ys) {\n            if (b.vy < -1.4) {\n              const hit = -b.vy;\n              b.vy = hit * 0.26;\n              b.wr += (b.r > 0 ? -1 : 1) * hit * 0.16 + (Math.random() - 0.5) * hit * 0.12;\n              b.wp += (Math.random() - 0.5) * hit * 0.2;\n              if (hit > 4) {\n                s.dipV += hit * 0.004;\n                for (const o of pebs) if (o !== b && o.mode === \"rest\") { o.wr += (Math.random() - 0.5) * 0.35; o.wp += (Math.random() - 0.5) * 0.25; }\n              }\n            } else { b.vy = 0; if (b.mode === \"drop\" && Math.abs(b.wr) + Math.abs(b.wp) < 0.4) b.mode = \"rest\"; }\n            b.y = ys;\n            // rocking on a curved base: gravity pulls it back level, the stone takes the energy out slowly\n            b.wr += (-58 * b.r - 2.6 * b.wr) * h;\n            b.wp += (-70 * b.p - 2.8 * b.wp) * h;\n            if (b.mode === \"off\") b.vz *= Math.exp(-h * 0.9);\n          } else if (b.mode === \"off\" && !over) {\n            b.wp -= 9 * h;\n          }\n          b.r += b.wr * h; b.p += b.wp * h;\n        }\n        s.dipV += (-900 * s.dip - 30 * s.dipV) * h; s.dip += s.dipV * h;\n      }\n      for (let i = pebs.length - 1; i >= 0; i--) if (pebs[i].y < -6) pebs.splice(i, 1);\n      for (const b of pebs) {\n        if (b.wait > 0 || b.mode !== \"rest\" || Math.abs(b.vx) > 0.004 || Math.abs(b.wr) > 0.01 || Math.abs(b.wp) > 0.01 || Math.abs(b.r) > 0.002 || Math.abs(b.p) > 0.002) moving = true;\n      }\n      if (Math.abs(s.dip) > 1e-4) moving = true;\n      return moving;\n    };\n\n    const frame = (now: number) => {\n      s.raf = 0;\n      if (!s.visible) return;\n      const dtRaw = s.last ? (now - s.last) / 1000 : 0.016;\n      const dt = Math.min(0.033, dtRaw);\n      s.last = now; s.frame++;\n      if (!s.t0) { s.t0 = now; s.demoAt = now + 3400; }\n      if (!calm && !s.touched && now > s.demoAt) {\n        if (list.current.length >= MAX || (s.demoStep % 2 === 1 && list.current.length > 2)) dismiss(list.current[list.current.length - 1].id, false);\n        else { push(make(feed.current++), false); }\n        s.demoStep++;\n        s.demoAt = now + 2900;\n      }\n      let moving = reduce ? false : physics(dt);\n      if (!calm) {\n        s.time += dt;\n        s.sx += (s.px - s.sx) * (1 - Math.exp(-dt * 3)); s.sy += (s.py - s.sy) * (1 - Math.exp(-dt * 3));\n      }\n      const fast = moving;\n      if (s.fresh || !canAcc) { draw(1, 0); s.fresh = false; s.count = 1; }\n      else if (fast) { draw(0.55, 1 + (s.frame % 64)); s.count = 4; }\n      else if (!calm) { draw(0.12, 1 + (s.frame % 64)); s.count = 8; moving = true; }\n      else if (s.count < 48) { s.count++; draw(1 / s.count, s.count); }\n      if (s.first) { s.first = false; setShown(\"gl\"); }\n      if (!calm && dtRaw > 0.026) s.slow++; else s.slow = Math.max(0, s.slow - 2);\n      if (s.slow > 40 && scale > 0.5) { scale *= 0.84; s.slow = 0; size(); }\n      if (moving || s.count < 48) s.raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { if (!s.raf && s.visible) { s.last = 0; s.raf = requestAnimationFrame(frame); } };\n\n    // Tap a pebble to flick it away.\n    const pick = (cx: number, cy: number) => {\n      const v = view();\n      const fw = norm(sub(v.tgt, v.cam)), rt = norm(cross(fw, [0, 1, 0])), up = cross(rt, fw);\n      let best = -1, bd = 1e9;\n      for (const b of pebs) {\n        if (b.mode === \"off\" || b.wait > 0) continue;\n        const d = sub([b.x, b.y, b.z], v.cam);\n        const z = dot(d, fw);\n        const u = (dot(d, rt) / z) * v.foc + v.shift[0], w = (dot(d, up) / z) * v.foc + v.shift[1];\n        const sx = cssW / 2 + u * cssH, sy = cssH / 2 - w * cssH;\n        const rpx = (RAD[0] * v.foc / z) * cssH;\n        const dd = Math.hypot(cx - sx, (cy - sy) * 1.6);\n        if (dd < rpx && dd < bd) { bd = dd; best = b.id; }\n      }\n      return best;\n    };\n    const sub = (a: number[], b: number[]) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];\n    const dot = (a: number[], b: number[]) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n    const cross = (a: number[], b: number[]) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];\n    const norm = (a: number[]) => { const l = Math.hypot(a[0], a[1], a[2]); return [a[0] / l, a[1] / l, a[2] / l]; };\n\n    size();\n    const ro = new ResizeObserver(() => { size(); wake(); });\n    ro.observe(box);\n    const io = new IntersectionObserver(([e]) => { s.visible = e.isIntersecting && !document.hidden; if (s.visible) wake(); }, { threshold: 0.05 });\n    io.observe(box);\n    const vis = () => { s.visible = !document.hidden; if (s.visible) wake(); };\n    document.addEventListener(\"visibilitychange\", vis);\n    const click = (e: MouseEvent) => {\n      const r = box.getBoundingClientRect();\n      const id = pick(e.clientX - r.left, e.clientY - r.top);\n      if (id > 0) dismiss(id);\n    };\n    const move = (e: PointerEvent) => {\n      const r = box.getBoundingClientRect();\n      s.px = ((e.clientX - r.left) / r.width) * 2 - 1; s.py = ((e.clientY - r.top) / r.height) * 2 - 1;\n      cv.style.cursor = pick(e.clientX - r.left, e.clientY - r.top) > 0 ? \"pointer\" : \"default\";\n      if (!calm) wake();\n    };\n    const leave = () => { s.px = 0; s.py = 0; };\n    cv.addEventListener(\"click\", click);\n    box.addEventListener(\"pointermove\", move);\n    box.addEventListener(\"pointerleave\", leave);\n    const lost = (e: Event) => { e.preventDefault(); setShown(\"still\"); };\n    cv.addEventListener(\"webglcontextlost\", lost);\n    wake();\n    return () => {\n      cancelAnimationFrame(s.raf); ro.disconnect(); io.disconnect();\n      document.removeEventListener(\"visibilitychange\", vis);\n      cv.removeEventListener(\"click\", click); cv.removeEventListener(\"webglcontextlost\", lost);\n      box.removeEventListener(\"pointermove\", move); box.removeEventListener(\"pointerleave\", leave);\n      api.current = null;\n    };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, []);\n\n  const lead = toasts[0];\n  const rest = toasts.slice(1);\n  const Icon = ({ kind, className }: { kind: Kind; className?: string }) => (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" className={className} fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      {kind === \"success\" && (<><circle cx=\"12\" cy=\"12\" r=\"9\" /><path d=\"M8 12.2l2.7 2.7L16.4 9\" /></>)}\n      {kind === \"warning\" && (<><path d=\"M12 3.5l9 16H3z\" /><path d=\"M12 10v4\" /><circle cx=\"12\" cy=\"17\" r=\"0.6\" fill=\"currentColor\" /></>)}\n      {kind === \"error\" && (<><circle cx=\"12\" cy=\"12\" r=\"9\" /><path d=\"M9 9l6 6M15 9l-6 6\" /></>)}\n    </svg>\n  );\n\n  return (\n    <section\n      className=\"relative isolate overflow-hidden bg-[#eadccb] text-[#2b1d12]\"\n      style={{ fontFamily: FONT }}\n      onKeyDown={(e) => { if (e.key === \"Escape\" && list.current[0]) dismiss(list.current[0].id); }}\n    >\n      <div ref={stage} className=\"relative h-[900px] w-full sm:h-[860px] lg:h-[760px]\">\n        <canvas ref={canvas} aria-hidden=\"true\" className={`absolute inset-0 h-full w-full transition-opacity duration-700 motion-reduce:transition-none ${shown === \"gl\" ? \"opacity-100\" : \"opacity-0\"}`} />\n        {shown === \"still\" && <Still toasts={toasts} />}\n\n        <div className=\"pointer-events-none absolute inset-0 mx-auto flex max-w-[1600px] flex-col justify-end px-5 pb-6 sm:px-10 lg:justify-between lg:px-16 lg:pb-12 lg:pt-12\">\n          <p className=\"hidden text-[11px] font-semibold uppercase tracking-[0.32em] text-[#2b1d12] lg:block\">Quarry &amp; Fennel <span className=\"mx-2 text-[#2b1d12]/40\">/</span> cast resin notices</p>\n          <div ref={panel} className=\"pointer-events-auto w-full max-w-[25rem] rounded-[28px] bg-[#f7efe5]/80 p-5 backdrop-blur-md sm:p-6 lg:bg-transparent lg:p-0 lg:backdrop-blur-none\">\n            {lead ? (\n              <div key={lead.id}>\n                <p className=\"flex items-center gap-2 text-[12px] font-semibold uppercase tracking-[0.24em]\" style={{ color: KINDS[lead.kind].ink }}>\n                  <Icon kind={lead.kind} className=\"h-4 w-4\" /> {KINDS[lead.kind].label} <span className=\"text-[#2b1d12]/50\">· newest</span>\n                </p>\n                <h2 className=\"pebble-toast-word mt-2 text-[64px] leading-[0.86] tracking-[-0.04em] sm:text-[84px] lg:text-[108px]\" style={{ fontFamily: SERIF }}>{lead.title}</h2>\n                <div className=\"mt-3 flex items-start gap-3 lg:mt-5\">\n                  <p className=\"flex-1 text-balance text-[15px] font-medium leading-[1.45] tracking-[-0.01em] lg:text-[17px]\">{lead.body}</p>\n                  <button type=\"button\" onClick={() => dismiss(lead.id)} aria-label={`Dismiss: ${lead.title}`} className=\"grid h-10 w-10 shrink-0 place-items-center rounded-full bg-[#2b1d12] text-[#f7efe5] outline-none transition-transform hover:scale-105 focus-visible:ring-2 focus-visible:ring-[#2b1d12] focus-visible:ring-offset-2 focus-visible:ring-offset-[#eadccb] motion-reduce:transition-none\">\n                    <svg aria-hidden=\"true\" viewBox=\"0 0 20 20\" className=\"h-4 w-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\"><path d=\"M5 5l10 10M15 5L5 15\" /></svg>\n                  </button>\n                </div>\n              </div>\n            ) : (\n              <div>\n                <h2 className=\"text-[64px] leading-[0.86] tracking-[-0.04em] lg:text-[108px]\" style={{ fontFamily: SERIF }}>All clear</h2>\n                <p className=\"mt-3 text-[15px] font-medium lg:text-[17px]\">Nothing left on the ledge. Drop a new notice below.</p>\n              </div>\n            )}\n            {rest.length > 0 && (\n              <ul className=\"mt-5 divide-y divide-[#2b1d12]/10 border-y border-[#2b1d12]/10\">\n                {rest.map((t) => (\n                  <li key={t.id} className=\"flex items-center gap-3 py-1.5\">\n                    <span className=\"grid h-7 w-7 shrink-0 place-items-center rounded-full\" style={{ background: KINDS[t.kind].css, color: KINDS[t.kind].ink }}><Icon kind={t.kind} className=\"h-4 w-4\" /></span>\n                    <span className=\"min-w-0 flex-1 truncate text-[14px]\"><span className=\"font-semibold\">{t.title}</span><span className=\"text-[#2b1d12]/70\"> · {KINDS[t.kind].label}</span></span>\n                    <button type=\"button\" onClick={() => dismiss(t.id)} aria-label={`Dismiss: ${t.title}`} className=\"grid h-10 w-10 shrink-0 place-items-center rounded-full text-[#2b1d12] outline-none hover:bg-[#2b1d12]/10 focus-visible:ring-2 focus-visible:ring-[#2b1d12]\">\n                      <svg aria-hidden=\"true\" viewBox=\"0 0 20 20\" className=\"h-4 w-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\"><path d=\"M5 5l10 10M15 5L5 15\" /></svg>\n                    </button>\n                  </li>\n                ))}\n              </ul>\n            )}\n            <div className=\"mt-5 flex flex-wrap items-center gap-2\">\n              <span className=\"mr-1 text-[12px] font-semibold uppercase tracking-[0.2em] text-[#2b1d12]/80\">Drop</span>\n              {(Object.keys(KINDS) as Kind[]).map((k) => (\n                <button key={k} type=\"button\" onClick={() => pushKind(k)} className=\"flex h-10 items-center gap-2 rounded-full bg-white/70 pl-2 pr-4 text-[14px] font-semibold text-[#2b1d12] outline-none ring-1 ring-[#2b1d12]/10 transition-colors hover:bg-white focus-visible:ring-2 focus-visible:ring-[#2b1d12]\">\n                  <span className=\"grid h-6 w-6 place-items-center rounded-full\" style={{ background: KINDS[k].css, color: KINDS[k].ink }}><Icon kind={k} className=\"h-3.5 w-3.5\" /></span>\n                  {KINDS[k].label}\n                </button>\n              ))}\n            </div>\n          </div>\n        </div>\n        {shown === \"gl\" && <p className=\"pointer-events-none absolute bottom-12 right-16 hidden text-[11px] font-semibold uppercase tracking-[0.3em] text-[#2b1d12]/80 lg:block\">Tap a pebble to flick it off</p>}\n        <div role=\"status\" aria-live=\"polite\" className=\"sr-only\">{said.polite}</div>\n        <div role=\"alert\" aria-live=\"assertive\" className=\"sr-only\">{said.urgent}</div>\n      </div>\n      <style>{`\n        @keyframes pebble-toast-rise { from { opacity: 0; transform: translateY(0.14em); filter: blur(8px); } to { opacity: 1; transform: none; filter: blur(0); } }\n        .pebble-toast-word { animation: pebble-toast-rise 480ms cubic-bezier(0.2, 0.9, 0.2, 1) both; }\n        @media (prefers-reduced-motion: reduce) { .pebble-toast-word { animation: none; } }\n      `}</style>\n    </section>\n  );\n}\n"}]}
