{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"sunlit-print-table-photo-gallery-in-webgl-where-the-chosen-print-lifts-off-travertine-into-focus-through-window-light-and-leaf-shadows","type":"registry:block","title":"Sunlit Print Table Photo Gallery in WebGL Where the Chosen Print Lifts off Travertine into Focus Through Window Light and Leaf Shadows","description":"Free 3D photo gallery in raw WebGL: curled prints on a sunlit travertine table, one lifts into focus while its shadow softens. React and HTML code.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/sunlit-print-table-photo-gallery-in-webgl-where-the-chosen-print-lifts-off-travertine-into-focus-through-window-light-and-leaf-shadows.tsx","type":"registry:component","content":"import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n/** The prints. `focus` is the crop centre (0 to 1), `tone` shows until the photo arrives. */\nconst plates = [\n  { title: \"Tulle at noon\", src: \"https://images.pexels.com/photos/25863051/pexels-photo-25863051.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Woman half hidden in a cloud of bright orange tulle against a blue sky\", focus: [0.56, 0.5], tone: \"#e8721c\" },\n  { title: \"Crosswind\", src: \"https://images.pexels.com/photos/27582026/pexels-photo-27582026.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Woman in a flowing coral chiffon gown lifted by the wind under a pale blue sky\", focus: [0.5, 0.4], tone: \"#e9744e\" },\n  { title: \"Made fast\", src: \"https://images.pexels.com/photos/31041225/pexels-photo-31041225.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Bright yellow cloth tied to a wooden post and pulled tight across a deep blue sky\", focus: [0.5, 0.5], tone: \"#e9b320\" },\n  { title: \"Red weather\", src: \"https://images.pexels.com/photos/6053189/pexels-photo-6053189.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Woman in a pleated red dress leaning into the frame beneath scattered white clouds\", focus: [0.52, 0.55], tone: \"#d8231c\" },\n  { title: \"Cumulus\", src: \"https://images.pexels.com/photos/6540372/pexels-photo-6540372.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Woman in a long red gown standing against a deep blue sky with a low band of cloud\", focus: [0.52, 0.62], tone: \"#1f6fc2\" },\n  { title: \"White wall\", src: \"https://images.pexels.com/photos/9547892/pexels-photo-9547892.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Woman in a short yellow dress standing before a white wall with a wedge of blue sky above\", focus: [0.62, 0.6], tone: \"#d9d4c8\" },\n  { title: \"Saffron\", src: \"https://images.pexels.com/photos/13433087/pexels-photo-13433087.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Woman in profile wrapped in billowing yellow fabric with soft clouds behind her\", focus: [0.45, 0.5], tone: \"#e3b94a\" },\n];\n\nconst N = plates.length;\nconst MASTHEAD = \"Midi\"; // the wordmark, also printed on every sheet\nconst SERIES = \"Summer proofs\";\nconst HOLD_MS = 4400; // rest between automatic changes\nconst LIFT_SPRING = 18; // pull of a chosen print toward the camera\nconst LIFT_DAMPING = 4.6; // lower for more overshoot\nconst DROP_GRAVITY = 8; // how hard a print falls back to the table\nconst TEX_W = 720;\nconst TEX_H = 960;\nconst PAD = 40; // paper margin around the photograph, in texture pixels\nconst FOOT = 96; // the deeper bottom margin that carries the caption\nconst SERIF = '\"Didot\", \"Bodoni 72\", \"Bodoni MT\", \"Playfair Display\", \"Libre Bodoni\", Georgia, serif';\nconst GROTESK = '\"Inter Tight\", \"Inter\", ui-sans-serif, system-ui, sans-serif';\n\nconst mod = (a: number, n: number) => ((a % n) + n) % n;\nconst clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));\n\n// The set, in metres. A print is 21 by 28 cm and lies face up on a stone table.\nconst HX = 0.105;\nconst HY = 0.14;\nconst K_HERO = 0.35; // the gentle arch a lifted sheet keeps\n/** Where each print lies: x, z, turn in radians, how far its long edges curl up, and a little twist. */\nconst slots = [\n  [0.05, -0.56, 0.05, 0.75, 0.2],\n  [-0.21, -0.28, -0.1, 0.6, -0.25],\n  [-0.53, -0.45, 0.1, 1.1, 0.35],\n  [-0.47, -0.13, 0.2, 0.95, 0.3],\n  [0.34, -0.28, -0.16, 1.0, -0.4],\n  [0.6, -0.48, -0.07, 0.9, -0.3],\n  [0.48, 0.07, 0.13, 0.7, 0.3],\n];\n\n/** The branches whose shadows cross the table: base and direction in the plane of the window, length, bend, and a seed for the leaves. */\nconst branches = [\n  [-0.5, 1.02, 0.74, 0.72, -0.5, 1],\n  [-0.5, 0.74, 0.3, 0.5, 0.42, 4],\n  [0.66, 2.5, -1.62, 0.62, 0.3, 7],\n];\nconst rnd = (a: number, b: number) => {\n  const x = Math.sin(a * 127.1 + b * 311.7) * 43758.5453;\n  return x - Math.floor(x);\n};\n\nconst GLSL_HEAD = `#version 300 es\nprecision highp float;\nprecision highp sampler2DArray;\nconst int NP = 7;\nconst vec2 HS = vec2(${HX}, ${HY});\nconst vec3 SUN = vec3(-0.52, 0.72, 0.46);\nconst vec3 SUNC = vec3(1.0, 0.93, 0.8) * 2.0;\nconst vec3 SKYC = vec3(0.44, 0.65, 1.0) * 0.44;\nconst vec3 FILL = vec3(0.065, 0.055, 0.045);\nuniform vec3 uPc[7];\nuniform vec3 uPu[7];\nuniform vec3 uPv[7];\nuniform vec2 uPk[7];\nuniform sampler2DArray uTex;\nuniform vec3 uCam, uRt, uUp, uFw;\nuniform float uTan, uAspect, uFocus, uAperture;\nuniform vec4 uLf[24];\nuniform vec2 uLg[24];\nuniform vec4 uSt[6];\nuniform vec3 uBb[3];\n\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); }\n\n// Where a ray meets print i, a sheet bent into a shallow gutter: distance along the ray, and how far outside the sheet it lands.\nbool sheet(int i, vec3 P, vec3 D, out float t, out float sd, out vec2 hit) {\n  vec3 n = cross(uPu[i], uPv[i]);\n  vec3 p = P - uPc[i];\n  float pu = dot(p, uPu[i]), pv = dot(p, uPv[i]), pw = dot(p, n);\n  float du = dot(D, uPu[i]), dv = dot(D, uPv[i]), dw = dot(D, n);\n  if (abs(dw) < 1e-4) return false;\n  vec2 k = uPk[i];\n  t = -pw / dw;\n  for (int j = 0; j < 2; j++) {\n    float x = clamp(pu + t * du, -HS.x * 1.4, HS.x * 1.4), y = clamp(pv + t * dv, -HS.y * 1.4, HS.y * 1.4);\n    t -= (pw + t * dw - k.x * x * x - k.y * x * y) / (dw - 2.0 * k.x * x * du - k.y * (du * y + x * dv));\n  }\n  if (t < 2e-4) return false;\n  hit = vec2(pu + t * du, pv + t * dv);\n  vec2 q = abs(hit) - HS;\n  sd = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0);\n  return true;\n}\n\n// The olive branches outside the window, as soft-edged shapes in a plane near the glass. The leaves are posed on the CPU each frame.\nfloat foliage(vec2 q) {\n  float d = 1e3;\n  for (int b = 0; b < 3; b++) {\n    vec3 bb = uBb[b];\n    if (length(q - bb.xy) > bb.z) continue;\n    for (int j = 0; j < 2; j++) {\n      vec4 st = uSt[b * 2 + j];\n      vec2 pa = q - st.xy, ba = st.zw - st.xy;\n      d = min(d, length(pa - ba * clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0)) - 0.004);\n    }\n    for (int j = 0; j < 8; j++) {\n      vec4 lf = uLf[b * 8 + j]; vec2 lg = uLg[b * 8 + j];\n      vec2 dd = q - lf.xy;\n      vec2 l = vec2(dd.x * lf.z + dd.y * lf.w, -dd.x * lf.w + dd.y * lf.z);\n      float x = clamp(l.x / lg.x, 0.0, 1.0);\n      d = min(d, max(abs(l.y) - lg.y * sqrt(4.0 * x * (1.0 - x)) * (1.2 - 0.55 * x), max(-l.x, l.x - lg.x)));\n    }\n  }\n  return d;\n}\n\n// Sunlight that reaches a point before the prints get in the way: a tall window with glazing bars, and a branch swaying outside it.\nfloat gobo(vec3 P) {\n  float t = (P.x + 1.5) / -SUN.x;\n  vec2 w = vec2(P.z + SUN.z * t, P.y + SUN.y * t);\n  float b = 0.0075 * t;\n  float open = smoothstep(-0.87 - b, -0.87 + b, w.x) * smoothstep(2.73 + b, 2.73 - b, w.x) * smoothstep(0.86 - b, 0.86 + b, w.y) * smoothstep(3.42 + b, 3.42 - b, w.y);\n  float bx = abs(mod(w.x + 0.87, 0.9) - 0.45);\n  float by = abs(w.y - 3.02);\n  float bars = smoothstep(0.03 - b, 0.03 + b, 0.45 - bx);\n  bars *= smoothstep(0.026 - b, 0.026 + b, by);\n  float t2 = (P.x + 1.05) / -SUN.x;\n  vec2 q = vec2(P.z + SUN.z * t2, P.y + SUN.y * t2);\n  float lit = open * bars;\n  if (lit < 0.004) return 0.0;\n  float lb = 0.0085 * t2;\n  return lit * mix(0.06, 1.0, smoothstep(-lb, lb, foliage(q)));\n}\nfloat sunVis(vec3 P, int skip) {\n  float v = gobo(P);\n  if (v < 0.004) return 0.0;\n  float t, sd; vec2 h;\n  for (int i = 0; i < NP; i++) {\n    if (i == skip) continue;\n    if (sheet(i, P, SUN, t, sd, h)) { float w = t * 0.021 + 0.0005; v *= smoothstep(-w, w, sd); }\n  }\n  return v;\n}\n// How much open sky a point still sees with the prints overhead: a wide, soft shadow that fades as a sheet rises.\nfloat skyVis(vec3 P, int skip) {\n  float v = 1.0; float t, sd; vec2 h;\n  for (int i = 0; i < NP; i++) {\n    if (i == skip) continue;\n    if (sheet(i, P, vec3(0.0, 1.0, 0.0), t, sd, h)) { float w = t * 0.85 + 0.0035; v *= 1.0 - (1.0 - smoothstep(-w, w, sd)) / (1.0 + 53.0 * t * t); }\n  }\n  return v;\n}\n\n// The room a glossy sheet mirrors: pale walls, the sunny window on the left and a second window on the far wall.\nvec3 env(vec3 ro, vec3 rd, float soft) {\n  vec3 c = mix(vec3(0.3, 0.27, 0.24), vec3(0.52, 0.49, 0.45), smoothstep(-0.2, 0.9, rd.y));\n  if (rd.z < -1e-3) {\n    vec3 p = ro + rd * ((-3.2 - ro.z) / rd.z);\n    float m = smoothstep(-1.5 - soft, -1.5 + soft, p.x) * smoothstep(1.7 + soft, 1.7 - soft, p.x) * smoothstep(0.45 - soft, 0.45 + soft, p.y) * smoothstep(4.6 + soft, 4.6 - soft, p.y);\n    float bar = mix(1.0, smoothstep(0.0, 0.05 + soft, 0.4 - abs(mod(p.x + 1.5, 0.8) - 0.4)), 0.85);\n    c = mix(c, vec3(0.74, 0.86, 1.0) * 3.4, m * bar);\n  }\n  if (rd.x < -1e-3) {\n    vec3 p = ro + rd * ((-1.5 - ro.x) / rd.x);\n    float m = smoothstep(-0.87 - soft, -0.87 + soft, p.z) * smoothstep(2.73 + soft, 2.73 - soft, p.z) * smoothstep(1.02 - soft, 1.02 + soft, p.y) * smoothstep(3.42 + soft, 3.42 - soft, p.y);\n    float bar = smoothstep(0.0, 0.04 + soft, 0.45 - abs(mod(p.z + 0.87, 0.9) - 0.45)) * smoothstep(0.02, 0.05 + soft, abs(p.y - 3.02));\n    c = mix(c, vec3(0.85, 0.92, 1.0) * 6.0, m * mix(1.0, bar, 0.9));\n  }\n  return c;\n}\n\n// exposed for paper in full sun: straight through the mid tones so the photographs keep their colour, with a soft shoulder\nvec3 tonemap(vec3 x) { x *= 0.58; vec3 q = x * x; q *= q; return x / pow(1.0 + q, vec3(0.25)); }\nvec4 pack(vec3 col, float depth) {\n  float coc = clamp(uAperture * (1.0 - uFocus / max(depth, 0.05)), -1.0, 1.0);\n  coc = sign(coc) * max(abs(coc) - 0.07, 0.0); // whatever is close to the focal plane stays fully sharp\n  return vec4(pow(tonemap(col), vec3(1.0 / 2.2)), 0.5 + 0.5 * coc);\n}\n`;\n\nconst VS_FULL = `#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_TABLE = `${GLSL_HEAD}\nin vec2 vUv;\nout vec4 o;\nconst vec3 HAZE = vec3(1.25, 1.12, 0.95);\nvoid main() {\n  vec2 ndc = vUv * 2.0 - 1.0;\n  vec3 rd = normalize(uFw + uRt * (ndc.x * uTan * uAspect) + uUp * (ndc.y * uTan));\n  if (rd.y > -1e-3) { o = pack(HAZE, 60.0); return; }\n  float t = -uCam.y / rd.y;\n  vec3 P = uCam + rd * t;\n  float far = smoothstep(0.8, 2.4, t);\n\n  // honed travertine, cut across the bed: cloudy masses of cream and tan, pale calcite veins, and filled pores gathered in the darker stone\n  vec2 p = P.xz;\n  float w1 = fbm(p * 1.7 + 3.0), w2 = fbm(p * 1.7 + 11.0);\n  vec2 wq = p + 0.3 * vec2(w1, w2);\n  float cloud = fbm(wq * 3.4);\n  float mott = fbm(wq * 10.0 + 5.0);\n  float tone = smoothstep(0.3, 0.72, cloud * 0.62 + mott * 0.38);\n  vec3 alb = mix(vec3(0.81, 0.725, 0.595), vec3(0.62, 0.51, 0.375), tone);\n  float vein = abs(fract(dot(p, vec2(0.62, 0.9)) * 1.1 + w1 * 1.3 + mott * 0.12) - 0.5);\n  alb = mix(alb, vec3(0.87, 0.81, 0.71), (1.0 - smoothstep(0.0, 0.014, vein)) * 0.4 * smoothstep(0.3, 0.6, w2));\n  vec2 g = wq * vec2(80.0, 110.0);\n  vec2 id = floor(g), f = fract(g) - 0.5;\n  float cluster = smoothstep(0.42, 0.7, vnoise(wq * 9.0 + 30.0)) * (0.4 + 0.6 * tone);\n  float r = step(1.0 - 0.6 * cluster, hash(id)) * (0.16 + 0.3 * hash(id + 7.7));\n  vec2 jf = f + (vec2(hash(id + 1.3), hash(id + 2.9)) - 0.5) * 0.5;\n  float pit = (1.0 - smoothstep(r - 0.14, r, length(jf))) * step(0.001, r) * (1.0 - far);\n  alb = mix(alb, alb * vec3(0.8, 0.8, 0.83), pit * 0.8);\n  alb *= 1.0 + (vnoise(p * 420.0) - 0.5) * 0.06 * (1.0 - far);\n\n  // sun on the stone. Paper is not opaque, so each sheet also lets a little light through, tinted by what is printed on it\n  float sv = gobo(P);\n  vec3 through = vec3(0.0);\n  if (sv > 0.004) {\n    float lit = sv, ts, sd; vec2 h;\n    for (int i = 0; i < NP; i++) {\n      if (!sheet(i, P, SUN, ts, sd, h)) continue;\n      float w = ts * 0.021 + 0.0005;\n      float cover = 1.0 - smoothstep(-w, w, sd);\n      if (cover > 0.0) through += pow(textureLod(uTex, vec3(clamp(h / HS * 0.5 + 0.5, 0.02, 0.98), float(i)), 3.0 + 40.0 * ts).rgb, vec3(1.5)) * cover * lit * 0.11;\n      sv *= 1.0 - cover;\n    }\n  }\n  float kv = skyVis(P, -1);\n  vec3 col = alb * (SUNC * SUN.y * (sv + through) + SKYC * kv + FILL);\n  // the faint sheen of honed stone, strongest where the view skims the surface\n  vec3 R = reflect(rd, vec3(0.0, 1.0, 0.0));\n  float F = 0.04 + 0.96 * pow(1.0 - max(-rd.y, 0.0), 5.0);\n  col += env(P, R, 0.45) * F * 0.8 * kv * (1.0 - 0.7 * pit);\n  col = mix(col, HAZE, smoothstep(1.5, 3.4, t) * 0.75);\n  o = pack(col, dot(rd, uFw) * t);\n}`;\n\nconst VS_PRINT = `#version 300 es\nprecision highp float;\nlayout(location = 0) in vec2 aUv;\nuniform vec3 uC, uU, uV, uCam, uRt, uUp, uFw;\nuniform vec2 uK;\nuniform float uTan, uAspect, uOff;\nout vec3 vW; out vec2 vL;\nvoid main() {\n  vec2 l = aUv * vec2(${HX}, ${HY});\n  vW = uC + uU * l.x + uV * l.y + cross(uU, uV) * (uK.x * l.x * l.x + uK.y * l.x * l.y - uOff);\n  vL = l;\n  vec3 d = vW - uCam;\n  float z = dot(d, uFw);\n  gl_Position = vec4(dot(d, uRt) / (uTan * uAspect), dot(d, uUp) / uTan, (z * 20.04 - 1.6) / 19.96, z);\n}`;\n\nconst FS_PRINT = `${GLSL_HEAD}\nuniform vec3 uC, uU, uV;\nuniform vec2 uK;\nuniform int uIdx;\nuniform float uOff;\nconst vec3 PLATE = vec3(${(HX * (1 - (2 * PAD) / TEX_W) + 0.004).toFixed(5)}, ${(HY * (1 - (PAD + FOOT) / TEX_H) + 0.004).toFixed(5)}, ${((HY * (FOOT - PAD)) / TEX_H).toFixed(5)});\nin vec3 vW; in vec2 vL;\nout vec4 o;\nvoid main() {\n  vec3 pn = cross(uU, uV);\n  vec3 N = normalize(pn - uU * (2.0 * uK.x * vL.x + uK.y * vL.y) - uV * (uK.y * vL.x));\n  vec3 V = normalize(uCam - vW);\n  bool back = dot(N, V) < 0.0;\n  // the plate mark: the picture sits in a shallow pressed rectangle whose bevel catches the sun on one side and loses it on the other\n  vec2 pq = abs(vL - vec2(0.0, PLATE.z)) - PLATE.xy;\n  float pd = length(max(pq, 0.0)) + min(max(pq.x, pq.y), 0.0);\n  vec2 pg = pq.x > pq.y ? vec2(sign(vL.x), 0.0) : vec2(0.0, sign(vL.y - PLATE.z));\n  float bevel = smoothstep(-0.0001, 0.0002, pd) * (1.0 - smoothstep(0.0007, 0.001, pd));\n  if (!back) N = normalize(N - (uU * pg.x + uV * pg.y) * bevel * 0.42);\n  float sv = sunVis(vW, uIdx);\n  float kv = skyVis(vW, uIdx);\n  float nl = dot(N, SUN);\n  vec2 uv = vL / HS * 0.5 + 0.5;\n  vec3 col;\n  if (uOff > 0.0) {\n    // the sheet's thickness: a second copy just behind the face, showing as a sliver of raw paper core along the edges turned to the camera\n    col = vec3(0.8, 0.765, 0.7) * (SUNC * 0.4 * sv + SKYC * kv * 0.7 + FILL);\n  } else if (!back) {\n    vec3 alb = texture(uTex, vec3(uv, float(uIdx))).rgb;\n    // baryta paper: a tooth you only notice in the margins\n    alb *= 0.985 + 0.03 * vnoise(vL * 900.0);\n    col = alb * (SUNC * max(nl, 0.0) * sv + SKYC * kv * (0.55 + 0.45 * N.y) + FILL * (1.2 - 0.6 * N.y));\n    // satin coat: a soft picture of the room, and a broad sheen where the sheet leans toward the sun\n    float F = 0.04 + 0.96 * pow(1.0 - max(dot(N, V), 0.0), 5.0);\n    col += env(vW, reflect(-V, N), 0.3) * F * 0.6;\n    col += SUNC * pow(max(dot(N, normalize(SUN + V)), 0.0), 60.0) * 0.28 * sv * step(0.0, nl);\n    // the cut edge of the sheet\n    float e = min(HS.x - abs(vL.x), HS.y - abs(vL.y));\n    col *= 1.0 - 0.12 * smoothstep(0.0009, 0.0, e);\n  } else {\n    N = -N;\n    vec3 paper = vec3(0.86, 0.835, 0.78) * (0.97 + 0.06 * vnoise(vL * 500.0));\n    // the back of a print lit from the front glows a little with what is printed on it\n    vec3 through = texture(uTex, vec3(uv, float(uIdx)), 3.0).rgb;\n    col = paper * (SUNC * max(dot(N, SUN), 0.0) * sv + SKYC * kv * (0.55 + 0.45 * N.y) + vec3(0.42, 0.36, 0.28) * (0.5 - 0.5 * N.y))\n        + paper * through * SUNC * max(nl, 0.0) * sv * 0.2;\n  }\n  o = pack(col, dot(vW - uCam, uFw));\n}`;\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 coc0 = abs(c0.a * 2.0 - 1.0);\n  vec3 lin0 = pow(c0.rgb, vec3(2.2));\n  vec3 acc = lin0; float wsum = 1.0; float spread = coc0;\n  float rot = 6.2832 * ign(gl_FragCoord.xy);\n  // 40 taps over the whole blur disc, then 14 more packed into the middle so slightly soft edges stay clean\n  for (int k = 1; k < 54; k++) {\n    float r = k < 40 ? sqrt(float(k) / 40.0) * uMaxR : sqrt(float(k - 39) / 14.0) * min(uMaxR, 3.2);\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 > c0.a * 2.0 - 1.0) 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);\n    acc += lin * w; wsum += w; spread = max(spread, cs * step(0.5, w));\n  }\n  o = vec4(pow(acc / wsum, vec3(1.0 / 2.2)), spread);\n}`;\n\nconst FS_PRINTOUT = `#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)))); }\nvoid main() {\n  // tidy the blur where the lens pass was sparse, let the brightest stone bloom a little, then vignette and grain\n  vec4 c = texture(uScene, vUv);\n  float r = clamp(c.a * 4.0, 0.0, 1.0) * 1.5;\n  vec3 col = c.rgb * 4.0;\n  for (int k = 0; k < 8; k++) {\n    float a = float(k) * 0.7854;\n    col += texture(uScene, vUv + vec2(cos(a), sin(a)) * r * (k % 2 == 0 ? 1.0 : 1.9) * uPx).rgb;\n  }\n  col /= 12.0;\n  vec3 glow = textureLod(uScene, vUv, 5.5).rgb * 0.5 + textureLod(uScene, vUv, 7.0).rgb * 0.5;\n  col += pow(glow, vec3(3.0)) * 0.05;\n  // a veil of warm flare from the window side, a gentle grade, then vignette and grain\n  col += vec3(1.0, 0.82, 0.58) * 0.07 * smoothstep(1.25, 0.0, length(vUv - vec2(0.0, 1.0)));\n  float lum = dot(col, vec3(0.3, 0.59, 0.11));\n  col = mix(vec3(lum), col, 1.07);\n  vec2 q = vUv - 0.5;\n  col *= 1.0 - 0.42 * dot(q, q);\n  col += (ign(gl_FragCoord.xy + fract(uTime) * 61.0) - 0.5) * 0.022;\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/** A sheet as a fine grid, so the vertex shader can bend it. */\nconst SEG = 24;\nfunction sheetMesh() {\n  const out: number[] = [];\n  for (let i = 0; i < SEG; i++) {\n    for (let j = 0; j < 4; j++) {\n      const x0 = (i / SEG) * 2 - 1, x1 = ((i + 1) / SEG) * 2 - 1, y0 = (j / 4) * 2 - 1, y1 = ((j + 1) / 4) * 2 - 1;\n      out.push(x0, y0, x1, y0, x1, y1, x0, y0, x1, y1, x0, y1);\n    }\n  }\n  return new Float32Array(out);\n}\n\n/** Lay out one sheet: paper, the photograph cropped around its focus point, and a printed caption in the wide bottom margin. */\nfunction paintSheet(ctx: CanvasRenderingContext2D, i: number, img: HTMLImageElement | null) {\n  const p = plates[i];\n  ctx.fillStyle = \"#f4f1e9\";\n  ctx.fillRect(0, 0, TEX_W, TEX_H);\n  const iw = TEX_W - PAD * 2, ih = TEX_H - PAD - FOOT;\n  if (img) {\n    const s = Math.max(iw / img.naturalWidth, ih / img.naturalHeight);\n    const sw = iw / s, sh = ih / s;\n    ctx.drawImage(img, clamp(p.focus[0] * img.naturalWidth - sw / 2, 0, img.naturalWidth - sw), clamp(p.focus[1] * img.naturalHeight - sh / 2, 0, img.naturalHeight - sh), sw, sh, PAD, PAD, iw, ih);\n  } else {\n    const g = ctx.createLinearGradient(0, PAD, 0, PAD + ih);\n    g.addColorStop(0, \"#3f7fd0\");\n    g.addColorStop(1, p.tone);\n    ctx.fillStyle = g;\n    ctx.fillRect(PAD, PAD, iw, ih);\n  }\n  const base = TEX_H - FOOT / 2 + 8;\n  ctx.fillStyle = \"#24211d\";\n  ctx.textBaseline = \"alphabetic\";\n  (ctx as unknown as { letterSpacing: string }).letterSpacing = \"3.4px\";\n  ctx.font = `600 15px ${GROTESK}`;\n  ctx.textAlign = \"left\";\n  ctx.fillText(p.title.toUpperCase(), PAD, base);\n  ctx.textAlign = \"right\";\n  ctx.fillText(`${String(i + 1).padStart(2, \"0\")} / ${String(N).padStart(2, \"0\")}`, TEX_W - PAD, base);\n  (ctx as unknown as { letterSpacing: string }).letterSpacing = \"-1px\";\n  ctx.font = `italic 34px ${SERIF}`;\n  ctx.textAlign = \"center\";\n  ctx.fillText(MASTHEAD, TEX_W / 2, base + 4);\n}\n\ntype V3 = [number, number, number];\nconst add = (a: V3, b: V3, k = 1): V3 => [a[0] + b[0] * k, a[1] + b[1] * k, a[2] + b[2] * k];\nconst dot = (a: V3, b: V3) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\nconst cross = (a: V3, b: V3): V3 => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];\nconst norm = (a: V3): V3 => {\n  const l = Math.hypot(a[0], a[1], a[2]) || 1;\n  return [a[0] / l, a[1] / l, a[2] / l];\n};\nconst mix3 = (a: V3, b: V3, t: number): V3 => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];\nconst smooth = (t: number) => {\n  const x = clamp(t, 0, 1);\n  return x * x * (3 - 2 * x);\n};\n\ntype Sim = {\n  active: number;\n  lift: Float32Array; liftV: Float32Array; flex: Float32Array; flexV: Float32Array; hov: Float32Array; wait: Float32Array;\n  puffs: { at: number; j: number; imp: number }[];\n  hover: number; inside: boolean; px: number; py: number; cx: number; cy: number; downX: number; downY: number;\n  focus: number; paused: boolean; nextAuto: number; dirty: boolean;\n  pick: (x: number, y: number) => number;\n};\n\nexport default function SunlitPrintTableGallery() {\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 sim = useRef<Sim>({\n    active: 0,\n    lift: Float32Array.from({ length: N }, (_, i) => (i === 0 ? 1 : 0)), liftV: new Float32Array(N), flex: new Float32Array(N), flexV: new Float32Array(N), hov: new Float32Array(N), wait: new Float32Array(N),\n    puffs: [], hover: -1, inside: false, px: 0, py: 0, cx: 0, cy: 0, downX: 0, downY: 0,\n    focus: 0.6, paused: false, nextAuto: 0, dirty: true,\n    pick: () => -1,\n  });\n\n  /** Put the lifted print down and pick another one up. */\n  const choose = useCallback((next: number) => {\n    const s = sim.current;\n    const to = mod(next, N);\n    if (to === s.active) return;\n    s.liftV[s.active] += 0.9; // a small toss before it drops\n    s.wait[to] = 0.2; // one edge peels off the stone before the sheet leaves it\n    s.active = to;\n    s.nextAuto = performance.now() + HOLD_MS * 1.6;\n    s.dirty = true;\n    setActive(to);\n  }, []);\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 progTable: WebGLProgram, progPrint: WebGLProgram, progLens: WebGLProgram, progOut: WebGLProgram;\n    try {\n      progTable = program(gl, VS_FULL, FS_TABLE);\n      progPrint = program(gl, VS_PRINT, FS_PRINT);\n      progLens = program(gl, VS_FULL, FS_LENS);\n      progOut = program(gl, VS_FULL, FS_PRINTOUT);\n    } catch {\n      setMode(\"still\");\n      return;\n    }\n    setMode(\"gl\");\n\n    // the sheets, one layer each of an sRGB array texture so the light maths is linear\n    const tex = gl.createTexture();\n    gl.activeTexture(gl.TEXTURE0);\n    gl.bindTexture(gl.TEXTURE_2D_ARRAY, tex);\n    gl.texStorage3D(gl.TEXTURE_2D_ARRAY, Math.floor(Math.log2(TEX_H)) + 1, gl.SRGB8_ALPHA8, TEX_W, TEX_H, N);\n    gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);\n    gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n    gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n    const aniso = gl.getExtension(\"EXT_texture_filter_anisotropic\");\n    if (aniso) gl.texParameterf(gl.TEXTURE_2D_ARRAY, aniso.TEXTURE_MAX_ANISOTROPY_EXT, 8);\n    const scratch = document.createElement(\"canvas\");\n    scratch.width = TEX_W;\n    scratch.height = TEX_H;\n    const sctx = scratch.getContext(\"2d\")!;\n    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);\n    const upload = (layer: number) => {\n      gl.activeTexture(gl.TEXTURE0);\n      gl.bindTexture(gl.TEXTURE_2D_ARRAY, tex);\n      gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, layer, TEX_W, TEX_H, 1, gl.RGBA, gl.UNSIGNED_BYTE, scratch);\n      gl.generateMipmap(gl.TEXTURE_2D_ARRAY);\n      s.dirty = true;\n    };\n    let alive = true;\n    plates.forEach((p, i) => {\n      paintSheet(sctx, i, null);\n      upload(i);\n      const img = new Image();\n      img.crossOrigin = \"anonymous\";\n      img.onload = () => {\n        if (!alive) return;\n        paintSheet(sctx, i, img);\n        upload(i);\n      };\n      img.src = p.src;\n    });\n\n    const vao = gl.createVertexArray();\n    gl.bindVertexArray(vao);\n    gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());\n    gl.bufferData(gl.ARRAY_BUFFER, sheetMesh(), gl.STATIC_DRAW);\n    gl.enableVertexAttribArray(0);\n    gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 8, 0);\n    gl.bindVertexArray(null);\n    const emptyVao = gl.createVertexArray();\n\n    // multisampled scene target, resolved into a texture the lens pass reads (colour + blur size in alpha)\n    const msFbo = gl.createFramebuffer();\n    const msColor = gl.createRenderbuffer();\n    const msDepth = gl.createRenderbuffer();\n    const resFbo = gl.createFramebuffer();\n    const resTex = gl.createTexture();\n    const lensFbo = gl.createFramebuffer();\n    const lensTex = gl.createTexture();\n    let W = 0, H = 0, scale = Math.min(window.devicePixelRatio || 1, 1.5);\n    const samples = Math.min(4, gl.getParameter(gl.MAX_SAMPLES));\n    const resize = () => {\n      const cw = wrap.clientWidth, ch = wrap.clientHeight;\n      let k = scale;\n      if (cw * ch * k * k > 1.5e6) k = Math.sqrt(1.5e6 / (cw * ch));\n      const w = Math.max(2, Math.round(cw * k)), h = Math.max(2, Math.round(ch * k));\n      if (w === W && h === H) return;\n      W = w;\n      H = h;\n      canvas.width = W;\n      canvas.height = H;\n      gl.bindRenderbuffer(gl.RENDERBUFFER, msColor);\n      gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples, gl.RGBA8, W, H);\n      gl.bindRenderbuffer(gl.RENDERBUFFER, msDepth);\n      gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples, gl.DEPTH_COMPONENT24, W, H);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, msFbo);\n      gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, msColor);\n      gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, msDepth);\n      for (const [unit, t, f, mip] of [[gl.TEXTURE2, resTex, resFbo, false], [gl.TEXTURE3, lensTex, lensFbo, true]] as const) {\n        gl.activeTexture(unit);\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, mip ? gl.LINEAR_MIPMAP_LINEAR : 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, f);\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 pc = new Float32Array(21), pu = new Float32Array(21), pv = new Float32Array(21), pk = new Float32Array(14);\n    const TAN = Math.tan((19.5 * Math.PI) / 180);\n    const view = { cam: [0, 0.66, 0.62] as V3, rt: [1, 0, 0] as V3, up: [0, 1, 0] as V3, fw: [0, 0, -1] as V3, tan: TAN, aspect: 1.6 };\n\n    /** Camera and every sheet's pose for this instant. */\n    const pose = (t: number) => {\n      const aspect = W / H;\n      const tan = TAN * (aspect < 1.15 ? Math.pow(1.15 / aspect, 0.55) : 1);\n      const frame = (cam: V3) => {\n        const fw = norm([0 - cam[0], 0.07 - cam[1], 0 - cam[2]]);\n        const rt = norm([-fw[2], 0, fw[0]]);\n        return { fw, rt, up: cross(rt, fw) };\n      };\n      // the lifted print is placed against a steady camera, so the real one can drift and lean around it\n      const cam0: V3 = [0, 0.66, 0.62];\n      const f0 = frame(cam0);\n      const drift = reduce ? 0 : 1;\n      const cam: V3 = [s.cx * 0.07 + drift * 0.012 * Math.sin(t * 0.33), 0.66 - s.cy * 0.03 + drift * 0.006 * Math.sin(t * 0.27 + 1), 0.62];\n      const f = frame(cam);\n      view.cam = cam;\n      view.fw = f.fw;\n      view.rt = f.rt;\n      view.up = f.up;\n      view.tan = tan;\n      view.aspect = aspect;\n      const d = Math.max((0.56 * TAN) / tan, HX / (0.64 * tan * aspect));\n      const narrow = clamp((aspect - 0.6) / 0.9, 0, 1);\n      const bob = drift * Math.sin(t * 0.9);\n      const heroC = add(add(add(cam0, f0.fw, d), f0.rt, 0.04 * narrow * d / 0.56), f0.up, 0.014 + 0.004 * bob);\n      let heroN = norm(add(add(add([-f0.fw[0], -f0.fw[1], -f0.fw[2]], [0, 1, 0], 0.5), f0.rt, -0.12 + s.cx * 0.2 + drift * 0.03 * Math.sin(t * 0.5)), f0.up, -s.cy * 0.2));\n      const heroV0 = norm(add([0, 1, 0], heroN, -heroN[1]));\n      const heroU0 = cross(heroV0, heroN);\n      const roll = -0.035 + drift * 0.012 * Math.sin(t * 0.41 + 2);\n      const heroU = norm(add(add([0, 0, 0], heroU0, Math.cos(roll)), heroV0, Math.sin(roll)));\n      const heroV = cross(heroN, heroU);\n      heroN = cross(heroU, heroV);\n      let best = 0, bestLift = -1;\n      for (let i = 0; i < N; i++) {\n        const [sx, sz, yaw, curl, twist] = slots[i];\n        const l = s.lift[i];\n        const x = sx * (0.42 + 0.58 * narrow), z = sz;\n        const ey = l < 1 ? 1 - (1 - l) * (1 - l) : 1 + (l - 1) * 0.5;\n        const exz = smooth(l) + Math.max(0, l - 1) * 0.4;\n        const er = smooth((l - 0.04) / 0.86);\n        const u0: V3 = [Math.cos(yaw), 0, -Math.sin(yaw)];\n        const v0: V3 = [-Math.sin(yaw), 0, -Math.cos(yaw)];\n        let u = norm(mix3(u0, heroU, er));\n        // mid flight the sheet rolls a little, as if lifted by one edge\n        const tw = 0.3 * Math.sin(Math.PI * clamp(l, 0, 1)) * (i % 2 ? 1 : -1) * (1 - er * 0.4) + s.hov[i] * 0.05;\n        let v = mix3(v0, heroV, er);\n        v = norm(add(v, u, -dot(u, v)));\n        const n0 = cross(u, v);\n        u = norm(add(add([0, 0, 0], u, Math.cos(tw)), n0, -Math.sin(tw)));\n        const hop = s.hov[i] * 0.014 * (1 - clamp(l, 0, 1));\n        const c: V3 = [x + (heroC[0] - x) * exz, 0.0018 + hop + (heroC[1] - 0.0018) * ey, z + (heroC[2] - z) * exz];\n        pc.set(c, i * 3);\n        pu.set(u, i * 3);\n        pv.set(v, i * 3);\n        const lc = clamp(l, 0, 1);\n        pk[i * 2] = clamp(curl * (1 - lc) + K_HERO * lc + s.flex[i] + s.hov[i] * 0.9 * (1 - lc), -0.25, 3.4);\n        pk[i * 2 + 1] = twist * (1 - lc) + s.flex[i] * 0.25;\n        if (l > bestLift) {\n          bestLift = l;\n          best = i;\n        }\n      }\n      const heroDepth = dot(add([pc[best * 3], pc[best * 3 + 1], pc[best * 3 + 2]], cam, -1), f.fw);\n      const want = 0.95 + (heroDepth - 0.95) * smooth(bestLift * 1.15);\n      s.focus = reduce ? want : s.focus + (want - s.focus) * 0.14;\n    };\n\n    /** Which print lies under a point of the stage, or -1. */\n    s.pick = (mx: number, my: number) => {\n      const rd = norm(add(add(view.fw, view.rt, mx * view.tan * view.aspect), view.up, -my * view.tan));\n      let hit = -1, near = 1e9;\n      for (let i = 0; i < N; i++) {\n        const c: V3 = [pc[i * 3], pc[i * 3 + 1], pc[i * 3 + 2]];\n        const u: V3 = [pu[i * 3], pu[i * 3 + 1], pu[i * 3 + 2]];\n        const v: V3 = [pv[i * 3], pv[i * 3 + 1], pv[i * 3 + 2]];\n        const n = cross(u, v);\n        const dn = dot(rd, n);\n        if (Math.abs(dn) < 1e-5) continue;\n        const t = dot(add(c, view.cam, -1), n) / dn;\n        if (t <= 0 || t > near) continue;\n        const p = add(add(view.cam, rd, t), c, -1);\n        if (Math.abs(dot(p, u)) < HX && Math.abs(dot(p, v)) < HY) {\n          near = t;\n          hit = i;\n        }\n      }\n      return hit;\n    };\n\n    const lf = new Float32Array(96), lg = new Float32Array(48), st = new Float32Array(24), bb = new Float32Array(9);\n    /** Pose every leaf for this instant: the branches sway from their base and each leaf flutters at its own pace. */\n    const foliage = (t: number) => {\n      branches.forEach(([bx, by, ang0, len, bend, seed], b) => {\n        const ang = ang0 + (b === 1 ? 1.3 : b === 2 ? 0.8 : 1) * (0.05 * Math.sin(t * 0.62) + 0.02 * Math.sin(t * 1.31 + 1));\n        let px = bx, py = by;\n        for (let j = 1; j <= 8; j++) {\n          const k = (b * 8 + j - 1) * 4;\n          if (j < 8) {\n            const q = j / 7;\n            const ax = bx + Math.cos(ang + bend * q * 0.5) * len * q, ay = by + Math.sin(ang + bend * q * 0.5) * len * q;\n            const la = ang + bend * q + (j % 2 ? 1 : -1) * (0.75 + 0.2 * rnd(j, seed)) + 0.12 * Math.sin(t * (1.1 + 0.23 * j) + seed + j * 1.7);\n            lf.set([ax, ay, Math.cos(la), Math.sin(la)], k);\n            lg.set([0.13 + 0.05 * rnd(seed, j), 0.027], k / 2);\n            if (j === 4) st.set([bx, by, ax, ay], b * 8);\n            if (j === 7) st.set([st[b * 8 + 2], st[b * 8 + 3], ax, ay], b * 8 + 4);\n            px = ax;\n            py = ay;\n          } else {\n            lf.set([px, py, Math.cos(ang + bend), Math.sin(ang + bend)], k);\n            lg.set([0.15, 0.026], k / 2);\n          }\n        }\n        bb.set([(bx + px) / 2, (by + py) / 2, Math.hypot(px - bx, py - by) / 2 + 0.24], b * 3);\n      });\n    };\n\n    const shared = (p: WebGLProgram) => {\n      gl.useProgram(p);\n      gl.uniform4fv(U(p, \"uLf\"), lf);\n      gl.uniform2fv(U(p, \"uLg\"), lg);\n      gl.uniform4fv(U(p, \"uSt\"), st);\n      gl.uniform3fv(U(p, \"uBb\"), bb);\n      gl.uniform3fv(U(p, \"uPc\"), pc);\n      gl.uniform3fv(U(p, \"uPu\"), pu);\n      gl.uniform3fv(U(p, \"uPv\"), pv);\n      gl.uniform2fv(U(p, \"uPk\"), pk);\n      gl.uniform1i(U(p, \"uTex\"), 0);\n      gl.uniform3fv(U(p, \"uCam\"), view.cam);\n      gl.uniform3fv(U(p, \"uRt\"), view.rt);\n      gl.uniform3fv(U(p, \"uUp\"), view.up);\n      gl.uniform3fv(U(p, \"uFw\"), view.fw);\n      gl.uniform1f(U(p, \"uTan\"), view.tan);\n      gl.uniform1f(U(p, \"uAspect\"), view.aspect);\n      gl.uniform1f(U(p, \"uFocus\"), s.focus);\n      gl.uniform1f(U(p, \"uAperture\"), 0.72);\n    };\n\n    const draw = (t: number) => {\n      pose(t);\n      foliage(reduce ? 0 : t);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, msFbo);\n      gl.viewport(0, 0, W, H);\n      gl.disable(gl.DEPTH_TEST);\n      gl.disable(gl.CULL_FACE);\n      gl.depthMask(false);\n      shared(progTable);\n      gl.bindVertexArray(emptyVao);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n      gl.enable(gl.DEPTH_TEST);\n      gl.depthMask(true);\n      gl.clear(gl.DEPTH_BUFFER_BIT);\n      shared(progPrint);\n      gl.bindVertexArray(vao);\n      for (let i = 0; i < N; i++) {\n        gl.uniform3f(U(progPrint, \"uC\"), pc[i * 3], pc[i * 3 + 1], pc[i * 3 + 2]);\n        gl.uniform3f(U(progPrint, \"uU\"), pu[i * 3], pu[i * 3 + 1], pu[i * 3 + 2]);\n        gl.uniform3f(U(progPrint, \"uV\"), pv[i * 3], pv[i * 3 + 1], pv[i * 3 + 2]);\n        gl.uniform2f(U(progPrint, \"uK\"), pk[i * 2], pk[i * 2 + 1]);\n        gl.uniform1i(U(progPrint, \"uIdx\"), i);\n        gl.uniform1f(U(progPrint, \"uOff\"), 0);\n        gl.drawArrays(gl.TRIANGLES, 0, SEG * 24);\n        gl.uniform1f(U(progPrint, \"uOff\"), 0.0011);\n        gl.drawArrays(gl.TRIANGLES, 0, SEG * 24);\n      }\n      gl.bindFramebuffer(gl.READ_FRAMEBUFFER, msFbo);\n      gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, resFbo);\n      gl.blitFramebuffer(0, 0, W, H, 0, 0, W, H, gl.COLOR_BUFFER_BIT, gl.NEAREST);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, lensFbo);\n      gl.disable(gl.DEPTH_TEST);\n      gl.useProgram(progLens);\n      gl.uniform1i(U(progLens, \"uScene\"), 2);\n      gl.uniform2f(U(progLens, \"uPx\"), 1 / W, 1 / H);\n      gl.uniform1f(U(progLens, \"uMaxR\"), H * 0.012);\n      gl.bindVertexArray(emptyVao);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n      gl.activeTexture(gl.TEXTURE3);\n      gl.bindTexture(gl.TEXTURE_2D, lensTex);\n      gl.generateMipmap(gl.TEXTURE_2D);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n      gl.useProgram(progOut);\n      gl.uniform1i(U(progOut, \"uScene\"), 3);\n      gl.uniform2f(U(progOut, \"uPx\"), 1 / W, 1 / H);\n      gl.uniform1f(U(progOut, \"uTime\"), reduce ? 0 : t);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n    };\n\n    /** One small step: the chosen sheet springs up, the others fall, land, and send a puff of air to their neighbours. */\n    const physics = (dt: number, now: number) => {\n      for (let i = 0; i < N; i++) {\n        let a = 0;\n        if (i === s.active && s.wait[i] > 0) {\n          s.wait[i] -= dt;\n        } else if (i === s.active) {\n          a = LIFT_SPRING * (1 - s.lift[i]) - LIFT_DAMPING * s.liftV[i];\n          s.liftV[i] += a * dt;\n          s.lift[i] += s.liftV[i] * dt;\n        } else if (s.lift[i] > 0 || s.liftV[i] > 0) {\n          a = -DROP_GRAVITY - 1.1 * s.liftV[i];\n          s.liftV[i] += a * dt;\n          s.lift[i] += s.liftV[i] * dt;\n          if (s.lift[i] <= 0) {\n            const hit = -s.liftV[i];\n            s.lift[i] = 0;\n            s.liftV[i] = hit > 1.6 ? hit * 0.15 : 0;\n            a = 0;\n            if (hit > 0.6) {\n              s.flexV[i] -= hit * 5.5; // the sheet slaps flat, then springs back into its curl\n              for (let j = 0; j < N; j++) {\n                if (j === i || j === s.active) continue;\n                const dist = Math.hypot(slots[i][0] - slots[j][0], slots[i][1] - slots[j][1]);\n                s.puffs.push({ at: now + (dist / 1.5) * 1000, j, imp: hit * 9 * Math.exp(-dist / 0.34) });\n              }\n            }\n          }\n        }\n        // the paper's own flutter, shaken by how hard the sheet is being moved\n        const fa = -420 * s.flex[i] - 6 * s.flexV[i] - a * 1.5;\n        s.flexV[i] += fa * dt;\n        s.flex[i] += s.flexV[i] * dt;\n        const hv = (s.hover === i && i !== s.active) || s.wait[i] > 0 ? 1 : 0;\n        s.hov[i] += (hv - s.hov[i]) * Math.min(1, dt * 9);\n      }\n      for (let k = s.puffs.length - 1; k >= 0; k--) {\n        const p = s.puffs[k];\n        if (now < p.at) continue;\n        s.flexV[p.j] += p.imp;\n        if (s.lift[p.j] <= 0) s.liftV[p.j] += p.imp * 0.045;\n        s.puffs.splice(k, 1);\n      }\n    };\n\n    let raf = 0, visible = true, last = performance.now(), slow = 0, frames = 0;\n    s.nextAuto = last + HOLD_MS + 600;\n    const tick = (now: number) => {\n      const real = now - last;\n      const dt = Math.min(0.05, real / 1000);\n      last = now;\n      if (reduce) {\n        for (let i = 0; i < N; i++) {\n          const to = i === s.active ? 1 : 0;\n          if (s.lift[i] !== to) s.dirty = true;\n          s.lift[i] = to;\n          s.liftV[i] = 0;\n          s.flex[i] = 0;\n          s.flexV[i] = 0;\n        }\n      } else {\n        const sub = Math.max(1, Math.ceil(dt / 0.004));\n        for (let i = 0; i < sub; i++) physics(dt / sub, now);\n        s.cx += (s.px - s.cx) * Math.min(1, dt * 3.2);\n        s.cy += (s.py - s.cy) * Math.min(1, dt * 3.2);\n        if (s.paused || s.inside) s.nextAuto = Math.max(s.nextAuto, now + 1800); // never change print under someone's pointer\n        if (!document.hidden && now > s.nextAuto) {\n          choose(s.active + 1);\n          s.nextAuto = now + HOLD_MS;\n        }\n      }\n      if (!reduce || s.dirty) {\n        draw(now / 1000);\n        s.dirty = false;\n        // measure, do not guess: if the machine cannot hold the frame rate, render fewer pixels\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.85;\n            slow = 0;\n            frames = 0;\n            resize();\n          }\n        }\n      }\n      if (visible) raf = requestAnimationFrame(tick);\n    };\n    const io = new IntersectionObserver(([e]) => {\n      const was = visible;\n      visible = e.isIntersecting;\n      if (visible && !was) {\n        last = performance.now();\n        frames = 0;\n        raf = requestAnimationFrame(tick);\n      }\n    });\n    io.observe(wrap);\n    raf = requestAnimationFrame(tick);\n\n    const at = (e: PointerEvent) => {\n      const r = wrap.getBoundingClientRect();\n      return [clamp(((e.clientX - r.left) / r.width) * 2 - 1, -1, 1), clamp(((e.clientY - r.top) / r.height) * 2 - 1, -1, 1)];\n    };\n    const move = (e: PointerEvent) => {\n      const [x, y] = at(e);\n      if (e.pointerType === \"mouse\") {\n        s.px = x;\n        s.py = y;\n      }\n      const h = s.pick(x, y);\n      s.hover = h === s.active ? -1 : h;\n      s.inside = e.pointerType === \"mouse\";\n      canvas.style.cursor = \"pointer\";\n      s.dirty = true;\n    };\n    const down = (e: PointerEvent) => {\n      s.downX = e.clientX;\n      s.downY = e.clientY;\n    };\n    const up = (e: PointerEvent) => {\n      if (Math.hypot(e.clientX - s.downX, e.clientY - s.downY) > 10) return;\n      const [x, y] = at(e);\n      const h = s.pick(x, y);\n      choose(h < 0 || h === s.active ? s.active + 1 : h);\n      s.hover = -1;\n    };\n    const leave = () => {\n      s.px = 0;\n      s.py = 0;\n      s.hover = -1;\n      s.inside = false;\n    };\n    wrap.addEventListener(\"pointermove\", move);\n    canvas.addEventListener(\"pointerdown\", down);\n    canvas.addEventListener(\"pointerup\", up);\n    wrap.addEventListener(\"pointerleave\", leave);\n\n    return () => {\n      alive = false;\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      wrap.removeEventListener(\"pointermove\", move);\n      canvas.removeEventListener(\"pointerdown\", down);\n      canvas.removeEventListener(\"pointerup\", up);\n      wrap.removeEventListener(\"pointerleave\", leave);\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    };\n  }, [reduce, choose]);\n\n  // without WebGL the plain version still changes print by itself\n  useEffect(() => {\n    if (mode !== \"still\" || reduce) return;\n    const id = window.setInterval(() => {\n      if (!sim.current.paused && !document.hidden) choose(sim.current.active + 1);\n    }, HOLD_MS);\n    return () => window.clearInterval(id);\n  }, [mode, reduce, choose]);\n\n  const onKey = (e: React.KeyboardEvent) => {\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") {\n      e.preventDefault();\n      choose(sim.current.active + 1);\n    } else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      choose(sim.current.active - 1);\n    }\n  };\n  const pause = (v: boolean) => () => {\n    sim.current.paused = v;\n    if (!v) sim.current.nextAuto = performance.now() + HOLD_MS;\n  };\n  const btn = \"grid h-11 w-11 place-items-center rounded-full border border-stone-900/25 bg-white/40 text-stone-900 backdrop-blur-sm transition hover:bg-white/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-stone-900\";\n\n  return (\n    <section className=\"relative overflow-hidden bg-[#e6d9c3]\" onFocus={pause(true)} onBlur={pause(false)}>\n      <div\n        ref={wrapRef}\n        role=\"group\"\n        aria-roledescription=\"carousel\"\n        aria-label=\"Seven photographic prints on a sunlit stone table. Use the left and right arrow keys to lift the next print.\"\n        tabIndex={0}\n        onKeyDown={onKey}\n        className=\"group relative h-[620px] w-full select-none outline-none sm:h-[780px]\"\n      >\n        <canvas ref={canvasRef} aria-hidden=\"true\" className={`absolute inset-0 h-full w-full touch-pan-y ${mode === \"still\" ? \"hidden\" : \"\"}`} />\n\n        {/* the same table built from plain images, for browsers without WebGL 2 */}\n        {mode === \"still\" && (\n          <div className=\"absolute inset-0 overflow-hidden\" style={{ background: \"radial-gradient(120% 90% at 30% 20%, #f1e6d2 0%, #e4d5bb 55%, #d3c2a5 100%)\" }}>\n            <style>{`@keyframes sunlit-print-table-float { from { transform: translate(-50%, 0) rotate(-2.6deg); } to { transform: translate(-50%, -12px) rotate(-1.4deg); } } .sunlit-print-table-float { animation: sunlit-print-table-float 3.2s ease-in-out infinite alternate; } @keyframes sunlit-print-table-sway { from { transform: rotate(-2.5deg); } to { transform: rotate(3deg); } } .sunlit-print-table-sway { transform-origin: 0% 0%; animation: sunlit-print-table-sway 4.6s ease-in-out infinite alternate; } @media (prefers-reduced-motion: reduce) { .sunlit-print-table-float, .sunlit-print-table-sway { animation: none; } }`}</style>\n            <div className=\"absolute inset-x-0 top-0 h-[70%]\" style={{ perspective: \"1200px\", perspectiveOrigin: \"50% 10%\" }}>\n              <div className=\"absolute inset-x-0 top-0 h-[150%]\" style={{ transform: \"rotateX(52deg)\", transformOrigin: \"50% 0%\" }}>\n                {plates.map((p, i) => {\n                  if (i === active) return null;\n                  const [x, z, yaw] = slots[i];\n                  return (\n                    <div key={p.src} className=\"absolute w-[19%] bg-[#f4f1e9] p-[0.8%] pb-[2%] shadow-[10px_8px_10px_rgba(70,58,70,0.42)] sm:w-[13%]\" style={{ left: `${50 + x * 70}%`, top: `${60 + z * 82}%`, transform: `translate(-50%, -50%) rotate(${-yaw * 57}deg)` }}>\n                      <img src={p.src} alt=\"\" width={900} height={1200} className=\"aspect-[3/4] w-full object-cover\" style={{ background: p.tone, objectPosition: `${p.focus[0] * 100}% ${p.focus[1] * 100}%` }} />\n                    </div>\n                  );\n                })}\n              </div>\n            </div>\n            {/* window bars and an olive branch, as shadows */}\n            <div aria-hidden=\"true\" className=\"absolute inset-0\" style={{ background: \"linear-gradient(122deg, rgba(74,70,92,0.4) 0%, rgba(74,70,92,0.4) 5%, transparent 5.8%, transparent 30%, rgba(74,70,92,0.26) 30.4%, rgba(74,70,92,0.26) 31.8%, transparent 32.3%, transparent 86%, rgba(74,70,92,0.26) 86.5%, rgba(74,70,92,0.26) 88%, transparent 88.6%)\" }} />\n            <svg aria-hidden=\"true\" viewBox=\"0 0 400 200\" className=\"sunlit-print-table-sway absolute left-[12%] top-0 w-[46%] max-w-[560px] opacity-40\" style={{ filter: \"blur(2.5px)\" }}>\n              <path d=\"M10 6 C120 30 230 34 380 14\" fill=\"none\" stroke=\"#4a465c\" strokeWidth=\"3\" />\n              {[[60, 16, 62], [110, 26, -48], [160, 31, 58], [210, 32, -50], [262, 29, 52], [312, 23, -46], [360, 16, 40]].map(([x, y, r]) => (\n                <ellipse key={x} cx={x + 26} cy={y} rx=\"28\" ry=\"7.5\" fill=\"#4a465c\" transform={`rotate(${r} ${x} ${y})`} />\n              ))}\n            </svg>\n            <div key={active} className=\"sunlit-print-table-float absolute left-1/2 top-[14%] w-[60%] max-w-[330px] bg-[#f4f1e9] p-[14px] pb-[40px] shadow-[90px_70px_26px_-8px_rgba(74,62,78,0.42),0_1px_2px_rgba(60,50,30,0.3)] sm:left-[55%] sm:top-[10%]\" style={{ transform: \"translate(-50%, 0) rotate(-2.6deg)\" }}>\n              <img src={plates[active].src} alt={plates[active].alt} width={900} height={1200} className=\"aspect-[3/4] w-full object-cover\" style={{ background: plates[active].tone, objectPosition: `${plates[active].focus[0] * 100}% ${plates[active].focus[1] * 100}%` }} />\n              <p aria-hidden=\"true\" className=\"absolute inset-x-[14px] bottom-[11px] flex items-baseline justify-between text-[8px] font-semibold uppercase tracking-[0.22em] text-stone-800\" style={{ fontFamily: GROTESK }}>\n                <span>{plates[active].title}</span>\n                <span className=\"text-[16px] font-normal normal-case italic tracking-tight\" style={{ fontFamily: SERIF }}>{MASTHEAD}</span>\n                <span className=\"tabular-nums\">{String(active + 1).padStart(2, \"0\")} / {String(N).padStart(2, \"0\")}</span>\n              </p>\n            </div>\n          </div>\n        )}\n\n        {/* keyboard focus ring, drawn above the canvas so it is not covered */}\n        <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 hidden ring-2 ring-inset ring-stone-900 group-focus-visible:block\" />\n        <div className=\"pointer-events-none absolute inset-x-0 top-0 flex items-baseline justify-between p-5 text-stone-900 sm:p-9\">\n          <p className=\"text-[28px] italic leading-none sm:text-[32px]\" style={{ fontFamily: SERIF, letterSpacing: \"-0.03em\" }}>\n            {MASTHEAD}\n          </p>\n          <p className=\"text-[10px] font-semibold uppercase tracking-[0.28em] text-stone-800 sm:text-[11px]\" style={{ fontFamily: GROTESK }}>\n            Pick a print<span className=\"hidden sm:inline\">, or use the arrow keys</span>\n          </p>\n        </div>\n        <div className=\"pointer-events-none absolute inset-x-0 bottom-0 flex items-end justify-between gap-4 p-5 sm:p-9\">\n          <p aria-live=\"polite\" className=\"text-stone-900\">\n            <span className=\"block text-[11px] font-semibold uppercase tracking-[0.28em] text-stone-800\" style={{ fontFamily: GROTESK }}>\n              <span className=\"tabular-nums\">{String(active + 1).padStart(2, \"0\")}</span>\n              <span className=\"mx-2 text-stone-600\">/</span>\n              <span className=\"tabular-nums\">{String(N).padStart(2, \"0\")}</span>\n              <span className=\"ml-4 hidden sm:inline\">{SERIES}</span>\n            </span>\n            <span className=\"mt-2 block text-[40px] italic leading-[0.92] sm:text-[84px]\" style={{ fontFamily: SERIF, letterSpacing: \"-0.035em\" }}>\n              {plates[active].title}\n            </span>\n            <span className=\"sr-only\">. {plates[active].alt}</span>\n          </p>\n          <div className=\"pointer-events-auto flex gap-2\">\n            <button type=\"button\" onClick={() => choose(sim.current.active - 1)} aria-label=\"Previous print\" className={btn}>\n              <svg aria-hidden=\"true\" width=\"18\" height=\"18\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                <path d=\"M12 4l-6 6 6 6\" />\n              </svg>\n            </button>\n            <button type=\"button\" onClick={() => choose(sim.current.active + 1)} aria-label=\"Next print\" className={btn}>\n              <svg aria-hidden=\"true\" width=\"18\" height=\"18\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                <path d=\"M8 4l6 6-6 6\" />\n              </svg>\n            </button>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
