{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"moulded-pulp-bento-tray-feature-section-in-webgl-where-a-glass-loupe-a-brass-key-a-spool-and-a-folded-card-lift-into-focus","type":"registry:block","title":"Moulded Pulp Bento Tray Feature Section in WebGL Where a Glass Loupe, a Brass Key, a Spool and a Folded Card Lift into Focus","description":"Free React bento feature section in raw WebGL: a pressed pulp tray in daylight where each feature is an object that rises out of its pocket into focus.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/moulded-pulp-bento-tray-feature-section-in-webgl-where-a-glass-loupe-a-brass-key-a-spool-and-a-folded-card-lift-into-focus.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\n\n/** The product, and one feature per compartment of the tray (in the order the compartments are cut). */\nconst product = { name: \"Oddment\", line: \"A shared notebook for small studios\" };\nconst features = [\n  { name: \"Find it at a glance\", line: \"Search reads inside every file, scan and screenshot, so the thing you half remember comes up first.\", object: \"Glass loupe\" },\n  { name: \"Private until you say\", line: \"Every page starts locked. Hand a key to one person, a team or the open web, and take it back whenever you like.\", object: \"Brass key\" },\n  { name: \"Threads that hold\", line: \"Replies stay tied to the sentence they are about, even after the page around them has been rewritten twice.\", object: \"Cotton spool\" },\n  { name: \"Fold a note into a page\", line: \"Any note becomes a tidy public page with its own address, and it changes when the note does.\", object: \"Folded card\" },\n];\n\nconst LIFT_SPRING = 150; // pull on an object toward its lifted or resting height\nconst LIFT_DAMPING = 12.5; // lower lets it overshoot further before it settles\nconst DEMO = true; // walks through the compartments by itself until somebody touches the section\nconst SERIF = '\"Iowan Old Style\", \"Palatino Linotype\", Palatino, \"Book Antiqua\", Georgia, serif';\nconst GROTESK = '\"Inter Tight\", \"Inter\", ui-sans-serif, system-ui, sans-serif';\n\n// compartments of the tray in metres: centre x, centre z, half width, half depth\nconst CELLS = [\n  [-0.83, 0.0, 0.75, 0.98],\n  [0.81, -0.52, 0.77, 0.46],\n  [0.395, 0.52, 0.355, 0.46],\n  [1.225, 0.52, 0.355, 0.46],\n];\n// where each object rests (its middle), so the lens can focus on it\nconst RESTS = [\n  [-0.83, -0.03, -0.18],\n  [0.81, -0.09, -0.52],\n  [0.395, 0.07, 0.52],\n  [1.225, 0.02, 0.52],\n];\nconst v3 = (a: number[]) => `vec3(${a.map((x) => x.toFixed(4)).join(\", \")})`;\nconst v4 = (a: number[]) => `vec4(${a.map((x) => x.toFixed(4)).join(\", \")})`;\nconst norm = (a: number[]) => {\n  const l = Math.hypot(a[0], a[1], a[2]);\n  return a.map((x) => x / l);\n};\n// daylight from a tall window behind and to the left of the tray\nconst SUN = norm([-0.52, 0.74, -0.42]);\nconst FILL = norm([0.75, 0.42, 0.52]);\n\nconst GLSL = `#version 300 es\nprecision highp float;\nuniform vec3 uCam, uRt, uUp, uFw;\nuniform float uTan, uAspect, uFocus, uAperture, uTime;\nuniform vec2 uShift, uRes;\nuniform vec4 uLift;\nin vec2 vUv;\nout vec4 o;\n\nconst vec3 L = ${v3(SUN)};\nconst vec3 FD = ${v3(FILL)};\nconst vec3 KEY = vec3(1.0, 0.93, 0.83) * 3.3;\nconst vec3 SKY = vec3(0.88, 0.87, 0.87) * 1.12;\nconst float FL = -0.12;\nconst float TB = -0.18;\nconst vec4 CA = ${v4(CELLS[0])};\nconst vec4 CB = ${v4(CELLS[1])};\nconst vec4 CC = ${v4(CELLS[2])};\nconst vec4 CD = ${v4(CELLS[3])};\n\nfloat ign(vec2 p) { return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715)))); }\nfloat hash(vec2 p) { p = fract(p * vec2(123.34, 456.21)); p += dot(p, p + 45.32); return fract(p.x * p.y); }\nfloat vnoise(vec2 p) {\n  vec2 i = floor(p), f = fract(p); f = f * f * (3.0 - 2.0 * f);\n  return mix(mix(hash(i), hash(i + vec2(1, 0)), f.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), f.x), f.y);\n}\nfloat fbm(vec2 p) { return 0.5 * vnoise(p) + 0.25 * vnoise(p * 2.1 + 7.3) + 0.125 * vnoise(p * 4.3 + 1.7) + 0.0625 * vnoise(p * 8.9); }\nmat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, s, -s, c); }\n\nfloat sdRB(vec3 p, vec3 b, float r) { vec3 q = abs(p) - b + r; return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0) - r; }\nfloat sdR2(vec2 p, vec2 b) { vec2 q = abs(p) - b; return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0); }\nfloat smax(float a, float b, float k) { float h = clamp(0.5 + 0.5 * (a - b) / k, 0.0, 1.0); return mix(b, a, h) + k * h * (1.0 - h); }\nfloat smin(float a, float b, float k) { float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0); return mix(b, a, h) - k * h * (1.0 - h); }\n// a solid cylinder: radial distance and height measured from its middle\nfloat sdCyl(float rr, float y, float r, float h) { vec2 w = vec2(rr - r, abs(y) - h); return min(max(w.x, w.y), 0.0) + length(max(w, 0.0)); }\n\n// ---------- the tray: one moulded slab with four drafted pockets ----------\nfloat pocket(vec3 p, vec4 c) {\n  vec3 q = p - vec3(c.x, 0.0, c.y);\n  float dy = clamp(-q.y, 0.0, 0.12);\n  vec2 h = c.zw - dy * 0.22;\n  return sdRB(q - vec3(0.0, 0.09, 0.0), vec3(h.x, 0.21, h.y), 0.1);\n}\nfloat sdTray(vec3 p) {\n  float d = sdRB(p - vec3(0.0, -0.09, 0.0), vec3(1.72, 0.09, 1.12), 0.07);\n  float k = min(min(pocket(p, CA), pocket(p, CB)), min(pocket(p, CC), pocket(p, CD)));\n  return smax(d, -k, 0.035);\n}\n\n// ---------- the objects, each in its own frame so it can lift and turn ----------\nvec3 lensP(vec3 p) {\n  float l = uLift.x;\n  vec3 q = p - vec3(CA.x - 0.02, FL + 0.072 + l * 0.25, CA.y - 0.2);\n  q.yz = rot(-l * 0.42) * q.yz;\n  q.xz = rot(-1.2) * q.xz;\n  q.xy = rot(-l * 0.08) * q.xy;\n  return q;\n}\nvec3 lensD(vec3 d) {\n  float l = uLift.x;\n  d.yz = rot(-l * 0.42) * d.yz;\n  d.xz = rot(-1.2) * d.xz;\n  d.xy = rot(-l * 0.08) * d.xy;\n  return d;\n}\nvec3 lensDinv(vec3 d) {\n  float l = uLift.x;\n  d.xy = rot(l * 0.08) * d.xy;\n  d.xz = rot(1.2) * d.xz;\n  d.yz = rot(l * 0.42) * d.yz;\n  return d;\n}\n// leaving the glass from inside: the nearest of its two spherical faces and its ground edge, found exactly\nfloat exitGlass(vec3 o, vec3 d, out vec3 nl) {\n  const float R = 1.5, th = 0.058;\n  float best = 1e9;\n  for (int k = 0; k < 2; k++) {\n    vec3 c = vec3(0.0, k == 0 ? -(R - th) : (R - th), 0.0);\n    vec3 oc = o - c;\n    float b = dot(oc, d), cc = dot(oc, oc) - R * R;\n    float t = -b + sqrt(max(b * b - cc, 0.0));\n    if (t < best) { best = t; nl = normalize(oc + d * t); }\n  }\n  float a = dot(d.xz, d.xz), b = dot(o.xz, d.xz), cc = dot(o.xz, o.xz) - 0.16;\n  if (a > 1e-6) {\n    float t = (-b + sqrt(max(b * b - a * cc, 0.0))) / a;\n    if (t < best) { best = t; vec3 e = o + d * t; nl = normalize(vec3(e.x, 0.0, e.z)); }\n  }\n  return best;\n}\nfloat sdGlass(vec3 q) {\n  const float R = 1.5, th = 0.058;\n  float a = length(q + vec3(0.0, R - th, 0.0)) - R;\n  float b = length(q - vec3(0.0, R - th, 0.0)) - R;\n  return max(max(a, b), length(q.xz) - 0.4);\n}\nfloat sdRim(vec3 q) { return sdR2(vec2(length(q.xz) - 0.425, q.y), vec2(0.026, 0.036)) - 0.012; }\nfloat sdHandle(vec3 q) {\n  // a brass ferrule and a turned walnut handle running out from the rim\n  float x = q.x - 0.44;\n  float rr = length(q.yz);\n  float fer = sdCyl(rr, x - 0.05, 0.026, 0.05) - 0.008;\n  float r = 0.026 + 0.012 * sin(clamp((x - 0.1) / 0.44, 0.0, 1.0) * 2.8);\n  float wood = sdCyl(rr, x - 0.33, r, 0.21) - 0.012;\n  return min(fer, wood) * 0.85;\n}\nfloat handleId(vec3 q) { return q.x - 0.46 < 0.1 ? 3.0 : 8.0; }\n\nvec3 keyP(vec3 p) {\n  float l = uLift.y;\n  vec3 q = p - vec3(CB.x + 0.03, FL + 0.03 + l * 0.38, CB.y - 0.02);\n  q.xz = rot(0.1 - l * 0.22) * q.xz;\n  q.yz = rot(-l * 0.62) * q.yz;\n  q.xy = rot(l * 0.16) * q.xy;\n  return q;\n}\nfloat sdKey(vec3 q) {\n  vec3 b = q - vec3(-0.43, 0.0, 0.0);\n  float d = sdR2(vec2(length(b.xz) - 0.15, b.y), vec2(0.026, 0.011)) - 0.012;\n  // a trefoil of small lobes inside the bow\n  float a = atan(b.z, b.x);\n  float lobe = sdR2(vec2(length(b.xz) - 0.075 - 0.02 * cos(a * 3.0), b.y), vec2(0.008, 0.008)) - 0.008;\n  d = min(d, lobe);\n  d = min(d, length(q - vec3(clamp(q.x, -0.3, 0.5), 0.0, 0.0)) - 0.027);\n  float rr = length(q.yz);\n  d = min(d, sdCyl(rr, q.x + 0.27, 0.03, 0.016) - 0.009);\n  d = min(d, sdCyl(rr, q.x + 0.2, 0.022, 0.01) - 0.008);\n  float bit = sdRB(q - vec3(0.4, 0.0, 0.07), vec3(0.095, 0.012, 0.07), 0.006);\n  float n1 = sdRB(q - vec3(0.355, 0.0, 0.125), vec3(0.017, 0.05, 0.04), 0.003);\n  float n2 = sdRB(q - vec3(0.445, 0.0, 0.145), vec3(0.015, 0.05, 0.04), 0.003);\n  d = min(d, max(bit, -min(n1, n2)));\n  d = min(d, length(q - vec3(0.5, 0.0, 0.0)) - 0.031);\n  return d;\n}\n\nvec3 spoolP(vec3 p) {\n  float l = uLift.z;\n  vec3 q = p - vec3(CC.x, FL + l * 0.3, CC.y);\n  q.xy = rot(l * 0.16) * q.xy;\n  q.yz = rot(-l * 0.1) * q.yz;\n  q.xz = rot(l * 2.4 + 0.6) * q.xz;\n  return q;\n}\nfloat sdFlange(vec3 q, float y) { return sdCyl(length(q.xz), q.y - y, 0.2, 0.016) - 0.012; }\nfloat sdSpoolWood(vec3 q) {\n  float d = min(sdFlange(q, 0.028), sdFlange(q, 0.352));\n  d = max(d, -(length(q.xz) - 0.042));\n  // a nick in the top rim, where the end of the thread is caught\n  d = max(d, -sdRB(q - vec3(0.215, 0.352, 0.0), vec3(0.03, 0.05, 0.008), 0.004));\n  return d;\n}\nfloat sdThread(vec3 q) {\n  float r = 0.168 + 0.004 * sin(q.y * 34.0);\n  return sdCyl(length(q.xz), q.y - 0.19, r, 0.14) - 0.004;\n}\n\nvec3 cardP(vec3 p) {\n  float l = uLift.w;\n  vec3 q = p - vec3(CD.x, FL + l * 0.3, CD.y - 0.02);\n  q.xz = rot(-0.32 + l * 0.3) * q.xz;\n  q.yz = rot(l * 0.22) * q.yz;\n  return q;\n}\nfloat cardTh() { return 0.62 + uLift.w * 0.12; }\nfloat sdCard(vec3 q) {\n  float th = cardTh(), len = 0.36;\n  vec3 v = q - vec3(0.0, len * cos(th), 0.0);\n  v.z = abs(v.z);\n  float along = dot(v.yz, vec2(-cos(th), sin(th)));\n  float across = dot(v.yz, vec2(sin(th), cos(th)));\n  return sdRB(vec3(v.x, along - len * 0.5, across), vec3(0.25, len * 0.5, 0.004), 0.003);\n}\n\n// a printed slip lying on the floor of the big pocket, under the loupe\nvec3 slipP(vec3 p) { vec3 q = p - vec3(CA.x + 0.02, FL + 0.004, CA.y - 0.12); q.xz = rot(0.12) * q.xz; return q; }\nfloat sdSlip(vec3 q) { return sdRB(q, vec3(0.46, 0.003, 0.62), 0.002); }\n\n// id: 1 tray, 2 glass, 3 brass, 5 beech, 6 thread, 7 card, 8 walnut, 9 slip\nvec2 map(vec3 p, bool glass) {\n  vec2 r = vec2(sdTray(p), 1.0);\n  float sl = sdSlip(slipP(p)); if (sl < r.x) r = vec2(sl, 9.0);\n  vec3 q = lensP(p);\n  if (length(q - vec3(0.35, 0.0, 0.0)) - 0.85 < r.x) {\n    if (glass) { float g = sdGlass(q); if (g < r.x) r = vec2(g, 2.0); }\n    float m = sdRim(q); if (m < r.x) r = vec2(m, 3.0);\n    float h = sdHandle(q); if (h < r.x) r = vec2(h, handleId(q));\n  }\n  q = keyP(p);\n  if (length(q) - 0.68 < r.x) { float k = sdKey(q); if (k < r.x) r = vec2(k, 3.0); }\n  q = spoolP(p);\n  if (length(q - vec3(0.0, 0.19, 0.0)) - 0.32 < r.x) {\n    float w = sdSpoolWood(q); if (w < r.x) r = vec2(w, 5.0);\n    float t = sdThread(q); if (t < r.x) r = vec2(t, 6.0);\n  }\n  q = cardP(p);\n  if (length(q - vec3(0.0, 0.17, 0.0)) - 0.42 < r.x) { float c = sdCard(q); if (c < r.x) r = vec2(c, 7.0); }\n  return r;\n}\n\nvec3 normalAt(vec3 p, bool g) {\n  const vec2 e = vec2(1.0, -1.0) * 0.0007;\n  return normalize(e.xyy * map(p + e.xyy, g).x + e.yyx * map(p + e.yyx, g).x + e.yxy * map(p + e.yxy, g).x + e.xxx * map(p + e.xxx, g).x);\n}\nfloat march(vec3 ro, vec3 rd, float t, float tEnd, bool g, int n, out float id) {\n  id = -1.0;\n  for (int i = 0; i < 140; i++) {\n    if (i >= n) break;\n    vec2 h = map(ro + rd * t, g);\n    if (h.x < 0.00035 * t) { id = h.y; return t; }\n    t += h.x * 0.92;\n    if (t > tEnd) break;\n  }\n  return tEnd;\n}\nvec2 boxI(vec3 ro, vec3 rd, vec3 c, vec3 h) {\n  vec3 m = 1.0 / rd, n = m * (ro - c), k = abs(m) * h;\n  vec3 t1 = -n - k, t2 = -n + k;\n  return vec2(max(max(t1.x, t1.y), t1.z), min(min(t2.x, t2.y), t2.z));\n}\n\n// the window: tall panes with glazing bars, whose shadow lies across the table\nfloat window_(vec3 p) {\n  vec3 a = normalize(cross(L, vec3(0.0, 1.0, 0.0))), b = cross(a, L);\n  vec2 u = vec2(dot(p, a), dot(p, b));\n  // one upright and one transom, far from the table, so their shadows are wide and soft\n  float bx = abs(u.x - 0.9);\n  float by = abs(u.y + 1.15);\n  float frame = smoothstep(2.3, 2.6, abs(u.x - 0.3)) + smoothstep(2.4, 2.8, abs(u.y + 0.2));\n  return clamp((0.25 + 0.75 * smoothstep(0.02, 0.14, bx)) * (0.25 + 0.75 * smoothstep(0.02, 0.14, by)) - frame, 0.08, 1.0);\n}\nfloat shadow(vec3 ro, vec3 rd) {\n  float res = 1.0, t = 0.012;\n  for (int i = 0; i < 40; i++) {\n    float h = map(ro + rd * t, false).x;\n    res = min(res, 7.0 * h / t);\n    t += clamp(h, 0.01, 0.16);\n    if (res < 0.002 || t > 2.8) break;\n  }\n  return clamp(res, 0.0, 1.0);\n}\n// sun through the loupe: the glass bends what falls on it into a smaller, brighter disc\nfloat caustic(vec3 p) {\n  vec3 q = lensP(p), d = lensD(L);\n  if (d.y < 0.05) return 1.0;\n  float t = -q.y / d.y;\n  if (t <= 0.0) return 1.0;\n  float r = length((q + d * t).xz);\n  float f = 2.4;\n  float k = max(1.0 - t / f, 0.15);\n  float rs = r / k;\n  float lit = smoothstep(0.405, 0.38, rs);\n  float rimShade = smoothstep(0.37, 0.4, r) * smoothstep(0.5, 0.46, r);\n  float bright = min(0.78 / (k * k), 1.32) * (1.0 + 0.3 * smoothstep(0.4, 0.33, rs) * smoothstep(0.2, 0.36, rs));\n  float inside = step(r, 0.46);\n  return mix(1.0, mix(0.06, bright, lit) * (1.0 - 0.85 * rimShade * (1.0 - lit)), inside);\n}\nfloat ao(vec3 p, vec3 n) {\n  float o = 0.0, s = 1.0;\n  for (int i = 1; i <= 5; i++) {\n    float h = 0.012 + 0.045 * float(i);\n    o += (h - map(p + n * h, false).x) * s;\n    s *= 0.72;\n  }\n  return clamp(1.0 - 2.4 * o, 0.0, 1.0);\n}\n\nvec3 env(vec3 d) {\n  vec3 c = mix(vec3(0.6, 0.56, 0.5), vec3(0.97, 0.97, 0.98), smoothstep(-0.35, 0.55, d.y));\n  // the side of the room behind the camera is in shade: warm and dim, which gives polished metal its contrast\n  c *= mix(1.0, 0.32, smoothstep(-0.1, 0.7, d.z) * smoothstep(0.95, 0.4, d.y));\n  c = mix(c, c * vec3(1.0, 0.86, 0.7), smoothstep(-0.1, 0.7, d.z) * 0.5);\n  vec3 a = normalize(cross(L, vec3(0.0, 1.0, 0.0))), b = cross(a, L);\n  float k = dot(d, L);\n  if (k > 0.0) {\n    vec2 u = vec2(dot(d, a), dot(d, b)) / k;\n    float pane = smoothstep(0.02, 0.0, sdR2(u, vec2(0.32, 0.5)));\n    float bars = smoothstep(0.012, 0.02, abs(u.x)) * smoothstep(0.012, 0.02, abs(u.y - 0.1));\n    c += vec3(1.0, 0.96, 0.9) * 9.0 * pane * bars;\n  }\n  float kf = dot(d, FD);\n  if (kf > 0.0) {\n    vec3 a2 = normalize(cross(FD, vec3(0.0, 1.0, 0.0))), b2 = cross(a2, FD);\n    vec2 u2 = vec2(dot(d, a2), dot(d, b2)) / kf;\n    c += vec3(1.0, 0.98, 0.95) * 2.4 * smoothstep(0.08, 0.0, sdR2(u2, vec2(0.5, 0.36)));\n  }\n  return c;\n}\n\nfloat tableTex(vec2 x) {\n  // a pale linen cloth: fine weave and a slow mottle\n  float w = 0.5 + 0.5 * sin(x.x * 900.0) * sin(x.y * 900.0);\n  return 0.94 + 0.05 * fbm(x * 1.4) + 0.025 * w + 0.03 * (vnoise(x * vec2(9.0, 160.0)) - 0.5);\n}\n\nstruct M { vec3 alb; float rough; float metal; vec3 n; float sss; };\nM material(vec3 p, vec3 n, float id) {\n  M m; m.n = n; m.metal = 0.0; m.sss = 0.0; m.rough = 0.6;\n  if (id < 0.5) {\n    m.alb = vec3(0.8, 0.74, 0.66) * tableTex(p.xz);\n    m.rough = 0.8;\n  } else if (id < 1.5) {\n    // pressed pulp: a pale grey-green, fibres and a few darker flecks, a soft dimpled skin\n    // (sampled on a plane that turns with the walls, so the texture never smears down a vertical face)\n    vec2 w = p.xz + vec2(p.y, -p.y) * 1.3;\n    float f = fbm(w * 26.0);\n    float dens = fbm(w * 5.0 + 11.0);\n    m.alb = mix(vec3(0.69, 0.72, 0.66), vec3(0.79, 0.81, 0.76), f) * (0.94 + 0.08 * dens);\n    float fleck = smoothstep(0.82, 0.9, vnoise(w * vec2(170.0, 60.0))) * 0.5 + smoothstep(0.93, 0.97, vnoise(w.yx * 230.0));\n    m.alb *= 1.0 - 0.13 * fleck;\n    vec2 g = vec2(vnoise(w * 90.0), vnoise(w.yx * 90.0 + 3.0)) - 0.5;\n    vec2 g2 = vec2(vnoise(w * 26.0), vnoise(w.yx * 26.0 + 5.0)) - 0.5;\n    vec3 tg = vec3(g.x, 0.0, g.y) * 0.22 + vec3(g2.x, 0.0, g2.y) * 0.12;\n    m.n = normalize(n + tg - n * dot(n, tg));\n    m.rough = 0.9; m.sss = 0.45;\n  } else if (id < 3.5) {\n    // brass: worn bright where handled, a warmer patina in the hollows\n    vec3 q = lensP(p);\n    float pat = fbm(p.xz * 18.0 + p.y * 7.0);\n    m.alb = mix(vec3(1.0, 0.78, 0.42), vec3(0.78, 0.55, 0.28), smoothstep(0.45, 0.8, pat));\n    m.metal = 1.0; m.rough = 0.16 + 0.22 * pat;\n    vec2 g = vec2(vnoise(p.xz * 110.0), vnoise(p.zx * 110.0 + 4.0)) - 0.5;\n    m.n = normalize(n + vec3(g.x, 0.0, g.y) * 0.01);\n  } else if (id < 5.5) {\n    vec3 q = spoolP(p);\n    float ring = sin(length(q.xz + vec2(0.4, 0.1)) * 140.0 + fbm(q.xz * 20.0) * 6.0);\n    m.alb = mix(vec3(0.82, 0.64, 0.44), vec3(0.74, 0.55, 0.36), 0.5 + 0.5 * ring);\n    m.rough = 0.42;\n  } else if (id < 6.5) {\n    vec3 q = spoolP(p);\n    // wound cotton: fine turns that catch the light, a little unevenness in the winding\n    float g = sin(q.y * 520.0 + atan(q.z, q.x) * 0.5);\n    float lay = vnoise(vec2(atan(q.z, q.x) * 6.0, q.y * 30.0));\n    m.alb = vec3(0.72, 0.19, 0.12) * (0.86 + 0.14 * g) * (0.9 + 0.2 * lay);\n    m.n = normalize(n + vec3(0.0, g * 0.18, 0.0));\n    m.rough = 0.75; m.sss = 0.6;\n  } else if (id < 7.5) {\n    // cotton card, printed on its front face\n    vec3 q = cardP(p);\n    float th = cardTh(), len = 0.36;\n    vec3 v = q - vec3(0.0, len * cos(th), 0.0);\n    float along = dot(vec2(v.y, abs(v.z)), vec2(-cos(th), sin(th)));\n    float across = dot(vec2(v.y, abs(v.z)), vec2(sin(th), cos(th)));\n    m.alb = vec3(0.95, 0.94, 0.91) * (0.97 + 0.04 * vnoise(q.xy * 220.0));\n    m.alb *= 0.9 + 0.1 * smoothstep(0.0, 0.025, along);\n    if (v.z > 0.0 && across > 0.0) {\n      vec2 c = vec2(v.x, along);\n      float band = step(abs(c.x + 0.04), 0.19) * step(abs(c.y - 0.12), 0.06);\n      float lines = step(abs(c.x + 0.1), 0.13) * step(abs(c.y - 0.235), 0.035) * step(0.45, fract(c.y * 52.0));\n      m.alb = mix(m.alb, vec3(0.13, 0.26, 0.74), band);\n      m.alb = mix(m.alb, vec3(0.16, 0.15, 0.14), lines * 0.85);\n    }\n    m.rough = 0.7; m.sss = 0.5;\n  } else if (id > 8.5) {\n    // a page of an index, set in tiny type: one entry is marked in coral, the thing that was being looked for\n    vec3 q = slipP(p);\n    vec2 u = vec2(q.x, q.z);\n    m.alb = vec3(0.965, 0.955, 0.93) * (0.975 + 0.035 * vnoise(u * 300.0));\n    float lh = 0.046;\n    float y = (u.y + 0.44) / lh;\n    float row = floor(y), fy = abs(fract(y) - 0.5);\n    float wx = (u.x + 0.36) / 0.72;\n    float body = step(0.0, y) * step(y, 21.0) * step(0.0, wx);\n    float band = smoothstep(0.2, 0.12, fy);\n    float tw = wx * 8.0 + hash(vec2(row, 1.0)) * 4.0;\n    float gap = smoothstep(0.0, 0.05, fract(tw)) * smoothstep(0.2, 0.15, fract(tw));\n    float lineLen = smoothstep(0.01, -0.01, wx - (0.55 + 0.42 * hash(vec2(row, 7.0))));\n    float tex = 0.7 + 0.3 * vnoise(vec2(u.x * 170.0, row * 5.0));\n    float ink = body * band * (1.0 - gap) * lineLen * tex;\n    if (row > 6.5 && row < 7.5) m.alb = mix(m.alb, vec3(0.98, 0.66, 0.52), body * smoothstep(0.42, 0.34, fy) * step(0.16, wx) * step(wx, 0.5));\n    m.alb = mix(m.alb, vec3(0.28, 0.26, 0.24), ink * 0.85);\n    // the heading: two bold words and a rule above the entries\n    float hy = (u.y + 0.53) / 0.05;\n    m.alb = mix(m.alb, vec3(0.13, 0.12, 0.11), smoothstep(0.33, 0.25, abs(hy)) * step(0.0, wx) * step(wx, 0.42) * smoothstep(0.03, 0.06, fract(wx * 3.2)));\n    m.alb = mix(m.alb, vec3(0.3, 0.28, 0.26), step(abs(u.y + 0.475), 0.0025) * step(0.0, wx) * step(wx, 1.0));\n    m.rough = 0.8; m.sss = 0.4;\n  } else {\n    vec3 q = lensP(p);\n    m.alb = vec3(0.24, 0.13, 0.07) * (0.8 + 0.4 * vnoise(vec2(q.x * 60.0, atan(q.z, q.y) * 3.0)));\n    m.rough = 0.22;\n  }\n  return m;\n}\n\n// light arriving at a surface point, before the material is applied\nvec3 shade(vec3 p, vec3 n0, vec3 rd, float id, bool full) {\n  M m = material(p, n0, id);\n  vec3 n = m.n;\n  float sh = full ? shadow(p + n0 * 0.006, L) : 1.0;\n  sh *= window_(p) * caustic(p);\n  float o = full ? ao(p, n0) : 1.0;\n  if (id < 0.5) o *= 0.55 + 0.45 * smoothstep(0.0, 0.4, max(abs(p.x) - 1.72, abs(p.z) - 1.12));\n  float nl = dot(n, L);\n  float wrap = max((nl + m.sss * 0.6) / (1.0 + m.sss * 0.6), 0.0);\n  vec3 sssTint = mix(vec3(1.0), m.alb * 1.3, m.sss * 0.5 * (1.0 - max(nl, 0.0)));\n  vec3 bounce = vec3(0.92, 0.86, 0.76) * 0.35 * (0.5 - 0.5 * n.y);\n  vec3 diff = KEY * wrap * sh * sssTint + SKY * (0.62 + 0.38 * n.y) * o + bounce * o + vec3(1.0, 0.97, 0.92) * 0.45 * max(dot(n, FD), 0.0) * o;\n  vec3 R = reflect(rd, n);\n  float F = 0.04 + 0.96 * pow(1.0 - clamp(dot(-rd, n), 0.0, 1.0), 5.0);\n  float shin = 2.0 / (m.rough * m.rough * m.rough + 0.002);\n  float spec = pow(max(dot(R, L), 0.0), shin) * (shin + 2.0) / 8.0;\n  if (m.metal > 0.5) {\n    vec3 Fm = m.alb + (1.0 - m.alb) * pow(1.0 - clamp(dot(-rd, n), 0.0, 1.0), 5.0);\n    vec3 refl = env(R) * mix(1.0, 0.55, m.rough) * o;\n    return Fm * (refl + KEY * sh * spec * 0.8) + m.alb * diff * 0.02;\n  }\n  vec3 col = m.alb * diff;\n  col += F * (env(R) * o * (1.0 - m.rough) * 0.6 + KEY * sh * spec * (1.0 - m.rough * 0.85));\n  return col;\n}\n\n// what a mirror or a lens sees: the rest of the scene, lit but without its own reflections\nvec3 trace2(vec3 ro, vec3 rd, bool full) {\n  float id;\n  vec2 bb = boxI(ro, rd, vec3(0.0, 0.27, 0.0), vec3(1.8, 0.46, 1.2));\n  float tT = rd.y < -1e-4 ? (TB - ro.y) / rd.y : 1e9;\n  float tEnd = min(tT, 6.0);\n  float t = 1e9;\n  id = -1.0;\n  if (bb.y > max(bb.x, 0.0)) t = march(ro, rd, max(bb.x, 0.0), min(bb.y, tEnd), false, full ? 70 : 44, id);\n  if (id > 0.0) { vec3 p = ro + rd * t; return shade(p, normalAt(p, false), rd, id, full); }\n  if (tT < 1e8) { vec3 p = ro + rd * tT; return shade(p, vec3(0.0, 1.0, 0.0), rd, 0.0, full); }\n  return env(rd);\n}\n\nvec3 tonemap(vec3 x) { x *= 0.31; return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0); }\n\nvoid main() {\n  vec2 ndc = vUv * 2.0 - 1.0 - uShift;\n  vec3 rd = normalize(uFw + uRt * (ndc.x * uTan * uAspect) + uUp * (ndc.y * uTan));\n  vec3 ro = uCam;\n  float jit = ign(gl_FragCoord.xy);\n  float tT = (TB - ro.y) / min(rd.y, -1e-4);\n  vec2 bb = boxI(ro, rd, vec3(0.0, 0.27, 0.0), vec3(1.8, 0.46, 1.2));\n  float id = -1.0, t = tT;\n  if (bb.y > max(bb.x, 0.0)) t = march(ro, rd, max(bb.x, 0.0), min(bb.y, tT), true, 140, id);\n  if (id < 0.0) { t = tT; id = 0.0; }\n  vec3 p = ro + rd * t;\n  vec3 col;\n  if (id > 1.5 && id < 2.5) {\n    // the loupe: a mirror on top, and through it the floor of the pocket, bent and enlarged\n    vec3 n = normalAt(p, true);\n    float F = 0.04 + 0.96 * pow(1.0 - clamp(dot(-rd, n), 0.0, 1.0), 5.0);\n    vec3 R = reflect(rd, n);\n    vec3 dir = refract(rd, n, 1.0 / 1.52);\n    vec3 pi = p - n * 0.002;\n    vec3 nl;\n    float s = exitGlass(lensP(pi), lensD(dir), nl);\n    vec3 pe = pi + dir * s;\n    vec3 ne = lensDinv(nl);\n    vec3 od = refract(dir, -ne, 1.52);\n    if (dot(od, od) < 0.01) od = reflect(dir, -ne);\n    vec3 through = trace2(pe + od * 0.004, od, true) * vec3(0.95, 0.985, 0.97);\n    vec3 refl = env(R);\n    col = mix(through, refl, F);\n    col += KEY * 3.0 * pow(max(dot(R, L), 0.0), 900.0);\n    // the ground edge of the glass catches a thin bright line\n    float edge = smoothstep(0.37, 0.4, length(lensP(p).xz));\n    col += vec3(0.9, 0.95, 1.0) * edge * 0.35;\n  } else {\n    vec3 n = id > 0.5 ? normalAt(p, true) : vec3(0.0, 1.0, 0.0);\n    col = shade(p, n, rd, id, true);\n    if (id > 2.5 && id < 3.5) {\n      // brass mirrors the tray and its neighbours, softened by its roughness\n      M m = material(p, n, id);\n      vec3 R = reflect(rd, m.n);\n      vec3 Fm = m.alb + (1.0 - m.alb) * pow(1.0 - clamp(dot(-rd, m.n), 0.0, 1.0), 5.0);\n      vec3 seen = trace2(p + n * 0.01, R, false);\n      col = mix(col, Fm * seen * mix(1.0, 0.6, m.rough) + col * 0.25, 0.62);\n    }\n  }\n\n  float depth = t * dot(rd, uFw);\n  float coc = clamp(uAperture * (1.0 - uFocus / max(depth, 0.05)), -1.0, 1.0);\n  o = vec4(pow(tonemap(col), vec3(1.0 / 2.2)), 0.5 + 0.5 * coc);\n}`;\n\nconst VS = `#version 300 es\nout vec2 vUv;\nvoid main() { vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2)); vUv = p; gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0); }`;\n\nconst FS_LENS = `#version 300 es\nprecision highp float;\nuniform sampler2D uScene;\nuniform vec2 uPx;\nuniform float uMaxR;\nin vec2 vUv;\nout vec4 o;\nfloat ign(vec2 p) { return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715)))); }\nvoid main() {\n  vec4 c0 = texture(uScene, vUv);\n  float s0 = c0.a * 2.0 - 1.0;\n  float coc0 = abs(s0);\n  vec3 lin0 = pow(c0.rgb, vec3(2.2));\n  float w0 = 1.0 / (1.04 - max(lin0.r, max(lin0.g, lin0.b)) * 0.9);\n  vec3 acc = lin0 * w0; float wsum = w0;\n  float rot = 6.2832 * ign(gl_FragCoord.xy);\n  for (int k = 1; k < 28; k++) {\n    float r = sqrt(float(k) / 28.0) * uMaxR;\n    float a = float(k) * 2.39996 + rot;\n    vec4 s = texture(uScene, vUv + vec2(cos(a), sin(a)) * r * uPx);\n    float sc = s.a * 2.0 - 1.0;\n    float cs = abs(sc);\n    if (sc > s0) cs = min(cs, coc0 * 1.6 + 0.02);\n    vec3 lin = pow(s.rgb, vec3(2.2));\n    float w = smoothstep(r - 1.0, r + 1.0, cs * uMaxR) / (1.04 - max(lin.r, max(lin.g, lin.b)) * 0.9);\n    acc += lin * w; wsum += w;\n  }\n  o = vec4(pow(acc / wsum, vec3(1.0 / 2.2)), 1.0);\n}`;\n\nconst FS_OUT = `#version 300 es\nprecision highp float;\nuniform sampler2D uScene;\nuniform vec2 uPx;\nuniform float uTime;\nin vec2 vUv;\nout vec4 o;\nfloat ign(vec2 p) { return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715)))); }\nconst vec3 LU = vec3(0.299, 0.587, 0.114);\nvoid main() {\n  vec3 m = texture(uScene, vUv).rgb;\n  vec3 cNW = texture(uScene, vUv + vec2(-1.0, -1.0) * uPx).rgb, cNE = texture(uScene, vUv + vec2(1.0, -1.0) * uPx).rgb;\n  vec3 cSW = texture(uScene, vUv + vec2(-1.0, 1.0) * uPx).rgb, cSE = texture(uScene, vUv + vec2(1.0, 1.0) * uPx).rgb;\n  float lNW = dot(cNW, LU), lNE = dot(cNE, LU), lSW = dot(cSW, LU), lSE = dot(cSE, LU);\n  float lM = dot(m, LU);\n  float lMin = min(lM, min(min(lNW, lNE), min(lSW, lSE))), lMax = max(lM, max(max(lNW, lNE), max(lSW, lSE)));\n  vec2 dir = vec2(-((lNW + lNE) - (lSW + lSE)), (lNW + lSW) - (lNE + lSE));\n  float rcp = 1.0 / (min(abs(dir.x), abs(dir.y)) + max((lNW + lNE + lSW + lSE) * 0.03125, 0.0078));\n  dir = clamp(dir * rcp, -8.0, 8.0) * uPx;\n  vec3 a = 0.5 * (texture(uScene, vUv + dir * (1.0 / 3.0 - 0.5)).rgb + texture(uScene, vUv + dir * (2.0 / 3.0 - 0.5)).rgb);\n  vec3 b = a * 0.5 + 0.25 * (texture(uScene, vUv - dir * 0.5).rgb + texture(uScene, vUv + dir * 0.5).rgb);\n  float lB = dot(b, LU);\n  vec3 col = (lB < lMin || lB > lMax) ? a : b;\n  col += (m - 0.25 * (cNW + cNE + cSW + cSE)) * 0.35;\n  vec3 glow = vec3(0.0);\n  float rot = 6.2832 * ign(gl_FragCoord.xy);\n  for (int k = 0; k < 12; k++) {\n    float an = float(k) * 2.39996 + rot;\n    float d = 3.0 + 22.0 * sqrt(float(k) / 12.0);\n    vec3 s = texture(uScene, vUv + vec2(cos(an), sin(an)) * d * uPx).rgb;\n    glow += s * smoothstep(0.95, 1.0, dot(s, LU));\n  }\n  col += glow / 12.0 * vec3(0.22, 0.18, 0.12);\n  vec2 q = vUv - 0.5;\n  col *= 1.0 - 0.3 * dot(q, q);\n  col += (ign(gl_FragCoord.xy + fract(uTime) * 61.0) - 0.5) * 0.018;\n  o = vec4(col, 1.0);\n}`;\n\nfunction program(gl: WebGL2RenderingContext, vs: string, fs: string) {\n  const p = gl.createProgram()!;\n  for (const [type, src] of [[gl.VERTEX_SHADER, vs], [gl.FRAGMENT_SHADER, fs]] as const) {\n    const s = gl.createShader(type)!;\n    gl.shaderSource(s, src);\n    gl.compileShader(s);\n    if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s) || \"shader\");\n    gl.attachShader(p, s);\n  }\n  gl.linkProgram(p);\n  if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p) || \"link\");\n  return p;\n}\n\n/** Small drawings of the four objects, for the still tray shown without WebGL. */\nfunction Glyph({ i }: { i: number }) {\n  const common = { \"aria-hidden\": true as const, className: \"h-full w-full\", viewBox: \"0 0 100 100\" };\n  if (i === 0)\n    return (\n      <svg {...common}>\n        <defs>\n          <radialGradient id=\"pulp-tray-lens\" cx=\"40%\" cy=\"35%\" r=\"70%\">\n            <stop offset=\"0\" stopColor=\"#ffffff\" stopOpacity=\"0.9\" />\n            <stop offset=\"0.5\" stopColor=\"#dfe6e2\" stopOpacity=\"0.5\" />\n            <stop offset=\"1\" stopColor=\"#b9c4bf\" stopOpacity=\"0.6\" />\n          </radialGradient>\n        </defs>\n        <path d=\"M58 64 L86 88\" stroke=\"#3b2414\" strokeWidth=\"8\" strokeLinecap=\"round\" />\n        <path d=\"M58 64 L64 69\" stroke=\"#c99a52\" strokeWidth=\"9\" strokeLinecap=\"round\" />\n        <circle cx=\"42\" cy=\"46\" r=\"26\" fill=\"url(#pulp-tray-lens)\" stroke=\"#c4914a\" strokeWidth=\"5\" />\n      </svg>\n    );\n  if (i === 1)\n    return (\n      <svg {...common}>\n        <circle cx=\"22\" cy=\"50\" r=\"12\" fill=\"none\" stroke=\"#c4914a\" strokeWidth=\"5\" />\n        <path d=\"M34 50 H84\" stroke=\"#c4914a\" strokeWidth=\"5\" strokeLinecap=\"round\" />\n        <path d=\"M70 50 V60 H76 V56 H82 V50\" fill=\"#c4914a\" />\n      </svg>\n    );\n  if (i === 2)\n    return (\n      <svg {...common}>\n        <rect x=\"28\" y=\"22\" width=\"44\" height=\"7\" rx=\"3\" fill=\"#cfa77a\" />\n        <rect x=\"31\" y=\"29\" width=\"38\" height=\"42\" fill=\"#c33a24\" />\n        <rect x=\"28\" y=\"71\" width=\"44\" height=\"7\" rx=\"3\" fill=\"#b88d60\" />\n      </svg>\n    );\n  return (\n    <svg {...common}>\n      <path d=\"M20 74 L50 30 L80 74 Z\" fill=\"#f4f2ec\" stroke=\"#d7d3ca\" strokeWidth=\"1.5\" />\n      <path d=\"M38 62 L50 44 L62 62 Z\" fill=\"#2443b8\" />\n    </svg>\n  );\n}\n\n/** The tray drawn with plain elements, for browsers without WebGL 2. */\nfunction Still({ active, side }: { active: number; side: boolean }) {\n  const cells = [\n    { x: 2, y: 2, w: 47, h: 96 },\n    { x: 51, y: 2, w: 47, h: 47 },\n    { x: 51, y: 51, w: 22.5, h: 47 },\n    { x: 75.5, y: 51, w: 22.5, h: 47 },\n  ];\n  return (\n    <div aria-hidden=\"true\" className=\"absolute inset-0 overflow-hidden bg-[#e7e1d6]\" style={{ backgroundImage: \"radial-gradient(120% 90% at 30% 10%, #f4f0e8 0%, #e7e1d6 55%, #d9d2c5 100%)\" }}>\n      <div className={`absolute ${side ? \"left-[42%] right-[5%] top-[16%]\" : \"left-[6%] right-[6%] top-[12%]\"}`} style={{ perspective: \"1400px\" }}>\n        <div className=\"relative aspect-[3.4/2.2] rounded-[22px] bg-[#dcdcd4] shadow-[0_40px_60px_-20px_rgba(60,48,30,0.35),0_8px_18px_rgba(60,48,30,0.18)]\" style={{ transform: \"rotateX(38deg)\", transformOrigin: \"50% 70%\" }}>\n          {cells.map((c, i) => (\n            <div key={i} className=\"absolute rounded-[16px] bg-[#d2d3ca]\" style={{ left: `${c.x}%`, top: `${c.y}%`, width: `${c.w}%`, height: `${c.h}%`, boxShadow: \"inset 0 10px 18px rgba(70,64,50,0.28), inset 0 -2px 3px rgba(255,255,255,0.6)\" }}>\n              <div className=\"absolute inset-[16%] transition-transform duration-500 ease-out motion-reduce:transition-none\" style={{ transform: i === active ? \"translateY(-14%) scale(1.08)\" : \"none\", filter: i === active ? \"drop-shadow(0 18px 12px rgba(50,40,25,0.3))\" : \"drop-shadow(0 3px 2px rgba(50,40,25,0.35))\" }}>\n                <Glyph i={i} />\n              </div>\n            </div>\n          ))}\n        </div>\n      </div>\n    </div>\n  );\n}\n\ntype Sim = { lift: number[]; vel: number[]; active: number; focus: number; touched: boolean; dirty: boolean };\n\nexport default function PulpTrayFeatures() {\n  const reduce = useReducedMotion();\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const [active, setActive] = useState(0);\n  const [mode, setMode] = useState<\"pending\" | \"gl\" | \"still\">(\"pending\");\n  const [side, setSide] = useState(true);\n  const [handled, setHandled] = useState(false);\n  const sim = useRef<Sim>({ lift: [1, 0, 0, 0], vel: [0, 0, 0, 0], active: 0, focus: NaN, touched: false, dirty: true });\n\n  const choose = (i: number) => {\n    sim.current.touched = true;\n    setHandled(true);\n    setActive(i);\n  };\n\n  useEffect(() => {\n    const s = sim.current;\n    if (s.active !== active) {\n      // a small press into the pulp before it rises: anticipation\n      s.vel[active] -= 1.1;\n      s.active = active;\n    }\n    s.dirty = true;\n  }, [active]);\n\n  useEffect(() => {\n    const wrap = wrapRef.current;\n    const canvas = canvasRef.current;\n    if (!wrap || !canvas) return;\n    const gl = canvas.getContext(\"webgl2\", { antialias: false, alpha: false, powerPreference: \"high-performance\" });\n    if (!gl) {\n      setMode(\"still\");\n      return;\n    }\n    const s = sim.current;\n    let pScene: WebGLProgram, pLens: WebGLProgram, pOut: WebGLProgram;\n    try {\n      pScene = program(gl, VS, GLSL);\n      pLens = program(gl, VS, FS_LENS);\n      pOut = program(gl, VS, FS_OUT);\n    } catch {\n      setMode(\"still\");\n      return;\n    }\n    setMode(\"gl\");\n\n    const vao = gl.createVertexArray();\n    const fbos = [gl.createFramebuffer(), gl.createFramebuffer()];\n    const texs = [gl.createTexture(), gl.createTexture()];\n    let W = 0, H = 0, scale = Math.min(window.devicePixelRatio || 1, 2), cssW = 1, cssH = 1, wide = true;\n    const TAN = Math.tan((11 * Math.PI) / 180);\n    const cam = { pos: [0, 5, 6], rt: [1, 0, 0], up: [0, 1, 0], fw: [0, 0, -1], shift: [0, 0] };\n\n    const aim = (t: number) => {\n      const aspect = cssW / cssH;\n      wide = cssW >= 1024;\n      const el = (wide ? 0.74 : 0.86) + (reduce ? 0 : 0.012 * Math.sin(t * 0.21));\n      const yaw = (wide ? 0.3 : 0.06) + (reduce ? 0 : 0.03 * Math.sin(t * 0.17));\n      const target = [0.06, -0.02, 0.02];\n      const dist = wide ? Math.max(3.75 / (1.32 * TAN * aspect), 2.5 / (2 * TAN * 0.92)) : Math.max(3.8 / (2 * TAN * aspect), 2.6 / (2 * TAN));\n      cam.pos = [target[0] + Math.sin(yaw) * Math.cos(el) * dist, target[1] + Math.sin(el) * dist, target[2] + Math.cos(yaw) * Math.cos(el) * dist];\n      let fw = [target[0] - cam.pos[0], target[1] - cam.pos[1], target[2] - cam.pos[2]];\n      const fl = Math.hypot(fw[0], fw[1], fw[2]);\n      fw = fw.map((v) => v / fl);\n      let rt = [-fw[2], 0, fw[0]];\n      const rl = Math.hypot(rt[0], rt[2]);\n      rt = rt.map((v) => v / rl);\n      cam.fw = fw;\n      cam.rt = rt;\n      cam.up = [rt[1] * fw[2] - rt[2] * fw[1], rt[2] * fw[0] - rt[0] * fw[2], rt[0] * fw[1] - rt[1] * fw[0]];\n      cam.shift = wide ? [0.38, -0.06] : [0, 0.02];\n      return aspect;\n    };\n\n    const resize = () => {\n      cssW = wrap.clientWidth;\n      cssH = wrap.clientHeight;\n      let k = scale;\n      if (cssW * cssH * k * k > 1.6e6) k = Math.sqrt(1.6e6 / (cssW * cssH));\n      const w = Math.max(2, Math.round(cssW * k)), h = Math.max(2, Math.round(cssH * k));\n      aim(0);\n      setSide(wide);\n      if (w === W && h === H) return;\n      W = w;\n      H = h;\n      canvas.width = W;\n      canvas.height = H;\n      texs.forEach((t, i) => {\n        gl.activeTexture(gl.TEXTURE1 + i);\n        gl.bindTexture(gl.TEXTURE_2D, t);\n        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, W, H, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_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, fbos[i]);\n        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, t, 0);\n      });\n      s.dirty = true;\n    };\n    resize();\n    const ro = new ResizeObserver(resize);\n    ro.observe(wrap);\n\n    const U = (p: WebGLProgram, n: string) => gl.getUniformLocation(p, n);\n    const focusTo = () => {\n      const r = RESTS[s.active], l = s.lift[s.active];\n      const d = [r[0] - cam.pos[0], r[1] + l * 0.34 - cam.pos[1], r[2] - cam.pos[2]];\n      return d[0] * cam.fw[0] + d[1] * cam.fw[1] + d[2] * cam.fw[2];\n    };\n\n    const draw = (t: number) => {\n      const aspect = aim(t);\n      if (Number.isNaN(s.focus) || reduce) s.focus = focusTo();\n      gl.bindVertexArray(vao);\n      gl.disable(gl.DEPTH_TEST);\n      gl.viewport(0, 0, W, H);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, fbos[0]);\n      gl.useProgram(pScene);\n      gl.uniform4fv(U(pScene, \"uLift\"), s.lift);\n      gl.uniform3fv(U(pScene, \"uCam\"), cam.pos);\n      gl.uniform3fv(U(pScene, \"uRt\"), cam.rt);\n      gl.uniform3fv(U(pScene, \"uUp\"), cam.up);\n      gl.uniform3fv(U(pScene, \"uFw\"), cam.fw);\n      gl.uniform1f(U(pScene, \"uTan\"), TAN);\n      gl.uniform1f(U(pScene, \"uAspect\"), aspect);\n      gl.uniform2fv(U(pScene, \"uShift\"), cam.shift);\n      gl.uniform2f(U(pScene, \"uRes\"), W, H);\n      gl.uniform1f(U(pScene, \"uFocus\"), s.focus);\n      gl.uniform1f(U(pScene, \"uAperture\"), 1.5);\n      gl.uniform1f(U(pScene, \"uTime\"), t);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, fbos[1]);\n      gl.useProgram(pLens);\n      gl.uniform1i(U(pLens, \"uScene\"), 1);\n      gl.uniform2f(U(pLens, \"uPx\"), 1 / W, 1 / H);\n      gl.uniform1f(U(pLens, \"uMaxR\"), H * 0.012);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n      gl.useProgram(pOut);\n      gl.uniform1i(U(pOut, \"uScene\"), 2);\n      gl.uniform2f(U(pOut, \"uPx\"), 1 / W, 1 / H);\n      gl.uniform1f(U(pOut, \"uTime\"), reduce ? 0 : t);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n    };\n\n    const physics = (dt: number, t: number) => {\n      for (let i = 0; i < 4; i++) {\n        const goal = i === s.active ? 1 + 0.035 * Math.sin(t * 1.4) : 0;\n        s.vel[i] += (LIFT_SPRING * (goal - s.lift[i]) - LIFT_DAMPING * s.vel[i]) * dt;\n        s.lift[i] += s.vel[i] * dt;\n        // a resting object cannot sink into the floor of its pocket\n        if (s.lift[i] < 0) {\n          s.lift[i] = 0;\n          if (s.vel[i] < 0) s.vel[i] *= -0.18;\n        }\n      }\n      const f = focusTo();\n      s.focus += (f - s.focus) * Math.min(1, dt * 5);\n    };\n    const settle = () => {\n      for (let i = 0; i < 4; i++) {\n        s.lift[i] = i === s.active ? 1 : 0;\n        s.vel[i] = 0;\n      }\n    };\n\n    let raf = 0, visible = true, last = performance.now(), slow = 0, frames = 0;\n    const t0 = last;\n    let played = 0, demoAt = 3.6;\n    const tick = (now: number) => {\n      const real = now - last;\n      const dt = Math.min(Math.max(real / 1000, 0), 0.05);\n      last = now;\n      const t = (now - t0) / 1000;\n      if (reduce) {\n        if (s.dirty) settle();\n      } else {\n        const sub = Math.max(1, Math.ceil(dt / 0.004));\n        for (let i = 0; i < sub; i++) physics(dt / sub, t);\n        played += dt;\n        if (DEMO && !s.touched && played > demoAt) {\n          setActive((a) => (a + 1) % features.length);\n          demoAt = played + 3.2;\n        }\n      }\n      if (!reduce || s.dirty) {\n        draw(reduce ? 0 : t);\n        s.dirty = false;\n        if (!reduce && ++frames > 20) {\n          slow = slow * 0.92 + (real > 24 ? 1 : 0) * 0.08;\n          if (slow > 0.6 && scale > 0.5) {\n            scale *= 0.84;\n            slow = 0;\n            frames = 0;\n            resize();\n          }\n        }\n      }\n      if (visible && !document.hidden) raf = requestAnimationFrame(tick);\n      else raf = 0;\n    };\n    const wake = () => {\n      if (raf || !visible || document.hidden) return;\n      last = performance.now();\n      frames = 0;\n      raf = requestAnimationFrame(tick);\n    };\n    const io = new IntersectionObserver(([e]) => {\n      visible = e.isIntersecting;\n      wake();\n    });\n    io.observe(wrap);\n    document.addEventListener(\"visibilitychange\", wake);\n    raf = requestAnimationFrame(tick);\n\n    // which compartment is under the pointer: cast the ray onto the top of the tray\n    const cellAt = (e: PointerEvent) => {\n      const r = canvas.getBoundingClientRect();\n      const aspect = aim(0);\n      const nx = ((e.clientX - r.left) / r.width) * 2 - 1 - cam.shift[0];\n      const ny = 1 - ((e.clientY - r.top) / r.height) * 2 - cam.shift[1];\n      const d = [0, 1, 2].map((k) => cam.fw[k] + cam.rt[k] * nx * TAN * aspect + cam.up[k] * ny * TAN);\n      if (d[1] >= 0) return -1;\n      const t = (0.0 - cam.pos[1]) / d[1];\n      const x = cam.pos[0] + d[0] * t, z = cam.pos[2] + d[2] * t;\n      return CELLS.findIndex((c) => Math.abs(x - c[0]) < c[2] + 0.04 && Math.abs(z - c[1]) < c[3] + 0.04);\n    };\n    const move = (e: PointerEvent) => {\n      const i = cellAt(e);\n      canvas.style.cursor = i >= 0 ? \"pointer\" : \"\";\n      if (i >= 0 && e.pointerType === \"mouse\" && i !== s.active) {\n        s.touched = true;\n        setHandled(true);\n        setActive(i);\n      }\n    };\n    const down = (e: PointerEvent) => {\n      const i = cellAt(e);\n      if (i >= 0) {\n        s.touched = true;\n        setHandled(true);\n        setActive(i);\n      }\n    };\n    const lost = (e: Event) => {\n      e.preventDefault();\n      setMode(\"still\");\n    };\n    canvas.addEventListener(\"pointermove\", move);\n    canvas.addEventListener(\"pointerdown\", down);\n    canvas.addEventListener(\"webglcontextlost\", lost);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", wake);\n      canvas.removeEventListener(\"pointermove\", move);\n      canvas.removeEventListener(\"pointerdown\", down);\n      canvas.removeEventListener(\"webglcontextlost\", lost);\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    };\n  }, [reduce]);\n\n  const f = features[active];\n\n  return (\n    <section className=\"relative overflow-hidden bg-[#e7e1d6] text-[#1d1a16]\" style={{ fontFamily: GROTESK }}>\n      <div ref={wrapRef} className=\"relative h-[360px] sm:h-[540px] lg:absolute lg:inset-0 lg:h-auto\">\n        <canvas ref={canvasRef} aria-hidden=\"true\" className={`absolute inset-0 h-full w-full touch-pan-y ${mode === \"still\" ? \"hidden\" : \"\"}`} />\n        {mode === \"still\" && <Still active={active} side={side} />}\n        <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-x-0 bottom-0 h-16 bg-gradient-to-b from-[#e7e1d6]/0 to-[#e7e1d6] lg:hidden\" />\n      </div>\n\n      <div className=\"pointer-events-none relative flex flex-col px-5 pb-10 pt-2 sm:px-9 lg:h-[780px] lg:w-[40%] lg:max-w-[540px] lg:justify-between lg:py-12 lg:pl-14 lg:pr-0\">\n        <div className=\"hidden lg:block\">\n          <p className=\"text-[11px] font-semibold uppercase tracking-[0.26em] text-[#1d1a16]/70\">\n            {product.name}\n            <span className=\"mx-2 text-[#1d1a16]/35\">/</span>\n            {product.line}\n          </p>\n          <h2 className=\"mt-4 text-[34px] italic leading-[1.05] text-[#1d1a16]\" style={{ fontFamily: SERIF, letterSpacing: \"-0.02em\" }}>\n            Four things it does, each kept in its own place.\n          </h2>\n        </div>\n        <h2 className=\"text-[26px] italic leading-[1.1] lg:hidden\" style={{ fontFamily: SERIF, letterSpacing: \"-0.02em\" }}>\n          Four things {product.name} does, each in its own place.\n        </h2>\n\n        <div className=\"mt-6 lg:mt-0\" aria-live={handled ? \"polite\" : \"off\"}>\n          <p className=\"text-[12px] font-semibold uppercase tracking-[0.24em] text-[#1d1a16]/70\">\n            <span className=\"tabular-nums text-[#1d1a16]\">{`0${active + 1}`}</span>\n            <span className=\"mx-2 text-[#1d1a16]/35\">/</span>\n            {f.object}\n          </p>\n          <div className=\"relative mt-2 min-h-[150px] sm:min-h-[170px] lg:min-h-[230px]\">\n            <AnimatePresence mode=\"wait\" initial={false}>\n              <motion.div\n                key={active}\n                initial={reduce ? false : { opacity: 0, y: 18 }}\n                animate={{ opacity: 1, y: 0 }}\n                exit={reduce ? { opacity: 0 } : { opacity: 0, y: -10 }}\n                transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 320, damping: 30 }}\n              >\n                <h3 className=\"text-[44px] font-semibold leading-[0.92] sm:text-[58px] lg:text-[68px]\" style={{ letterSpacing: \"-0.05em\" }}>\n                  {f.name}\n                </h3>\n                <p className=\"mt-4 max-w-[30ch] text-[18px] leading-[1.35] text-[#3a352d] sm:text-[20px]\" style={{ fontFamily: SERIF }}>\n                  {f.line}\n                </p>\n              </motion.div>\n            </AnimatePresence>\n          </div>\n        </div>\n\n        <ul className=\"pointer-events-auto mt-6 grid grid-cols-1 gap-x-6 border-t sm:grid-cols-2 border-[#1d1a16]/15 lg:mt-0 lg:grid-cols-1\">\n          {features.map((x, i) => (\n            <li key={x.name} className=\"border-b border-[#1d1a16]/15\">\n              <button\n                type=\"button\"\n                aria-pressed={active === i}\n                onClick={() => choose(i)}\n                onFocus={() => choose(i)}\n                onMouseEnter={() => choose(i)}\n                className=\"group flex min-h-[48px] w-full items-center gap-3 py-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#1d1a16] focus-visible:ring-offset-2 focus-visible:ring-offset-[#e7e1d6]\"\n              >\n                <span className={`text-[11px] font-semibold tabular-nums tracking-[0.12em] ${active === i ? \"text-[#1d1a16]\" : \"text-[#1d1a16]/55\"}`}>{`0${i + 1}`}</span>\n                <span className={`text-[15px] font-semibold tracking-[-0.01em] transition-colors sm:text-[16px] ${active === i ? \"text-[#1d1a16]\" : \"text-[#1d1a16]/65 group-hover:text-[#1d1a16]\"}`}>{x.name}</span>\n                <span className={`ml-auto hidden h-[2px] origin-left bg-[#1d1a16] transition-all duration-300 motion-reduce:transition-none sm:block ${active === i ? \"w-8\" : \"w-0\"}`} />\n              </button>\n            </li>\n          ))}\n        </ul>\n      </div>\n    </section>\n  );\n}\n"}]}
