{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"brushed-titanium-membership-card-in-webgl-rocking-on-a-stone-tray-in-window-light-with-an-anisotropic-sheen-and-laser-etched-type","type":"registry:block","title":"Brushed Titanium Membership Card in WebGL Rocking on a Stone Tray in Window Light with an Anisotropic Sheen and Laser Etched Type","description":"Free React WebGL card: brushed titanium with laser-etched type, rocking in a pale stone tray under window light. Tilt it to sweep the sheen, click to flip it.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/brushed-titanium-membership-card-in-webgl-rocking-on-a-stone-tray-in-window-light-with-an-anisotropic-sheen-and-laser-etched-type.tsx","type":"registry:component","content":"import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n/** Everything etched into the card. Change the words here and the laser follows. */\nconst card = {\n  house: \"TESSERA\",\n  tier: \"RESERVE\",\n  number: \"1234 5678 9012 3456\", // a placeholder, not a real card number\n  memberLabel: \"MEMBER\",\n  member: \"ILSE MARROW\",\n  validLabel: \"VALID THRU\",\n  valid: \"09/31\",\n  serial: \"No. 0417\",\n  signature: \"Ilse Marrow\",\n  small: [\n    \"This card belongs to Tessera Reserve. If you find it,\",\n    \"please hand it in at any Tessera house or write to members@tessera.example\",\n  ],\n};\nconst sides = [\n  { tag: \"Face\", title: \"Ilse Marrow\" },\n  { tag: \"Reverse\", title: \"Signed and numbered\" },\n];\n\nconst TILT = 0.2; // how far the card rocks toward the pointer, in radians\nconst SPRING = 60; // pull toward the pose it is asked for\nconst DAMPING = 8.5; // lower for more wobble\nconst FLIP_SPRING = 26;\nconst FLIP_DAMPING = 5.2; // lower for more overshoot when it turns over\nconst REST_YAW = -0.1; // the card lies a little askew in the tray\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 clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));\n\n// The card, in metres of a scene where it is 1.6 wide: the 85.6 by 54 mm proportion, a 1 mm plate.\nconst HX = 0.8;\nconst HY = 0.5047;\nconst HT = 0.011;\nconst CR = 0.06;\nconst TW = 1600;\nconst TH = 1010;\n\nconst GLSL_HEAD = `#version 300 es\nprecision highp float;\nprecision highp sampler2DArray;\nconst vec2 HS = vec2(${HX}, ${HY});\nconst float CR = ${CR};\nconst vec3 SUN = vec3(-0.4196, 0.6594, -0.6237);\nconst vec3 SUNC = vec3(1.0, 0.92, 0.80);\nconst vec3 SKY = vec3(0.56, 0.64, 0.78);\nconst float WZ = -3.2;\nuniform vec3 uC, uU, uV, uN;\nuniform sampler2DArray uMat;\nuniform vec3 uCam, uRt, uUp, uFw;\nuniform float uTan, uAspect, uFocus, uAperture, uTime;\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); }\nfloat sdCard(vec2 p) { vec2 q = abs(p) - HS + CR; return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - CR; }\n\n// a box rounded in plan by rx and along every edge by re\nfloat sdRR(vec3 p, vec3 b, float rx, float re) {\n  vec2 q = abs(p.xz) - b.xz + rx;\n  float d2 = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - rx;\n  vec2 w = vec2(d2 + re, abs(p.y) - b.y + re);\n  return min(max(w.x, w.y), 0.0) + length(max(w, 0.0)) - re;\n}\n// the stone tray: a honed slab with a shallow pocket cut into it, the pocket floor at y = 0\nfloat sdTray(vec3 p) {\n  float o = sdRR(p - vec3(0.0, 0.0025, 0.0), vec3(1.3, 0.0625, 0.92), 0.17, 0.022);\n  float i = sdRR(p - vec3(0.0, 0.2, 0.0), vec3(1.12, 0.2, 0.74), 0.09, 0.045);\n  return max(o, -i);\n}\nfloat softShadow(vec3 ro, vec3 ld) {\n  float res = 1.0, t = 0.004;\n  for (int i = 0; i < 28; i++) {\n    float h = sdTray(ro + ld * t);\n    res = min(res, 12.0 * h / t);\n    t += clamp(h, 0.006, 0.12);\n    if (res < 0.002 || t > 2.2) break;\n  }\n  return clamp(res, 0.0, 1.0);\n}\n// the window behind the tray: follow the sun back to its glass and see whether a glazing bar is in the way\nfloat pane(vec3 P) {\n  float t = (WZ - P.z) / SUN.z;\n  vec3 q = P + SUN * t;\n  float w = 0.0093 * t + 0.004;\n  float open = smoothstep(-w, w, q.x + 5.5) * smoothstep(-w, w, 3.0 - q.x) * smoothstep(-w, w, q.y - 1.0) * smoothstep(-w, w, 9.0 - q.y);\n  return open * smoothstep(0.05 - w, 0.05 + w, abs(q.x + 1.0)) * smoothstep(0.045 - w, 0.045 + w, abs(q.y - 2.7));\n}\n// the room as a mirror sees it: limewashed walls, a bright ceiling, the tall window and its bars, the table below\nvec3 room(vec3 ro, vec3 rd, float s) {\n  vec3 c = mix(vec3(0.12, 0.115, 0.11), vec3(0.3, 0.3, 0.3), smoothstep(-0.05, 0.85, rd.y));\n  c += vec3(0.3, 0.28, 0.25) * smoothstep(0.3, 0.95, dot(rd, normalize(vec3(0.9, 0.35, 0.1)))); // a lit wall on the right\n  if (rd.z < -0.02) {\n    float t = (WZ - ro.z) / rd.z;\n    vec3 q = ro + rd * t;\n    float w = s * t + 0.012;\n    // the mirror sees the nearest bay of the window: two lights wide, with a sill and a head\n    float open = smoothstep(-w, w, q.x + 1.9) * smoothstep(-w, w, 0.5 - q.x) * smoothstep(-w, w, q.y - 1.0) * smoothstep(-w, w, 4.5 - q.y);\n    float bars = smoothstep(0.05 - w, 0.05 + w, abs(q.x + 1.0)) * smoothstep(0.045 - w, 0.045 + w, abs(q.y - 2.7));\n    vec3 sky = mix(vec3(1.0, 0.97, 0.92), vec3(0.7, 0.8, 1.0), smoothstep(1.0, 4.5, q.y)) * 5.0;\n    c = mix(c, sky, open * bars);\n  }\n  if (rd.y < 0.0) c = mix(c, vec3(0.3, 0.28, 0.25), smoothstep(0.0, -0.12, rd.y));\n  return c;\n}\n\n// how much of a round lamp at L a point P can see past the card\nfloat lit(vec3 P, vec3 L, float rl) {\n  vec3 d = L - P;\n  float dn = dot(d, uN);\n  if (abs(dn) < 1e-5) return 1.0;\n  float t = dot(uC - P, uN) / dn;\n  if (t <= 0.0 || t >= 1.0) return 1.0;\n  vec3 q = P + d * t - uC;\n  float w = rl * t + 0.002;\n  return smoothstep(-w, w, sdCard(vec2(dot(q, uU), dot(q, uV))));\n}\n\nvec3 tonemap(vec3 x) { x *= 0.74; return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0); }\nvec4 pack(vec3 col, float depth) {\n  float coc = clamp(uAperture * (1.0 - uFocus / max(depth, 0.05)), -1.0, 1.0);\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_SET = `${GLSL_HEAD}\nin vec2 vUv;\nout vec4 o;\nvec3 trayN(vec3 p) {\n  const vec2 k = vec2(1.0, -1.0);\n  const float e = 0.0012;\n  return normalize(k.xyy * sdTray(p + k.xyy * e) + k.yyx * sdTray(p + k.yyx * e) + k.yxy * sdTray(p + k.yxy * e) + k.xxx * sdTray(p + k.xxx * e));\n}\nfloat occ(vec3 p, vec3 n) {\n  float a = 0.0, w = 1.0;\n  for (int i = 1; i <= 5; i++) {\n    float h = 0.012 * float(i * i);\n    a += w * (h - min(sdTray(p + n * h), p.y + 0.06 + n.y * h));\n    w *= 0.6;\n  }\n  return clamp(1.0 - 3.2 * a, 0.0, 1.0);\n}\n// pale travertine: soft bands laid down along its length, a few open pores, a honed (not polished) face\nvec3 stone(vec3 P) {\n  float warp = fbm(P.xz * vec2(1.4, 2.2) + 4.0);\n  float band = fbm(vec2(P.x * 0.7 + warp * 0.9, P.z * 5.5 + P.y * 9.0 + warp * 2.4));\n  vec3 c = mix(vec3(0.66, 0.6, 0.52), vec3(0.87, 0.835, 0.775), smoothstep(0.3, 0.7, band));\n  c = mix(c, vec3(0.78, 0.7, 0.6), 0.35 * smoothstep(0.55, 0.8, fbm(P.xz * vec2(0.6, 3.5) + 9.0)));\n  c *= 0.965 + 0.05 * vnoise(P.xz * 70.0 + P.y * 50.0);\n  vec2 pq = P.xz * vec2(34.0, 95.0) + P.y * 60.0 + vec2(fbm(P.xz * 9.0), 0.0) * 3.0;\n  float pore = smoothstep(0.84, 0.95, vnoise(pq)) * smoothstep(0.4, 0.7, vnoise(P.xz * 4.0 + 2.0));\n  return c * (1.0 - 0.3 * pore);\n}\nvoid main() {\n  vec2 ndc = vUv * 2.0 - 1.0;\n  vec3 ro = uCam;\n  vec3 rd = normalize(uFw + uRt * (ndc.x * uTan * uAspect) + uUp * (ndc.y * uTan));\n  float tHit = -1.0;\n  vec3 bmin = vec3(-1.31, -0.062, -0.93), bmax = vec3(1.31, 0.068, 0.93);\n  vec3 inv = 1.0 / rd;\n  vec3 ta = (bmin - ro) * inv, tb = (bmax - ro) * inv;\n  vec3 tmn = min(ta, tb), tmx = max(ta, tb);\n  float tn = max(max(tmn.x, tmn.y), tmn.z), tf = min(min(tmx.x, tmx.y), tmx.z);\n  if (tf > max(tn, 0.0)) {\n    float t = max(tn, 0.0);\n    for (int i = 0; i < 80; i++) {\n      float d = sdTray(ro + rd * t);\n      if (d < 0.00025 * t) { tHit = t; break; }\n      t += d;\n      if (t > tf) break;\n    }\n  }\n  bool tray = tHit > 0.0;\n  if (!tray) {\n    if (rd.y >= -1e-3) { o = pack(room(ro, rd, 0.1), 80.0); return; }\n    tHit = (-0.06 - ro.y) / rd.y;\n  }\n  vec3 P = ro + rd * tHit;\n  vec3 n = tray ? trayN(P) : vec3(0.0, 1.0, 0.0);\n  vec3 alb = tray ? stone(P) : vec3(0.3, 0.255, 0.205) * (0.9 + 0.16 * fbm(P.xz * vec2(1.2, 9.0))) * (0.95 + 0.08 * vnoise(P.xz * vec2(40.0, 400.0)));\n\n  // sun through the window: blocked by the glazing bars, the tray's own rim and the card\n  float sv = max(dot(n, SUN), 0.0) * pane(P) * softShadow(P + n * 0.002, SUN) * lit(P, P + SUN * 20.0, 0.5);\n  // the sky through the same window, and the room, both partly hidden under the card\n  float ao = occ(P, n);\n  float under = mix(1.0, lit(P, P + vec3(-0.6, 2.4, -1.6), 2.6), 0.85);\n  vec3 amb = SKY * (0.42 + 0.22 * n.y) * ao * under + vec3(0.2, 0.17, 0.13) * 0.25 * ao;\n  vec3 col = alb * (SUNC * 2.5 * sv + amb);\n  // honed stone keeps a faint sheen where the window lands\n  vec3 V = -rd;\n  float F = 0.03 + 0.97 * pow(1.0 - max(dot(n, V), 0.0), 5.0);\n  col += F * room(P, reflect(rd, n), 0.35) * 0.35 * ao * under;\n  col += SUNC * sv * 0.25 * pow(max(dot(n, normalize(SUN + V)), 0.0), 60.0);\n  o = pack(col, dot(rd, uFw) * tHit);\n}`;\n\nconst VS_CARD = `#version 300 es\nprecision highp float;\nlayout(location = 0) in vec3 aPos;\nlayout(location = 1) in vec3 aNor;\nuniform vec3 uC, uU, uV, uN, uCam, uRt, uUp, uFw;\nuniform float uTan, uAspect;\nout vec3 vW; out vec3 vL; out vec3 vNl;\nvoid main() {\n  vW = uC + uU * aPos.x + uV * aPos.y + uN * aPos.z;\n  vL = aPos; vNl = aNor;\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 * 30.1 - 6.0) / 29.9, z);\n}`;\n\nconst FS_CARD = `${GLSL_HEAD}\nin vec3 vW; in vec3 vL; in vec3 vNl;\nout vec4 o;\nconst vec3 TI = vec3(0.56, 0.535, 0.50); // titanium, a touch warmer and darker than steel\nvoid main() {\n  vec3 V = normalize(uCam - vW);\n  vec3 nl = normalize(vNl);\n  vec3 Ng = normalize(uU * nl.x + uV * nl.y + uN * nl.z);\n  float face = smoothstep(0.75, 0.98, abs(nl.z));\n  float side = vL.z > 0.0 ? 1.0 : -1.0;\n  float vis = pane(vW) * softShadow(vW + Ng * 0.004, SUN);\n\n  // the edge: a polished chamfer, an ordinary mirror\n  vec3 Re = reflect(-V, Ng);\n  float Fe = pow(1.0 - max(dot(Ng, V), 0.0), 5.0);\n  vec3 edge = mix(TI, vec3(1.0), Fe) * (room(vW, Re, 0.02) * 0.9 + SUNC * 3.0 * vis * 6.0 * pow(max(dot(Ng, normalize(SUN + V)), 0.0), 120.0));\n  vec3 col = edge;\n\n  if (face > 0.0) {\n    vec2 uv = vL.xy / HS * 0.5 + 0.5;\n    if (side < 0.0) uv.x = 1.0 - uv.x;\n    float layer = side > 0.0 ? 0.0 : 1.0;\n    vec3 m = texture(uMat, vec3(uv, layer)).rgb;\n    // the etch sits a hair below the plate, so its walls catch light\n    vec2 e = vec2(1.4 / ${TW}.0, 1.4 / ${TH}.0);\n    float hx = texture(uMat, vec3(uv + vec2(e.x, 0.0), layer), 0.5).g - texture(uMat, vec3(uv - vec2(e.x, 0.0), layer), 0.5).g;\n    float hy = texture(uMat, vec3(uv + vec2(0.0, e.y), layer), 0.5).g - texture(uMat, vec3(uv - vec2(0.0, e.y), layer), 0.5).g;\n    vec2 g = vec2(hx, hy) * 3.0 * clamp(1.4 / (fwidth(uv.x) * ${TW}.0), 0.0, 1.0);\n    float etch = smoothstep(0.1, 0.6, m.r);\n    float pol = m.b;\n    vec2 pp = vL.xy * vec2(side, 1.0);\n\n    // brushing: fine grooves run along the card's length, so the surface only tilts across them\n    float fade = clamp(1.0 / (fwidth(pp.y) * 900.0) - 0.4, 0.0, 1.0);\n    float gro = (vnoise(vec2(pp.x * 3.0, pp.y * 900.0)) - 0.5) * fade + (vnoise(vec2(pp.x * 1.3 + 9.0, pp.y * 260.0)) - 0.5) * 0.8;\n    float slow = fbm(pp * 2.2 + 3.0) - 0.5;\n    vec2 tiltL = -g + vec2(0.0, gro * 0.035 + slow * 0.03) * (1.0 - pol);\n    vec3 N = normalize(Ng + uU * (tiltL.x * side) + uV * tiltL.y);\n    vec3 T = normalize(uU - N * dot(uU, N));\n    vec3 B = cross(N, T);\n    float NV = max(dot(N, V), 1e-3);\n    vec3 F = TI + (1.0 - TI) * pow(1.0 - NV, 5.0);\n\n    // the room smeared across the grooves: a fan of reflections spread along B\n    float spread = mix(0.26, 0.015, pol);\n    vec3 env = vec3(0.0); float ws = 0.0;\n    for (int k = -6; k <= 6; k++) {\n      float a = float(k) / 6.0;\n      float wt = exp(-a * a * 2.2);\n      env += room(vW, reflect(-V, normalize(N + B * a * spread)), 0.02 + spread * 0.08) * wt;\n      ws += wt;\n    }\n    env /= ws;\n    // the sun as an anisotropic highlight: narrow along the grooves, long across them\n    vec3 L = SUN, H = normalize(L + V);\n    float NL = max(dot(N, L), 0.0);\n    float aT = mix(0.045, 0.02, pol), aB = mix(0.3, 0.02, pol);\n    float hn = max(dot(H, N), 1e-3);\n    float ward = NL * exp(-(pow(dot(H, T) / aT, 2.0) + pow(dot(H, B) / aB, 2.0)) / (hn * hn)) / (12.566 * aT * aB * sqrt(max(NL * NV, 1e-4)));\n    vec3 metal = F * (env + SUNC * 3.0 * vis * min(ward, 14.0) * 0.3);\n    metal *= 0.9 + 0.22 * (gro * 0.5 + 0.5) * (1.0 - pol);\n\n    // the laser mark: a dark, matte oxide with a faint frost\n    float frost = vnoise(pp * 1400.0);\n    vec3 et = vec3(0.03, 0.029, 0.028) * (0.8 + 0.4 * frost) * (SUNC * 2.5 * vis * NL + SKY * 0.5 + vec3(0.06));\n    et += 0.025 * room(vW, reflect(-V, N), 0.5);\n    col = mix(metal, et, etch);\n    col = mix(edge, col, face);\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 s0 = c0.a * 2.0 - 1.0;\n  float coc0 = abs(s0);\n  vec3 lin0 = pow(c0.rgb, vec3(2.2));\n  float w0 = 1.0 / (1.03 - max(lin0.r, max(lin0.g, lin0.b)));\n  vec3 acc = lin0 * w0; float wsum = w0;\n  float rot = 6.2832 * ign(gl_FragCoord.xy);\n  for (int k = 1; k < 36; k++) {\n    float r = k < 26 ? sqrt(float(k) / 26.0) * uMaxR : sqrt(float(k - 25) / 10.0) * min(uMaxR, 3.0);\n    float a = float(k) * 2.39996 + rot;\n    vec4 s = texture(uScene, vUv + vec2(cos(a), sin(a)) * r * uPx);\n    float sc = s.a * 2.0 - 1.0;\n    float cs = abs(sc);\n    if (sc > s0) cs = min(cs, coc0 * 1.6 + 0.02);\n    vec3 lin = pow(s.rgb, vec3(2.2));\n    float w = smoothstep(r - 1.0, r + 1.0, cs * uMaxR) / (1.03 - max(lin.r, max(lin.g, lin.b)));\n    acc += lin * w; wsum += w;\n  }\n  o = vec4(pow(acc / wsum, vec3(1.0 / 2.2)), coc0);\n}`;\n\nconst FS_OUT = `#version 300 es\nprecision highp float;\nuniform sampler2D uScene;\nuniform vec2 uPx;\nuniform float uTime;\nin vec2 vUv;\nout vec4 o;\nfloat ign(vec2 p) { return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715)))); }\nvoid main() {\n  vec4 c = texture(uScene, vUv);\n  float r = clamp(c.a * 4.0, 0.0, 1.0) * 1.4;\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  // a little bloom where the sheen runs hottest\n  vec3 glow = vec3(0.0);\n  float rot = 6.2832 * ign(gl_FragCoord.xy);\n  for (int k = 0; k < 12; k++) {\n    float a = float(k) * 2.39996 + rot;\n    float d = 2.0 + 16.0 * sqrt(float(k) / 12.0);\n    vec3 s = texture(uScene, vUv + vec2(cos(a), sin(a)) * d * uPx).rgb;\n    glow += s * smoothstep(0.9, 1.0, min(s.r, min(s.g, s.b)));\n  }\n  col += glow / 12.0 * vec3(0.22, 0.21, 0.19);\n  vec2 q = vUv - 0.5;\n  col *= 1.0 - 0.38 * dot(q, q);\n  col += (ign(gl_FragCoord.xy + fract(uTime) * 61.0) - 0.5) * 0.018;\n  o = vec4(col, 1.0);\n}`;\n\nfunction program(gl: WebGL2RenderingContext, vs: string, fs: string) {\n  const p = gl.createProgram()!;\n  for (const [type, src] of [[gl.VERTEX_SHADER, vs], [gl.FRAGMENT_SHADER, fs]] as const) {\n    const s = gl.createShader(type)!;\n    gl.shaderSource(s, src);\n    gl.compileShader(s);\n    if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s) || \"shader\");\n    gl.attachShader(p, s);\n  }\n  gl.linkProgram(p);\n  if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p) || \"link\");\n  return p;\n}\n\n/** The plate as triangles: two faces, a flat side, and a small chamfer-round between them. Position + normal. */\nfunction cardMesh() {\n  const SEG = 10;\n  const B = 0.004;\n  const ring = (d: number, z: number, tilt: number, nz: number) => {\n    const out: number[][] = [];\n    for (let k = 0; k < 4; k++) {\n      const cx = (k === 0 || k === 3 ? 1 : -1) * (HX - CR);\n      const cy = (k < 2 ? 1 : -1) * (HY - CR);\n      for (let j = 0; j <= SEG; j++) {\n        const a = ((k + j / SEG) * Math.PI) / 2;\n        const dx = Math.cos(a), dy = Math.sin(a);\n        out.push([cx + (CR - d) * dx, cy + (CR - d) * dy, z, dx * tilt, dy * tilt, nz]);\n      }\n    }\n    return out;\n  };\n  const rings: number[][][] = [];\n  for (const sgn of [1, -1]) {\n    const order = sgn > 0 ? [0, 30, 60, 90] : [90, 60, 30, 0];\n    for (const deg of order) {\n      const p = (deg * Math.PI) / 180;\n      rings.push(ring(B * (1 - Math.sin(p)), sgn * (HT - B * (1 - Math.cos(p))), Math.sin(p), sgn * Math.cos(p)));\n    }\n  }\n  const v: number[] = [];\n  const M = rings[0].length;\n  for (let r = 0; r < rings.length - 1; r++) {\n    for (let i = 0; i < M; i++) {\n      const a = rings[r][i], b = rings[r][(i + 1) % M], c = rings[r + 1][i], d = rings[r + 1][(i + 1) % M];\n      v.push(...a, ...b, ...c, ...b, ...d, ...c);\n    }\n  }\n  for (const [r, z] of [[0, 1], [rings.length - 1, -1]]) {\n    for (let i = 0; i < M; i++) v.push(0, 0, z * HT, 0, 0, z, ...rings[r][i], ...rings[r][(i + 1) % M]);\n  }\n  return new Float32Array(v);\n}\n\ntype Channel = \"etch\" | \"height\" | \"polish\";\n\n/** Draw one side of the plate into one channel: where the laser marked it, how deep, and where it was left mirror-polished. */\nfunction paintSide(ctx: CanvasRenderingContext2D, side: number, ch: Channel) {\n  ctx.globalCompositeOperation = \"source-over\";\n  ctx.fillStyle = { etch: \"#000\", height: \"#808080\", polish: \"#000\" }[ch];\n  ctx.fillRect(0, 0, TW, TH);\n  const put = (c: Partial<Record<Channel, string>>, draw: () => void) => {\n    const col = c[ch];\n    if (!col) return;\n    ctx.fillStyle = col;\n    ctx.strokeStyle = col;\n    draw();\n  };\n  const tracked = (s: string, x: number, y: number, font: string, gap: number, align: \"left\" | \"right\" | \"center\" = \"left\") => {\n    ctx.font = font;\n    ctx.textAlign = \"left\";\n    const widths = [...s].map((c) => ctx.measureText(c).width + gap);\n    const total = widths.reduce((a, b) => a + b, 0) - gap;\n    let cx = align === \"left\" ? x : align === \"right\" ? x - total : x - total / 2;\n    [...s].forEach((c, i) => {\n      ctx.fillText(c, cx, y);\n      cx += widths[i];\n    });\n  };\n  const ETCH = { etch: \"#fff\", height: \"#606060\" };\n  // the tessera mark: a three by three mosaic of tiles, the centre one left mirror-bright\n  const mark = (x: number, y: number, size: number) => {\n    const g = size * 0.07;\n    const t = (size - 2 * g) / 3;\n    for (let r = 0; r < 3; r++) {\n      for (let c = 0; c < 3; c++) {\n        const tx = x + c * (t + g), ty = y + r * (t + g);\n        if (r === 1 && c === 1) put({ polish: \"#fff\", height: \"#8c8c8c\" }, () => ctx.fillRect(tx, ty, t, t));\n        else if ((r + c) % 2 === 0) put(ETCH, () => ctx.fillRect(tx, ty, t, t));\n        else\n          put(ETCH, () => {\n            ctx.lineWidth = Math.max(3, t * 0.08);\n            ctx.strokeRect(tx + ctx.lineWidth / 2, ty + ctx.lineWidth / 2, t - ctx.lineWidth, t - ctx.lineWidth);\n          });\n      }\n    }\n  };\n  ctx.textBaseline = \"alphabetic\";\n  if (side === 0) {\n    put(ETCH, () => tracked(card.house, 112, 196, `600 70px ${GROTESK}`, 26));\n    put(ETCH, () => tracked(card.tier, 116, 246, `500 22px ${GROTESK}`, 12));\n    mark(1370, 118, 118);\n    put(ETCH, () => tracked(card.number, 112, 640, `500 84px ${GROTESK}`, 7));\n    put(ETCH, () => ctx.fillRect(114, 712, 1372, 2));\n    put(ETCH, () => {\n      tracked(card.memberLabel, 116, 800, `600 20px ${GROTESK}`, 9);\n      tracked(card.validLabel, 1486, 800, `600 20px ${GROTESK}`, 9, \"right\");\n    });\n    put(ETCH, () => {\n      tracked(card.member, 112, 868, `500 46px ${GROTESK}`, 7);\n      tracked(card.valid, 1486, 868, `500 46px ${GROTESK}`, 7, \"right\");\n    });\n  } else {\n    put(ETCH, () => ctx.fillRect(0, 108, TW, 150));\n    put(ETCH, () => tracked(card.serial, 112, 360, `600 22px ${GROTESK}`, 9));\n    put(ETCH, () => {\n      ctx.lineWidth = 3;\n      ctx.strokeRect(112, 400, 900, 150);\n    });\n    put(ETCH, () => {\n      ctx.font = `italic 84px ${SERIF}`;\n      ctx.textAlign = \"left\";\n      ctx.fillText(card.signature, 150, 505);\n    });\n    put(ETCH, () => tracked(\"AUTHORISED SIGNATURE\", 114, 600, `600 18px ${GROTESK}`, 8));\n    mark(1210, 372, 210);\n    put(ETCH, () => {\n      tracked(card.small[0], 114, 830, `500 25px ${GROTESK}`, 2);\n      tracked(card.small[1], 114, 874, `500 25px ${GROTESK}`, 2);\n    });\n    put(ETCH, () => tracked(card.house, 1486, 874, `600 30px ${GROTESK}`, 12, \"right\"));\n  }\n}\n\ntype Sim = {\n  roll: number; vroll: number; pitch: number; vpitch: number; flip: number; vflip: number; goal: number;\n  px: number; py: number; inside: boolean; focus: number; t0: number; dirty: boolean;\n};\n\nexport default function TitaniumTrayCard() {\n  const reduce = useReducedMotion();\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const [side, setSide] = useState(0);\n  const [mode, setMode] = useState<\"pending\" | \"gl\" | \"still\">(\"pending\");\n  const sim = useRef<Sim>({ roll: 0, vroll: 0, pitch: 0, vpitch: 0, flip: 0, vflip: 0, goal: 0, px: 0, py: 0, inside: false, focus: 3, t0: 0, dirty: true });\n\n  const turn = useCallback(() => {\n    const s = sim.current;\n    s.goal += 1;\n    s.vflip -= 1.6; // it digs in on one edge before it goes over\n    s.dirty = true;\n    setSide(((s.goal % 2) + 2) % 2);\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 progSet: WebGLProgram, progCard: WebGLProgram, progLens: WebGLProgram, progOut: WebGLProgram;\n    try {\n      progSet = program(gl, VS_FULL, FS_SET);\n      progCard = program(gl, VS_CARD, FS_CARD);\n      progLens = program(gl, VS_FULL, FS_LENS);\n      progOut = program(gl, VS_FULL, FS_OUT);\n    } catch {\n      setMode(\"still\");\n      return;\n    }\n    setMode(\"gl\");\n\n    // one array texture, a layer per side: etch in red, depth in green, mirror polish in blue\n    const levels = Math.floor(Math.log2(TW)) + 1;\n    const aniso = gl.getExtension(\"EXT_texture_filter_anisotropic\");\n    const matTex = gl.createTexture();\n    gl.activeTexture(gl.TEXTURE1);\n    gl.bindTexture(gl.TEXTURE_2D_ARRAY, matTex);\n    gl.texStorage3D(gl.TEXTURE_2D_ARRAY, levels, gl.RGBA8, TW, TH, 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_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 scratch = document.createElement(\"canvas\");\n    const mix = document.createElement(\"canvas\");\n    scratch.width = mix.width = TW;\n    scratch.height = mix.height = TH;\n    const sctx = scratch.getContext(\"2d\")!;\n    const mctx = mix.getContext(\"2d\")!;\n    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);\n    for (let layer = 0; layer < 2; layer++) {\n      mctx.globalCompositeOperation = \"source-over\";\n      mctx.fillStyle = \"#000\";\n      mctx.fillRect(0, 0, TW, TH);\n      for (const [ch, tint] of [[\"etch\", \"#f00\"], [\"height\", \"#0f0\"], [\"polish\", \"#00f\"]] as const) {\n        paintSide(sctx, layer, ch);\n        sctx.globalCompositeOperation = \"multiply\";\n        sctx.fillStyle = tint;\n        sctx.fillRect(0, 0, TW, TH);\n        mctx.globalCompositeOperation = \"lighter\";\n        mctx.drawImage(scratch, 0, 0);\n      }\n      gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, layer, TW, TH, 1, gl.RGBA, gl.UNSIGNED_BYTE, mix);\n    }\n    gl.generateMipmap(gl.TEXTURE_2D_ARRAY);\n\n    const mesh = cardMesh();\n    const vao = gl.createVertexArray();\n    gl.bindVertexArray(vao);\n    gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());\n    gl.bufferData(gl.ARRAY_BUFFER, mesh, gl.STATIC_DRAW);\n    gl.enableVertexAttribArray(0);\n    gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0);\n    gl.enableVertexAttribArray(1);\n    gl.vertexAttribPointer(1, 3, gl.FLOAT, false, 24, 12);\n    gl.bindVertexArray(null);\n    const emptyVao = gl.createVertexArray();\n\n    // multisampled scene, resolved to a texture for the lens pass (colour, with 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, 2);\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.9e6) k = Math.sqrt(1.9e6 / (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_COMPONENT16, 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] of [[gl.TEXTURE2, resTex, resFbo], [gl.TEXTURE3, lensTex, lensFbo]] 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, 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 TAN = Math.tan((17 * Math.PI) / 180);\n    const pose = { c: [0, 0, 0], u: [1, 0, 0], v: [0, 1, 0], n: [0, 0, 1] };\n\n    const shared = (p: WebGLProgram, cam: number[], rt: number[], up: number[], fw: number[], t: number) => {\n      gl.useProgram(p);\n      gl.uniform3fv(U(p, \"uC\"), pose.c);\n      gl.uniform3fv(U(p, \"uU\"), pose.u);\n      gl.uniform3fv(U(p, \"uV\"), pose.v);\n      gl.uniform3fv(U(p, \"uN\"), pose.n);\n      gl.uniform1i(U(p, \"uMat\"), 1);\n      gl.uniform3fv(U(p, \"uCam\"), cam);\n      gl.uniform3fv(U(p, \"uRt\"), rt);\n      gl.uniform3fv(U(p, \"uUp\"), up);\n      gl.uniform3fv(U(p, \"uFw\"), fw);\n      gl.uniform1f(U(p, \"uTan\"), TAN);\n      gl.uniform1f(U(p, \"uAspect\"), W / H);\n      gl.uniform1f(U(p, \"uFocus\"), s.focus);\n      gl.uniform1f(U(p, \"uAperture\"), 1.2);\n      gl.uniform1f(U(p, \"uTime\"), t);\n    };\n\n    const draw = (t: number) => {\n      // the plate's pose: turn over about its short axis, rock under the pointer, then lie askew in the tray\n      const A = s.flip * Math.PI + s.roll;\n      const Pt = s.pitch;\n      const cy = Math.cos(REST_YAW), sy = Math.sin(REST_YAW);\n      const rot = (x: number, y: number, z: number) => {\n        [x, z] = [x * Math.cos(A) + z * Math.sin(A), -x * Math.sin(A) + z * Math.cos(A)];\n        [y, z] = [y * Math.cos(Pt) - z * Math.sin(Pt), y * Math.sin(Pt) + z * Math.cos(Pt)];\n        const wx = x, wy = z, wz = -y;\n        return [wx * cy + wz * sy, wy, -wx * sy + wz * cy];\n      };\n      pose.u = rot(1, 0, 0);\n      pose.v = rot(0, 1, 0);\n      pose.n = rot(0, 0, 1);\n      // it rests on whichever corner is lowest, so a tilt makes it rock on an edge instead of sinking into the stone\n      let low = Infinity;\n      for (const ex of [-1, 1]) for (const ey of [-1, 1]) for (const ez of [-1, 1]) low = Math.min(low, rot(ex * (HX - CR * 0.3), ey * (HY - CR * 0.3), ez * HT)[1]);\n      const spin = Math.sin(clamp(Math.abs(s.flip - Math.round(s.flip)), 0, 0.5) * Math.PI);\n      pose.c = [0.03, -low + 0.0008 + 0.16 * spin * spin, 0.02];\n\n      const aspect = W / H;\n      const el = 0.92;\n      const dist = Math.max(1.3 / TAN, 1.72 / (TAN * aspect));\n      const drift = reduce ? 0 : 1;\n      const tgt = [0, 0.0, 0.08];\n      const az = drift * 0.035 * Math.sin(t * 0.21);\n      const cam = [tgt[0] + Math.sin(az) * Math.cos(el) * dist, tgt[1] + Math.sin(el) * dist + drift * 0.02 * Math.sin(t * 0.17 + 1), tgt[2] + Math.cos(az) * Math.cos(el) * dist];\n      let fw = [tgt[0] - cam[0], tgt[1] - cam[1], tgt[2] - cam[2]];\n      const fl = Math.hypot(fw[0], fw[1], fw[2]);\n      fw = fw.map((v) => v / fl);\n      let rt = [-fw[2], 0, fw[0]];\n      const rl = Math.hypot(rt[0], rt[2]);\n      rt = rt.map((v) => v / rl);\n      const up = [rt[1] * fw[2] - rt[2] * fw[1], rt[2] * fw[0] - rt[0] * fw[2], rt[0] * fw[1] - rt[1] * fw[0]];\n      s.focus = (pose.c[0] - cam[0]) * fw[0] + (pose.c[1] - cam[1]) * fw[1] + (pose.c[2] - cam[2]) * fw[2];\n\n      gl.bindFramebuffer(gl.FRAMEBUFFER, msFbo);\n      gl.viewport(0, 0, W, H);\n      gl.disable(gl.DEPTH_TEST);\n      gl.depthMask(false);\n      shared(progSet, cam, rt, up, fw, t);\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(progCard, cam, rt, up, fw, t);\n      gl.bindVertexArray(vao);\n      gl.drawArrays(gl.TRIANGLES, 0, mesh.length / 6);\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.009);\n      gl.bindVertexArray(emptyVao);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\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    const physics = (dt: number, t: number) => {\n      // with nobody steering, the card rocks slowly so the window's reflection runs across the brushing\n      const idle = s.inside ? 0 : 1;\n      const wantRoll = (s.inside ? s.px * TILT : 0) + idle * 0.06 * Math.sin(t * 0.62 + 0.9);\n      const wantPitch = (s.inside ? s.py * TILT * 0.7 : 0) + idle * 0.025 * Math.sin(t * 0.43 + 0.4);\n      s.vroll += (SPRING * (wantRoll - s.roll) - DAMPING * s.vroll) * dt;\n      s.roll += s.vroll * dt;\n      s.vpitch += (SPRING * (wantPitch - s.pitch) - DAMPING * s.vpitch) * dt;\n      s.pitch += s.vpitch * dt;\n      s.vflip += (FLIP_SPRING * (s.goal - s.flip) - FLIP_DAMPING * s.vflip) * dt;\n      s.flip += s.vflip * dt;\n    };\n\n    let raf = 0, visible = true, last = performance.now(), slow = 0, frames = 0;\n    s.t0 = last;\n    const tick = (now: number) => {\n      const real = now - last;\n      const dt = Math.min(0.05, real / 1000);\n      last = now;\n      const t = (now - s.t0) / 1000;\n      if (reduce) {\n        if (s.flip !== s.goal) s.dirty = true;\n        s.flip = s.goal;\n        s.vflip = 0;\n        s.pitch = 0.05;\n        s.roll = 0.03;\n      } else {\n        const sub = Math.max(1, Math.ceil(dt / 0.006));\n        for (let i = 0; i < sub; i++) physics(dt / sub, t);\n      }\n      if (!reduce || s.dirty) {\n        draw(reduce ? 0 : t);\n        s.dirty = false;\n        // measure, do not guess: if frames run long, 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.6) {\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    let first: number[] | null = null;\n    const move = (e: PointerEvent) => {\n      const r = wrap.getBoundingClientRect();\n      s.px = clamp(((e.clientX - r.left) / r.width) * 2 - 1, -1, 1);\n      s.py = clamp(((e.clientY - r.top) / r.height) * 2 - 1, -1, 1);\n      // a pointer that is merely resting over the stage does not steer: it has to travel first\n      if (first === null) first = [e.clientX, e.clientY];\n      const moved = Math.hypot(e.clientX - first[0], e.clientY - first[1]) > 6;\n      if (moved) first = [-1e6, -1e6];\n      s.inside = moved && e.pointerType === \"mouse\";\n    };\n    const click = () => turn();\n    const leave = () => {\n      s.inside = false;\n    };\n    wrap.addEventListener(\"pointermove\", move);\n    canvas.addEventListener(\"click\", click);\n    wrap.addEventListener(\"pointerleave\", leave);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      wrap.removeEventListener(\"pointermove\", move);\n      canvas.removeEventListener(\"click\", click);\n      wrap.removeEventListener(\"pointerleave\", leave);\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    };\n  }, [reduce, turn]);\n\n  const onKey = (e: React.KeyboardEvent) => {\n    const s = sim.current;\n    const nudge = (dx: number, dy: number) => {\n      e.preventDefault();\n      s.inside = true;\n      s.px = clamp(s.px + dx, -1, 1);\n      s.py = clamp(s.py + dy, -1, 1);\n    };\n    if (e.key === \"ArrowLeft\") nudge(-0.25, 0);\n    else if (e.key === \"ArrowRight\") nudge(0.25, 0);\n    else if (e.key === \"ArrowUp\") nudge(0, -0.25);\n    else if (e.key === \"ArrowDown\") nudge(0, 0.25);\n    else if ((e.key === \"Enter\" || e.key === \" \") && e.target === e.currentTarget) {\n      e.preventDefault();\n      turn();\n    }\n  };\n\n  const brushed =\n    \"repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0 1px, rgba(0,0,0,0.04) 1px 2px), linear-gradient(100deg, #8d8a85 0%, #c9c6c0 30%, #f1efea 44%, #a9a59f 58%, #8b8782 100%)\";\n  const etched = \"#2a2826\";\n\n  return (\n    <section className=\"relative overflow-hidden bg-[#ddd7cd]\">\n      <div\n        ref={wrapRef}\n        role=\"group\"\n        aria-label=\"A brushed titanium membership card lying in a stone tray. Arrow keys rock it under the window light, Enter turns it over.\"\n        tabIndex={0}\n        onKeyDown={onKey}\n        onBlur={() => (sim.current.inside = false)}\n        className=\"relative h-[620px] w-full select-none outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#2a2826]/60 sm:h-[780px]\"\n      >\n        <canvas ref={canvasRef} aria-hidden=\"true\" className={`absolute inset-0 h-full w-full cursor-pointer touch-pan-y ${mode === \"still\" ? \"hidden\" : \"\"}`} />\n\n        {/* the same card laid out with plain elements, for browsers without WebGL 2 */}\n        {mode === \"still\" && (\n          <div className=\"absolute inset-0 flex items-center justify-center\" style={{ background: \"radial-gradient(70% 60% at 45% 40%, #efebe4 0%, #ddd7cd 60%, #c9c2b6 100%)\", perspective: \"1400px\" }}>\n            <div className=\"relative aspect-[1.6/1] w-[78%] max-w-[760px] rounded-[28px] bg-[#e4dfd6] p-[3.5%] shadow-[inset_0_2px_8px_rgba(80,70,55,0.35),0_30px_60px_rgba(80,70,55,0.25)]\">\n              <style>{`@keyframes titanium-tray-card-rock { from { transform: rotateX(26deg) rotateY(-5deg) rotateZ(-4deg); } to { transform: rotateX(22deg) rotateY(5deg) rotateZ(-3deg); } } .titanium-tray-card-rock { animation: titanium-tray-card-rock 4s ease-in-out infinite alternate; } @media (prefers-reduced-motion: reduce) { .titanium-tray-card-rock { animation: none; } }`}</style>\n              <div\n                className=\"titanium-tray-card-rock mx-auto mt-[6%] aspect-[1.585/1] w-[70%] rounded-[14px] p-[5%] shadow-[0_1px_0_#f5f3ef_inset,0_-1px_0_#6e6a64_inset,0_18px_30px_rgba(60,50,40,0.35)]\"\n                style={{ background: brushed, transform: \"rotateX(26deg) rotateZ(-4deg)\", fontFamily: GROTESK, color: etched }}\n              >\n                {side === 0 ? (\n                  <div className=\"flex h-full flex-col justify-between\">\n                    <p className=\"text-[clamp(14px,2.6vw,26px)] font-semibold tracking-[0.3em]\">{card.house}</p>\n                    <p className=\"text-[clamp(12px,2.6vw,28px)] font-medium tracking-[0.08em] tabular-nums\">{card.number}</p>\n                    <p className=\"flex justify-between text-[clamp(8px,1.3vw,14px)] font-medium tracking-[0.14em]\">\n                      <span>{card.member}</span>\n                      <span>{card.valid}</span>\n                    </p>\n                  </div>\n                ) : (\n                  <div className=\"flex h-full flex-col justify-between\">\n                    <div className=\"-mx-[7%] h-[18%] bg-[#2a2826]\" />\n                    <p className=\"text-[clamp(14px,2.4vw,26px)] italic\" style={{ fontFamily: SERIF }}>{card.signature}</p>\n                    <p className=\"text-[clamp(7px,1vw,11px)] font-medium tracking-[0.04em]\">{card.small.join(\" \")}</p>\n                  </div>\n                )}\n              </div>\n            </div>\n          </div>\n        )}\n\n        <div className=\"pointer-events-none absolute inset-x-0 top-0 flex items-baseline justify-between p-5 text-[#24221f] sm:p-9\">\n          <p className=\"text-[22px] font-semibold leading-none tracking-[0.32em] sm:text-[26px]\" style={{ fontFamily: GROTESK }}>\n            {card.house}\n          </p>\n          <p className=\"text-[10px] font-medium uppercase tracking-[0.28em] text-[#3d3a35] sm:text-[11px]\" style={{ fontFamily: GROTESK }}>\n            <span className=\"hidden sm:inline\">Move to rock it, click to turn</span>\n            <span className=\"sm:hidden\">Tap to turn</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-[#1d1b18]\">\n            <span className=\"block text-[11px] font-medium uppercase tracking-[0.28em] text-[#3d3a35]\" style={{ fontFamily: GROTESK }}>\n              <span className=\"tabular-nums text-[#1d1b18]\">{`0${side + 1}`}</span>\n              <span className=\"mx-2 text-[#3d3a35]/60\">/</span>\n              <span className=\"tabular-nums\">02</span>\n              <span className=\"ml-4\">{sides[side].tag}</span>\n            </span>\n            <span className=\"mt-2 block text-[34px] font-semibold leading-[0.95] sm:text-[64px]\" style={{ fontFamily: GROTESK, letterSpacing: \"-0.045em\" }}>\n              {sides[side].title}\n            </span>\n            <span className=\"sr-only\">\n              {side === 0 ? `. Card number ${card.number}, valid through ${card.valid}.` : `. Serial ${card.serial}, signed ${card.signature}.`}\n            </span>\n          </p>\n          <button\n            type=\"button\"\n            onClick={turn}\n            aria-pressed={side === 1}\n            className=\"pointer-events-auto inline-flex h-11 shrink-0 items-center gap-2.5 rounded-full border border-[#24221f]/25 bg-[#f4f1ec]/70 pl-4 pr-5 text-[12px] font-medium uppercase tracking-[0.2em] text-[#1d1b18] backdrop-blur-sm transition hover:bg-[#f4f1ec] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#24221f]\"\n            style={{ fontFamily: GROTESK }}\n          >\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=\"M4 10a6 6 0 0 1 10.6-3.8M16 10a6 6 0 0 1-10.6 3.8M14.8 3v3.4h-3.4M5.2 17v-3.4h3.4\" />\n            </svg>\n            Turn over\n          </button>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
