{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ray-marched-gold-solitaire-ring-jewellery-hero-resting-on-a-pale-silk-fold-with-a-dispersive-stone-that-turns-to-the-pointer","type":"registry:block","title":"Ray-Marched Gold Solitaire Ring Jewellery Hero Resting on a Pale Silk Fold with a Dispersive Stone That Turns to the Pointer","description":"Free React jewellery hero: a gold ring with a brilliant-cut stone stands in a fold of pale silk, throwing coloured fire as the pointer turns it.","dependencies":[],"files":[{"path":"components/we-inc/ray-marched-gold-solitaire-ring-jewellery-hero-resting-on-a-pale-silk-fold-with-a-dispersive-stone-that-turns-to-the-pointer.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// Everything a visitor would edit first.\nconst piece = {\n  house: \"Maison Ardeline\",\n  kind: \"The Solitaire, No. 4\",\n  headline: [\"Light,\", \"kept\", \"in gold.\"],\n  line: \"One brilliant-cut stone held in four claws on a softly domed band of yellow gold, made to be worn every day and handed on after.\",\n  cta: \"Choose your size\",\n  more: \"Book a fitting\",\n  note: \"Yellow gold, round brilliant\",\n};\n// Materials, in linear light (0 to 1).\nconst GOLD = [0.98, 0.66, 0.27]; // reflectance of the metal head on; 0.95, 0.93, 0.88 gives white gold or platinum\nconst SILK = [0.86, 0.75, 0.66]; // the pale champagne silk\nconst STONE_TINT = [1.0, 0.995, 0.985]; // colour of the stone; 0.55, 0.7, 1.0 gives a pale sapphire\nconst IOR = [2.33, 2.42, 2.55]; // red, green and blue bend by different amounts: this spread is the fire\nconst FONT = '\"Inter Tight\", \"Inter\", ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif';\nconst SERIF = '\"Didot\", \"Bodoni 72\", \"Bodoni MT\", \"Iowan Old Style\", \"Palatino Linotype\", Palatino, Georgia, serif';\n\nconst f4 = (n: number) => n.toFixed(5);\nconst v3 = (c: number[]) => `vec3(${c.map(f4).join(\", \")})`;\n\n// ---- the stone: a round brilliant as 73 flat facets, generated here and written into the shader ----\nconst GS = 1.22; // stone size\nconst G = 0.19 * GS, GT = 0.006 * GS, TAB = 0.066 * GS;\nconst facets: number[][] = [];\n(() => {\n  const rad = Math.PI / 180;\n  const add = (a: number, tilt: number, up: boolean, px: number, py: number) => {\n    const s = Math.sin(tilt * rad), c = Math.cos(tilt * rad) * (up ? 1 : -1);\n    facets.push([Math.cos(a) * s, c, Math.sin(a) * s, px * s + py * c]);\n  };\n  facets.push([0, 1, 0, TAB]);\n  const rt = G - (TAB - GT) / Math.tan(34 * rad);\n  for (let i = 0; i < 16; i++) { const a = (i * 22.5) * rad; facets.push([Math.cos(a), 0, Math.sin(a), G]); }\n  for (let i = 0; i < 8; i++) {\n    const a = i * 45 * rad, b = (i * 45 + 22.5) * rad;\n    add(a, 34, true, G, GT); // bezel\n    add(b, 21, true, rt, TAB); // star\n    add(a, 40.8, false, G, -GT); // pavilion main\n  }\n  for (let i = 0; i < 16; i++) {\n    const a = (i * 22.5 + 11.25) * rad;\n    add(a, 43, true, G, GT); // upper girdle\n    add(a, 43.5, false, G, -GT); // lower girdle\n  }\n})();\n// a ray against the stone: where it enters, where it leaves, and the facet at each (planes come in as a uniform list)\nconst NF = facets.length;\nconst GEM_ISECT = `uniform vec4 uGem[${NF}];\nbool gemHit(vec3 ro, vec3 rd, out float tn, out vec3 nn, out float tf, out vec3 nf){\n  tn = -1e5; tf = 1e5; nn = vec3(0.0, 1.0, 0.0); nf = nn; bool ok = true;\n  for (int i = 0; i < ${NF}; i++) {\n    vec4 P = uGem[i]; float dn = dot(rd, P.xyz); float nm = P.w - dot(ro, P.xyz);\n    if (dn < -1e-6) { float t = nm / dn; if (t > tn) { tn = t; nn = P.xyz; } }\n    else if (dn > 1e-6) { float t = nm / dn; if (t < tf) { tf = t; nf = P.xyz; } }\n    else if (nm < 0.0) ok = false;\n  }\n  return ok && tn <= tf && tf > 0.0;\n}`;\n\nconst VERT = `attribute vec2 aPos; void main(){ gl_Position = vec4(aPos, 0.0, 1.0); }`;\n\n// The photograph: a gold solitaire standing in a fold of silk, a window of daylight behind and to the left.\nconst SCENE = `\nprecision highp float;\nuniform vec2 uRes; uniform vec2 uJit; uniform vec2 uLens; uniform float uSeed; uniform sampler2D uHist; uniform float uBlend;\nuniform vec3 uCam; uniform vec3 uTgt; uniform float uFoc; uniform vec2 uShift; uniform float uFocus; uniform float uAper;\nuniform vec2 uYaw; uniform vec3 uSun;\nconst vec3 GOLD = ${v3(GOLD)}; const vec3 SILK = ${v3(SILK)}; const vec3 TINT = ${v3(STONE_TINT)}; const vec3 IOR = ${v3(IOR)};\nconst vec3 SUNC = vec3(1.0, 0.94, 0.85);\nconst float RR = 0.6; const float RH = 0.062; const float RW = 0.1;\nconst vec3 RC = vec3(0.0, 0.658, 0.0);\nconst vec3 GC = vec3(0.0, 0.83, 0.0); const float GS = ${GS.toFixed(3)};\nfloat h21(vec2 p){ vec3 q = fract(vec3(p.xyx) * 0.1031); q += dot(q, q.yzx + 33.33); return fract((q.x + q.y) * q.z); }\nfloat n2(vec2 x){ vec2 i = floor(x); vec2 f = fract(x); f = f * f * (3.0 - 2.0 * f);\n  return mix(mix(h21(i), h21(i + vec2(1.0, 0.0)), f.x), mix(h21(i + vec2(0.0, 1.0)), h21(i + vec2(1.0, 1.0)), f.x), f.y); }\nfloat smin(float a, float b, float k){ float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0); return mix(b, a, h) - k * h * (1.0 - h); }\nvec3 toL(vec3 p){ p -= RC; return vec3(uYaw.x * p.x + uYaw.y * p.z, p.y, -uYaw.y * p.x + uYaw.x * p.z); }\nvec3 dirL(vec3 v){ return vec3(uYaw.x * v.x + uYaw.y * v.z, v.y, -uYaw.y * v.x + uYaw.x * v.z); }\nvec3 dirW(vec3 v){ return vec3(uYaw.x * v.x - uYaw.y * v.z, v.y, uYaw.y * v.x + uYaw.x * v.z); }\n${GEM_ISECT}\n\n// ---- the metal, in the ring's own frame: band round the z axis, stone on top ----\nfloat capsule(vec3 p, vec3 a, vec3 b, float ra, float rb){ vec3 pa = p - a; vec3 ba = b - a; float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0); return length(pa - ba * h) - mix(ra, rb, h); }\nfloat metal(vec3 q){\n  // a comfort-fit band: domed outside, softly rounded edges, a touch heavier at the shoulders\n  float sh = smoothstep(0.2, 0.62, q.y);\n  vec2 b = vec2(length(q.xy) - RR - 0.008 * sh, q.z);\n  vec2 e = vec2(RH + 0.01 * sh, RW - 0.02 * sh);\n  vec2 d = abs(b) - e + 0.05;\n  float band = min(max(d.x, d.y), 0.0) + length(max(d, 0.0)) - 0.05;\n  vec3 g = (q - GC) / GS;\n  if (length(g) > 0.42) return band;\n  // the basket: a little collar under the stone and four claws over its edge\n  float collar = length(vec2(length(g.xz) - 0.112, g.y + 0.075)) - 0.019;\n  float stem = max(length(g.xz) - 0.07 + 0.25 * (g.y + 0.1), abs(g.y + 0.15) - 0.07);\n  vec2 ax = abs(g.xz); vec2 dg = normalize(vec2(1.0));\n  vec3 c = vec3(ax.x, g.y, ax.y);\n  float claw = capsule(c, vec3(dg * 0.06, -0.15).xzy, vec3(dg * 0.165, -0.02).xzy, 0.024, 0.02);\n  claw = min(claw, capsule(c, vec3(dg * 0.165, -0.02).xzy, vec3(dg * 0.181, 0.032).xzy, 0.02, 0.017));\n  float s = smin(band, smin(stem, collar, 0.03) * GS, 0.04);\n  return min(s, smin(claw, collar, 0.012) * GS);\n}\nfloat metalW(vec3 p){ return metal(toL(p)); }\nfloat sphereT(vec3 ro, vec3 rd, vec3 c, float r){ vec3 oc = ro - c; float b = dot(oc, rd); float h = b * b - dot(oc, oc) + r * r; if (h < 0.0) return -1.0; h = sqrt(h); return max(-b - h, 0.0) < -b + h ? max(-b - h, 0.0) : -1.0; }\nfloat marchMetal(vec3 ro, vec3 rd){\n  float t = sphereT(ro, rd, RC + vec3(0.0, 0.1, 0.0), 0.98); if (t < 0.0) return -1.0;\n  float te = t + 2.0;\n  for (int i = 0; i < 96; i++) { float d = metalW(ro + rd * t); if (d < 0.0006) return t; t += d * 0.9; if (t > te) break; }\n  return -1.0;\n}\nvec3 metalN(vec3 p){ vec2 e = vec2(0.0012, -0.0012); return normalize(e.xyy * metalW(p + e.xyy) + e.yyx * metalW(p + e.yyx) + e.yxy * metalW(p + e.yxy) + e.xxx * metalW(p + e.xxx)); }\nbool gemW(vec3 ro, vec3 rd, out float t, out vec3 n){\n  vec3 o = toL(ro) - GC; vec3 d = dirL(rd); float tf; vec3 nf;\n  if (!gemHit(o, d, t, n, tf, nf) || t < 0.0) return false;\n  n = dirW(n); return true;\n}\n\n// ---- the silk: a broad fold rising behind, slow ripples, fine grain of the weave ----\nfloat silkH(vec2 p){\n  float r = length(p);\n  vec2 f = vec2(0.6, 0.8); vec2 g = vec2(0.8, -0.6);\n  float u = dot(p, f); float v = dot(p, g);\n  float h = 0.17 * sin(v * 1.25 + 0.7 * sin(u * 0.45) + 0.6) + 0.055 * sin(v * 2.7 - u * 0.4 + 2.0) + 0.02 * sin(v * 5.1 + u * 0.9);\n  h *= smoothstep(0.55, 2.6, r);\n  float z0 = 1.25 + 0.22 * sin(p.x * 0.8 + 0.5);\n  h += 0.62 * exp(-pow((p.y - z0) / 0.62, 2.0)) * smoothstep(-5.0, -1.0, p.x);\n  h += 0.18 * smoothstep(2.0, 7.0, p.y) * (1.0 + 0.4 * sin(p.x * 0.6));\n  return h - 0.004;\n}\nvec3 silkN(vec2 p){ float e = 0.012; return normalize(vec3(silkH(p - vec2(e, 0.0)) - silkH(p + vec2(e, 0.0)), 2.0 * e, silkH(p - vec2(0.0, e)) - silkH(p + vec2(0.0, e)))); }\nfloat marchSilk(vec3 ro, vec3 rd){\n  float top = 1.05; float t = 0.0;\n  if (ro.y > top) { if (rd.y >= 0.0) return -1.0; t = (top - ro.y) / rd.y; }\n  float pd = 1.0; float pt = t;\n  for (int i = 0; i < 110; i++) {\n    vec3 p = ro + rd * t; float d = p.y - silkH(p.xz);\n    if (d < 0.0) return mix(pt, t, pd / (pd - d));\n    pd = d; pt = t; t += max(d * 0.45, 0.002 + t * 0.002);\n    if (t > 45.0 || (p.y > top && rd.y > 0.0)) break;\n  }\n  return -1.0;\n}\n\nvec3 env(vec3 d){\n  // a quiet room: dim walls, darker still behind the camera, so metal and stone keep their contrast\n  vec3 c = mix(vec3(0.16, 0.15, 0.145), vec3(0.42, 0.42, 0.44), smoothstep(-0.1, 0.8, d.y));\n  c *= mix(0.16, 1.0, smoothstep(-0.6, 0.3, d.z));\n  if (d.y < 0.0) c = mix(c, SILK * 0.55, smoothstep(0.0, -0.2, d.y));\n  // the window: six panes of daylight with soft edges and thin glazing bars\n  vec3 wr = normalize(cross(vec3(0.0, 1.0, 0.0), uSun)); vec3 wu = cross(uSun, wr);\n  float k = dot(d, uSun);\n  if (k > 0.2) {\n    vec2 w = vec2(dot(d, wr), dot(d, wu)) / k;\n    float win = smoothstep(0.62, 0.55, abs(w.x)) * smoothstep(0.82, 0.74, abs(w.y));\n    float bars = smoothstep(0.012, 0.03, abs(w.x)) * smoothstep(0.012, 0.03, abs(abs(w.y) - 0.27)) * smoothstep(0.012, 0.03, abs(w.y + 0.0));\n    c += vec3(1.0, 0.97, 0.92) * 9.0 * win * bars * (0.85 + 0.15 * w.y);\n  }\n  // a tall white card to camera right, a low warm bounce in front\n  c += vec3(1.0) * 2.0 * smoothstep(0.05, -0.05, abs(atan(d.x, -d.z) - 1.15) - 0.2) * smoothstep(-0.05, 0.1, d.y) * smoothstep(0.7, 0.5, d.y);\n  c += vec3(1.0, 0.95, 0.88) * 3.5 * smoothstep(0.03, -0.03, abs(atan(d.x, -d.z) + 0.35) - 0.06) * smoothstep(0.05, 0.15, d.y) * smoothstep(0.9, 0.75, d.y);\n  c += SUNC * 80.0 * smoothstep(0.9993, 0.9998, dot(d, uSun));\n  return c;\n}\n\n// soft shadow of the metal; the stone lets most light through and throws coloured fire instead\nfloat shadowMetal(vec3 p, vec3 L){\n  float t = sphereT(p, L, RC + vec3(0.0, 0.1, 0.0), 0.98); if (t < 0.0) return 1.0;\n  float res = 1.0; t = max(t, 0.03);\n  for (int i = 0; i < 40; i++) { float h = metalW(p + L * t); res = min(res, 14.0 * h / t); t += clamp(h, 0.006, 0.12); if (res < 0.003 || t > 4.0) break; }\n  res = clamp(res, 0.0, 1.0); return res * res * (3.0 - 2.0 * res);\n}\nvec3 spectrum(float x){ return clamp(abs(fract(x + vec3(0.0, 0.667, 0.333)) * 6.0 - 3.0) - 1.0, 0.0, 1.0); }\n\nvec3 shadeSilk(vec3 p, vec3 rd, bool cheap){\n  vec3 n = silkN(p.xz);\n  // the weave: a fine cross-grain that only shows in the sheen\n  float weave = cheap ? 0.5 : n2(p.xz * vec2(160.0, 9.0)) * 0.5 + n2(p.xz * vec2(7.0, 170.0)) * 0.5;\n  vec3 L = uSun; vec3 V = -rd; vec3 H = normalize(L + V);\n  vec3 fd = vec3(0.6, 0.0, 0.8); vec3 T = normalize(fd - n * dot(n, fd));\n  float sh = cheap ? 1.0 : shadowMetal(p + n * 0.004, L);\n  float dm = cheap ? 1.0 : metalW(p);\n  float wrapd = max((dot(n, L) + 0.3) / 1.3, 0.0);\n  float TH = dot(T, H); float kk = pow(sqrt(max(1.0 - TH * TH, 0.0)), 90.0);\n  float ao = 1.0 - 0.55 * exp(-max(dm, 0.0) * 22.0) - 0.15 * exp(-max(dm, 0.0) * 4.0);\n  vec3 col = SILK * (SUNC * 1.55 * wrapd * sh + vec3(0.78, 0.82, 0.92) * 0.42 * ao * (0.6 + 0.4 * n.y));\n  col += SUNC * mix(SILK, vec3(1.0), 0.35) * kk * 1.4 * sh * (0.75 + 0.5 * weave) * smoothstep(-0.1, 0.3, dot(n, L));\n  col += SILK * 0.18 * pow(1.0 - max(dot(n, V), 0.0), 3.0);\n  if (!cheap) {\n    // warm light bounced off the gold onto the silk around it\n    col += GOLD * SILK * 0.5 * exp(-max(dm, 0.0) * 9.0) * (0.4 + 0.6 * sh);\n    // fire: where sunlight passes through the stone, it lands split into colour\n    float tn; vec3 nn; float tf; vec3 nf;\n    vec3 o = toL(p) - GC; vec3 d = dirL(L);\n    if (gemHit(o, d, tn, nn, tf, nf) && tn > 0.0) {\n      // a few separate points of coloured light, one chance per small cell, that move as the ring turns\n      vec2 k = p.xz * 26.0 + vec2(uYaw.y * 6.0, uYaw.x * 5.0);\n      vec2 cell = floor(k); vec2 fc = fract(k) - 0.5;\n      float on = step(0.72, h21(cell + 7.0));\n      vec2 off = vec2(h21(cell + 1.3), h21(cell + 4.1)) * 0.6 - 0.3;\n      float dot1 = on * exp(-dot(fc - off, fc - off) * 260.0);\n      float edge = smoothstep(0.0, 0.03, min(tf - tn, 0.2));\n      col *= mix(1.0, 0.8, edge);\n      col += spectrum(h21(cell + 2.7)) * dot1 * SUNC * edge * 1.6;\n    }\n  }\n  return col;\n}\n\nvec3 shadeMetal(vec3 p, vec3 rd, float rnd){\n  vec3 n = metalN(p);\n  vec3 jit = vec3(h21(gl_FragCoord.xy + uSeed * 91.0), h21(gl_FragCoord.yx + uSeed * 37.0), rnd) - 0.5;\n  n = normalize(n + jit * 0.003);\n  vec3 r = reflect(rd, n); float nv = clamp(dot(-rd, n), 0.0, 1.0);\n  vec3 F = GOLD + (1.0 - GOLD) * pow(1.0 - nv, 5.0);\n  vec3 o = p + n * 0.004;\n  vec3 rc;\n  float tg; vec3 ng; bool g = gemW(o, r, tg, ng);\n  float tm = marchMetal(o, r);\n  if (g && (tm < 0.0 || tg < tm)) rc = vec3(1.4, 1.38, 1.36) * env(reflect(r, ng)) * 0.35 + 0.6 * vec3(0.9);\n  else if (tm > 0.0) {\n    // gold seen in gold: the inside of the band and the claws reflect each other\n    vec3 q = o + r * tm; vec3 n2 = metalN(q); vec3 r2 = reflect(r, n2);\n    rc = (GOLD + (1.0 - GOLD) * pow(1.0 - clamp(dot(-r, n2), 0.0, 1.0), 5.0)) * (r2.y < -0.05 ? SILK * 0.9 : env(r2)) * 0.85;\n  } else if (r.y < -0.002) {\n    float ts = marchSilk(o, r);\n    // a grazing ray that runs out of steps still lands on the cloth, never on the sky\n    if (ts < 0.0) ts = max(-o.y / r.y, 0.0);\n    rc = shadeSilk(o + r * ts, r, true);\n  } else rc = env(r);\n  // the band sitting in the silk is darker where it meets it\n  float ao = 0.55 + 0.45 * smoothstep(0.0, 0.16, p.y - silkH(p.xz));\n  float sh = 0.75 + 0.25 * shadowMetal(o, uSun);\n  return F * rc * ao * sh;\n}\n\nvec3 shadeGem(vec3 p, vec3 rd, vec3 nW){\n  vec3 o = toL(p) - GC; vec3 d0 = dirL(rd); vec3 n = dirL(nW);\n  float nv = clamp(dot(-d0, n), 0.0, 1.0);\n  float F = 0.17 + 0.83 * pow(1.0 - nv, 5.0);\n  vec3 col = F * env(dirW(reflect(d0, n)));\n  for (int c = 0; c < 3; c++) {\n    float ior = c == 0 ? IOR.x : (c == 1 ? IOR.y : IOR.z);\n    vec3 d = refract(d0, n, 1.0 / ior); vec3 q = o; float thr = 1.0 - F; float acc = 0.0;\n    for (int b = 0; b < 6; b++) {\n      float tn; vec3 nn; float tf; vec3 nf;\n      gemHit(q + d * 0.0004, d, tn, nn, tf, nf);\n      q = q + d * (0.0004 + max(tf, 0.0));\n      vec3 e = refract(d, -nf, ior);\n      if (dot(e, e) > 0.01) {\n        float ce = clamp(dot(e, nf), 0.0, 1.0); float Fe = 0.17 + 0.83 * pow(1.0 - ce, 5.0);\n        vec3 ew = dirW(e);\n        // light leaving through the bottom sees the gold basket\n        vec3 en = env(ew);\n        if (ew.y < -0.3) en = GOLD * env(reflect(ew, vec3(0.0, 1.0, 0.0))) * 0.6;\n        float v = c == 0 ? en.x : (c == 1 ? en.y : en.z);\n        acc += thr * (1.0 - Fe) * v; thr *= Fe;\n      }\n      d = reflect(d, -nf);\n    }\n    float tv = c == 0 ? TINT.x : (c == 1 ? TINT.y : TINT.z);\n    acc = (acc + thr * 0.5) * tv;\n    if (c == 0) col.x += acc; else if (c == 1) col.y += acc; else col.z += acc;\n  }\n  return mix(col, vec3(dot(col, vec3(0.3333))), 0.18);\n}\n\nvec3 tone(vec3 x){ vec3 c = (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14); return pow(clamp(c, 0.0, 1.0), vec3(1.0 / 2.2)); }\n\nvoid main(){\n  vec2 uv = (gl_FragCoord.xy + uJit - 0.5 * uRes) / uRes.y - uShift;\n  vec3 fw = normalize(uTgt - uCam); vec3 rt = normalize(cross(vec3(0.0, 1.0, 0.0), fw)); vec3 up = cross(fw, rt);\n  vec3 pd = normalize(fw * uFoc + rt * uv.x + up * uv.y);\n  // a real lens: each frame looks through a different point of the aperture, all focused on the ring\n  vec3 ro = uCam + (rt * uLens.x + up * uLens.y) * uAper;\n  vec3 fp = uCam + pd * (uFocus / dot(pd, fw));\n  vec3 rd = normalize(fp - ro);\n  float rnd = fract(52.9829189 * fract(dot(gl_FragCoord.xy, vec2(0.06711056, 0.00583715))) + uSeed);\n  float tm = marchMetal(ro, rd);\n  float tg; vec3 ng; bool g = gemW(ro, rd, tg, ng);\n  vec3 col;\n  if (g && (tm < 0.0 || tg < tm)) col = shadeGem(ro + rd * tg, rd, ng);\n  else if (tm > 0.0) col = shadeMetal(ro + rd * tm, rd, rnd);\n  else {\n    float ts = marchSilk(ro, rd);\n    if (ts > 0.0) {\n      col = shadeSilk(ro + rd * ts, rd, false);\n      col = mix(col, SILK * vec3(1.08, 1.05, 1.02), 1.0 - exp(-max(ts - 6.0, 0.0) * 0.08));\n    } else col = SILK * vec3(1.08, 1.05, 1.02);\n  }\n  col = tone(col * 0.8);\n  vec3 prev = texture2D(uHist, gl_FragCoord.xy / uRes).rgb;\n  gl_FragColor = vec4(mix(prev, col, uBlend), 1.0);\n}\n`;\n\n// Developing it: a gentle vignette and a little grain over the gathered frames.\nconst POST = `\nprecision highp float;\nuniform sampler2D uImg; uniform vec2 uRes; uniform float uGrain;\nfloat h21(vec2 p){ vec3 q = fract(vec3(p.xyx) * 0.1031); q += dot(q, q.yzx + 33.33); return fract((q.x + q.y) * q.z); }\nvoid main(){\n  vec2 uv = gl_FragCoord.xy / uRes;\n  vec3 c = texture2D(uImg, uv).rgb;\n  vec2 q = uv - 0.5; c *= 1.0 - 0.16 * dot(q, q);\n  c += (h21(gl_FragCoord.xy + uGrain * 37.0) - 0.5) * 0.018;\n  gl_FragColor = vec4(c, 1.0);\n}\n`;\n\n// Camera for a frame of this size: the ring sits right of the words on wide screens, under them on phones.\nfunction camera(w: number, h: number) {\n  const wide = w >= 900, mid = w >= 640;\n  const dist = wide ? 6.1 : 6.5, el = wide ? 0.22 : 0.26;\n  const tgt = [0, 0.62, 0.15];\n  const cam = [0, tgt[1] + dist * Math.sin(el), -dist * Math.cos(el)];\n  const foc = wide ? 2.2 : mid ? 1.9 : 1.22;\n  const shift = wide ? [Math.min(0.4, (w / h) * 0.19), 0.0] : [mid ? 0.0 : -0.03, mid ? -0.2 : -0.24];\n  return { dist, tgt, cam, foc, shift };\n}\n\n// No WebGL: the same still life in CSS, a gold ring with a bright stone on pale silk.\nfunction Still() {\n  return (\n    <div aria-hidden=\"true\" className=\"absolute inset-0 overflow-hidden\" style={{ background: \"radial-gradient(120% 80% at 75% 30%, #f3ebe2 0%, #e2d4c6 45%, #cdbbaa 100%)\" }}>\n      <div className=\"absolute inset-0 opacity-70\" style={{ backgroundImage: \"linear-gradient(160deg, transparent 40%, rgba(255,255,255,0.45) 52%, transparent 62%), linear-gradient(150deg, transparent 58%, rgba(120,90,70,0.16) 70%, transparent 82%)\" }} />\n      <div className=\"absolute left-1/2 top-[58%] h-[230px] w-[200px] -translate-x-1/2 lg:left-[68%] lg:top-[30%] lg:h-[300px] lg:w-[260px]\">\n        <div className=\"absolute bottom-[-4%] left-[10%] h-[14%] w-[110%] rounded-full blur-lg\" style={{ background: \"radial-gradient(ellipse at 40% 50%, rgba(90,60,30,0.4), transparent 70%)\" }} />\n        <div className=\"absolute inset-x-[8%] bottom-0 top-[18%] rounded-full\" style={{ border: \"22px solid transparent\", background: \"conic-gradient(from 200deg, #7a4f12, #f6d58a, #b98228, #fff1c4, #8a5a16, #e8b852, #7a4f12) border-box\", WebkitMask: \"linear-gradient(#000 0 0) padding-box exclude, linear-gradient(#000 0 0)\", mask: \"linear-gradient(#000 0 0) padding-box exclude, linear-gradient(#000 0 0)\" }} />\n        <div className=\"absolute left-1/2 top-[2%] h-[64px] w-[64px] -translate-x-1/2 rotate-45 rounded-[10px]\" style={{ background: \"conic-gradient(from 10deg, #ffffff, #cfe3ff, #fff6e0, #9fb8d8, #ffffff, #ffe0f0, #dde8f5, #ffffff)\", boxShadow: \"0 0 0 3px #d9a840, 0 8px 18px -6px rgba(80,50,20,0.5)\" }} />\n      </div>\n    </div>\n  );\n}\n\nexport default function GoldSolitaireRingHero() {\n  const stage = useRef<HTMLDivElement>(null);\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const [shown, setShown] = useState<\"wait\" | \"gl\" | \"still\">(\"wait\");\n  const api = useRef<{ nudge: (d: number) => void } | null>(null);\n\n  useEffect(() => {\n    const box = stage.current, cv = canvas.current;\n    if (!box || !cv) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const gl = cv.getContext(\"webgl\", { antialias: false, alpha: false, preserveDrawingBuffer: false }) as WebGLRenderingContext | null;\n    if (!gl) { setShown(\"still\"); return; }\n    const compile = (type: number, src: string) => {\n      const sh = gl.createShader(type);\n      if (!sh) return null;\n      gl.shaderSource(sh, src); gl.compileShader(sh);\n      if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) { console.warn(gl.getShaderInfoLog(sh)); return null; }\n      return sh;\n    };\n    const link = (frag: string) => {\n      const v = compile(gl.VERTEX_SHADER, VERT), f = compile(gl.FRAGMENT_SHADER, frag), p = gl.createProgram();\n      if (!v || !f || !p) return null;\n      gl.attachShader(p, v); gl.attachShader(p, f); gl.bindAttribLocation(p, 0, \"aPos\"); gl.linkProgram(p);\n      return gl.getProgramParameter(p, gl.LINK_STATUS) ? p : null;\n    };\n    const scene = link(SCENE), post = link(POST);\n    if (!scene || !post) { setShown(\"still\"); return; }\n    const U = (p: WebGLProgram, n: string) => gl.getUniformLocation(p, n);\n    const su = Object.fromEntries([\"uRes\", \"uJit\", \"uLens\", \"uSeed\", \"uHist\", \"uBlend\", \"uCam\", \"uTgt\", \"uFoc\", \"uShift\", \"uFocus\", \"uAper\", \"uYaw\", \"uSun\", \"uGem\"].map((n) => [n, U(scene, n)]));\n    const pu = Object.fromEntries([\"uImg\", \"uRes\", \"uGrain\"].map((n) => [n, U(post, n)]));\n    const quad = gl.createBuffer();\n    gl.bindBuffer(gl.ARRAY_BUFFER, quad);\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n    gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n\n    // two images that take turns: last frame's gathered picture, and this frame's\n    const tex = [gl.createTexture(), gl.createTexture()], fbo = [gl.createFramebuffer(), gl.createFramebuffer()];\n    let W = 0, H = 0, cssW = 1, cssH = 1, scale = 1, cur = 0;\n    const s = { t: 0, last: 0, raf: 0, visible: true, alive: true, first: true, frame: 0, n: 0, slow: 0, fpsT: 0, fpsN: 0, yaw: 0.72, vel: 0, aim: 0.72, idle: true, lastMove: -10, still: 0 };\n    const size = () => {\n      const r = box.getBoundingClientRect();\n      cssW = Math.max(1, r.width); cssH = Math.max(1, r.height);\n      const dpr = Math.min(1.5, window.devicePixelRatio || 1) * scale;\n      const k = Math.min(1, Math.sqrt(1.1e6 / (cssW * cssH * dpr * dpr)));\n      const w = Math.max(2, Math.round(cssW * dpr * k)), h = Math.max(2, Math.round(cssH * dpr * k));\n      if (w === W && h === H) return;\n      W = w; H = h; cv.width = W; cv.height = H; s.n = 0;\n      for (let i = 0; i < 2; i++) {\n        gl.bindTexture(gl.TEXTURE_2D, tex[i]);\n        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, W, H, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);\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, fbo[i]);\n        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex[i], 0);\n      }\n      gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n    };\n    const gemPlanes = new Float32Array(facets.flat());\n    const sun = (() => { const v = [-0.48, 0.8, 0.36]; const l = Math.hypot(...v); return v.map((n) => n / l); })();\n\n    // a well spread set of sub-pixel and lens offsets, so a few frames already look supersampled\n    const halton = (i: number, b: number) => { let f = 1, r = 0; while (i > 0) { f /= b; r += f * (i % b); i = Math.floor(i / b); } return r; };\n    const draw = (blend: number) => {\n      const c = camera(cssW, cssH);\n      const i = s.frame + 1;\n      const jx = halton(i % 64, 2) - 0.5, jy = halton(i % 64, 3) - 0.5;\n      const la = halton(i % 97, 5) * Math.PI * 2, lr = Math.sqrt(halton(i % 97, 7));\n      const nxt = 1 - cur;\n      gl.useProgram(scene);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, fbo[nxt]);\n      gl.viewport(0, 0, W, H);\n      gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, tex[cur]);\n      gl.uniform1i(su.uHist, 0);\n      gl.uniform1f(su.uBlend, blend);\n      gl.uniform2f(su.uRes, W, H);\n      gl.uniform2f(su.uJit, jx, jy);\n      gl.uniform2f(su.uLens, Math.cos(la) * lr, Math.sin(la) * lr);\n      gl.uniform1f(su.uSeed, reduce ? (s.n * 0.618) % 1 : (s.frame * 0.61803) % 1);\n      gl.uniform3f(su.uCam, c.cam[0], c.cam[1], c.cam[2]); gl.uniform3f(su.uTgt, c.tgt[0], c.tgt[1], c.tgt[2]);\n      gl.uniform1f(su.uFoc, c.foc); gl.uniform2f(su.uShift, c.shift[0], c.shift[1]);\n      gl.uniform1f(su.uFocus, c.dist); gl.uniform1f(su.uAper, 0.09);\n      gl.uniform2f(su.uYaw, Math.cos(s.yaw), Math.sin(s.yaw));\n      gl.uniform3f(su.uSun, sun[0], sun[1], sun[2]);\n      gl.uniform4fv(su.uGem, gemPlanes);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n      cur = nxt;\n      gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n      gl.viewport(0, 0, W, H);\n      gl.useProgram(post);\n      gl.bindTexture(gl.TEXTURE_2D, tex[cur]);\n      gl.uniform1i(pu.uImg, 0); gl.uniform2f(pu.uRes, W, H);\n      gl.uniform1f(pu.uGrain, s.frame % 61);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n    };\n\n    const frame = (now: number) => {\n      s.raf = 0;\n      if (!s.visible || !s.alive) return;\n      const dtRaw = s.last ? (now - s.last) / 1000 : 0.016;\n      s.last = now; s.frame++;\n      const dt = Math.min(dtRaw, 0.05);\n      s.t += dt;\n      // with nobody steering, the ring rocks slowly so the stone keeps finding the window\n      if (s.t - s.lastMove > 2.5 && s.t > 3.6) s.aim = 0.72 + 0.55 * Math.sin((s.t - 3.6) * 0.3);\n      // a heavy, well-damped spring: it leans into the turn and settles without a wobble\n      const before = s.yaw;\n      s.vel += ((s.aim - s.yaw) * 7.0 - s.vel * 4.6) * dt;\n      s.yaw += s.vel * dt;\n      const moved = Math.abs(s.yaw - before);\n      // gather frames: fresh after a jump, many deep when the ring is nearly still\n      // moving: mostly this frame, so nothing smears; still: keep gathering for clean edges\n      s.n = moved > 0.0004 ? 1 : s.n + 1;\n      const blend = moved > 0.0004 ? Math.min(1, 0.45 + moved * 120) : Math.max(1 / (s.n + 1), 0.035);\n      draw(blend);\n      if (s.first) { s.first = false; setShown(\"gl\"); }\n      s.fpsN++;\n      if (now - s.fpsT > 1000) { box.dataset.fps = String(Math.round((s.fpsN * 1000) / (now - s.fpsT))); s.fpsT = now; s.fpsN = 0; }\n      // measured, not guessed: if frames keep running long, trace fewer pixels\n      if (dtRaw > 0.026) s.slow++; else s.slow = Math.max(0, s.slow - 2);\n      if (s.slow > 40 && scale > 0.45) { scale *= 0.8; s.slow = 0; size(); }\n      // reduced motion: gather a still, then stop\n      if (reduce && s.n > 40 && Math.abs(s.vel) < 1e-3) return;\n      s.raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { if (!s.raf && s.visible && s.alive) { s.last = 0; s.raf = requestAnimationFrame(frame); } };\n\n    size();\n    const ro = new ResizeObserver(() => { size(); wake(); });\n    ro.observe(box);\n    const io = new IntersectionObserver(([e]) => { s.visible = e.isIntersecting && !document.hidden; if (s.visible) wake(); }, { threshold: 0.05 });\n    io.observe(box);\n    const vis = () => { s.visible = !document.hidden; if (s.visible) wake(); };\n    document.addEventListener(\"visibilitychange\", vis);\n\n    const move = (e: PointerEvent) => {\n      const r = box.getBoundingClientRect();\n      const x = (e.clientX - r.left) / r.width - 0.5;\n      s.aim = 0.72 + x * 1.6; s.lastMove = s.t;\n      if (reduce) { s.yaw = s.aim; s.vel = 0; s.n = 0; }\n      wake();\n    };\n    box.addEventListener(\"pointermove\", move);\n    api.current = { nudge: (d) => { s.aim += d; s.lastMove = s.t + 3; if (reduce) { s.yaw = s.aim; s.vel = 0; s.n = 0; } wake(); } };\n    const lost = (e: Event) => { e.preventDefault(); setShown(\"still\"); };\n    cv.addEventListener(\"webglcontextlost\", lost);\n    wake();\n\n    return () => {\n      s.alive = false;\n      cancelAnimationFrame(s.raf); ro.disconnect(); io.disconnect();\n      document.removeEventListener(\"visibilitychange\", vis);\n      box.removeEventListener(\"pointermove\", move);\n      cv.removeEventListener(\"webglcontextlost\", lost);\n      api.current = null;\n    };\n  }, []);\n\n  const turn = \"pointer-events-auto flex h-10 w-10 items-center justify-center rounded-full border border-[#2a1d12]/25 text-[#2a1d12] outline-none transition-colors hover:bg-[#2a1d12] hover:text-[#f7efe4] focus-visible:ring-2 focus-visible:ring-[#2a1d12] focus-visible:ring-offset-2 focus-visible:ring-offset-[#e9dfd3] motion-reduce:transition-none\";\n  return (\n    <section className=\"relative isolate overflow-hidden bg-[#ded1c3] text-[#2a1d12]\" style={{ fontFamily: FONT }}>\n      <style>{`\n        @keyframes gold-solitaire-ring-hero-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }\n        .gold-solitaire-ring-hero-rise { animation: gold-solitaire-ring-hero-rise 900ms cubic-bezier(0.2, 0.9, 0.2, 1) both; }\n        @media (prefers-reduced-motion: reduce) { .gold-solitaire-ring-hero-rise { animation: none; } }\n      `}</style>\n      <div ref={stage} className=\"relative mx-auto h-[860px] w-full max-w-[1600px] sm:h-[800px] lg:h-[760px]\">\n        {shown === \"still\" && <Still />}\n        <canvas ref={canvas} aria-hidden=\"true\" className={`absolute inset-0 h-full w-full transition-opacity duration-700 motion-reduce:transition-none ${shown === \"gl\" ? \"opacity-100\" : \"opacity-0\"}`} />\n        <div className=\"pointer-events-none absolute inset-0 flex flex-col px-6 pb-8 pt-6 sm:px-10 lg:px-16 lg:pb-12 lg:pt-10\">\n          <p className=\"flex items-center justify-between text-[11px] font-semibold uppercase tracking-[0.34em] text-[#3b2a1c]\">\n            <span>{piece.house}</span>\n            <span className=\"hidden sm:inline\">{piece.kind}</span>\n          </p>\n          <div className=\"gold-solitaire-ring-hero-rise mt-8 max-w-[36rem] lg:my-auto\">\n            <h1 className=\"text-[56px] font-normal leading-[0.9] tracking-[-0.035em] text-[#24170c] sm:text-[76px] lg:text-[104px]\" style={{ fontFamily: SERIF }}>\n              {piece.headline.map((l, i) => (\n                <span key={l} className={`block ${i === 1 ? \"italic text-[#8a5a1c]\" : \"\"}`}>{l}</span>\n              ))}\n            </h1>\n            <p className=\"mt-5 max-w-[25rem] text-[16px] leading-[1.55] text-[#3b2a1c] lg:mt-7 lg:text-[17px]\">{piece.line}</p>\n            <div className=\"mt-6 flex flex-wrap items-center gap-x-6 gap-y-3 lg:mt-8\">\n              <a href=\"#\" className=\"pointer-events-auto inline-flex h-[52px] items-center gap-3 whitespace-nowrap rounded-full bg-[#24170c] pl-7 pr-6 text-[15px] font-semibold tracking-[-0.01em] text-[#f9f1e6] shadow-[0_14px_30px_-14px_rgba(40,22,8,0.8)] outline-none transition-transform duration-200 hover:-translate-y-0.5 focus-visible:ring-2 focus-visible:ring-[#24170c] focus-visible:ring-offset-2 focus-visible:ring-offset-[#e9dfd3] motion-reduce:transition-none\">\n                {piece.cta}\n                <svg aria-hidden=\"true\" viewBox=\"0 0 20 20\" className=\"h-4 w-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\"><path d=\"M4 10h12M11 5l5 5-5 5\" /></svg>\n              </a>\n              <a href=\"#\" className=\"pointer-events-auto inline-flex h-11 items-center text-[15px] font-semibold text-[#24170c] underline decoration-[#24170c]/30 underline-offset-[6px] outline-none hover:decoration-[#24170c] focus-visible:ring-2 focus-visible:ring-[#24170c] focus-visible:ring-offset-2 focus-visible:ring-offset-[#e9dfd3]\">{piece.more}</a>\n            </div>\n          </div>\n          <div className=\"mt-auto flex items-end justify-between gap-4\">\n            <span className=\"text-[11px] font-semibold uppercase tracking-[0.26em] text-[#3b2a1c]\">{piece.note}</span>\n            {shown === \"gl\" && (\n              <div className=\"flex items-center gap-2\" role=\"group\" aria-label=\"Turn the ring\">\n                <button type=\"button\" aria-label=\"Turn the ring left\" onClick={() => api.current?.nudge(-0.45)} className={turn}>\n                  <svg aria-hidden=\"true\" viewBox=\"0 0 20 20\" className=\"h-4 w-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\"><path d=\"M12.5 4.5 7 10l5.5 5.5\" /></svg>\n                </button>\n                <button type=\"button\" aria-label=\"Turn the ring right\" onClick={() => api.current?.nudge(0.45)} className={turn}>\n                  <svg aria-hidden=\"true\" viewBox=\"0 0 20 20\" className=\"h-4 w-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\"><path d=\"M7.5 4.5 13 10l-5.5 5.5\" /></svg>\n                </button>\n              </div>\n            )}\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
