{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ray-marched-brass-hotel-key-sign-in-form-where-the-key-swings-toward-a-lock-case-on-green-leather-as-you-type-and-throws-the-bolt-on-submit","type":"registry:block","title":"Ray-Marched Brass Hotel Key Sign-In Form Where the Key Swings Toward a Lock Case on Green Leather as You Type and Throws the Bolt on Submit","description":"Free React sign-in form beside a WebGL brass key on green leather. Fill it in and the key swings to the lock; sign in and it turns and throws the bolt.","dependencies":[],"files":[{"path":"components/we-inc/ray-marched-brass-hotel-key-sign-in-form-where-the-key-swings-toward-a-lock-case-on-green-leather-as-you-type-and-throws-the-bolt-on-submit.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// Everything a visitor reads, in one place.\nconst copy = {\n  house: \"Calloway House\",\n  room: \"Guest ledger\",\n  head: [\"Your room\", \"is waiting.\"],\n  done: [\"The door\", \"is open.\"],\n  lede: \"Sign in with the address you booked under. The key on the desk follows along.\",\n  ledeDone: \"Welcome in. Press the button once more to lock up and watch it again.\",\n  email: \"Email address\",\n  password: \"Password\",\n  button: \"Turn the key\",\n  again: \"Lock it again\",\n  forgot: \"Forgotten your password?\",\n  badEmail: \"Enter the address you booked with, for example ada@calloway.example.\",\n  badPassword: \"Your password is at least 8 characters long.\",\n  ok: \"Signed in. This is a demo, so nothing left the page.\",\n};\nconst ROOM = \"214\"; // engraved on the fob\nconst DEMO_EMAIL = \"ada@calloway.example\";\nconst DEMO_PASSWORD = \"brassbound\";\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\nconst VERT = `ATTR vec2 aPos; void main(){ gl_Position = vec4(aPos, 0.0, 1.0); }`;\nconst TONE = `vec3 tone(vec3 x){ x *= 0.82; vec3 a = x * (2.51 * x + 0.03); vec3 b = x * (2.43 * x + 0.59) + 0.14; return pow(clamp(a / b, 0.0, 1.0), vec3(1.0 / 2.2)); }`;\n\n// The photograph: a brass box lock and a hotel key on a green leather desk top, with low sun\n// coming through a window to the left and laying the shadow of its glazing bars across the leather.\nconst SCENE = `\nprecision highp float;\nuniform vec2 uRes; uniform vec2 uJit; uniform float uSeed; uniform float uAper;\nuniform vec3 uCam; uniform vec3 uTgt; uniform float uFoc; uniform float uFocus;\nuniform vec4 uKey; uniform float uRoll; uniform vec4 uFob; uniform vec4 uRing; uniform float uBolt; uniform float uDirect; uniform float uGlow; uniform sampler2D uNum;\nconst vec3 LC = vec3(0.86, 0.4, 0.3); const vec3 LH = vec3(0.34, 0.4, 0.66);\nconst vec3 HOLE = vec3(0.52, 0.48, 0.3);\nconst vec3 SUN = vec3(-0.70, 0.52, 0.49);\nconst vec3 SUNC = vec3(3.1, 2.45, 1.75);\nconst vec3 BRASS = vec3(0.98, 0.74, 0.40);\nconst vec3 LEATHER = vec3(0.036, 0.088, 0.052);\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 box(vec3 p, vec3 b, float r){ vec3 q = abs(p) - b + r; return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0) - r; }\nfloat cylX(vec3 p, float r, float a, float b){ vec2 d = vec2(length(p.yz) - r, max(a - p.x, p.x - b)); return min(max(d.x, d.y), 0.0) + length(max(d, 0.0)); }\nfloat smin(float a, float b, float k){ float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0); return mix(b, a, h) - k * h * (1.0 - h); }\n\n// ---- the key, in its own frame: shaft along x, tip at 0, bit hanging down at roll 0 ----\nvec3 toKey(vec3 p){\n  vec3 d = p - uKey.xyz; float c = cos(uKey.w); float s = sin(uKey.w);\n  vec3 q = vec3(c * d.x + s * d.z, d.y, -s * d.x + c * d.z);\n  float cr = cos(uRoll); float sr = sin(uRoll);\n  return vec3(q.x, cr * q.y + sr * q.z, -sr * q.y + cr * q.z);\n}\nfloat sdKey(vec3 q){\n  float d = cylX(q, 0.04, -1.08, -0.02) - 0.004;\n  // turned collars where the shaft meets the bow, like a lathe left them\n  float col = cylX(q, 0.066, -1.1, -1.03) - 0.006;\n  col = min(col, cylX(q, 0.055, -0.98, -0.95) - 0.005);\n  col = min(col, cylX(q, 0.05, -0.36, -0.33) - 0.004);\n  d = min(d, col);\n  // the tip is a little drum\n  d = min(d, cylX(q, 0.05, -0.04, 0.0) - 0.004);\n  // the bit, with two wards cut out of it\n  vec3 b = q - vec3(-0.15, -0.13, 0.0);\n  float bit = box(b, vec3(0.1, 0.1, 0.026), 0.008);\n  bit = max(bit, -box(b - vec3(-0.035, -0.06, 0.0), vec3(0.016, 0.06, 0.05), 0.0));\n  bit = max(bit, -box(b - vec3(0.05, -0.1, 0.0), vec3(0.016, 0.035, 0.05), 0.0));\n  d = min(d, bit);\n  // the bow: an oval ring with a pierced trefoil inside, flat in the plane of the bit\n  vec2 e = (q.xy - vec2(-1.36, 0.0)) / vec2(0.28, 0.23);\n  float ring = (length(e) - 1.0) * 0.23;\n  float bow2 = abs(ring + 0.035) - 0.035;\n  vec2 t = q.xy - vec2(-1.36, 0.0);\n  float a = atan(t.y, t.x); float r3 = 0.105 + 0.03 * cos(3.0 * a);\n  bow2 = min(bow2, abs(length(t) - r3) - 0.016);\n  bow2 = min(bow2, max(abs(t.y) - 0.02, abs(t.x + 0.0) - 0.2));\n  vec2 w = vec2(bow2, abs(q.z) - 0.026);\n  float bow = min(max(w.x, w.y), 0.0) + length(max(w, 0.0)) - 0.007;\n  return smin(d, bow, 0.03);\n}\n// ---- the fob, in its own frame: hole at the origin, body along +x ----\nvec3 toFob(vec3 p){\n  vec3 d = p - uFob.xyz; float c = cos(uFob.w); float s = sin(uFob.w);\n  vec3 q = vec3(c * d.x + s * d.z, d.y, -s * d.x + c * d.z);\n  float cp = cos(uRing.w); float sp = sin(uRing.w);\n  return vec3(cp * q.x + sp * q.y, -sp * q.x + cp * q.y, q.z);\n}\nfloat sdFob(vec3 q){\n  // a long oval of ivory celluloid, thickest down its middle\n  vec2 c = vec2(clamp(q.x, 0.1, 0.62), 0.0);\n  float r = length(q.xz - c) - 0.19;\n  float th = 0.034 - 0.012 * smoothstep(-0.19, 0.0, r);\n  vec2 w = vec2(r + 0.02, abs(q.y) - th);\n  float d = min(max(w.x, w.y), 0.0) + length(max(w, 0.0)) - 0.02;\n  return max(d, -(length(q.xz - vec2(0.08, 0.0)) - 0.045));\n}\nfloat sdGrommet(vec3 q){ vec2 t = vec2(length(q.xz - vec2(0.08, 0.0)) - 0.058, q.y); return length(t) - 0.03; }\nfloat sdRing(vec3 p){\n  vec3 d = p - uRing.xyz; float c = cos(uFob.w); float s = sin(uFob.w);\n  vec3 q = vec3(c * d.x + s * d.z, d.y, -s * d.x + c * d.z);\n  vec2 t = vec2(length(q.xy) - 0.11, q.z);\n  return length(t) - 0.012;\n}\n// ---- the lock: a brass case with a keyhole in its side and a bolt in its face ----\nvec2 keyhole(vec2 yz){\n  float circ = length(yz - vec2(0.03, 0.0)) - 0.055;\n  vec2 s = yz - vec2(-0.07, 0.0);\n  float slot = max(abs(s.y) - (0.026 + 0.12 * max(-s.x, 0.0) * 0.18), abs(s.x) - 0.1);\n  return vec2(min(circ, slot), 0.0);\n}\n// x: distance, y: 1 where the surface is brass, 0 on the black japanned case\nvec2 sdLock(vec3 p){\n  vec3 q = p - LC;\n  float body = box(q, LH, 0.045);\n  // the keyhole runs into the case, the bolt slot opens in its face\n  vec3 e = p - HOLE;\n  float kh = keyhole(e.yz).x;\n  body = max(body, -max(kh, -e.x - 0.06));\n  vec3 bq = p - vec3(LC.x, LC.y - 0.08, LC.z - LH.z);\n  body = max(body, -box(bq, vec3(0.085, 0.1, 0.03), 0.004));\n  // brass: a cover plate standing proud of the top with four screws, the escutcheon, the bolt\n  float plate = box(q - vec3(0.0, LH.y, 0.0), vec3(LH.x - 0.06, 0.012, LH.z - 0.06), 0.012);\n  vec2 sxz = abs(q.xz) - vec2(LH.x - 0.12, LH.z - 0.12);\n  float screw = length(vec3(sxz.x, max(q.y - LH.y - 0.012, 0.0), sxz.y)) - 0.034;\n  screw = max(screw, -(abs(q.y - LH.y - 0.04) - 0.03));\n  screw = max(screw, -box(vec3(sxz.x + sxz.y, q.y - LH.y - 0.04, sxz.x - sxz.y), vec3(0.004, 0.012, 0.05), 0.0));\n  float esc = box(vec3(e.x + 0.012, 0.0, 0.0), vec3(0.016, 1.0, 1.0), 0.0);\n  esc = max(esc, length((e.yz - vec2(-0.02, 0.0)) / vec2(1.35, 1.0)) - 0.13) - 0.004;\n  esc = max(esc, -max(kh, -e.x - 0.06));\n  float bolt = box(bq - vec3(0.0, 0.0, 0.2 - uBolt), vec3(0.07, 0.085, 0.24), 0.03);\n  float brass = min(min(plate, screw), min(esc, bolt));\n  return brass < body ? vec2(brass, 1.0) : vec2(body, 0.0);\n}\nfloat map(vec3 p, out float id){\n  float d = p.y; id = 0.0;\n  float k = sdKey(toKey(p)); if (k < d) { d = k; id = 1.0; }\n  vec2 l = sdLock(p); if (l.x < d) { d = l.x; id = l.y > 0.5 ? 4.0 : 2.0; }\n  vec3 f = toFob(p);\n  float fb = sdFob(f); if (fb < d) { d = fb; id = 3.0; }\n  float g = min(sdGrommet(f), sdRing(p)); if (g < d) { d = g; id = 1.0; }\n  return d;\n}\nfloat mapD(vec3 p){ float i; return map(p, i); }\nvec3 nrm(vec3 p){\n  vec2 e = vec2(0.0012, -0.0012);\n  return normalize(e.xyy * mapD(p + e.xyy) + e.yyx * mapD(p + e.yyx) + e.yxy * mapD(p + e.yxy) + e.xxx * mapD(p + e.xxx));\n}\nfloat shadow(vec3 ro, vec3 rd){\n  float res = 1.0; float t = 0.01;\n  for (int i = 0; i < 40; i++) {\n    float h = mapD(ro + rd * t); if (ro.y + rd.y * t > 1.4) break;\n    res = min(res, 9.0 * h / t); t += clamp(h, 0.012, 0.18);\n    if (res < 0.002 || t > 5.0) break;\n  }\n  return clamp(res, 0.0, 1.0);\n}\nfloat ao(vec3 p, vec3 n){\n  float o = 0.0; float w = 1.0;\n  for (int i = 1; i <= 5; i++) { float h = 0.02 + 0.05 * float(i); o += (h - mapD(p + n * h)) * w; w *= 0.7; }\n  return clamp(1.0 - 2.2 * o, 0.0, 1.0);\n}\n// sunlight only arrives through the panes of the window to the left\nfloat pane(vec3 p){\n  float t = (-5.0 - p.x) / SUN.x; vec3 w = p + SUN * t;\n  float s = 0.02 + 0.012 * t;\n  float m = smoothstep(-2.6 - s, -2.6 + s, w.z) * smoothstep(3.4 + s, 3.4 - s, w.z) * smoothstep(0.9 - s, 0.9 + s, w.y) * smoothstep(6.0 + s, 6.0 - s, w.y);\n  float bz = abs(fract((w.z + 2.6) / 2.0) - 0.5) * 2.0; float by = abs(fract((w.y - 0.9) / 1.7) - 0.5) * 1.7;\n  m *= smoothstep(0.04, 0.04 + s * 1.8, bz) * smoothstep(0.035, 0.035 + s * 1.8, by);\n  return m;\n}\n// the room as brass sees it: a dark panelled study, the bright window to the left, green leather below\nvec3 room(vec3 ro, vec3 rd, float rough){\n  vec3 c = mix(vec3(0.16, 0.11, 0.07), vec3(0.07, 0.05, 0.035), smoothstep(0.1, 0.9, rd.y));\n  // dark panelling at eye level, a few vertical boards catching the light\n  c *= 0.75 + 0.25 * smoothstep(0.3, 0.5, abs(fract(atan(rd.z, rd.x) * 2.2) - 0.5) * 2.0);\n  if (rd.x < -0.05) {\n    vec3 w = rd * (5.0 / -rd.x);\n    float s = 0.08 + rough * 3.0;\n    float m = smoothstep(-2.4 - s, -2.4 + s, w.z) * smoothstep(3.0 + s, 3.0 - s, w.z) * smoothstep(0.7 - s, 0.7 + s, w.y) * smoothstep(6.5 + s, 6.5 - s, w.y);\n    float bz = abs(fract((w.z + 2.4) / 1.8) - 0.5) * 1.8; float by = abs(fract((w.y - 0.7) / 1.9) - 0.5) * 1.9;\n    m *= mix(1.0, smoothstep(0.06, 0.06 + s, bz) * smoothstep(0.06, 0.06 + s, by), 1.0 - smoothstep(0.1, 0.5, rough));\n    c = mix(c, vec3(3.6, 3.1, 2.5) * mix(1.0, 0.75, smoothstep(0.0, 0.8, w.y / 6.0)), m);\n  }\n  // a big sheet of warm card held up behind the camera, the photographer's fill\n  float card = dot(rd, normalize(vec3(0.35, 0.5, -0.8)));\n  c += vec3(1.25, 1.0, 0.75) * smoothstep(0.72 - rough * 0.4, 0.86, card);\n  // a pale lampshade away to the right\n  float lamp = smoothstep(0.993 - rough * 0.1, 0.998 - rough * 0.04, dot(rd, normalize(vec3(0.75, 0.5, 0.9))));\n  c += vec3(2.4, 1.7, 1.0) * lamp;\n  // below the horizon: the desk itself, with the sun patches on it\n  if (rd.y < -0.001) {\n    vec3 q = ro + rd * (-ro.y / rd.y);\n    vec3 desk = LEATHER * (SUNC * 0.55 * pane(q) * mix(1.0, 0.6, rough) + vec3(0.3, 0.26, 0.2));\n    c = mix(c, desk, smoothstep(0.0, -0.06, rd.y));\n  }\n  return c;\n}\nvec3 ggx(vec3 n, vec3 v, vec3 l, float a, vec3 f0){\n  vec3 h = normalize(l + v); float nh = max(dot(n, h), 0.0); float a2 = a * a * a * a;\n  float dd = nh * nh * (a2 - 1.0) + 1.0; float D = a2 / (3.14159 * dd * dd);\n  vec3 F = f0 + (1.0 - f0) * pow(1.0 - max(dot(h, v), 0.0), 5.0);\n  return D * F * 0.25 * max(dot(n, l), 0.0);\n}\nvec3 shadeBrass(vec3 p, vec3 n, vec3 v, float id, float o){\n  // polished where fingers rub it, duller and darker in the corners where polish never reaches\n  float wear = n2(p.xz * 5.0 + p.y * 4.0) * 0.7 + n2(p.xz * 23.0) * 0.3;\n  float rough = mix(0.14, 0.34, wear) + (1.0 - o) * 0.25;\n  if (id > 3.5) {\n    rough = 0.3 + 0.04 * n2(vec2(p.z * 2.0, p.x * 60.0)) + 0.04 * n2(p.xz * 6.0);\n    // an engraved double rule round the top plate\n    vec2 tq = abs(p.xz - LC.xz) - vec2(LH.x - 0.1, LH.z - 0.1);\n    float tr = abs(max(tq.x, tq.y));\n    float cut = (smoothstep(0.006, 0.0, abs(tr - 0.0)) + smoothstep(0.004, 0.0, abs(tr - 0.022))) * step(LC.y + LH.y, p.y);\n    o *= 1.0 - 0.8 * clamp(cut, 0.0, 1.0); rough += cut * 0.4;\n  }\n  vec3 tint = mix(BRASS, BRASS * vec3(0.6, 0.47, 0.32), (1.0 - o) * 0.7 + 0.08 * wear);\n  vec3 r = reflect(-v, n);\n  float fr = pow(1.0 - max(dot(n, v), 0.0), 5.0);\n  vec3 F = tint + (1.0 - tint) * fr;\n  vec3 col = room(p, r, rough) * F * mix(0.35, 1.0, o);\n  float sh = shadow(p + n * 0.004, SUN) * pane(p);\n  col += SUNC * sh * ggx(n, v, SUN, rough, tint) * 1.0;\n  // a little light bounced up off the leather into the underside\n  col += tint * LEATHER * SUNC * 0.5 * clamp(-n.y, 0.0, 1.0) * o;\n  // the top plate is an older, darker brass than the key\n  col *= mix(vec3(1.0), vec3(0.78, 0.64, 0.44), step(3.5, id) * step(LC.y + LH.y - 0.01, p.y));\n  return col;\n}\n// black japanned iron: a deep gloss coat over near-black, so it is mostly what it reflects\nvec3 shadeJapan(vec3 p, vec3 n, vec3 v, float o){\n  vec3 nb = normalize(n + 0.012 * vec3(n2(p.yz * 31.0) - 0.5, n2(p.xz * 31.0) - 0.5, n2(p.xy * 31.0) - 0.5));\n  float sh = shadow(p + n * 0.004, SUN) * pane(p);\n  vec3 col = vec3(0.016, 0.012, 0.009) * (SUNC * sh * max(dot(nb, SUN), 0.0) + vec3(0.3) * o);\n  float fr = 0.045 + 0.955 * pow(1.0 - max(dot(nb, v), 0.0), 5.0);\n  col += room(p, reflect(-v, nb), 0.1) * fr * mix(0.3, 1.0, o);\n  col += SUNC * sh * ggx(nb, v, SUN, 0.1, vec3(0.045));\n  // a faint warm sheen where the brass plate lights the case under its lip\n  col += vec3(0.25, 0.16, 0.06) * 0.15 * smoothstep(-0.25, 0.0, p.y - LC.y - LH.y) * o;\n  return col;\n}\nvec3 shadeFob(vec3 p, vec3 n, vec3 v, float o){\n  vec3 q = toFob(p);\n  vec3 alb = vec3(0.86, 0.79, 0.64) * (0.95 + 0.08 * n2(p.xz * 30.0));\n  // the room number, cut into the celluloid and filled with oxblood\n  vec2 nu = vec2((q.x - 0.2) / 0.56, 1.0 - (q.z + 0.14) / 0.28);\n  float ink = 0.0;\n  if (nu.x > 0.0 && nu.x < 1.0 && nu.y > 0.0 && nu.y < 1.0 && q.y > 0.0) ink = texture2D(uNum, nu).r;\n  alb = mix(alb, vec3(0.3, 0.035, 0.03), ink);\n  float sh = shadow(p + n * 0.004, SUN) * pane(p);\n  float ndl = dot(n, SUN); float wrap = clamp((ndl + 0.3) / 1.3, 0.0, 1.0);\n  vec3 col = alb * (SUNC * sh * wrap * 0.9 + vec3(0.25, 0.22, 0.18) * o) + vec3(0.9, 0.5, 0.25) * SUNC * 0.05 * sh * (1.0 - max(ndl, 0.0));\n  float fr = 0.04 + 0.96 * pow(1.0 - max(dot(n, v), 0.0), 5.0);\n  col = mix(col, room(p, reflect(-v, n), 0.08) * o, fr);\n  col += SUNC * sh * ggx(n, v, SUN, 0.12, vec3(0.04));\n  return col;\n}\nvec3 shadeLeather(vec3 p, vec3 v, float blur){\n  // pebbled grain, a scuff or two, and a gilt double rule tooled round the edge of the panel\n  vec2 g = p.xz * 34.0;\n  float k = 1.0 - smoothstep(0.0, 0.05, blur);\n  vec2 gr = vec2(n2(g) - n2(g + vec2(0.4, 0.0)), n2(g) - n2(g + vec2(0.0, 0.4))) * 0.9;\n  gr += vec2(n2(p.xz * 3.0) - 0.5, n2(p.xz * 3.0 + 9.0) - 0.5) * 0.1;\n  vec3 n = normalize(vec3(gr.x * 0.07 * k, 1.0, gr.y * 0.07 * k));\n  float tone = 0.82 + 0.3 * n2(p.xz * 1.3 + 4.0) + 0.06 * n2(g * 0.25);\n  vec3 alb = LEATHER * tone;\n  vec2 rq = abs(p.xz - vec2(0.3, 0.6)) - vec2(2.35, 1.55);\n  float edge = abs(max(rq.x, rq.y));\n  float rule = smoothstep(0.012 + blur, 0.0, abs(edge - 0.0)) + smoothstep(0.007 + blur, 0.0, abs(edge - 0.06));\n  float gilt = clamp(rule, 0.0, 1.0) * (0.75 + 0.25 * n2(p.xz * 60.0));\n  float sh = shadow(p + vec3(0.0, 0.002, 0.0), SUN);\n  float lit = pane(p) * sh;\n  float o = ao(p, vec3(0.0, 1.0, 0.0));\n  vec3 col = alb * (SUNC * lit * max(dot(n, SUN), 0.0) + vec3(0.36, 0.28, 0.19) * o);\n  // sun scattered back up off the bright patches warms the leather around them\n  col += alb * vec3(0.5, 0.42, 0.25) * 0.35 * smoothstep(1.5, -0.5, p.z) * o;\n  // the brass throws warm light down onto the leather beside it\n  col += alb * vec3(1.2, 0.8, 0.35) * 0.35 * (1.0 - o) * smoothstep(1.2, 0.0, length(p.xz - LC.xz));\n  float fr = 0.04 + 0.96 * pow(1.0 - max(dot(n, v), 0.0), 5.0);\n  col += room(p, reflect(-v, n), 0.85) * fr * 0.12 * o;\n  col += SUNC * lit * ggx(n, v, SUN, 0.42, vec3(0.04)) * 0.9;\n  vec3 gc = vec3(1.0, 0.76, 0.38);\n  vec3 gcol = gc * (SUNC * lit * 0.35 + vec3(0.12, 0.1, 0.07)) + SUNC * lit * ggx(vec3(0.0, 1.0, 0.0), v, SUN, 0.25, gc) * 0.6;\n  col = mix(col, gcol, gilt * 0.85);\n  // the far end of the desk falls away into the dim room\n  return col * mix(1.0, 0.55, smoothstep(0.8, 3.5, p.z));\n}\nvoid main(){\n  vec2 fc = gl_FragCoord.xy + uJit;\n  vec2 uv = (fc - 0.5 * uRes) / uRes.y;\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  // a thin lens: every sample looks through a different spot of the aperture at the same focal plane\n  float ign = fract(52.9829189 * fract(dot(gl_FragCoord.xy, vec2(0.06711056, 0.00583715))) + uSeed);\n  float ang = ign * 6.2831853 + uSeed * 17.0; float rr = sqrt(fract(ign * 7.13 + uSeed * 3.7));\n  vec2 lens = vec2(cos(ang), sin(ang)) * rr * uAper * step(0.001, uSeed);\n  vec3 fp = ro + rd * (uFocus / dot(rd, fw));\n  ro += rt * lens.x + up * lens.y;\n  rd = normalize(fp - ro);\n  vec3 col;\n  float t = 0.0; float id = -1.0; bool hit = false;\n  float tmax = rd.y < 0.0 ? -ro.y / rd.y + 0.01 : 30.0;\n  for (int i = 0; i < 150; i++) {\n    vec3 p = ro + rd * t;\n    float d = map(p, id);\n    if (d < 0.0006 * t) { hit = true; break; }\n    t += d * 0.9;\n    if (t > tmax) break;\n  }\n  if (!hit) { t = tmax; id = 0.0; }\n  vec3 p = ro + rd * t;\n  vec3 v = -rd;\n  float blur = abs(t * dot(rd, fw) - uFocus) * 0.004;\n  if (id < 0.5 || p.y < 0.0015) col = shadeLeather(vec3(p.x, 0.0, p.z), v, blur);\n  else {\n    vec3 n = nrm(p); float o = ao(p, n);\n    if (id > 3.5) col = shadeBrass(p, n, v, id, o);\n    else if (id > 2.5) col = shadeFob(p, n, v, o);\n    else if (id > 1.5) col = shadeJapan(p, n, v, o);\n    else col = shadeBrass(p, n, v, id, o);\n  }\n  // a warm haze in the shaft of sun\n  col += vec3(0.05, 0.035, 0.02) * uGlow * smoothstep(0.4, -0.6, (gl_FragCoord.x / uRes.x - 0.2));\n  col = min(col, vec3(30.0));\n  if (uDirect > 0.5) col = tone(col);\n  outC = vec4(col, 1.0);\n}\n`;\n\nconst POST = `\nprecision highp float;\nuniform sampler2D uAcc; uniform vec2 uRes; uniform float uGrain;\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 = texture2D(uAcc, uv).rgb;\n  vec3 b = vec3(0.0);\n  for (int i = 0; i < 16; i++) {\n    float a = float(i) * 2.39996; float r = sqrt((float(i) + 0.5) / 16.0);\n    vec3 s = texture2D(uAcc, uv + vec2(cos(a), sin(a)) * r * 0.02 * vec2(uRes.y / uRes.x, 1.0)).rgb;\n    b += min(max(s - 1.4, 0.0), vec3(8.0)) * (1.0 - 0.6 * r);\n  }\n  c += b * 0.016;\n  vec2 q = (uv - vec2(0.5, 0.52)) * vec2(uRes.x / uRes.y, 1.0);\n  c *= 1.0 - 0.38 * smoothstep(0.35, 1.2, length(q));\n  c = tone(c);\n  c += (h21(gl_FragCoord.xy + uGrain * 91.7) - 0.5) * 0.02;\n  outC = vec4(c, 1.0);\n}\n`;\n\n// Where the key lies for a given amount of the form filled in, and where it goes when signing in.\ntype Pose = { x: number; y: number; z: number; yaw: number; roll: number };\nconst REST: Pose = { x: 0.3, y: 0.044, z: -0.85, yaw: -0.5, roll: Math.PI / 2 };\nconst NEAR: Pose = { x: 0.08, y: 0.044, z: 0.06, yaw: 0.45, roll: Math.PI / 2 };\nconst READY: Pose = { x: 0.3, y: 0.48, z: 0.3, yaw: 0, roll: 0 };\nconst IN: Pose = { x: 0.84, y: 0.48, z: 0.3, yaw: 0, roll: 0 };\nconst mixPose = (a: Pose, b: Pose, t: number): Pose => ({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t, z: a.z + (b.z - a.z) * t, yaw: a.yaw + (b.yaw - a.yaw) * t, roll: a.roll + (b.roll - a.roll) * t });\nconst ease = (t: number) => (t <= 0 ? 0 : t >= 1 ? 1 : t * t * (3 - 2 * t));\n\n// No WebGL: the same desk drawn in SVG from the same viewpoint, lit from the same window.\nfunction Still({ open }: { open: boolean }) {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 740 760\" preserveAspectRatio=\"xMidYMid slice\" className=\"absolute inset-0 h-full w-full\">\n      <defs>\n        <linearGradient id=\"bk-desk\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stopColor=\"#2c2e1c\" /><stop offset=\"0.45\" stopColor=\"#1b3322\" /><stop offset=\"1\" stopColor=\"#1d3f29\" /></linearGradient>\n        <linearGradient id=\"bk-sun\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\"><stop offset=\"0\" stopColor=\"#5f9a60\" stopOpacity=\"0.95\" /><stop offset=\"1\" stopColor=\"#4d8a55\" stopOpacity=\"0.75\" /></linearGradient>\n        <linearGradient id=\"bk-brass\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stopColor=\"#fbe7ad\" /><stop offset=\"0.45\" stopColor=\"#d9ad5c\" /><stop offset=\"1\" stopColor=\"#8a5f23\" /></linearGradient>\n        <linearGradient id=\"bk-rod\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stopColor=\"#fff0c0\" /><stop offset=\"0.5\" stopColor=\"#c99a48\" /><stop offset=\"1\" stopColor=\"#5e3f15\" /></linearGradient>\n        <linearGradient id=\"bk-case\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\"><stop offset=\"0\" stopColor=\"#1a120c\" /><stop offset=\"0.6\" stopColor=\"#2a1c12\" /><stop offset=\"1\" stopColor=\"#120c08\" /></linearGradient>\n        <linearGradient id=\"bk-fob\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stopColor=\"#fbf4e6\" /><stop offset=\"1\" stopColor=\"#cfc0a2\" /></linearGradient>\n        <filter id=\"bk-soft\" x=\"-30%\" y=\"-30%\" width=\"160%\" height=\"160%\"><feGaussianBlur stdDeviation=\"9\" /></filter>\n        <radialGradient id=\"bk-vig\" cx=\"0.5\" cy=\"0.5\" r=\"0.75\"><stop offset=\"0.55\" stopColor=\"#000\" stopOpacity=\"0\" /><stop offset=\"1\" stopColor=\"#000\" stopOpacity=\"0.45\" /></radialGradient>\n      </defs>\n      <rect width=\"740\" height=\"760\" fill=\"url(#bk-desk)\" />\n      {/* sun through the window, with the shadows of its bars */}\n      <style>{`@keyframes bk-cloud { 0%, 100% { opacity: 1; } 50% { opacity: 0.72; } } .bk-cloud { animation: bk-cloud 7s ease-in-out infinite; } @media (prefers-reduced-motion: reduce) { .bk-cloud { animation: none; } }`}</style>\n      <path className=\"bk-cloud\" d=\"M0 345 L740 300 L740 760 L0 760 Z\" fill=\"url(#bk-sun)\" />\n      <path d=\"M0 440 L740 470 L740 520 L0 478 Z M380 300 L470 300 L620 760 L520 760 Z\" fill=\"#163222\" opacity=\"0.85\" />\n      <path d=\"M0 400 L560 140 L740 230 M0 420 L560 155 L740 245 M30 640 L740 420 M40 652 L740 432\" stroke=\"#d6b064\" strokeWidth=\"2\" fill=\"none\" opacity=\"0.7\" />\n      {/* the lock case */}\n      <ellipse cx=\"560\" cy=\"400\" rx=\"130\" ry=\"26\" fill=\"#000\" opacity=\"0.55\" filter=\"url(#bk-soft)\" />\n      <path d=\"M425 175 L520 150 L640 255 L640 340 L540 405 L425 330 Z\" fill=\"url(#bk-case)\" />\n      <path d=\"M425 175 L520 150 L640 255 L540 280 Z\" fill=\"url(#bk-brass)\" />\n      <path d=\"M440 180 L518 160 L622 252 L542 272 Z\" fill=\"none\" stroke=\"#7a5320\" strokeWidth=\"2\" opacity=\"0.6\" />\n      <path d=\"M540 280 L640 255 L640 340 L540 405 Z\" fill=\"#20160e\" />\n      <ellipse cx=\"465\" cy=\"275\" rx=\"13\" ry=\"22\" fill=\"url(#bk-brass)\" />\n      <ellipse cx=\"466\" cy=\"277\" rx=\"4\" ry=\"9\" fill=\"#0d0805\" />\n      <rect x=\"572\" y={open ? 336 : 326} width=\"26\" height=\"34\" rx=\"3\" fill=\"url(#bk-brass)\" style={{ transition: \"y 300ms\" }} />\n      {/* the key and its fob */}\n      <g transform={open ? \"translate(40 -120)\" : \"\"}>\n        <ellipse cx=\"370\" cy=\"470\" rx=\"160\" ry=\"16\" fill=\"#000\" opacity=\"0.4\" filter=\"url(#bk-soft)\" transform=\"rotate(-38 370 470)\" />\n        <path d=\"M300 495 L465 380\" stroke=\"url(#bk-rod)\" strokeWidth=\"11\" strokeLinecap=\"round\" />\n        <path d=\"M440 398 l26 -18 l10 14 l-8 6 l6 9 l-8 6 l-6 -9 l-12 8 Z\" fill=\"url(#bk-brass)\" />\n        <ellipse cx=\"275\" cy=\"512\" rx=\"44\" ry=\"38\" fill=\"none\" stroke=\"url(#bk-brass)\" strokeWidth=\"12\" transform=\"rotate(-35 275 512)\" />\n        <path d=\"M275 485 q22 18 0 40 q-22 -22 0 -40 M252 512 h46\" stroke=\"url(#bk-brass)\" strokeWidth=\"6\" fill=\"none\" />\n        <g transform=\"rotate(-62 205 600)\">\n          <rect x=\"140\" y=\"565\" width=\"150\" height=\"66\" rx=\"33\" fill=\"url(#bk-fob)\" />\n          <circle cx=\"270\" cy=\"598\" r=\"7\" fill=\"#1a2a1c\" />\n          <text x=\"200\" y=\"612\" textAnchor=\"middle\" fontSize=\"40\" fontFamily={SERIF} fill=\"#a2321f\" transform=\"rotate(180 200 598)\">{ROOM}</text>\n        </g>\n      </g>\n      <rect width=\"740\" height=\"760\" fill=\"url(#bk-vig)\" />\n    </svg>\n  );\n}\n\nexport default function BrassHotelKeySignInForm() {\n  const stage = useRef<HTMLDivElement>(null);\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const emailRef = useRef<HTMLInputElement>(null);\n  const passRef = useRef<HTMLInputElement>(null);\n  const [email, setEmail] = useState(DEMO_EMAIL);\n  const [password, setPassword] = useState(DEMO_PASSWORD);\n  const [errors, setErrors] = useState<{ email?: string; password?: string }>({});\n  const [done, setDone] = useState(false);\n  const [said, setSaid] = useState(false); // only a real sign-in is announced, never the demo\n  const [shown, setShown] = useState<\"wait\" | \"gl\" | \"still\">(\"wait\");\n  const api = useRef<{ fill: (p: number, user: boolean) => void; open: (user: boolean) => void; close: () => void; nudge: () => void; stop: () => void } | null>(null);\n\n  useEffect(() => {\n    const box = stage.current, cv = canvas.current;\n    if (!box || !cv) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const opts = { antialias: false, alpha: false, powerPreference: \"high-performance\" as const };\n    const gl2 = cv.getContext(\"webgl2\", opts) as WebGL2RenderingContext | null;\n    const gl = (gl2 ?? cv.getContext(\"webgl\", opts)) as WebGLRenderingContext | null;\n    if (!gl) { setShown(\"still\"); return; }\n    const canAcc = !!gl2 && (!!gl2.getExtension(\"EXT_color_buffer_float\") || !!gl2.getExtension(\"EXT_color_buffer_half_float\"));\n    const head = gl2 ? \"#version 300 es\\n#define ATTR in\\n\" : \"#define ATTR attribute\\n\";\n    const fhead = gl2 ? \"#version 300 es\\n#define texture2D texture\\nprecision highp float;\\nout vec4 outC;\\n\" : \"#define outC gl_FragColor\\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, head + VERT), f = compile(gl.FRAGMENT_SHADER, fhead + 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 U = (p: WebGLProgram, n: string) => gl.getUniformLocation(p, n);\n    const su = Object.fromEntries([\"uRes\", \"uJit\", \"uSeed\", \"uAper\", \"uCam\", \"uTgt\", \"uFoc\", \"uFocus\", \"uKey\", \"uRoll\", \"uFob\", \"uRing\", \"uBolt\", \"uDirect\", \"uGlow\", \"uNum\"].map((n) => [n, U(scene, n)]));\n    const pu = post ? Object.fromEntries([\"uAcc\", \"uRes\", \"uGrain\"].map((n) => [n, U(post, n)])) : {};\n    const quad = gl.createBuffer();\n    gl.bindBuffer(gl.ARRAY_BUFFER, quad);\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n    gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n\n    // the number on the fob, set in the serif and handed to the shader as a mask\n    const num = document.createElement(\"canvas\");\n    num.width = 256; num.height = 128;\n    const ng = num.getContext(\"2d\");\n    if (ng) {\n      ng.fillStyle = \"#000\"; ng.fillRect(0, 0, 256, 128);\n      ng.fillStyle = \"#fff\"; ng.textAlign = \"center\"; ng.textBaseline = \"middle\";\n      ng.font = `600 104px ${SERIF}`;\n      ng.fillText(ROOM, 128, 70);\n    }\n    gl.activeTexture(gl.TEXTURE3);\n    gl.bindTexture(gl.TEXTURE_2D, gl.createTexture());\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.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, num);\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 s = {\n      fill: 1, fillShown: 1, fillVel: 0, phase: \"rest\" as \"rest\" | \"lift\" | \"insert\" | \"turn\" | \"open\" | \"back\",\n      clock: 0, roll: 0, rollVel: 0, bolt: 0, boltVel: 0, pose: mixPose(REST, NEAR, 1),\n      fobYaw: 0, fobYawVel: 0, wobble: 0, wobbleVel: 0,\n      count: 0, fresh: true, frame: 0, drawn: \"rest\" as string, drawnFill: -1, thunk: 0, shake: 0, slow: 0, visible: true, raf: 0, last: 0, t0: 0, touched: false, demoAt: 0, px: 0, py: 0, sx: 0, sy: 0,\n    };\n    s.fobYaw = s.pose.yaw + 0.5;\n    const size = () => {\n      const r = box.getBoundingClientRect();\n      cssW = Math.max(1, r.width); cssH = Math.max(1, r.height);\n      const dpr = Math.min(1.5, window.devicePixelRatio || 1) * scale;\n      const k = Math.min(1, Math.sqrt(1.1e6 / (cssW * cssH * dpr * dpr)));\n      const w = Math.max(2, Math.round(cssW * dpr * k)), h = Math.max(2, Math.round(cssH * dpr * k));\n      if (w === W && h === H) return;\n      W = w; H = h; cv.width = W; cv.height = H;\n      if (gl2 && acc && fbo) {\n        gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, acc);\n        gl2.texImage2D(gl.TEXTURE_2D, 0, gl2.RGBA16F, W, H, 0, gl.RGBA, gl2.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 key's place in the world, and the fob and ring that trail behind it.\n    const rig = () => {\n      const p = s.pose;\n      const c = Math.cos(p.yaw), sn = Math.sin(p.yaw);\n      const bx = p.x - c * 1.62, bz = p.z - sn * 1.62;\n      const fy = s.fobYaw;\n      const fc = Math.cos(fy), fs = Math.sin(fy);\n      const hy = Math.max(0.06, p.y - 0.13);\n      const hx = bx - fc * 0.12, hz = bz - fs * 0.12;\n      const rx = (bx + hx) / 2, rz = (bz + hz) / 2, ry = (p.y + hy) / 2;\n      // the fob's far end rests on the leather, so it tips up when the key is lifted\n      const pitch = Math.asin(Math.min(0.95, Math.max(0, (hy - 0.06) / 0.7)));\n      return { fob: [hx + 0, hy, hz, Math.PI + fy] as const, ring: [rx, ry, rz, -pitch] as const };\n    };\n\n    const camera = () => {\n      const wide = cssW / cssH > 0.95;\n      const tgt = wide ? [-0.15, 0.12, 0.05] : [-0.2, 0.12, 0.0];\n      const el = 0.66 - s.sy * 0.03 + Math.sin(s.shake * 40) * s.shake * 0.004, az = -0.38 + s.sx * 0.06, dist = wide ? 7.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 fw = [tgt[0] - cam[0], tgt[1] - cam[1], 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      // focus on the middle of the key\n      const focus = (-0.25 - cam[0]) * fw[0] + (0.1 - cam[1]) * fw[1] + (-0.15 - cam[2]) * fw[2];\n      return { cam, tgt, foc: wide ? 1.75 : 1.6, focus };\n    };\n\n    const draw = (alpha: number, sample: number) => {\n      const c = camera(), r = rig();\n      const jx = sample ? halton(sample, 2) - 0.5 : 0, jy = sample ? halton(sample, 3) - 0.5 : 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.uniform2f(su.uJit, canAcc ? jx : 0, canAcc ? jy : 0);\n      gl.uniform1f(su.uSeed, canAcc && sample ? (sample * 0.61803) % 1 || 0.5 : 0);\n      gl.uniform1f(su.uAper, 0.045);\n      gl.uniform3f(su.uCam, c.cam[0], c.cam[1], c.cam[2]); gl.uniform3f(su.uTgt, c.tgt[0], c.tgt[1], c.tgt[2]);\n      gl.uniform1f(su.uFoc, c.foc); gl.uniform1f(su.uFocus, c.focus);\n      gl.uniform4f(su.uKey, s.pose.x, s.pose.y, s.pose.z, s.pose.yaw);\n      gl.uniform1f(su.uRoll, s.pose.roll + s.roll);\n      gl.uniform4f(su.uFob, r.fob[0], r.fob[1], r.fob[2], r.fob[3]);\n      gl.uniform4f(su.uRing, r.ring[0], r.ring[1], r.ring[2], r.ring[3]);\n      gl.uniform1f(su.uBolt, s.bolt * 0.3);\n      gl.uniform1f(su.uDirect, canAcc ? 0 : 1);\n      gl.uniform1f(su.uGlow, 1); gl.uniform1i(su.uNum, 3);\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, s.frame % 64);\n        gl.drawArrays(gl.TRIANGLES, 0, 3);\n      }\n    };\n\n    const fill = (p: number, user: boolean) => { if (user) s.touched = true; if (p > s.fill && s.phase === \"rest\") s.wobbleVel += 1.4 * (Math.random() > 0.5 ? 1 : -1); s.fill = p; if (s.phase !== \"rest\" && s.phase !== \"back\") s.phase = \"back\"; s.clock = 0; wake(); };\n    const open = (user: boolean) => { if (user) s.touched = true; if (s.phase === \"rest\") { s.phase = \"lift\"; s.clock = 0; wake(); } };\n    const close = () => { s.phase = \"back\"; s.clock = 0; wake(); };\n    const nudge = () => { s.wobbleVel += 6; wake(); };\n    // the moment someone reaches for the form, the demo stops and leaves the fields to them\n    const stop = () => { s.touched = true; wake(); };\n    api.current = { fill, open, close, nudge, stop };\n\n    let start = mixPose(REST, NEAR, 1);\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 + 2900; }\n      // self-running demo: opens filled in, signs in, locks again, types again\n      if (!reduce && !s.touched && now > s.demoAt) demo.step(now);\n\n      s.clock += dt;\n      if (reduce) {\n        // reduced motion: no travel, the picture simply changes to the new state\n        if (s.phase === \"lift\" || s.phase === \"insert\" || s.phase === \"turn\") s.phase = \"open\";\n        if (s.phase === \"back\") s.phase = \"rest\";\n        s.fillShown = s.fill; s.fillVel = 0;\n        const shut = s.phase !== \"open\";\n        s.pose = shut ? mixPose(REST, NEAR, s.fill) : { ...IN };\n        s.roll = shut ? 0 : -Math.PI / 2; s.bolt = shut ? 0 : 1;\n        s.fobYaw = s.pose.yaw + 0.5 - (shut ? 0 : 0.45);\n        s.rollVel = s.boltVel = s.fobYawVel = s.wobble = s.wobbleVel = 0;\n        if (s.phase !== s.drawn) { s.drawn = s.phase; s.count = 0; s.fresh = true; }\n        if (s.fill !== s.drawnFill) { s.drawnFill = s.fill; s.count = 0; s.fresh = true; }\n      } else {\n      // the fill spring: a heavy key on leather, so it drags a little and settles\n      s.fillVel += (60 * (s.fill - s.fillShown) - 13 * s.fillVel) * dt;\n      s.fillShown += s.fillVel * dt;\n      s.wobbleVel += (-140 * s.wobble - 8 * s.wobbleVel) * dt; s.wobble += s.wobbleVel * dt;\n      const lying = mixPose(REST, NEAR, s.fillShown);\n      lying.yaw += s.wobble * 0.05;\n      if (s.phase === \"rest\") { s.pose = lying; s.roll += (0 - s.roll) * Math.min(1, dt * 10); s.boltVel += (-300 * s.bolt - 26 * s.boltVel) * dt; s.bolt += s.boltVel * dt; }\n      else if (s.phase === \"lift\") {\n        // it is picked up: rises, rolls its bit down and lines up with the keyhole\n        if (s.clock < dt * 1.5) start = { ...s.pose };\n        const e = Math.min(1, s.clock / 0.7);\n        const m = mixPose(start, READY, ease(e));\n        m.y += Math.sin(Math.PI * e) * 0.12;\n        s.pose = m;\n        if (e >= 1) { s.phase = \"insert\"; s.clock = 0; }\n      } else if (s.phase === \"insert\") {\n        const e = Math.min(1, s.clock / 0.38);\n        s.pose = mixPose(READY, IN, e * e * (3 - 2 * e) * (1 + 0.02 * Math.sin(e * 9)));\n        if (e >= 1) { s.phase = \"turn\"; s.clock = 0; s.rollVel = 0; s.thunk = 0; }\n      } else if (s.phase === \"turn\") {\n        // a quarter turn against the springs inside, a touch past, and back\n        s.rollVel += (520 * (-Math.PI / 2 - s.roll) - 22 * s.rollVel) * dt;\n        s.roll += s.rollVel * dt;\n        if (s.clock > 0.16) { s.boltVel += (420 * (1 - s.bolt) - 20 * s.boltVel) * dt; s.bolt += s.boltVel * dt; if (!s.thunk && s.bolt > 0.95) { s.thunk = 1; s.shake = 1; } }\n        if (s.clock > 1.2) { s.phase = \"open\"; }\n      } else if (s.phase === \"open\") {\n        s.rollVel += (520 * (-Math.PI / 2 - s.roll) - 22 * s.rollVel) * dt; s.roll += s.rollVel * dt;\n        s.boltVel += (420 * (1 - s.bolt) - 20 * s.boltVel) * dt; s.bolt += s.boltVel * dt;\n      } else if (s.phase === \"back\") {\n        // turn back, draw out and lay it down where the form says it should lie\n        s.rollVel += (300 * (0 - s.roll) - 26 * s.rollVel) * dt; s.roll += s.rollVel * dt;\n        s.boltVel += (300 * (0 - s.bolt) - 26 * s.boltVel) * dt; s.bolt += s.boltVel * dt;\n        if (s.clock < dt * 1.5) start = { ...s.pose };\n        if (s.clock > 0.3) {\n          const e = Math.min(1, (s.clock - 0.3) / 0.9);\n          const m = mixPose(start, lying, ease(e));\n          m.y += Math.sin(Math.PI * e) * 0.1 * (start.y > 0.2 ? 1 : 0);\n          s.pose = m;\n          if (e >= 1) s.phase = \"rest\";\n        }\n      }\n      // the fob trails its key, swinging through on a lag\n      const want = s.pose.yaw + 0.5 - (s.phase === \"rest\" ? 0 : 0.45) + s.wobble * 0.3;\n      s.fobYawVel += (34 * (want - s.fobYaw) - 5 * s.fobYawVel) * dt; s.fobYaw += s.fobYawVel * dt;\n      s.sx += (s.px - s.sx) * (1 - Math.exp(-dt * 3)); s.sy += (s.py - s.sy) * (1 - Math.exp(-dt * 3));\n      s.shake *= Math.exp(-dt * 9);\n      }\n\n      const moving = s.phase !== \"rest\" && s.phase !== \"open\" || Math.abs(s.fillVel) > 0.003 || Math.abs(s.fill - s.fillShown) > 0.002 || Math.abs(s.fobYawVel) > 0.01 || Math.abs(s.boltVel) > 0.01 || Math.abs(s.rollVel) > 0.01 || Math.abs(s.wobbleVel) > 0.01 || s.shake > 0.01 || Math.abs(s.px - s.sx) + Math.abs(s.py - s.sy) > 0.002;\n      if (s.fresh || !canAcc) { draw(1, 0); s.fresh = false; s.count = 1; }\n      else if (moving) { draw(0.42, 1 + (s.frame % 64)); s.count = 3; }\n      else if (s.count < 48) { s.count++; draw(1 / s.count, s.count); }\n      if (s.frame === 1) setShown(\"gl\");\n      if (dtRaw > 0.026) s.slow++; else s.slow = Math.max(0, s.slow - 2);\n      if (s.slow > 40 && scale > 0.5) { scale *= 0.82; s.slow = 0; size(); }\n      if (moving || s.count < 48 || (!reduce && !s.touched)) s.raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { if (!s.raf && s.visible) { s.last = 0; s.raf = requestAnimationFrame(frame); } };\n\n    // the demo script, driven from the frame loop so it pauses off screen\n    const demo = { step: (_now: number) => {} };\n    let stage_ = 0, typed = 0;\n    demo.step = (now: number) => {\n      if (stage_ === 0) { open(false); demoUi.sign(); stage_ = 1; s.demoAt = now + 3800; }\n      else if (stage_ === 1) { close(); demoUi.clear(); fill(0, false); stage_ = 2; typed = 0; s.demoAt = now + 1500; }\n      else if (stage_ === 2) {\n        const total = DEMO_EMAIL.length + DEMO_PASSWORD.length;\n        typed++;\n        const e = DEMO_EMAIL.slice(0, Math.min(typed, DEMO_EMAIL.length));\n        const pw = DEMO_PASSWORD.slice(0, Math.max(0, typed - DEMO_EMAIL.length));\n        demoUi.type(e, pw);\n        fill(progress(e, pw), false);\n        s.demoAt = now + (typed === DEMO_EMAIL.length ? 420 : 70 + Math.random() * 60);\n        if (typed >= total) { stage_ = 0; s.demoAt = now + 1600; }\n      }\n    };\n\n    size();\n    s.fill = progress(DEMO_EMAIL, DEMO_PASSWORD); s.fillShown = s.fill; s.pose = mixPose(REST, NEAR, s.fill);\n    s.fobYaw = s.pose.yaw + 0.5;\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    const move = (e: PointerEvent) => {\n      if (reduce) return;\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      wake();\n    };\n    const leave = () => { s.px = 0; s.py = 0; wake(); };\n    box.addEventListener(\"pointermove\", move);\n    box.addEventListener(\"pointerleave\", leave);\n    const lost = (e: Event) => { e.preventDefault(); setShown(\"still\"); };\n    cv.addEventListener(\"webglcontextlost\", lost);\n    wake();\n    return () => {\n      cancelAnimationFrame(s.raf); ro.disconnect(); io.disconnect();\n      document.removeEventListener(\"visibilitychange\", vis);\n      box.removeEventListener(\"pointermove\", move); box.removeEventListener(\"pointerleave\", leave);\n      cv.removeEventListener(\"webglcontextlost\", lost);\n      api.current = null;\n    };\n  }, []);\n\n  // The demo reaches into the form through these, so what it types is really in the fields.\n  const demoUi = useRef({\n    sign: () => {}, clear: () => {}, type: (_e: string, _p: string) => {},\n  }).current;\n  demoUi.sign = () => { setErrors({}); setDone(true); };\n  demoUi.clear = () => { setDone(false); setEmail(\"\"); setPassword(\"\"); setErrors({}); };\n  demoUi.type = (e: string, p: string) => { setEmail(e); setPassword(p); };\n\n  const edit = (e: string, p: string) => {\n    setEmail(e); setPassword(p); setDone(false); setSaid(false);\n    setErrors({});\n    api.current?.fill(progress(e, p), true);\n  };\n  const submit = (ev: React.FormEvent) => {\n    ev.preventDefault();\n    if (done) { setDone(false); setSaid(false); api.current?.close(); emailRef.current?.focus(); return; }\n    const next: { email?: string; password?: string } = {};\n    if (!/^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(email.trim())) next.email = copy.badEmail;\n    if (password.length < 8) next.password = copy.badPassword;\n    setErrors(next);\n    if (next.email || next.password) {\n      api.current?.nudge();\n      (next.email ? emailRef : passRef).current?.focus();\n      return;\n    }\n    // nothing is sent or stored: the key turns and the form says so\n    setDone(true); setSaid(true);\n    api.current?.open(true);\n  };\n  const headline = done ? copy.done : copy.head;\n\n  return (\n    <section className=\"relative isolate overflow-hidden bg-[#f3ecdf] text-[#1d2a22]\" style={{ fontFamily: FONT }}>\n      <div className=\"mx-auto flex w-full max-w-[1600px] flex-col-reverse lg:min-h-[760px] lg:flex-row\">\n        <div className=\"relative z-10 flex w-full flex-col justify-center px-6 py-10 sm:px-10 lg:w-[42%] lg:px-16 lg:py-14\">\n          <p className=\"text-[11px] font-semibold uppercase tracking-[0.32em] text-[#1d2a22]/70\">{copy.house} <span className=\"mx-2 text-[#1d2a22]/30\">/</span> {copy.room}</p>\n          <h2 className=\"mt-6 text-[52px] leading-[0.9] tracking-[-0.04em] sm:text-[68px] lg:text-[84px]\" style={{ fontFamily: SERIF }}>\n            <span className=\"block\">{headline[0]}</span>\n            <span className=\"block italic text-[#1f5c3d]\">{headline[1]}</span>\n          </h2>\n          <p className=\"mt-5 max-w-[24rem] text-[16px] leading-relaxed text-[#1d2a22]/75\">{done ? copy.ledeDone : copy.lede}</p>\n          <form onSubmit={submit} onFocus={() => api.current?.stop()} onPointerDown={() => api.current?.stop()} noValidate className=\"mt-8 w-full max-w-[24rem] space-y-5\">\n            <div>\n              <label htmlFor=\"brass-key-email\" className=\"block text-[12px] font-semibold uppercase tracking-[0.2em] text-[#1d2a22]/80\">{copy.email}</label>\n              <input\n                ref={emailRef} id=\"brass-key-email\" name=\"email\" type=\"email\" inputMode=\"email\" autoComplete=\"off\" autoCapitalize=\"none\" spellCheck={false}\n                value={email} onChange={(e) => edit(e.target.value, password)} placeholder=\"you@example.com\"\n                aria-invalid={!!errors.email} aria-describedby={errors.email ? \"brass-key-email-error\" : undefined}\n                className={`mt-2 h-12 w-full rounded-lg border bg-white/70 px-4 text-[17px] tracking-[-0.01em] text-[#1d2a22] outline-none transition-[border-color,box-shadow] placeholder:text-[#1d2a22]/40 focus-visible:border-[#1f5c3d] focus-visible:ring-4 focus-visible:ring-[#1f5c3d]/25 ${errors.email ? \"border-[#a3341f]\" : \"border-[#1d2a22]/25\"}`}\n              />\n              {errors.email && <p id=\"brass-key-email-error\" className=\"mt-2 text-[14px] leading-snug text-[#a3341f]\">{errors.email}</p>}\n            </div>\n            <div>\n              <div className=\"flex items-baseline justify-between\">\n                <label htmlFor=\"brass-key-password\" className=\"block text-[12px] font-semibold uppercase tracking-[0.2em] text-[#1d2a22]/80\">{copy.password}</label>\n                <a href=\"#\" className=\"rounded text-[13px] text-[#1f5c3d] underline decoration-[#1f5c3d]/40 underline-offset-4 hover:decoration-[#1f5c3d] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#1f5c3d]\">{copy.forgot}</a>\n              </div>\n              <input\n                ref={passRef} id=\"brass-key-password\" name=\"password\" type=\"password\" autoComplete=\"off\"\n                value={password} onChange={(e) => edit(email, e.target.value)}\n                aria-invalid={!!errors.password} aria-describedby={errors.password ? \"brass-key-password-error\" : undefined}\n                className={`mt-2 h-12 w-full rounded-lg border bg-white/70 px-4 text-[17px] tracking-[0.08em] text-[#1d2a22] outline-none transition-[border-color,box-shadow] focus-visible:border-[#1f5c3d] focus-visible:ring-4 focus-visible:ring-[#1f5c3d]/25 ${errors.password ? \"border-[#a3341f]\" : \"border-[#1d2a22]/25\"}`}\n              />\n              {errors.password && <p id=\"brass-key-password-error\" className=\"mt-2 text-[14px] leading-snug text-[#a3341f]\">{errors.password}</p>}\n            </div>\n            <button type=\"submit\" className=\"h-12 w-full rounded-lg bg-[#1f4d35] text-[16px] font-semibold tracking-[-0.01em] text-[#f6efe0] transition-[transform,background-color] duration-200 hover:bg-[#173d2a] focus-visible:outline-none focus-visible:ring-4 focus-visible:ring-[#c9973f] focus-visible:ring-offset-2 focus-visible:ring-offset-[#f3ecdf] active:scale-[0.99] motion-reduce:transition-none\">\n              {done ? copy.again : copy.button}\n            </button>\n            <p aria-live=\"polite\" className=\"min-h-[1.5em] text-[14px] text-[#1d2a22]/75\">{said ? copy.ok : \"\"}</p>\n          </form>\n        </div>\n        <div ref={stage} className=\"relative h-[380px] w-full overflow-hidden bg-[#0f3523] sm:h-[460px] lg:h-auto lg:w-[58%]\">\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          {shown === \"still\" && <Still open={done} />}\n        </div>\n      </div>\n    </section>\n  );\n}\n\nfunction progress(e: string, p: string) {\n  return Math.min(1, e.length / DEMO_EMAIL.length) * 0.5 + Math.min(1, p.length / 8) * 0.5;\n}\n"}]}
