{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"sunlit-cast-resin-cube-pricing-in-webgl-where-a-shaft-of-window-light-picks-the-plan-and-the-cubes-tumble-over-to-yearly","type":"registry:block","title":"Sunlit Cast Resin Cube Pricing in WebGL Where a Shaft of Window Light Picks the Plan and the Cubes Tumble over to Yearly","description":"Free React pricing section in raw WebGL: three cast resin cubes on stone, a shaft of sun that moves to the chosen plan, and cubes that tip over for yearly prices.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/sunlit-cast-resin-cube-pricing-in-webgl-where-a-shaft-of-window-light-picks-the-plan-and-the-cubes-tumble-over-to-yearly.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport { motion, useReducedMotion } from \"framer-motion\";\n\n/** The product and its three plans. Prices are per month; `yearly` is the monthly rate when billed once a year. */\nconst product = { name: \"Penrow\", line: \"Bookkeeping for small studios\" };\nconst plans = [\n  {\n    name: \"Solo\",\n    monthly: 12,\n    yearly: 10,\n    pitch: \"One set of books, kept tidy.\",\n    features: [\"1 seat and 2 bank feeds\", \"Invoices, quotes and receipts\", \"Year-end export for your accountant\"],\n    size: 0.66, // edge of the cube, in metres\n    resin: [7.5, 3.3, 0.4], // how strongly the resin soaks up red, green and blue\n  },\n  {\n    name: \"Studio\",\n    monthly: 29,\n    yearly: 24,\n    pitch: \"The whole studio in one ledger.\",\n    features: [\"5 seats, unlimited bank feeds\", \"Payroll for up to 10 people\", \"Project budgets and time sheets\", \"Approvals before money moves\"],\n    size: 0.8,\n    resin: [0.1, 2.9, 5.0],\n  },\n  {\n    name: \"Company\",\n    monthly: 79,\n    yearly: 66,\n    pitch: \"Several entities, one close.\",\n    features: [\"25 seats across entities\", \"Consolidated month-end close\", \"Custom roles and audit trail\", \"A named onboarding lead\"],\n    size: 1.0,\n    resin: [0.5, 4.8, 2.0],\n  },\n];\n\nconst GAP = 0.42; // floor between neighbouring cubes\nconst PIVOT = -0.5; // the line on the floor the cubes tip over: monthly they stand behind it, yearly in front\nconst WEIGHT = 20; // gravity on the cubes: higher falls faster\nconst BOUNCE = 0.24; // how much speed survives each landing\nconst SHAFT_SPRING = 46; // pull of the light toward the chosen cube\nconst SHAFT_DAMPING = 7.5; // lower lets the light overshoot further\nconst DEMO = true; // plays through the plans by itself until somebody touches it\nconst SERIF = '\"Iowan Old Style\", \"Palatino Linotype\", Palatino, \"Book Antiqua\", Georgia, serif';\nconst GROTESK = '\"Inter Tight\", \"Inter\", ui-sans-serif, system-ui, sans-serif';\n\nconst clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));\nconst HALF_PI = Math.PI / 2;\nconst TILE = 1024;\n\n// where each cube stands along the row\nconst XS = (() => {\n  const total = plans.reduce((a, p) => a + p.size, 0) + GAP * (plans.length - 1);\n  let x = -total / 2;\n  return plans.map((p) => {\n    const c = x + p.size / 2;\n    x += p.size + GAP;\n    return c;\n  });\n})();\n\n// the sun, low and behind the wall, coming through a tall window above the frame\nconst SUN_DIR = [-0.2, 0.423, -0.884];\nconst WALL_Z = -8;\n\nconst GLSL = `#version 300 es\nprecision highp float;\nconst float ZW = ${WALL_Z.toFixed(1)};\nconst float SILL = 3.0;\nconst float RAD = 0.04;\nconst float SC = 0.5;\nconst vec3 L = vec3(${SUN_DIR.join(\", \")});\nconst vec3 SUN = vec3(1.0, 0.85, 0.64) * 7.5;\nconst vec3 SKY = vec3(0.6, 0.65, 0.74) * 0.66;\nconst vec3 FILLD = vec3(0.1407, 0.3283, 0.9340);\nconst vec3 FILL = vec3(1.0, 0.94, 0.86) * 0.56;\nuniform vec3 uC[3];\nuniform vec2 uCS[3];\nuniform float uH[3];\nuniform vec3 uAbs[3];\nuniform vec3 uSlot;\nuniform sampler2D uTex;\nuniform vec3 uCam, uRt, uUp, uFw;\nuniform float uTan, uAspect, uFocus, uAperture, uTime;\nuniform vec2 uShift, uRes;\nin vec2 vUv;\nout vec4 o;\n\nfloat ign(vec2 p) { return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715)))); }\nfloat hash(vec2 p) { p = fract(p * vec2(123.34, 456.21)); p += dot(p, p + 45.32); return fract(p.x * p.y); }\nfloat vnoise(vec2 p) {\n  vec2 i = floor(p), f = fract(p); f = f * f * (3.0 - 2.0 * f);\n  return mix(mix(hash(i), hash(i + vec2(1, 0)), f.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), f.x), f.y);\n}\nfloat fbm(vec2 p) { return 0.5 * vnoise(p) + 0.25 * vnoise(p * 2.1 + 7.3) + 0.125 * vnoise(p * 4.3 + 1.7) + 0.0625 * vnoise(p * 8.9); }\n\n// each cube has rolled about the x axis: into its own frame and back out\nvec3 dirL(vec3 d, int i) { vec2 r = uCS[i]; return vec3(d.x, d.y * r.x + d.z * r.y, -d.y * r.y + d.z * r.x); }\nvec3 dirW(vec3 d, int i) { vec2 r = uCS[i]; return vec3(d.x, d.y * r.x - d.z * r.y, d.y * r.y + d.z * r.x); }\nvec3 toL(vec3 p, int i) { return dirL(p - uC[i], i); }\nvec3 toW(vec3 q, int i) { return dirW(q, i) + uC[i]; }\n\nvec2 boxI(vec3 ro, vec3 rd, float h) {\n  rd = mix(rd, vec3(1e-5), lessThan(abs(rd), vec3(1e-5)));\n  vec3 m = 1.0 / rd, n = m * ro, k = abs(m) * h;\n  vec3 t1 = -n - k, t2 = -n + k;\n  return vec2(max(max(t1.x, t1.y), t1.z), min(min(t2.x, t2.y), t2.z));\n}\nfloat sdCube(vec3 q, float h) {\n  vec3 d = abs(q) - (h - RAD);\n  return length(max(d, 0.0)) + min(max(d.x, max(d.y, d.z)), 0.0) - RAD;\n}\n\n// The window: a tall slot in the wall, above the top of the frame. A point is in the sun\n// when the line from it toward the sun passes through the slot and over its sill.\nfloat slot(vec3 p) {\n  float k = (ZW - p.z) / L.z;\n  float pen = 0.011 * k + 0.012;\n  float x = p.x + L.x * k;\n  float y = p.y + L.y * k;\n  return smoothstep(-pen, pen, uSlot.y - abs(x - uSlot.x)) * smoothstep(-pen, pen, y - SILL);\n}\n\n// what is left of a ray of sun after it has crossed the other cubes: resin tints it and scatters most of it\nvec3 through(vec3 p, vec3 l, int skip) {\n  vec3 T = vec3(1.0);\n  for (int i = 0; i < 3; i++) {\n    if (i == skip) continue;\n    vec2 tb = boxI(toL(p, i), dirL(l, i), uH[i] - 0.004);\n    float len = tb.y - max(tb.x, 0.0);\n    if (len > 0.0 && tb.y > 0.0) {\n      // the arrises throw light aside, so the pool of colour has a dark outline and a bright heart\n      vec3 lo = toL(p, i), ld = dirL(l, i);\n      vec3 e1 = uH[i] - abs(lo + ld * max(tb.x, 0.0)), e2 = uH[i] - abs(lo + ld * tb.y);\n      float rim = min(e1.x + e1.y + e1.z - max(e1.x, max(e1.y, e1.z)), e2.x + e2.y + e2.z - max(e2.x, max(e2.y, e2.z)));\n      // and the faces gather what is left into a brighter band just inside that outline\n      float band = exp(-pow((rim - 0.22 * uH[i]) / (0.09 * uH[i]), 2.0));\n      T *= exp(-uAbs[i] * (0.12 + len * 1.0)) * (0.5 + 0.8 * exp(-SC * len)) * (0.25 + 0.75 * smoothstep(0.0, 0.1 * uH[i], rim)) * (1.2 + 1.3 * band);\n    }\n  }\n  return T;\n}\nvec3 sunVis(vec3 p, int skip, float jit, int ns) {\n  vec3 a = normalize(cross(L, vec3(0.0, 1.0, 0.0))), b = cross(L, a);\n  vec3 acc = vec3(0.0);\n  for (int j = 0; j < ns; j++) {\n    float an = float(j) * 2.39996 + jit * 6.2832;\n    float r = sqrt((float(j) + 0.5) / float(ns)) * 0.021;\n    acc += through(p, normalize(L + (a * cos(an) + b * sin(an)) * r), skip);\n  }\n  return acc / float(ns) * slot(p);\n}\n\nfloat lamp(vec3 rd, vec3 c, vec2 half_, float s) {\n  float d = dot(rd, c);\n  if (d <= 0.02) return 0.0;\n  vec3 rt = normalize(cross(vec3(0.0, 1.0, 0.0), c));\n  vec3 up = cross(c, rt);\n  vec2 q = vec2(dot(rd, rt), dot(rd, up)) / d;\n  vec2 e = half_ - abs(q);\n  // a skylight with one glazing bar\n  return smoothstep(-s, s, e.x) * smoothstep(-s, s, e.y) * (1.0 - 0.7 * smoothstep(s * 0.6, 0.0, abs(q.x + 0.08) - 0.012));\n}\n// the room a mirror would see: sky through a roof light, a white card behind the camera, dark elsewhere\nvec3 room(vec3 rd) {\n  vec3 c = mix(vec3(0.05, 0.055, 0.06), SKY * 0.9, smoothstep(-0.15, 0.9, rd.y));\n  c += vec3(0.86, 0.93, 1.0) * 60.0 * lamp(rd, normalize(vec3(0.2, 0.92, 0.34)), vec2(0.7, 0.42), 0.035);\n  // two tall strip lights off to the sides: they only show as thin lines down the rounded edges\n  c += vec3(1.0, 0.97, 0.92) * 75.0 * (lamp(rd, normalize(vec3(-0.86, 0.12, 0.5)), vec2(0.07, 0.7), 0.03) + lamp(rd, normalize(vec3(0.88, 0.1, 0.46)), vec2(0.05, 0.7), 0.03));\n  c += FILL * 2.2 * lamp(rd, normalize(vec3(-0.25, 0.22, 1.0)), vec2(0.8, 0.42), 0.12);\n  return c;\n}\n\nvec3 floorAlb(vec2 x) {\n  // pale terrazzo: a cream binder with marble chips of two sizes ground flat into it\n  vec3 a = mix(vec3(0.83, 0.76, 0.63), vec3(0.93, 0.87, 0.75), fbm(x * 0.7 + 2.0));\n  a *= 0.965 + 0.07 * vnoise(x * 190.0);\n  for (int s = 0; s < 2; s++) {\n    vec2 u = x * (s == 0 ? 5.2 : 12.5) + float(s) * 17.0;\n    vec2 c = floor(u), f = fract(u), id = vec2(0.0);\n    float d1 = 9.0, d2 = 9.0;\n    for (int j = -1; j <= 1; j++) for (int i = -1; i <= 1; i++) {\n      vec2 g = vec2(float(i), float(j));\n      vec2 r = g + vec2(hash(c + g), hash(c + g + 31.7)) - f;\n      float d = dot(r, r);\n      if (d < d1) { d2 = d1; d1 = d; id = c + g; } else if (d < d2) d2 = d;\n    }\n    float chip = smoothstep(0.0, 0.05, sqrt(d2) - sqrt(d1) - 0.14 - 0.3 * hash(id + 9.1)) * step(hash(id + 3.3), s == 0 ? 0.42 : 0.58);\n    float t = hash(id + 5.7);\n    vec3 cc = t < 0.3 ? vec3(0.96, 0.94, 0.89) : t < 0.5 ? vec3(0.6, 0.55, 0.5) : t < 0.72 ? vec3(0.84, 0.58, 0.4) : t < 0.88 ? vec3(0.74, 0.71, 0.62) : vec3(0.33, 0.4, 0.35);\n    a = mix(a, cc * (0.9 + 0.2 * vnoise(u * 5.0)), chip);\n  }\n  return a;\n}\nvec3 tintOf(int i) { return exp(-uAbs[i] * 0.42); }\n// a cube standing in the sun is a lantern: this is the coloured light it throws on a nearby surface\nvec3 lantern(vec3 p, vec3 n, int skip) {\n  vec3 c = vec3(0.0);\n  for (int i = 0; i < 3; i++) {\n    if (i == skip) continue;\n    float s = slot(uC[i] + vec3(0.0, uH[i], 0.0));\n    if (s < 0.01) continue;\n    vec3 d = uC[i] - p;\n    float r2 = dot(d, d);\n    c += tintOf(i) * tintOf(i) * SUN * s * uH[i] * uH[i] * 0.34 * max(dot(n, d) * inversesqrt(r2) + 0.15, 0.0) / (r2 + 0.05);\n  }\n  return c;\n}\n// a cube as seen in a reflection: its colour under the lights, without looking inside it\nvec3 cubeFar(int i, vec3 p, vec3 n) {\n  float s = slot(uC[i] + vec3(0.0, uH[i], 0.0));\n  vec3 t = tintOf(i);\n  return t * (SKY * (0.35 + 0.4 * n.y) + FILL * (0.25 + 0.6 * max(dot(n, FILLD), 0.0)) + SUN * s * (0.1 + 0.3 * max(dot(n, L), 0.0)) * t);\n}\nfloat aoCubes(vec3 p) {\n  float ao = 1.0;\n  for (int i = 0; i < 3; i++) {\n    float d = sdCube(toL(p, i), uH[i]);\n    float k = 1.0 - smoothstep(0.0, uH[i] * 1.5, d);\n    ao *= 1.0 - 0.72 * k * k;\n  }\n  return ao;\n}\n\nvec3 shadeWall(vec3 p) {\n  vec3 alb = vec3(0.024, 0.165, 0.1) * (0.8 + 0.42 * fbm(p.xy * vec2(0.55, 0.9) + 3.0)) * (0.98 + 0.04 * vnoise(p.xy * vec2(5.0, 23.0)));\n  float corner = 0.5 + 0.5 * smoothstep(0.0, 2.4, p.y);\n  float g = exp(-pow((p.x - uSlot.x - 1.9) / 3.4, 2.0));\n  vec3 bounce = vec3(1.0, 0.82, 0.6) * (0.5 + 1.6 * g) * exp(-p.y * 0.3);\n  return alb * (SKY * 0.5 * corner + FILL * 0.22 + bounce * 0.42);\n}\n\nvec3 shadeFloor(vec3 p, vec3 rd, float jit, int ns, bool mirror) {\n  vec3 alb = floorAlb(p.xz);\n  vec2 bump = vec2(vnoise(p.xz * 46.0 + 1.0), vnoise(p.xz * 46.0 + 7.0)) - 0.5;\n  vec3 n = normalize(vec3(bump.x * 0.03, 1.0, bump.y * 0.03));\n  float ao = aoCubes(p) * (0.62 + 0.38 * smoothstep(0.0, 3.0, p.z - ZW));\n  vec3 sv = sunVis(p + vec3(0.0, 0.003, 0.0), -1, jit, ns);\n  vec3 col = alb * (SUN * max(dot(n, L), 0.0) * sv + SKY * ao + FILL * 0.3 * ao);\n  // looking into the light, honed stone glares\n  col += SUN * sv * pow(max(dot(reflect(rd, n), L), 0.0), 22.0) * 0.16;\n  col += alb * lantern(p, n, -1) * ao;\n  if (mirror) {\n    // polished terrazzo seen at a low angle carries a soft reflection of whatever stands on it\n    vec3 R = reflect(rd, n);\n    float F = 0.04 + 0.96 * pow(1.0 - clamp(-rd.y, 0.0, 1.0), 5.0);\n    vec3 sheen = room(R) * F * 0.35;\n    float got = 0.0; vec3 seen = vec3(0.0);\n    for (int i = 0; i < 3; i++) {\n      vec3 lo = toL(p, i), ld = dirL(reflect(rd, vec3(0.0, 1.0, 0.0)), i);\n      vec2 tb = boxI(lo, ld, uH[i]);\n      if (tb.y > max(tb.x, 0.0) && tb.x > 0.0) {\n        vec3 q = lo + ld * tb.x;\n        vec3 nl = step(vec3(uH[i] - 0.002), abs(q)) * sign(q);\n        float w = exp(-tb.x * 1.7 / uH[i]) * smoothstep(0.0, 0.03, tb.y - tb.x);\n        if (w > got) { got = w; seen = cubeFar(i, toW(q, i), dirW(nl, i)); }\n      }\n    }\n    col += sheen * (1.0 - got) * ao;\n    col = mix(col, seen, got * F * 0.9);\n  }\n  return col;\n}\n\n// floor, wall, the other cubes or the room, for mirrors and for looking through a block\nvec3 traceSet(vec3 ro, vec3 rd, int self, float jit, bool gloss) {\n  float best = 1e9; int hit = -1; vec3 nrm = vec3(0.0);\n  if (rd.y < -1e-4) { best = -ro.y / rd.y; hit = 3; }\n  if (rd.z < -1e-4) { float tw = (ZW - ro.z) / rd.z; if (tw < best) { best = tw; hit = 4; } }\n  for (int i = 0; i < 3; i++) {\n    if (i == self) continue;\n    vec3 lo = toL(ro, i), ld = dirL(rd, i);\n    vec2 tb = boxI(lo, ld, uH[i]);\n    if (tb.y > tb.x && tb.x > 0.0 && tb.x < best) {\n      best = tb.x; hit = i;\n      vec3 q = lo + ld * tb.x;\n      nrm = dirW(step(vec3(uH[i] - 0.002), abs(q)) * sign(q), i);\n    }\n  }\n  if (hit < 0) return room(rd);\n  vec3 p = ro + rd * best;\n  if (hit == 3) return shadeFloor(p, rd, jit, 1, false);\n  if (hit == 4) {\n    vec3 w = shadeWall(p);\n    // a polished face picks up the row of window panes high in the wall\n    if (gloss) {\n      float px = abs(fract(p.x / 0.6 + 0.5) - 0.5) * 0.6;\n      w += vec3(0.88, 0.94, 1.0) * 3.6 * smoothstep(0.215, 0.205, px) * smoothstep(1.2, 1.26, p.y) * smoothstep(3.0, 2.9, p.y);\n    }\n    return w;\n  }\n  return cubeFar(hit, p, nrm);\n}\n\nvec3 shadeCube(int i, vec3 p, vec3 rd, float jit) {\n  float h = uH[i];\n  vec3 q = toL(p, i);\n  vec3 nl = normalize(max(abs(q) - (h - RAD), 0.0) * sign(q) + sign(q) * 1e-5);\n  vec3 rdl = dirL(rd, i);\n\n  // The price is white resin cast inside the block, a little way under the face it is read through.\n  // Looking along the bent line of sight shifts it against the surface, and its thickness shows as a darker flank.\n  int k = -1;\n  if (nl.z > 0.92) k = 0; else if (nl.y > 0.92) k = 1; else if (nl.z < -0.92) k = 2;\n  float paint = 0.0, flank = 0.0;\n  vec3 rf0 = refract(rdl, nl, 1.0 / 1.49);\n  if (k >= 0) {\n    vec2 f = k == 0 ? q.xy : k == 1 ? vec2(q.x, -q.z) : vec2(q.x, -q.y);\n    vec3 tv = k == 0 ? vec3(0.0, 1.0, 0.0) : k == 1 ? vec3(0.0, 0.0, -1.0) : vec3(0.0, -1.0, 0.0);\n    vec3 nf = k == 0 ? vec3(0.0, 0.0, 1.0) : k == 1 ? vec3(0.0, 1.0, 0.0) : vec3(0.0, 0.0, -1.0);\n    vec2 slide = vec2(rf0.x, dot(rf0, tv)) / max(-dot(rf0, nf), 0.25);\n    vec2 sc = vec2(1.0 / 3.0, 0.5), org = vec2(float(i), k == 1 ? 1.0 : 0.0);\n    vec2 dx = dFdx(f / (2.0 * h)) * sc, dy = dFdy(f / (2.0 * h)) * sc;\n    for (int s = 0; s < 4; s++) {\n      vec2 uv = clamp((f + slide * h * (0.1 + 0.035 * float(s))) / (2.0 * h) + 0.5, 0.004, 0.996);\n      float m = textureGrad(uTex, (uv + org) * sc, dx, dy).r;\n      if (s == 0) paint = m; else flank = max(flank, m);\n    }\n    flank = max(flank - paint, 0.0);\n  }\n  // cast resin is never optically flat: a slow ripple left by the mould\n  vec2 rip = vec2(vnoise(q.xy * 5.0 + q.z * 3.0 + float(i) * 9.0), vnoise(q.yz * 5.0 + q.x * 3.0 + 4.0)) - 0.5;\n  vec3 nb = normalize(nl + vec3(rip.x, rip.y, rip.x - rip.y) * 0.012);\n  vec3 n = dirW(nb, i);\n\n  // inside the block: follow the bent line of sight as it mirrors off the inner faces until it finds a way out,\n  // gathering on the way the light that reaches it from the sun, the sky and the fill card through the resin\n  vec3 A = uAbs[i], ext = A + SC * 0.3, pig = exp(-A * 0.3);\n  vec3 Ll = dirL(L, i), Ul = dirL(vec3(0.0, 1.0, 0.0), i), Fl = dirL(FILLD, i);\n  vec3 pos = q - nl * 0.003, dir = rf0;\n  vec3 trans = vec3(1.0), body = vec3(0.0);\n  for (int leg = 0; leg < 3; leg++) {\n    float Lx = max(boxI(pos, dir, h).y, 0.004);\n    vec3 acc = vec3(0.0);\n    for (int s = 0; s < 3; s++) {\n      float t = Lx * (float(s) + 0.2 + 0.6 * jit) / 3.0;\n      vec3 pk = pos + dir * t;\n      float ds = max(boxI(pk, Ll, h).y, 0.0);\n      vec3 pw = toW(pk + Ll * ds, i);\n      vec3 ins = SUN * slot(pw) * through(pw, L, i) * exp(-(A * 0.5 + SC * 0.3) * ds) * 2.0;\n      ins += SKY * exp(-ext * 0.7 * max(boxI(pk, Ul, h).y, 0.0)) * 3.0;\n      ins += FILL * exp(-ext * 0.7 * max(boxI(pk, Fl, h).y, 0.0)) * 3.2;\n      acc += exp(-ext * t) * ins;\n    }\n    body += trans * acc * pig * SC * Lx / 3.0;\n    // a couple of air bubbles the pour trapped: each is a small bright ring with a glint\n    if (leg == 0) for (int b = 0; b < 2; b++) {\n      vec3 r = vec3(hash(vec2(float(i) * 7.0 + float(b), 3.1)), hash(vec2(float(b) * 5.0 + float(i), 8.7)), hash(vec2(float(i + b) * 3.0, 1.3)));\n      vec3 oc = pos - (r - 0.5) * h * vec3(1.3, 1.2, 0.9);\n      float rad = (0.011 + 0.012 * r.z) * (0.5 + h), tc = -dot(oc, dir);\n      vec3 cl = oc + dir * tc;\n      float d2 = dot(cl, cl) / (rad * rad);\n      if (tc > 0.0 && tc < Lx && d2 < 1.0) {\n        vec3 nb2 = normalize(cl - dir * rad * sqrt(1.0 - d2));\n        body += trans * exp(-ext * tc) * ((SKY + FILL) * (0.2 + 2.2 * d2 * d2 * d2) + vec3(4.0) * pow(max(dot(nb2, normalize(Ul + Fl * 0.6)), 0.0), 24.0));\n      }\n    }\n    trans *= exp(-(A + SC * 0.55) * Lx);\n    vec3 pe = pos + dir * Lx;\n    vec3 ne = -normalize(step(vec3(h - 0.006), abs(pe)) * sign(pe) + sign(pe) * 1e-4);\n    // light that is trapped inside runs to the edges and leaves there: the far arrises of the block shine through it\n    vec3 ee = h - abs(pe);\n    float ed = ee.x + ee.y + ee.z - max(ee.x, max(ee.y, ee.z)) - min(ee.x, min(ee.y, ee.z));\n    body += trans * pig * (SKY * 1.5 + FILL * 1.3 + SUN * slot(toW(pe, i)) * 0.9) * exp(-ed / (0.03 * h + 0.008)) * 0.55;\n    vec3 od = refract(dir, ne, 1.49);\n    float inside = 1.0;\n    if (dot(od, od) > 0.0) {\n      inside = 0.04 + 0.96 * pow(1.0 - clamp(dot(od, -ne), 0.0, 1.0), 5.0);\n      body += trans * (1.0 - inside) * traceSet(toW(pe, i) + dirW(od, i) * 0.004, dirW(od, i), i, jit, false);\n    }\n    trans *= inside;\n    dir = reflect(dir, ne);\n    pos = pe + ne * 0.004;\n  }\n  body += trans * pig * (SKY * 0.5 + FILL * 0.3);\n\n  vec3 glow = lantern(p, n, i);\n  body += pig * glow * 0.9;\n  vec3 light = glow + SKY * (0.7 + 0.6 * n.y) + FILL * (0.8 + 3.2 * max(dot(n, FILLD), 0.0)) + SUN * max(dot(n, L), 0.0) * slot(p) * through(p + n * 0.01, L, i);\n  vec3 veil = exp(-A * h * 0.16);\n  vec3 col = mix(body, pig * (body * 0.5 + light * 0.2), flank);\n  col = mix(col, vec3(0.97, 0.95, 0.9) * light * veil + body * 0.1, paint);\n\n  float F = 0.04 + 0.96 * pow(1.0 - clamp(dot(-rd, n), 0.0, 1.0), 5.0);\n  // handled objects: faint wipe marks dull the mirror in patches, and specks of dust sit on the top\n  vec2 sq = (abs(nl.y) > 0.5 ? q.xz : abs(nl.z) > 0.5 ? q.xy : q.zy) / h;\n  F *= 0.62 + 0.38 * smoothstep(0.25, 0.7, fbm(sq * 2.3 + float(i) * 5.0));\n  vec3 R = reflect(rd, n);\n  vec3 refl = traceSet(p + n * 0.006, R, i, jit, true);\n  vec3 sp = SUN * slot(p) * through(p + n * 0.01, L, i);\n  refl += sp * (6.0 * pow(max(dot(R, L), 0.0), 380.0) + 0.9 * pow(max(dot(R, L), 0.0), 34.0));\n  col = mix(col, refl, F);\n  float speck = step(0.9965, hash(floor(sq * 90.0) + float(i))) * step(0.9, n.y);\n  col += speck * (SKY * 0.5 + SUN * slot(p) * 0.25);\n  return col;\n}\n\nvec3 tonemap(vec3 x) { x *= 0.31; return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0); }\n\nvoid main() {\n  vec2 ndc = vUv * 2.0 - 1.0 - uShift;\n  vec3 rd = normalize(uFw + uRt * (ndc.x * uTan * uAspect) + uUp * (ndc.y * uTan));\n  float jit = ign(gl_FragCoord.xy);\n  float best = 60.0; int hit = -1;\n  if (rd.y < -1e-4) { best = -uCam.y / rd.y; hit = 3; }\n  if (rd.z < -1e-4) { float tw = (ZW - uCam.z) / rd.z; if (tw < best) { best = tw; hit = 4; } }\n  for (int i = 0; i < 3; i++) {\n    vec3 lo = toL(uCam, i), ld = dirL(rd, i);\n    vec2 tb = boxI(lo, ld, uH[i]);\n    if (tb.y > max(tb.x, 0.0) && tb.x < best) {\n      float t = max(tb.x, 0.0); bool ok = false;\n      for (int s = 0; s < 30; s++) {\n        float d = sdCube(lo + ld * t, uH[i]);\n        if (d < 0.0004) { ok = true; break; }\n        t += d;\n        if (t > tb.y) break;\n      }\n      if (ok && t < best) { best = t; hit = i; }\n    }\n  }\n  vec3 p = uCam + rd * best;\n  vec3 col;\n  if (hit < 0) col = room(rd);\n  else if (hit == 3) col = shadeFloor(p, rd, jit, 6, true);\n  else if (hit == 4) col = shadeWall(p);\n  else col = shadeCube(hit, p, rd, jit);\n\n  // dust in the air shows the shaft itself\n  float beam = 0.0;\n  for (int s = 0; s < 8; s++) {\n    vec3 pb = uCam + rd * (best * (float(s) + jit) / 8.0);\n    beam += slot(pb) * dot(through(pb, L, -1), vec3(0.333));\n  }\n  col += SUN * beam / 8.0 * min(best, 22.0) * 0.0013;\n\n  float depth = best * dot(rd, uFw);\n  // motes of dust drifting through the room: only the ones inside the shaft catch the sun\n  for (int k = 0; k < 44; k++) {\n    float fk = float(k);\n    vec3 r = vec3(hash(vec2(fk, 1.7)), hash(vec2(fk, 5.3)), hash(vec2(fk, 9.1)));\n    vec3 pm = vec3(-3.4 + 6.4 * r.x, 0.08 + 2.2 * r.y, -3.6 + 8.0 * r.z);\n    pm += vec3(sin(uTime * 0.13 + fk * 2.1), 0.5 * sin(uTime * 0.09 + fk), cos(uTime * 0.1 + fk * 1.3)) * 0.3;\n    vec3 d = pm - uCam;\n    float z = dot(d, uFw);\n    if (z > depth) continue;\n    vec2 sp = vec2(dot(d, uRt) / (z * uTan * uAspect), dot(d, uUp) / (z * uTan)) + uShift;\n    float dist = length((sp - (vUv * 2.0 - 1.0)) * uRes * 0.5);\n    float size = (0.7 + 7.0 * abs(1.0 - uFocus / z)) * uRes.y / 780.0;\n    if (dist > size) continue;\n    col += SUN * slot(pm) * dot(through(pm, L, -1), vec3(0.333)) * smoothstep(size, size * 0.55, dist) * (0.25 + r.y) * 0.9 / (size * size) * (uRes.y / 780.0) * (uRes.y / 780.0);\n  }\n  float coc = clamp(uAperture * (1.0 - uFocus / max(depth, 0.05)), -1.0, 1.0);\n  o = vec4(pow(tonemap(col), vec3(1.0 / 2.2)), 0.5 + 0.5 * coc);\n}`;\n\nconst VS = `#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_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  // a disc of taps for whatever is out of focus; a tap only counts if its own blur reaches this pixel\n  for (int k = 1; k < 28; k++) {\n    float r = sqrt(float(k) / 28.0) * uMaxR;\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)), 1.0);\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)))); }\nconst vec3 LU = vec3(0.299, 0.587, 0.114);\nvoid main() {\n  // smooth the stair-steps along hard edges\n  vec3 m = texture(uScene, vUv).rgb;\n  vec3 cNW = texture(uScene, vUv + vec2(-1.0, -1.0) * uPx).rgb, cNE = texture(uScene, vUv + vec2(1.0, -1.0) * uPx).rgb;\n  vec3 cSW = texture(uScene, vUv + vec2(-1.0, 1.0) * uPx).rgb, cSE = texture(uScene, vUv + vec2(1.0, 1.0) * uPx).rgb;\n  float lNW = dot(cNW, LU), lNE = dot(cNE, LU), lSW = dot(cSW, LU), lSE = dot(cSE, LU);\n  float lM = dot(m, LU);\n  float lMin = min(lM, min(min(lNW, lNE), min(lSW, lSE))), lMax = max(lM, max(max(lNW, lNE), max(lSW, lSE)));\n  vec2 dir = vec2(-((lNW + lNE) - (lSW + lSE)), (lNW + lSW) - (lNE + lSE));\n  float rcp = 1.0 / (min(abs(dir.x), abs(dir.y)) + max((lNW + lNE + lSW + lSE) * 0.03125, 0.0078));\n  dir = clamp(dir * rcp, -8.0, 8.0) * uPx;\n  vec3 a = 0.5 * (texture(uScene, vUv + dir * (1.0 / 3.0 - 0.5)).rgb + texture(uScene, vUv + dir * (2.0 / 3.0 - 0.5)).rgb);\n  vec3 b = a * 0.5 + 0.25 * (texture(uScene, vUv - dir * 0.5).rgb + texture(uScene, vUv + dir * 0.5).rgb);\n  float lB = dot(b, LU);\n  vec3 col = (lB < lMin || lB > lMax) ? a : b;\n  // and give back a little of the bite the smoothing took\n  col += (m - 0.25 * (cNW + cNE + cSW + cSE)) * 0.4;\n  // halation: the hottest sunlit stone bleeds a little\n  vec3 glow = vec3(0.0);\n  float rot = 6.2832 * ign(gl_FragCoord.xy);\n  for (int k = 0; k < 14; k++) {\n    float an = float(k) * 2.39996 + rot;\n    float d = 3.0 + 26.0 * sqrt(float(k) / 14.0);\n    vec3 s = texture(uScene, vUv + vec2(cos(an), sin(an)) * d * uPx).rgb;\n    glow += s * smoothstep(0.8, 1.0, dot(s, LU));\n  }\n  col += glow / 14.0 * vec3(0.3, 0.22, 0.14);\n  vec2 q = vUv - 0.5;\n  col *= 1.0 - 0.55 * dot(q, q);\n  col += (ign(gl_FragCoord.xy + fract(uTime) * 61.0) - 0.5) * 0.02;\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 lettering cast inside the cubes: one tile per plan and billing period, white where the white resin goes. */\nfunction artwork() {\n  const cv = document.createElement(\"canvas\");\n  cv.width = TILE * plans.length;\n  cv.height = TILE * 2;\n  const ctx = cv.getContext(\"2d\")!;\n  ctx.fillStyle = \"#000\";\n  ctx.fillRect(0, 0, cv.width, cv.height);\n  ctx.fillStyle = \"#fff\";\n  ctx.textBaseline = \"alphabetic\";\n  const tracked = (s: string, x: number, y: number, font: string, gap: number, right = false) => {\n    ctx.font = font;\n    ctx.textAlign = \"left\";\n    const w = [...s].map((c) => ctx.measureText(c).width + gap);\n    let cx = right ? x - (w.reduce((a, b) => a + b, 0) - gap) : x;\n    [...s].forEach((c, i) => {\n      ctx.fillText(c, cx, y);\n      cx += w[i];\n    });\n    return cx;\n  };\n  plans.forEach((plan, i) => {\n    for (let row = 0; row < 2; row++) {\n      // row 0 is drawn into the top half of the canvas and ends up as the yearly face (the texture is flipped)\n      const yearly = row === 0;\n      const x0 = i * TILE, y0 = row * TILE;\n      ctx.save();\n      ctx.translate(x0, y0);\n      ctx.scale(TILE / 512, TILE / 512);\n      tracked(plan.name.toUpperCase(), 50, 88, `600 31px ${GROTESK}`, 9);\n      tracked(`0${i + 1}`, 462, 88, `600 31px ${GROTESK}`, 5, true);\n      ctx.fillRect(50, 114, 412, 4);\n      const end = tracked(\"$\", 44, 282, `500 104px ${GROTESK}`, 0);\n      tracked(String(yearly ? plan.yearly : plan.monthly), end + 6, 378, `600 292px ${GROTESK}`, -17);\n      tracked(yearly ? \"A MONTH, YEARLY\" : \"A MONTH\", 50, 458, `600 30px ${GROTESK}`, 7);\n      ctx.restore();\n    }\n  });\n  return cv;\n}\n\ntype Sim = {\n  th: number[]; om: number[]; goal: number[]; wait: number[];\n  sx: number; svx: number; sw: number; svw: number;\n  shake: number; vshake: number; plan: number; yearly: boolean; dirty: boolean; touched: boolean;\n};\n\n/** The same scene laid out with plain elements, for browsers without WebGL 2. */\nfunction Still({ plan, yearly }: { plan: number; yearly: boolean }) {\n  const hues = [[\"#f3b52b\", \"#b9741a\"], [\"#f4642c\", \"#b8371a\"], [\"#d0245f\", \"#7d1238\"]];\n  return (\n    <div aria-hidden=\"true\" className=\"absolute inset-0 overflow-hidden\" style={{ background: \"linear-gradient(180deg, #10291f 0%, #1c4735 46%, #24523d 58%, #8a7f6c 58%, #6f6657 100%)\" }}>\n      <div className=\"absolute inset-x-0 top-[58%] h-[9%]\" style={{ background: \"linear-gradient(180deg, rgba(0,0,0,0.3), rgba(0,0,0,0))\" }} />\n      <div\n        className=\"absolute bottom-0 top-[62%] w-[30%] -translate-x-1/2 transition-[left] duration-700 ease-out motion-reduce:transition-none sm:w-[22%]\"\n        style={{ left: `${[20, 50, 80][plan]}%`, background: \"linear-gradient(180deg, #f3dfbd, #fbe9c9)\", clipPath: \"polygon(14% 0, 86% 0, 100% 100%, 0 100%)\", filter: \"blur(2px)\" }}\n      />\n      {plans.map((p, i) => {\n        const lit = i === plan;\n        return (\n          <div key={p.name} className=\"absolute bottom-[16%] -translate-x-1/2\" style={{ left: `${[20, 50, 80][i]}%`, width: `min(${p.size * 25}%, ${p.size * 250}px)`, aspectRatio: \"1 / 1\" }}>\n            <div className=\"absolute -bottom-[5%] left-[6%] h-[12%] w-full rounded-[50%] bg-black/50 blur-md\" style={lit ? { background: hues[i][1], opacity: 0.7 } : undefined} />\n            <div className=\"absolute inset-x-0 bottom-full h-[12%]\" style={{ background: lit ? \"#ffe2b0\" : hues[i][0], clipPath: \"polygon(7% 0, 93% 0, 100% 100%, 0 100%)\", filter: lit ? \"none\" : \"brightness(0.72)\" }} />\n            <div\n              className=\"absolute inset-0 flex flex-col justify-between p-[9%] text-[#fbf3e2]\"\n              style={{ background: lit ? `linear-gradient(175deg, #ffcf8a 0%, ${hues[i][0]} 34%, ${hues[i][1]} 100%)` : `linear-gradient(175deg, ${hues[i][0]} 0%, ${hues[i][1]} 100%)`, filter: lit ? \"none\" : \"brightness(0.78)\", boxShadow: \"inset 0 1px 0 rgba(255,255,255,0.35), inset 0 0 0 1px rgba(255,255,255,0.12)\", fontFamily: GROTESK }}\n            >\n              <span className=\"border-b border-current pb-[6%] text-[7px] font-semibold uppercase tracking-[0.22em] sm:text-[10px]\">{p.name}</span>\n              <span className=\"text-[clamp(22px,7vw,112px)] font-semibold leading-[0.8] tracking-[-0.06em]\">\n                <span className=\"mr-[0.04em] align-top text-[0.4em] font-medium tracking-normal\">$</span>\n                {yearly ? p.yearly : p.monthly}\n              </span>\n            </div>\n          </div>\n        );\n      })}\n    </div>\n  );\n}\n\nexport default function ResinCubePricing() {\n  const reduce = useReducedMotion();\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const [plan, setPlan] = useState(1);\n  const [yearly, setYearly] = useState(false);\n  const [mode, setMode] = useState<\"pending\" | \"gl\" | \"still\">(\"pending\");\n  const [marks, setMarks] = useState<number[]>([24, 50, 76]);\n  const [handled, setHandled] = useState(false);\n  const sim = useRef<Sim>({\n    th: [0, 0, 0], om: [0, 0, 0], goal: [0, 0, 0], wait: [0, 0, 0],\n    sx: NaN, svx: 0, sw: 0, svw: 0, shake: 0, vshake: 0, plan: 1, yearly: false, dirty: true, touched: false,\n  });\n\n  // choosing a plan: the light swings over and the chosen cube rocks on its edge\n  useEffect(() => {\n    const s = sim.current;\n    if (s.plan !== plan) {\n      s.plan = plan;\n      if (Math.abs(s.om[plan]) < 0.01) s.om[plan] = (s.goal[plan] ? -1 : 1) * 0.5 * Math.sqrt((0.586 * WEIGHT) / plans[plan].size);\n    }\n    s.dirty = true;\n  }, [plan]);\n  // changing the billing period: every cube tips over its front edge, the small one first\n  useEffect(() => {\n    const s = sim.current;\n    if (s.yearly !== yearly) {\n      s.yearly = yearly;\n      plans.forEach((_, i) => {\n        s.goal[i] = yearly ? 1 : 0;\n        s.wait[i] = i * 0.13;\n      });\n    }\n    s.dirty = true;\n  }, [yearly]);\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 pScene: WebGLProgram, pLens: WebGLProgram, pOut: WebGLProgram;\n    try {\n      pScene = program(gl, VS, GLSL);\n      pLens = program(gl, VS, FS_LENS);\n      pOut = program(gl, VS, FS_OUT);\n    } catch {\n      setMode(\"still\");\n      return;\n    }\n    setMode(\"gl\");\n\n    const art = gl.createTexture();\n    gl.activeTexture(gl.TEXTURE0);\n    gl.bindTexture(gl.TEXTURE_2D, art);\n    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);\n    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, artwork());\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_WRAP_S, gl.CLAMP_TO_EDGE);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n    const aniso = gl.getExtension(\"EXT_texture_filter_anisotropic\");\n    if (aniso) gl.texParameterf(gl.TEXTURE_2D, aniso.TEXTURE_MAX_ANISOTROPY_EXT, 8);\n    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n\n    const vao = gl.createVertexArray();\n    const fbos = [gl.createFramebuffer(), gl.createFramebuffer()];\n    const texs = [gl.createTexture(), gl.createTexture()];\n    let W = 0, H = 0, scale = Math.min(window.devicePixelRatio || 1, 2), cssW = 1, cssH = 1;\n    const TAN = Math.tan((7.7 * Math.PI) / 180);\n    const cam = { pos: [0, 2, 10], rt: [1, 0, 0], up: [0, 1, 0], fw: [0, 0, -1], shift: [0, 0], focus: 10 };\n\n    const aim = (sway: number, lift: number) => {\n      const aspect = cssW / cssH;\n      const wide = aspect > 1.2;\n      const dist = Math.max(10, 2.05 / (TAN * aspect));\n      const el = wide ? 0.15 : 0.12;\n      const target = [0, 0.5, PIVOT];\n      cam.pos = [target[0] + sway, target[1] + Math.sin(el) * dist + lift, target[2] + Math.cos(el) * dist];\n      let fw = [target[0] - cam.pos[0], target[1] - cam.pos[1] + lift, target[2] - cam.pos[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      cam.fw = fw;\n      cam.rt = rt;\n      cam.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      cam.shift = wide ? [0, -0.235] : [0, -0.3];\n      cam.focus = fl;\n      return aspect;\n    };\n    const project = (p: number[]) => {\n      const d = [p[0] - cam.pos[0], p[1] - cam.pos[1], p[2] - cam.pos[2]];\n      const z = d[0] * cam.fw[0] + d[1] * cam.fw[1] + d[2] * cam.fw[2];\n      const x = (d[0] * cam.rt[0] + d[1] * cam.rt[1] + d[2] * cam.rt[2]) / (z * TAN * (cssW / cssH)) + cam.shift[0];\n      const y = (d[0] * cam.up[0] + d[1] * cam.up[1] + d[2] * cam.up[2]) / (z * TAN) + cam.shift[1];\n      return [(x * 0.5 + 0.5) * cssW, (0.5 - y * 0.5) * cssH];\n    };\n\n    const resize = () => {\n      cssW = wrap.clientWidth;\n      cssH = wrap.clientHeight;\n      let k = scale;\n      if (cssW * cssH * k * k > 2.1e6) k = Math.sqrt(2.1e6 / (cssW * cssH));\n      const w = Math.max(2, Math.round(cssW * k)), h = Math.max(2, Math.round(cssH * k));\n      aim(0, 0);\n      setMarks(XS.map((x) => (project([x, 0, PIVOT])[0] / cssW) * 100));\n      if (w === W && h === H) return;\n      W = w;\n      H = h;\n      canvas.width = W;\n      canvas.height = H;\n      texs.forEach((t, i) => {\n        gl.activeTexture(gl.TEXTURE1 + i);\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, fbos[i]);\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 centre = (i: number) => {\n      const h = plans[i].size / 2, c = Math.cos(s.th[i]), sn = Math.sin(s.th[i]);\n      // the cube turns about its front bottom edge, which stays on the pivot line\n      return [XS[i], h * c + h * sn, PIVOT + h * sn - h * c];\n    };\n    // where the window has to be for the sun to land on a cube\n    const shaftFor = (i: number) => {\n      const c = centre(i);\n      return c[0] + SUN_DIR[0] * ((WALL_Z - c[2]) / SUN_DIR[2]);\n    };\n\n    const draw = (t: number) => {\n      const aspect = aim(reduce ? 0 : 0.16 * Math.sin(t * 0.23), s.shake);\n      gl.bindVertexArray(vao);\n      gl.disable(gl.DEPTH_TEST);\n      gl.viewport(0, 0, W, H);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, fbos[0]);\n      gl.useProgram(pScene);\n      const cs: number[] = [], cc: number[] = [], hh: number[] = [], ab: number[] = [];\n      plans.forEach((p, i) => {\n        cc.push(...centre(i));\n        cs.push(Math.cos(s.th[i]), Math.sin(s.th[i]));\n        hh.push(p.size / 2);\n        ab.push(...p.resin);\n      });\n      gl.uniform3fv(U(pScene, \"uC\"), cc);\n      gl.uniform2fv(U(pScene, \"uCS\"), cs);\n      gl.uniform1fv(U(pScene, \"uH\"), hh);\n      gl.uniform3fv(U(pScene, \"uAbs\"), ab);\n      gl.uniform3f(U(pScene, \"uSlot\"), s.sx, s.sw + (reduce ? 0 : 0.012 * Math.sin(t * 0.8)), 0);\n      gl.uniform1i(U(pScene, \"uTex\"), 0);\n      gl.uniform3fv(U(pScene, \"uCam\"), cam.pos);\n      gl.uniform3fv(U(pScene, \"uRt\"), cam.rt);\n      gl.uniform3fv(U(pScene, \"uUp\"), cam.up);\n      gl.uniform3fv(U(pScene, \"uFw\"), cam.fw);\n      gl.uniform1f(U(pScene, \"uTan\"), TAN);\n      gl.uniform1f(U(pScene, \"uAspect\"), aspect);\n      gl.uniform2fv(U(pScene, \"uShift\"), cam.shift);\n      gl.uniform2f(U(pScene, \"uRes\"), W, H);\n      gl.uniform1f(U(pScene, \"uFocus\"), cam.focus);\n      gl.uniform1f(U(pScene, \"uAperture\"), 0.8);\n      gl.uniform1f(U(pScene, \"uTime\"), t);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, fbos[1]);\n      gl.useProgram(pLens);\n      gl.uniform1i(U(pLens, \"uScene\"), 1);\n      gl.uniform2f(U(pLens, \"uPx\"), 1 / W, 1 / H);\n      gl.uniform1f(U(pLens, \"uMaxR\"), H * 0.0085);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n      gl.useProgram(pOut);\n      gl.uniform1i(U(pOut, \"uScene\"), 2);\n      gl.uniform2f(U(pOut, \"uPx\"), 1 / W, 1 / H);\n      gl.uniform1f(U(pOut, \"uTime\"), reduce ? 0 : t);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n    };\n\n    // A cube on its edge is an upside-down pendulum with two places to rest: flat on one face (0) or on the next (a quarter turn).\n    const physics = (dt: number) => {\n      plans.forEach((p, i) => {\n        const k = WEIGHT / p.size;\n        if (s.wait[i] > 0) {\n          s.wait[i] -= dt;\n          return;\n        }\n        const want = s.goal[i] * HALF_PI;\n        const side = s.th[i] > Math.PI / 4 ? HALF_PI : 0;\n        let acc = -k * Math.sin(Math.PI / 4 - s.th[i]);\n        // a steady push until it is over the balance point, then gravity does the rest\n        if (side !== want) acc += (want > side ? 1 : -1) * k * 0.86;\n        s.om[i] += acc * dt;\n        s.th[i] += s.om[i] * dt;\n        for (const [wall, sign] of [[0, -1], [HALF_PI, 1]] as const) {\n          if ((s.th[i] - wall) * sign > 0) {\n            s.th[i] = wall;\n            const hit = Math.abs(s.om[i]);\n            if (s.om[i] * sign > 0) s.om[i] = hit > 0.5 ? -s.om[i] * BOUNCE : 0;\n            if (hit > 1.2) s.vshake -= hit * p.size * p.size * p.size * 0.085;\n          }\n        }\n      });\n      const tx = shaftFor(s.plan), tw = plans[s.plan].size / 2 + 0.34;\n      s.svx += (SHAFT_SPRING * (tx - s.sx) - SHAFT_DAMPING * s.svx) * dt;\n      s.sx += s.svx * dt;\n      s.svw += (SHAFT_SPRING * (tw - s.sw) - SHAFT_DAMPING * 1.4 * s.svw) * dt;\n      s.sw += s.svw * dt;\n      s.vshake += (-900 * s.shake - 34 * s.vshake) * dt;\n      s.shake += s.vshake * dt;\n    };\n    const settle = () => {\n      plans.forEach((_, i) => {\n        s.th[i] = s.goal[i] * HALF_PI;\n        s.om[i] = 0;\n        s.wait[i] = 0;\n      });\n      s.sx = shaftFor(s.plan);\n      s.sw = plans[s.plan].size / 2 + 0.34;\n      s.svx = s.svw = s.shake = s.vshake = 0;\n    };\n    settle();\n\n    let raf = 0, visible = true, last = performance.now(), slow = 0, frames = 0;\n    const t0 = last;\n    // the demo keeps its own clock, counted in simulated time, so a slow machine never gets ahead of its cubes\n    let played = 0, demoAt = 4.2, step = 0;\n    const tick = (now: number) => {\n      const real = now - last;\n      const dt = clamp(real / 1000, 0, 0.05); // the first frame can be stamped before the effect ran\n      last = now;\n      const t = (now - t0) / 1000;\n      if (reduce) {\n        if (s.dirty) settle();\n      } else {\n        const sub = Math.max(1, Math.ceil(dt / 0.004));\n        for (let i = 0; i < sub; i++) physics(dt / sub);\n        played += dt;\n        if (DEMO && !s.touched && played > demoAt) {\n          // the gallery plays itself: yearly, the big plan, the small one, monthly, and home again\n          const script = [() => setYearly(true), () => setPlan(2), () => setPlan(0), () => setYearly(false), () => setPlan(1)];\n          script[step % script.length]();\n          step++;\n          demoAt = played + 3.4;\n        }\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.5) {\n            scale *= 0.84;\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    // pressing a cube chooses its plan\n    const over = (e: PointerEvent) => {\n      const r = wrap.getBoundingClientRect();\n      const x = e.clientX - r.left, y = e.clientY - r.top;\n      aim(0, 0);\n      for (let i = 0; i < plans.length; i++) {\n        const c = centre(i), h = plans[i].size / 2;\n        const a = project([c[0] - h, c[1] + h, c[2]]), b = project([c[0] + h, 0, c[2] + h]);\n        if (x > a[0] - 6 && x < b[0] + 6 && y > a[1] - 6 && y < b[1] + 6) return i;\n      }\n      return -1;\n    };\n    const touch = () => {\n      s.touched = true;\n      setHandled(true);\n    };\n    const down = (e: PointerEvent) => {\n      touch();\n      const i = over(e);\n      if (i >= 0) setPlan(i);\n    };\n    const move = (e: PointerEvent) => {\n      canvas.style.cursor = over(e) >= 0 ? \"pointer\" : \"\";\n    };\n    const lost = (e: Event) => {\n      e.preventDefault();\n      setMode(\"still\");\n    };\n    canvas.addEventListener(\"pointerdown\", down);\n    canvas.addEventListener(\"pointermove\", move);\n    canvas.addEventListener(\"webglcontextlost\", lost);\n    wrap.addEventListener(\"keydown\", touch);\n    wrap.addEventListener(\"pointerdown\", touch);\n    wrap.addEventListener(\"focusin\", touch);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      canvas.removeEventListener(\"pointerdown\", down);\n      canvas.removeEventListener(\"pointermove\", move);\n      canvas.removeEventListener(\"webglcontextlost\", lost);\n      wrap.removeEventListener(\"keydown\", touch);\n      wrap.removeEventListener(\"pointerdown\", touch);\n      wrap.removeEventListener(\"focusin\", touch);\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    };\n  }, [reduce]);\n\n  const chosen = plans[plan];\n  const price = yearly ? chosen.yearly : chosen.monthly;\n  const ink = \"text-[#f6eedd]\";\n\n  return (\n    <section className=\"relative overflow-hidden bg-[#163a2d]\" style={{ fontFamily: GROTESK }}>\n      <div ref={wrapRef} className=\"relative h-[600px] w-full sm:h-[780px]\">\n        <canvas ref={canvasRef} aria-hidden=\"true\" className={`absolute inset-0 h-full w-full touch-pan-y ${mode === \"still\" ? \"hidden\" : \"\"}`} />\n        {mode === \"still\" && <Still plan={plan} yearly={yearly} />}\n\n        <div className={`pointer-events-none absolute inset-x-0 top-0 flex items-center justify-between p-5 sm:p-9 ${ink}`}>\n          <p className=\"flex items-baseline gap-3\">\n            <span className=\"text-[22px] italic leading-none sm:text-[26px]\" style={{ fontFamily: SERIF, letterSpacing: \"-0.02em\" }}>\n              {product.name}\n            </span>\n            <span className=\"hidden text-[11px] font-medium uppercase tracking-[0.26em] text-[#f6eedd]/75 sm:inline\">{product.line}</span>\n          </p>\n          <div className=\"pointer-events-auto flex items-center gap-3 text-[11px] font-semibold uppercase tracking-[0.2em]\">\n            <span id=\"resin-cube-pricing-billing\" className={yearly ? \"text-[#f6eedd]/70\" : \"\"}>\n              Monthly\n            </span>\n            <button\n              type=\"button\"\n              role=\"switch\"\n              aria-checked={yearly}\n              aria-label=\"Bill yearly\"\n              onClick={() => setYearly((v) => !v)}\n              className=\"relative h-10 w-[68px] rounded-full border border-[#f6eedd]/35 bg-black/25 backdrop-blur-sm transition-colors hover:bg-black/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#f6eedd]\"\n            >\n              <span\n                className=\"absolute left-1 top-1 h-[30px] w-[30px] rounded-full bg-[#f6eedd] shadow-[0_2px_6px_rgba(0,0,0,0.4)] transition-transform duration-300 ease-out motion-reduce:transition-none\"\n                style={{ transform: yearly ? \"translateX(28px)\" : \"none\" }}\n              />\n            </button>\n            <span className={yearly ? \"\" : \"text-[#f6eedd]/70\"}>Yearly</span>\n          </div>\n        </div>\n\n        <div className={`pointer-events-none absolute left-5 top-[76px] sm:left-9 sm:top-[112px] ${ink}`} aria-live={handled ? \"polite\" : \"off\"}>\n          <p className=\"text-[11px] font-semibold uppercase tracking-[0.26em] text-[#f6eedd]/80\">\n            <span className=\"tabular-nums text-[#f6eedd]\">{`0${plan + 1}`}</span>\n            <span className=\"mx-2 text-[#f6eedd]/45\">/</span>\n            {chosen.name}\n          </p>\n          <h2 className=\"mt-1 flex items-start overflow-hidden pb-1 font-semibold leading-[0.84] sm:mt-2\" style={{ letterSpacing: \"-0.065em\" }}>\n            <span className=\"mr-1 mt-[0.1em] text-[40px] font-medium sm:text-[76px]\" style={{ letterSpacing: \"0\" }}>\n              $\n            </span>\n            <motion.span\n              key={`${plan}-${yearly}`}\n              initial={reduce ? false : { y: \"0.5em\", opacity: 0 }}\n              animate={{ y: 0, opacity: 1 }}\n              transition={{ type: \"spring\", stiffness: 260, damping: 24 }}\n              className=\"block text-[104px] tabular-nums sm:text-[196px]\"\n            >\n              {price}\n            </motion.span>\n            <span className=\"ml-3 mt-[0.72em] self-start text-[12px] font-semibold uppercase leading-[1.5] tracking-[0.2em] text-[#f6eedd]/80 sm:ml-5 sm:mt-[9.6em] sm:text-[12px]\">\n              a month\n              <span className=\"block normal-case tracking-normal text-[#f6eedd]/75\" style={{ letterSpacing: \"0.01em\" }}>\n                {yearly ? `$${chosen.yearly * 12} billed once a year` : \"billed every month\"}\n              </span>\n            </span>\n          </h2>\n          <p className=\"mt-1 text-[19px] italic leading-tight sm:mt-2 sm:text-[26px]\" style={{ fontFamily: SERIF, letterSpacing: \"-0.01em\" }}>\n            {chosen.pitch}\n          </p>\n        </div>\n\n        <div className={`absolute right-9 top-[96px] hidden w-[262px] lg:block ${ink}`}>\n          <ul className=\"space-y-2 border-t border-[#f6eedd]/30 pt-3.5 text-[14px] leading-snug\">\n            {chosen.features.map((f) => (\n              <li key={f} className=\"flex gap-3\">\n                <svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"mt-0.5 shrink-0\">\n                  <path d=\"M4 10.5l4 4 8-9\" />\n                </svg>\n                {f}\n              </li>\n            ))}\n          </ul>\n          <a\n            href=\"#\"\n            className=\"mt-4 inline-flex h-11 items-center gap-3 rounded-full bg-[#f6eedd] pl-5 pr-4 text-[14px] font-semibold text-[#12281f] transition hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#f6eedd] focus-visible:ring-offset-2 focus-visible:ring-offset-[#163a2d]\"\n          >\n            Start with {chosen.name}\n            <svg aria-hidden=\"true\" width=\"18\" height=\"18\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n              <path d=\"M4 10h12M11 5l5 5-5 5\" />\n            </svg>\n          </a>\n        </div>\n\n        <fieldset className=\"absolute inset-x-0 bottom-4 h-11\">\n          <legend className=\"sr-only\">Plan</legend>\n          {plans.map((p, i) => (\n            <label\n              key={p.name}\n              htmlFor={`resin-cube-pricing-plan-${i}`}\n              className=\"absolute top-0 -translate-x-1/2 cursor-pointer\"\n              style={{ left: `${mode === \"still\" ? [20, 50, 80][i] : marks[i]}%` }}\n            >\n              <input id={`resin-cube-pricing-plan-${i}`} type=\"radio\" name=\"resin-cube-pricing-plan\" value={p.name} checked={plan === i} onChange={() => setPlan(i)} className=\"peer sr-only\" />\n              <span className=\"flex h-11 items-center gap-2.5 whitespace-nowrap rounded-full border border-black/10 bg-[#f6eedd]/90 pl-3 pr-4 text-[12px] font-semibold uppercase tracking-[0.16em] text-[#12281f] shadow-[0_6px_20px_rgba(20,14,6,0.28)] backdrop-blur-sm transition peer-checked:bg-[#12281f] peer-checked:text-[#f6eedd] peer-focus-visible:ring-2 peer-focus-visible:ring-[#12281f] peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-[#f6eedd] sm:text-[13px]\">\n                <span className={`grid h-4 w-4 place-items-center rounded-full border-[1.5px] ${plan === i ? \"border-[#f6eedd]\" : \"border-[#12281f]/60\"}`}>\n                  <span className={`h-2 w-2 rounded-full bg-[#f6eedd] transition-transform ${plan === i ? \"scale-100\" : \"scale-0\"}`} />\n                </span>\n                {p.name}\n              </span>\n            </label>\n          ))}\n        </fieldset>\n      </div>\n\n      <div className={`border-t border-[#f6eedd]/15 px-5 pb-8 pt-6 lg:hidden ${ink}`}>\n        <ul className=\"space-y-2.5 text-[15px] leading-snug\">\n          {chosen.features.map((f) => (\n            <li key={f} className=\"flex gap-3\">\n              <svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"mt-0.5 shrink-0\">\n                <path d=\"M4 10.5l4 4 8-9\" />\n              </svg>\n              {f}\n            </li>\n          ))}\n        </ul>\n        <a\n          href=\"#\"\n          className=\"mt-6 inline-flex h-12 items-center gap-3 rounded-full bg-[#f6eedd] pl-6 pr-5 text-[14px] font-semibold text-[#12281f] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#f6eedd] focus-visible:ring-offset-2 focus-visible:ring-offset-[#163a2d]\"\n        >\n          Start with {chosen.name}\n          <svg aria-hidden=\"true\" width=\"18\" height=\"18\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n            <path d=\"M4 10h12M11 5l5 5-5 5\" />\n          </svg>\n        </a>\n      </div>\n    </section>\n  );\n}\n"}]}
