{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ray-traced-cast-glass-column-bar-chart-that-rises-through-steel-collars-and-throws-amber-to-ruby-light-across-a-white-floor","type":"registry:block","title":"Ray-Traced Cast Glass Column Bar Chart That Rises Through Steel Collars and Throws Amber to Ruby Light Across a White Floor","description":"Free React bar chart whose bars are columns of coloured glass, ray traced in a WebGL shader on a sunlit white floor, with two data sets and a real data table.","dependencies":[],"files":[{"path":"components/we-inc/ray-traced-cast-glass-column-bar-chart-that-rises-through-steel-collars-and-throws-amber-to-ruby-light-across-a-white-floor.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// DEMO DATA. Six columns, two sets. One scene unit of glass is SCALE bookings.\nconst labels = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\"];\nconst months = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\"];\nconst sets = [\n  { key: \"This year\", noun: \"bookings this half\", values: [92, 118, 104, 163, 207, 248] },\n  { key: \"Last year\", noun: \"bookings, same half last year\", values: [121, 84, 146, 132, 188, 171] },\n];\n// The colour of white paper seen through each column, front face to back face (red, green, blue from 0 to 1).\nconst glass: [number, number, number][] = [\n  [1.0, 0.7, 0.08],\n  [1.0, 0.52, 0.06],\n  [1.0, 0.34, 0.08],\n  [0.95, 0.2, 0.12],\n  [0.84, 0.1, 0.16],\n  [0.64, 0.05, 0.2],\n];\nconst SCALE = 100;\nconst N = labels.length;\nconst FONT = '\"Inter Tight\", \"Inter\", ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif';\nconst SERIF = '\"Iowan Old Style\", \"Palatino Linotype\", Palatino, \"Book Antiqua\", Georgia, serif';\n\n// Scene units.\nconst PITCH = 0.8, HALF = 0.2;\nconst xOf = (i: number) => (i - (N - 1) / 2) * PITCH;\nconst sum = (a: number[]) => a.reduce((x, y) => x + y, 0);\nconst fmt = (n: number) => n.toLocaleString(\"en-GB\");\n\nconst VERT = `#version 300 es\nin vec2 aPos; void main(){ gl_Position = vec4(aPos, 0.0, 1.0); }`;\n\nconst TONE = `\nvec3 film(vec3 x){ return clamp(x * (2.51 * x + 0.03) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0); }\nvec3 tone(vec3 x){ x *= 0.86; float l = max(x.r, max(x.g, x.b)) + 1e-4; vec3 keep = x / l * film(vec3(l)).r; return pow(mix(film(x), keep, 0.55), vec3(1.0 / 2.2)); }\n`;\n\n// The photograph. Every column is a box, so a ray meets it in closed form: in through one face,\n// bounced off the inside of the others for as long as the angle is past critical, and out. The\n// coloured light on the floor is found by walking from the floor toward the sun through the glass.\nconst SCENE = `#version 300 es\nprecision highp float;\nout vec4 outC;\nconst int N = ${N};\nuniform vec2 uRes; uniform vec4 uJit; uniform float uSeed;\nuniform vec3 uCam; uniform vec3 uTgt; uniform float uFoc; uniform vec2 uShift; uniform float uFocus;\nuniform float uH[N]; uniform vec3 uSig[N]; uniform float uSel; uniform vec3 uSun;\nuniform sampler2D uTex; uniform float uDirect;\nconst float P = ${PITCH.toFixed(3)}; const float HW = ${HALF.toFixed(3)};\nconst float CW = ${(HALF + 0.036).toFixed(3)}; const float CH = 0.03;\nconst float BEV = 0.022;\nconst vec3 SUNC = vec3(1.0, 0.93, 0.82);\nconst vec3 HAZE = vec3(0.98, 0.955, 0.925);\n${TONE}\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 barX(int i){ return (float(i) - float(N - 1) * 0.5) * P; }\nfloat fres(float c){ return 0.04 + 0.96 * pow(1.0 - clamp(c, 0.0, 1.0), 5.0); }\n// the faces are bloomed like a lens, so head-on they give back very little\nfloat fresG(float c){ return 0.018 + 0.982 * pow(1.0 - clamp(c, 0.0, 1.0), 5.0); }\n\nbool boxHit(vec3 ro, vec3 rd, vec3 lo, vec3 hi, out float tN, out float tF, out vec3 nN, out vec3 nF){\n  vec3 s = vec3(rd.x < 0.0 ? -1.0 : 1.0, rd.y < 0.0 ? -1.0 : 1.0, rd.z < 0.0 ? -1.0 : 1.0);\n  vec3 inv = 1.0 / (s * max(abs(rd), vec3(1e-6)));\n  vec3 a = (lo - ro) * inv; vec3 b = (hi - ro) * inv; vec3 mn = min(a, b); vec3 mx = max(a, b);\n  tN = max(mn.x, max(mn.y, mn.z)); tF = min(mx.x, min(mx.y, mx.z));\n  nN = -s * step(mn.yzx, mn.xyz) * step(mn.zxy, mn.xyz);\n  nF = s * step(mx.xyz, mx.yzx) * step(mx.xyz, mx.zxy);\n  return tF > max(tN, 0.0);\n}\n// The arrises are ground and polished: near an edge the normal rolls over to the next face.\nvec3 bevel(vec3 p, vec3 c, vec3 b, vec3 n, float r){\n  vec3 q = p - c; vec3 d = (b - abs(q)) / r;\n  vec3 w = (1.0 - abs(n)) * pow(clamp(1.0 - d, 0.0, 1.0), vec3(2.0));\n  return normalize(n + sign(q) * w * 2.2);\n}\nfloat arris(vec3 p, vec3 c, vec3 b, vec3 n, float r){\n  vec3 w = (1.0 - abs(n)) * clamp(1.0 - (b - abs(p - c)) / r, 0.0, 1.0);\n  return max(w.x, max(w.y, w.z));\n}\n// Seeds: the few small bubbles any cast block keeps. They ride up and down with the glass.\nvec4 seed(int i, int k){\n  float f = float(i) * 7.31 + float(k) * 3.17;\n  vec3 r = fract(sin(vec3(f * 12.9898, f * 78.233 + 1.3, f * 37.719 + 2.1)) * 43758.5453);\n  return vec4(barX(i) + (r.x - 0.5) * (HW * 1.5), uH[i] - 0.12 - r.y * 0.75, (r.z - 0.5) * (HW * 1.5), 0.007 + 0.009 * fract(f * 0.37));\n}\n// Cast glass is never quite flat.\nvec3 wob(vec3 n, vec3 p){\n  vec3 g = vec3(sin(p.y * 5.3 + p.z * 9.0 + p.x * 2.0), sin(p.x * 8.0 + p.z * 7.0 + 1.7), sin(p.y * 6.1 + p.x * 9.5 + 0.6));\n  return normalize(n + (g - n * dot(g, n)) * 0.012);\n}\n\n// ---- the room ----\nfloat rectL(vec3 rd, vec3 c, vec3 n, vec3 u, vec3 v, vec2 hs, float soft){\n  float dn = dot(rd, n); if (dn > -1e-4) return 0.0;\n  float t = dot(c, n) / dn; if (t < 0.0) return 0.0;\n  vec3 q = rd * t - c; float s = soft * t;\n  vec2 d = abs(vec2(dot(q, u), dot(q, v))) - hs;\n  return smoothstep(s, -s, d.x) * smoothstep(s, -s, d.y);\n}\nvec3 env(vec3 rd){\n  float up = smoothstep(-0.05, 0.75, rd.y);\n  vec3 c = mix(vec3(1.02, 0.985, 0.94), vec3(0.6, 0.72, 0.95), up);\n  // behind the camera the studio is unlit: it is what gives the glass its dark edges\n  c *= mix(0.16, 1.0, smoothstep(-0.85, 0.1, rd.z + rd.x * 0.25));\n  // a tall soft light behind the camera's right shoulder: the sheen on the faces that look at the lens\n  vec3 fn = normalize(vec3(-0.5, -0.1, 1.0));\n  c += vec3(1.0, 0.98, 0.95) * 4.0 * rectL(rd, vec3(6.5, 3.0, -11.0), fn, normalize(cross(vec3(0.0, 1.0, 0.0), fn)), vec3(0.0, 1.0, 0.0), vec2(1.3, 4.5), 0.09);\n  // the far window, low on the right: it is what the polished tops mirror, glazing bars and all\n  vec3 tn = -normalize(vec3(0.45, 0.2, 0.85));\n  vec3 tu = normalize(cross(vec3(0.0, 1.0, 0.0), tn)); vec3 tv = cross(tn, tu);\n  vec3 tq = rd * (20.0 / max(dot(rd, -tn), 1e-3)) + tn * 20.0;\n  vec2 tw = vec2(dot(tq, tu), dot(tq, tv) - 1.6);\n  float pane = smoothstep(0.17, 0.14, abs(fract(tw.x / 0.8 + 0.1) - 0.5));\n  float inWin = step(0.0, dot(rd, -tn)) * smoothstep(0.03, -0.03, abs(tw.x) - 5.2) * smoothstep(0.03, -0.03, abs(tw.y) - 2.3);\n  c = mix(c, c * 0.22 + vec3(1.0, 0.985, 0.95) * (2.2 + 2.0 * smoothstep(-2.3, 2.3, tw.y)) * pane, inWin);\n  // a tall window on the camera's left, with one glazing bar\n  vec3 wn = normalize(vec3(1.0, 0.0, -0.75));\n  vec3 wu = normalize(cross(vec3(0.0, 1.0, 0.0), wn));\n  float win = rectL(rd, vec3(-9.0, 2.6, 7.0), wn, wu, vec3(0.0, 1.0, 0.0), vec2(2.4, 2.6), 0.012);\n  float barV = rectL(rd, vec3(-9.0, 2.6, 7.0), wn, wu, vec3(0.0, 1.0, 0.0), vec2(0.1, 2.6), 0.006);\n  c += vec3(0.95, 0.98, 1.0) * 3.4 * win * (1.0 - barV);\n  // one small hard lamp high over the camera: the hot line along every top front arris\n  c += vec3(1.0, 0.97, 0.9) * 46.0 * smoothstep(0.9965, 0.9992, dot(rd, normalize(vec3(0.42, 0.86, -0.28))));\n  // the sun\n  float s = dot(rd, uSun);\n  c += SUNC * (70.0 * smoothstep(0.9988, 0.9996, s) + 1.6 * pow(max(s, 0.0), 180.0));\n  return c;\n}\n\n// What the sun delivers to a point on the floor once the glass has had its say. Through a pair of\n// parallel faces the light arrives straight and coloured. Through a corner it is thrown wide, so\n// that part of the shadow only sees coloured sky.\nvec3 gL; vec3 gL2; vec3 gOcc; bool gTwo;\n// The sun comes in through an opening: behind the row the floor is in open shade.\nfloat sunMask(vec2 g){ float d = 2.9 + 0.3 * g.x - g.y; return smoothstep(-0.2, 0.2, d); }\nvec3 sunT(vec3 gp, vec3 L){\n  vec3 T = vec3(1.0); gOcc = vec3(1.0);\n  for (int i = 0; i < N; i++) {\n    float x = barX(i); float h = uH[i];\n    if (h < 0.004) continue;\n    vec3 lo = vec3(x - HW, 0.0, -HW); vec3 hi = vec3(x + HW, h, HW);\n    float a; float b; vec3 n1; vec3 n2;\n    if (!boxHit(gp, L, lo, hi, a, b, n1, n2)) continue;\n    gOcc *= exp(-uSig[i] * 0.3);\n    if (a <= 0.0) { T *= exp(-uSig[i] * b) * 0.9; continue; }\n    vec3 pe = gp + L * a;\n    vec3 d = refract(L, n1, 1.0 / 1.5);\n    float a2; float b2; vec3 m1; vec3 m2;\n    boxHit(pe - n1 * 1e-4, d, lo, hi, a2, b2, m1, m2);\n    b2 = max(b2, 0.0);\n    float par = step(dot(m2, n1), -0.5);\n    // the ground arris bends light away: a thin dark line down each side of the shadow\n    vec3 q = pe - vec3(x, 0.0, 0.0); vec3 e = (vec3(HW, h, HW) - abs(q)) * (1.0 - abs(n1));\n    float edge = min(min(e.x + abs(n1.x), e.y + abs(n1.y)), e.z + abs(n1.z));\n    float dark = smoothstep(0.0, BEV, edge);\n    // and lays what it took as a bright seam just inside\n    float seam = exp(-pow((edge - BEV * 1.9) / (BEV * 0.7), 2.0));\n    T *= exp(-uSig[i] * b2) * mix(0.3, 0.94, par) * mix(0.4, 1.0, dark) * (1.0 + 0.55 * seam * par);\n  }\n  return T;\n}\n// The sunlit side of every column is also a weak mirror: it lays a pale patch of sun on the floor beside it.\nfloat glint(vec3 gp){\n  vec3 d = vec3(-uSun.x, uSun.y, uSun.z); float g = 0.0;\n  if (d.x < 0.05) return 0.0;\n  for (int i = 0; i < N; i++) {\n    float t = (barX(i) - HW - gp.x) / d.x;\n    if (t <= 0.0) continue;\n    float y = d.y * t; float z = gp.z + d.z * t;\n    g += smoothstep(uH[i] + 0.02, uH[i] - 0.02, y) * smoothstep(HW + 0.015, HW - 0.015, abs(z));\n  }\n  return g;\n}\nfloat contact(vec3 gp){\n  float o = 1.0;\n  for (int i = 0; i < N; i++) {\n    vec2 q = abs(gp.xz - vec2(barX(i), 0.0)) - vec2(CW);\n    float d = length(max(q, 0.0));\n    o *= 1.0 - 0.5 * exp(-d / 0.05) - 0.16 * exp(-d / 0.3) * min(uH[i], 1.0);\n  }\n  return o;\n}\nvec3 paper(vec3 gp){\n  float fib = n2(gp.xz * 70.0) * 0.55 + n2(gp.xz * vec2(260.0, 230.0)) * 0.45;\n  float trowel = n2(gp.xz * 0.9 + 3.0) * 0.6 + n2(gp.xz * vec2(2.6, 1.7)) * 0.4;\n  vec3 alb = vec3(0.905, 0.9, 0.89) * (0.975 + 0.05 * fib) * (0.94 + 0.11 * trowel) * (1.0 - 0.1 * smoothstep(0.86, 0.97, n2(gp.xz * 38.0)));\n  vec2 uv = vec2((gp.x - 0.27 + 2.6) / 5.2, (-0.34 - gp.z) / 0.325);\n  if (uv.x > 0.0 && uv.x < 1.0 && uv.y > 0.0 && uv.y < 1.0) {\n    float col = floor((gp.x - 0.27) / P + float(N) * 0.5);\n    float on = uSel < -0.5 ? 0.92 : (abs(col - uSel) < 0.5 ? 0.97 : 0.3);\n    alb = mix(alb, vec3(0.06, 0.06, 0.075), texture(uTex, uv).r * on);\n  }\n  return alb;\n}\nvec3 floorLite(vec3 gp){\n  float pool = 0.5 + 0.5 * smoothstep(13.0, 2.0, length((gp.xz - vec2(0.6, -0.6)) * vec2(0.75, 1.0)));\n  vec3 T = sunT(gp, gL);\n  if (gTwo) T = 0.5 * (T + sunT(gp, gL2));\n  T *= sunMask(gp.xz);\n  vec3 sky = vec3(0.55, 0.55, 0.59) * contact(gp) * mix(vec3(1.0), gOcc, 0.94);\n  return paper(gp) * (SUNC * 1.75 * uSun.y * (T + 0.1 * glint(gp) * sunMask(gp.xz)) * pool + sky * (0.7 + 0.3 * pool));\n}\nvec3 floorFar(vec3 gp, float dist){ return mix(floorLite(gp), HAZE, smoothstep(9.0, 40.0, dist)); }\nvec3 envR(vec3 p, vec3 r){\n  if (r.y < -0.002) { float t = -p.y / r.y; return floorFar(p + r * t, t); }\n  return env(r);\n}\n\nvoid nearest(vec3 ro, vec3 rd, int skip, out float tb, out float te, out int ib, out vec3 nb){\n  tb = 1e9; te = 1e9; ib = -1; nb = vec3(0.0);\n  for (int i = 0; i < N; i++) {\n    if (i == skip || uH[i] < 0.004) continue;\n    float x = barX(i); float a; float b; vec3 n1; vec3 n2;\n    if (boxHit(ro, rd, vec3(x - HW, 0.0, -HW), vec3(x + HW, uH[i], HW), a, b, n1, n2) && a > 0.0 && a < tb) { tb = a; te = b; ib = i; nb = n1; }\n  }\n}\n// A column as another column sees it: tinted straight through, with a sheen.\nvec3 simpleBar(int i, vec3 ro, vec3 rd, float t, float te, vec3 n){\n  vec3 p = ro + rd * t;\n  vec3 nn = bevel(p, vec3(barX(i), 0.0, 0.0), vec3(HW, uH[i], HW), n, BEV);\n  float F = fresG(dot(-rd, nn));\n  return F * envR(p, reflect(rd, nn)) + (1.0 - F) * exp(-uSig[i] * (te - t)) * 0.92 * envR(ro + rd * te, rd);\n}\nvec3 outside(vec3 ro, vec3 rd, int self){\n  float tb; float te; int ib; vec3 nb; nearest(ro, rd, self, tb, te, ib, nb);\n  float tg = rd.y < -1e-4 ? -ro.y / rd.y : 1e9;\n  if (ib >= 0 && tb < tg) return simpleBar(ib, ro, rd, tb, te, nb);\n  if (tg < 1e8) return floorFar(ro + rd * tg, tg);\n  return env(rd);\n}\n\n// One ray into a column and every way it can leave.\nvec3 shadeBar(int i, vec3 ro, vec3 rd, float t, vec3 nf){\n  float x = barX(i); float h = uH[i];\n  vec3 c = vec3(x, 0.0, 0.0); vec3 b = vec3(HW, h, HW);\n  vec3 lo = vec3(x - HW, 0.0, -HW); vec3 hi = vec3(x + HW, h, HW);\n  vec3 p = ro + rd * t;\n  vec3 n = wob(bevel(p, c, b, nf, BEV), p);\n  float F = fresG(dot(-rd, n));\n  vec3 col = F * outside(p + nf * 1e-3, reflect(rd, n), i);\n  // looking down the length of a column the colour would go to black: the tops are read at a shallower depth\n  vec3 thr = vec3(1.0 - F); vec3 sig = uSig[i] * (nf.y > 0.5 ? 0.3 : 1.0);\n  // a polished arris is a thin window onto the sky: light gets through it by the short way\n  float ar = arris(p, c, b, nf, BEV);\n  col += thr * ar * ar * exp(-sig * 0.07) * vec3(1.25, 1.2, 1.1);\n  thr *= 1.0 - 0.7 * ar * ar;\n  vec3 d = refract(rd, n, 1.0 / 1.5); vec3 o = p - nf * 1e-4;\n  for (int k = 0; k < 6; k++) {\n    float a; float e; vec3 n1; vec3 n2;\n    boxHit(o, d, lo, hi, a, e, n1, n2);\n    e = max(e, 0.0);\n    if (k == 0) {\n      for (int j = 0; j < 5; j++) {\n        vec4 sd = seed(i, j); if (sd.y < CH + 0.05) continue;\n        vec3 oc = o - sd.xyz; float bb = dot(oc, d); float hh = bb * bb - dot(oc, oc) + sd.w * sd.w;\n        if (hh > 0.0) { float ts = -bb - sqrt(hh); if (ts > 0.0 && ts < e) {\n          vec3 bn = normalize(o + d * ts - sd.xyz); float rim = 1.0 - clamp(dot(-d, bn), 0.0, 1.0);\n          vec3 tt = thr * exp(-sig * ts);\n          // air in glass: clear in the middle, a mirror ring round the edge\n          col += tt * smoothstep(0.3, 0.75, rim) * (0.25 + 0.75 * env(reflect(d, bn))) * 0.9;\n          thr *= 1.0 - 0.8 * smoothstep(0.3, 0.75, rim);\n        } }\n      }\n    }\n    o += d * e; thr *= exp(-sig * e);\n    if (n2.y < -0.5) return col + thr * floorLite(vec3(o.x, 0.0, o.z));\n    if (o.y < CH) return col + thr * vec3(0.3, 0.3, 0.32);\n    vec3 nn = wob(bevel(o, c, b, n2, BEV), o);\n    vec3 r = refract(d, -nn, 1.5);\n    if (dot(r, r) < 0.5) { d = reflect(d, -n2); o -= n2 * 1e-4; continue; }\n    float Fo = fres(dot(r, nn));\n    col += thr * (1.0 - Fo) * outside(o + n2 * 1e-3, r, i);\n    thr *= Fo;\n    if (max(thr.r, max(thr.g, thr.b)) < 0.03) return col;\n    d = reflect(d, -n2); o -= n2 * 1e-4;\n  }\n  return col + thr * vec3(0.4);\n}\n\n// The stainless collar each column slides through.\nfloat collarHit(vec3 ro, vec3 rd, out int ic, out vec3 nc){\n  float tb = 1e9; ic = -1; nc = vec3(0.0);\n  for (int i = 0; i < N; i++) {\n    float x = barX(i); float a; float b; vec3 n1; vec3 n2;\n    if (boxHit(ro, rd, vec3(x - CW, 0.0, -CW), vec3(x + CW, CH, CW), a, b, n1, n2) && a > 0.0 && a < tb) { tb = a; ic = i; nc = n1; }\n  }\n  return tb;\n}\nvec3 shadeCollar(int i, vec3 p, vec3 nf, vec3 rd){\n  vec3 q = p - vec3(barX(i), 0.0, 0.0);\n  // flush with the floor: the glass shows in the frame as a tile\n  if (nf.y > 0.5 && max(abs(q.x), abs(q.z)) < HW) return floorLite(vec3(p.x, 0.0, p.z)) * exp(-uSig[i] * 0.35) + fres(-rd.y) * env(reflect(rd, nf));\n  vec3 n = bevel(p, vec3(barX(i), 0.0, 0.0), vec3(CW, CH, CW), nf, 0.012);\n  float inner = nf.y > 0.5 ? smoothstep(HW + 0.012, HW, max(abs(q.x), abs(q.z))) : 0.0;\n  vec3 s = outside(p + nf * 1e-3, reflect(rd, n), -1);\n  vec3 f0 = vec3(0.62, 0.63, 0.65);\n  vec3 f = f0 + (1.0 - f0) * pow(1.0 - clamp(dot(-rd, n), 0.0, 1.0), 5.0);\n  return f * s * (1.0 - 0.75 * inner) + vec3(0.05) * max(dot(n, uSun), 0.0);\n}\n\nvec3 shadeGround(vec3 gp, vec3 rd, vec2 rnd, float dist){\n  gTwo = true; vec3 col = floorLite(gp); gTwo = false;\n  if (dot(gp.xz, gp.xz) < 60.0) {\n    // a satin floor: at a low angle it carries a soft image of what stands on it\n    vec3 r = normalize(reflect(rd, vec3(0.0, 1.0, 0.0)) + vec3(rnd.x, 0.0, rnd.y) * 0.03);\n    float f = fres(-rd.y);\n    float tb; float te; int ib; vec3 nb; nearest(gp + vec3(0.0, 0.002, 0.0), r, -1, tb, te, ib, nb);\n    if (ib >= 0) {\n      vec3 m = simpleBar(ib, gp + vec3(0.0, 0.002, 0.0), r, tb, te, nb);\n      col = mix(col, m, clamp(f * 1.7 * exp(-tb * 0.5), 0.0, 0.5));\n    }\n  }\n  return mix(col, HAZE, smoothstep(9.0, 40.0, dist));\n}\n\nvoid main(){\n  vec2 fc = gl_FragCoord.xy + uJit.xy;\n  vec2 uv = (fc - 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 rd = normalize(fw * uFoc + rt * uv.x + up * uv.y);\n  vec3 ro = uCam;\n  vec3 fp = ro + rd * (uFocus / dot(rd, fw));\n  ro += rt * uJit.z + up * uJit.w; rd = normalize(fp - ro);\n  float ign = fract(52.9829189 * fract(dot(gl_FragCoord.xy, vec2(0.06711056, 0.00583715))) + uSeed);\n  float ang = ign * 6.2831853; float rr = sqrt(fract(ign * 7.13 + uSeed * 3.7));\n  vec2 rnd = vec2(cos(ang), sin(ang)) * rr * step(0.001, uSeed);\n  // the sun has a width: each exposure looks at a different part of its disc\n  vec3 su = normalize(cross(uSun, vec3(0.0, 1.0, 0.0))); vec3 sv = cross(su, uSun);\n  gL = normalize(uSun + (su * rnd.x + sv * rnd.y) * 0.015);\n  gL2 = normalize(uSun - (su * rnd.x + sv * rnd.y) * 0.015); gTwo = false;\n\n  float tg = rd.y < 0.0 ? -ro.y / rd.y : 1e9;\n  float tb; float te; int ib; vec3 nb; nearest(ro, rd, -1, tb, te, ib, nb);\n  int ic; vec3 nc; float tc = collarHit(ro, rd, ic, nc);\n  vec3 col;\n  if (ic >= 0 && tc < tb && tc < tg) col = shadeCollar(ic, ro + rd * tc, nc, rd);\n  else if (ib >= 0 && tb < tg) col = shadeBar(ib, ro, rd, tb, nb);\n  else if (tg < 1e8) col = shadeGround(ro + rd * tg, rd, rnd, tg);\n  else col = env(rd);\n  col = min(col, vec3(24.0));\n  if (uDirect > 0.5) col = tone(col);\n  outC = vec4(col, 1.0);\n}\n`;\n\n// Developing the negative: a little bloom off the hot highlights, the filmic curve, vignette, grain.\nconst POST = `#version 300 es\nprecision highp float;\nout vec4 outC;\nuniform sampler2D uAcc; uniform vec2 uRes; uniform float uGrain; uniform vec2 uCentre;\n${TONE}\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 = texture(uAcc, uv).rgb;\n  vec2 px = 1.0 / uRes;\n  vec3 nb = texture(uAcc, uv + vec2(px.x, 0.0)).rgb + texture(uAcc, uv - vec2(px.x, 0.0)).rgb + texture(uAcc, uv + vec2(0.0, px.y)).rgb + texture(uAcc, uv - vec2(0.0, px.y)).rgb;\n  c = max(c + (c - nb * 0.25) * 0.45, 0.0);\n  vec3 b = vec3(0.0);\n  for (int i = 0; i < 20; i++) {\n    float a = float(i) * 2.39996; float r = sqrt((float(i) + 0.5) / 20.0);\n    vec3 s = texture(uAcc, uv + vec2(cos(a), sin(a)) * r * 0.02 * vec2(uRes.y / uRes.x, 1.0)).rgb;\n    b += min(max(s - 1.7, 0.0), vec3(6.0)) * (1.0 - 0.6 * r);\n  }\n  c += b * 0.01;\n  vec2 q = (uv - uCentre) * vec2(uRes.x / uRes.y, 1.0);\n  c *= 1.0 - 0.24 * smoothstep(0.4, 1.3, length(q));\n  c = tone(c);\n  // printed a touch harder and richer than the negative\n  c = mix(vec3(dot(c, vec3(0.299, 0.587, 0.114))), c, 1.14);\n  c = mix(c, c * c * (3.0 - 2.0 * c), 0.22);\n  c += (h21(gl_FragCoord.xy + uGrain * 91.7) - 0.5) * 0.018;\n  outC = vec4(c, 1.0);\n}\n`;\n\n// The month names printed on the floor in front of the columns, drawn once as a flat plan.\nfunction floorPrint() {\n  const W = 2048, H = 128, px = W / 5.2;\n  const cv = document.createElement(\"canvas\");\n  cv.width = W; cv.height = H;\n  const g = cv.getContext(\"2d\");\n  if (!g) return cv;\n  g.fillStyle = \"#000\"; g.fillRect(0, 0, W, H);\n  g.fillStyle = \"#fff\"; g.textAlign = \"center\"; g.textBaseline = \"top\";\n  g.font = `700 ${0.165 * px}px ${FONT}`;\n  labels.forEach((l, i) => g.fillText(l.toUpperCase().split(\"\").join(\"\\u200A\"), (xOf(i) + 2.6) * px, 0.05 * px));\n  return cv;\n}\n\nconst css = (c: [number, number, number], k = 1) => `rgb(${c.map((v) => Math.round(Math.min(1, v * k) * 255)).join(\",\")})`;\n\n// No WebGL: the same chart from the front, built from gradients.\nfunction Still({ values }: { values: number[] }) {\n  const top = Math.max(...sets.flatMap((s) => s.values));\n  return (\n    <div aria-hidden=\"true\" className=\"absolute inset-x-0 top-[6%] mx-auto flex h-[46%] w-[86%] max-w-[560px] items-end justify-between lg:left-auto lg:right-[8%] lg:top-[18%] lg:mx-0 lg:h-[56%] lg:w-[46%]\">\n      {values.map((v, i) => (\n        <div key={labels[i]} className=\"relative w-[11%]\" style={{ height: `${(v / top) * 100}%` }}>\n          <div className=\"absolute left-0 top-full h-[70%] w-full origin-top-left skew-x-[52deg] blur-[3px]\" style={{ background: `linear-gradient(180deg, ${css(glass[i])} 0%, transparent 100%)`, opacity: 0.75 }} />\n          <div className=\"absolute inset-0 rounded-[2px]\" style={{ background: `linear-gradient(90deg, ${css(glass[i], 0.7)} 0%, ${css(glass[i], 1.15)} 5%, ${css(glass[i])} 9%, ${css(glass[i], 1.08)} 78%, ${css(glass[i], 0.72)} 80%, ${css(glass[i], 0.86)} 100%)`, boxShadow: \"inset 0 2px 0 rgba(255,255,255,0.85), inset 1px 0 0 rgba(255,255,255,0.5), inset -1px 0 0 rgba(0,0,0,0.2)\" }} />\n          <div className=\"absolute -inset-x-[9%] bottom-0 h-[5px] rounded-[1px]\" style={{ background: \"linear-gradient(180deg, #f4f5f6 0%, #8d9299 60%, #c9ccd1 100%)\" }} />\n        </div>\n      ))}\n    </div>\n  );\n}\n\nexport default function RayTracedCastGlassColumnBarChart() {\n  const stage = useRef<HTMLDivElement>(null);\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const hit = useRef<HTMLDivElement>(null);\n  const [set, setSet] = useState(0);\n  const [sel, setSel] = useState(-1);\n  const [hover, setHover] = useState(-1);\n  const [live, setLive] = useState<number[]>(sets[0].values);\n  const [shown, setShown] = useState<\"wait\" | \"gl\" | \"still\">(\"wait\");\n  const api = useRef<{ go: (k: number, fromUser: boolean) => void; press: (i: number) => void; mark: (i: number) => void } | null>(null);\n  const selRef = useRef(-1);\n\n  useEffect(() => {\n    const box = stage.current, cv = canvas.current, pad = hit.current;\n    if (!box || !cv || !pad) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const gl = cv.getContext(\"webgl2\", { antialias: false, alpha: false, powerPreference: \"high-performance\" }) as WebGL2RenderingContext | null;\n    if (!gl) { setShown(\"still\"); return; }\n    const canAcc = !!gl.getExtension(\"EXT_color_buffer_float\") || !!gl.getExtension(\"EXT_color_buffer_half_float\");\n    const info = gl.getExtension(\"WEBGL_debug_renderer_info\");\n    const renderer = info ? String(gl.getParameter(info.UNMASKED_RENDERER_WEBGL)) : \"\";\n    const software = /swiftshader|llvmpipe|software|basic render/i.test(renderer);\n    const still = reduce || software; // no idle drift: draw, refine, then rest\n\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      return gl.getShaderParameter(sh, gl.COMPILE_STATUS) ? sh : null;\n    };\n    const link = (frag: string) => {\n      const v = compile(gl.VERTEX_SHADER, VERT), f = compile(gl.FRAGMENT_SHADER, frag);\n      const 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 = canAcc ? link(POST) : null;\n    if (!scene || (canAcc && !post)) { setShown(\"still\"); return; }\n    const su = Object.fromEntries([\"uRes\", \"uJit\", \"uSeed\", \"uCam\", \"uTgt\", \"uFoc\", \"uShift\", \"uFocus\", \"uH\", \"uSig\", \"uSel\", \"uSun\", \"uTex\", \"uDirect\"].map((n) => [n, gl.getUniformLocation(scene, n)]));\n    const pu = post ? Object.fromEntries([\"uAcc\", \"uRes\", \"uGrain\", \"uCentre\"].map((n) => [n, gl.getUniformLocation(post, n)])) : {};\n    // absorption per unit of depth, from the colour that survives one column's thickness\n    const sig = new Float32Array(glass.flatMap((c) => c.map((v) => -Math.log(Math.max(0.003, Math.min(0.995, Math.pow(v, 2.2)))) / (HALF * 2))));\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    const tex = gl.createTexture();\n    gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, tex);\n    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, floorPrint());\n    gl.generateMipmap(gl.TEXTURE_2D);\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.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n\n    // The accumulation plate: every frame is one more exposure blended onto it.\n    const acc = canAcc ? gl.createTexture() : null;\n    const fbo = canAcc ? gl.createFramebuffer() : null;\n    let W = 0, H = 0, scale = 1, cssW = 1, cssH = 1;\n    const start = sets[0].values.map((v) => v / SCALE);\n    const s = {\n      h: start.slice(), v: start.map(() => 0), to: start.slice(), next: start.slice(), at: start.map(() => 0),\n      dip: start.map(() => 0), dv: start.map(() => 0), set: 0,\n      px: 0, py: 0, sx: 0, sy: 0, sun: 0, count: 0, fresh: true, frame: 0, slow: 0, hover: -1,\n      visible: true, raf: 0, last: 0, t0: 0, touched: false, demoAt: 0, first: true, sent: \"\",\n    };\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(software ? 1 : 1.5, window.devicePixelRatio || 1) * scale;\n      // never more than about a million and a half pixels of tracing\n      const k = Math.min(1, Math.sqrt(1.45e6 / (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;\n      if (acc && fbo) {\n        gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, acc);\n        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, W, H, 0, gl.RGBA, gl.HALF_FLOAT, null);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n        gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);\n        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, acc, 0);\n        gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n      }\n      s.count = 0; s.fresh = true;\n    };\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\n    // The camera: a long lens, low and off to the left, so the row runs away from it.\n    const camera = () => {\n      const wide = cssW >= 1024, aspect = cssW / cssH;\n      const el = (wide ? 0.27 : 0.36) - s.sy * 0.012, az = (wide ? -0.5 : -0.3) + s.sx * 0.04, dist = 13;\n      const tgt = wide ? [0.3, 0.8, 0] : [0, 0.9, 0];\n      const cam = [tgt[0] + dist * Math.sin(az) * Math.cos(el), tgt[1] + dist * Math.sin(el), tgt[2] - dist * Math.cos(az) * Math.cos(el)];\n      const foc = wide ? 2.8 * Math.min(1, aspect / 1.55) : 1.28 * Math.min(1, aspect / 0.52);\n      // the camera stays level and the lens is shifted down instead, as for architecture: verticals stay vertical\n      const fall = ((cam[1] - tgt[1]) / Math.hypot(tgt[0] - cam[0], tgt[2] - cam[2])) * foc;\n      const fw = [tgt[0] - cam[0], 0, tgt[2] - cam[2]];\n      const fl = Math.hypot(fw[0], fw[1], fw[2]); fw[0] /= fl; fw[1] /= fl; fw[2] /= fl;\n      const rt = [fw[2], 0, -fw[0]]; const rl = Math.hypot(rt[0], rt[2]); rt[0] /= rl; rt[2] /= rl;\n      const up = [fw[1] * rt[2] - fw[2] * rt[1], fw[2] * rt[0] - fw[0] * rt[2], fw[0] * rt[1] - fw[1] * rt[0]];\n      const shift = wide ? [0.165 * aspect, -0.07 + fall] : [0, 0.2 + fall];\n      return { cam, tgt, fw, rt, up, foc, shift, wide };\n    };\n    // Which column a point on the screen is over.\n    const pick = (cx: number, cy: number) => {\n      const r = box.getBoundingClientRect(), c = camera();\n      const ux = (cx - r.left - r.width / 2) / r.height - c.shift[0], uy = (r.height / 2 - (cy - r.top)) / r.height - c.shift[1];\n      const d = [0, 1, 2].map((i) => c.fw[i] * c.foc + c.rt[i] * ux + c.up[i] * uy);\n      let best = -1, bt = 1e9;\n      for (let i = 0; i < N; i++) {\n        const lo = [xOf(i) - HALF - 0.04, 0, -HALF - 0.04], hi = [xOf(i) + HALF + 0.04, Math.max(s.h[i], 0.25), HALF + 0.04];\n        let tn = -1e9, tf = 1e9;\n        for (let a = 0; a < 3; a++) {\n          const inv = 1 / (Math.abs(d[a]) < 1e-6 ? 1e-6 : d[a]);\n          const t1 = (lo[a] - c.cam[a]) * inv, t2 = (hi[a] - c.cam[a]) * inv;\n          tn = Math.max(tn, Math.min(t1, t2)); tf = Math.min(tf, Math.max(t1, t2));\n        }\n        if (tf > Math.max(tn, 0) && tn < bt) { bt = tn; best = i; }\n      }\n      return best;\n    };\n\n    const draw = (alpha: number, sample: number) => {\n      const c = camera();\n      const jx = sample ? halton(sample, 2) - 0.5 : 0, jy = sample ? halton(sample, 3) - 0.5 : 0;\n      const la = halton(sample, 5) * Math.PI * 2, lr = sample ? Math.sqrt(halton(sample, 7)) * 0.065 : 0;\n      gl.useProgram(scene);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, canAcc ? fbo : null);\n      gl.viewport(0, 0, W, H);\n      if (canAcc && alpha < 1) { gl.enable(gl.BLEND); gl.blendColor(0, 0, 0, alpha); gl.blendFunc(gl.CONSTANT_ALPHA, gl.ONE_MINUS_CONSTANT_ALPHA); } else gl.disable(gl.BLEND);\n      gl.uniform2f(su.uRes, W, H);\n      gl.uniform4f(su.uJit, canAcc ? jx : 0, canAcc ? jy : 0, canAcc ? Math.cos(la) * lr : 0, canAcc ? Math.sin(la) * lr : 0);\n      gl.uniform1f(su.uSeed, canAcc && sample ? (sample * 0.61803) % 1 || 0.5 : 0);\n      gl.uniform3f(su.uCam, c.cam[0], c.cam[1], c.cam[2]); gl.uniform3f(su.uTgt, c.tgt[0], c.cam[1], c.tgt[2]);\n      gl.uniform1f(su.uFoc, c.foc);\n      gl.uniform2f(su.uShift, c.shift[0], c.shift[1]);\n      gl.uniform1f(su.uFocus, (0.3 - c.cam[0]) * c.fw[0] + (0.8 - c.cam[1]) * c.fw[1] + (-0.2 - c.cam[2]) * c.fw[2]);\n      gl.uniform1fv(su.uH, s.h.map((h, i) => Math.max(0, h + s.dip[i])));\n      gl.uniform3fv(su.uSig, sig);\n      gl.uniform1f(su.uSel, s.hover >= 0 ? s.hover : selRef.current);\n      // the sun: behind the row and to the left, drifting a little\n      const sa = -0.62 + s.sun, se = 0.66;\n      gl.uniform3f(su.uSun, Math.sin(sa) * Math.cos(se), Math.sin(se), Math.cos(sa) * Math.cos(se));\n      gl.uniform1i(su.uTex, 0);\n      gl.uniform1f(su.uDirect, canAcc ? 0 : 1);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n      if (canAcc && post) {\n        gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n        gl.disable(gl.BLEND);\n        gl.useProgram(post);\n        gl.uniform1i(pu.uAcc, 1); gl.uniform2f(pu.uRes, W, H);\n        gl.uniform1f(pu.uGrain, still ? 1 : s.frame % 64);\n        gl.uniform2f(pu.uCentre, c.wide ? 0.6 : 0.5, c.wide ? 0.45 : 0.66);\n        gl.drawArrays(gl.TRIANGLES, 0, 3);\n      }\n    };\n\n    const go = (k: number, fromUser: boolean) => {\n      if (fromUser) s.touched = true;\n      if (k === s.set) return;\n      s.set = k; setSet(k);\n      const now = performance.now();\n      // the change runs down the row: each column sets off a beat after the one before\n      sets[k].values.forEach((v, i) => { s.next[i] = v / SCALE; s.at[i] = now + i * 105; });\n      if (reduce) { s.next.forEach((v, i) => { s.h[i] = s.to[i] = v; s.v[i] = 0; }); s.count = 0; }\n      wake();\n    };\n    const press = (i: number) => { s.touched = true; if (!reduce) s.dv[i] -= 0.9; s.count = 0; wake(); };\n    const mark = () => { s.touched = true; s.count = Math.min(s.count, 1); wake(); };\n    api.current = { go, press, mark };\n\n    const frame = (now: number) => {\n      s.raf = 0;\n      if (!s.visible) return;\n      const dtRaw = s.last ? (now - s.last) / 1000 : 0.016;\n      const dt = Math.min(0.033, dtRaw);\n      s.last = now; s.frame++;\n      if (!s.t0) { s.t0 = now; s.demoAt = now + 3800; }\n\n      // the self-running demo: it opens finished, holds, then swaps the two sets until someone touches it\n      if (!still && !s.touched && now > s.demoAt) { go(1 - s.set, false); s.demoAt = now + 4600; }\n\n      let moving = false, fast = false;\n      if (!reduce) {\n        const steps = 3, hh = dt / steps;\n        for (let i = 0; i < N; i++) {\n          if (s.to[i] !== s.next[i] && now >= s.at[i]) s.to[i] = s.next[i];\n          for (let k = 0; k < steps; k++) {\n            // heavy glass on a spring: it arrives late, goes a little past, and comes back once\n            const down = s.to[i] < s.h[i] - 0.002 || (s.v[i] < 0 && s.to[i] <= s.h[i] + 0.05);\n            s.v[i] += ((down ? 150 : 82) * (s.to[i] - s.h[i]) - (down ? 9.5 : 11.5) * s.v[i]) * hh; s.h[i] += s.v[i] * hh;\n            s.dv[i] += (-520 * s.dip[i] - 26 * s.dv[i]) * hh; s.dip[i] += s.dv[i] * hh;\n          }\n          if (Math.abs(s.v[i]) > 0.002 || Math.abs(s.to[i] - s.h[i]) > 0.0006 || s.to[i] !== s.next[i] || Math.abs(s.dip[i]) > 0.0006 || Math.abs(s.dv[i]) > 0.004) moving = true;\n          else { s.h[i] = s.to[i]; s.v[i] = 0; s.dip[i] = 0; s.dv[i] = 0; }\n          if (Math.abs(s.v[i]) > 0.1 || Math.abs(s.dv[i]) > 0.1) fast = true;\n        }\n      }\n      // the numbers on the page are read off the glass\n      const vals = s.h.map((h) => Math.round(h * SCALE));\n      const key = vals.join(\",\");\n      if (key !== s.sent) { s.sent = key; setLive(vals); }\n\n      if (!still) {\n        s.sx += (s.px - s.sx) * (1 - Math.exp(-dt * 3)); s.sy += (s.py - s.sy) * (1 - Math.exp(-dt * 3));\n        const t = (now - s.t0) / 1000;\n        s.sun = Math.sin(t * 0.33) * 0.09 + s.sx * 0.05;\n        moving = true;\n      }\n\n      if (s.fresh || !canAcc) { draw(1, 0); s.fresh = false; s.count = 1; }\n      else if (moving) { draw(fast ? 0.6 : still ? 0.5 : 0.1, 1 + (s.frame % 64)); s.count = still ? 1 : 6; }\n      else if (s.count < 48) { s.count++; draw(1 / s.count, s.count); }\n      if (s.first) { s.first = false; setShown(\"gl\"); }\n\n      // measured, not guessed: if frames run long for a while, give up some resolution\n      if (!still && dtRaw > 0.026) s.slow++; else s.slow = Math.max(0, s.slow - 2);\n      if (s.slow > 45 && scale > 0.5) { scale *= 0.82; s.slow = 0; size(); }\n\n      if (moving || s.count < 48 || (!still && !s.touched)) s.raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { if (!s.raf && s.visible) { 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 over = (i: number) => { if (i !== s.hover) { s.hover = i; setHover(i); pad.style.cursor = i >= 0 ? \"pointer\" : \"default\"; s.count = Math.min(s.count, 1); wake(); } };\n    const move = (e: PointerEvent) => {\n      const r = box.getBoundingClientRect();\n      s.px = ((e.clientX - r.left) / r.width) * 2 - 1; s.py = ((e.clientY - r.top) / r.height) * 2 - 1;\n      if (e.pointerType === \"mouse\") over(e.target === pad ? pick(e.clientX, e.clientY) : -1);\n      if (!still) wake();\n    };\n    const click = (e: MouseEvent) => {\n      const i = pick(e.clientX, e.clientY);\n      s.touched = true;\n      const nextSel = i < 0 || i === selRef.current ? -1 : i;\n      selRef.current = nextSel; setSel(nextSel);\n      if (i >= 0) press(i); else mark();\n    };\n    const leave = () => { s.px = 0; s.py = 0; over(-1); };\n    box.addEventListener(\"pointermove\", move);\n    pad.addEventListener(\"click\", click);\n    box.addEventListener(\"pointerleave\", leave);\n    const lost = (e: Event) => { e.preventDefault(); setShown(\"still\"); };\n    cv.addEventListener(\"webglcontextlost\", lost);\n    wake();\n\n    return () => {\n      cancelAnimationFrame(s.raf); ro.disconnect(); io.disconnect();\n      document.removeEventListener(\"visibilitychange\", vis);\n      box.removeEventListener(\"pointermove\", move); pad.removeEventListener(\"click\", click);\n      box.removeEventListener(\"pointerleave\", leave); cv.removeEventListener(\"webglcontextlost\", lost);\n      api.current = null;\n    };\n  }, []);\n\n  const choose = (k: number) => {\n    if (api.current) api.current.go(k, true); else { setSet(k); setLive(sets[k].values); }\n  };\n  const toggleDay = (i: number) => {\n    const next = sel === i ? -1 : i;\n    selRef.current = next; setSel(next);\n    if (api.current) { if (next >= 0) api.current.press(i); else api.current.mark(i); }\n  };\n\n  const focus = hover >= 0 ? hover : sel;\n  const other = sets[1 - set];\n  const number = focus >= 0 ? live[focus] : sum(live);\n  const now = focus >= 0 ? sets[set].values[focus] : sum(sets[set].values);\n  const then = focus >= 0 ? other.values[focus] : sum(other.values);\n  const change = Math.round(((now - then) / then) * 100);\n  const line = focus >= 0 ? `bookings in ${months[focus]}` : sets[set].noun;\n\n  return (\n    <section className=\"relative isolate overflow-hidden bg-[#eeebe6] text-[#131419]\" style={{ fontFamily: FONT }}>\n      <div ref={stage} className=\"relative mx-auto h-[760px] w-full max-w-[1600px]\" style={{ background: \"radial-gradient(90% 80% at 60% 60%, #f7f4ef 0%, #ece8e2 60%, #dcd7cf 100%)\" }}>\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\n        {shown === \"still\" && <Still values={live} />}\n\n        <div ref={hit} aria-hidden=\"true\" className=\"absolute inset-x-0 top-0 h-[54%] select-none lg:inset-y-0 lg:left-[34%] lg:h-auto\" />\n\n        <div className=\"pointer-events-none absolute inset-0 flex flex-col justify-end px-6 pb-7 sm:px-10 lg:justify-between lg:px-16 lg:pb-12 lg:pt-14\">\n          <div>\n            <p className=\"hidden text-[11px] font-medium uppercase tracking-[0.34em] text-[#131419]/60 lg:block\">Halden Rooms <span className=\"mx-2 text-[#131419]/30\">/</span> bookings by month <span className=\"mx-2 text-[#131419]/30\">/</span> demo data</p>\n            <div className=\"lg:mt-9\">\n              <p className=\"text-[104px] font-medium leading-[0.8] tracking-[-0.07em] tabular-nums sm:text-[150px] lg:text-[208px]\" aria-live=\"off\">{fmt(number)}</p>\n              <p className=\"mt-4 flex max-w-[84vw] flex-wrap items-baseline gap-x-3 gap-y-1 lg:mt-6\">\n                <span className=\"text-[20px] italic leading-snug text-[#131419]/80 lg:text-[25px]\" style={{ fontFamily: SERIF }}>{line}</span>\n                <span className=\"text-[13px] font-semibold tabular-nums tracking-[-0.01em]\" style={{ color: change >= 0 ? \"#b3260f\" : \"#5b5f6b\" }}>{change >= 0 ? \"+\" : \"−\"}{Math.abs(change)}% on {other.key.toLowerCase()}</span>\n              </p>\n            </div>\n          </div>\n\n          <div className=\"pointer-events-auto mt-5 lg:mt-0\">\n            <div role=\"group\" aria-label=\"Data set\" className=\"inline-flex rounded-full bg-[#131419]/[0.07] p-1\">\n              {sets.map((d, k) => (\n                <button key={d.key} type=\"button\" aria-pressed={set === k} onClick={() => choose(k)} className={`h-10 rounded-full px-5 text-[13px] font-semibold tracking-[-0.01em] transition-colors duration-200 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#131419] motion-reduce:transition-none ${set === k ? \"bg-[#131419] text-white\" : \"text-[#131419]/70 hover:text-[#131419]\"}`}>{d.key}</button>\n              ))}\n            </div>\n            <ul className=\"mt-3 grid max-w-[26rem] grid-cols-6 gap-x-0.5\" aria-label={`${sets[set].key}, bookings by month, demo data`}>\n              {labels.map((l, i) => (\n                <li key={l}>\n                  <button type=\"button\" aria-pressed={sel === i} aria-label={`${months[i]}: ${sets[set].values[i]} bookings`} onClick={() => toggleDay(i)} className={`flex h-11 w-full flex-col items-start justify-center rounded-[10px] px-1.5 text-left sm:px-2.5 transition-colors duration-200 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-[#131419] motion-reduce:transition-none ${focus === i ? \"bg-[#131419]/[0.08]\" : \"hover:bg-[#131419]/[0.05]\"}`}>\n                    <span className=\"flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-[0.14em] text-[#131419]/60 sm:tracking-[0.2em]\"><span className=\"h-1.5 w-1.5 shrink-0 rounded-full\" style={{ background: css(glass[i], 0.92) }} />{l}</span>\n                    <span className=\"text-[14px] font-semibold tabular-nums tracking-[-0.02em]\">{sets[set].values[i]}</span>\n                  </button>\n                </li>\n              ))}\n            </ul>\n          </div>\n        </div>\n        <p className=\"pointer-events-none absolute bottom-12 right-16 hidden text-[11px] uppercase tracking-[0.3em] text-[#131419]/50 lg:block\">Press a column</p>\n\n        <table className=\"sr-only\">\n          <caption>Bookings by month, demo data</caption>\n          <thead><tr><th scope=\"col\">Month</th>{sets.map((d) => <th key={d.key} scope=\"col\">{d.key}</th>)}</tr></thead>\n          <tbody>\n            {months.map((m, i) => <tr key={m}><th scope=\"row\">{m}</th>{sets.map((d) => <td key={d.key}>{d.values[i]}</td>)}</tr>)}\n            <tr><th scope=\"row\">Total</th>{sets.map((d) => <td key={d.key}>{sum(d.values)}</td>)}</tr>\n          </tbody>\n        </table>\n      </div>\n    </section>\n  );\n}\n"}]}
