{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"typed-sentence-of-blue-light-on-a-dark-studio-floor-that-stands-up-as-a-ray-marched-homepage-with-floating-layers","type":"registry:block","title":"Typed Sentence of Blue Light on a Dark Studio Floor That Stands Up as a Ray Marched Homepage with Floating Layers","description":"WebGL piece: type a sentence, watch it glow on a dark studio floor, then a ray-marched homepage stands up with floating layers. Free React and HTML code.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/typed-sentence-of-blue-light-on-a-dark-studio-floor-that-stands-up-as-a-ray-marched-homepage-with-floating-layers.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport type { FormEvent } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n/** The sentences the piece types by itself, and the page each one becomes. */\nconst DEMOS: { sentence: string; site: Site }[] = [\n  {\n    sentence: \"A surf school in Ericeira with lessons at sunrise\",\n    site: { brand: \"Saltline\", nav: [\"Lessons\", \"Coaches\", \"Visit\"], headline: \"First light,\\nfirst wave.\", sub: \"Small group surf lessons on the reef at Ericeira, in the water before the town wakes.\", cta: \"Book a lesson\", foot: \"Ericeira, Portugal\", photo: 0 },\n  },\n  {\n    sentence: \"A bakery in Leith that bakes sourdough overnight\",\n    site: { brand: \"Night Oven\", nav: [\"Bread\", \"Mornings\", \"Find us\"], headline: \"Baked while\\nyou sleep.\", sub: \"Slow sourdough shaped by hand in Leith and out of the oven as the street lights go off.\", cta: \"Reserve a loaf\", foot: \"Leith, Edinburgh\", photo: 1 },\n  },\n  {\n    sentence: \"A flower studio in Ghent that stays open late on Fridays\",\n    site: { brand: \"Nachtbloem\", nav: [\"Bunches\", \"Weddings\", \"Studio\"], headline: \"Flowers\\nafter dark.\", sub: \"Seasonal stems tied to order in Ghent, with the door open late every Friday.\", cta: \"Order a bunch\", foot: \"Ghent, Belgium\", photo: 2 },\n  },\n];\n\nconst PHOTOS = [\n  { src: \"https://images.pexels.com/photos/31814300/pexels-photo-31814300.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Silhouette of a surfer standing a board upright on the shore at sunrise\", tone: \"#6f7278\" },\n  { src: \"https://images.pexels.com/photos/30895276/pexels-photo-30895276.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Scored round loaf of bread on a cloth beside a rolling pin and a proving bowl\", tone: \"#3a3b3e\" },\n  { src: \"https://images.pexels.com/photos/19793720/pexels-photo-19793720.jpeg?auto=compress&cs=tinysrgb&w=900\", alt: \"Bunch of white tulips against a dark background\", tone: \"#2b2c30\" },\n];\n\ntype Site = { brand: string; nav: string[]; headline: string; sub: string; cta: string; foot: string; photo: number };\n\nconst BLUE = \"#4F98FB\";\nconst INK = \"#0B0D12\";\nconst PAPER = \"#F6F4EF\";\nconst FONT = '\"Inter Tight\", \"Inter\", ui-sans-serif, system-ui, sans-serif';\nconst MAX_CHARS = 84;\n/** Seconds the finished page is held before the next demo sentence is typed. */\nconst HOLD = 5.2;\n/** Lowest and highest render scale (canvas pixels per CSS pixel). The loop steps down when frames run slow. */\nconst MIN_SCALE = 0.6001;\nconst MAX_SCALE = 1.5001;\nconst LIE = -1.47; // page angle when it lies back on the floor, in radians\n\n/** Turns any sentence a visitor types into the words for a page. Demo sentences use their written page. */\nfunction compose(sentence: string): Site {\n  const clean = sentence.trim().replace(/\\s+/g, \" \");\n  const demo = DEMOS.find((d) => d.sentence.toLowerCase() === clean.toLowerCase());\n  if (demo) return demo.site;\n  const s = clean.toLowerCase();\n  const body = clean.replace(/[.!?]+$/, \"\");\n  const words = body.replace(/^(a|an|the|my|our)\\s+/i, \"\").split(\" \");\n  const brand = words.slice(0, 2).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(\" \") || \"Your page\";\n  const booking = /(book|lesson|class|school|studio|salon|barber|clinic|dentist|yoga|tour|coach|trainer|hotel|guest)/.test(s);\n  const selling = /(shop|store|sell|bakery|bake|cafe|coffee|restaurant|florist|flower|menu|pizza|food|bar|market)/.test(s);\n  const photo = /(surf|beach|sea|ocean|wave|swim|sail)/.test(s) ? 0 : /(bak|bread|cafe|coffee|restaurant|food|pizza|kitchen)/.test(s) ? 1 : /(flor|flower|garden|plant|bloom|wedding)/.test(s) ? 2 : -1;\n  return {\n    brand,\n    nav: selling ? [\"Shop\", \"Story\", \"Find us\"] : booking ? [\"Book\", \"About\", \"Visit\"] : [\"Work\", \"About\", \"Contact\"],\n    headline: body ? body.charAt(0).toUpperCase() + body.slice(1) + \".\" : \"Your sentence here.\",\n    sub: \"Set from the sentence on the floor. Type another and press return.\",\n    cta: selling ? \"Order now\" : booking ? \"Book a visit\" : \"Get in touch\",\n    foot: \"Draft one\",\n    photo,\n  };\n}\n\n/* ---------- canvas text, used as textures ---------- */\n\ntype Ctx = CanvasRenderingContext2D;\nconst setFont = (c: Ctx, weight: number, size: number, track = 0) => {\n  c.font = `${weight} ${size}px ${FONT}`;\n  (c as unknown as { letterSpacing: string }).letterSpacing = `${(track * size).toFixed(2)}px`;\n};\nfunction wrap(c: Ctx, text: string, maxW: number): string[] {\n  const out: string[] = [];\n  for (const para of text.split(\"\\n\")) {\n    let line = \"\";\n    for (const word of para.split(\" \")) {\n      const next = line ? line + \" \" + word : word;\n      if (line && c.measureText(next).width > maxW) {\n        out.push(line);\n        line = word;\n      } else line = next;\n    }\n    out.push(line);\n  }\n  return out;\n}\n/** Largest size at which the text fits the box. */\nfunction fit(c: Ctx, text: string, weight: number, track: number, maxW: number, maxH: number, lead: number, from: number, to: number) {\n  let size = from;\n  let lines: string[] = [text];\n  for (; size >= to; size -= 4) {\n    setFont(c, weight, size, track);\n    lines = wrap(c, text, maxW);\n    const widest = Math.max(...lines.map((l) => c.measureText(l).width));\n    if (widest <= maxW && lines.length * size * lead <= maxH) break;\n  }\n  return { size: Math.max(size, to), lines };\n}\n\n/** The sheet itself: the small print that stays on the paper. 2048 x 1536. */\nfunction drawPage(c: Ctx, site: Site) {\n  c.fillStyle = PAPER;\n  c.fillRect(0, 0, 2048, 1536);\n  c.textBaseline = \"alphabetic\";\n  c.fillStyle = \"#3d4149\";\n  setFont(c, 500, 54, -0.015);\n  wrap(c, site.sub, 960).slice(0, 3).forEach((l, i) => c.fillText(l, 123, 985 + i * 70));\n  c.fillStyle = \"rgba(11,13,18,0.14)\";\n  c.fillRect(123, 1426, 1802, 3);\n  c.fillStyle = \"#8d9097\";\n  setFont(c, 600, 25, 0.14);\n  c.fillText(site.foot.toUpperCase(), 123, 1481);\n  const right = site.brand.toUpperCase();\n  c.fillText(right, 1925 - c.measureText(right).width, 1481);\n}\n\n/** One sheet holding the pieces that lift off the page: photograph, headline, menu and button label. 2048 x 2048. */\nfunction drawParts(c: Ctx, site: Site, img: HTMLImageElement | null) {\n  c.fillStyle = \"#000\";\n  c.fillRect(0, 0, 2048, 2048);\n  // photograph, 628 x 1024\n  if (img && img.naturalWidth) {\n    const s = Math.max(628 / img.naturalWidth, 1024 / img.naturalHeight);\n    const w = img.naturalWidth * s;\n    const h = img.naturalHeight * s;\n    c.drawImage(img, (628 - w) / 2, (1024 - h) / 2, w, h);\n  } else {\n    // no photograph for this sentence: a quiet study of a low sun over a dark plain\n    const g = c.createLinearGradient(0, 0, 0, 1024);\n    g.addColorStop(0, \"#3a3c42\");\n    g.addColorStop(0.6, \"#b9bbc1\");\n    g.addColorStop(0.64, \"#d8d9dd\");\n    g.addColorStop(0.645, \"#2a2b30\");\n    g.addColorStop(1, \"#0e0f12\");\n    c.fillStyle = g;\n    c.fillRect(0, 0, 628, 1024);\n    const r = c.createRadialGradient(330, 610, 6, 330, 610, 330);\n    r.addColorStop(0, \"rgba(255,255,255,1)\");\n    r.addColorStop(0.16, \"rgba(255,255,255,0.92)\");\n    r.addColorStop(0.2, \"rgba(255,255,255,0.3)\");\n    r.addColorStop(1, \"rgba(255,255,255,0)\");\n    c.fillStyle = r;\n    c.fillRect(0, 0, 628, 660);\n    const w = c.createLinearGradient(0, 660, 0, 1024);\n    w.addColorStop(0, \"rgba(255,255,255,0.5)\");\n    w.addColorStop(1, \"rgba(255,255,255,0)\");\n    c.fillStyle = w;\n    c.fillRect(290, 662, 80, 362);\n  }\n  c.fillStyle = \"#000\";\n  c.fillRect(628, 0, 1420, 1024);\n  c.fillRect(0, 1024, 2048, 1024);\n  c.fillStyle = \"#fff\";\n  c.textBaseline = \"alphabetic\";\n  // headline, 1024 x 512 at (1024, 0)\n  const head = fit(c, site.headline, 800, -0.045, 1000, 500, 0.93, 232, 60);\n  setFont(c, 800, head.size, -0.045);\n  head.lines.forEach((l, i) => c.fillText(l, 1032, head.size * 0.8 + 6 + i * head.size * 0.93));\n  // menu bar label, 2048 x 144 at (0, 1100)\n  setFont(c, 800, 62, -0.02);\n  c.fillText(site.brand, 68, 1100 + 94);\n  setFont(c, 500, 47, 0);\n  let x = 2048 - 70;\n  for (const item of [...site.nav].reverse()) {\n    x -= c.measureText(item).width;\n    c.fillText(item, x, 1100 + 89);\n    x -= 76;\n  }\n  // button label, 1024 x 284 at (0, 1400)\n  setFont(c, 700, 98, -0.02);\n  const label = site.cta;\n  const lw = c.measureText(label).width;\n  const start = (1024 - lw - 124) / 2;\n  c.fillText(label, start, 1400 + 177);\n  c.lineWidth = 12;\n  c.lineCap = \"round\";\n  c.lineJoin = \"round\";\n  c.strokeStyle = \"#fff\";\n  const ax = start + lw + 46;\n  c.beginPath();\n  c.moveTo(ax, 1542);\n  c.lineTo(ax + 76, 1542);\n  c.moveTo(ax + 46, 1512);\n  c.lineTo(ax + 76, 1542);\n  c.lineTo(ax + 46, 1572);\n  c.stroke();\n}\n\n/** The sentence as it lies on the floor. Returns where the caret sits, in 0..1 of the canvas. */\nfunction drawSentence(c: Ctx, text: string, w: number, h: number, maxLines: number) {\n  c.fillStyle = \"#000\";\n  c.fillRect(0, 0, w, h);\n  c.fillStyle = \"#fff\";\n  c.textBaseline = \"alphabetic\";\n  const pad = 64;\n  const lead = 1.2;\n  const base = Math.floor((h - pad * 2) / (maxLines * lead));\n  const f = fit(c, text || \" \", 600, -0.02, w - pad * 2, h - pad * 2 + 8, lead, base, 40);\n  setFont(c, 600, f.size, -0.02);\n  const top = (h - f.lines.length * f.size * lead) / 2;\n  f.lines.forEach((l, i) => c.fillText(l, pad, top + f.size * 0.92 + i * f.size * lead));\n  const last = f.lines[f.lines.length - 1] ?? \"\";\n  const cx = pad + c.measureText(last).width + f.size * 0.1;\n  const cy = top + (f.lines.length - 0.5) * f.size * lead;\n  return [cx / w, cy / h, (f.size * 0.52) / h, (f.size * 0.035) / w] as const;\n}\n\n/* ---------- shaders ---------- */\n\nconst VERT = `#version 300 es\nin vec2 a; out vec2 vUv;\nvoid main(){ vUv = a * 0.5 + 0.5; gl_Position = vec4(a, 0.0, 1.0); }`;\n\nconst SCENE = `#version 300 es\nprecision highp float;\nin vec2 vUv; out vec4 o;\nuniform vec2 uRes;\nuniform vec3 uCam, uTarget;\nuniform float uFov, uTilt, uGlow, uInk, uText, uTime;\nuniform vec4 uEx;      // how far the menu, headline, photograph and button float off the sheet (0..1)\nuniform vec3 uHinge;   // x, z of the bottom edge and the turn of the sheet\nuniform vec4 uSent;    // floor rectangle that holds the sentence: centre x, centre z, half width, half depth\nuniform vec4 uCaret;   // u, v, half height, strength\nuniform vec2 uPulse;   // position along the sentence, strength\nuniform float uCaretA, uSentR, uBeam;\nuniform sampler2D uPage, uParts, uSentTex;\n\nconst float W = 2.6, H = 1.95, T = 0.07;\nconst vec3 BLUE = vec3(0.078, 0.314, 0.965);\nconst vec3 PAPER = vec3(0.905, 0.89, 0.85);\nconst vec3 KEY = vec3(-0.352, 0.553, 0.755);\nconst vec3 KEYC = vec3(1.02, 1.0, 0.96);\n\nvec3 gPill, gSentL; float gZH, gPix, gDist;\nfloat lodOf(float texels){ return clamp(log2(gDist * gPix * texels), 0.0, 7.0); }\n\nmat2 rot(float a){ float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }\nvec3 toPage(vec3 p){ p.xz -= uHinge.xy; p.y -= 0.032; p.xz = rot(uHinge.z) * p.xz; p.yz = rot(uTilt) * p.yz; return p; }\nvec3 dirPage(vec3 d){ d.xz = rot(uHinge.z) * d.xz; d.yz = rot(uTilt) * d.yz; return d; }\nvec3 dirWorld(vec3 d){ d.yz = rot(-uTilt) * d.yz; d.xz = rot(-uHinge.z) * d.xz; return d; }\nvec3 fromPage(vec3 q){ q.yz = rot(-uTilt) * q.yz; q.xz = rot(-uHinge.z) * q.xz; q.y += 0.032; q.xz += uHinge.xy; return q; }\n\nfloat slab(vec3 q, vec2 c, vec2 h, float r, float z0, float th, float bev){\n  vec2 d2 = abs(q.xy - c) - h + r;\n  float d = length(max(d2, 0.0)) + min(max(d2.x, d2.y), 0.0) - r;\n  vec2 w = vec2(d, abs(q.z - z0) - th) + bev;\n  return min(max(w.x, w.y), 0.0) + length(max(w, 0.0)) - bev;\n}\n\nvec2 map(vec3 p){\n  float fl = p.y, wall = p.z + 6.0;\n  float k = 1.6, hh = clamp(0.5 + 0.5 * (wall - fl) / k, 0.0, 1.0);\n  float room = mix(wall, fl, hh) - k * hh * (1.0 - hh);\n  vec3 q = toPage(p);\n  float bound = length(q - vec3(0.0, H * 0.5, 0.2)) - 1.85;\n  if (bound > 0.4) return vec2(min(room, bound), 1.0);\n  vec2 r = vec2(room, 1.0);\n  float d = slab(q, vec2(0.0, H * 0.5), vec2(W * 0.5, H * 0.5), 0.07, 0.0, T * 0.5, 0.006);\n  if (d < r.x) r = vec2(d, 2.0);\n  d = slab(q, vec2(0.0, 1.770), vec2(1.196, 0.083), 0.083, T * 0.5 + 0.024 + uEx.x * 0.17, 0.024, 0.016);\n  if (d < r.x) r = vec2(d, 3.0);\n  d = slab(q, vec2(0.753, 0.858), vec2(0.43, 0.702), 0.05, T * 0.5 + 0.02 + uEx.z * 0.42, 0.02, 0.007);\n  if (d < r.x) r = vec2(d, 4.0);\n  d = slab(q, vec2(-0.784, 0.37), vec2(0.36, 0.1), 0.1, T * 0.5 + 0.04 + uEx.w * 0.46, 0.04, 0.034);\n  if (d < r.x) r = vec2(d, 5.0);\n  return r;\n}\n\nvec3 normal(vec3 p){\n  vec2 e = vec2(1.0, -1.0) * 0.0012;\n  return normalize(e.xyy * map(p + e.xyy).x + e.yyx * map(p + e.yyx).x + e.yxy * map(p + e.yxy).x + e.xxx * map(p + e.xxx).x);\n}\n\nfloat vis(float vt){ return smoothstep(0.0, 0.015, uInk * 1.05 - vt); }\n\nfloat headA(vec2 xy, float lod){\n  vec2 uv = vec2((xy.x + 1.144) / 1.404, 1.0 - (xy.y - 0.819) / 0.702);\n  if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) return 0.0;\n  vec2 a = vec2(1024.0 + uv.x * 1024.0, uv.y * 512.0) / 2048.0;\n  return textureLod(uParts, a, lod).r * vis(1.0 - xy.y / H);\n}\n\nfloat shadow(vec3 ro, vec3 rd){\n  float res = 1.0, t = 0.02;\n  for (int i = 0; i < 28; i++){\n    float h = map(ro + rd * t).x;\n    res = min(res, 7.0 * h / t);\n    t += clamp(h, 0.012, 0.32);\n    if (res < 0.004 || t > 5.5) break;\n  }\n  res = clamp(res, 0.0, 1.0);\n  res = res * res * (3.0 - 2.0 * res);\n  if (uEx.y > 0.01){\n    vec3 q = toPage(ro), d = dirPage(rd);\n    float tt = (gZH - q.z) / d.z;\n    if (tt > 0.002) res *= 1.0 - 0.62 * headA(q.xy + d.xy * tt, 3.5 + tt * 7.0);\n  }\n  return res;\n}\n\nfloat occ(vec3 p, vec3 n){\n  float o = 0.0, s = 1.0;\n  for (int i = 0; i < 5; i++){\n    float h = 0.012 + 0.11 * float(i) / 4.0;\n    o += (h - map(p + n * h).x) * s;\n    s *= 0.8;\n  }\n  return clamp(1.0 - 3.6 * o, 0.0, 1.0);\n}\n\n// The studio the glossy pieces mirror: one large overhead softbox and a strip to the side.\nvec3 env(vec3 d){\n  vec3 c = vec3(0.010, 0.011, 0.014) + vec3(0.02, 0.022, 0.027) * smoothstep(-0.2, 0.9, d.y);\n  if (d.y > 0.02){\n    vec2 h = d.xz * (6.0 / d.y) - vec2(-2.4, 2.2);\n    vec2 b = 1.0 - smoothstep(vec2(2.5, 1.5), vec2(3.4, 2.3), abs(h));\n    c += vec3(3.2, 3.15, 3.05) * b.x * b.y;\n  }\n  if (d.x < -0.02){\n    vec2 h = d.yz * (-7.5 / d.x) - vec2(2.6, 2.0);\n    vec2 b = 1.0 - smoothstep(vec2(1.7, 0.45), vec2(2.2, 0.75), abs(h));\n    c += vec3(1.5, 1.5, 1.55) * b.x * b.y;\n  }\n  return c;\n}\n\nvec3 lit(vec3 p, vec3 n, float m, vec3 rd, bool hq){\n  vec3 q = toPage(p), nq = dirPage(n);\n  float vt = 1.0 - q.y / H, iv = vis(vt);\n  vec3 alb = PAPER, em = vec3(0.0);\n  float gl = 0.05, f0 = 0.04, rough = 40.0;\n  bool front = nq.z > 0.6;\n  float spot = 1.0;\n  if (m < 1.5){\n    alb = vec3(0.05, 0.052, 0.058); gl = 0.0;\n    vec2 c = p.xz - uHinge.xy - vec2(-0.2, 0.5);\n    spot = 1.0 / (1.0 + dot(c, c) * 0.11);\n    spot *= spot;\n    // a low wash of light on the curved back wall\n    vec2 wd = vec2(p.x - uHinge.x - 0.5, p.y - 0.9);\n    em = vec3(0.04, 0.045, 0.06) * (1.0 - smoothstep(-5.0, -2.5, p.z)) * exp(-(wd.x * wd.x / 11.0 + wd.y * wd.y / 2.2));\n  } else if (m < 2.5){\n    if (front){\n      vec3 tx = pow(textureLod(uPage, vec2(q.x / W + 0.5, vt), lodOf(788.0)).rgb, vec3(2.2));\n      alb = mix(PAPER, tx, iv);\n    }\n    spot = 1.0 - 0.3 * length(q.xy - vec2(-1.0, 1.7)) / 2.6;\n    alb *= 0.955 + 0.03 * fract(sin(dot(floor(q.xy * 900.0), vec2(12.9898, 78.233))) * 43758.5453) + 0.015 * sin(q.x * 310.0 + sin(q.y * 170.0) * 2.0) * sin(q.y * 280.0 + sin(q.x * 130.0) * 2.0);\n    gl = 0.16; rough = 18.0;\n  } else if (m < 3.5){\n    vec3 c = vec3(0.007, 0.008, 0.012);\n    if (front){\n      vec2 uv = vec2((q.x + 1.196) / 2.392, 1.0 - (q.y - 1.687) / 0.166);\n      c = mix(c, vec3(0.93), textureLod(uParts, vec2(uv.x * 2048.0, 1100.0 + uv.y * 144.0) / 2048.0, lodOf(856.0)).r);\n    }\n    alb = mix(PAPER, c, iv); gl = mix(0.05, 0.75, iv); rough = 220.0;\n  } else if (m < 4.5){\n    vec3 c = PAPER;\n    if (front){\n      vec2 uv = vec2((q.x - 0.323) / 0.86, 1.0 - (q.y - 0.156) / 1.404);\n      vec3 tx = pow(textureLod(uParts, vec2(uv.x * 628.0, uv.y * 1024.0) / 2048.0, lodOf(730.0)).rgb, vec3(2.2));\n      float l = dot(tx, vec3(0.2126, 0.7152, 0.0722));\n      l = l * l * (3.0 - 2.0 * l) * 0.35 + l * 0.65;\n      c = vec3(l) * vec3(0.96, 0.985, 1.03) * 0.92 + 0.004;\n    }\n    alb = mix(PAPER, c, iv); gl = mix(0.05, 0.42, iv); rough = 160.0;\n  } else {\n    float lab = 0.0;\n    if (front){\n      vec2 uv = vec2((q.x + 1.144) / 0.72, 1.0 - (q.y - 0.27) / 0.2);\n      lab = textureLod(uParts, vec2(uv.x * 1024.0, 1400.0 + uv.y * 284.0) / 2048.0, lodOf(1422.0)).r;\n    }\n    float core = 0.72 + 0.28 * max(dot(n, -rd), 0.0);\n    alb = mix(PAPER, mix(BLUE * 0.22, vec3(0.9), lab), iv);\n    em = iv * (BLUE * (0.03 + 1.55 * uGlow) * core + lab * vec3(0.95, 0.97, 1.0) * (0.2 + 1.4 * uGlow));\n    gl = mix(0.05, 0.85, iv); rough = 260.0;\n  }\n  if (m > 1.5 && front && uInk > 0.002 && uInk < 0.998){\n    float d = uInk * 1.05 - vt;\n    em += (BLUE * 5.0 + 1.2) * exp(-abs(d) * 110.0) + BLUE * 0.9 * exp(-max(d, 0.0) * 9.0) * step(0.0, d);\n  }\n  float sh = 1.0, ao = 1.0;\n  if (hq){ sh = shadow(p + n * 0.004, KEY); ao = occ(p, n); }\n  float ndl = max(dot(n, KEY), 0.0);\n  vec3 col = alb * (KEYC * ndl * sh * spot + vec3(0.085, 0.092, 0.11) * ao * (0.55 + 0.45 * n.y) * (0.35 + 0.65 * spot));\n  vec3 lb = gPill - p; float d2 = dot(lb, lb);\n  float nb = max(dot(n, lb * inversesqrt(d2)), 0.0) * 0.8 + 0.2;\n  if (m < 4.5) col += alb * BLUE * uGlow * 0.62 * nb / (0.22 + d2 * 3.0) * (0.4 + 0.6 * ao);\n  vec3 ls = gSentL - p; d2 = dot(ls, ls);\n  col += alb * BLUE * uText * 0.55 * max(dot(n, ls * inversesqrt(d2)), 0.0) / (0.5 + d2);\n  vec3 r = reflect(rd, n);\n  float fr = f0 + (1.0 - f0) * pow(1.0 - max(dot(n, -rd), 0.0), 5.0);\n  col += env(r) * fr * gl * (0.3 + 0.7 * ao);\n  col += KEYC * pow(max(dot(n, normalize(KEY - rd)), 0.0), rough) * gl * sh * 0.5;\n  col += alb * vec3(0.5, 0.52, 0.56) * max(dot(n, vec3(0.83, 0.28, -0.48)), 0.0);\n  return col + em;\n}\n\n// The headline is a sheet of cut letters floating in front of the page.\nvoid letters(vec3 ro, vec3 rd, float tmax, inout vec3 col){\n  vec3 q = toPage(ro), d = dirPage(rd);\n  if (abs(d.z) < 0.0001) return;\n  float depth = 0.0085 * min(1.0, uEx.y * 6.0);\n  vec4 acc = vec4(0.0);\n  for (int i = 0; i < 7; i++){\n    float tt = (gZH - float(i) * depth - q.z) / d.z;\n    if (tt < 0.0 || tt > tmax + 0.004) continue;\n    vec2 xy = q.xy + d.xy * tt;\n    float a = headA(xy, clamp(log2(tt * gPix * 730.0), 0.0, 6.0));\n    if (a < 0.003) continue;\n    vec3 c = vec3(0.008, 0.009, 0.013);\n    if (i == 0) c += env(reflect(rd, dirWorld(vec3(0.0, 0.0, 1.0)))) * 0.02;\n    else c = vec3(0.075, 0.08, 0.092) * (1.0 - 0.1 * float(i));\n    vec3 pw = ro + rd * tt;\n    vec3 lb = gPill - pw;\n    c += BLUE * uGlow * 0.05 / (0.15 + dot(lb, lb) * 2.0);\n    acc.rgb += (1.0 - acc.a) * a * c;\n    acc.a += (1.0 - acc.a) * a;\n    if (depth < 0.0005) break;\n  }\n  col = mix(col, acc.rgb / max(acc.a, 0.001), acc.a);\n}\n\n// The sentence: letters of lit glass standing a few millimetres off the floor, and their image in it.\nvoid sentence(vec3 ro, vec3 rd, float tmax, float onFloor, inout vec3 col){\n  if (rd.y > -0.001) return;\n  float hT = 0.02;\n  vec4 acc = vec4(0.0);\n  for (int i = 0; i < 12; i++){\n    float fi = float(i);\n    float y = i < 6 ? hT * (1.0 - fi / 5.0) : -hT * (fi - 6.0) / 5.0;\n    float tt = (y - ro.y) / rd.y;\n    vec3 p = ro + rd * tt;\n    vec2 su = (rot(uSentR) * (p.xz - uSent.xy)) / (uSent.zw * 2.0) + 0.5;\n    float inside = step(0.0, su.x) * step(su.x, 1.0) * step(0.0, su.y) * step(su.y, 1.0);\n    float a = textureLod(uSentTex, su, clamp(log2(tt * gPix * 520.0), 0.0, 5.0)).r * inside;\n    a *= i < 6 ? step(tt, tmax + 0.02) : onFloor * 0.2;\n    float wave = uPulse.y * exp(-pow((su.x - uPulse.x) * 5.0, 2.0));\n    vec3 c = i == 0 ? mix(BLUE, vec3(1.0), 0.86) * (2.6 + 6.0 * wave) : BLUE * (2.3 - 0.3 * min(fi, 5.0)) * (1.0 + 3.0 * wave) + vec3(0.25) * exp(-fi * 1.3);\n    if (i >= 6) c = BLUE * (1.3 - 0.18 * (fi - 6.0));\n    a *= uText;\n    acc.rgb += (1.0 - acc.a) * a * c;\n    acc.a += (1.0 - acc.a) * a;\n  }\n  col = mix(col, acc.rgb / max(acc.a, 0.001), acc.a);\n}\n\n// The blade of light that leaves the sentence and writes the page.\nvoid beam(vec3 ro, vec3 rd, float tmax, inout vec3 col){\n  if (uBeam < 0.01 || uInk < 0.002 || uInk > 0.998) return;\n  vec3 S = vec3(uSent.x, 0.05, uSent.y);\n  vec3 Lc = fromPage(vec3(0.0, H * (1.0 - uInk * 1.05), T * 0.5 + 0.02));\n  vec3 X = dirWorld(vec3(1.0, 0.0, 0.0));\n  vec3 A = Lc - S;\n  vec3 N = normalize(cross(X, A));\n  float dn = dot(rd, N);\n  if (abs(dn) < 0.0005) return;\n  float tt = dot(Lc - ro, N) / dn;\n  if (tt < 0.0 || tt > tmax) return;\n  vec3 v = ro + rd * tt - S;\n  vec3 Ap = A - X * dot(A, X);\n  float sA = dot(v, Ap) / dot(A, Ap), lat = (dot(v, X) - sA * dot(A, X)) / (W * 0.5);\n  float w = max(sA, 0.02);\n  float m = smoothstep(0.0, 0.06, sA) * (1.0 - smoothstep(0.985, 1.0, sA)) * (1.0 - smoothstep(0.9, 1.0, abs(lat) / w));\n  float rays = 0.55 + 0.45 * sin(lat / w * 23.0 + sin(lat / w * 7.0) * 2.0);\n  col += (BLUE * 1.1 + 0.12) * m * uBeam * rays * (0.14 + 0.5 * sA * sA);\n}\n\nvec2 march(vec3 ro, vec3 rd, int steps, float far){\n  float t = 0.0; vec2 h = vec2(0.0);\n  for (int i = 0; i < 96; i++){\n    if (i >= steps) break;\n    h = map(ro + rd * t);\n    if (h.x < 0.0007 * (1.0 + t) || t > far) break;\n    t += h.x;\n  }\n  return vec2(t, t > far ? 0.0 : h.y);\n}\n\nvec3 aces(vec3 x){ 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 uv = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;\n  vec3 f = normalize(uTarget - uCam), rgt = normalize(cross(f, vec3(0.0, 1.0, 0.0))), up = cross(rgt, f);\n  vec3 rd = normalize(f + (uv.x * rgt + uv.y * up) * 2.0 * tan(uFov * 0.5));\n  vec3 ro = uCam;\n  gZH = T * 0.5 + 0.004 + uEx.y * 0.22;\n  gPix = 2.0 * tan(uFov * 0.5) / uRes.y;\n  gPill = fromPage(vec3(-0.784, 0.37, T * 0.5 + 0.08 + uEx.w * 0.46));\n  gSentL = vec3(uSent.x, 0.12, uSent.y);\n\n  vec2 hit = march(ro, rd, 96, 30.0);\n  float t = hit.x;\n  vec3 col = vec3(0.0);\n  if (hit.y > 0.5){\n    vec3 p = ro + rd * t, n = normal(p);\n    gDist = t;\n    col = lit(p, n, hit.y, rd, true);\n    if (hit.y < 1.5){\n      // the floor: sentence of light, then what it mirrors\n      float flat_ = smoothstep(0.9, 0.99, n.y);\n      vec2 su = (rot(uSentR) * (p.xz - uSent.xy)) / (uSent.zw * 2.0) + 0.5;\n      float inside = step(0.0, su.x) * step(su.x, 1.0) * step(0.0, su.y) * step(su.y, 1.0);\n      float a = texture(uSentTex, su).r * inside;\n      float g1 = textureLod(uSentTex, su, 2.6).r, g2 = textureLod(uSentTex, su, 5.4).r;\n      float wave = uPulse.y * exp(-pow((su.x - uPulse.x) * 5.0, 2.0));\n      vec2 cd = (su - uCaret.xy) / vec2(max(uCaret.w, 0.0005), uCaret.z);\n      float caret = uCaret.w > 0.0 ? (1.0 - smoothstep(0.6, 1.0, abs(cd.x))) * (1.0 - smoothstep(0.9, 1.0, abs(cd.y))) * inside * uCaretA : 0.0;\n      vec3 e = (g1 * 0.5 + g2 * 0.7) * BLUE * (1.0 + 3.0 * wave) * uText + a * 0.0;\n      e += caret * mix(BLUE, vec3(1.0), 0.5) * 3.0;\n      col += e * flat_;\n      vec3 lb = gPill - p;\n      col += BLUE * uGlow * 0.035 / (0.35 + dot(lb, lb)) * flat_;\n      vec3 rr = reflect(rd, n);\n      float fr = 0.07 + 0.93 * pow(1.0 - max(dot(n, -rd), 0.0), 5.0);\n      vec3 rp = p + n * 0.004;\n      vec2 rh = march(rp, rr, 56, 14.0);\n      vec3 rc = vec3(0.012, 0.013, 0.017);\n      if (rh.y > 0.5){\n        vec3 hp = rp + rr * rh.x;\n        gDist = t + rh.x;\n        rc = lit(hp, normal(hp), rh.y, rr, false);\n      }\n      letters(rp, rr, rh.x, rc);\n      float fn = 0.5 + 0.5 * sin(p.x * 3.1 + sin(p.z * 2.3) * 1.7) * sin(p.z * 2.7 + sin(p.x * 1.9) * 1.3);\n      float clear = 1.0 - smoothstep(0.0, 0.25, textureLod(uSentTex, su, 7.0).r) * step(-0.3, su.x) * step(su.x, 1.3) * step(-0.5, su.y) * step(su.y, 1.5);\n      col += rc * fr * exp(-rh.x * 1.5) * (0.86 + 0.14 * fn) * clear;\n    }\n  }\n  sentence(ro, rd, t, hit.y > 0.5 && hit.y < 1.5 ? 1.0 : 0.0, col);\n  letters(ro, rd, t, col);\n  beam(ro, rd, t, col);\n  // light in the air around the button\n  float tc = clamp(dot(gPill - ro, rd), 0.0, t);\n  float dm = length(ro + rd * tc - gPill);\n  col += BLUE * uGlow * 0.006 / (0.06 + dm * dm * 3.0);\n  float mx = max(col.r, max(col.g, col.b));\n  col = mix(col * (aces(vec3(mx)).r / max(mx, 0.0001)), aces(col), 0.25);\n  col = pow(col, vec3(1.0 / 2.2));\n  o = vec4(col, clamp(t / 24.0, 0.0, 1.0));\n}`;\n\nconst POST = `#version 300 es\nprecision highp float;\nin vec2 vUv; out vec4 o;\nuniform sampler2D uSrc;\nuniform vec2 uRes;\nuniform float uFocus, uTime;\nfloat hash(vec2 p){ return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453); }\nvoid main(){\n  vec4 c0 = texture(uSrc, vUv);\n  float z = c0.a * 24.0;\n  {\n    vec2 e = 1.0 / uRes; vec3 L = vec3(0.299, 0.587, 0.114);\n    float nw = dot(textureLod(uSrc, vUv + vec2(-e.x, -e.y), 0.0).rgb, L), ne = dot(textureLod(uSrc, vUv + vec2(e.x, -e.y), 0.0).rgb, L);\n    float sw = dot(textureLod(uSrc, vUv + vec2(-e.x, e.y), 0.0).rgb, L), se = dot(textureLod(uSrc, vUv + e, 0.0).rgb, L), lm = dot(c0.rgb, L);\n    float lo = min(lm, min(min(nw, ne), min(sw, se))), hi = max(lm, max(max(nw, ne), max(sw, se)));\n    vec2 dir = vec2(-((nw + ne) - (sw + se)), (nw + sw) - (ne + se));\n    float rcp = 1.0 / (min(abs(dir.x), abs(dir.y)) + max((nw + ne + sw + se) * 0.03125, 0.0078));\n    dir = clamp(dir * rcp, -8.0, 8.0) * e;\n    vec3 a = 0.5 * (textureLod(uSrc, vUv + dir * (1.0 / 3.0 - 0.5), 0.0).rgb + textureLod(uSrc, vUv + dir * (2.0 / 3.0 - 0.5), 0.0).rgb);\n    vec3 b = a * 0.5 + 0.25 * (textureLod(uSrc, vUv - dir * 0.5, 0.0).rgb + textureLod(uSrc, vUv + dir * 0.5, 0.0).rgb);\n    float lb = dot(b, L);\n    c0.rgb = (lb < lo || lb > hi) ? a : b;\n  }\n  float px = uRes.y / 720.0;\n  float coc = clamp(abs(z - uFocus) / max(z, 0.1) * (z < uFocus ? 5.0 : 36.0) - 0.7, 0.0, 7.0) * px;\n  vec3 acc = c0.rgb; float ws = 1.0;\n  float j = hash(gl_FragCoord.xy) * 6.283;\n  float lod = log2(max(coc / 3.0, 1.0));\n  for (int i = 0; i < 14; i++){\n    float fi = (float(i) + 0.5) / 14.0;\n    float a = float(i) * 2.39996 + j;\n    vec2 off = vec2(cos(a), sin(a)) * sqrt(fi) * coc / uRes;\n    vec4 s = textureLod(uSrc, vUv + off, lod);\n    float w = 1.0 + 5.0 * pow(max(s.r, max(s.g, s.b)), 6.0);\n    acc += s.rgb * w; ws += w;\n  }\n  vec3 col = acc / ws;\n  vec3 bl = textureLod(uSrc, vUv, 3.5).rgb * 0.4 + textureLod(uSrc, vUv, 5.0).rgb * 0.35 + textureLod(uSrc, vUv, 6.5).rgb * 0.25;\n  col += bl * bl * 0.05;\n  vec2 v = vUv - 0.5;\n  col *= 1.0 - dot(v, v) * 0.75;\n  float g = hash(gl_FragCoord.xy + fract(uTime) * 91.7) - 0.5;\n  col += g * 0.028 * (1.0 - 0.5 * col);\n  o = vec4(col, 1.0);\n}`;\n\n/* ---------- small motion helpers ---------- */\n\ntype Spring = { x: number; v: number; t: number; k: number; c: number };\nconst spring = (x: number, k: number, c: number): Spring => ({ x, v: 0, t: x, k, c });\nconst stepSpring = (s: Spring, dt: number) => {\n  s.v += (-s.k * (s.x - s.t) - s.c * s.v) * dt;\n  s.x += s.v * dt;\n};\n\nfunction ArrowIcon() {\n  return (\n    <svg viewBox=\"0 0 20 20\" className=\"h-5 w-5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d=\"M4 10h12M11 5l5 5-5 5\" />\n    </svg>\n  );\n}\n\nexport default function SentenceOfLightStandingPage() {\n  const reduce = useReducedMotion();\n  const [value, setValue] = useState(DEMOS[0].sentence);\n  const [site, setSite] = useState<Site>(DEMOS[0].site);\n  const [live, setLive] = useState(false);\n  const rootRef = useRef<HTMLElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const inputRef = useRef<HTMLInputElement>(null);\n  // The render loop owns the scene. React talks to it through this handle.\n  const api = useRef<{ type: (text: string) => void; build: (text: string) => void; focus: (on: boolean) => void } | null>(null);\n\n  useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    if (!root || !canvas) return;\n    const gl = canvas.getContext(\"webgl2\", { antialias: false, alpha: false, powerPreference: \"high-performance\" });\n    if (!gl) return;\n\n    const compile = (type: number, src: string) => {\n      const s = gl.createShader(type)!;\n      gl.shaderSource(s, src);\n      gl.compileShader(s);\n      if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s) || \"shader\");\n      return s;\n    };\n    const link = (fs: string) => {\n      const p = gl.createProgram()!;\n      gl.attachShader(p, compile(gl.VERTEX_SHADER, VERT));\n      gl.attachShader(p, compile(gl.FRAGMENT_SHADER, fs));\n      gl.bindAttribLocation(p, 0, \"a\");\n      gl.linkProgram(p);\n      if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p) || \"link\");\n      return p;\n    };\n    let scene: WebGLProgram;\n    let post: WebGLProgram;\n    try {\n      scene = link(SCENE);\n      post = link(POST);\n    } catch (e) {\n      console.error(e);\n      return;\n    }\n    const U = (p: WebGLProgram, n: string) => gl.getUniformLocation(p, n);\n    const su = Object.fromEntries([\"uRes\", \"uCam\", \"uTarget\", \"uFov\", \"uTilt\", \"uGlow\", \"uInk\", \"uText\", \"uTime\", \"uEx\", \"uHinge\", \"uSent\", \"uCaret\", \"uPulse\", \"uCaretA\", \"uSentR\", \"uBeam\", \"uPage\", \"uParts\", \"uSentTex\"].map((n) => [n, U(scene, n)]));\n    const pu = Object.fromEntries([\"uSrc\", \"uRes\", \"uFocus\", \"uTime\"].map((n) => [n, U(post, n)]));\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);\n    gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n\n    const aniso = gl.getExtension(\"EXT_texture_filter_anisotropic\");\n    const makeTex = () => {\n      const t = gl.createTexture()!;\n      gl.bindTexture(gl.TEXTURE_2D, t);\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      if (aniso) gl.texParameterf(gl.TEXTURE_2D, aniso.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(8, gl.getParameter(aniso.MAX_TEXTURE_MAX_ANISOTROPY_EXT)));\n      return t;\n    };\n    const upload = (t: WebGLTexture, src: HTMLCanvasElement) => {\n      gl.bindTexture(gl.TEXTURE_2D, t);\n      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, src);\n      gl.generateMipmap(gl.TEXTURE_2D);\n    };\n    const mk = (w: number, h: number) => {\n      const c = document.createElement(\"canvas\");\n      c.width = w;\n      c.height = h;\n      return [c, c.getContext(\"2d\")!] as const;\n    };\n    const [pageCv, pageCx] = mk(2048, 1536);\n    const [partsCv, partsCx] = mk(2048, 2048);\n    const [sentCv, sentCx] = mk(2048, 512);\n    const pageTex = makeTex();\n    const partsTex = makeTex();\n    const sentTex = makeTex();\n\n    // photographs, loaded so that they may be used as textures\n    let photoOk = true;\n    const imgs = PHOTOS.map((p) => {\n      const im = new Image();\n      im.crossOrigin = \"anonymous\";\n      im.decoding = \"async\";\n      im.onload = () => {\n        if (cur.photo >= 0 && imgs[cur.photo] === im) paintSite(cur);\n        dirty = true;\n      };\n      im.src = p.src;\n      return im;\n    });\n\n    let cur: Site = DEMOS[0].site;\n    const paintSite = (s: Site) => {\n      cur = s;\n      drawPage(pageCx, s);\n      upload(pageTex, pageCv);\n      const im = photoOk && s.photo >= 0 && imgs[s.photo] && imgs[s.photo].complete && imgs[s.photo].naturalWidth ? imgs[s.photo] : null;\n      drawParts(partsCx, s, im);\n      try {\n        upload(partsTex, partsCv);\n      } catch {\n        // a photograph that may not be read back: draw the plain light study instead\n        photoOk = false;\n        const [c2, x2] = mk(2048, 2048);\n        drawParts(x2, s, null);\n        upload(partsTex, c2);\n      }\n    };\n\n    // layout: wide stage or phone\n    let cssW = 0;\n    let cssH = 0;\n    let phone = false;\n    let caret = [0, 0, 0, 0] as readonly number[];\n    let shown = DEMOS[0].sentence;\n    const paintSentence = () => {\n      const w = phone ? 1536 : 2048;\n      const h = phone ? 768 : 512;\n      if (sentCv.width !== w) {\n        sentCv.width = w;\n        sentCv.height = h;\n      }\n      caret = drawSentence(sentCx, shown, w, h, phone ? 3 : 2);\n      upload(sentTex, sentCv);\n    };\n\n    // the moving parts\n    const tilt = spring(0, 34, 6.2);\n    const ex = [spring(1, 130, 11), spring(1, 120, 10.5), spring(1, 100, 9.5), spring(1, 110, 9)];\n    const glow = spring(1, 260, 24);\n    const ink = { x: 1, t: 1, rate: 1 };\n    const pulse = { x: 2, on: false };\n    const text = spring(1, 60, 14);\n    const cam = { ax: 0, ay: 0, tx: 0, ty: 0, push: spring(0, 30, 9) };\n    let caretFlash = 0;\n    let focused = false;\n    let demo = !reduce;\n    let demoIx = 0;\n    let clock = 0;\n    let idleAt = HOLD;\n    let cues: { at: number; fn: () => void }[] = [];\n    let target = shown; // what the typist is heading for\n    let typeAt = 0;\n    let afterType: (() => void) | null = null;\n    let dirty = true;\n    const at = (delay: number, fn: () => void) => {\n      cues.push({ at: clock + delay, fn });\n      cues.sort((a, b) => a.at - b.at);\n    };\n\n    const rise = (s: Site) => {\n      paintSite(s);\n      setSite(s);\n      ink.x = 0;\n      ink.t = 0;\n      pulse.x = -0.25;\n      pulse.on = true;\n      at(0.3, () => {\n        tilt.t = 0;\n        cam.push.t = 1;\n      });\n      at(1.0, () => {\n        ink.t = 1;\n        ink.rate = 1.15;\n      });\n      at(1.85, () => (ex[0].t = 1));\n      at(1.97, () => (ex[1].t = 1));\n      at(2.1, () => (ex[2].t = 1));\n      at(2.26, () => (ex[3].t = 1));\n      at(2.62, () => (glow.t = 0.75));\n      at(2.7, () => (glow.t = 0.1));\n      at(2.8, () => {\n        glow.t = 1;\n        cam.push.t = 0;\n      });\n      at(2.9, () => (idleAt = clock + HOLD));\n    };\n    const fold = (then: () => void) => {\n      cues = [];\n      idleAt = Infinity;\n      glow.t = 0;\n      at(0.06, () => (ex[3].t = 0));\n      at(0.13, () => (ex[2].t = 0));\n      at(0.2, () => (ex[1].t = 0));\n      at(0.26, () => (ex[0].t = 0));\n      at(0.3, () => {\n        ink.t = 0;\n        ink.rate = 2.6;\n      });\n      at(0.55, () => (tilt.t = LIE));\n      at(1.05, then);\n    };\n    const nextDemo = () => {\n      demoIx = (demoIx + 1) % DEMOS.length;\n      const d = DEMOS[demoIx];\n      fold(() => {\n        target = d.sentence;\n        afterType = () => at(0.35, () => rise(d.site));\n      });\n    };\n    const settle = () => {\n      // bring the page back to its finished state at once (used with reduced motion)\n      cues = [];\n      tilt.x = tilt.t = 0;\n      tilt.v = 0;\n      ex.forEach((e) => ((e.x = e.t = 1), (e.v = 0)));\n      glow.x = glow.t = 1;\n      ink.x = ink.t = 1;\n      pulse.on = false;\n      dirty = true;\n    };\n\n    api.current = {\n      type: (t) => {\n        shown = target = t;\n        afterType = null;\n        caretFlash = 1;\n        paintSentence();\n        dirty = true;\n      },\n      build: (t) => {\n        demo = false;\n        shown = target = t;\n        afterType = null;\n        paintSentence();\n        const s = compose(t);\n        if (reduce) {\n          paintSite(s);\n          setSite(s);\n          settle();\n          return;\n        }\n        fold(() => rise(s));\n        at(1.05 + 2.9 + 16, () => {\n          if (!focused) demo = true;\n        });\n      },\n      focus: (on) => {\n        focused = on;\n        dirty = true;\n        if (on && demo) {\n          demo = false;\n          const typing = target !== shown || afterType;\n          target = shown;\n          afterType = null;\n          if (typing || tilt.t !== 0) {\n            cues = [];\n            rise(compose(shown));\n          } else idleAt = Infinity;\n        }\n        if (!on && !demo) at(18, () => {\n          if (!focused) {\n            demo = true;\n            idleAt = clock + 1;\n          }\n        });\n      },\n    };\n\n    // render target\n    const fbo = gl.createFramebuffer();\n    const fbTex = gl.createTexture()!;\n    gl.bindTexture(gl.TEXTURE_2D, fbTex);\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    let scale = Math.min(MAX_SCALE, Math.max(1, window.devicePixelRatio || 1));\n    let bw = 0;\n    let bh = 0;\n    const resize = () => {\n      const r = canvas.getBoundingClientRect();\n      cssW = Math.max(1, r.width);\n      cssH = Math.max(1, r.height);\n      const wasPhone = phone;\n      phone = cssW / cssH < 0.95;\n      // never more than about 1.5 million pixels through the ray marcher\n      const s = Math.min(scale, Math.sqrt(1.5e6 / (cssW * cssH)));\n      const w = Math.round(cssW * s);\n      const h = Math.round(cssH * s);\n      if (w !== bw || h !== bh) {\n        bw = w;\n        bh = h;\n        canvas.width = w;\n        canvas.height = h;\n        gl.bindTexture(gl.TEXTURE_2D, fbTex);\n        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);\n        gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);\n        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbTex, 0);\n      }\n      if (wasPhone !== phone || !caret[2]) paintSentence();\n      dirty = true;\n    };\n\n    paintSite(cur);\n    resize();\n    paintSentence();\n\n    let time = 0;\n    const draw = () => {\n      const wide = cssW / cssH;\n      // camera\n      const az = (phone ? -0.2 : -0.32) + cam.ax * 0.16 + Math.sin(time * 0.23) * 0.022;\n      const el = (phone ? 0.3 : 0.335) - cam.ay * 0.07 + Math.sin(time * 0.31 + 1) * 0.008;\n      const dist = (phone ? 12.0 : 8.0 * Math.max(1, 1.62 / wide)) * (1 - 0.035 * cam.push.x);\n      const tgt = phone ? [0, 0.42, 0.6] : [0.42, 0.7, 0.4];\n      const camPos = [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 hinge = phone ? [0, 0, 0] : [1.0, 0, 0];\n      const sent = phone ? [0, 1.75, 1.42, 0.95] : [-0.3, 1.12, 1.62, 0.52];\n      const breathe = reduce ? 0 : 1;\n\n      gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);\n      gl.viewport(0, 0, bw, bh);\n      gl.useProgram(scene);\n      gl.uniform2f(su.uRes, bw, bh);\n      gl.uniform3f(su.uCam, camPos[0], camPos[1], camPos[2]);\n      gl.uniform3f(su.uTarget, tgt[0], tgt[1], tgt[2]);\n      gl.uniform1f(su.uFov, phone ? 0.5 : 0.4);\n      gl.uniform1f(su.uTilt, tilt.x);\n      gl.uniform1f(su.uGlow, Math.max(0, glow.x) * (1 + 0.035 * Math.sin(time * 1.7) * breathe));\n      gl.uniform1f(su.uInk, ink.x);\n      gl.uniform1f(su.uText, text.x);\n      gl.uniform1f(su.uTime, time);\n      const b = (i: number) => Math.max(0, ex[i].x) * (1 + 0.05 * Math.sin(time * 0.7 + i * 1.7) * breathe);\n      gl.uniform4f(su.uEx, b(0), b(1), b(2), b(3));\n      gl.uniform3f(su.uHinge, hinge[0], hinge[2], hinge[1]);\n      gl.uniform4f(su.uSent, sent[0], sent[1], sent[2], sent[3]);\n      gl.uniform1f(su.uSentR, -az * 0.62);\n      gl.uniform1f(su.uBeam, ink.t === 1 && tilt.t === 0 ? 1 : 0);\n      const blink = focused || target !== shown ? (Math.sin(time * 6.5) > -0.2 ? 1 : 0.15) : 0;\n      gl.uniform4f(su.uCaret, caret[0], caret[1], caret[2], blink > 0 ? caret[3] * (1 + caretFlash) : 0);\n      gl.uniform1f(su.uCaretA, Math.min(1.6, blink + caretFlash));\n      gl.uniform2f(su.uPulse, pulse.x, pulse.on ? 1 : 0);\n      gl.activeTexture(gl.TEXTURE0);\n      gl.bindTexture(gl.TEXTURE_2D, pageTex);\n      gl.uniform1i(su.uPage, 0);\n      gl.activeTexture(gl.TEXTURE1);\n      gl.bindTexture(gl.TEXTURE_2D, partsTex);\n      gl.uniform1i(su.uParts, 1);\n      gl.activeTexture(gl.TEXTURE2);\n      gl.bindTexture(gl.TEXTURE_2D, sentTex);\n      gl.uniform1i(su.uSentTex, 2);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n\n      gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n      gl.viewport(0, 0, bw, bh);\n      gl.useProgram(post);\n      gl.activeTexture(gl.TEXTURE0);\n      gl.bindTexture(gl.TEXTURE_2D, fbTex);\n      gl.generateMipmap(gl.TEXTURE_2D);\n      gl.uniform1i(pu.uSrc, 0);\n      gl.uniform2f(pu.uRes, bw, bh);\n      const fx = camPos[0] - (hinge[0] - 0.75);\n      const fy = camPos[1] - 0.9;\n      const fz = camPos[2] - 0.25;\n      gl.uniform1f(pu.uFocus, Math.sqrt(fx * fx + fy * fy + fz * fz));\n      gl.uniform1f(pu.uTime, reduce ? 0 : time);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n    };\n\n    let raf = 0;\n    let last = 0;\n    let onScreen = true;\n    let slow = 0;\n    let first = true;\n    const frame = (now: number) => {\n      raf = 0;\n      const raw = last ? (now - last) / 1000 : 0.016;\n      last = now;\n      const dt = Math.min(raw, 0.1);\n      if (reduce) {\n        if (dirty) {\n          dirty = false;\n          draw();\n        }\n      } else {\n        clock += dt;\n        time += dt;\n        while (cues.length && cues[0].at <= clock) cues.shift()!.fn();\n        if (demo && clock > idleAt) {\n          idleAt = Infinity;\n          nextDemo();\n        }\n        // the typist\n        if (target !== shown && clock >= typeAt) {\n          if (!target.startsWith(shown)) {\n            shown = shown.slice(0, Math.max(0, shown.length - 3));\n            typeAt = clock + 0.016;\n          } else {\n            shown = target.slice(0, shown.length + 1);\n            typeAt = clock + 0.03 + Math.random() * 0.035 + (shown.endsWith(\" \") ? 0.03 : 0);\n            caretFlash = 1;\n          }\n          paintSentence();\n          setValue(shown);\n          if (target === shown && afterType) {\n            const fn = afterType;\n            afterType = null;\n            fn();\n          }\n        }\n        for (let n = 0; n < 4; n++) {\n          const h = dt / 4;\n          stepSpring(tilt, h);\n          ex.forEach((e) => stepSpring(e, h));\n          stepSpring(glow, h);\n          stepSpring(text, h);\n          stepSpring(cam.push, h);\n        }\n        // the sheet cannot swing through the floor\n        if (tilt.x < LIE - 0.06) {\n          tilt.x = LIE - 0.06;\n          tilt.v *= -0.25;\n        }\n        ink.x += Math.sign(ink.t - ink.x) * Math.min(Math.abs(ink.t - ink.x), dt * ink.rate);\n        if (pulse.on) {\n          pulse.x += dt * 1.9;\n          if (pulse.x > 1.5) pulse.on = false;\n        }\n        caretFlash *= Math.exp(-dt * 9);\n        const kc = 1 - Math.exp(-dt * 3.2);\n        cam.ax += (cam.tx - cam.ax) * kc;\n        cam.ay += (cam.ty - cam.ay) * kc;\n        draw();\n        // step the resolution down if this machine cannot hold the frame rate\n        if (raw > 0.03) slow++;\n        else slow = Math.max(0, slow - 1);\n        if (slow > 24 && scale > MIN_SCALE) {\n          scale = Math.max(MIN_SCALE, scale * 0.84);\n          slow = 0;\n          resize();\n        }\n      }\n      if (first) {\n        first = false;\n        setLive(true);\n      }\n      if (onScreen && !document.hidden) raf = requestAnimationFrame(frame);\n    };\n    const kick = () => {\n      if (!raf && onScreen && !document.hidden) {\n        last = 0;\n        raf = requestAnimationFrame(frame);\n      }\n    };\n    const io = new IntersectionObserver(([e]) => {\n      onScreen = e.isIntersecting;\n      kick();\n    });\n    io.observe(root);\n    const ro = new ResizeObserver(() => {\n      resize();\n      kick();\n    });\n    ro.observe(canvas);\n    const onVis = () => kick();\n    document.addEventListener(\"visibilitychange\", onVis);\n    const onMove = (e: PointerEvent) => {\n      if (reduce) return;\n      const r = root.getBoundingClientRect();\n      cam.tx = Math.max(-1, Math.min(1, ((e.clientX - r.left) / r.width) * 2 - 1));\n      cam.ty = Math.max(-1, Math.min(1, ((e.clientY - r.top) / r.height) * 2 - 1));\n    };\n    const onLeave = () => {\n      cam.tx = 0;\n      cam.ty = 0;\n    };\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    const onLost = (e: Event) => {\n      e.preventDefault();\n      setLive(false);\n      cancelAnimationFrame(raf);\n    };\n    canvas.addEventListener(\"webglcontextlost\", onLost);\n    kick();\n\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      ro.disconnect();\n      document.removeEventListener(\"visibilitychange\", onVis);\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      canvas.removeEventListener(\"webglcontextlost\", onLost);\n      imgs.forEach((im) => (im.onload = null));\n      api.current = null;\n      [pageTex, partsTex, sentTex, fbTex].forEach((t) => gl.deleteTexture(t));\n      gl.deleteFramebuffer(fbo);\n      gl.deleteBuffer(quad);\n      gl.deleteProgram(scene);\n      gl.deleteProgram(post);\n    };\n  }, [reduce]);\n\n  const submit = (e: FormEvent) => {\n    e.preventDefault();\n    const t = value.trim();\n    if (!t) return;\n    if (api.current) api.current.build(t);\n    else setSite(compose(t));\n  };\n\n  const photo = site.photo >= 0 ? PHOTOS[site.photo] : null;\n  const headLines = site.headline.split(\"\\n\");\n  const longHead = site.headline.length > 28;\n\n  return (\n    <section ref={rootRef} className=\"relative isolate h-[660px] w-full overflow-hidden md:h-[740px]\" style={{ backgroundColor: INK, fontFamily: FONT }}>\n      <style>{`\n        @keyframes sentence-of-light-standing-page-breathe { 0%, 100% { opacity: .82 } 50% { opacity: 1 } }\n        .sentence-of-light-standing-page-glow { animation: sentence-of-light-standing-page-breathe 4.5s ease-in-out infinite }\n        @media (prefers-reduced-motion: reduce) { .sentence-of-light-standing-page-glow { animation: none } }\n      `}</style>\n\n      {/* The still: the same picture built from elements. Shown before the renderer starts and wherever it cannot run. */}\n      <div className={`absolute inset-0 transition-opacity duration-700 ${live ? \"opacity-0\" : \"opacity-100\"}`} style={{ background: \"radial-gradient(90% 60% at 58% 58%, #1a1d25 0%, #0e1016 46%, #0B0D12 100%)\" }}>\n        <div className=\"absolute inset-x-0 top-[62%] bottom-0\" style={{ background: \"linear-gradient(180deg, rgba(79,152,251,0.05) 0%, rgba(11,13,18,0) 60%)\" }} aria-hidden=\"true\" />\n        <div className=\"absolute left-1/2 top-[45%] w-[min(86vw,560px)] -translate-x-1/2 -translate-y-1/2 md:left-[57%] md:top-[43%]\" style={{ perspective: \"1600px\" }}>\n          <div className=\"relative rounded-[14px]\" style={{ aspectRatio: \"4 / 3\", backgroundColor: PAPER, transform: \"rotateY(19deg) rotateX(3deg)\", transformStyle: \"preserve-3d\", boxShadow: \"-1px 0 0 #cfcbc2, -3px 1px 0 #b9b5ac, 0 60px 90px -30px rgba(0,0,0,0.9), 0 0 120px -20px rgba(79,152,251,0.28)\" }}>\n            <div className=\"absolute inset-x-[4%] top-[5%] flex h-[8.5%] items-center justify-between rounded-full px-[3%] text-white\" style={{ backgroundColor: INK, transform: \"translateZ(22px)\", boxShadow: \"0 14px 18px -8px rgba(11,13,18,0.5), inset 0 1px 0 rgba(255,255,255,0.14)\" }}>\n              <span className=\"text-[11px] font-extrabold tracking-tight md:text-[13px]\">{site.brand}</span>\n              <span className=\"flex gap-3 text-[9px] font-medium text-white/85 md:text-[11px]\">\n                {site.nav.map((n) => (\n                  <span key={n}>{n}</span>\n                ))}\n              </span>\n            </div>\n            <h2 className={`absolute left-[6%] top-[21%] w-[56%] font-extrabold leading-[0.93] tracking-[-0.045em] ${longHead ? \"text-[22px] md:text-[30px]\" : \"text-[34px] md:text-[54px]\"}`} style={{ color: INK, transform: \"translateZ(38px)\", textShadow: \"10px 16px 14px rgba(11,13,18,0.16)\" }}>\n              {headLines.map((l) => (\n                <span key={l} className=\"block\">\n                  {l}\n                </span>\n              ))}\n            </h2>\n            <p className=\"absolute left-[6%] top-[62%] w-[46%] text-[9px] font-medium leading-snug text-slate-600 md:text-[12px]\">{site.sub}</p>\n            <div className=\"absolute right-[4.5%] top-[20%] h-[72%] w-[33%] overflow-hidden rounded-[10px]\" style={{ backgroundColor: photo ? photo.tone : \"#7d8087\", transform: \"translateZ(56px)\", boxShadow: \"18px 30px 34px -12px rgba(11,13,18,0.5), inset 0 0 0 1px rgba(255,255,255,0.12)\" }}>\n              {photo ? <img src={photo.src} alt={photo.alt} width={628} height={1024} className=\"h-full w-full object-cover grayscale\" /> : <div className=\"h-full w-full\" style={{ background: \"radial-gradient(60% 40% at 64% 32%, #fff 0%, rgba(255,255,255,0.2) 45%, rgba(255,255,255,0) 100%), linear-gradient(160deg, #d9dade 0%, #7d8087 55%, #1d1e22 100%)\" }} />}\n            </div>\n            <div className=\"sentence-of-light-standing-page-glow absolute left-[6%] top-[79.5%] flex h-[10.5%] w-[28%] items-center justify-center gap-1.5 rounded-full text-[9px] font-bold text-white md:text-[13px]\" style={{ backgroundColor: BLUE, transform: \"translateZ(84px)\", boxShadow: \"0 0 0 1px rgba(255,255,255,0.25) inset, 0 0 26px 2px rgba(79,152,251,0.85), 0 0 90px 18px rgba(79,152,251,0.45), 16px 26px 30px -10px rgba(11,13,18,0.5)\" }}>\n              {site.cta}\n              <ArrowIcon />\n            </div>\n            <div className=\"absolute inset-x-[6%] bottom-[4%] flex justify-between border-t border-slate-900/15 pt-[1.5%] text-[7px] font-semibold uppercase tracking-[0.14em] text-slate-500 md:text-[8px]\">\n              <span>{site.foot}</span>\n              <span>{site.brand}</span>\n            </div>\n          </div>\n        </div>\n        <p aria-hidden=\"true\" className=\"absolute inset-x-6 top-[74%] mx-auto max-w-[620px] text-center text-[19px] font-semibold leading-tight tracking-tight md:left-[8%] md:right-auto md:top-[72%] md:text-left md:text-[30px]\" style={{ color: \"#dbe9ff\", textShadow: \"0 0 18px rgba(79,152,251,0.95), 0 0 60px rgba(79,152,251,0.7)\", transform: \"perspective(900px) rotateX(58deg)\", transformOrigin: \"50% 0\" }}>\n          {value}\n        </p>\n      </div>\n\n      <canvas ref={canvasRef} aria-hidden=\"true\" className={`absolute inset-0 h-full w-full transition-opacity duration-700 ${live ? \"opacity-100\" : \"opacity-0\"}`} />\n\n      <p className=\"pointer-events-none absolute left-5 top-5 text-[10px] font-semibold uppercase tracking-[0.22em] text-white/45 md:left-8 md:top-7 md:text-[11px]\">One sentence in, one page up</p>\n\n      <form onSubmit={submit} className=\"absolute inset-x-4 bottom-5 mx-auto flex max-w-[620px] items-center gap-2 rounded-full border border-white/10 bg-white/[0.06] p-1.5 pl-5 backdrop-blur-xl focus-within:border-[#4F98FB]/70 md:bottom-7\" style={{ boxShadow: \"0 18px 50px -18px rgba(0,0,0,0.9), inset 0 1px 0 rgba(255,255,255,0.08)\" }}>\n        <label htmlFor=\"sentence-of-light-standing-page-input\" className=\"sr-only\">\n          Describe a business in one sentence\n        </label>\n        <input\n          id=\"sentence-of-light-standing-page-input\"\n          ref={inputRef}\n          type=\"text\"\n          value={value}\n          maxLength={MAX_CHARS}\n          autoComplete=\"off\"\n          spellCheck={false}\n          placeholder=\"Describe a business in one sentence\"\n          onChange={(e) => {\n            setValue(e.target.value);\n            api.current?.type(e.target.value);\n          }}\n          onFocus={(e) => {\n            api.current?.focus(true);\n            e.target.select();\n          }}\n          onBlur={() => api.current?.focus(false)}\n          className=\"h-11 min-w-0 flex-1 bg-transparent text-[15px] font-medium tracking-tight text-white caret-[#4F98FB] outline-none placeholder:text-white/40 md:text-[17px]\"\n        />\n        <button type=\"submit\" aria-label=\"Stand the page up from this sentence\" className=\"flex h-11 w-11 shrink-0 items-center justify-center rounded-full text-white transition-transform duration-200 hover:scale-105 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-offset-2 focus-visible:ring-offset-[#0B0D12] active:scale-95 motion-reduce:transition-none md:w-auto md:gap-2 md:px-5\" style={{ backgroundColor: BLUE, boxShadow: \"0 0 24px -2px rgba(79,152,251,0.8), inset 0 1px 0 rgba(255,255,255,0.35)\" }}>\n          <span className=\"hidden text-[15px] font-bold tracking-tight md:inline\">Build</span>\n          <ArrowIcon />\n        </button>\n      </form>\n      <p className=\"sr-only\" aria-live=\"polite\">\n        Page shown: {site.brand}. {site.headline.replace(\"\\n\", \" \")}\n      </p>\n    </section>\n  );\n}\n"}]}
