{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"folded-paper-tag-faq-hung-on-brass-hooks-in-ray-marched-sunlight-where-each-tag-drops-open-to-show-its-printed-answer","type":"registry:block","title":"Folded Paper Tag FAQ Hung on Brass Hooks in Ray Marched Sunlight Where Each Tag Drops Open to Show Its Printed Answer","description":"Free React FAQ: folded card tags on brass hooks in WebGL sunlight. Press one and its flap drops open on its crease to show the printed answer.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/folded-paper-tag-faq-hung-on-brass-hooks-in-ray-marched-sunlight-where-each-tag-drops-open-to-show-its-printed-answer.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\n\n/** The questions. Each one is printed on the front of a folded tag and its answer inside. */\nconst tags = [\n  {\n    q: \"How long does framing take?\",\n    a: \"Most pieces are ready in ten working days. A rush job takes three, as long as the moulding you choose is on the rack.\",\n    paper: [0.66, 0.53, 0.38],\n  },\n  {\n    q: \"Can you frame a shirt or an object?\",\n    a: \"Yes. Shirts, medals, tiles and letters go into deep box frames, stitched or pinned in place so nothing is ever glued.\",\n    paper: [0.6, 0.63, 0.52],\n  },\n  {\n    q: \"Is the glass anti-reflective?\",\n    a: \"Museum glass is offered on every order. It cuts glare in a bright room and filters the light that fades ink and dyes.\",\n    paper: [0.74, 0.57, 0.51],\n  },\n  {\n    q: \"Do you collect large work?\",\n    a: \"We collect and deliver across the city on Thursdays. Anything over a metre travels in one of our own padded crates.\",\n    paper: [0.55, 0.6, 0.64],\n  },\n  {\n    q: \"Can I bring my own frame?\",\n    a: \"Bring it in. We check the joints, cut a fresh mount and fit new glass to the frame you already love.\",\n    paper: [0.84, 0.78, 0.64],\n  },\n];\nconst SHOP = \"Marrow Lane Framers\";\nconst START_OPEN = 1; // which tag hangs open when the piece loads\nconst DEMO_EVERY = 5200; // ms between tags in the self-playing demo, until someone clicks\n\n// Scene sizes in world units (must match the shader constants below).\nconst N = tags.length;\nconst SP = 0.5; // gap between hooks\nconst HW = 0.2; // half the tag width\nconst HOOKY = 1.08;\nconst HZ = 0.13;\nconst LS = 0.2; // string length\nconst F = 2.2; // lens: higher is longer and flatter\nconst CW = 384; // atlas pixels per tag column\nconst S = CW / (2 * HW); // atlas pixels per world unit\nconst SPREAD = Math.round(0.9 * S);\nconst QTOP = SPREAD + 8;\nconst AH = QTOP + Math.round(0.4 * S) + 8;\n\nconst VERT = `#version 300 es\nin vec2 aP; void main(){ gl_Position=vec4(aP,0.,1.); }`;\n\nconst FRAG = `#version 300 es\nprecision highp float;\nuniform vec2 uRes; uniform float uTime; uniform vec4 uTag[5]; uniform vec3 uPaper[5];\nuniform vec3 uRo; uniform vec3 uTa; uniform sampler2D uAtlas;\nout vec4 o;\nconst float SP=${SP.toFixed(3)}, HW=${HW.toFixed(3)}, PT=0.06, PB=-0.44, FL=0.40, TH=0.0038, CR=0.0065;\nconst float HOOKY=${HOOKY.toFixed(3)}, HZ=${HZ.toFixed(3)}, LS=${LS.toFixed(3)};\nconst float CWp=${CW.toFixed(1)}, Sp=${S.toFixed(3)}, QT=${QTOP.toFixed(1)}, AW=${(CW * N).toFixed(1)}, AH=${AH.toFixed(1)};\nconst vec3 L=normalize(vec3(-0.6,0.58,0.55));\n\nfloat h21(vec2 p){ p=fract(p*vec2(233.34,851.73)); p+=dot(p,p+23.45); return fract(p.x*p.y); }\nfloat vn(vec2 p){ vec2 i=floor(p),f=fract(p); f=f*f*(3.-2.*f);\n  return mix(mix(h21(i),h21(i+vec2(1,0)),f.x),mix(h21(i+vec2(0,1)),h21(i+vec2(1,1)),f.x),f.y); }\nfloat fbm(vec2 p){ float s=0.,a=.5; for(int i=0;i<4;i++){ s+=a*vn(p); p=p*2.03+7.1; a*=.5; } return s; }\n\nfloat box2(vec2 p,vec2 b){ vec2 d=abs(p)-b; return length(max(d,0.))+min(max(d.x,d.y),0.); }\nfloat box3(vec3 p,vec3 b){ vec3 d=abs(p)-b; return length(max(d,0.))+min(max(d.x,max(d.y,d.z)),0.); }\nfloat ext(float d2,float z,float h){ vec2 w=vec2(d2,abs(z)-h); return min(max(w.x,w.y),0.)+length(max(w,0.)); }\nfloat cap(vec3 p,vec3 a,vec3 b,float r){ vec3 pa=p-a,ba=b-a; float h=clamp(dot(pa,ba)/dot(ba,ba),0.,1.); return length(pa-ba*h)-r; }\n\nvec3 tagLocal(vec3 p,int i){\n  vec4 T=uTag[i]; vec3 q=p-vec3(float(i-2)*SP,HOOKY,HZ);\n  float c=cos(T.x),s=sin(T.x); q.xy=mat2(c,-s,s,c)*q.xy; q.y+=LS;\n  c=cos(T.z); s=sin(T.z); q.xz=mat2(c,-s,s,c)*q.xz;\n  float bx=q.x/HW; q.z+=0.011*bx*bx; return q;\n}\n// flap frame: u along the paper from the crease, v across its thickness (+ is the answer side)\nvec2 flapUV(vec3 l,vec4 T){\n  float b=T.y; vec3 dir=vec3(0.,-cos(b),sin(b)), n=vec3(0.,sin(b),cos(b));\n  vec3 q=l-vec3(0.,PB,CR); float u=dot(q,dir); return vec2(u, dot(q,n)+CR-T.w*u*u);\n}\n// x: distance, y: part (0 paper panel, 1 flap, 2 crease, 3 ring, 4 string)\nvec2 tagSDF(vec3 l,vec4 T){\n  vec2 xy=l.xy;\n  float d2=box2(xy-vec2(0.,(PT+PB)*.5),vec2(HW,(PT-PB)*.5));\n  d2=max(d2,(abs(xy.x)+xy.y-(HW+PT-0.065))*0.7071);\n  d2=max(d2,-(length(xy)-0.013));\n  vec2 r=vec2(ext(d2,l.z,TH),0.);\n  vec2 fu=flapUV(l,T);\n  float df=ext(box2(vec2(l.x,fu.x-FL*.5),vec2(HW,FL*.5)-0.016)-0.016,fu.y,TH);\n  if(df<r.x) r=vec2(df,1.);\n  float ry=l.y-PB, rz=l.z-CR; float th=atan(-ry,-rz);\n  if(th>-0.02 && th<T.y+0.02){ float dc=max(abs(length(vec2(ry,rz))-CR)-TH,abs(l.x)-HW); if(dc<r.x) r=vec2(dc,2.); }\n  float dr=ext(abs(length(xy)-0.025)-0.011,l.z,TH+0.0011); if(dr<r.x) r=vec2(dr,3.);\n  float ds=min(cap(l,vec3(0.,LS+0.001,0.),vec3(0.003,0.0,0.0075),0.0032),cap(l,vec3(0.,LS+0.001,0.),vec3(-0.003,0.0,-0.0075),0.0032));\n  ds=min(ds,cap(l,vec3(0.003,-0.002,0.0075),vec3(-0.003,-0.002,-0.0075),0.0032));\n  if(ds<r.x) r=vec2(ds,4.);\n  return r;\n}\n// id: 0 wall, 1 oak rail, 2 brass, 10+i*10+part tag\nvec2 map(vec3 p){\n  vec2 r=vec2(p.z,0.);\n  float rail=box3(p-vec3(0.,HOOKY+0.01,0.012),vec3(1.21,0.052,0.010))-0.004;\n  if(rail<r.x) r=vec2(rail,1.);\n  int hi=clamp(int(floor(p.x/SP+2.5)),0,4); float hx=float(hi-2)*SP;\n  float br=ext(length(p.xy-vec2(hx,HOOKY+0.01))-0.026,p.z-0.029,0.003)-0.002;\n  br=min(br,cap(p,vec3(hx,HOOKY+0.01,0.03),vec3(hx,HOOKY-0.012,HZ),0.0075));\n  br=min(br,cap(p,vec3(hx,HOOKY-0.012,HZ),vec3(hx,HOOKY+0.028,HZ+0.026),0.0068));\n  if(br<r.x) r=vec2(br,2.);\n  if(p.z<HZ+0.6){\n    int i0=clamp(int(floor(p.x/SP+2.)),0,4), i1=min(i0+1,4);\n    vec2 a=tagSDF(tagLocal(p,i0),uTag[i0]); if(a.x<r.x) r=vec2(a.x,10.+float(i0)*10.+a.y);\n    if(i1!=i0){ vec2 b=tagSDF(tagLocal(p,i1),uTag[i1]); if(b.x<r.x) r=vec2(b.x,10.+float(i1)*10.+b.y); }\n  } else r.x=min(r.x,p.z-HZ-0.06);\n  return r;\n}\nvec3 nor(vec3 p){ vec2 e=vec2(0.0006,-0.0006);\n  return normalize(e.xyy*map(p+e.xyy).x+e.yyx*map(p+e.yyx).x+e.yxy*map(p+e.yxy).x+e.xxx*map(p+e.xxx).x); }\nfloat shadow(vec3 p){ float s=1.,t=0.004;\n  for(int i=0;i<34;i++){ float h=map(p+L*t).x; s=min(s,14.*h/t); t+=clamp(h,0.003,0.06); if(s<0.01||t>1.4) break; }\n  return clamp(s,0.,1.); }\nfloat ao(vec3 p,vec3 n){ float a=0.,w=1.; for(int i=1;i<=4;i++){ float h=0.012*float(i)*float(i); a+=w*(h-map(p+n*h).x); w*=.6; } return clamp(1.-a*7.,0.,1.); }\n// sunlight comes through a four-pane window with leaves outside\nfloat sun(vec3 p){\n  vec2 w=(p+L*((2.6-p.z)/L.z)).xy-vec2(-2.62,3.44);\n  float bl=0.035;\n  float m=smoothstep(bl,-bl,box2(w,vec2(1.05,0.66)));\n  vec2 g=abs(w); m*=smoothstep(0.018,0.018+bl,g.x)*smoothstep(0.016,0.016+bl,g.y);\n  float lv=fbm(w*2.6+vec2(uTime*0.05,sin(uTime*0.3)*0.06));\n  m*=mix(0.25,1.,smoothstep(0.38,0.6,lv+0.12*(w.x+0.6)));\n  return m;\n}\nvec3 env(vec3 d){\n  vec3 c=mix(vec3(0.33,0.27,0.21),vec3(0.62,0.58,0.52),smoothstep(-0.3,0.6,d.y));\n  c+=vec3(3.2,2.6,1.9)*pow(max(dot(d,L),0.),24.);\n  c+=vec3(0.9,0.8,0.65)*smoothstep(0.8,0.95,d.z)*0.5;\n  return c;\n}\nvoid main(){\n  vec2 uv=(gl_FragCoord.xy-0.5*uRes)/uRes.y;\n  vec3 fw=normalize(uTa-uRo), rt=normalize(cross(fw,vec3(0,1,0))), up=cross(rt,fw);\n  vec3 rd=normalize(fw*${F.toFixed(2)}+rt*uv.x+up*uv.y), ro=uRo;\n  float t=(ro.z-0.75)/max(-rd.z,1e-3); vec2 h=vec2(0.);\n  for(int i=0;i<120;i++){ h=map(ro+rd*t); if(h.x<0.00025*t||t>40.) break; t+=h.x*0.85; }\n  vec3 p=ro+rd*t, n=nor(p), col;\n  float id=h.y, sh=shadow(p+n*0.0015), sm=sun(p), oc=ao(p,n);\n  float dl=max(dot(n,L),0.);\n  vec3 sunC=vec3(1.0,0.82,0.58)*3.0, amb=vec3(0.31,0.3,0.31)*(0.62+0.38*n.y)*oc, bounce=vec3(0.32,0.24,0.16)*0.35*oc*max(-n.y*0.5+0.5,0.);\n  amb*=0.82+0.3*smoothstep(1.8,-1.4,p.x-p.y*0.6);\n  vec3 alb; float spec=0., rough=0.9, metal=0.;\n  if(id<0.5){\n    float g=fbm(p.xy*9.)*0.6+fbm(p.xy*42.)*0.4;\n    vec2 e=vec2(0.004,0.); float gx=fbm((p.xy+e)*42.)-fbm((p.xy-e)*42.), gy=fbm((p.xy+e.yx)*42.)-fbm((p.xy-e.yx)*42.);\n    n=normalize(n+vec3(-gx,-gy,0.)*0.55); dl=max(dot(n,L),0.);\n    alb=vec3(0.78,0.71,0.6)*(0.9+0.16*g);\n  } else if(id<1.5){\n    float gr=fbm(vec2(p.x*3.,p.y*90.+fbm(p.xy*6.)*4.));\n    alb=mix(vec3(0.36,0.22,0.12),vec3(0.55,0.37,0.2),gr); spec=0.3; rough=0.45;\n  } else if(id<2.5){\n    alb=vec3(0.85,0.64,0.34); metal=1.; rough=0.28+0.15*fbm(p.xy*80.); spec=1.;\n  } else {\n    int ti=int(floor((id-10.)/10.)); float part=id-10.-float(ti)*10.;\n    vec3 l=tagLocal(p,ti); vec3 pap=uPaper[ti];\n    float fib=fbm(l.xy*160.)*0.5+fbm(l.xy*30.)*0.5;\n    alb=pap*(0.93+0.1*fib); rough=0.85; spec=0.06;\n    vec2 a=vec2(-1.);\n    float x=(l.x/(2.*HW)+0.5)*CWp+float(ti)*CWp;\n    if(part<0.5){ if(l.z>0.) a=vec2(x,(PT-l.y)*Sp); }\n    else if(part<1.5){ vec2 f=flapUV(l,uTag[ti]); a= f.y>0. ? vec2(x,(0.5+f.x)*Sp) : vec2(x,QT+(FL-f.x)*Sp); }\n    else if(part<3.5){ alb= part>2.5 ? vec3(0.86,0.8,0.68) : alb; }\n    else { alb=vec3(0.62,0.5,0.36)*(0.8+0.3*fbm(vec2(l.y*300.,l.x*40.))); rough=1.; }\n    alb*=mix(0.72,1.,smoothstep(0.15,0.6,abs(n.z)));\n    if(a.x>=0.){ vec4 ink=texture(uAtlas,a/vec2(AW,AH)); alb=mix(alb,ink.rgb*(0.85+0.2*fib),ink.a); }\n  }\n  vec3 dif=alb*(sunC*dl*sh*sm+amb+bounce);\n  if(id>9.5){ float tr=max(dot(-n,L),0.)*sm*sh; dif+=alb*alb*sunC*tr*0.35; }\n  vec3 r=reflect(rd,n), hv=normalize(L-rd);\n  float fr=0.04+0.96*pow(1.-max(dot(n,-rd),0.),5.);\n  float g=pow(max(dot(n,hv),0.),2./(rough*rough*rough+0.002));\n  if(metal>0.5){ dif=alb*(env(r)*mix(0.35,1.,oc)+sunC*g*sh*sm*0.5*(1.-rough))+alb*amb*0.25; }\n  else dif+=spec*(fr*env(r)*0.25*oc+sunC*g*sh*sm*0.08);\n  col=dif;\n  float hz=smoothstep(-0.2,1.0,sm)*0.0; col+=hz;\n  col*=1.0-0.28*dot(uv*vec2(0.8,1.),uv*vec2(0.8,1.));\n  col=(col*(2.51*col+0.03))/(col*(2.43*col+0.59)+0.14);\n  col=pow(clamp(col,0.,1.),vec3(1./2.2));\n  col+=(h21(gl_FragCoord.xy+fract(uTime)*91.)-0.5)*0.022;\n  o=vec4(col,1.);\n}`;\n\nfunction wrap(ctx: CanvasRenderingContext2D, text: string, max: number) {\n  const out: string[] = [];\n  let line = \"\";\n  for (const w of text.split(\" \")) {\n    const t = line ? line + \" \" + w : w;\n    if (ctx.measureText(t).width > max && line) {\n      out.push(line);\n      line = w;\n    } else line = t;\n  }\n  if (line) out.push(line);\n  return out;\n}\n\nconst SERIF = '\"Iowan Old Style\", \"Palatino Linotype\", Palatino, \"Book Antiqua\", Georgia, serif';\n\n/** Prints every question and answer onto one texture the shader reads from. */\nfunction makeAtlas() {\n  const c = document.createElement(\"canvas\");\n  c.width = CW * N;\n  c.height = AH;\n  const g = c.getContext(\"2d\")!;\n  const ink = \"rgba(30,23,18,1)\";\n  const red = \"rgba(128,46,34,1)\";\n  tags.forEach((t, i) => {\n    const x0 = i * CW;\n    const pad = 34;\n    const no = `No. ${String(i + 1).padStart(2, \"0\")}`;\n    // inside spread: answer\n    g.fillStyle = red;\n    g.font = `600 17px ${SERIF}`;\n    g.letterSpacing = \"3px\";\n    g.fillText(\"ANSWER\", x0 + pad, 0.17 * S);\n    g.textAlign = \"right\";\n    g.fillText(no.toUpperCase(), x0 + CW - pad, 0.17 * S);\n    g.textAlign = \"left\";\n    g.letterSpacing = \"0px\";\n    g.fillStyle = ink;\n    g.fillRect(x0 + pad, 0.17 * S + 14, CW - pad * 2, 2);\n    g.font = `500 33px ${SERIF}`;\n    wrap(g, t.a, CW - pad * 2).forEach((ln, k) => g.fillText(ln, x0 + pad, 0.17 * S + 66 + k * 42));\n    g.font = `italic 400 19px ${SERIF}`;\n    g.fillStyle = \"rgba(40,31,24,0.75)\";\n    g.fillText(SHOP, x0 + pad, 0.86 * S);\n    // outside of the flap: question\n    const q0 = QTOP;\n    g.strokeStyle = ink;\n    g.lineWidth = 2;\n    g.strokeRect(x0 + 20, q0 + 18, CW - 40, 0.4 * S - 36);\n    g.lineWidth = 1;\n    g.strokeRect(x0 + 27, q0 + 25, CW - 54, 0.4 * S - 50);\n    g.fillStyle = red;\n    g.beginPath();\n    g.arc(x0 + CW - 64, q0 + 70, 26, 0, Math.PI * 2);\n    g.lineWidth = 2.5;\n    g.strokeStyle = red;\n    g.stroke();\n    g.font = `700 19px ${SERIF}`;\n    g.textAlign = \"center\";\n    g.fillText(String(i + 1).padStart(2, \"0\"), x0 + CW - 64, q0 + 77);\n    g.textAlign = \"left\";\n    g.fillStyle = ink;\n    g.font = `700 42px ${SERIF}`;\n    wrap(g, t.q, CW - 2 * pad - 64).forEach((ln, k) => g.fillText(ln, x0 + pad + 6, q0 + 92 + k * 48));\n    g.font = `600 14px ${SERIF}`;\n    g.letterSpacing = \"3px\";\n    g.fillStyle = \"rgba(40,31,24,0.7)\";\n    g.fillText(\"UNFOLD TO READ\", x0 + pad + 6, q0 + 0.4 * S - 46);\n    g.letterSpacing = \"0px\";\n  });\n  return c;\n}\n\ntype Tag = { s: number; sv: number; b: number; bv: number; t: number; tv: number };\n\nfunction camera(aspect: number) {\n  const halfW = 1.46;\n  const halfH = 0.57;\n  const D = Math.max((halfW * F) / (0.5 * aspect), (halfH * F) / 0.5);\n  const ta = [0.05, 0.62, 0.08];\n  const dir = [0.17, 0.1, 1];\n  const len = Math.hypot(dir[0], dir[1], dir[2]);\n  const ro = ta.map((v, k) => v + (dir[k] / len) * D);\n  return { ro, ta };\n}\n\nexport default function FoldedPaperTagFaq() {\n  const reduce = useReducedMotion();\n  const [open, setOpen] = useState<number | null>(START_OPEN);\n  const [webgl, setWebgl] = useState(true);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const openRef = useRef<number | null>(START_OPEN);\n  const userRef = useRef(false);\n  const pokeRef = useRef<() => void>(() => {});\n  const fpsRef = useRef(0);\n\n  const choose = (i: number) => {\n    userRef.current = true;\n    setOpen((cur) => (cur === i ? null : i));\n  };\n\n  useEffect(() => {\n    openRef.current = open;\n    pokeRef.current();\n  }, [open]);\n\n  // self-playing demo: walks along the hooks until someone takes over\n  useEffect(() => {\n    if (reduce) return;\n    const id = window.setInterval(() => {\n      if (userRef.current) return;\n      setOpen((cur) => ((cur ?? -1) + 1) % N);\n    }, DEMO_EVERY);\n    return () => window.clearInterval(id);\n  }, [reduce]);\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    if (!canvas) return;\n    const gl = canvas.getContext(\"webgl2\", { antialias: false, alpha: false, powerPreference: \"high-performance\" });\n    if (!gl) {\n      setWebgl(false);\n      return;\n    }\n    const sh = (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    let prog: WebGLProgram;\n    try {\n      prog = gl.createProgram()!;\n      gl.attachShader(prog, sh(gl.VERTEX_SHADER, VERT));\n      gl.attachShader(prog, sh(gl.FRAGMENT_SHADER, FRAG));\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      setWebgl(false);\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, \"aP\");\n    gl.enableVertexAttribArray(loc);\n    gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);\n    const tex = gl.createTexture();\n    gl.bindTexture(gl.TEXTURE_2D, tex);\n    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, makeAtlas());\n    gl.generateMipmap(gl.TEXTURE_2D);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n    const U = (n: string) => gl.getUniformLocation(prog, n);\n    const uRes = U(\"uRes\"), uTime = U(\"uTime\"), uTag = U(\"uTag\"), uPaper = U(\"uPaper\"), uRo = U(\"uRo\"), uTa = U(\"uTa\");\n    gl.uniform1i(U(\"uAtlas\"), 0);\n    gl.uniform3fv(uPaper, new Float32Array(tags.flatMap((t) => t.paper)));\n\n    const st: Tag[] = tags.map((_, i) => ({ s: 0.02 * Math.sin(i * 2.1), sv: 0, b: i === openRef.current ? 0.12 : Math.PI, bv: 0, t: 0, tv: 0 }));\n    let scale = 1;\n    let w = 0, h = 0, aspect = 4 / 3;\n    const resize = () => {\n      const r = canvas.getBoundingClientRect();\n      const dpr = Math.min(window.devicePixelRatio || 1, 1.5);\n      const budget = 1.1e6;\n      const k = Math.min(dpr * scale, Math.sqrt(budget / Math.max(1, r.width * r.height)));\n      w = Math.max(2, Math.round(r.width * k));\n      h = Math.max(2, Math.round(r.height * k));\n      canvas.width = w;\n      canvas.height = h;\n      aspect = r.width / Math.max(1, r.height);\n      gl.viewport(0, 0, w, h);\n      draw(lastT);\n    };\n\n    let lastT = 0;\n    const draw = (time: number) => {\n      const cam = camera(aspect);\n      gl.uniform2f(uRes, w, h);\n      gl.uniform1f(uTime, time);\n      gl.uniform3fv(uRo, cam.ro);\n      gl.uniform3fv(uTa, cam.ta);\n      gl.uniform4fv(uTag, new Float32Array(st.flatMap((q) => [q.s, q.b, q.t, Math.max(-0.5, Math.min(0.5, q.bv * 0.05))])));\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n    };\n\n    const step = (dt: number, time: number) => {\n      st.forEach((q, i) => {\n        const want = openRef.current === i;\n        let acc: number;\n        if (want) acc = -60 * Math.sin(q.b) + 2.6 * (Math.PI - q.b) - 1.5 * q.bv;\n        else acc = 150 * (Math.PI - q.b) - 11 * q.bv - 20 * Math.sin(q.b);\n        q.bv += acc * dt;\n        q.b += q.bv * dt;\n        if (q.b > Math.PI) {\n          q.b = Math.PI;\n          if (q.bv > 0) {\n            q.sv += q.bv * 0.012 * (i % 2 ? 1 : -1);\n            q.bv *= -0.28;\n          }\n        }\n        if (q.b < 0.02) {\n          q.b = 0.02;\n          q.bv = Math.abs(q.bv) * 0.3;\n        }\n        const breeze = 0.014 * Math.sin(time * 0.7 + i * 1.3) + 0.006 * Math.sin(time * 1.9 + i);\n        q.sv += (-17 * (q.s - breeze) - 0.9 * q.sv - q.bv * 0.02 * Math.cos(q.b)) * dt;\n        q.s += q.sv * dt;\n        q.tv += (-10 * q.t - 1.2 * q.tv + 0.04 * acc * dt * 10 * (i % 2 ? 1 : -1) * 0.02) * dt;\n        q.t += q.tv * dt;\n      });\n    };\n\n    const kick = () => {\n      st.forEach((q, i) => {\n        const want = openRef.current === i;\n        if (want && q.b > 3.0 && Math.abs(q.bv) < 0.5) {\n          q.bv = 0.9; // the flap lifts off its crease for a moment before it drops\n          q.tv += 0.5 * (i % 2 ? 1 : -1);\n        }\n        if (!want && q.b < 3.0) q.sv += 0.25 * (i % 2 ? -1 : 1);\n      });\n    };\n\n    let raf = 0;\n    let visible = true;\n    let prev = performance.now();\n    let frames = 0, fpsT = prev, slow = 0;\n    const loop = (now: number) => {\n      raf = 0;\n      const dt = Math.min(0.05, (now - prev) / 1000);\n      prev = now;\n      lastT = now / 1000;\n      const sub = Math.ceil(dt / (1 / 240));\n      for (let k = 0; k < sub; k++) step(dt / sub, lastT);\n      draw(lastT);\n      frames++;\n      if (now - fpsT > 1000) {\n        fpsRef.current = (frames * 1000) / (now - fpsT);\n        canvas.dataset.fps = fpsRef.current.toFixed(1);\n        if (fpsRef.current < 40 && scale > 0.6) {\n          slow++;\n          if (slow >= 2) {\n            scale = Math.max(0.6, scale - 0.15);\n            slow = 0;\n            resize();\n          }\n        } else slow = 0;\n        frames = 0;\n        fpsT = now;\n      }\n      if (visible) raf = requestAnimationFrame(loop);\n    };\n    const start = () => {\n      if (reduce) return;\n      if (!raf && visible) {\n        prev = performance.now();\n        raf = requestAnimationFrame(loop);\n      }\n    };\n    pokeRef.current = () => {\n      if (reduce) {\n        st.forEach((q, i) => {\n          q.b = openRef.current === i ? 0.12 : Math.PI;\n          q.bv = 0;\n        });\n        draw(lastT);\n      } else kick();\n    };\n\n    // pointer shortcut: press a tag in the picture\n    const hit = (ev: PointerEvent | MouseEvent) => {\n      const r = canvas.getBoundingClientRect();\n      const ux = (ev.clientX - r.left - r.width / 2) / r.height;\n      const uy = -(ev.clientY - r.top - r.height / 2) / r.height;\n      const { ro, ta } = camera(aspect);\n      const fw = ta.map((v, k) => v - ro[k]);\n      const fl = Math.hypot(fw[0], fw[1], fw[2]);\n      const f = fw.map((v) => v / fl);\n      const rtRaw = [-f[2], 0, f[0]];\n      const rl = Math.hypot(rtRaw[0], rtRaw[2]);\n      const rt = rtRaw.map((v) => v / rl);\n      const up = [rt[1] * f[2] - rt[2] * f[1], rt[2] * f[0] - rt[0] * f[2], rt[0] * f[1] - rt[1] * f[0]];\n      const rd = [0, 1, 2].map((k) => f[k] * F + rt[k] * ux + up[k] * uy);\n      const tt = (HZ - ro[2]) / rd[2];\n      const x = ro[0] + rd[0] * tt, y = ro[1] + rd[1] * tt;\n      const i = Math.round(x / SP) + 2;\n      if (i < 0 || i >= N || Math.abs(x - (i - 2) * SP) > HW + 0.03) return -1;\n      if (y > HOOKY + 0.05 || y < HOOKY - LS - 0.9) return -1;\n      return i;\n    };\n    const onClick = (e: MouseEvent) => {\n      const i = hit(e);\n      if (i >= 0) choose(i);\n    };\n    const onMove = (e: PointerEvent) => {\n      const i = hit(e);\n      canvas.style.cursor = i >= 0 ? \"pointer\" : \"default\";\n      if (i >= 0 && !reduce) st[i].sv += 0.012 * Math.sign(e.movementX || 0);\n    };\n    canvas.addEventListener(\"click\", onClick);\n    canvas.addEventListener(\"pointermove\", onMove);\n\n    const ro = new ResizeObserver(resize);\n    ro.observe(canvas);\n    resize();\n    const io = new IntersectionObserver(([e]) => {\n      visible = e.isIntersecting && !document.hidden;\n      if (visible) start();\n    });\n    io.observe(canvas);\n    const onVis = () => {\n      visible = !document.hidden;\n      if (visible) start();\n    };\n    document.addEventListener(\"visibilitychange\", onVis);\n    start();\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", onVis);\n      canvas.removeEventListener(\"click\", onClick);\n      canvas.removeEventListener(\"pointermove\", onMove);\n      pokeRef.current = () => {};\n      gl.deleteTexture(tex);\n      gl.deleteBuffer(buf);\n      gl.deleteProgram(prog);\n    };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [reduce]);\n\n  return (\n    <section className=\"relative overflow-hidden bg-[#e6dccb] text-[#2a221b]\">\n      <div className=\"mx-auto grid max-w-6xl items-start gap-8 px-4 py-12 sm:px-6 lg:grid-cols-[1.45fr_1fr] lg:gap-12 lg:py-16\">\n        <div className=\"relative aspect-[4/3] w-full overflow-hidden rounded-[4px] bg-[#cdbfa8] shadow-[0_1px_0_rgba(255,255,255,0.5)_inset,0_30px_60px_-30px_rgba(60,40,20,0.45)]\">\n          {webgl ? (\n            <canvas ref={canvasRef} aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full\" />\n          ) : (\n            <StillWall open={open} />\n          )}\n        </div>\n        <div>\n          <p className=\"text-[12px] font-semibold uppercase tracking-[0.22em] text-[#7a3326]\">{SHOP}</p>\n          <h2\n            className=\"mt-3 text-[40px] leading-[1.02] tracking-[-0.02em] sm:text-[52px]\"\n            style={{ fontFamily: SERIF, fontWeight: 600 }}\n          >\n            Asked at the counter\n          </h2>\n          <p className=\"mt-4 max-w-sm text-[15px] leading-relaxed text-[#5a4c3e]\">\n            Pick a tag to let it fall open. The same answer is printed inside the paper.\n          </p>\n          <ul className=\"mt-7 border-t border-[#2a221b]/20\">\n            {tags.map((t, i) => {\n              const isOpen = open === i;\n              return (\n                <li key={t.q} className=\"border-b border-[#2a221b]/20\">\n                  <h3>\n                    <button\n                      type=\"button\"\n                      aria-expanded={isOpen}\n                      aria-controls={`fptf-a-${i}`}\n                      onClick={() => choose(i)}\n                      className=\"flex min-h-[48px] w-full items-center gap-4 py-3 text-left text-[17px] leading-snug transition-colors hover:text-[#7a3326] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#7a3326] focus-visible:ring-offset-2 focus-visible:ring-offset-[#e6dccb]\"\n                      style={{ fontFamily: SERIF }}\n                    >\n                      <span className=\"w-7 shrink-0 text-[13px] tabular-nums tracking-[0.1em] text-[#7a3326]\">\n                        {String(i + 1).padStart(2, \"0\")}\n                      </span>\n                      <span className=\"flex-1 font-semibold\">{t.q}</span>\n                      <svg\n                        aria-hidden=\"true\"\n                        viewBox=\"0 0 20 20\"\n                        className={`h-4 w-4 shrink-0 transition-transform duration-300 ${isOpen ? \"rotate-180\" : \"\"}`}\n                      >\n                        <path d=\"M5 8l5 5 5-5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n                      </svg>\n                    </button>\n                  </h3>\n                  <AnimatePresence initial={false}>\n                    {isOpen && (\n                      <motion.div\n                        id={`fptf-a-${i}`}\n                        role=\"region\"\n                        aria-label={t.q}\n                        initial={reduce ? false : { height: 0, opacity: 0 }}\n                        animate={{ height: \"auto\", opacity: 1 }}\n                        exit={reduce ? { opacity: 0 } : { height: 0, opacity: 0 }}\n                        transition={{ duration: reduce ? 0 : 0.35, ease: [0.22, 1, 0.36, 1] }}\n                        className=\"overflow-hidden\"\n                      >\n                        <p className=\"pb-4 pl-11 pr-6 text-[15px] leading-relaxed text-[#4a3e33]\">{t.a}</p>\n                      </motion.div>\n                    )}\n                  </AnimatePresence>\n                </li>\n              );\n            })}\n          </ul>\n        </div>\n      </div>\n    </section>\n  );\n}\n\n/** Shown when the browser has no WebGL 2: the same wall, drawn with plain CSS. */\nfunction StillWall({ open }: { open: number | null }) {\n  return (\n    <div\n      className=\"absolute inset-0\"\n      style={{\n        background:\n          \"linear-gradient(160deg,#a89a88,#8c7f70)\",\n      }}\n    >\n      <div className=\"absolute left-[20%] top-[8%] grid h-[66%] w-[74%] grid-cols-2 gap-[3%] opacity-80 blur-[3px]\">\n        {[0, 1, 2, 3].map((k) => (\n          <div key={k} className=\"bg-[#f6e4bf]/70\" />\n        ))}\n      </div>\n      <div className=\"absolute left-[9%] right-[9%] top-[24%] h-[4.5%] rounded-[3px] bg-gradient-to-b from-[#c79a62] to-[#8f6438] shadow-[6px_8px_8px_rgba(50,30,15,0.35)]\" />\n      <div className=\"absolute inset-x-[11%] top-[26%] flex justify-between\">\n        {tags.map((t, i) => {\n          const c = `rgb(${t.paper.map((v) => Math.round(Math.min(255, v * 290))).join(\",\")})`;\n          const isOpen = open === i;\n          return (\n            <div key={t.q} className=\"flex w-[16%] flex-col items-center\" style={{ filter: \"drop-shadow(10px 14px 6px rgba(60,40,20,0.3))\" }}>\n              <div className=\"h-3 w-3 rounded-full bg-[#d0a865]\" />\n              <div className=\"h-6 w-px bg-[#8a7258]\" />\n              <div\n                className=\"relative w-full px-2 pb-2 pt-6 text-[8px] leading-tight text-[#2a221b] sm:text-[11px]\"\n                style={{\n                  background: c,\n                  aspectRatio: isOpen ? \"0.44\" : \"0.8\",\n                  clipPath: \"polygon(25% 0,75% 0,100% 13%,100% 100%,0 100%,0 13%)\",\n                  fontFamily: SERIF,\n                }}\n              >\n                <span className=\"absolute left-1/2 top-[5%] h-2 w-2 -translate-x-1/2 rounded-full border border-[#efe6d4] bg-[#5a4c3e]\" />\n                {isOpen && <span className=\"absolute inset-x-0 top-[55%] h-px bg-black/15\" />}\n                <span className={isOpen ? \"font-normal\" : \"font-semibold\"}>{isOpen ? t.a : t.q}</span>\n              </div>\n            </div>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n"}]}
