{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"recipe-card-holder-product-gallery-in-webgl-with-photo-cards-in-a-walnut-stand-on-a-sunlit-counter-that-flip-over-the-back-with-weight","type":"registry:block","title":"Recipe Card Holder Product Gallery in WebGL with Photo Cards in a Walnut Stand on a Sunlit Counter That Flip Over the Back with Weight","description":"Free React WebGL gallery: product photos printed on thick cards in a walnut recipe stand on a sunny counter. Next lifts the front card over the top.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/recipe-card-holder-product-gallery-in-webgl-with-photo-cards-in-a-walnut-stand-on-a-sunlit-counter-that-flip-over-the-back-with-weight.tsx","type":"registry:component","content":"import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\n\n/** The goods on the cards. Change a line here and its printed card and caption follow. */\nconst shop = { name: \"Larder & Lathe\", season: \"Spring kitchen goods\" };\nconst items = [\n  {\n    name: \"Terracotta stacking mugs\",\n    note: \"Wheel thrown, left raw outside and glazed within. Sold as a set of four.\",\n    price: \"$84\",\n    care: [\"Hand wash in warm water.\", \"The bare clay darkens with use\", \"and that is meant to happen.\"],\n    photo: \"https://images.pexels.com/photos/6611421/pexels-photo-6611421.jpeg?auto=compress&cs=tinysrgb&w=1200\",\n    alt: \"Terracotta mugs stacked beside white cups and plates on a pottery shelf\",\n    tone: \"#b9876a\",\n  },\n  {\n    name: \"Enamel lidded pots\",\n    note: \"Steel shells in poppy, ink and chalk, with turned beech knobs on the lids.\",\n    price: \"$136\",\n    care: [\"Medium heat only.\", \"Lift, never drag, on glass hobs.\", \"Oil the beech knobs each season.\"],\n    photo: \"https://images.pexels.com/photos/20430668/pexels-photo-20430668.jpeg?auto=compress&cs=tinysrgb&w=1200\",\n    alt: \"Red, navy and white enamel pots with wooden knobs on a checked cloth beside peppers\",\n    tone: \"#c9b49a\",\n  },\n  {\n    name: \"Striped linen towels\",\n    note: \"Washed flax with indigo stripes, folded and tied three to a bundle.\",\n    price: \"$42\",\n    care: [\"Wash at forty degrees.\", \"Line dry and press while damp.\", \"Softer every time it is washed.\"],\n    photo: \"https://images.pexels.com/photos/4794900/pexels-photo-4794900.jpeg?auto=compress&cs=tinysrgb&w=1200\",\n    alt: \"Blue and white striped linen towels folded on a woven rattan tray with cotton flowers\",\n    tone: \"#a8a49a\",\n  },\n  {\n    name: \"Copper saucepans\",\n    note: \"Tin lined, with riveted iron handles. Three sizes that nest on one hook.\",\n    price: \"$310\",\n    care: [\"Polish the copper with lemon and salt.\", \"Retin when the grey wears through.\", \"Never heat one empty.\"],\n    photo: \"https://images.pexels.com/photos/35225640/pexels-photo-35225640.jpeg?auto=compress&cs=tinysrgb&w=1200\",\n    alt: \"Copper saucepans lined up on shelves and an old iron range in a tiled kitchen\",\n    tone: \"#8a6a50\",\n  },\n  {\n    name: \"Clip-top pantry jars\",\n    note: \"Thick glass with wire bails and fresh rubber seals, for oil, salt and sugar.\",\n    price: \"$28\",\n    care: [\"Dishwasher safe without the seal.\", \"Boil the seals to refresh them.\", \"Keep the oil jar out of the sun.\"],\n    photo: \"https://images.pexels.com/photos/5590955/pexels-photo-5590955.jpeg?auto=compress&cs=tinysrgb&w=1200\",\n    alt: \"Glass oil bottle and clip-top jars of salt and sugar on a wooden worktop\",\n    tone: \"#b39b78\",\n  },\n];\nconst OAK = \"https://images.pexels.com/photos/6544938/pexels-photo-6544938.jpeg?auto=compress&cs=tinysrgb&w=1280\";\nconst WALNUT = \"https://images.pexels.com/photos/9996341/pexels-photo-9996341.jpeg?auto=compress&cs=tinysrgb&w=1280\";\n\nconst AUTOPLAY_MS = 4600; // time between self-playing flips\nconst FIRST_FLIP_MS = 3400; // the stand holds still first so it is seen complete\nconst FLIGHT_S = 1.3; // how long one card takes to go over the top\nconst LIFT = 0.98; // how high it is lifted while it turns\nconst LEAN = 0.2; // radians the cards lean back in the slot\nconst SLOT_GAP = 0.074; // distance between cards in the slot\nconst SLOT_SPRING = 150;\nconst SLOT_DAMPING = 15; // lower for more knock-on wobble\nconst GROTESK = '\"Inter Tight\", \"Inter\", ui-sans-serif, system-ui, sans-serif';\nconst SERIF = '\"Iowan Old Style\", \"Palatino Linotype\", Palatino, \"Book Antiqua\", Georgia, serif';\n\nconst N = items.length;\nconst TW = 960;\nconst TH = 640;\nconst clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));\nconst smooth = (a: number, b: number, x: number) => {\n  const t = clamp((x - a) / (b - a), 0, 1);\n  return t * t * (3 - 2 * t);\n};\nconst smoother = (a: number, b: number, x: number) => {\n  const t = clamp((x - a) / (b - a), 0, 1);\n  return t * t * t * (t * (t * 6 - 15) + 10);\n};\n\nconst VS = `#version 300 es\nin vec2 p; void main(){ gl_Position = vec4(p, 0.0, 1.0); }`;\n\nconst FS = `#version 300 es\nprecision highp float;\nprecision highp sampler2DArray;\nuniform vec2 uRes; uniform vec3 uCam; uniform vec3 uTgt; uniform vec2 uShift; uniform float uFov;\nuniform vec3 uCC[5]; uniform mat3 uCI[5]; uniform float uLay[5];\nuniform float uSS; uniform float uFocus; uniform float uSeed;\nuniform sampler2DArray uCards; uniform sampler2D uOak; uniform sampler2D uWal;\nout vec4 fragColor;\nconst vec3 L = vec3(-0.62, 0.62, -0.48);\nconst vec3 SUN = vec3(1.0, 0.8, 0.6) * 3.1;\nconst vec3 SKY = vec3(0.64, 0.67, 0.74) * 0.5;\nconst float WALLZ = 4.0;\nconst vec3 BMIN = vec3(-1.3, -0.01, -1.55);\nconst vec3 BMAX = vec3(1.3, 3.1, 1.05);\n\nfloat h21(vec2 p){ p = fract(p * vec2(123.34, 456.21)); p += dot(p, p + 45.32); return fract(p.x * p.y); }\nfloat vn(vec2 p){ vec2 i = floor(p), f = fract(p); f = f * f * (3.0 - 2.0 * f);\n  return mix(mix(h21(i), h21(i + vec2(1, 0)), f.x), mix(h21(i + vec2(0, 1)), h21(i + 1.0), f.x), f.y); }\nfloat sdRR(vec2 p, vec2 b, float r){ vec2 q = abs(p) - b + r; return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r; }\nfloat sdCard(vec3 p){ float d = sdRR(p.xy, vec2(0.75, 0.5), 0.042);\n  vec2 w = vec2(d + 0.003, abs(p.z) - 0.008); return min(max(w.x, w.y), 0.0) + length(max(w, 0.0)) - 0.003; }\nfloat sdRBox(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 sdHolder(vec3 p){\n  float b = sdRBox(p - vec3(0.0, 0.19, -0.1), vec3(1.02, 0.19, 0.5), 0.05);\n  float t = sdRBox(p - vec3(0.0, 0.5, -0.13), vec3(0.93, 0.3, 0.25), 0.014);\n  return max(b, -t);\n}\nfloat map(vec3 p, out float id){\n  float d = sdHolder(p); id = 1.0;\n  for (int i = 0; i < 5; i++){\n    vec3 q = p - uCC[i]; float bd = length(q) - 0.93; if (bd > d) continue;\n    float c = sdCard(uCI[i] * q); if (c < d){ d = c; id = 2.0 + float(i); }\n  }\n  return d;\n}\nfloat mapD(vec3 p){ float id; return map(p, id); }\nvec2 box(vec3 ro, vec3 rd){ vec3 i = 1.0 / rd; vec3 a = (BMIN - ro) * i, b = (BMAX - ro) * i;\n  vec3 lo = min(a, b), hi = max(a, b); return vec2(max(max(lo.x, lo.y), lo.z), min(min(hi.x, hi.y), hi.z)); }\nfloat march(vec3 ro, vec3 rd, float tmax, out float id){\n  id = 0.0; vec2 bb = box(ro, rd); if (bb.x > bb.y || bb.y < 0.0) return 1e9;\n  float t = max(bb.x, 0.0); float te = min(bb.y, tmax);\n  for (int i = 0; i < 120; i++){ float d = map(ro + rd * t, id); if (d < 0.00025 * t) return t; t += d * 0.92; if (t > te) break; }\n  return 1e9;\n}\nfloat shadow(vec3 p){\n  vec2 bb = box(p, L); if (bb.x > bb.y || bb.y < 0.0) return 1.0;\n  float t = max(bb.x, 0.0) + 0.002; float res = 1.0; float ph = 1e10;\n  for (int i = 0; i < 60; i++){ if (t > bb.y) break; float h = mapD(p + L * t); if (h < 0.0004) return 0.0;\n    float y = h * h / (2.0 * ph); float d = sqrt(max(h * h - y * y, 0.0)); res = min(res, 11.0 * d / max(0.0001, t - y)); ph = h; t += clamp(h, 0.005, 0.2); }\n  return clamp(res, 0.0, 1.0);\n}\nfloat ao(vec3 p, vec3 n){\n  if (any(lessThan(p, BMIN - 0.5)) || any(greaterThan(p, BMAX + 0.5))) return 1.0;\n  float o = 0.0, s = 1.0;\n  for (int i = 1; i <= 5; i++){ float h = 0.01 + 0.06 * float(i); o += (h - mapD(p + n * h)) * s; s *= 0.72; }\n  return clamp(1.0 - 1.7 * o, 0.0, 1.0);\n}\nvec3 nrm(vec3 p){ const vec2 k = vec2(1, -1); float e = 0.0005;\n  return normalize(k.xyy * mapD(p + k.xyy * e) + k.yyx * mapD(p + k.yyx * e) + k.yxy * mapD(p + k.yxy * e) + k.xxx * mapD(p + k.xxx * e)); }\n// Sun through a tall window on the left: its frame and glazing bars land on everything.\nfloat win(vec3 p){\n  float t = (-5.0 - p.x) / L.x; vec3 q = p + L * t; float s = 0.015 + t * 0.012;\n  float inside = smoothstep(-s, s, q.y - 0.9) * smoothstep(-s, s, 5.6 - q.y) * smoothstep(-s, s, q.z + 4.4) * smoothstep(-s, s, 4.6 - q.z);\n  float bars = smoothstep(0.035 - s, 0.035 + s, abs(fract(q.z / 1.7 + 0.15) - 0.5) * 1.7);\n  float hb = smoothstep(0.03 - s, 0.03 + s, abs(q.y - 3.5));\n  return inside * bars * hb;\n}\nvec3 env(vec3 r){\n  vec3 c = mix(vec3(0.36, 0.3, 0.24), vec3(0.8, 0.76, 0.7), smoothstep(-0.25, 0.6, r.y));\n  float w = smoothstep(0.82, 0.95, dot(r, normalize(vec3(-1.0, 0.5, -0.4))));\n  return c + vec3(2.4, 2.1, 1.75) * w;\n}\nvec3 light(vec3 p, vec3 n, vec3 v, vec3 alb, float rough, float f0, float occ, float sh, float refl){\n  float ndl = max(dot(n, L), 0.0); vec3 h = normalize(L + v);\n  float ndh = max(dot(n, h), 0.0); float a = rough * rough; float a2 = a * a; float dd = ndh * ndh * (a2 - 1.0) + 1.0;\n  float D = a2 / (3.14159 * dd * dd); float ndv = max(dot(n, v), 0.001);\n  float F = f0 + (1.0 - f0) * pow(1.0 - max(dot(h, v), 0.0), 5.0);\n  float k = (rough + 1.0) * (rough + 1.0) / 8.0; float G = ndl / (ndl * (1.0 - k) + k) * ndv / (ndv * (1.0 - k) + k);\n  float spec = D * F * G / (4.0 * ndl * ndv + 0.001);\n  vec3 col = (alb * (1.0 - F) + spec * 3.14159) * SUN * ndl * sh;\n  col += alb * (SKY * (0.55 + 0.45 * n.y) + vec3(0.42, 0.31, 0.2) * (0.5 - 0.5 * n.y) * 0.8) * occ;\n  float Fr = f0 + (1.0 - f0) * pow(1.0 - ndv, 5.0);\n  col += env(reflect(-v, n)) * Fr * occ * refl;\n  return col;\n}\nvec3 aces(vec3 x){ return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0); }\nvec3 render(vec2 fc){\n  vec2 uv = (fc - 0.5 * uRes) / uRes.y - uShift;\n  vec3 f = normalize(uTgt - uCam); vec3 r = normalize(cross(vec3(0, 1, 0), f)); vec3 u = cross(f, r);\n  vec3 rd = normalize(f * uFov + uv.x * r + uv.y * u); vec3 ro = uCam; vec3 v = -rd;\n  float tp = rd.y < 0.0 ? -ro.y / rd.y : 1e9; float tw = rd.z > 0.0 ? (WALLZ - ro.z) / rd.z : 1e9;\n  float id; float tm = march(ro, rd, min(tp, tw), id);\n  vec3 col;\n  if (tm < 1e8){\n    vec3 p = ro + rd * tm; vec3 n = nrm(p);\n    float occ = ao(p, n); float sh = shadow(p + n * 0.003) * win(p);\n    if (id > 1.5){\n      int i = int(id - 2.0 + 0.5); vec3 lp = uCI[i] * (p - uCC[i]);\n      vec2 cu = vec2(lp.x / 1.5 + 0.5, 0.5 - lp.y);\n      float bl = clamp(abs(tm - uFocus) * 1.4, 0.0, 2.5);\n      vec3 alb; float rough = 0.55; float refl = 0.35;\n      float grain = 0.965 + 0.035 * vn(lp.xy * vec2(420.0, 380.0)) + 0.02 * vn(lp.xy * 60.0);\n      if (lp.z < -0.0055){ alb = texture(uCards, vec3(cu, uLay[i]), bl).rgb; rough = 0.38; refl = 0.55; }\n      else if (lp.z > 0.0055){ alb = texture(uCards, vec3(cu.x, 1.0 - cu.y, uLay[i] + 5.0), bl).rgb; }\n      else { alb = vec3(0.8, 0.76, 0.68) * (0.9 + 0.1 * vn(vec2(lp.x + lp.y, lp.z) * 900.0)); }\n      alb *= grain;\n      col = light(p, n, v, alb, rough, 0.04, occ, sh, refl);\n      float back = max(dot(-n, L), 0.0);\n      if (back > 0.0) col += alb * SUN * 0.07 * back * shadow(p - n * 0.02) * win(p);\n    } else {\n      vec3 an = pow(abs(n), vec3(4.0)); an /= an.x + an.y + an.z;\n      vec3 tx = texture(uWal, vec2(p.y * 0.8, p.z * 0.3) + 0.21).rgb;\n      vec3 ty = texture(uWal, vec2(p.z * 0.8, p.x * 0.3) + 0.57).rgb;\n      vec3 tz = texture(uWal, vec2(p.y * 0.8, p.x * 0.3) + 0.83).rgb;\n      vec3 alb = (tx * an.x + ty * an.y + tz * an.z) * vec3(0.6, 0.5, 0.45);\n      float sheen = 0.5 + 0.5 * vn(vec2(p.x * 2.0, p.y * 40.0 + p.z * 40.0));\n      col = light(p, n, v, alb, 0.34 + 0.08 * sheen, 0.045, occ, sh, 0.6);\n    }\n  } else if (tp < tw){\n    vec3 p = ro + rd * tp; vec3 n = vec3(0, 1, 0);\n    float bl = clamp(abs(tp - uFocus) * 1.1, 0.0, 6.0);\n    vec3 alb = texture(uOak, vec2(p.x * 0.36, p.z * 0.62) + 0.37, bl).rgb * vec3(0.98, 0.9, 0.8);\n    float occ = ao(p, n) * mix(0.55, 1.0, smoothstep(0.0, 0.45, WALLZ - p.z));\n    float sh = shadow(p + n * 0.002) * win(p);\n    col = light(p, n, v, alb, 0.46, 0.04, occ, sh, 0.5);\n  } else {\n    vec3 p = ro + rd * tw; vec3 n = vec3(0, 0, -1);\n    vec3 alb = vec3(0.76, 0.7, 0.62) * (0.95 + 0.05 * vn(p.xy * 2.3)) ;\n    float occ = mix(0.5, 1.0, smoothstep(0.0, 0.5, p.y));\n    col = light(p, n, v, alb, 0.9, 0.02, occ, shadow(p + n * 0.01) * win(p), 0.0);\n  }\n  col = aces(col * 0.82);\n  return pow(col, vec3(1.0 / 2.2));\n}\nvoid main(){\n  vec3 c;\n  if (uSS > 1.5) c = 0.5 * (render(gl_FragCoord.xy + vec2(-0.25, 0.25)) + render(gl_FragCoord.xy + vec2(0.25, -0.25)));\n  else c = render(gl_FragCoord.xy);\n  vec2 q = gl_FragCoord.xy / uRes; c *= 0.88 + 0.12 * smoothstep(1.15, 0.35, length(q - vec2(0.55, 0.55)));\n  c += (h21(gl_FragCoord.xy + uSeed) - 0.5) * 0.018;\n  fragColor = vec4(c, 1.0);\n}`;\n\ntype Sim = { slot: number; vel: number; target: number; lean: number; leanV: number; y: number; yV: number };\n\nfunction cover(ctx: CanvasRenderingContext2D, img: HTMLImageElement, x: number, y: number, w: number, h: number) {\n  const s = Math.max(w / img.naturalWidth, h / img.naturalHeight);\n  const sw = w / s;\n  const sh = h / s;\n  ctx.drawImage(img, (img.naturalWidth - sw) / 2, (img.naturalHeight - sh) / 2, sw, sh, x, y, w, h);\n}\n\n/** Paints the printed face (photo, number, name, price) and the ruled reverse of one card. */\nfunction paintCard(ctx: CanvasRenderingContext2D, i: number, side: \"front\" | \"back\", img: HTMLImageElement | null) {\n  const it = items[i];\n  const num = `No. ${String(i + 1).padStart(2, \"0\")}`;\n  ctx.save();\n  ctx.fillStyle = side === \"front\" ? \"#f3eee4\" : \"#f5f0e5\";\n  ctx.fillRect(0, 0, TW, TH);\n  if (side === \"front\") {\n    ctx.fillStyle = \"#6b5b4a\";\n    ctx.font = `600 19px ${GROTESK}`;\n    ctx.fillText(num.toUpperCase(), 44, 76);\n    ctx.fillStyle = \"#2a2018\";\n    ctx.font = `italic 36px ${SERIF}`;\n    ctx.fillText(it.name, 150, 78);\n    ctx.textAlign = \"right\";\n    ctx.font = `500 26px ${GROTESK}`;\n    ctx.fillText(it.price, TW - 44, 77);\n    ctx.fillStyle = it.tone;\n    ctx.fillRect(40, 112, TW - 80, 488);\n    if (img) cover(ctx, img, 40, 112, TW - 80, 488);\n    ctx.fillStyle = \"rgba(40,30,20,0.22)\";\n    ctx.fillRect(40, 112, TW - 80, 1);\n  } else {\n    ctx.strokeStyle = \"rgba(186,70,58,0.7)\";\n    ctx.lineWidth = 2;\n    ctx.beginPath();\n    ctx.moveTo(0, 132);\n    ctx.lineTo(TW, 132);\n    ctx.stroke();\n    ctx.strokeStyle = \"rgba(108,148,190,0.5)\";\n    ctx.lineWidth = 1.5;\n    for (let y = 196; y < TH - 20; y += 62) {\n      ctx.beginPath();\n      ctx.moveTo(0, y);\n      ctx.lineTo(TW, y);\n      ctx.stroke();\n    }\n    ctx.fillStyle = \"#3a2c20\";\n    ctx.font = `600 22px ${GROTESK}`;\n    ctx.fillText(`${shop.name.toUpperCase()}  ·  ${num.toUpperCase()}`, 52, 96);\n    ctx.font = `italic 38px ${SERIF}`;\n    ctx.fillStyle = \"#2f3a52\";\n    it.care.forEach((line, k) => ctx.fillText(line, 64, 184 + k * 62));\n  }\n  ctx.restore();\n}\n\nfunction compile(gl: WebGL2RenderingContext, type: number, src: string) {\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  return s;\n}\n\nexport default function RecipeCardHolderGallery() {\n  const reduce = useReducedMotion();\n  const rootRef = useRef<HTMLElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const [active, setActive] = useState(0);\n  const [noGL, setNoGL] = useState(false);\n  const cmd = useRef<{ queue: number[]; pausedUntil: number }>({ queue: [], pausedUntil: 0 });\n\n  const go = useCallback((dir: number, user = true) => {\n    if (user) cmd.current.pausedUntil = performance.now() + 12000;\n    if (cmd.current.queue.length < 2) cmd.current.queue.push(dir);\n    if (noGL) setActive((a) => (a + dir + N) % N);\n  }, [noGL]);\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    const root = rootRef.current;\n    if (!canvas || !root) return;\n    const gl = canvas.getContext(\"webgl2\", { antialias: false, alpha: false, powerPreference: \"high-performance\" });\n    if (!gl) {\n      setNoGL(true);\n      return;\n    }\n    let prog: WebGLProgram;\n    try {\n      prog = gl.createProgram()!;\n      gl.attachShader(prog, compile(gl, gl.VERTEX_SHADER, VS));\n      gl.attachShader(prog, compile(gl, gl.FRAGMENT_SHADER, FS));\n      gl.linkProgram(prog);\n      if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(prog) || \"link\");\n    } catch (e) {\n      console.warn(e);\n      setNoGL(true);\n      return;\n    }\n    gl.useProgram(prog);\n    const buf = gl.createBuffer();\n    gl.bindBuffer(gl.ARRAY_BUFFER, buf);\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n    const loc = gl.getAttribLocation(prog, \"p\");\n    gl.enableVertexAttribArray(loc);\n    gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);\n    const U = (n: string) => gl.getUniformLocation(prog, n);\n    const u = {\n      res: U(\"uRes\"), cam: U(\"uCam\"), tgt: U(\"uTgt\"), shift: U(\"uShift\"), fov: U(\"uFov\"), cc: U(\"uCC\"), ci: U(\"uCI\"),\n      lay: U(\"uLay\"), ss: U(\"uSS\"), focus: U(\"uFocus\"), seed: U(\"uSeed\"),\n    };\n    gl.uniform1i(U(\"uCards\"), 0);\n    gl.uniform1i(U(\"uOak\"), 1);\n    gl.uniform1i(U(\"uWal\"), 2);\n    const aniso = gl.getExtension(\"EXT_texture_filter_anisotropic\");\n\n    // Card faces and backs live in one array texture: layers 0-4 fronts, 5-9 reverses.\n    const cardTex = gl.createTexture();\n    gl.activeTexture(gl.TEXTURE0);\n    gl.bindTexture(gl.TEXTURE_2D_ARRAY, cardTex);\n    gl.texStorage3D(gl.TEXTURE_2D_ARRAY, 10, gl.SRGB8_ALPHA8, TW, TH, N * 2);\n    gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);\n    gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.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    if (aniso) gl.texParameterf(gl.TEXTURE_2D_ARRAY, aniso.TEXTURE_MAX_ANISOTROPY_EXT, 8);\n    const pc = document.createElement(\"canvas\");\n    pc.width = TW;\n    pc.height = TH;\n    const pctx = pc.getContext(\"2d\")!;\n    let dirty = true;\n    const upload = (layer: number, i: number, side: \"front\" | \"back\", img: HTMLImageElement | null) => {\n      paintCard(pctx, i, side, img);\n      gl.activeTexture(gl.TEXTURE0);\n      gl.bindTexture(gl.TEXTURE_2D_ARRAY, cardTex);\n      gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, layer, TW, TH, 1, gl.RGBA, gl.UNSIGNED_BYTE, pc);\n      gl.generateMipmap(gl.TEXTURE_2D_ARRAY);\n      dirty = true;\n    };\n    items.forEach((_, i) => {\n      upload(i, i, \"front\", null);\n      upload(N + i, i, \"back\", null);\n    });\n    let alive = true;\n    let loaded = 0;\n    items.forEach((it, i) => {\n      const img = new Image();\n      img.crossOrigin = \"anonymous\";\n      img.onload = () => {\n        if (!alive) return;\n        upload(i, i, \"front\", img);\n        loaded++;\n      };\n      img.src = it.photo;\n    });\n    const woodTex = (unit: number, src: string, fill: [number, number, number]) => {\n      const t = gl.createTexture();\n      gl.activeTexture(gl.TEXTURE0 + unit);\n      gl.bindTexture(gl.TEXTURE_2D, t);\n      gl.texImage2D(gl.TEXTURE_2D, 0, gl.SRGB8_ALPHA8, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([...fill, 255]));\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n      const img = new Image();\n      img.crossOrigin = \"anonymous\";\n      img.onload = () => {\n        if (!alive) return;\n        gl.activeTexture(gl.TEXTURE0 + unit);\n        gl.bindTexture(gl.TEXTURE_2D, t);\n        gl.texImage2D(gl.TEXTURE_2D, 0, gl.SRGB8_ALPHA8, gl.RGBA, gl.UNSIGNED_BYTE, img);\n        gl.generateMipmap(gl.TEXTURE_2D);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);\n        if (aniso) gl.texParameterf(gl.TEXTURE_2D, aniso.TEXTURE_MAX_ANISOTROPY_EXT, 8);\n        dirty = true;\n      };\n      img.src = src;\n      return t;\n    };\n    const oak = woodTex(1, OAK, [214, 186, 150]);\n    const wal = woodTex(2, WALNUT, [96, 60, 38]);\n\n    // Physical state of each card. order[k] is the card standing in slot k (0 = front).\n    const order = items.map((_, i) => i);\n    const sims: Sim[] = items.map((_, i) => ({ slot: i, vel: 0, target: i, lean: 0, leanV: 0, y: 0, yV: 0 }));\n    const jitter = items.map((_, i) => ({ x: Math.sin(i * 12.9) * 0.022, yaw: Math.sin(i * 7.3) * 0.018 }));\n    let flight: { card: number; t: number; dir: number; shuffled: boolean } | null = null;\n    const pending: { card: number; at: number; target: number }[] = [];\n    const cc = new Float32Array(15);\n    const ci = new Float32Array(45);\n    const lay = new Float32Array(N);\n    const zSlot = (s: number) => -0.262 + s * SLOT_GAP;\n\n    const pose = (i: number, k: number, s: Sim, extra: { pitch: number; yaw: number; roll: number; lift: number; z: number | null }) => {\n      const pitch = LEAN + s.lean + extra.pitch;\n      const yaw = jitter[i].yaw + extra.yaw;\n      const roll = extra.roll;\n      // Rotation = Ry(yaw) * Rz(roll) * Rx(pitch); columns are the card's right, up and back axes.\n      const cx = Math.cos(pitch), sx = Math.sin(pitch), cy = Math.cos(yaw), sy = Math.sin(yaw), cz = Math.cos(roll), sz = Math.sin(roll);\n      const rx = [[1, 0, 0], [0, cx, -sx], [0, sx, cx]];\n      const rz = [[cz, -sz, 0], [sz, cz, 0], [0, 0, 1]];\n      const ry = [[cy, 0, sy], [0, 1, 0], [-sy, 0, cy]];\n      const mul = (a: number[][], b: number[][]) => a.map((r) => [0, 1, 2].map((c) => r[0] * b[0][c] + r[1] * b[1][c] + r[2] * b[2][c]));\n      const m = mul(ry, mul(rz, rx));\n      const restUp = [0, Math.cos(LEAN + s.lean), Math.sin(LEAN + s.lean)];\n      const base = [jitter[i].x, 0.201 + s.y, extra.z ?? zSlot(s.slot)];\n      const c = [base[0] + restUp[0] * 0.5, base[1] + restUp[1] * 0.5 + extra.lift, base[2] + restUp[2] * 0.5];\n      cc.set(c, k * 3);\n      // Inverse rotation = transpose; GLSL reads mat3 column by column, so write rows of m as columns.\n      for (let col = 0; col < 3; col++) for (let row = 0; row < 3; row++) ci[k * 9 + col * 3 + row] = m[col][row];\n      lay[k] = i;\n      return c;\n    };\n\n    let W = 0, H = 0, scale = 1, ss = 2;\n    let phone = false;\n    const resize = () => {\n      const r = canvas.getBoundingClientRect();\n      phone = r.width < 640;\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      let w = r.width * dpr * scale, h = r.height * dpr * scale;\n      const cap = 1400000 / (ss > 1.5 ? 1.6 : 1);\n      if (w * h > cap) {\n        const k = Math.sqrt(cap / (w * h));\n        w *= k;\n        h *= k;\n      }\n      W = Math.max(2, Math.round(w));\n      H = Math.max(2, Math.round(h));\n      canvas.width = W;\n      canvas.height = H;\n      gl.viewport(0, 0, W, H);\n      dirty = true;\n    };\n    resize();\n    const ro = new ResizeObserver(resize);\n    ro.observe(canvas);\n\n    const ptr = { x: 0, y: 0, sx: 0, sy: 0, vx: 0, vy: 0 };\n    const onMove = (e: PointerEvent) => {\n      const r = root.getBoundingClientRect();\n      ptr.x = clamp(((e.clientX - r.left) / r.width) * 2 - 1, -1, 1);\n      ptr.y = clamp(((e.clientY - r.top) / r.height) * 2 - 1, -1, 1);\n    };\n    const onLeave = () => {\n      ptr.x = 0;\n      ptr.y = 0;\n    };\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n\n    const start = performance.now();\n    let clock = 0; // seconds of drawn time, so a slow first load never flips early\n    let nextAuto = FIRST_FLIP_MS / 1000;\n    let raf = 0, last = start, visible = true, frames = 0, acc = 0;\n    const step = (dt: number, now: number) => {\n      // Start a new flight when the stand is free.\n      if (!flight && cmd.current.queue.length) {\n        const dir = cmd.current.queue.shift()!;\n        const card = dir > 0 ? order[0] : order[N - 1];\n        if (reduce) {\n          if (dir > 0) order.push(order.shift()!);\n          else order.unshift(order.pop()!);\n          order.forEach((c, k) => Object.assign(sims[c], { slot: k, target: k, vel: 0 }));\n          setActive(order[0]);\n        } else {\n          flight = { card, t: 0, dir, shuffled: false };\n          if (dir < 0) {\n            order.unshift(order.pop()!);\n            order.forEach((c, k) => c !== card && pending.push({ card: c, at: now + (N - k) * 55, target: k }));\n            setActive(card);\n          }\n        }\n        dirty = true;\n      }\n      clock += dt;\n      if (!reduce && clock > nextAuto && (loaded >= N || clock > 7) && now > cmd.current.pausedUntil && !flight && !cmd.current.queue.length) {\n        cmd.current.queue.push(1);\n        nextAuto = clock + AUTOPLAY_MS / 1000;\n      }\n      if (flight) {\n        flight.t += dt / FLIGHT_S;\n        if (flight.dir > 0 && !flight.shuffled && flight.t > 0.3) {\n          flight.shuffled = true;\n          order.push(order.shift()!);\n          order.forEach((c, k) => c !== flight!.card && pending.push({ card: c, at: now + (k - 0) * 70, target: k }));\n          setActive(order[0]);\n        }\n        if (flight.t >= 1) {\n          const s = sims[flight.card];\n          const k = order.indexOf(flight.card);\n          Object.assign(s, { slot: k, target: k, vel: 0, y: 0.045, yV: -1.6, lean: flight.dir > 0 ? -0.05 : 0.06, leanV: flight.dir > 0 ? 1.4 : -1.2 });\n          // The landing knocks the neighbours.\n          order.forEach((c) => c !== flight!.card && (sims[c].leanV += (flight!.dir > 0 ? 0.35 : -0.5) * (0.6 + Math.random() * 0.4)));\n          flight = null;\n          nextAuto = Math.max(nextAuto, clock + (AUTOPLAY_MS - 1200) / 1000);\n        }\n      }\n      for (let p = pending.length - 1; p >= 0; p--) if (now >= pending[p].at) {\n        sims[pending[p].card].target = pending[p].target;\n        pending.splice(p, 1);\n      }\n      sims.forEach((s, i) => {\n        if (flight && flight.card === i) return;\n        const a = -SLOT_SPRING * (s.slot - s.target) - SLOT_DAMPING * s.vel;\n        s.vel += a * dt;\n        s.slot += s.vel * dt;\n        // Sliding forward tips the top back a touch, then the card rocks to rest.\n        const la = -90 * s.lean - 7 * s.leanV + s.vel * -1.9 * 0;\n        s.leanV += (la - a * 0.0016) * dt;\n        s.lean += s.leanV * dt;\n        s.yV -= 9.8 * dt;\n        s.y += s.yV * dt;\n        if (s.y < 0) {\n          s.y = 0;\n          s.yV = Math.abs(s.yV) > 0.25 ? -s.yV * 0.32 : 0;\n        }\n      });\n      ptr.vx += (-60 * (ptr.sx - ptr.x) - 11 * ptr.vx) * dt;\n      ptr.vy += (-60 * (ptr.sy - ptr.y) - 11 * ptr.vy) * dt;\n      ptr.sx += ptr.vx * dt;\n      ptr.sy += ptr.vy * dt;\n    };\n\n    const draw = (now: number) => {\n      const t = (now - start) / 1000;\n      const aspect = W / H;\n      let k = 0;\n      order.forEach((i) => {\n        const s = sims[i];\n        if (flight && flight.card === i) return;\n        const sway = reduce ? 0 : 0;\n        pose(i, k++, s, { pitch: sway, yaw: 0, roll: 0, lift: 0, z: null });\n      });\n      if (flight) {\n        const i = flight.card;\n        const s = sims[i];\n        const p = flight.dir > 0 ? flight.t : 1 - flight.t;\n        const z0 = zSlot(0), z1 = zSlot(N - 1);\n        const ant = flight.dir > 0 ? Math.sin(Math.PI * clamp(p / 0.13, 0, 1)) * (p < 0.13 ? 1 : 0) : 0;\n        const lift = LIFT * Math.pow(Math.sin(Math.PI * smooth(0.03, 0.96, p)), 0.6) - ant * 0.02;\n        const spin = Math.PI * 2 * smoother(0.02, 0.76, p); // edge-on to the sky at the top of the arc\n        pose(i, k++, s, {\n          pitch: spin - ant * 0.14,\n          yaw: 0.16 * Math.sin(Math.PI * p),\n          roll: -0.07 * Math.sin(Math.PI * 2 * p),\n          lift,\n          z: z0 + (z1 - z0) * smoother(0.18, 0.84, p) - 0.18 * Math.sin(Math.PI * smooth(0.0, 0.5, p)) * (1 - smooth(0.5, 0.9, p)),\n        });\n      }\n      const az = 0.4 + (reduce ? 0 : ptr.sx * 0.05 + Math.sin(t * 0.21) * 0.025);\n      const el = 0.3 + (reduce ? 0 : -ptr.sy * 0.02 + Math.sin(t * 0.17) * 0.012);\n      const dist = phone ? 6.6 + Math.max(0, 0.9 - aspect) * 3.0 : 5.75;\n      const tgt = [0, phone ? 1.05 : 1.1, -0.12];\n      const cam = [tgt[0] + dist * Math.sin(az) * Math.cos(el), tgt[1] + dist * Math.sin(el), tgt[2] - dist * Math.cos(az) * Math.cos(el)];\n      const front = cc.subarray(0, 3);\n      const focus = Math.hypot(front[0] - cam[0], front[1] - cam[1], front[2] - cam[2]);\n      gl.uniform2f(u.res, W, H);\n      gl.uniform3fv(u.cam, cam);\n      gl.uniform3fv(u.tgt, tgt);\n      gl.uniform2f(u.shift, phone ? 0 : clamp((aspect - 1) * 0.28, 0, 0.36), phone ? 0.1 : 0.1);\n      gl.uniform1f(u.fov, 2.1);\n      gl.uniform3fv(u.cc, cc);\n      gl.uniformMatrix3fv(u.ci, false, ci);\n      gl.uniform1fv(u.lay, lay);\n      gl.uniform1f(u.ss, ss);\n      gl.uniform1f(u.focus, focus);\n      gl.uniform1f(u.seed, reduce ? 0 : (t * 60) % 97);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n    };\n\n    const loop = (now: number) => {\n      raf = requestAnimationFrame(loop);\n      const dt = Math.min(0.05, (now - last) / 1000);\n      const ft = now - last;\n      last = now;\n      step(dt, now);\n      const moving = !reduce || dirty || !!flight;\n      if (!moving) return;\n      dirty = false;\n      draw(now);\n      if (!reduce) {\n        frames++;\n        acc += ft;\n        if (frames === 40) {\n          const avg = acc / frames;\n          (root as HTMLElement).dataset.fps = String(Math.round(1000 / avg));\n          if (avg > 24 && (ss > 1.5 || scale > 0.5)) {\n            if (ss > 1.5) ss = 1;\n            else scale = Math.max(0.5, scale * 0.85);\n            resize();\n          } else if (avg < 15 && scale < 1) {\n            scale = Math.min(1, scale * 1.08);\n            resize();\n          }\n          frames = 0;\n          acc = 0;\n        }\n      }\n    };\n    const run = () => {\n      cancelAnimationFrame(raf);\n      if (visible && !document.hidden) {\n        last = performance.now();\n        raf = requestAnimationFrame(loop);\n      }\n    };\n    const io = new IntersectionObserver(([e]) => {\n      visible = e.isIntersecting;\n      run();\n    });\n    io.observe(root);\n    const onVis = () => run();\n    document.addEventListener(\"visibilitychange\", onVis);\n    run();\n    return () => {\n      alive = false;\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      ro.disconnect();\n      document.removeEventListener(\"visibilitychange\", onVis);\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      gl.deleteTexture(cardTex);\n      gl.deleteTexture(oak);\n      gl.deleteTexture(wal);\n      gl.deleteBuffer(buf);\n      gl.deleteProgram(prog);\n    };\n  }, [reduce]);\n\n  const it = items[active];\n  const onKey = (e: React.KeyboardEvent) => {\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") {\n      e.preventDefault();\n      go(1);\n    } else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      go(-1);\n    }\n  };\n  const btn =\n    \"grid h-12 w-12 place-items-center rounded-full border border-[#2a2018]/20 bg-[#f6f1e8]/80 text-[#2a2018] shadow-[0_1px_0_rgba(255,255,255,0.8)_inset,0_6px_14px_-8px_rgba(60,40,20,0.5)] backdrop-blur-sm transition hover:bg-white active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#2a2018] focus-visible:ring-offset-2 focus-visible:ring-offset-[#e8dccb]\";\n\n  return (\n    <section\n      ref={rootRef}\n      aria-labelledby=\"rch-title\"\n      className=\"relative w-full overflow-hidden bg-[#e5d9c6]\"\n      style={{ fontFamily: GROTESK }}\n    >\n      <div\n        role=\"group\"\n        aria-roledescription=\"carousel\"\n        aria-label={`${shop.name} product cards`}\n        tabIndex={0}\n        onKeyDown={onKey}\n        className=\"relative h-[560px] w-full outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#2a2018] sm:h-[740px]\"\n      >\n        <canvas ref={canvasRef} aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full\" />\n        {noGL && (\n          <div aria-hidden=\"true\" className=\"absolute inset-0 bg-[linear-gradient(180deg,#efe5d6_0%,#e6d8c3_58%,#c9a77f_58%,#b48c62_100%)]\">\n            <div className=\"absolute bottom-[14%] left-1/2 w-[min(78vw,520px)] -translate-x-1/2 sm:left-[64%]\" style={{ perspective: \"1200px\" }}>\n              {[2, 1, 0].map((d) => {\n                const ix = (active + d) % N;\n                return (\n                  <div\n                    key={d}\n                    className=\"absolute bottom-[34px] left-0 right-0 rounded-[10px] bg-[#f3eee4] p-[4%] shadow-[0_18px_30px_-18px_rgba(40,25,10,0.7)]\"\n                    style={{ transform: `translateY(${-d * 24}px) translateX(${d * 6}px) scale(${1 - d * 0.035}) rotateX(${12 + d}deg)`, transformOrigin: \"bottom\" }}\n                  >\n                    <img src={items[ix].photo} alt=\"\" className=\"aspect-[888/478] w-full object-cover\" style={{ backgroundColor: items[ix].tone }} />\n                    <div className=\"h-8\" />\n                  </div>\n                );\n              })}\n              <div className=\"relative h-[70px] rounded-[10px] bg-[linear-gradient(180deg,#6b4429,#4a2c19)] shadow-[0_24px_30px_-16px_rgba(40,20,5,0.8)]\" />\n            </div>\n          </div>\n        )}\n        <div className=\"pointer-events-none absolute left-5 top-5 sm:left-12 sm:top-11\">\n          <p className=\"text-[12px] font-semibold uppercase tracking-[0.22em] text-[#4a3b2c]\">{shop.name}</p>\n          <p className=\"mt-1 text-[13px] text-[#5a4a3a]\">{shop.season}, one card at a time</p>\n        </div>\n        <div className=\"absolute bottom-10 left-12 hidden w-[min(40%,440px)] sm:block\">\n          <Caption it={it} index={active} reduce={!!reduce} />\n          <Controls go={go} btn={btn} />\n        </div>\n      </div>\n      <div className=\"px-5 pb-8 pt-2 sm:hidden\">\n        <Caption it={it} index={active} reduce={!!reduce} />\n        <Controls go={go} btn={btn} />\n      </div>\n      <p className=\"sr-only\" aria-live=\"polite\">\n        {`Card ${active + 1} of ${N}: ${it.name}, ${it.price}. ${it.alt}.`}\n      </p>\n    </section>\n  );\n}\n\nfunction Caption({ it, index, reduce }: { it: (typeof items)[number]; index: number; reduce: boolean }) {\n  return (\n    <div className=\"min-h-[188px] sm:min-h-[214px]\">\n      <p className=\"text-[13px] font-semibold tabular-nums tracking-[0.18em] text-[#5a4a3a]\">\n        {String(index + 1).padStart(2, \"0\")} <span className=\"text-[#8a7864]\">/ {String(N).padStart(2, \"0\")}</span>\n      </p>\n      <AnimatePresence mode=\"wait\" initial={false}>\n        <motion.div\n          key={index}\n          initial={reduce ? false : { opacity: 0, y: 14, filter: \"blur(4px)\" }}\n          animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n          exit={reduce ? undefined : { opacity: 0, y: -10, filter: \"blur(4px)\" }}\n          transition={{ duration: 0.38, ease: [0.2, 0.7, 0.2, 1] }}\n        >\n          <h2 id=\"rch-title\" className=\"mt-3 text-[34px] leading-[1.02] tracking-[-0.02em] text-[#231a12] sm:text-[52px]\" style={{ fontFamily: SERIF }}>\n            {it.name}\n          </h2>\n          <p className=\"mt-3 max-w-[34ch] text-[15px] leading-relaxed text-[#4a3b2c]\">{it.note}</p>\n          <p className=\"mt-2 text-[17px] font-semibold tabular-nums text-[#231a12]\">{it.price}</p>\n        </motion.div>\n      </AnimatePresence>\n    </div>\n  );\n}\n\nfunction Controls({ go, btn }: { go: (d: number) => void; btn: string }) {\n  return (\n    <div className=\"mt-5 flex items-center gap-3\">\n      <button type=\"button\" aria-label=\"Previous card\" onClick={() => go(-1)} className={btn}>\n        <svg width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" fill=\"none\" aria-hidden=\"true\">\n          <path d=\"M12.5 4.5 7 10l5.5 5.5\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n        </svg>\n      </button>\n      <button type=\"button\" aria-label=\"Next card\" onClick={() => go(1)} className={btn}>\n        <svg width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" fill=\"none\" aria-hidden=\"true\">\n          <path d=\"M7.5 4.5 13 10l-5.5 5.5\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n        </svg>\n      </button>\n      <span className=\"ml-2 text-[13px] text-[#5a4a3a]\">Flip to the next card</span>\n    </div>\n  );\n}\n"}]}
