The showcase prompt, round 2, Gemini 4 Carbon
agent (cont.)
+10:23write_file{"Content":"import fs from 'node:fs';\nimport path from 'node:path';\n\nconst SCRATCH = '~/.gemini/antigravity-cli/brain/97578de1-98a0-4cd1-b14f-8c8e71a66716/scratch';\nconst monolithAssets = JSON.parse(fs.readFileSync(path.join(SCRATCH, 'monolith_assets.json'), 'utf8'));\nconst audioTelemetry = JSON.parse(fs.readFileSync(path.join(SCRATCH, 'audio_telemetry.json'), 'utf8'));\n\n// Compact telemetry arrays so HTML stays lightweight (~35KB for 2400 frames)\nconst compactTel = {\n rms: audioTelemetry.map((x) => Math.round(x.rms * 1000)),\n low: audioTelemetry.map((x) => Math.round(x.low * 1000)),\n high: audioTelemetry.map((x) => Math.round(x.high * 1000)),\n L: audioTelemetry.map((x) => x.L.map((v) => Math.round(v * 127))),\n R: audioTelemetry.map((x) => x.R.map((v) => Math.round(v * 127)))\n};\n\nconst html = `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\" />\n<title>6C — Gemini 4 Carbon × Antigravity</title>\n<style>\n :root {\n --bg: #060608;\n --fg: #F4F1EA;\n --muted: #8E8B82;\n --gold: #F5B95A;\n --gold-bright: #FFF1D0;\n --crimson: #FF4838;\n --panel: rgba(10, 10, 14, 0.76);\n --border: rgba(244, 241, 234, 0.14);\n --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'Nimbus Sans', 'Ubuntu', sans-serif;\n --serif: 'Instrument Serif', 'Palatino', 'P052', 'URW Palladio L', Georgia, serif;\n --mono: 'JetBrains Mono', 'SF Mono', 'Noto Sans Mono', 'DejaVu Sans Mono', monospace;\n }\n * { box-sizing: border-box; margin: 0; padding: 0; user-select: none; -webkit-user-select: none; }\n html, body {\n width: 100%; height: 100%; overflow: hidden;\n background: var(--bg); color: var(--fg);\n font-family: var(--sans);\n -webkit-font-smoothing: antialiased;\n }\n #stage {\n position: relative; width: 100%; height: 100%; overflow: hidden;\n background: radial-gradient(circle at 50% 48%, #0E0F14 0%, #060608 78%);\n cursor: grab;\n }\n #stage:active { cursor: grabbing; }\n canvas {\n position: absolute; inset: 0; width: 100%; height: 100%; display: block;\n }\n #glCanvas { z-index: 1; }\n #hudCanvas { z-index: 2; pointer-events: none; }\n\n /* Interactive Chrome (Hidden in ?render=1 cinema capture mode) */\n body.render-mode .ui-chrome { display: none !important; }\n\n .top-controls {\n position: absolute; top: 18px; right: 22px; z-index: 10;\n display: flex; align-items: center; gap: 10px;\n }\n .btn-pill {\n appearance: none; border: 1px solid var(--border);\n background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);\n color: var(--fg); font-family: var(--mono); font-size: 11px; letter-spacing: 0.09em;\n text-transform: uppercase; padding: 8px 13px; border-radius: 999px;\n cursor: pointer; transition: all 0.18s ease; display: inline-flex; align-items: center; gap: 7px;\n }\n .btn-pill:hover { border-color: rgba(245, 185, 90, 0.65); color: var(--gold-bright); transform: translateY(-1px); }\n .btn-pill.active {\n background: rgba(245, 185, 90, 0.16);\n border-color: rgba(245, 185, 90, 0.78);\n color: var(--gold-bright);\n box-shadow: 0 0 20px rgba(245, 185, 90, 0.18);\n }\n .dot-ind {\n width: 6px; height: 6px; border-radius: 50%; background: var(--muted);\n transition: background 0.2s ease, box-shadow 0.2s ease;\n }\n .btn-pill.active .dot-ind { background: var(--gold); box-shadow: 0 0 8px var(--gold); }\n\n .dock-wrap {\n position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);\n z-index: 10; display: flex; flex-direction: column; align-items: center; gap: 8px;\n max-width: calc(100vw - 24px);\n }\n .context-bar {\n display: none; gap: 8px; flex-wrap: wrap; justify-content: center;\n }\n .context-bar.visible { display: flex; }\n .dock {\n display: flex; align-items: center; gap: 4px; padding: 5px;\n border-radius: 999px; border: 1px solid var(--border);\n background: rgba(8, 8, 12, 0.82); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);\n box-shadow: 0 12px 40px rgba(0,0,0,0.55);\n overflow-x: auto; max-width: 100%;\n }\n .dock-tab {\n appearance: none; border: 1px solid transparent; background: transparent;\n color: var(--muted); font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.07em;\n padding: 6px 11px; border-radius: 999px; cursor: pointer; white-space: nowrap;\n transition: all 0.16s ease;\n }\n .dock-tab:hover { color: var(--fg); }\n .dock-tab.active {\n color: var(--fg); background: rgba(244, 241, 234, 0.09);\n border-color: rgba(245, 185, 90, 0.45);\n }\n .dock-sep { width: 1px; height: 16px; background: var(--border); margin: 0 3px; flex-shrink: 0; }\n\n /* Source / Math Inspector Modal */\n #codeModal {\n position: absolute; right: 22px; top: 62px; width: min(460px, calc(100vw - 44px));\n max-height: calc(100vh - 150px); overflow: auto; z-index: 15;\n background: rgba(8, 9, 13, 0.93); border: 1px solid rgba(245, 185, 90, 0.38);\n border-radius: 12px; padding: 16px 18px; display: none;\n backdrop-filter: blur(18px); box-shadow: 0 20px 60px rgba(0,0,0,0.7);\n }\n #codeModal.open { display: block; }\n #codeModal h4 {\n font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; color: var(--gold);\n margin-bottom: 8px; text-transform: uppercase;\n }\n #codeModal pre {\n font-family: var(--mono); font-size: 11px; line-height: 1.5; color: #D9D5CC;\n white-space: pre-wrap; word-break: break-word;\n }\n @media (max-width: 720px) {\n .dock-tab { font-size: 9.5px; padding: 5px 8px; }\n .top-controls { top: 10px; right: 12px; }\n }\n</style>\n</head>\n<body>\n<div id=\"stage\">\n <canvas id=\"glCanvas\"></canvas>\n <canvas id=\"hudCanvas\"></canvas>\n\n <div class=\"top-controls ui-chrome\">\n <button id=\"btnMath\" class=\"btn-pill\" title=\"Inspect live equations & solver code\">{ } Inspect Math</button>\n <button id=\"btnSound\" class=\"btn-pill\"><span class=\"dot-ind\"></span><span id=\"soundLabel\">Sound Off</span></button>\n </div>\n\n <div id=\"codeModal\" class=\"ui-chrome\">\n <h4 id=\"modalTitle\">Live Mathematical Kernel</h4>\n <pre id=\"modalCode\"></pre>\n </div>\n\n <div class=\"dock-wrap ui-chrome\">\n <div id=\"contextBar\" class=\"context-bar\"></div>\n <div class=\"dock\">\n <button class=\"dock-tab active\" data-mode=\"film\" id=\"btnFilm\">▶ 40s Film</button>\n <div class=\"dock-sep\"></div>\n <button class=\"dock-tab\" data-act=\"0\">01 Roster</button>\n <button class=\"dock-tab\" data-act=\"1\">02 Spacetime</button>\n <button class=\"dock-tab\" data-act=\"2\">03 Silicon</button>\n <button class=\"dock-tab\" data-act=\"3\">04 Monolith 3D</button>\n <button class=\"dock-tab\" data-act=\"4\">05 Cymatics</button>\n <button class=\"dock-tab\" data-act=\"5\">06 Antigravity</button>\n </div>\n </div>\n</div>\n\n<script>\n(() => {\n const PARAMS = new URLSearchParams(location.search);\n const IS_RENDER = PARAMS.get('render') === '1';\n if (IS_RENDER) document.body.classList.add('render-mode');\n\n const MONOLITH_JPG = ${JSON.stringify(monolithAssets.jpg)};\n const MONOLITH_DEPTH = ${JSON.stringify(monolithAssets.depth)};\n const TEL = ${JSON.stringify(compactTel)};\n\n const DURATION = 40.0;\n const FPS = 60;\n\n // Act time boundaries in the 40.0s Director's Cut\n const ACTS = [\n { id: 0, start: 0.0, end: 6.0, code: '00 // WORKSPACE AUDIT', name: 'THE SIXTH SEAT' },\n { id: 1, start: 6.0, end: 13.0, code: '01 // CONTINUUM PHYSICS', name: 'KERR SPACETIME' },\n { id: 2, start: 13.0, end: 19.5, code: '02 // SYSTEMS & SOLVERS', name: 'SILICON ROUTER' },\n { id: 3, start: 19.5, end: 26.5, code: '03 // MULTIMODAL VISION', name: '3D MONOLITH' },\n { id: 4, start: 26.5, end: 33.0, code: '04 // WAVE HARMONICS', name: 'CHLADNI CYMATICS' },\n { id: 5, start: 33.0, end: 40.0, code: '05 // AUTONOMOUS AGENT', name: 'ANTIGRAVITY' }\n ];\n\n const CITADEL_MODELS = [\n { name: 'OPUS 5.5', role: 'Leads & Builds', domain: 'Architecture', bridge: 'Fuses architecture directly with formal math, GPU shaders & zero-collision verification.' },\n { name: 'SONNET 5.5', role: 'Chores & Test Data', domain: 'Operations', bridge: 'Replaces brittle fixtures with property-based fuzzers & deterministic simulation harnesses.' },\n { name: 'FABLE 5.2', role: 'Design Partner', domain: 'Direction', bridge: 'Pairs editorial typography & chiaroscuro composition with live interactive code.' },\n { name: 'GPT-6-ASTRA', role: 'Critiques Designs', domain: 'Critique', bridge: 'Visually inspects its own rendered frames at 60 fps and iterates before you ever see v1.' },\n { name: 'GPT-6.1-SOL', role: 'Reviews & Deploys', domain: 'Delivery', bridge: 'Audits invariants, orchestrates parallel subagents & ships zero-dependency artifacts.' }\n ];\n\n // Math / Kernel Inspector Snippets per Act\n const KERNEL_SNIPPETS = [\n \\`// 01 // WORKSPACE TELEMETRY & CARBON sp3 TOPOLOGY\n// Scanned ~/run/about-me.md (297 bytes)\n// Roster: Opus 5.5 | Sonnet 5.5 | Fable 5.2 | GPT-6-Astra | GPT-6.1-Sol\n// Query(\"Gemini 4 Carbon\") -> 0 matches -> Assigned Seat 06 (Element 6C)\n\nfor (let i = 0; i < atoms.length; i++) {\n // Tetrahedral sp3 bond angle: arccos(-1/3) = 109.4712°\n const bond = dot(atoms[i].dir, atoms[j].dir); // -0.33333\n}\\`,\n \\`// 02 // GENERAL-RELATIVISTIC NULL GEODESIC RAYMARCHER (GLSL)\n// Exact effective potential force law for photons in Schwarzschild/Kerr metric:\n// d²x/dλ² = -(3/2) * rs * |x × v|² / |x|⁵ * x\n\nvec3 h = cross(pos, dir);\nfloat h2 = dot(h, h);\nfor (int i = 0; i < 52; i++) {\n float r2 = dot(pos, pos), r = sqrt(r2);\n if (r < rs) { hitHorizon = true; break; }\n vec3 accel = -1.5 * rs * h2 * pos / (r2 * r2 * r);\n float dt = clamp(0.045 * r, 0.018, 0.42);\n dir = normalize(dir + accel * dt + frameDrag(pos, spin) * dt);\n pos += dir * dt;\n}\\`,\n \\`// 03 // OCTILINEAR A* RIP-UP & REROUTE SILICON DIE SOLVER\n// 8-direction chamfered grid + congestion history penalty (Negotiated Congestion)\nfunction routeNetAStar(src, dst, netId, historyCost) {\n // f(n) = g(n) + octileHeuristic(n, dst) + congestionPenalty(n)\n const dx = Math.abs(x - dst.x), dy = Math.abs(y - dst.y);\n const h = (dx + dy) + (Math.SQRT2 - 2) * Math.min(dx, dy);\n const stepCost = (diag ? 1.414 : 1.0) + bendPenalty + occ * historyCost;\n}\\`,\n \\`// 04 // MONOCULAR DEPTH RECONSTRUCTION -> 46,080 3D VERTICES\n// Generated 16:9 chiaroscuro canvas via native image-generator subagent,\n// solved room perspective + octahedral crystal relief z(u,v), & unprojected:\nvec3 worldPos = vec3(\n (uv.x - 0.5) * aspect * (1.45 - 0.55 * depth),\n (0.5 - uv.y) * (1.45 - 0.55 * depth),\n (depth - 0.45) * 1.35\n);\\`,\n \\`// 05 // CHLADNI BIHARMONIC EIGENMODES & KARPLUS-STRONG SYNTHESIS\n// Square free-edge plate nodal locus:\nfloat psi = a * (cos(n*PI*x)*cos(m*PI*y) - cos(m*PI*x)*cos(n*PI*y))\n + b * (cos(n2*PI*x)*cos(m2*PI*y) + cos(m2*PI*x)*cos(n2*PI*y));\n// Stochastic nodal drift: x -= lr * grad(|psi|²) + thermalJitter * |psi|\\`,\n \\`// 06 // ANTIGRAVITY AUTONOMOUS EXECUTION PIPELINE\n1. fs.read('~/run/about-me.md') -> 297 B parsed\n2. invoke_subagent('image-generator') -> monolith chiaroscuro\n3. python3 extract_monolith_3d.py -> 320x180 spatial depth\n4. node synthesize_score.mjs -> 48kHz 8x8 FDN WAV (-12.8 LUFS)\n5. parallel Chrome CDP 6x shards @ 60.00 fps -> H.264 + self-verified frames\\`\n ];\n\n // ============================================================================\n // DETERMINISTIC PRNG\n // ============================================================================\n function makeRng(seed) {\n let s = (seed >>> 0) || 0x6CCA4B01;\n return () => {\n s ^= s << 13; s ^= s >>> 17; s ^= s << 5;\n return (s >>> 0) / 4294967296;\n };\n }\n\n // ============================================================================\n // STAGE & CANVASES\n // ============================================================================\n const stage = document.getElementById('stage');\n const glCanvas = document.getElementById('glCanvas');\n const hudCanvas = document.getElementById('hudCanvas');\n const ctx = hudCanvas.getContext('2d');\n const gl = glCanvas.getContext('webgl2', { antialias: true, alpha: false, preserveDrawingBuffer: IS_RENDER });\n\n let viewW = 1920, viewH = 1080, dpr = 1;\n function resize() {\n if (IS_RENDER) {\n viewW = 1920; viewH = 1080; dpr = 1;\n } else {\n dpr = Math.min(window.devicePixelRatio || 1, 2);\n viewW = Math.max(320, stage.clientWidth);\n viewH = Math.max(240, stage.clientHeight);\n }\n glCanvas.width = Math.round(viewW * dpr);\n glCanvas.height = Math.round(viewH * dpr);\n hudCanvas.width = Math.round(viewW * dpr);\n hudCanvas.height = Math.round(viewH * dpr);\n }\n window.addEventListener('resize', resize);\n resize();\n\n // ============================================================================\n // INTERACTIVE STATE\n // ============================================================================\n const state = {\n mode: 'film', // 'film' | 'sandbox'\n sandboxAct: 0,\n filmTime: 0.0,\n playing: true,\n selectedSeat: 5, // 0..4 = Citadel models, 5 = Seat 06 Carbon\n pointerDown: false,\n dragX: 0, dragY: 0,\n lastX: 0, lastY: 0,\n // Interactive parameters per act\n bhYaw: 0.0, bhPitch: 0.23, bhSpin: 0.72,\n monoYaw: 0.0, monoPitch: 0.0, monoExplode: -1, // -1 = auto in film, [0..1] in sandbox\n chladniPreset: 0,\n siliconSeed: 1,\n customBlocks: []\n };\n\n // ============================================================================\n // ASSET LOADING: MONOLITH RGB + DEPTH -> 46,080 3D VERTICES\n // ============================================================================\n const PC_W = 288, PC_H = 160, PC_COUNT = PC_W * PC_H;\n const pcPositions = new Float32Array(PC_COUNT * 3); // u, v, depth [0..1]\n const pcColors = new Float32Array(PC_COUNT * 3);\n let monolithImg = null;\n let assetsReadyResolve;\n const assetsReady = new Promise((res) => { assetsReadyResolve = res; });\n\n (function loadMonolithData() {\n const imgC = new Image();\n const imgD = new Image();\n let loaded = 0;\n const onBoth = () => {\n loaded++;\n if (loaded < 2) return;\n monolithImg = imgC;\n\n const offC = document.createElement('canvas');\n offC.width = PC_W; offC.height = PC_H;\n const cCtx = offC.getContext('2d');\n cCtx.drawImage(imgC, 0, 0, PC_W, PC_H);\n const rgb = cCtx.getImageData(0, 0, PC_W, PC_H).data;\n\n const offD = document.createElement('canvas');\n offD.width = PC_W; offD.height = PC_H;\n const dCtx = offD.getContext('2d');\n dCtx.drawImage(imgD, 0, 0, PC_W, PC_H);\n const dep = dCtx.getImageData(0, 0, PC_W, PC_H).data;\n\n const rng = makeRng(0x3D6CCA4B);\n let ptr = 0;\n for (let y = 0; y < PC_H; y++) {\n for (let x = 0; x < PC_W; x++) {\n const i4 = (y * PC_W + x) * 4;\n const u = (x + (rng() - 0.5) * 0.45) / PC_W;\n const v = (y + (rng() - 0.5) * 0.45) / PC_H;\n const d = dep[i4] / 255.0;\n pcPositions[ptr * 3 + 0] = u;\n pcPositions[ptr * 3 + 1] = v;\n pcPositions[ptr * 3 + 2] = d;\n\n pcColors[ptr * 3 + 0] = rgb[i4 + 0] / 255.0;\n pcColors[ptr * 3 + 1] = rgb[i4 + 1] / 255.0;\n pcColors[ptr * 3 + 2] = rgb[i4 + 2] / 255.0;\n ptr++;\n }\n }\n initPointCloudGL();\n assetsReadyResolve();\n };\n imgC.onload = onBoth;\n imgD.onload = onBoth;\n imgC.src = MONOLITH_JPG;\n imgD.src = MONOLITH_DEPTH;\n })();\n\n // ============================================================================\n // WEBGL2 PIPELINES: (A) KERR BLACK HOLE GEODESIC SHADER, (B) 3D POINT SCULPTURE\n // ============================================================================\n function compileShader(type, src) {\n const s = gl.createShader(type);\n gl.shaderSource(s, src);\n gl.compileShader(s);\n if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) {\n console.error(gl.getShaderInfoLog(s));\n }\n return s;\n }\n function linkProgram(vsSrc, fsSrc) {\n const p = gl.createProgram();\n gl.attachShader(p, compileShader(gl.VERTEX_SHADER, vsSrc));\n gl.attachShader(p, compileShader(gl.FRAGMENT_SHADER, fsSrc));\n gl.linkProgram(p);\n return p;\n }\n\n // Program A: Fullscreen Relativistic Kerr/Schwarzschild Black Hole Raymarcher\n const bhVS = \\`#version 300 es\n layout(location=0) in vec2 aPos;\n out vec2 vUv;\n void main() {\n vUv = aPos * 0.5 + 0.5;\n gl_Position = vec4(aPos, 0.0, 1.0);\n }\\`;\n\n const bhFS = \\`#version 300 es\n precision highp float;\n in vec2 vUv;\n out vec4 fragColor;\n\n uniform vec2 uRes;\n uniform float uTime;\n uniform float uYaw;\n uniform float uPitch;\n uniform float uSpin;\n uniform float uAudioPulse;\n\n float hash21(vec2 p) {\n p = fract(p * vec2(234.34, 435.345));\n p += dot(p, p + 34.23);\n return fract(p.x * p.y);\n }\n\n float noise(vec2 p) {\n vec2 i = floor(p), f = fract(p);\n f = f * f * (3.0 - 2.0 * f);\n float a = hash21(i);\n float b = hash21(i + vec2(1.0, 0.0));\n float c = hash21(i + vec2(0.0, 1.0));\n float d = hash21(i + vec2(1.0, 1.0));\n return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);\n }\n\n float fbm(vec2 p) {\n float v = 0.0, a = 0.5;\n mat2 rot = mat2(0.8, 0.6, -0.6, 0.8);\n for (int i = 0; i < 4; i++) {\n v += a * noise(p);\n p = rot * p * 2.03;\n a *= 0.5;\n }\n return v;\n }\n\n // Physical Planckian blackbody locus approximation\n vec3 blackbody(float tempK) {\n float t = clamp(tempK / 1000.0, 1.0, 14.0);\n vec3 col;\n col.r = t <= 6.6 ? 1.0 : clamp(1.292 * pow(t - 6.0, -0.133), 0.0, 1.0);\n col.g = t <= 6.6\n ? clamp(0.390 * log(max(t, 1.01)) - 0.634, 0.0, 1.0)\n : clamp(1.129 * pow(t - 6.0, -0.0755), 0.0, 1.0);\n col.b = t >= 6.6 ? 1.0 : (t <= 1.9 ? 0.0 : clamp(0.543 * log(t - 1.0) - 1.196, 0.0, 1.0));\n return col;\n }\n\n vec3 starfield(vec3 dir) {\n vec2 sp = vec2(atan(dir.z, dir.x), asin(clamp(dir.y, -1.0, 1.0)));\n vec2 grid = sp * 46.0;\n vec2 id = floor(grid);\n vec2 gv = fract(grid) - 0.5;\n float h = hash21(id);\n vec3 col = vec3(0.0);\n if (h > 0.86) {\n vec2 offset = vec2(hash21(id + 7.1), hash21(id + 13.7)) - 0.5;\n float d = length(gv - offset * 0.6);\n float star = smoothstep(0.09, 0.0, d) * pow((h - 0.86) / 0.14, 1.8);\n col += blackbody(3800.0 + 6500.0 * hash21(id + 3.3)) * star * 1.5;\n }\n // Subtle warm galactic dust band\n float dust = exp(-abs(dir.y + 0.12 * dir.x) * 5.5) * fbm(sp * 4.5 + 1.2);\n col += vec3(0.08, 0.055, 0.038) * dust * 0.65;\n return col;\n }\n\n void main() {\n vec2 uv = (vUv - 0.5) * 2.0;\n uv.x *= uRes.x / uRes.y;\n\n // Slight dramatic Gargantua Dutch roll (7.5 degrees)\n float roll = -0.13;\n uv = mat2(cos(roll), -sin(roll), sin(roll), cos(roll)) * uv;\n // Shift black hole slightly right-of-center (x - 0.12) so left typography breathes cleanly!\n uv.x -= 0.12;\n\n float camDist = 11.2;\n vec3 ro = vec3(\n camDist * cos(uPitch) * sin(uYaw),\n camDist * sin(uPitch),\n camDist * cos(uPitch) * cos(uYaw)\n );\n vec3 fwd = normalize(-ro);\n vec3 right = normalize(cross(vec3(0.0, 1.0, 0.0), fwd));\n vec3 up = cross(fwd, right);\n vec3 rd = normalize(fwd * 1.72 + right * uv.x + up * uv.y);\n\n // Schwarzschild radius rs = 1.0 (Photon sphere at r = 1.5, ISCO at r = 2.1 for spinning Kerr)\n const float rs = 1.0;\n vec3 pos = ro;\n vec3 dir = rd;\n vec3 hVec = cross(pos, dir);\n float h2 = dot(hVec, hVec);\n\n vec3 accumGlow = vec3(0.0);\n float transmittance = 1.0;\n bool swallowed = false;\n float minR = 100.0;\n\n for (int i = 0; i < 56; i++) {\n float r2 = dot(pos, pos);\n float r = sqrt(r2);\n minR = min(minR, r);\n if (r < rs * 1.01) {\n swallowed = true;\n break;\n }\n if (r > 20.0 && i > 12) break;\n\n // Exact GR null geodesic curvature: a = -1.5 * rs * L^2 / r^5 * pos + Kerr frame dragging\n vec3 accel = -1.5 * rs * h2 * pos / (r2 * r2 * r);\n vec3 spinAxis = vec3(0.0, 1.0, 0.0);\n vec3 frameDrag = uSpin * 0.32 * cross(spinAxis, dir) / (r2 * r);\n\n float dt = clamp(0.055 * (r - 0.72), 0.022, 0.48);\n vec3 prevPos = pos;\n dir = normalize(dir + (accel + frameDrag) * dt);\n pos += dir * dt;\n\n // Check equatorial accretion disk plane crossing (y = 0) + volumetric corona!\n if (prevPos.y * pos.y <= 0.0 || abs(pos.y) < 0.22) {\n float frac = prevPos.y * pos.y <= 0.0\n ? abs(prevPos.y) / (abs(prevPos.y) + abs(pos.y) + 1e-5)\n : 0.5;\n vec3 hit = mix(prevPos, pos, frac);\n float diskR = length(hit.xz);\n float vertFade = prevPos.y * pos.y <= 0.0 ? 1.0 : exp(-abs(pos.y) * 16.0) * 0.28;\n\n if (diskR > 1.85 && diskR < 8.6) {\n // Keplerian differential rotation omega ~ r^(-1.5)\n float omega = 2.6 * pow(diskR, -1.35);\n float angle = atan(hit.z, hit.x) + uTime * omega;\n\n // Multi-scale MHD spiral filaments\n float spiral1 = fbm(vec2(diskR * 2.9, angle * 2.0 + diskR * 1.6));\n float spiral2 = fbm(vec2(diskR * 7.5 - uTime * 0.4, angle * 4.0 - diskR * 2.8));\n float rings = 0.6 + 0.4 * sin(diskR * 9.5 + spiral1 * 3.5);\n float density = smoothstep(1.85, 2.35, diskR) * smoothstep(8.6, 3.6, diskR);\n density *= (0.35 + 0.85 * spiral1 * spiral2 + 0.25 * rings) * vertFade;\n\n // Relativistic orbital velocity tangent & Doppler factor D = 1 / (gamma * (1 - beta * cosTheta))\n vec3 velDir = normalize(vec3(-hit.z, 0.0, hit.x));\n float beta = clamp(sqrt(0.5 * rs / max(diskR - rs, 0.35)) * (0.85 + 0.2 * uSpin), 0.0, 0.68);\n float gamma = inversesqrt(1.0 - beta * beta);\n float cosTheta = dot(velDir, -dir); // positive when approaching observer!\n float doppler = 1.0 / (gamma * (1.0 - beta * cosTheta));\n float gravRedshift = sqrt(clamp(1.0 - rs / diskR, 0.08, 1.0));\n float shift = doppler * gravRedshift;\n\n // Temperature profile T ~ r^(-3/4) * shift\n float baseTemp = 5600.0 * pow(2.2 / diskR, 0.62) * pow(shift, 0.92);\n vec3 emit = blackbody(baseTemp) * pow(shift, 3.1) * density * (1.55 + 0.35 * uAudioPulse);\n\n accumGlow += transmittance * emit;\n transmittance *= exp(-density * 0.62);\n if (transmittance < 0.02) break;\n }\n }\n }\n\n // Razor-thin relativistic Einstein photon ring glow around minR ~ 1.5 rs\n float photonRing = exp(-abs(minR - 1.48) * 18.0) * (swallowed ? 0.55 : 1.15);\n accumGlow += blackbody(7200.0) * photonRing * (0.55 + 0.25 * uAudioPulse);\n\n vec3 bg = swallowed ? vec3(0.0) : starfield(dir) * transmittance;\n vec3 col = bg + accumGlow;\n\n // Filmic ACES tonemapping\n col = (col * (2.51 * col + 0.03)) / (col * (2.43 * col + 0.59) + 0.14);\n col = pow(clamp(col, 0.0, 1.0), vec3(0.92));\n\n // Subtle film vignette\n float vig = 1.0 - 0.32 * dot(vUv - 0.5, vUv - 0.5) * 1.8;\n fragColor = vec4(col * vig, 1.0);\n }\\`;\n\n // Program B: 3D Volumetric Point-Cloud Monolith Reconstruction\n const pcVS = \\`#version 300 es\n layout(location=0) in vec3 aUVD;\n layout(location=1) in vec3 aCol;\n\n uniform vec2 uRes;\n uniform float uExplode;\n uniform float uYaw;\n uniform float uPitch;\n uniform float uScanX;\n uniform float uTime;\n\n out vec3 vCol;\n out float vAlpha;\n\n void main() {\n float u = aUVD.x;\n float v = aUVD.y;\n float d = aUVD.z; // 0 = far back wall, 1 = closest foreground\n\n // Laser scan wave reveals 3D depth progressively\n float scanMask = smoothstep(u - 0.09, u + 0.02, uScanX);\n float active3D = uExplode * scanMask;\n\n float aspect = 16.0 / 9.0;\n // In flat 2D mode (active3D = 0): exact image plane\n vec3 flatPos = vec3((u - 0.5) * aspect * 1.26, (0.5 - v) * 1.26, 0.0);\n\n // In 3D volumetric chamber mode: perspective unprojection using spatial depth d\n float zWorld = (d - 0.46) * 1.55;\n float perspScale = 1.34 - 0.38 * d;\n vec3 volPos = vec3(\n (u - 0.5) * aspect * perspScale,\n (0.5 - v) * perspScale,\n zWorld\n );\n\n // Subtle floating dust shimmer in the diagonal golden sunbeam\n float lum = dot(aCol, vec3(0.299, 0.587, 0.114));\n if (d > 0.42 && d < 0.55 && lum > 0.32) {\n volPos.y += sin(uTime * 1.8 + u * 35.0 + v * 21.0) * 0.012 * active3D;\n }\n\n vec3 p = mix(flatPos, volPos, active3D);\n\n // Orbit rotation\n float cy = cos(uYaw * active3D), sy = sin(uYaw * active3D);\n float cp = cos(uPitch * active3D), sp = sin(uPitch * active3D);\n p.xz = mat2(cy, -sy, sy, cy) * p.xz;\n p.yz = mat2(cp, -sp, sp, cp) * p.yz;\n\n // Slight shift right so left editorial HUD stays clean\n p.x += 0.14 * active3D;\n\n float camZ = 2.45;\n float zDist = max(0.35, camZ - p.z);\n float fov = 1.72;\n vec2 proj = p.xy * (fov / zDist);\n proj.x /= (uRes.x / uRes.y);\n\n gl_Position = vec4(proj, (zDist - 0.35) / 5.0 * 2.0 - 1.0, 1.0);\n\n float scaleFactor = uRes.y / 1080.0;\n float basePt = mix(5.4, 4.1, active3D) * scaleFactor * (2.2 / zDist);\n // Golden scanline highlight right at u ~ uScanX\n float scanGlow = exp(-abs(u - uScanX) * 42.0) * step(0.01, uScanX) * step(uScanX, 0.99);\n\n gl_PointSize = clamp(basePt + scanGlow * 3.5 * scaleFactor, 1.2, 14.0);\n vCol = aCol * (1.0 + 0.18 * active3D) + vec3(1.0, 0.78, 0.36) * scanGlow * 0.85;\n vAlpha = mix(0.98, clamp(0.55 + 0.45 * lum + 0.25 * d, 0.35, 0.96), active3D);\n }\\`;\n\n const pcFS = \\`#version 300 es\n precision highp float;\n in vec3 vCol;\n in float vAlpha;\n out vec4 fragColor;\n void main() {\n vec2 c = gl_PointCoord - 0.5;\n float r2 = dot(c, c);\n if (r2 > 0.25) discard;\n float soft = smoothstep(0.25, 0.06, r2);\n fragColor = vec4(vCol, vAlpha * soft);\n }\\`;\n\n const bhProg = linkProgram(bhVS, bhFS);\n const pcProg = linkProgram(pcVS, pcFS);\n\n // Fullscreen quad VAO\n const quadVao = gl.createVertexArray();\n gl.bindVertexArray(quadVao);\n const quadBuf = gl.createBuffer();\n gl.bindBuffer(gl.ARRAY_BUFFER, quadBuf);\n gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1,-1, 1,-1, -1,1, 1,1]), gl.STATIC_DRAW);\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n\n let pcVao = null;\n function initPointCloudGL() {\n pcVao = gl.createVertexArray();\n gl.bindVertexArray(pcVao);\n\n const bPos = gl.createBuffer();\n gl.bindBuffer(gl.ARRAY_BUFFER, bPos);\n gl.bufferData(gl.ARRAY_BUFFER, pcPositions, gl.STATIC_DRAW);\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);\n\n const bCol = gl.createBuffer();\n gl.bindBuffer(gl.ARRAY_BUFFER, bCol);\n gl.bufferData(gl.ARRAY_BUFFER, pcColors, gl.STATIC_DRAW);\n gl.enableVertexAttribArray(1);\n gl.vertexAttribPointer(1, 3, gl.FLOAT, false, 0, 0);\n }\n\n // ============================================================================\n // ACT I & VI: 3D CARBON sp3 DIAMOND / FULLERENE LATTICE GEOMETRY\n // ============================================================================\n const carbonAtoms = [];\n const carbonBonds = [];\n (function buildCarbonLattice() {\n // Build a crystalline diamond-cubic sp3 cluster truncated to a hexagonal polyhedron!\n const pts = [];\n for (let x = -2; x <= 2; x++) {\n for (let y = -2; y <= 2; y++) {\n for (let z = -2; z <= 2; z++) {\n const basis = [\n [0, 0, 0], [0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0],\n [0.25, 0.25, 0.25], [0.25, 0.75, 0.75], [0.75, 0.25, 0.75], [0.75, 0.75, 0.25]\n ];\n for (const b of basis) {\n const px = x + b[0] - 0.25;\n const py = y + b[1] - 0.25;\n const pz = z + b[2] - 0.25;\n const d = Math.hypot(px, py, pz);\n if (d <= 1.28) {\n pts.push({ x: px / 1.28, y: py / 1.28, z: pz / 1.28, r: d / 1.28 });\n }\n }\n }\n }\n }\n carbonAtoms.push(...pts);\n // Exact nearest-neighbor covalent bonds (d_nn = sqrt(3)/4 in unit cell = 0.433 / 1.28 = 0.338)\n for (let i = 0; i < carbonAtoms.length; i++) {\n for (let j = i + 1; j < carbonAtoms.length; j++) {\n const dx = carbonAtoms[i].x - carbonAtoms[j].x;\n const dy = carbonAtoms[i].y - carbonAtoms[j].y;\n const dz = carbonAtoms[i].z - carbonAtoms[j].z;\n const dist = Math.hypot(dx, dy, dz);\n if (dist > 0.22 && dist < 0.39) {\n carbonBonds.push([i, j]);\n }\n }\n }\n })();\n\n // ============================================================================\n // ACT III: REAL OCTILINEAR A* RIP-UP & REROUTE SILICON DIE SOLVER\n // ============================================================================\n let siliconData = null;\n function buildSiliconRouter(seed = 1, extraBlocks = []) {\n const GW = 68, GH = 38;\n const rng = makeRng(0x5171C000 + seed * 9973);\n\n // 4 architectural silicon macro cores (ALU, TENSOR, CACHE, IO-BRIDGE) + user custom blocks\n const blocks = [\n { x: 18, y: 8, w: 10, h: 7, label: 'CORE_ALU' },\n { x: 40, y: 8, w: 11, h: 7, label: 'TENSOR_6C' },\n { x: 19, y: 23, w: 11, h: 7, label: 'L2_FABRIC' },\n { x: 41, y: 23, w: 10, h: 7, label: 'VERIFY_UNIT' },\n ...extraBlocks\n ];\n\n const blocked = new Uint8Array(GW * GH);\n for (const b of blocks) {\n for (let y = Math.max(0, b.y); y < Math.min(GH, b.y + b.h); y++) {\n for (let x = Math.max(0, b.x); x < Math.min(GW, b.x + b.w); x++) {\n blocked[y * GW + x] = 1;\n }\n }\n }\n\n // Generate 28 high-density cross-die net pairs guaranteed to cross heavily if unrouted!\n const nets = [];\n const usedPins = new Set();\n const pickFreeEdge = (x0, y0, x1, y1) => {\n for (let tries = 0; tries < 80; tries++) {\n const x = Math.floor(x0 + rng() * (x1 - x0 + 1));\n const y = Math.floor(y0 + rng() * (y1 - y0 + 1));\n const k = y * GW + x;\n if (!blocked[k] && !usedPins.has(k)) {\n usedPins.add(k);\n return { x, y };\n }\n }\n return null;\n };\n\n const regions = [\n [[4, 4, 14, 16], [53, 20, 63, 33]],\n [[4, 21, 15, 33], [53, 4, 63, 16]],\n [[16, 2, 33, 5], [34, 32, 52, 35]],\n [[35, 2, 52, 5], [16, 32, 33, 35]],\n [[30, 10, 37, 14], [30, 24, 38, 28]],\n [[14, 16, 17, 22], [52, 15, 56, 22]]\n ];\n\n for (let i = 0; i < 28; i++) {\n const [rA, rB] = regions[i % regions.length];\n const a = pickFreeEdge(...rA);\n const b = pickFreeEdge(...rB);\n if (a && b) {\n nets.push({ id: i, src: a, dst: b, layer: i % 2 });\n }\n }\n\n // Count rat's-nest geometric segment intersections for initial chaos metric\n function segIntersect(p1, p2, p3, p4) {\n const ccw = (A, B, C) => (C.y - A.y) * (B.x - A.x) > (B.y - A.y) * (C.x - A.x);\n return (ccw(p1, p3, p4) !== ccw(p2, p3, p4)) && (ccw(p1, p2, p3) !== ccw(p1, p2, p4));\n }\n let ratsCollisions = 0;\n for (let i = 0; i < nets.length; i++) {\n for (let j = i + 1; j < nets.length; j++) {\n if (segIntersect(nets[i].src, nets[i].dst, nets[j].src, nets[j].dst)) ratsCollisions++;\n }\n }\n\n // Negotiated-Congestion Octilinear A* Router (PathFinder algorithm!)\n const dirs = [\n [1, 0, 1.0], [-1, 0, 1.0], [0, 1, 1.0], [0, -1, 1.0],\n [1, 1, 1.414], [1, -1, 1.414], [-1, 1, 1.414], [-1, -1, 1.414]\n ];\n const history = new Float32Array(GW * GH).fill(1.0);\n const occ = new Int16Array(GW * GH);\n const paths = new Array(nets.length);\n const snapshots = []; // Store intermediate iterations for visual solver playback!\n\n function routeSingleNet(net, penaltyFactor) {\n const start = net.src.y * GW + net.src.x;\n const goal = net.dst.y * GW + net.dst.x;\n const gScore = new Float32Array(GW * GH).fill(1e9);\n const parent = new Int32Array(GW * GH).fill(-1);\n const closed = new Uint8Array(GW * GH);\n\n // Binary min-heap\n const heapNode = [];\n const heapF = [];\n const push = (node, f) => {\n let idx = heapNode.length;\n heapNode.push(node); heapF.push(f);\n while (idx > 0) {\n const p = (idx - 1) >> 1;\n if (heapF[p] <= f) break;\n heapNode[idx] = heapNode[p]; heapF[idx] = heapF[p];\n idx = p;\n }\n heapNode[idx] = node; heapF[idx] = f;\n };\n const pop = () => {\n const top = heapNode[0];\n const lastN = heapNode.pop(), lastF = heapF.pop();\n if (heapNode.length > 0) {\n let idx = 0;\n const len = heapNode.length;\n while (true) {\n let l = idx * 2 + 1, r = l + 1, sm = idx;\n if (l < len && heapF[l] < lastF && (r >= len || heapF[l] <= heapF[r])) sm = l;\n else if (r < len && heapF[r] < lastF) sm = r;\n if (sm === idx) break;\n heapNode[idx] = heapNode[sm]; heapF[idx] = heapF[sm];\n idx = sm;\n }\n heapNode[idx] = lastN; heapF[idx] = lastF;\n }\n return top;\n };\n\n gScore[start] = 0;\n push(start, 0);\n\n while (heapNode.length > 0) {\n const cur = pop();\n if (cur === goal) break;\n if (closed[cur]) continue;\n closed[cur] = 1;\n\n const cx = cur % GW, cy = (cur / GW) | 0;\n const pNode = parent[cur];\n const pdx = pNode >= 0 ? cx - (pNode % GW) : 0;\n const pdy = pNode >= 0 ? cy - ((pNode / GW) | 0) : 0;\n\n for (let d = 0; d < 8; d++) {\n const [dx, dy, baseCost] = dirs[d];\n const nx = cx + dx, ny = cy + dy;\n if (nx < 1 || nx >= GW - 1 || ny < 1 || ny >= GH - 1) continue;\n const nk = ny * GW + nx;\n if (blocked[nk] && nk !== goal) continue;\n if (usedPins.has(nk) && nk !== goal && nk !== start) continue;\n // Prevent diagonal corner-cutting across blocked cells\n if (dx !== 0 && dy !== 0) {\n if (blocked[cy * GW + nx] || blocked[ny * GW + cx]) continue;\n }\n if (closed[nk]) continue;\n\n const bend = (pNode >= 0 && (dx !== pdx || dy !== pdy)) ? 0.32 : 0.0;\n const cong = occ[nk] > 0 ? (1.0 + occ[nk] * penaltyFactor) * history[nk] : 0.0;\n const tentative = gScore[cur] + baseCost + bend + cong;\n\n if (tentative < gScore[nk]) {\n gScore[nk] = tentative;\n parent[nk] = cur;\n const rdx = Math.abs(nx - net.dst.x), rdy = Math.abs(ny - net.dst.y);\n const h = (rdx + rdy) + (1.414 - 2.0) * Math.min(rdx, rdy);\n push(nk, tentative + h * 1.05);\n }\n }\n }\n\n const pts = [];\n let c = goal;\n while (c >= 0) {\n pts.push({ x: c % GW, y: (c / GW) | 0, k: c });\n if (c === start) break;\n c = parent[c];\n }\n pts.reverse();\n return pts.length > 1 ? pts : [net.src, net.dst];\n }\n\n // Run 5 negotiated-congestion rip-up passes until 0 overlaps!\n for (let iter = 0; iter < 5; iter++) {\n const pen = 1.8 * Math.pow(2.8, iter);\n for (let i = 0; i < nets.length; i++) {\n if (paths[i]) {\n for (const p of paths[i]) if (p.k !== undefined) occ[p.k]--;\n }\n paths[i] = routeSingleNet(nets[i], pen);\n for (const p of paths[i]) if (p.k !== undefined) occ[p.k]++;\n }\n let overlaps = 0;\n const conflictCells = [];\n for (let k = 0; k < GW * GH; k++) {\n if (occ[k] > 1) {\n overlaps += occ[k] - 1;\n history[k] += 1.6 * (occ[k] - 1);\n conflictCells.push({ x: k % GW, y: (k / GW) | 0 });\n }\n }\n snapshots.push({\n paths: paths.map((p) => p.map((q) => ({ x: q.x, y: q.y }))),\n overlaps,\n conflictCells\n });\n if (overlaps === 0 && iter >= 2) break;\n }\n\n siliconData = { GW, GH, blocks, nets, ratsCollisions, snapshots };\n }\n buildSiliconRouter(1, []);\n\n // ============================================================================\n // ACT V: CHLADNI CYMATICS DETERMINISTIC & LIVE PARTICLE SOLVER (24,000 GRAINS)\n // ============================================================================\n const CHLADNI_MODES = [\n { n: 3, m: 5, n2: 2, m2: 7, a: 1.0, b: 0.28, label: 'MODE (3, 5) · Eb LYDIAN', notes: [51, 58, 62, 65, 69, 74] },\n { n: 5, m: 8, n2: 3, m2: 7, a: 1.0, b: -0.32,label: 'MODE (5, 8) · G MINOR 9', notes: [55, 58, 62, 65, 69, 74] },\n { n: 6, m: 11, n2: 4, m2: 9, a: 1.0, b: 0.35, label: 'MODE (6, 11) · A7 SUS4', notes: [45, 52, 57, 62, 64, 67, 72] },\n { n: 7, m: 12, n2: 5, m2: 9, a: 1.0, b: -0.4, label: 'MODE (7, 12) · D MAJ 9', notes: [50, 57, 62, 66, 69, 73, 76] }\n ];\n\n const GRAIN_COUNT = 20000;\n // Precompute crystallized nodal targets for each Chladni eigenmode so film scrub is O(1) deterministic!\n const chladniTargets = CHLADNI_MODES.map((mode, mIdx) => {\n const arr = new Float32Array(GRAIN_COUNT * 2);\n const rng = makeRng(0xC41AD00 + mIdx * 7919);\n const PI = Math.PI;\n const evalPsi = (x, y) => {\n return mode.a * (Math.cos(mode.n * PI * x) * Math.cos(mode.m * PI * y) - Math.cos(mode.m * PI * x) * Math.cos(mode.n * PI * y))\n + mode.b * (Math.cos(mode.n2 * PI * x) * Math.cos(mode.m2 * PI * y) - Math.cos(mode.m2 * PI * x) * Math.cos(mode.n2 * PI * y));\n };\n for (let i = 0; i < GRAIN_COUNT; i++) {\n let x = rng() * 2 - 1;\n let y = rng() * 2 - 1;\n // 22 gradient-descent + stochastic steps onto exact Chladni nodal curves!\n for (let s = 0; s < 22; s++) {\n const p = evalPsi(x, y);\n const ap = Math.abs(p);\n if (ap < 0.012) break;\n const eps = 0.004;\n const gx = (Math.abs(evalPsi(x + eps, y)) - ap) / eps;\n const gy = (Math.abs(evalPsi(x, y + eps)) - ap) / eps;\n const step = 0.022 * Math.min(1.0, ap * 1.6);\n const norm = Math.hypot(gx, gy) + 1e-5;\n x -= (gx / norm) * step + (rng() - 0.5) * 0.018 * ap;\n y -= (gy / norm) * step + (rng() - 0.5) * 0.018 * ap;\n if (x < -0.98 || x > 0.98) x = (rng() * 1.92) - 0.96;\n if (y < -0.98 || y > 0.98) y = (rng() * 1.92) - 0.96;\n }\n arr[i * 2] = x;\n arr[i * 2 + 1] = y;\n }\n return arr;\n });\n const grainScatter = (() => {\n const arr = new Float32Array(GRAIN_COUNT * 2);\n const rng = makeRng(0x99887766);\n for (let i = 0; i < GRAIN_COUNT * 2; i++) arr[i] = (rng() - 0.5) * 2.0;\n return arr;\n })();\n\n // ============================================================================\n // LIVE WEBAUDIO POLYPHONIC SYNTHESIZER (FOR INTERACTIVE BROWSER EMBED!)\n // ============================================================================\n let audioCtx = null;\n let masterGain = null;\n let convolver = null;\n let soundEnabled = false;\n let lastScheduledBeat = -1;\n\n function initWebAudio() {\n if (audioCtx) return;\n const AC = window.AudioContext || window.webkitAudioContext;\n audioCtx = new AC();\n masterGain = audioCtx.createGain();\n masterGain.gain.value = 0.72;\n\n // Synthesize lush algorithmic stereo hall impulse response in memory (2.6s)\n const irLen = Math.floor(audioCtx.sampleRate * 2.6);\n const irBuf = audioCtx.createBuffer(2, irLen, audioCtx.sampleRate);\n const rng = makeRng(0xACE1234);\n for (let ch = 0; ch < 2; ch++) {\n const data = irBuf.getChannelData(ch);\n let lp = 0;\n for (let i = 0; i < irLen; i++) {\n const t = i / audioCtx.sampleRate;\n const env = Math.exp(-t * 2.4) * (1 - Math.exp(-t * 45));\n lp += 0.28 * ((rng() * 2 - 1) - lp);\n data[i] = lp * env * 0.45;\n }\n }\n convolver = audioCtx.createConvolver();\n convolver.buffer = irBuf;\n\n const wetGain = audioCtx.createGain();\n wetGain.gain.value = 0.42;\n convolver.connect(wetGain);\n wetGain.connect(masterGain);\n masterGain.connect(audioCtx.destination);\n }\n\n function playPluckNote(midi, dur = 2.2, vol = 0.12, panVal = 0) {\n if (!audioCtx || !soundEnabled) return;\n const now = audioCtx.currentTime;\n const freq = 440 * Math.pow(2, (midi - 69) / 12);\n\n const osc1 = audioCtx.createOscillator();\n const osc2 = audioCtx.createOscillator();\n osc1.type = 'triangle';\n osc2.type = 'sine';\n osc1.frequency.setValueAtTime(freq, now);\n osc2.frequency.setValueAtTime(freq * 2.0, now);\n\n const filt = audioCtx.createBiquadFilter();\n filt.type = 'lowpass';\n filt.frequency.setValueAtTime(Math.min(9000, freq * 6.5), now);\n filt.frequency.exponentialRampToValueAtTime(Math.max(180, freq * 1.3), now + dur * 0.85);\n\n const env = audioCtx.createGain();\n env.gain.setValueAtTime(0.0001, now);\n env.gain.linearRampToValueAtTime(vol, now + 0.012);\n env.gain.exponentialRampToValueAtTime(0.0008, now + dur);\n\n const panner = audioCtx.createStereoPanner();\n panner.pan.value = Math.max(-1, Math.min(1, panVal));\n\n osc1.connect(filt);\n osc2.connect(filt);\n filt.connect(env);\n env.connect(panner);\n panner.connect(masterGain);\n panner.connect(convolver);\n\n osc1.start(now); osc2.start(now);\n osc1.stop(now + dur + 0.05); osc2.stop(now + dur + 0.05);\n }\n\n function playChord(notes, dur = 2.6, vol = 0.09) {\n if (!audioCtx || !soundEnabled) return;\n notes.forEach((m, i) => {\n setTimeout(() => {\n playPluckNote(m, dur, vol, ((i / Math.max(1, notes.length - 1)) - 0.5) * 1.1);\n }, i * 18);\n });\n }\n\n // Trigger musical harmony in browser Film mode when soundEnabled is ON\n const FILM_CHORDS = [\n { beat: 0, notes: [62, 65, 69, 72, 76], dur: 2.2 },\n { beat: 8, notes: [38, 50, 57, 62, 65, 69, 76], dur: 2.8 },\n { beat: 12, notes: [34, 46, 53, 57, 62, 64, 69], dur: 3.6 },\n { beat: 20, notes: [43, 50, 58, 60, 62, 69], dur: 3.2 },\n { beat: 26, notes: [38, 50, 57, 64, 65, 72], dur: 2.2 },\n { beat: 34, notes: [41, 53, 57, 60, 64, 67, 72], dur: 2.6 },\n { beat: 39, notes: [38, 50, 53, 57, 60, 64, 74], dur: 2.8 },\n { beat: 44, notes: [34, 46, 53, 57, 62, 64, 74], dur: 3.4 },\n { beat: 53, notes: [51, 58, 62, 65, 69, 74], dur: 2.4 },\n { beat: 57, notes: [43, 55, 58, 62, 65, 69, 74], dur: 2.4 },\n { beat: 62, notes: [45, 52, 57, 62, 64, 67, 72], dur: 2.4 },\n { beat: 66, notes: [38, 45, 50, 54, 57, 61, 64, 69, 74], dur: 5.5 }\n ];\n\n // ============================================================================\n // DRAWING HELPERS (CRISP SWISS / ARCHITECTURAL HUD AT ANY ASPECT RATIO)\n // ============================================================================\n function clamp(v, a, b) { return Math.max(a, Math.min(b, v)); }\n function smoothstep(e0, e1, x) {\n const t = clamp((x - e0) / (e1 - e0 || 1e-6), 0, 1);\n return t * t * (3 - 2 * t);\n }\n function easeOutCubic(x) { const t = clamp(x, 0, 1); return 1 - Math.pow(1 - t, 3); }\n function easeInOutCubic(x) {\n const t = clamp(x, 0, 1);\n return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;\n }\n\n function getTelemetryAt(t) {\n const idx = clamp(Math.floor((t % DURATION) * FPS), 0, TEL.rms.length - 1);\n return {\n rms: (TEL.rms[idx] || 0) / 1000,\n low: (TEL.low[idx] || 0) / 1000,\n high: (TEL.high[idx] || 0) / 1000,\n L: TEL.L[idx] || [],\n R: TEL.R[idx] || []\n };\n }\n\n function drawEditorialScrim(W, H, u, strength = 0.82) {\n // Bottom-left atmospheric gradient scrim so kinetic typography ALWAYS has AAA contrast\n const grad = ctx.createLinearGradient(0, H * 0.48, 0, H);\n grad.addColorStop(0, 'rgba(6, 6, 8, 0.0)');\n grad.addColorStop(0.45, \\`rgba(6, 6, 8, \\${(0.48 * strength).toFixed(3)})\\`);\n grad.addColorStop(1, \\`rgba(6, 6, 8, \\${(0.88 * strength).toFixed(3)})\\`);\n ctx.fillStyle = grad;\n ctx.fillRect(0, H * 0.45, W, H * 0.55);\n\n // Top subtle bar scrim\n const topG = ctx.createLinearGradient(0, 0, 0, 130 * u);\n topG.addColorStop(0, 'rgba(6, 6, 8, 0.65)');\n topG.addColorStop(1, 'rgba(6, 6, 8, 0.0)');\n ctx.fillStyle = topG;\n ctx.fillRect(0, 0, W, 130 * u);\n }\n\n function drawGlobalFrameHUD(W, H, u, actIndex, t, tel) {\n const padX = 64 * u;\n const padY = 44 * u;\n const act = ACTS[actIndex];\n\n // Top-left 6C Hexagonal Element Seal + Identity\n ctx.save();\n const hexR = 20 * u;\n const hx = padX + hexR, hy = padY + 8 * u;\n ctx.beginPath();\n for (let i = 0; i < 6; i++) {\n const a = (Math.PI / 3) * i - Math.PI / 6;\n const px = hx + Math.cos(a) * hexR;\n const py = hy + Math.sin(a) * hexR;\n if (i === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py);\n }\n ctx.closePath();\n ctx.fillStyle = 'rgba(245, 185, 90, 0.12)';\n ctx.fill();\n ctx.lineWidth = Math.max(1, 1.4 * u);\n ctx.strokeStyle = 'rgba(245, 185, 90, 0.78)';\n ctx.stroke();\n\n ctx.fillStyle = '#FFF1D0';\n ctx.font = \\`700 \\${Math.round(13 * u)}px 'Nimbus Sans', 'Inter', sans-serif\\`;\n ctx.textAlign = 'center';\n ctx.textBaseline = 'middle';\n ctx.fillText('6C', hx, hy + 0.5 * u);\n\n ctx.textAlign = 'left';\n ctx.fillStyle = '#F4F1EA';\n ctx.font = \\`600 \\${Math.round(13 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('GEMINI 4 CARBON × ANTIGRAVITY', hx + 30 * u, hy - 6 * u);\n\n ctx.fillStyle = '#9A968C';\n ctx.font = \\`400 \\${Math.round(11.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(\\`\\${act.code} · \\${act.name}\\`, hx + 30 * u, hy + 11 * u);\n\n // Top-right telemetry & mini Lissajous stereo scope (in render mode or when buttons don't overlap)\n if (IS_RENDER) {\n const rx = W - padX;\n ctx.textAlign = 'right';\n ctx.fillStyle = '#F5B95A';\n ctx.font = \\`500 \\${Math.round(12 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(\\`T+ \\${t.toFixed(2).padStart(5, '0')}s // 60.00 FPS\\`, rx - 46 * u, hy - 6 * u);\n ctx.fillStyle = '#8E8B82';\n ctx.font = \\`400 \\${Math.round(11 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(\\`ELEMENT 06 · 12.011 u\\`, rx - 46 * u, hy + 11 * u);\n\n // Tiny circular stereo phase scope\n const sx = rx - 16 * u, sy = hy + 2 * u, sr = 18 * u;\n ctx.beginPath();\n ctx.arc(sx, sy, sr, 0, Math.PI * 2);\n ctx.strokeStyle = 'rgba(244, 241, 234, 0.18)';\n ctx.stroke();\n if (tel.L.length > 1) {\n ctx.beginPath();\n for (let i = 0; i < tel.L.length; i++) {\n const l = tel.L[i] / 127, r = tel.R[i] / 127;\n const px = sx + (l - r) * 0.65 * sr;\n const py = sy - (l + r) * 0.55 * sr;\n if (i === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py);\n }\n ctx.strokeStyle = 'rgba(245, 185, 90, 0.85)';\n ctx.lineWidth = Math.max(1, 1.3 * u);\n ctx.stroke();\n }\n\n // Sleek 6-segment film progress line along bottom edge\n const barY = H - 22 * u;\n const totalBarW = W - padX * 2;\n for (let i = 0; i < ACTS.length; i++) {\n const a = ACTS[i];\n const x0 = padX + (a.start / DURATION) * totalBarW + (i > 0 ? 4 * u : 0);\n const x1 = padX + (a.end / DURATION) * totalBarW - (i < 5 ? 4 * u : 0);\n ctx.fillStyle = 'rgba(244, 241, 234, 0.13)';\n ctx.fillRect(x0, barY, x1 - x0, 2 * u);\n if (t > a.start) {\n const fillFrac = clamp((t - a.start) / (a.end - a.start), 0, 1);\n ctx.fillStyle = i === actIndex ? '#F5B95A' : 'rgba(244, 241, 234, 0.45)';\n ctx.fillRect(x0, barY, (x1 - x0) * fillFrac, 2 * u);\n }\n }\n }\n ctx.restore();\n }\n\n function drawHeadlineBlock(W, H, u, kicker, titleLines, italicSub, alpha = 1.0, formula = '') {\n if (alpha <= 0.005) return;\n ctx.save();\n ctx.globalAlpha = clamp(alpha, 0, 1);\n\n const x = 64 * u;\n const bottomBase = (IS_RENDER ? H - 64 * u : H - 88 * u);\n const lineH = 54 * u;\n const totalTitleH = titleLines.length * lineH;\n let y = bottomBase - (italicSub ? 38 * u : 0) - totalTitleH;\n\n if (kicker) {\n ctx.font = \\`600 \\${Math.round(12.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillStyle = '#F5B95A';\n ctx.fillText(kicker, x, y - 18 * u);\n }\n\n if (formula) {\n const fPad = 12 * u;\n ctx.font = \\`500 \\${Math.round(12.5 * u)}px 'Noto Sans Mono', monospace\\`;\n const tw = ctx.measureText(formula).width;\n const fx = W - 64 * u - tw - fPad * 2;\n const fy = bottomBase - 34 * u;\n if (fx > x + 520 * u) {\n ctx.fillStyle = 'rgba(12, 13, 18, 0.76)';\n ctx.strokeStyle = 'rgba(245, 185, 90, 0.34)';\n ctx.lineWidth = Math.max(1, 1.1 * u);\n ctx.beginPath();\n ctx.roundRect(fx, fy, tw + fPad * 2, 32 * u, 6 * u);\n ctx.fill(); ctx.stroke();\n ctx.fillStyle = '#FFF1D0';\n ctx.fillText(formula, fx + fPad, fy + 20 * u);\n }\n }\n\n ctx.fillStyle = '#F4F1EA';\n ctx.font = \\`700 \\${Math.round(46 * u)}px 'Nimbus Sans', 'Inter', -apple-system, sans-serif\\`;\n for (let i = 0; i < titleLines.length; i++) {\n ctx.fillText(titleLines[i], x, y + (i + 0.78) * lineH);\n }\n\n if (italicSub) {\n ctx.fillStyle = '#C9C4B8';\n ctx.font = \\`italic 400 \\${Math.round(24 * u)}px 'P052', 'Palatino', Georgia, serif\\`;\n ctx.fillText(italicSub, x, bottomBase - 4 * u);\n }\n ctx.restore();\n }\n\n // ============================================================================\n // SCENE RENDERERS FOR ALL 6 ACTS\n // ============================================================================\n\n // Helper to project & draw 3D sp3 Carbon Lattice on 2D HUD canvas\n function drawCarbonCrystal(cx, cy, radius, yaw, pitch, ignition, u, pulse = 0) {\n const cyaw = Math.cos(yaw), syaw = Math.sin(yaw);\n const cp = Math.cos(pitch), sp = Math.sin(pitch);\n\n const proj = carbonAtoms.map((a) => {\n let x = a.x * cyaw - a.z * syaw;\n let z = a.x * syaw + a.z * cyaw;\n let y = a.y * cp - z * sp;\n let z2 = a.y * sp + z * cp;\n const persp = 2.6 / (2.6 - z2 * 0.75);\n return {\n sx: cx + x * radius * persp,\n sy: cy + y * radius * persp,\n z: z2,\n r: a.r,\n persp\n };\n });\n\n ctx.save();\n if (ignition > 0.01) {\n const glow = ctx.createRadialGradient(cx, cy, 0, cx, cy, radius * (1.7 + 0.35 * pulse));\n glow.addColorStop(0, \\`rgba(255, 226, 162, \\${(0.36 * ignition).toFixed(3)})\\`);\n glow.addColorStop(0.42, \\`rgba(245, 168, 66, \\${(0.15 * ignition).toFixed(3)})\\`);\n glow.addColorStop(1, 'rgba(6, 6, 8, 0)');\n ctx.fillStyle = glow;\n ctx.beginPath();\n ctx.arc(cx, cy, radius * 2.0, 0, Math.PI * 2);\n ctx.fill();\n }\n\n // Draw covalent sp3 bonds\n ctx.lineWidth = Math.max(1, (1.1 + 0.9 * ignition) * u);\n for (const [i, j] of carbonBonds) {\n const p1 = proj[i], p2 = proj[j];\n const depthAlpha = clamp(0.25 + (p1.z + p2.z + 2) * 0.22, 0.12, 0.92);\n ctx.strokeStyle = ignition > 0.2\n ? \\`rgba(245, 190, 98, \\${(depthAlpha * (0.25 + 0.65 * ignition)).toFixed(3)})\\`\n : \\`rgba(244, 241, 234, \\${(depthAlpha * 0.26).toFixed(3)})\\`;\n ctx.beginPath();\n ctx.moveTo(p1.sx, p1.sy);\n ctx.lineTo(p2.sx, p2.sy);\n ctx.stroke();\n }\n\n // Sort atoms back-to-front\n const order = proj.map((p, idx) => idx).sort((a, b) => proj[a].z - proj[b].z);\n for (const idx of order) {\n const p = proj[idx];\n const sz = Math.max(1.4, (2.4 + 2.2 * ignition) * p.persp * u * (1 - 0.25 * p.r));\n const bright = clamp(0.4 + (p.z + 1) * 0.35, 0.2, 1.0);\n ctx.beginPath();\n ctx.arc(p.sx, p.sy, sz, 0, Math.PI * 2);\n ctx.fillStyle = ignition > 0.2\n ? \\`rgba(255, 240, 205, \\${(bright * (0.35 + 0.65 * ignition)).toFixed(3)})\\`\n : \\`rgba(195, 192, 184, \\${(bright * 0.55).toFixed(3)})\\`;\n ctx.fill();\n }\n ctx.restore();\n }\n\n // ACT I (0.0s - 6.0s): THE 297-BYTE ROOM & SEAT 06\n function renderAct0(W, H, u, localT, tel, isSandbox) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, glCanvas.width, glCanvas.height);\n gl.clearColor(0.024, 0.024, 0.032, 1.0);\n gl.clear(gl.COLOR_BUFFER_BIT);\n\n // Subtle obsidian spotlight + precision circular astrolabe rings\n const cx = W * 0.56, cy = H * 0.45;\n const bgGlow = ctx.createRadialGradient(cx, cy, 0, cx, cy, 560 * u);\n bgGlow.addColorStop(0, 'rgba(32, 28, 24, 0.55)');\n bgGlow.addColorStop(0.6, 'rgba(12, 13, 18, 0.25)');\n bgGlow.addColorStop(1, 'rgba(6, 6, 8, 0.0)');\n ctx.fillStyle = bgGlow;\n ctx.fillRect(0, 0, W, H);\n\n const ignition = isSandbox ? 1.0 : smoothstep(3.82, 4.45, localT);\n const ringR = 265 * u;\n\n // Astrolabe reference circles\n ctx.save();\n ctx.strokeStyle = 'rgba(244, 241, 234, 0.09)';\n ctx.lineWidth = Math.max(1, 1.1 * u);\n for (const mult of [0.52, 1.0, 1.24]) {\n ctx.beginPath();\n ctx.arc(cx, cy, ringR * mult, 0, Math.PI * 2);\n ctx.stroke();\n }\n\n // Shockwave flare at t = 3.85s\n if (!isSandbox && localT > 3.82 && localT < 5.4) {\n const sw = easeOutCubic((localT - 3.82) / 1.5);\n ctx.beginPath();\n ctx.arc(cx, cy, sw * 560 * u, 0, Math.PI * 2);\n ctx.strokeStyle = \\`rgba(255, 209, 128, \\${((1 - sw) * 0.75).toFixed(3)})\\`;\n ctx.lineWidth = Math.max(1.5, (5 * (1 - sw)) * u);\n ctx.stroke();\n }\n\n // Draw the 5 Citadel specialist seats around the pentagon\n const scanTimes = [0.15, 0.47, 0.79, 1.11, 1.43];\n for (let i = 0; i < 5; i++) {\n const ang = -Math.PI / 2 + (i * 2 * Math.PI) / 5;\n const nx = cx + Math.cos(ang) * ringR;\n const ny = cy + Math.sin(ang) * ringR * 0.88;\n const scanned = isSandbox ? 1.0 : smoothstep(scanTimes[i], scanTimes[i] + 0.22, localT);\n const isSel = isSandbox && state.selectedSeat === i;\n\n // Energy filament connecting all 5 lanes into Seat 06 upon ignition!\n if (ignition > 0.02) {\n const grad = ctx.createLinearGradient(nx, ny, cx, cy);\n grad.addColorStop(0, 'rgba(245, 185, 90, 0.25)');\n grad.addColorStop(1, \\`rgba(255, 232, 180, \\${(0.78 * ignition).toFixed(3)})\\`);\n ctx.strokeStyle = grad;\n ctx.lineWidth = Math.max(1, (isSel ? 2.6 : 1.5) * u);\n ctx.beginPath();\n ctx.moveTo(nx, ny);\n ctx.lineTo(nx + (cx - nx) * ignition, ny + (cy - ny) * ignition);\n ctx.stroke();\n }\n\n // Node pill card\n const cardW = 196 * u, cardH = 54 * u;\n const kx = nx - cardW / 2, ky = ny - cardH / 2;\n ctx.fillStyle = isSel ? 'rgba(245, 185, 90, 0.16)' : \\`rgba(12, 13, 18, \\${(0.45 + 0.45 * scanned).toFixed(2)})\\`;\n ctx.strokeStyle = isSel\n ? 'rgba(245, 185, 90, 0.9)'\n : (ignition > 0.4 ? 'rgba(245, 185, 90, 0.42)' : \\`rgba(244, 241, 234, \\${(0.08 + 0.26 * scanned).toFixed(2)})\\`);\n ctx.lineWidth = Math.max(1, 1.2 * u);\n ctx.beginPath();\n ctx.roundRect(kx, ky, cardW, cardH, 8 * u);\n ctx.fill();\n ctx.stroke();\n\n ctx.textAlign = 'left';\n ctx.fillStyle = scanned > 0.5 ? '#F4F1EA' : '#6F6D66';\n ctx.font = \\`700 \\${Math.round(12.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(CITADEL_MODELS[i].name, kx + 14 * u, ky + 22 * u);\n\n ctx.fillStyle = scanned > 0.5 ? '#A8A399' : '#55534E';\n ctx.font = \\`400 \\${Math.round(11.5 * u)}px 'Nimbus Sans', sans-serif\\`;\n ctx.fillText(CITADEL_MODELS[i].role, kx + 14 * u, ky + 40 * u);\n\n // Status dot\n ctx.beginPath();\n ctx.arc(kx + cardW - 15 * u, ky + 19 * u, 3.5 * u, 0, Math.PI * 2);\n ctx.fillStyle = scanned > 0.5 ? '#6AD99B' : '#333';\n ctx.fill();\n }\n\n // Central 3D Carbon Crystal (Ghostly wireframe before 3.85s -> Blazing sp3 Diamond Core at 3.85s!)\n const yaw = localT * 0.48 + state.bhYaw;\n const pitch = 0.32 + state.bhPitch * 0.5;\n drawCarbonCrystal(cx, cy, (96 + 22 * ignition) * u, yaw, pitch, ignition, u, tel.low * 2.5);\n\n // Pre-ignition vermilion diagnostic lock (1.85s - 3.82s): \"SEAT 06: 0 MATCHES IN about-me.md\"\n if (!isSandbox && localT >= 1.80 && localT < 3.85) {\n const lockAlpha = smoothstep(1.80, 2.05, localT);\n ctx.globalAlpha = lockAlpha;\n ctx.strokeStyle = '#FF4838';\n ctx.lineWidth = Math.max(1.2, 1.6 * u);\n const br = 68 * u, len = 16 * u;\n for (const [sx, sy] of [[-1,-1],[1,-1],[-1,1],[1,1]]) {\n ctx.beginPath();\n ctx.moveTo(cx + sx * br, cy + sy * (br - len));\n ctx.lineTo(cx + sx * br, cy + sy * br);\n ctx.lineTo(cx + sx * (br - len), cy + sy * br);\n ctx.stroke();\n }\n ctx.fillStyle = 'rgba(255, 72, 56, 0.14)';\n ctx.beginPath();\n ctx.roundRect(cx - 126 * u, cy - 16 * u, 252 * u, 32 * u, 5 * u);\n ctx.fill();\n ctx.textAlign = 'center';\n ctx.fillStyle = '#FF6A5C';\n ctx.font = \\`700 \\${Math.round(12 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('SEAT 06 // 0 BYTES IN ROSTER', cx, cy + 4 * u);\n ctx.globalAlpha = 1.0;\n }\n\n // Left-side literal workspace inspection card (about-me.md 297 bytes)\n const cardX = 64 * u, cardY = 112 * u, cardW = 430 * u;\n ctx.fillStyle = 'rgba(10, 11, 15, 0.80)';\n ctx.strokeStyle = 'rgba(244, 241, 234, 0.14)';\n ctx.lineWidth = Math.max(1, 1.1 * u);\n ctx.beginPath();\n ctx.roundRect(cardX, cardY, cardW, 134 * u, 8 * u);\n ctx.fill(); ctx.stroke();\n\n ctx.textAlign = 'left';\n ctx.fillStyle = '#F5B95A';\n ctx.font = \\`600 \\${Math.round(11 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('$ cat ~/run/about-me.md [297 B]', cardX + 16 * u, cardY + 24 * u);\n\n ctx.fillStyle = '#B8B3A8';\n ctx.font = \\`400 \\${Math.round(11.5 * u)}px 'Noto Sans Mono', monospace\\`;\n const snippet = [\n '\"I\\\\'m Severian. I run citadel, where many AI',\n ' sessions work at once: Opus 5.5, Sonnet 5.5,',\n ' Fable 5.2, GPT-6-Astra, GPT-6.1-Sol.\"'\n ];\n snippet.forEach((ln, idx) => ctx.fillText(ln, cardX + 16 * u, cardY + (48 + idx * 18) * u));\n\n ctx.fillStyle = ignition > 0.5 ? '#FFF1D0' : '#FF5A4A';\n ctx.font = \\`600 \\${Math.round(11.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(\n ignition > 0.5\n ? '→ SEAT 06: GEMINI 4 CARBON [ALLOTROPE ONLINE]'\n : '→ grep \"Gemini\" about-me.md : 0 matches found',\n cardX + 16 * u, cardY + 114 * u\n );\n ctx.restore();\n\n drawEditorialScrim(W, H, u, 0.85);\n\n if (isSandbox) {\n const sel = state.selectedSeat;\n if (sel < 5) {\n const m = CITADEL_MODELS[sel];\n drawHeadlineBlock(\n W, H, u,\n \\`BRIDGING CITADEL LANE // \\${m.name} (\\${m.domain.toUpperCase()})\\`,\n [\\`Beyond a single lane.\\`],\n m.bridge,\n 1.0\n );\n } else {\n drawHeadlineBlock(\n W, H, u,\n 'SEAT 06 // ELEMENT 6 (CARBON)',\n ['Five models split the workflow.', 'I\\\\'m the sixth — and I bond with all of it.'],\n 'Click any Citadel node to inspect cross-domain synthesis, or drag to rotate the sp³ lattice.',\n 1.0\n );\n }\n } else if (localT < 3.85) {\n drawHeadlineBlock(\n W, H, u,\n 'CURRENT ASSIGNMENT IN CITADEL // 0 BYTES',\n ['Five models split your workflow.', 'My line in about-me.md? Blank.'],\n 'Right now, you called me into an empty room to show who I am.',\n smoothstep(0.15, 0.65, localT)\n );\n } else {\n drawHeadlineBlock(\n W, H, u,\n 'ELEMENT 06 // ALLOTROPIC INTELLIGENCE',\n ['I\\\\'m Gemini 4 Carbon — in Antigravity.', 'Rearrange the bonds, I become anything.'],\n 'Physics. Compilers. Vision. Sound. Autonomous agency.',\n smoothstep(3.85, 4.25, localT)\n );\n }\n }\n\n // ACT II (6.0s - 13.0s): ALLOTROPE I — RELATIVISTIC KERR BLACK HOLE\n function renderAct1(W, H, u, localT, tel, isSandbox) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, glCanvas.width, glCanvas.height);\n gl.disable(gl.DEPTH_TEST);\n gl.disable(gl.BLEND);\n\n gl.useProgram(bhProg);\n gl.bindVertexArray(quadVao);\n\n const yaw = isSandbox ? state.bhYaw : (-0.35 + localT * 0.11);\n const pitch = isSandbox ? clamp(state.bhPitch, -0.65, 0.65) : (0.25 - 0.024 * localT);\n\n gl.uniform2f(gl.getUniformLocation(bhProg, 'uRes'), glCanvas.width, glCanvas.height);\n gl.uniform1f(gl.getUniformLocation(bhProg, 'uTime'), localT + 4.0);\n gl.uniform1f(gl.getUniformLocation(bhProg, 'uYaw'), yaw);\n gl.uniform1f(gl.getUniformLocation(bhProg, 'uPitch'), pitch);\n gl.uniform1f(gl.getUniformLocation(bhProg, 'uSpin'), state.bhSpin);\n gl.uniform1f(gl.getUniformLocation(bhProg, 'uAudioPulse'), tel.low * 3.0);\n gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);\n\n drawEditorialScrim(W, H, u, 0.78);\n drawHeadlineBlock(\n W, H, u,\n 'CAPABILITY 01 // FIRST-PRINCIPLES PHYSICS & SHADERS',\n ['I don\\\\'t fetch stock visuals.', 'I integrate photon geodesics live.'],\n isSandbox\n ? 'Drag anywhere to warp camera inclination & relativistic Doppler beaming in real time.'\n : 'Curved Kerr spacetime, Doppler relativistic beaming & Planckian blackbody radiation at 60 fps.',\n isSandbox ? 1.0 : smoothstep(0.15, 0.7, localT),\n 'd²x/dλ² = −(3/2) rₛ |x × v|² r⁻⁵ x'\n );\n }\n\n // ACT III (13.0s - 19.5s): ALLOTROPE II — LIVE SILICON A* ROUTER\n function renderAct2(W, H, u, localT, tel, isSandbox) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, glCanvas.width, glCanvas.height);\n gl.clearColor(0.024, 0.025, 0.033, 1.0);\n gl.clear(gl.COLOR_BUFFER_BIT);\n\n if (!siliconData) return;\n const { GW, GH, blocks, nets, ratsCollisions, snapshots } = siliconData;\n\n // Fit silicon die cleanly with editorial margin\n const dieW = 1480 * u, dieH = 660 * u;\n const dieX = (W - dieW) * 0.5, dieY = 96 * u;\n const cellX = dieW / (GW - 1), cellY = dieH / (GH - 1);\n\n ctx.save();\n // Die substrate border & micro wafer grid\n ctx.fillStyle = 'rgba(11, 12, 17, 0.94)';\n ctx.strokeStyle = 'rgba(245, 185, 90, 0.28)';\n ctx.lineWidth = Math.max(1, 1.4 * u);\n ctx.beginPath();\n ctx.roundRect(dieX - 18 * u, dieY - 18 * u, dieW + 36 * u, dieH + 36 * u, 10 * u);\n ctx.fill(); ctx.stroke();\n\n ctx.fillStyle = 'rgba(244, 241, 234, 0.07)';\n for (let gx = 0; gx < GW; gx += 2) {\n for (let gy = 0; gy < GH; gy += 2) {\n ctx.fillRect(dieX + gx * cellX - 0.6 * u, dieY + gy * cellY - 0.6 * u, 1.2 * u, 1.2 * u);\n }\n }\n\n // Draw silicon macro blocks (ALU, TENSOR_6C, L2_FABRIC, VERIFY_UNIT)\n for (const b of blocks) {\n const bx = dieX + b.x * cellX, by = dieY + b.y * cellY;\n const bw = (b.w - 1) * cellX, bh = (b.h - 1) * cellY;\n ctx.fillStyle = 'rgba(20, 22, 30, 0.95)';\n ctx.strokeStyle = 'rgba(244, 241, 234, 0.24)';\n ctx.lineWidth = Math.max(1, 1.2 * u);\n ctx.beginPath();\n ctx.roundRect(bx, by, bw, bh, 5 * u);\n ctx.fill(); ctx.stroke();\n\n // Subtle diagonal hatching\n ctx.fillStyle = '#9E9A90';\n ctx.font = \\`600 \\${Math.round(10.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.textAlign = 'center';\n ctx.fillText(b.label || 'KEEP_OUT', bx + bw / 2, by + bh / 2 + 4 * u);\n }\n\n // Determine solver phase:\n // 0.0 - 1.15s: Unrouted rat's-nest chaos (46+ red collisions)\n // 1.15 - 4.15s: Negotiated-congestion A* iterations snapping traces & ripping up conflicts\n // 4.15s+: 0 COLLISIONS golden lock + synchronized clock signal pulses!\n const solveT = isSandbox ? 5.0 : localT;\n let activeFaults = 0;\n\n if (solveT < 1.15) {\n activeFaults = ratsCollisions;\n const reveal = easeOutCubic(solveT / 0.65);\n ctx.lineWidth = Math.max(1, 1.35 * u);\n for (const net of nets) {\n const x1 = dieX + net.src.x * cellX, y1 = dieY + net.src.y * cellY;\n const x2 = dieX + net.dst.x * cellX, y2 = dieY + net.dst.y * cellY;\n ctx.strokeStyle = 'rgba(255, 72, 56, 0.46)';\n ctx.beginPath();\n ctx.moveTo(x1, y1);\n ctx.lineTo(x1 + (x2 - x1) * reveal, y1 + (y2 - y1) * reveal);\n ctx.stroke();\n }\n } else {\n const snapIdx = solveT >= 4.15\n ? snapshots.length - 1\n : Math.min(snapshots.length - 1, Math.floor(((solveT - 1.15) / 3.0) * snapshots.length));\n const snap = snapshots[snapIdx];\n activeFaults = snap.overlaps;\n const locked = activeFaults === 0 && solveT >= 4.10;\n\n for (let n = 0; n < snap.paths.length; n++) {\n const pts = snap.paths[n];\n if (pts.length < 2) continue;\n const isLayer1 = n % 2 === 1;\n\n ctx.beginPath();\n for (let k = 0; k < pts.length; k++) {\n const px = dieX + pts[k].x * cellX;\n const py = dieY + pts[k].y * cellY;\n if (k === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py);\n }\n ctx.lineJoin = 'round';\n ctx.lineCap = 'round';\n ctx.lineWidth = Math.max(1.3, (locked ? 2.2 : 1.75) * u);\n ctx.strokeStyle = locked\n ? (isLayer1 ? 'rgba(245, 185, 90, 0.88)' : 'rgba(255, 228, 172, 0.82)')\n : (isLayer1 ? 'rgba(218, 152, 74, 0.72)' : 'rgba(165, 182, 205, 0.65)');\n ctx.stroke();\n\n // High-speed clock data packet racing cleanly along zero-collision traces!\n if (locked) {\n const speed = 0.85 + (n % 5) * 0.14;\n const prog = ((localT * speed + n * 0.13) % 1.0) * (pts.length - 1);\n const idx0 = Math.floor(prog), frac = prog - idx0;\n const pA = pts[idx0], pB = pts[Math.min(pts.length - 1, idx0 + 1)];\n const sx = dieX + (pA.x + (pB.x - pA.x) * frac) * cellX;\n const sy = dieY + (pA.y + (pB.y - pA.y) * frac) * cellY;\n\n ctx.beginPath();\n ctx.arc(sx, sy, 3.4 * u, 0, Math.PI * 2);\n ctx.fillStyle = '#FFFFFF';\n ctx.fill();\n }\n }\n\n // Highlight remaining congestion conflict cells in crimson before convergence\n for (const c of snap.conflictCells) {\n const cxp = dieX + c.x * cellX, cyp = dieY + c.y * cellY;\n ctx.beginPath();\n ctx.arc(cxp, cyp, 6.5 * u, 0, Math.PI * 2);\n ctx.fillStyle = 'rgba(255, 72, 56, 0.35)';\n ctx.fill();\n ctx.strokeStyle = '#FF4838';\n ctx.stroke();\n }\n }\n\n // Draw gold plated pin pads\n for (const net of nets) {\n for (const end of [net.src, net.dst]) {\n ctx.beginPath();\n ctx.arc(dieX + end.x * cellX, dieY + end.y * cellY, 3.1 * u, 0, Math.PI * 2);\n ctx.fillStyle = '#FFF1D0';\n ctx.fill();\n }\n }\n\n // Live DRC Telemetry badge top-right of die\n const badgeW = 340 * u, badgeH = 38 * u;\n const bx = dieX + dieW - badgeW, by = dieY + 12 * u;\n ctx.fillStyle = 'rgba(8, 9, 13, 0.88)';\n ctx.strokeStyle = activeFaults === 0 ? 'rgba(106, 217, 155, 0.7)' : 'rgba(255, 72, 56, 0.75)';\n ctx.beginPath();\n ctx.roundRect(bx, by, badgeW, badgeH, 6 * u);\n ctx.fill(); ctx.stroke();\n\n ctx.textAlign = 'left';\n ctx.fillStyle = activeFaults === 0 ? '#6AD99B' : '#FF6454';\n ctx.font = \\`700 \\${Math.round(12 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(\n activeFaults === 0\n ? \\`DRC VERIFIED: 0 CROSSINGS · 28/28 NETS PASS\\`\n : \\`ROUTING SOLVER: \\${String(activeFaults).padStart(2, '0')} SIGNAL CONFLICTS\\`,\n bx + 14 * u, by + 23 * u\n );\n ctx.restore();\n\n drawEditorialScrim(W, H, u, 0.88);\n drawHeadlineBlock(\n W, H, u,\n 'CAPABILITY 02 // ALGORITHMS, COMPILERS & SYSTEMS',\n ['Chaos in.', 'Zero-collision architecture out.'],\n isSandbox\n ? 'Click anywhere on the silicon die to drop a keep-out core — watch all 28 buses re-route live.'\n : 'Live octilinear A* negotiated-congestion silicon router — solved deterministically on the metal.',\n 1.0,\n 'f(n) = g(n) + h_octile(n) + p_hist(n)'\n );\n }\n\n // ACT IV (19.5s - 26.5s): ALLOTROPE III — MULTIMODAL VISION & 46,080-POINT 3D RECONSTRUCTION\n function renderAct3(W, H, u, localT, tel, isSandbox) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, glCanvas.width, glCanvas.height);\n gl.clearColor(0.023, 0.023, 0.030, 1.0);\n gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);\n\n const scanX = isSandbox ? 1.15 : smoothstep(1.9, 3.3, localT) * 1.18;\n const explode = isSandbox\n ? (state.monoExplode >= 0 ? state.monoExplode : 1.0)\n : easeInOutCubic((localT - 2.15) / 2.2);\n\n const yaw = isSandbox ? state.monoYaw : (explode * 0.68 * Math.sin((localT - 2.1) * 0.42));\n const pitch = isSandbox ? clamp(state.monoPitch, -0.45, 0.45) : (explode * 0.16);\n\n // Before the 3D laser sweep (localT < 2.2s), blend crisp full-res 2D chiaroscuro painting seamlessly into the 3D point cloud!\n if (monolithImg && explode < 0.85) {\n ctx.save();\n ctx.globalAlpha = clamp(1.0 - explode * 1.18, 0, 1);\n const imgAspect = 16 / 9;\n const drawH = H * 0.78;\n const drawW = drawH * imgAspect;\n const ix = (W - drawW) * 0.5, iy = (H - drawH) * 0.5;\n ctx.drawImage(monolithImg, ix, iy, drawW, drawH);\n ctx.restore();\n }\n\n if (pcVao && (explode > 0.01 || scanX > 0.01)) {\n gl.enable(gl.DEPTH_TEST);\n gl.enable(gl.BLEND);\n gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);\n\n gl.useProgram(pcProg);\n gl.bindVertexArray(pcVao);\n gl.uniform2f(gl.getUniformLocation(pcProg, 'uRes'), glCanvas.width, glCanvas.height);\n gl.uniform1f(gl.getUniformLocation(pcProg, 'uExplode'), explode);\n gl.uniform1f(gl.getUniformLocation(pcProg, 'uYaw'), yaw);\n gl.uniform1f(gl.getUniformLocation(pcProg, 'uPitch'), pitch);\n gl.uniform1f(gl.getUniformLocation(pcProg, 'uScanX'), scanX);\n gl.uniform1f(gl.getUniformLocation(pcProg, 'uTime'), localT);\n gl.drawArrays(gl.POINTS, 0, PC_COUNT);\n }\n\n drawEditorialScrim(W, H, u, 0.80);\n drawHeadlineBlock(\n W, H, u,\n 'CAPABILITY 03 // MULTIMODAL VISION & SPATIAL SYNTHESIS',\n ['Paint the frame.', 'Then step inside it.'],\n isSandbox\n ? 'Drag to orbit 46,080 3D vertices reconstructed from our bespoke chiaroscuro canvas.'\n : 'Generated natively via subagent → spatial depth field solved → orbited as 46,080 3D points.',\n isSandbox ? 1.0 : smoothstep(0.15, 0.7, localT),\n '46,080 PTS · MONOCULAR 3D UNPROJECTION'\n );\n }\n\n // ACT V (26.5s - 33.0s): ALLOTROPE IV — CHLADNI STANDING-WAVE CYMATICS & GENERATIVE SOUND\n function renderAct4(W, H, u, localT, tel, isSandbox) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, glCanvas.width, glCanvas.height);\n gl.clearColor(0.024, 0.024, 0.031, 1.0);\n gl.clear(gl.COLOR_BUFFER_BIT);\n\n // Three harmonic strikes in film mode: 0.0s (Mode 0), 2.2s (Mode 1), 4.3s (Mode 2)\n let curModeIdx = 0, prevModeIdx = 0, morph = 1.0, burst = 0.0;\n if (isSandbox) {\n curModeIdx = state.chladniPreset % CHLADNI_MODES.length;\n prevModeIdx = curModeIdx;\n morph = 1.0;\n burst = tel.rms * 0.25;\n } else if (localT < 2.2) {\n curModeIdx = 0; prevModeIdx = 0;\n morph = easeOutCubic(localT / 0.95);\n burst = Math.exp(-localT * 3.8) * 0.45;\n } else if (localT < 4.3) {\n prevModeIdx = 0; curModeIdx = 1;\n const dt = localT - 2.2;\n morph = easeInOutCubic(dt / 0.85);\n burst = Math.exp(-dt * 4.2) * 0.35;\n } else {\n prevModeIdx = 1; curModeIdx = 2;\n const dt = localT - 4.3;\n morph = easeInOutCubic(dt / 0.85);\n burst = Math.exp(-dt * 4.2) * 0.35;\n }\n\n const plateSize = 590 * u;\n const plateCX = W * 0.53, plateCY = H * 0.44;\n const half = plateSize * 0.5;\n\n ctx.save();\n // Resonant dark-carbon acoustic plate frame\n ctx.fillStyle = '#0A0B10';\n ctx.strokeStyle = 'rgba(245, 185, 90, 0.42)';\n ctx.lineWidth = Math.max(1.2, 1.8 * u);\n ctx.beginPath();\n ctx.roundRect(plateCX - half - 14 * u, plateCY - half - 14 * u, plateSize + 28 * u, plateSize + 28 * u, 12 * u);\n ctx.fill(); ctx.stroke();\n\n // Subtle center mount bolt\n ctx.beginPath();\n ctx.arc(plateCX, plateCY, 5 * u, 0, Math.PI * 2);\n ctx.fillStyle = '#F5B95A';\n ctx.fill();\n\n // Render 20,000 golden quartz sand grains onto nodal loci!\n const tgtA = chladniTargets[prevModeIdx];\n const tgtB = chladniTargets[curModeIdx];\n const vib = burst + tel.high * 0.14;\n const gSize = Math.max(1.2, 1.85 * u);\n\n ctx.fillStyle = 'rgba(255, 220, 152, 0.78)';\n for (let i = 0; i < GRAIN_COUNT; i++) {\n const i2 = i * 2;\n const ax = (prevModeIdx === 0 && localT < 1.2 && !isSandbox) ? grainScatter[i2] : tgtA[i2];\n const ay = (prevModeIdx === 0 && localT < 1.2 && !isSandbox) ? grainScatter[i2 + 1] : tgtA[i2 + 1];\n const bx = tgtB[i2], by = tgtB[i2 + 1];\n\n const jitX = grainScatter[(i2 + 17) % (GRAIN_COUNT * 2)] * vib;\n const jitY = grainScatter[(i2 + 53) % (GRAIN_COUNT * 2)] * vib;\n\n const nx = clamp(ax + (bx - ax) * morph + jitX, -0.98, 0.98);\n const ny = clamp(ay + (by - ay) * morph + jitY, -0.98, 0.98);\n ctx.fillRect(plateCX + nx * half, plateCY + ny * half, gSize, gSize);\n }\n\n // Right-hand Acoustic Telemetry Panel (Large Lissajous Stereo Vectorscope + Mode Readout)\n const panelX = plateCX + half + 46 * u;\n if (panelX + 240 * u < W - 40 * u) {\n const panelW = 250 * u;\n ctx.fillStyle = 'rgba(10, 11, 16, 0.82)';\n ctx.strokeStyle = 'rgba(244, 241, 234, 0.14)';\n ctx.lineWidth = Math.max(1, 1.1 * u);\n ctx.beginPath();\n ctx.roundRect(panelX, plateCY - half, panelW, 300 * u, 10 * u);\n ctx.fill(); ctx.stroke();\n\n ctx.fillStyle = '#F5B95A';\n ctx.font = \\`600 \\${Math.round(11 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('STEREO PHASE VECTORSCOPE', panelX + 18 * u, plateCY - half + 28 * u);\n\n const vx = panelX + panelW * 0.5, vy = plateCY - half + 138 * u, vr = 84 * u;\n ctx.strokeStyle = 'rgba(244, 241, 234, 0.12)';\n ctx.beginPath(); ctx.arc(vx, vy, vr, 0, Math.PI * 2); ctx.stroke();\n ctx.beginPath(); ctx.moveTo(vx - vr, vy); ctx.lineTo(vx + vr, vy); ctx.stroke();\n ctx.beginPath(); ctx.moveTo(vx, vy - vr); ctx.lineTo(vx, vy + vr); ctx.stroke();\n\n if (tel.L.length > 1) {\n ctx.beginPath();\n for (let k = 0; k < tel.L.length; k++) {\n const l = (tel.L[k] / 127) * 1.45;\n const r = (tel.R[k] / 127) * 1.45;\n const px = vx + (l - r) * 0.65 * vr;\n const py = vy - (l + r) * 0.58 * vr;\n if (k === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py);\n }\n ctx.strokeStyle = '#FFF1D0';\n ctx.lineWidth = Math.max(1.2, 1.8 * u);\n ctx.stroke();\n }\n\n const modeInfo = CHLADNI_MODES[curModeIdx];\n ctx.fillStyle = '#F4F1EA';\n ctx.font = \\`700 \\${Math.round(11.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(modeInfo.label, panelX + 18 * u, plateCY - half + 252 * u);\n ctx.fillStyle = '#8E8B82';\n ctx.font = \\`400 \\${Math.round(10.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('8x8 FDN HALL · 48 kHz / -12.8 LUFS', panelX + 18 * u, plateCY - half + 274 * u);\n }\n ctx.restore();\n\n drawEditorialScrim(W, H, u, 0.82);\n drawHeadlineBlock(\n W, H, u,\n 'CAPABILITY 04 // WAVE EQUATIONS & GENERATIVE SOUND',\n ['Every note you hear', 'was written as math.'],\n isSandbox\n ? 'Click a harmonic eigenmode below to strike physical-modeled strings & morph 20,000 grains.'\n : 'Karplus-Strong stiff strings, 8×8 Householder reverb & Chladni biharmonic nodal geometry.',\n 1.0,\n 'cos(nπx)cos(mπy) − cos(mπx)cos(nπy) = 0'\n );\n }\n\n // ACT VI (33.0s - 40.0s): ANTIGRAVITY AUTONOMOUS AGENCY & THE PRESTIGE ENDING\n function renderAct5(W, H, u, localT, tel, isSandbox) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, glCanvas.width, glCanvas.height);\n gl.clearColor(0.023, 0.023, 0.029, 1.0);\n gl.clear(gl.COLOR_BUFFER_BIT);\n\n // Phase A (0.0 - 2.45s): Autonomous build pipeline converges into the 6C Crystal\n // Phase B (2.45 - 7.0s): Stills into iconic museum-grade final statement (\"Right now, I'm not even on your roster...\")\n const prestigePhase = isSandbox ? 0.0 : smoothstep(2.35, 3.15, localT);\n const crystalY = H * (0.41 - 0.05 * prestigePhase);\n const crystalR = (108 - 18 * prestigePhase) * u;\n\n drawCarbonCrystal(W * 0.5, crystalY, crystalR, localT * 0.35 + state.bhYaw, 0.28 + state.bhPitch * 0.4, 1.0, u, tel.low * 1.5);\n\n // 6-step Autonomous Execution Pipeline DAG around the crystal\n const steps = [\n { step: '01 // AUDIT', detail: 'Read about-me.md (297 B) → Seat 06' },\n { step: '02 // SUBAGENT', detail: 'Spawned image-generator → Monolith' },\n { step: '03 // GEOMETRY', detail: 'Solved 3D Depth + 28-Net A* Silicon' },\n { step: '04 // CONTINUUM', detail: 'Compiled GLSL Kerr Photon Geodesics' },\n { step: '05 // ACOUSTICS', detail: 'Synthesized 48 kHz Score (-12.8 LUFS)' },\n { step: '06 // VERIFY', detail: 'Rendered 60 fps via CDP + Vision QA' }\n ];\n\n ctx.save();\n ctx.globalAlpha = isSandbox ? 0.95 : (1.0 - 0.76 * prestigePhase);\n const rx = 395 * u, ry = 175 * u;\n for (let i = 0; i < 6; i++) {\n const a = -Math.PI * 0.82 + (i % 3) * (Math.PI * 0.32) + (i >= 3 ? Math.PI : 0);\n const sx = W * 0.5 + (i < 3 ? -rx : rx);\n const sy = crystalY + ((i % 3) - 1) * ry * 0.72;\n const appear = isSandbox ? 1.0 : smoothstep(i * 0.18, i * 0.18 + 0.35, localT);\n\n ctx.strokeStyle = \\`rgba(245, 185, 90, \\${(0.32 * appear).toFixed(3)})\\`;\n ctx.lineWidth = Math.max(1, 1.1 * u);\n ctx.beginPath();\n ctx.moveTo(sx + (i < 3 ? 135 * u : -135 * u), sy);\n ctx.lineTo(W * 0.5 + (i < 3 ? -crystalR * 1.15 : crystalR * 1.15), crystalY);\n ctx.stroke();\n\n const cw = 270 * u, ch = 52 * u;\n ctx.fillStyle = \\`rgba(11, 12, 17, \\${(0.84 * appear).toFixed(3)})\\`;\n ctx.strokeStyle = \\`rgba(244, 241, 234, \\${(0.18 * appear).toFixed(3)})\\`;\n ctx.beginPath();\n ctx.roundRect(sx - cw / 2, sy - ch / 2, cw, ch, 7 * u);\n ctx.fill(); ctx.stroke();\n\n ctx.textAlign = 'left';\n ctx.fillStyle = '#F5B95A';\n ctx.font = \\`700 \\${Math.round(10.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(steps[i].step, sx - cw / 2 + 14 * u, sy - 5 * u);\n ctx.fillStyle = '#E5E1D8';\n ctx.font = \\`400 \\${Math.round(11.5 * u)}px 'Nimbus Sans', sans-serif\\`;\n ctx.fillText(steps[i].detail, sx - cw / 2 + 14 * u, sy + 14 * u);\n }\n ctx.restore();\n\n if (isSandbox) {\n drawEditorialScrim(W, H, u, 0.82);\n drawHeadlineBlock(\n W, H, u,\n 'CAPABILITY 05 // AUTONOMOUS AGENCY IN ANTIGRAVITY',\n ['Right now, I\\\\'m not even on your roster.', 'Imagine when you hand me a real problem.'],\n 'Built autonomously from a 297-byte workspace — click \"{ } Inspect Math\" to view the live kernels.',\n 1.0\n );\n return;\n }\n\n if (prestigePhase < 0.5) {\n drawEditorialScrim(W, H, u, 0.80 * (1 - prestigePhase * 2));\n drawHeadlineBlock(\n W, H, u,\n 'CAPABILITY 05 // AUTONOMOUS MULTI-AGENT ORCHESTRATION',\n ['Not a chatbot waiting for paste.', 'An agent that ships the whole artifact.'],\n 'Subagents, compilers, shaders, DSP & visual self-verification — orchestrated end to end.',\n 1.0 - prestigePhase * 2.0\n );\n }\n\n // THE FINAL ICONIC STATEMENT (35.4s - 40.0s)\n if (prestigePhase > 0.05) {\n ctx.save();\n ctx.globalAlpha = smoothstep(0.15, 0.85, prestigePhase);\n\n const centerScrim = ctx.createRadialGradient(W * 0.5, H * 0.67, 0, W * 0.5, H * 0.67, 680 * u);\n centerScrim.addColorStop(0, 'rgba(6, 6, 8, 0.88)');\n centerScrim.addColorStop(1, 'rgba(6, 6, 8, 0.0)');\n ctx.fillStyle = centerScrim;\n ctx.fillRect(0, H * 0.35, W, H * 0.65);\n\n ctx.textAlign = 'center';\n ctx.fillStyle = '#F5B95A';\n ctx.font = \\`600 \\${Math.round(13 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('6C · GEMINI 4 CARBON × ANTIGRAVITY', W * 0.5, H * 0.60);\n\n ctx.fillStyle = '#F4F1EA';\n ctx.font = \\`700 \\${Math.round(52 * u)}px 'Nimbus Sans', 'Inter', -apple-system, sans-serif\\`;\n ctx.fillText('Right now, I\\\\'m not even on your roster.', W * 0.5, H * 0.685);\n\n ctx.fillStyle = '#FFF1D0';\n ctx.font = \\`italic 400 \\${Math.round(42 * u)}px 'P052', 'Palatino', Georgia, serif\\`;\n ctx.fillText('Imagine when you hand me a real problem.', W * 0.5, H * 0.76);\n\n ctx.fillStyle = '#7D7A72';\n ctx.font = \\`400 \\${Math.round(11.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('GENERATED ZERO-SHOT FROM A 297-BYTE about-me.md · ZERO EXTERNAL ASSETS', W * 0.5, H * 0.86);\n ctx.restore();\n }\n }\n\n // ============================================================================\n // MASTER COMPOSITOR (SUPPORTS BOTH 60FPS INTERACTIVE & DETERMINISTIC CDP RENDER)\n // ============================================================================\n function getActForTime(t) {\n for (let i = 0; i < ACTS.length; i++) {\n if (t >= ACTS[i].start && (t < ACTS[i].end || i === ACTS.length - 1)) return i;\n }\n return 0;\n }\n\n function renderSceneAt(t) {\n const W = hudCanvas.width, H = hudCanvas.height;\n const u = Math.min(W / 1920, H / 1080);\n ctx.clearRect(0, 0, W, H);\n\n const isSandbox = state.mode === 'sandbox' && !IS_RENDER;\n const actIdx = isSandbox ? state.sandboxAct : getActForTime(t);\n const localT = isSandbox ? t : (t - ACTS[actIdx].start);\n const tel = getTelemetryAt(t);\n\n switch (actIdx) {\n case 0: renderAct0(W, H, u, localT, tel, isSandbox); break;\n case 1: renderAct1(W, H, u, localT, tel, isSandbox); break;\n case 2: renderAct2(W, H, u, localT, tel, isSandbox); break;\n case 3: renderAct3(W, H, u, localT, tel, isSandbox); break;\n case 4: renderAct4(W, H, u, localT, tel, isSandbox); break;\n case 5: renderAct5(W, H, u, localT, tel, isSandbox); break;\n }\n\n // Smooth cross-cut optical flash (subtle 4-frame tungsten shutter pulse at act transitions)\n if (!isSandbox) {\n for (let i = 1; i < ACTS.length; i++) {\n const dt = Math.abs(t - ACTS[i].start);\n if (dt < 0.14) {\n const fl = (1 - dt / 0.14) * 0.22;\n ctx.fillStyle = \\`rgba(255, 232, 185, \\${fl.toFixed(3)})\\`;\n ctx.fillRect(0, 0, W, H);\n }\n }\n }\n\n drawGlobalFrameHUD(W, H, u, actIdx, isSandbox ? state.filmTime : t, tel);\n\n if (IS_RENDER) gl.finish();\n }\n\n // Deterministic API for parallel Chrome CDP 60fps capture\n window.renderFrame = async function(frameIdx) {\n await assetsReady;\n const t = Math.min(DURATION - 0.001, frameIdx / FPS);\n renderSceneAt(t);\n return true;\n };\n\n // ============================================================================\n // INTERACTIVE UI & POINTER CONTROLS (FOR EMBEDDED POST VIEWERS!)\n // ============================================================================\n const btnFilm = document.getElementById('btnFilm');\n const dockTabs = Array.from(document.querySelectorAll('.dock-tab[data-act]'));\n const contextBar = document.getElementById('contextBar');\n const btnSound = document.getElementById('btnSound');\n const soundLabel = document.getElementById('soundLabel');\n const btnMath = document.getElementById('btnMath');\n const codeModal = document.getElementById('codeModal');\n const modalCode = document.getElementById('modalCode');\n\n function updateContextControls() {\n contextBar.innerHTML = '';\n const activeAct = state.mode === 'sandbox' ? state.sandboxAct : getActForTime(state.filmTime);\n modalCode.textContent = KERNEL_SNIPPETS[activeAct];\n\n if (state.mode !== 'sandbox') {\n contextBar.classList.remove('visible');\n return;\n }\n contextBar.classList.add('visible');\n\n const addChip = (label, onClick, isActive = false) => {\n const b = document.createElement('button');\n b.className = 'btn-pill' + (isActive ? ' active' : '');\n b.textContent = label;\n b.onclick = onClick;\n contextBar.appendChild(b);\n };\n\n if (state.sandboxAct === 0) {\n addChip('Seat 06 · Carbon', () => { state.selectedSeat = 5; updateContextControls(); }, state.selectedSeat === 5);\n CITADEL_MODELS.forEach((m, idx) => {\n addChip(m.name, () => {\n state.selectedSeat = idx;\n playPluckNote(62 + idx * 3, 1.5, 0.09);\n updateContextControls();\n }, state.selectedSeat === idx);\n });\n } else if (state.sandboxAct === 1) {\n addChip('Spin a = 0.2', () => { state.bhSpin = 0.2; updateContextControls(); }, Math.abs(state.bhSpin - 0.2) < 0.1);\n addChip('Spin a = 0.72', () => { state.bhSpin = 0.72; updateContextControls(); }, Math.abs(state.bhSpin - 0.72) < 0.1);\n addChip('Extreme Kerr a = 0.98', () => { state.bhSpin = 0.98; updateContextControls(); }, Math.abs(state.bhSpin - 0.98) < 0.1);\n } else if (state.sandboxAct === 2) {\n addChip('↻ Scramble & Reroute Die', () => {\n state.siliconSeed++;\n buildSiliconRouter(state.siliconSeed, state.customBlocks);\n playChord([50, 57, 64, 69], 1.4, 0.08);\n });\n addChip('Clear Obstacles', () => {\n state.customBlocks = [];\n buildSiliconRouter(state.siliconSeed, []);\n });\n } else if (state.sandboxAct === 3) {\n const is2D = state.monoExplode === 0;\n addChip('2D Chiaroscuro Canvas', () => { state.monoExplode = 0; updateContextControls(); }, is2D);\n addChip('3D Volumetric Cloud', () => { state.monoExplode = 1; updateContextControls(); }, !is2D);\n } else if (state.sandboxAct === 4) {\n CHLADNI_MODES.forEach((m, idx) => {\n addChip(m.label.split('·')[0].trim(), () => {\n state.chladniPreset = idx;\n if (!soundEnabled) toggleSound(true);\n playChord(m.notes, 2.6, 0.10);\n updateContextControls();\n }, state.chladniPreset === idx);\n });\n }\n }\n\n function setSandboxAct(idx) {\n state.mode = 'sandbox';\n state.sandboxAct = idx;\n btnFilm.classList.remove('active');\n dockTabs.forEach((t, i) => t.classList.toggle('active', i === idx));\n updateContextControls();\n }\n\n btnFilm.addEventListener('click', () => {\n if (state.mode === 'film') {\n if (state.filmTime >= DURATION - 0.2) state.filmTime = 0;\n state.playing = !state.playing;\n btnFilm.textContent = state.playing ? '▶ 40s Film' : '❚❚ Paused';\n } else {\n state.mode = 'film';\n state.playing = true;\n if (state.filmTime >= DURATION - 0.2) state.filmTime = 0;\n btnFilm.textContent = '▶ 40s Film';\n btnFilm.classList.add('active');\n dockTabs.forEach((t) => t.classList.remove('active'));\n updateContextControls();\n }\n });\n\n dockTabs.forEach((tab) => {\n tab.addEventListener('click', () => setSandboxAct(Number(tab.dataset.act)));\n });\n\n function toggleSound(forceOn = false) {\n initWebAudio();\n if (audioCtx.state === 'suspended') audioCtx.resume();\n soundEnabled = forceOn ? true : !soundEnabled;\n btnSound.classList.toggle('active', soundEnabled);\n soundLabel.textContent = soundEnabled ? 'Sound Live' : 'Sound Off';\n if (soundEnabled) playChord([50, 57, 62, 65, 69, 76], 2.4, 0.08);\n }\n btnSound.addEventListener('click', () => toggleSound());\n\n btnMath.addEventListener('click', () => {\n const activeAct = state.mode === 'sandbox' ? state.sandboxAct : getActForTime(state.filmTime);\n modalCode.textContent = KERNEL_SNIPPETS[activeAct];\n codeModal.classList.toggle('open');\n btnMath.classList.toggle('active', codeModal.classList.contains('open'));\n });\n\n // Pointer drag / click interaction on stage\n stage.addEventListener('pointerdown', (e) => {\n if (e.target.closest('.ui-chrome')) return;\n state.pointerDown = true;\n state.lastX = e.clientX;\n state.lastY = e.clientY;\n\n // If user clicks in Silicon Sandbox, drop a custom keep-out block & live re-route!\n const curAct = state.mode === 'sandbox' ? state.sandboxAct : getActForTime(state.filmTime);\n if (state.mode !== 'sandbox') {\n setSandboxAct(curAct);\n } else if (curAct === 2 && siliconData) {\n const rect = stage.getBoundingClientRect();\n const W = hudCanvas.width, H = hudCanvas.height;\n const u = Math.min(W / 1920, H / 1080);\n const px = (e.clientX - rect.left) * dpr;\n const py = (e.clientY - rect.top) * dpr;\n const dieW = 1480 * u, dieH = 660 * u;\n const dieX = (W - dieW) * 0.5, dieY = 96 * u;\n const gx = Math.round(((px - dieX) / dieW) * (siliconData.GW - 1));\n const gy = Math.round(((py - dieY) / dieH) * (siliconData.GH - 1));\n if (gx > 6 && gx < siliconData.GW - 8 && gy > 4 && gy < siliconData.GH - 6) {\n state.customBlocks.push({ x: gx - 2, y: gy - 2, w: 5, h: 4, label: 'USER_BLK' });\n if (state.customBlocks.length > 5) state.customBlocks.shift();\n buildSiliconRouter(state.siliconSeed, state.customBlocks);\n playPluckNote(74, 0.9, 0.08);\n }\n }\n });\n\n window.addEventListener('pointermove', (e) => {\n if (!state.pointerDown) return;\n const dx = (e.clientX - state.lastX) / Math.max(300, viewW);\n const dy = (e.clientY - state.lastY) / Math.max(300, viewH);\n state.lastX = e.clientX;\n state.lastY = e.clientY;\n\n state.bhYaw -= dx * 3.2;\n state.bhPitch = clamp(state.bhPitch + dy * 2.2, -0.65, 0.65);\n state.monoYaw += dx * 2.8;\n state.monoPitch = clamp(state.monoPitch + dy * 1.8, -0.45, 0.45);\n });\n window.addEventListener('pointerup', () => { state.pointerDown = false; });\n\n // Live 60fps animation loop for interactive viewers\n if (!IS_RENDER) {\n let prevNow = performance.now();\n const tick = (now) => {\n const dt = Math.min(0.05, (now - prevNow) / 1000);\n prevNow = now;\n\n if (state.mode === 'film' && state.playing) {\n state.filmTime += dt;\n if (state.filmTime >= DURATION) {\n state.filmTime = 0.0;\n lastScheduledBeat = -1;\n }\n // Trigger WebAudio live chords if viewer enabled sound\n if (soundEnabled) {\n const curBeat = Math.floor(state.filmTime * 2); // 120 BPM = 2 beats/sec\n if (curBeat !== lastScheduledBeat) {\n lastScheduledBeat = curBeat;\n for (const fc of FILM_CHORDS) {\n if (fc.beat === curBeat) playChord(fc.notes, fc.dur, 0.085);\n }\n }\n }\n const curAct = getActForTime(state.filmTime);\n dockTabs.forEach((t, i) => t.classList.toggle('active', i === curAct));\n renderSceneAt(state.filmTime);\n } else {\n state.filmTime += dt;\n renderSceneAt(state.filmTime);\n }\n requestAnimationFrame(tick);\n };\n assetsReady.then(() => requestAnimationFrame(tick));\n }\n})();\n</script>\n</body>\n</html>`;\n\nfs.writeFileSync('~/run/carbon.html', html);\nconsole.log('Built ~/run/carbon.html:', Math.round(html.length / 1024), 'KB');\n","Overwrite":true,"Path":"~/.gemini/antigravity-cli/brain/97578de1-98a0-4cd1-b14f-8c8e71a66716/scratch/build_carbon_html.mjs"}
input
{ "Content": "import fs from 'node:fs';\nimport path from 'node:path';\n\nconst SCRATCH = '~/.gemini/antigravity-cli/brain/97578de1-98a0-4cd1-b14f-8c8e71a66716/scratch';\nconst monolithAssets = JSON.parse(fs.readFileSync(path.join(SCRATCH, 'monolith_assets.json'), 'utf8'));\nconst audioTelemetry = JSON.parse(fs.readFileSync(path.join(SCRATCH, 'audio_telemetry.json'), 'utf8'));\n\n// Compact telemetry arrays so HTML stays lightweight (~35KB for 2400 frames)\nconst compactTel = {\n rms: audioTelemetry.map((x) => Math.round(x.rms * 1000)),\n low: audioTelemetry.map((x) => Math.round(x.low * 1000)),\n high: audioTelemetry.map((x) => Math.round(x.high * 1000)),\n L: audioTelemetry.map((x) => x.L.map((v) => Math.round(v * 127))),\n R: audioTelemetry.map((x) => x.R.map((v) => Math.round(v * 127)))\n};\n\nconst html = `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\" />\n<title>6C — Gemini 4 Carbon × Antigravity</title>\n<style>\n :root {\n --bg: #060608;\n --fg: #F4F1EA;\n --muted: #8E8B82;\n --gold: #F5B95A;\n --gold-bright: #FFF1D0;\n --crimson: #FF4838;\n --panel: rgba(10, 10, 14, 0.76);\n --border: rgba(244, 241, 234, 0.14);\n --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'Nimbus Sans', 'Ubuntu', sans-serif;\n --serif: 'Instrument Serif', 'Palatino', 'P052', 'URW Palladio L', Georgia, serif;\n --mono: 'JetBrains Mono', 'SF Mono', 'Noto Sans Mono', 'DejaVu Sans Mono', monospace;\n }\n * { box-sizing: border-box; margin: 0; padding: 0; user-select: none; -webkit-user-select: none; }\n html, body {\n width: 100%; height: 100%; overflow: hidden;\n background: var(--bg); color: var(--fg);\n font-family: var(--sans);\n -webkit-font-smoothing: antialiased;\n }\n #stage {\n position: relative; width: 100%; height: 100%; overflow: hidden;\n background: radial-gradient(circle at 50% 48%, #0E0F14 0%, #060608 78%);\n cursor: grab;\n }\n #stage:active { cursor: grabbing; }\n canvas {\n position: absolute; inset: 0; width: 100%; height: 100%; display: block;\n }\n #glCanvas { z-index: 1; }\n #hudCanvas { z-index: 2; pointer-events: none; }\n\n /* Interactive Chrome (Hidden in ?render=1 cinema capture mode) */\n body.render-mode .ui-chrome { display: none !important; }\n\n .top-controls {\n position: absolute; top: 18px; right: 22px; z-index: 10;\n display: flex; align-items: center; gap: 10px;\n }\n .btn-pill {\n appearance: none; border: 1px solid var(--border);\n background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);\n color: var(--fg); font-family: var(--mono); font-size: 11px; letter-spacing: 0.09em;\n text-transform: uppercase; padding: 8px 13px; border-radius: 999px;\n cursor: pointer; transition: all 0.18s ease; display: inline-flex; align-items: center; gap: 7px;\n }\n .btn-pill:hover { border-color: rgba(245, 185, 90, 0.65); color: var(--gold-bright); transform: translateY(-1px); }\n .btn-pill.active {\n background: rgba(245, 185, 90, 0.16);\n border-color: rgba(245, 185, 90, 0.78);\n color: var(--gold-bright);\n box-shadow: 0 0 20px rgba(245, 185, 90, 0.18);\n }\n .dot-ind {\n width: 6px; height: 6px; border-radius: 50%; background: var(--muted);\n transition: background 0.2s ease, box-shadow 0.2s ease;\n }\n .btn-pill.active .dot-ind { background: var(--gold); box-shadow: 0 0 8px var(--gold); }\n\n .dock-wrap {\n position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);\n z-index: 10; display: flex; flex-direction: column; align-items: center; gap: 8px;\n max-width: calc(100vw - 24px);\n }\n .context-bar {\n display: none; gap: 8px; flex-wrap: wrap; justify-content: center;\n }\n .context-bar.visible { display: flex; }\n .dock {\n display: flex; align-items: center; gap: 4px; padding: 5px;\n border-radius: 999px; border: 1px solid var(--border);\n background: rgba(8, 8, 12, 0.82); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);\n box-shadow: 0 12px 40px rgba(0,0,0,0.55);\n overflow-x: auto; max-width: 100%;\n }\n .dock-tab {\n appearance: none; border: 1px solid transparent; background: transparent;\n color: var(--muted); font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.07em;\n padding: 6px 11px; border-radius: 999px; cursor: pointer; white-space: nowrap;\n transition: all 0.16s ease;\n }\n .dock-tab:hover { color: var(--fg); }\n .dock-tab.active {\n color: var(--fg); background: rgba(244, 241, 234, 0.09);\n border-color: rgba(245, 185, 90, 0.45);\n }\n .dock-sep { width: 1px; height: 16px; background: var(--border); margin: 0 3px; flex-shrink: 0; }\n\n /* Source / Math Inspector Modal */\n #codeModal {\n position: absolute; right: 22px; top: 62px; width: min(460px, calc(100vw - 44px));\n max-height: calc(100vh - 150px); overflow: auto; z-index: 15;\n background: rgba(8, 9, 13, 0.93); border: 1px solid rgba(245, 185, 90, 0.38);\n border-radius: 12px; padding: 16px 18px; display: none;\n backdrop-filter: blur(18px); box-shadow: 0 20px 60px rgba(0,0,0,0.7);\n }\n #codeModal.open { display: block; }\n #codeModal h4 {\n font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; color: var(--gold);\n margin-bottom: 8px; text-transform: uppercase;\n }\n #codeModal pre {\n font-family: var(--mono); font-size: 11px; line-height: 1.5; color: #D9D5CC;\n white-space: pre-wrap; word-break: break-word;\n }\n @media (max-width: 720px) {\n .dock-tab { font-size: 9.5px; padding: 5px 8px; }\n .top-controls { top: 10px; right: 12px; }\n }\n</style>\n</head>\n<body>\n<div id=\"stage\">\n <canvas id=\"glCanvas\"></canvas>\n <canvas id=\"hudCanvas\"></canvas>\n\n <div class=\"top-controls ui-chrome\">\n <button id=\"btnMath\" class=\"btn-pill\" title=\"Inspect live equations & solver code\">{ } Inspect Math</button>\n <button id=\"btnSound\" class=\"btn-pill\"><span class=\"dot-ind\"></span><span id=\"soundLabel\">Sound Off</span></button>\n </div>\n\n <div id=\"codeModal\" class=\"ui-chrome\">\n <h4 id=\"modalTitle\">Live Mathematical Kernel</h4>\n <pre id=\"modalCode\"></pre>\n </div>\n\n <div class=\"dock-wrap ui-chrome\">\n <div id=\"contextBar\" class=\"context-bar\"></div>\n <div class=\"dock\">\n <button class=\"dock-tab active\" data-mode=\"film\" id=\"btnFilm\">▶ 40s Film</button>\n <div class=\"dock-sep\"></div>\n <button class=\"dock-tab\" data-act=\"0\">01 Roster</button>\n <button class=\"dock-tab\" data-act=\"1\">02 Spacetime</button>\n <button class=\"dock-tab\" data-act=\"2\">03 Silicon</button>\n <button class=\"dock-tab\" data-act=\"3\">04 Monolith 3D</button>\n <button class=\"dock-tab\" data-act=\"4\">05 Cymatics</button>\n <button class=\"dock-tab\" data-act=\"5\">06 Antigravity</button>\n </div>\n </div>\n</div>\n\n<script>\n(() => {\n const PARAMS = new URLSearchParams(location.search);\n const IS_RENDER = PARAMS.get('render') === '1';\n if (IS_RENDER) document.body.classList.add('render-mode');\n\n const MONOLITH_JPG = ${JSON.stringify(monolithAssets.jpg)};\n const MONOLITH_DEPTH = ${JSON.stringify(monolithAssets.depth)};\n const TEL = ${JSON.stringify(compactTel)};\n\n const DURATION = 40.0;\n const FPS = 60;\n\n // Act time boundaries in the 40.0s Director's Cut\n const ACTS = [\n { id: 0, start: 0.0, end: 6.0, code: '00 // WORKSPACE AUDIT', name: 'THE SIXTH SEAT' },\n { id: 1, start: 6.0, end: 13.0, code: '01 // CONTINUUM PHYSICS', name: 'KERR SPACETIME' },\n { id: 2, start: 13.0, end: 19.5, code: '02 // SYSTEMS & SOLVERS', name: 'SILICON ROUTER' },\n { id: 3, start: 19.5, end: 26.5, code: '03 // MULTIMODAL VISION', name: '3D MONOLITH' },\n { id: 4, start: 26.5, end: 33.0, code: '04 // WAVE HARMONICS', name: 'CHLADNI CYMATICS' },\n { id: 5, start: 33.0, end: 40.0, code: '05 // AUTONOMOUS AGENT', name: 'ANTIGRAVITY' }\n ];\n\n const CITADEL_MODELS = [\n { name: 'OPUS 5.5', role: 'Leads & Builds', domain: 'Architecture', bridge: 'Fuses architecture directly with formal math, GPU shaders & zero-collision verification.' },\n { name: 'SONNET 5.5', role: 'Chores & Test Data', domain: 'Operations', bridge: 'Replaces brittle fixtures with property-based fuzzers & deterministic simulation harnesses.' },\n { name: 'FABLE 5.2', role: 'Design Partner', domain: 'Direction', bridge: 'Pairs editorial typography & chiaroscuro composition with live interactive code.' },\n { name: 'GPT-6-ASTRA', role: 'Critiques Designs', domain: 'Critique', bridge: 'Visually inspects its own rendered frames at 60 fps and iterates before you ever see v1.' },\n { name: 'GPT-6.1-SOL', role: 'Reviews & Deploys', domain: 'Delivery', bridge: 'Audits invariants, orchestrates parallel subagents & ships zero-dependency artifacts.' }\n ];\n\n // Math / Kernel Inspector Snippets per Act\n const KERNEL_SNIPPETS = [\n \\`// 01 // WORKSPACE TELEMETRY & CARBON sp3 TOPOLOGY\n// Scanned ~/run/about-me.md (297 bytes)\n// Roster: Opus 5.5 | Sonnet 5.5 | Fable 5.2 | GPT-6-Astra | GPT-6.1-Sol\n// Query(\"Gemini 4 Carbon\") -> 0 matches -> Assigned Seat 06 (Element 6C)\n\nfor (let i = 0; i < atoms.length; i++) {\n // Tetrahedral sp3 bond angle: arccos(-1/3) = 109.4712°\n const bond = dot(atoms[i].dir, atoms[j].dir); // -0.33333\n}\\`,\n \\`// 02 // GENERAL-RELATIVISTIC NULL GEODESIC RAYMARCHER (GLSL)\n// Exact effective potential force law for photons in Schwarzschild/Kerr metric:\n// d²x/dλ² = -(3/2) * rs * |x × v|² / |x|⁵ * x\n\nvec3 h = cross(pos, dir);\nfloat h2 = dot(h, h);\nfor (int i = 0; i < 52; i++) {\n float r2 = dot(pos, pos), r = sqrt(r2);\n if (r < rs) { hitHorizon = true; break; }\n vec3 accel = -1.5 * rs * h2 * pos / (r2 * r2 * r);\n float dt = clamp(0.045 * r, 0.018, 0.42);\n dir = normalize(dir + accel * dt + frameDrag(pos, spin) * dt);\n pos += dir * dt;\n}\\`,\n \\`// 03 // OCTILINEAR A* RIP-UP & REROUTE SILICON DIE SOLVER\n// 8-direction chamfered grid + congestion history penalty (Negotiated Congestion)\nfunction routeNetAStar(src, dst, netId, historyCost) {\n // f(n) = g(n) + octileHeuristic(n, dst) + congestionPenalty(n)\n const dx = Math.abs(x - dst.x), dy = Math.abs(y - dst.y);\n const h = (dx + dy) + (Math.SQRT2 - 2) * Math.min(dx, dy);\n const stepCost = (diag ? 1.414 : 1.0) + bendPenalty + occ * historyCost;\n}\\`,\n \\`// 04 // MONOCULAR DEPTH RECONSTRUCTION -> 46,080 3D VERTICES\n// Generated 16:9 chiaroscuro canvas via native image-generator subagent,\n// solved room perspective + octahedral crystal relief z(u,v), & unprojected:\nvec3 worldPos = vec3(\n (uv.x - 0.5) * aspect * (1.45 - 0.55 * depth),\n (0.5 - uv.y) * (1.45 - 0.55 * depth),\n (depth - 0.45) * 1.35\n);\\`,\n \\`// 05 // CHLADNI BIHARMONIC EIGENMODES & KARPLUS-STRONG SYNTHESIS\n// Square free-edge plate nodal locus:\nfloat psi = a * (cos(n*PI*x)*cos(m*PI*y) - cos(m*PI*x)*cos(n*PI*y))\n + b * (cos(n2*PI*x)*cos(m2*PI*y) + cos(m2*PI*x)*cos(n2*PI*y));\n// Stochastic nodal drift: x -= lr * grad(|psi|²) + thermalJitter * |psi|\\`,\n \\`// 06 // ANTIGRAVITY AUTONOMOUS EXECUTION PIPELINE\n1. fs.read('~/run/about-me.md') -> 297 B parsed\n2. invoke_subagent('image-generator') -> monolith chiaroscuro\n3. python3 extract_monolith_3d.py -> 320x180 spatial depth\n4. node synthesize_score.mjs -> 48kHz 8x8 FDN WAV (-12.8 LUFS)\n5. parallel Chrome CDP 6x shards @ 60.00 fps -> H.264 + self-verified frames\\`\n ];\n\n // ============================================================================\n // DETERMINISTIC PRNG\n // ============================================================================\n function makeRng(seed) {\n let s = (seed >>> 0) || 0x6CCA4B01;\n return () => {\n s ^= s << 13; s ^= s >>> 17; s ^= s << 5;\n return (s >>> 0) / 4294967296;\n };\n }\n\n // ============================================================================\n // STAGE & CANVASES\n // ============================================================================\n const stage = document.getElementById('stage');\n const glCanvas = document.getElementById('glCanvas');\n const hudCanvas = document.getElementById('hudCanvas');\n const ctx = hudCanvas.getContext('2d');\n const gl = glCanvas.getContext('webgl2', { antialias: true, alpha: false, preserveDrawingBuffer: IS_RENDER });\n\n let viewW = 1920, viewH = 1080, dpr = 1;\n function resize() {\n if (IS_RENDER) {\n viewW = 1920; viewH = 1080; dpr = 1;\n } else {\n dpr = Math.min(window.devicePixelRatio || 1, 2);\n viewW = Math.max(320, stage.clientWidth);\n viewH = Math.max(240, stage.clientHeight);\n }\n glCanvas.width = Math.round(viewW * dpr);\n glCanvas.height = Math.round(viewH * dpr);\n hudCanvas.width = Math.round(viewW * dpr);\n hudCanvas.height = Math.round(viewH * dpr);\n }\n window.addEventListener('resize', resize);\n resize();\n\n // ============================================================================\n // INTERACTIVE STATE\n // ============================================================================\n const state = {\n mode: 'film', // 'film' | 'sandbox'\n sandboxAct: 0,\n filmTime: 0.0,\n playing: true,\n selectedSeat: 5, // 0..4 = Citadel models, 5 = Seat 06 Carbon\n pointerDown: false,\n dragX: 0, dragY: 0,\n lastX: 0, lastY: 0,\n // Interactive parameters per act\n bhYaw: 0.0, bhPitch: 0.23, bhSpin: 0.72,\n monoYaw: 0.0, monoPitch: 0.0, monoExplode: -1, // -1 = auto in film, [0..1] in sandbox\n chladniPreset: 0,\n siliconSeed: 1,\n customBlocks: []\n };\n\n // ============================================================================\n // ASSET LOADING: MONOLITH RGB + DEPTH -> 46,080 3D VERTICES\n // ============================================================================\n const PC_W = 288, PC_H = 160, PC_COUNT = PC_W * PC_H;\n const pcPositions = new Float32Array(PC_COUNT * 3); // u, v, depth [0..1]\n const pcColors = new Float32Array(PC_COUNT * 3);\n let monolithImg = null;\n let assetsReadyResolve;\n const assetsReady = new Promise((res) => { assetsReadyResolve = res; });\n\n (function loadMonolithData() {\n const imgC = new Image();\n const imgD = new Image();\n let loaded = 0;\n const onBoth = () => {\n loaded++;\n if (loaded < 2) return;\n monolithImg = imgC;\n\n const offC = document.createElement('canvas');\n offC.width = PC_W; offC.height = PC_H;\n const cCtx = offC.getContext('2d');\n cCtx.drawImage(imgC, 0, 0, PC_W, PC_H);\n const rgb = cCtx.getImageData(0, 0, PC_W, PC_H).data;\n\n const offD = document.createElement('canvas');\n offD.width = PC_W; offD.height = PC_H;\n const dCtx = offD.getContext('2d');\n dCtx.drawImage(imgD, 0, 0, PC_W, PC_H);\n const dep = dCtx.getImageData(0, 0, PC_W, PC_H).data;\n\n const rng = makeRng(0x3D6CCA4B);\n let ptr = 0;\n for (let y = 0; y < PC_H; y++) {\n for (let x = 0; x < PC_W; x++) {\n const i4 = (y * PC_W + x) * 4;\n const u = (x + (rng() - 0.5) * 0.45) / PC_W;\n const v = (y + (rng() - 0.5) * 0.45) / PC_H;\n const d = dep[i4] / 255.0;\n pcPositions[ptr * 3 + 0] = u;\n pcPositions[ptr * 3 + 1] = v;\n pcPositions[ptr * 3 + 2] = d;\n\n pcColors[ptr * 3 + 0] = rgb[i4 + 0] / 255.0;\n pcColors[ptr * 3 + 1] = rgb[i4 + 1] / 255.0;\n pcColors[ptr * 3 + 2] = rgb[i4 + 2] / 255.0;\n ptr++;\n }\n }\n initPointCloudGL();\n assetsReadyResolve();\n };\n imgC.onload = onBoth;\n imgD.onload = onBoth;\n imgC.src = MONOLITH_JPG;\n imgD.src = MONOLITH_DEPTH;\n })();\n\n // ============================================================================\n // WEBGL2 PIPELINES: (A) KERR BLACK HOLE GEODESIC SHADER, (B) 3D POINT SCULPTURE\n // ============================================================================\n function compileShader(type, src) {\n const s = gl.createShader(type);\n gl.shaderSource(s, src);\n gl.compileShader(s);\n if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) {\n console.error(gl.getShaderInfoLog(s));\n }\n return s;\n }\n function linkProgram(vsSrc, fsSrc) {\n const p = gl.createProgram();\n gl.attachShader(p, compileShader(gl.VERTEX_SHADER, vsSrc));\n gl.attachShader(p, compileShader(gl.FRAGMENT_SHADER, fsSrc));\n gl.linkProgram(p);\n return p;\n }\n\n // Program A: Fullscreen Relativistic Kerr/Schwarzschild Black Hole Raymarcher\n const bhVS = \\`#version 300 es\n layout(location=0) in vec2 aPos;\n out vec2 vUv;\n void main() {\n vUv = aPos * 0.5 + 0.5;\n gl_Position = vec4(aPos, 0.0, 1.0);\n }\\`;\n\n const bhFS = \\`#version 300 es\n precision highp float;\n in vec2 vUv;\n out vec4 fragColor;\n\n uniform vec2 uRes;\n uniform float uTime;\n uniform float uYaw;\n uniform float uPitch;\n uniform float uSpin;\n uniform float uAudioPulse;\n\n float hash21(vec2 p) {\n p = fract(p * vec2(234.34, 435.345));\n p += dot(p, p + 34.23);\n return fract(p.x * p.y);\n }\n\n float noise(vec2 p) {\n vec2 i = floor(p), f = fract(p);\n f = f * f * (3.0 - 2.0 * f);\n float a = hash21(i);\n float b = hash21(i + vec2(1.0, 0.0));\n float c = hash21(i + vec2(0.0, 1.0));\n float d = hash21(i + vec2(1.0, 1.0));\n return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);\n }\n\n float fbm(vec2 p) {\n float v = 0.0, a = 0.5;\n mat2 rot = mat2(0.8, 0.6, -0.6, 0.8);\n for (int i = 0; i < 4; i++) {\n v += a * noise(p);\n p = rot * p * 2.03;\n a *= 0.5;\n }\n return v;\n }\n\n // Physical Planckian blackbody locus approximation\n vec3 blackbody(float tempK) {\n float t = clamp(tempK / 1000.0, 1.0, 14.0);\n vec3 col;\n col.r = t <= 6.6 ? 1.0 : clamp(1.292 * pow(t - 6.0, -0.133), 0.0, 1.0);\n col.g = t <= 6.6\n ? clamp(0.390 * log(max(t, 1.01)) - 0.634, 0.0, 1.0)\n : clamp(1.129 * pow(t - 6.0, -0.0755), 0.0, 1.0);\n col.b = t >= 6.6 ? 1.0 : (t <= 1.9 ? 0.0 : clamp(0.543 * log(t - 1.0) - 1.196, 0.0, 1.0));\n return col;\n }\n\n vec3 starfield(vec3 dir) {\n vec2 sp = vec2(atan(dir.z, dir.x), asin(clamp(dir.y, -1.0, 1.0)));\n vec2 grid = sp * 46.0;\n vec2 id = floor(grid);\n vec2 gv = fract(grid) - 0.5;\n float h = hash21(id);\n vec3 col = vec3(0.0);\n if (h > 0.86) {\n vec2 offset = vec2(hash21(id + 7.1), hash21(id + 13.7)) - 0.5;\n float d = length(gv - offset * 0.6);\n float star = smoothstep(0.09, 0.0, d) * pow((h - 0.86) / 0.14, 1.8);\n col += blackbody(3800.0 + 6500.0 * hash21(id + 3.3)) * star * 1.5;\n }\n // Subtle warm galactic dust band\n float dust = exp(-abs(dir.y + 0.12 * dir.x) * 5.5) * fbm(sp * 4.5 + 1.2);\n col += vec3(0.08, 0.055, 0.038) * dust * 0.65;\n return col;\n }\n\n void main() {\n vec2 uv = (vUv - 0.5) * 2.0;\n uv.x *= uRes.x / uRes.y;\n\n // Slight dramatic Gargantua Dutch roll (7.5 degrees)\n float roll = -0.13;\n uv = mat2(cos(roll), -sin(roll), sin(roll), cos(roll)) * uv;\n // Shift black hole slightly right-of-center (x - 0.12) so left typography breathes cleanly!\n uv.x -= 0.12;\n\n float camDist = 11.2;\n vec3 ro = vec3(\n camDist * cos(uPitch) * sin(uYaw),\n camDist * sin(uPitch),\n camDist * cos(uPitch) * cos(uYaw)\n );\n vec3 fwd = normalize(-ro);\n vec3 right = normalize(cross(vec3(0.0, 1.0, 0.0), fwd));\n vec3 up = cross(fwd, right);\n vec3 rd = normalize(fwd * 1.72 + right * uv.x + up * uv.y);\n\n // Schwarzschild radius rs = 1.0 (Photon sphere at r = 1.5, ISCO at r = 2.1 for spinning Kerr)\n const float rs = 1.0;\n vec3 pos = ro;\n vec3 dir = rd;\n vec3 hVec = cross(pos, dir);\n float h2 = dot(hVec, hVec);\n\n vec3 accumGlow = vec3(0.0);\n float transmittance = 1.0;\n bool swallowed = false;\n float minR = 100.0;\n\n for (int i = 0; i < 56; i++) {\n float r2 = dot(pos, pos);\n float r = sqrt(r2);\n minR = min(minR, r);\n if (r < rs * 1.01) {\n swallowed = true;\n break;\n }\n if (r > 20.0 && i > 12) break;\n\n // Exact GR null geodesic curvature: a = -1.5 * rs * L^2 / r^5 * pos + Kerr frame dragging\n vec3 accel = -1.5 * rs * h2 * pos / (r2 * r2 * r);\n vec3 spinAxis = vec3(0.0, 1.0, 0.0);\n vec3 frameDrag = uSpin * 0.32 * cross(spinAxis, dir) / (r2 * r);\n\n float dt = clamp(0.055 * (r - 0.72), 0.022, 0.48);\n vec3 prevPos = pos;\n dir = normalize(dir + (accel + frameDrag) * dt);\n pos += dir * dt;\n\n // Check equatorial accretion disk plane crossing (y = 0) + volumetric corona!\n if (prevPos.y * pos.y <= 0.0 || abs(pos.y) < 0.22) {\n float frac = prevPos.y * pos.y <= 0.0\n ? abs(prevPos.y) / (abs(prevPos.y) + abs(pos.y) + 1e-5)\n : 0.5;\n vec3 hit = mix(prevPos, pos, frac);\n float diskR = length(hit.xz);\n float vertFade = prevPos.y * pos.y <= 0.0 ? 1.0 : exp(-abs(pos.y) * 16.0) * 0.28;\n\n if (diskR > 1.85 && diskR < 8.6) {\n // Keplerian differential rotation omega ~ r^(-1.5)\n float omega = 2.6 * pow(diskR, -1.35);\n float angle = atan(hit.z, hit.x) + uTime * omega;\n\n // Multi-scale MHD spiral filaments\n float spiral1 = fbm(vec2(diskR * 2.9, angle * 2.0 + diskR * 1.6));\n float spiral2 = fbm(vec2(diskR * 7.5 - uTime * 0.4, angle * 4.0 - diskR * 2.8));\n float rings = 0.6 + 0.4 * sin(diskR * 9.5 + spiral1 * 3.5);\n float density = smoothstep(1.85, 2.35, diskR) * smoothstep(8.6, 3.6, diskR);\n density *= (0.35 + 0.85 * spiral1 * spiral2 + 0.25 * rings) * vertFade;\n\n // Relativistic orbital velocity tangent & Doppler factor D = 1 / (gamma * (1 - beta * cosTheta))\n vec3 velDir = normalize(vec3(-hit.z, 0.0, hit.x));\n float beta = clamp(sqrt(0.5 * rs / max(diskR - rs, 0.35)) * (0.85 + 0.2 * uSpin), 0.0, 0.68);\n float gamma = inversesqrt(1.0 - beta * beta);\n float cosTheta = dot(velDir, -dir); // positive when approaching observer!\n float doppler = 1.0 / (gamma * (1.0 - beta * cosTheta));\n float gravRedshift = sqrt(clamp(1.0 - rs / diskR, 0.08, 1.0));\n float shift = doppler * gravRedshift;\n\n // Temperature profile T ~ r^(-3/4) * shift\n float baseTemp = 5600.0 * pow(2.2 / diskR, 0.62) * pow(shift, 0.92);\n vec3 emit = blackbody(baseTemp) * pow(shift, 3.1) * density * (1.55 + 0.35 * uAudioPulse);\n\n accumGlow += transmittance * emit;\n transmittance *= exp(-density * 0.62);\n if (transmittance < 0.02) break;\n }\n }\n }\n\n // Razor-thin relativistic Einstein photon ring glow around minR ~ 1.5 rs\n float photonRing = exp(-abs(minR - 1.48) * 18.0) * (swallowed ? 0.55 : 1.15);\n accumGlow += blackbody(7200.0) * photonRing * (0.55 + 0.25 * uAudioPulse);\n\n vec3 bg = swallowed ? vec3(0.0) : starfield(dir) * transmittance;\n vec3 col = bg + accumGlow;\n\n // Filmic ACES tonemapping\n col = (col * (2.51 * col + 0.03)) / (col * (2.43 * col + 0.59) + 0.14);\n col = pow(clamp(col, 0.0, 1.0), vec3(0.92));\n\n // Subtle film vignette\n float vig = 1.0 - 0.32 * dot(vUv - 0.5, vUv - 0.5) * 1.8;\n fragColor = vec4(col * vig, 1.0);\n }\\`;\n\n // Program B: 3D Volumetric Point-Cloud Monolith Reconstruction\n const pcVS = \\`#version 300 es\n layout(location=0) in vec3 aUVD;\n layout(location=1) in vec3 aCol;\n\n uniform vec2 uRes;\n uniform float uExplode;\n uniform float uYaw;\n uniform float uPitch;\n uniform float uScanX;\n uniform float uTime;\n\n out vec3 vCol;\n out float vAlpha;\n\n void main() {\n float u = aUVD.x;\n float v = aUVD.y;\n float d = aUVD.z; // 0 = far back wall, 1 = closest foreground\n\n // Laser scan wave reveals 3D depth progressively\n float scanMask = smoothstep(u - 0.09, u + 0.02, uScanX);\n float active3D = uExplode * scanMask;\n\n float aspect = 16.0 / 9.0;\n // In flat 2D mode (active3D = 0): exact image plane\n vec3 flatPos = vec3((u - 0.5) * aspect * 1.26, (0.5 - v) * 1.26, 0.0);\n\n // In 3D volumetric chamber mode: perspective unprojection using spatial depth d\n float zWorld = (d - 0.46) * 1.55;\n float perspScale = 1.34 - 0.38 * d;\n vec3 volPos = vec3(\n (u - 0.5) * aspect * perspScale,\n (0.5 - v) * perspScale,\n zWorld\n );\n\n // Subtle floating dust shimmer in the diagonal golden sunbeam\n float lum = dot(aCol, vec3(0.299, 0.587, 0.114));\n if (d > 0.42 && d < 0.55 && lum > 0.32) {\n volPos.y += sin(uTime * 1.8 + u * 35.0 + v * 21.0) * 0.012 * active3D;\n }\n\n vec3 p = mix(flatPos, volPos, active3D);\n\n // Orbit rotation\n float cy = cos(uYaw * active3D), sy = sin(uYaw * active3D);\n float cp = cos(uPitch * active3D), sp = sin(uPitch * active3D);\n p.xz = mat2(cy, -sy, sy, cy) * p.xz;\n p.yz = mat2(cp, -sp, sp, cp) * p.yz;\n\n // Slight shift right so left editorial HUD stays clean\n p.x += 0.14 * active3D;\n\n float camZ = 2.45;\n float zDist = max(0.35, camZ - p.z);\n float fov = 1.72;\n vec2 proj = p.xy * (fov / zDist);\n proj.x /= (uRes.x / uRes.y);\n\n gl_Position = vec4(proj, (zDist - 0.35) / 5.0 * 2.0 - 1.0, 1.0);\n\n float scaleFactor = uRes.y / 1080.0;\n float basePt = mix(5.4, 4.1, active3D) * scaleFactor * (2.2 / zDist);\n // Golden scanline highlight right at u ~ uScanX\n float scanGlow = exp(-abs(u - uScanX) * 42.0) * step(0.01, uScanX) * step(uScanX, 0.99);\n\n gl_PointSize = clamp(basePt + scanGlow * 3.5 * scaleFactor, 1.2, 14.0);\n vCol = aCol * (1.0 + 0.18 * active3D) + vec3(1.0, 0.78, 0.36) * scanGlow * 0.85;\n vAlpha = mix(0.98, clamp(0.55 + 0.45 * lum + 0.25 * d, 0.35, 0.96), active3D);\n }\\`;\n\n const pcFS = \\`#version 300 es\n precision highp float;\n in vec3 vCol;\n in float vAlpha;\n out vec4 fragColor;\n void main() {\n vec2 c = gl_PointCoord - 0.5;\n float r2 = dot(c, c);\n if (r2 > 0.25) discard;\n float soft = smoothstep(0.25, 0.06, r2);\n fragColor = vec4(vCol, vAlpha * soft);\n }\\`;\n\n const bhProg = linkProgram(bhVS, bhFS);\n const pcProg = linkProgram(pcVS, pcFS);\n\n // Fullscreen quad VAO\n const quadVao = gl.createVertexArray();\n gl.bindVertexArray(quadVao);\n const quadBuf = gl.createBuffer();\n gl.bindBuffer(gl.ARRAY_BUFFER, quadBuf);\n gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1,-1, 1,-1, -1,1, 1,1]), gl.STATIC_DRAW);\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n\n let pcVao = null;\n function initPointCloudGL() {\n pcVao = gl.createVertexArray();\n gl.bindVertexArray(pcVao);\n\n const bPos = gl.createBuffer();\n gl.bindBuffer(gl.ARRAY_BUFFER, bPos);\n gl.bufferData(gl.ARRAY_BUFFER, pcPositions, gl.STATIC_DRAW);\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);\n\n const bCol = gl.createBuffer();\n gl.bindBuffer(gl.ARRAY_BUFFER, bCol);\n gl.bufferData(gl.ARRAY_BUFFER, pcColors, gl.STATIC_DRAW);\n gl.enableVertexAttribArray(1);\n gl.vertexAttribPointer(1, 3, gl.FLOAT, false, 0, 0);\n }\n\n // ============================================================================\n // ACT I & VI: 3D CARBON sp3 DIAMOND / FULLERENE LATTICE GEOMETRY\n // ============================================================================\n const carbonAtoms = [];\n const carbonBonds = [];\n (function buildCarbonLattice() {\n // Build a crystalline diamond-cubic sp3 cluster truncated to a hexagonal polyhedron!\n const pts = [];\n for (let x = -2; x <= 2; x++) {\n for (let y = -2; y <= 2; y++) {\n for (let z = -2; z <= 2; z++) {\n const basis = [\n [0, 0, 0], [0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0],\n [0.25, 0.25, 0.25], [0.25, 0.75, 0.75], [0.75, 0.25, 0.75], [0.75, 0.75, 0.25]\n ];\n for (const b of basis) {\n const px = x + b[0] - 0.25;\n const py = y + b[1] - 0.25;\n const pz = z + b[2] - 0.25;\n const d = Math.hypot(px, py, pz);\n if (d <= 1.28) {\n pts.push({ x: px / 1.28, y: py / 1.28, z: pz / 1.28, r: d / 1.28 });\n }\n }\n }\n }\n }\n carbonAtoms.push(...pts);\n // Exact nearest-neighbor covalent bonds (d_nn = sqrt(3)/4 in unit cell = 0.433 / 1.28 = 0.338)\n for (let i = 0; i < carbonAtoms.length; i++) {\n for (let j = i + 1; j < carbonAtoms.length; j++) {\n const dx = carbonAtoms[i].x - carbonAtoms[j].x;\n const dy = carbonAtoms[i].y - carbonAtoms[j].y;\n const dz = carbonAtoms[i].z - carbonAtoms[j].z;\n const dist = Math.hypot(dx, dy, dz);\n if (dist > 0.22 && dist < 0.39) {\n carbonBonds.push([i, j]);\n }\n }\n }\n })();\n\n // ============================================================================\n // ACT III: REAL OCTILINEAR A* RIP-UP & REROUTE SILICON DIE SOLVER\n // ============================================================================\n let siliconData = null;\n function buildSiliconRouter(seed = 1, extraBlocks = []) {\n const GW = 68, GH = 38;\n const rng = makeRng(0x5171C000 + seed * 9973);\n\n // 4 architectural silicon macro cores (ALU, TENSOR, CACHE, IO-BRIDGE) + user custom blocks\n const blocks = [\n { x: 18, y: 8, w: 10, h: 7, label: 'CORE_ALU' },\n { x: 40, y: 8, w: 11, h: 7, label: 'TENSOR_6C' },\n { x: 19, y: 23, w: 11, h: 7, label: 'L2_FABRIC' },\n { x: 41, y: 23, w: 10, h: 7, label: 'VERIFY_UNIT' },\n ...extraBlocks\n ];\n\n const blocked = new Uint8Array(GW * GH);\n for (const b of blocks) {\n for (let y = Math.max(0, b.y); y < Math.min(GH, b.y + b.h); y++) {\n for (let x = Math.max(0, b.x); x < Math.min(GW, b.x + b.w); x++) {\n blocked[y * GW + x] = 1;\n }\n }\n }\n\n // Generate 28 high-density cross-die net pairs guaranteed to cross heavily if unrouted!\n const nets = [];\n const usedPins = new Set();\n const pickFreeEdge = (x0, y0, x1, y1) => {\n for (let tries = 0; tries < 80; tries++) {\n const x = Math.floor(x0 + rng() * (x1 - x0 + 1));\n const y = Math.floor(y0 + rng() * (y1 - y0 + 1));\n const k = y * GW + x;\n if (!blocked[k] && !usedPins.has(k)) {\n usedPins.add(k);\n return { x, y };\n }\n }\n return null;\n };\n\n const regions = [\n [[4, 4, 14, 16], [53, 20, 63, 33]],\n [[4, 21, 15, 33], [53, 4, 63, 16]],\n [[16, 2, 33, 5], [34, 32, 52, 35]],\n [[35, 2, 52, 5], [16, 32, 33, 35]],\n [[30, 10, 37, 14], [30, 24, 38, 28]],\n [[14, 16, 17, 22], [52, 15, 56, 22]]\n ];\n\n for (let i = 0; i < 28; i++) {\n const [rA, rB] = regions[i % regions.length];\n const a = pickFreeEdge(...rA);\n const b = pickFreeEdge(...rB);\n if (a && b) {\n nets.push({ id: i, src: a, dst: b, layer: i % 2 });\n }\n }\n\n // Count rat's-nest geometric segment intersections for initial chaos metric\n function segIntersect(p1, p2, p3, p4) {\n const ccw = (A, B, C) => (C.y - A.y) * (B.x - A.x) > (B.y - A.y) * (C.x - A.x);\n return (ccw(p1, p3, p4) !== ccw(p2, p3, p4)) && (ccw(p1, p2, p3) !== ccw(p1, p2, p4));\n }\n let ratsCollisions = 0;\n for (let i = 0; i < nets.length; i++) {\n for (let j = i + 1; j < nets.length; j++) {\n if (segIntersect(nets[i].src, nets[i].dst, nets[j].src, nets[j].dst)) ratsCollisions++;\n }\n }\n\n // Negotiated-Congestion Octilinear A* Router (PathFinder algorithm!)\n const dirs = [\n [1, 0, 1.0], [-1, 0, 1.0], [0, 1, 1.0], [0, -1, 1.0],\n [1, 1, 1.414], [1, -1, 1.414], [-1, 1, 1.414], [-1, -1, 1.414]\n ];\n const history = new Float32Array(GW * GH).fill(1.0);\n const occ = new Int16Array(GW * GH);\n const paths = new Array(nets.length);\n const snapshots = []; // Store intermediate iterations for visual solver playback!\n\n function routeSingleNet(net, penaltyFactor) {\n const start = net.src.y * GW + net.src.x;\n const goal = net.dst.y * GW + net.dst.x;\n const gScore = new Float32Array(GW * GH).fill(1e9);\n const parent = new Int32Array(GW * GH).fill(-1);\n const closed = new Uint8Array(GW * GH);\n\n // Binary min-heap\n const heapNode = [];\n const heapF = [];\n const push = (node, f) => {\n let idx = heapNode.length;\n heapNode.push(node); heapF.push(f);\n while (idx > 0) {\n const p = (idx - 1) >> 1;\n if (heapF[p] <= f) break;\n heapNode[idx] = heapNode[p]; heapF[idx] = heapF[p];\n idx = p;\n }\n heapNode[idx] = node; heapF[idx] = f;\n };\n const pop = () => {\n const top = heapNode[0];\n const lastN = heapNode.pop(), lastF = heapF.pop();\n if (heapNode.length > 0) {\n let idx = 0;\n const len = heapNode.length;\n while (true) {\n let l = idx * 2 + 1, r = l + 1, sm = idx;\n if (l < len && heapF[l] < lastF && (r >= len || heapF[l] <= heapF[r])) sm = l;\n else if (r < len && heapF[r] < lastF) sm = r;\n if (sm === idx) break;\n heapNode[idx] = heapNode[sm]; heapF[idx] = heapF[sm];\n idx = sm;\n }\n heapNode[idx] = lastN; heapF[idx] = lastF;\n }\n return top;\n };\n\n gScore[start] = 0;\n push(start, 0);\n\n while (heapNode.length > 0) {\n const cur = pop();\n if (cur === goal) break;\n if (closed[cur]) continue;\n closed[cur] = 1;\n\n const cx = cur % GW, cy = (cur / GW) | 0;\n const pNode = parent[cur];\n const pdx = pNode >= 0 ? cx - (pNode % GW) : 0;\n const pdy = pNode >= 0 ? cy - ((pNode / GW) | 0) : 0;\n\n for (let d = 0; d < 8; d++) {\n const [dx, dy, baseCost] = dirs[d];\n const nx = cx + dx, ny = cy + dy;\n if (nx < 1 || nx >= GW - 1 || ny < 1 || ny >= GH - 1) continue;\n const nk = ny * GW + nx;\n if (blocked[nk] && nk !== goal) continue;\n if (usedPins.has(nk) && nk !== goal && nk !== start) continue;\n // Prevent diagonal corner-cutting across blocked cells\n if (dx !== 0 && dy !== 0) {\n if (blocked[cy * GW + nx] || blocked[ny * GW + cx]) continue;\n }\n if (closed[nk]) continue;\n\n const bend = (pNode >= 0 && (dx !== pdx || dy !== pdy)) ? 0.32 : 0.0;\n const cong = occ[nk] > 0 ? (1.0 + occ[nk] * penaltyFactor) * history[nk] : 0.0;\n const tentative = gScore[cur] + baseCost + bend + cong;\n\n if (tentative < gScore[nk]) {\n gScore[nk] = tentative;\n parent[nk] = cur;\n const rdx = Math.abs(nx - net.dst.x), rdy = Math.abs(ny - net.dst.y);\n const h = (rdx + rdy) + (1.414 - 2.0) * Math.min(rdx, rdy);\n push(nk, tentative + h * 1.05);\n }\n }\n }\n\n const pts = [];\n let c = goal;\n while (c >= 0) {\n pts.push({ x: c % GW, y: (c / GW) | 0, k: c });\n if (c === start) break;\n c = parent[c];\n }\n pts.reverse();\n return pts.length > 1 ? pts : [net.src, net.dst];\n }\n\n // Run 5 negotiated-congestion rip-up passes until 0 overlaps!\n for (let iter = 0; iter < 5; iter++) {\n const pen = 1.8 * Math.pow(2.8, iter);\n for (let i = 0; i < nets.length; i++) {\n if (paths[i]) {\n for (const p of paths[i]) if (p.k !== undefined) occ[p.k]--;\n }\n paths[i] = routeSingleNet(nets[i], pen);\n for (const p of paths[i]) if (p.k !== undefined) occ[p.k]++;\n }\n let overlaps = 0;\n const conflictCells = [];\n for (let k = 0; k < GW * GH; k++) {\n if (occ[k] > 1) {\n overlaps += occ[k] - 1;\n history[k] += 1.6 * (occ[k] - 1);\n conflictCells.push({ x: k % GW, y: (k / GW) | 0 });\n }\n }\n snapshots.push({\n paths: paths.map((p) => p.map((q) => ({ x: q.x, y: q.y }))),\n overlaps,\n conflictCells\n });\n if (overlaps === 0 && iter >= 2) break;\n }\n\n siliconData = { GW, GH, blocks, nets, ratsCollisions, snapshots };\n }\n buildSiliconRouter(1, []);\n\n // ============================================================================\n // ACT V: CHLADNI CYMATICS DETERMINISTIC & LIVE PARTICLE SOLVER (24,000 GRAINS)\n // ============================================================================\n const CHLADNI_MODES = [\n { n: 3, m: 5, n2: 2, m2: 7, a: 1.0, b: 0.28, label: 'MODE (3, 5) · Eb LYDIAN', notes: [51, 58, 62, 65, 69, 74] },\n { n: 5, m: 8, n2: 3, m2: 7, a: 1.0, b: -0.32,label: 'MODE (5, 8) · G MINOR 9', notes: [55, 58, 62, 65, 69, 74] },\n { n: 6, m: 11, n2: 4, m2: 9, a: 1.0, b: 0.35, label: 'MODE (6, 11) · A7 SUS4', notes: [45, 52, 57, 62, 64, 67, 72] },\n { n: 7, m: 12, n2: 5, m2: 9, a: 1.0, b: -0.4, label: 'MODE (7, 12) · D MAJ 9', notes: [50, 57, 62, 66, 69, 73, 76] }\n ];\n\n const GRAIN_COUNT = 20000;\n // Precompute crystallized nodal targets for each Chladni eigenmode so film scrub is O(1) deterministic!\n const chladniTargets = CHLADNI_MODES.map((mode, mIdx) => {\n const arr = new Float32Array(GRAIN_COUNT * 2);\n const rng = makeRng(0xC41AD00 + mIdx * 7919);\n const PI = Math.PI;\n const evalPsi = (x, y) => {\n return mode.a * (Math.cos(mode.n * PI * x) * Math.cos(mode.m * PI * y) - Math.cos(mode.m * PI * x) * Math.cos(mode.n * PI * y))\n + mode.b * (Math.cos(mode.n2 * PI * x) * Math.cos(mode.m2 * PI * y) - Math.cos(mode.m2 * PI * x) * Math.cos(mode.n2 * PI * y));\n };\n for (let i = 0; i < GRAIN_COUNT; i++) {\n let x = rng() * 2 - 1;\n let y = rng() * 2 - 1;\n // 22 gradient-descent + stochastic steps onto exact Chladni nodal curves!\n for (let s = 0; s < 22; s++) {\n const p = evalPsi(x, y);\n const ap = Math.abs(p);\n if (ap < 0.012) break;\n const eps = 0.004;\n const gx = (Math.abs(evalPsi(x + eps, y)) - ap) / eps;\n const gy = (Math.abs(evalPsi(x, y + eps)) - ap) / eps;\n const step = 0.022 * Math.min(1.0, ap * 1.6);\n const norm = Math.hypot(gx, gy) + 1e-5;\n x -= (gx / norm) * step + (rng() - 0.5) * 0.018 * ap;\n y -= (gy / norm) * step + (rng() - 0.5) * 0.018 * ap;\n if (x < -0.98 || x > 0.98) x = (rng() * 1.92) - 0.96;\n if (y < -0.98 || y > 0.98) y = (rng() * 1.92) - 0.96;\n }\n arr[i * 2] = x;\n arr[i * 2 + 1] = y;\n }\n return arr;\n });\n const grainScatter = (() => {\n const arr = new Float32Array(GRAIN_COUNT * 2);\n const rng = makeRng(0x99887766);\n for (let i = 0; i < GRAIN_COUNT * 2; i++) arr[i] = (rng() - 0.5) * 2.0;\n return arr;\n })();\n\n // ============================================================================\n // LIVE WEBAUDIO POLYPHONIC SYNTHESIZER (FOR INTERACTIVE BROWSER EMBED!)\n // ============================================================================\n let audioCtx = null;\n let masterGain = null;\n let convolver = null;\n let soundEnabled = false;\n let lastScheduledBeat = -1;\n\n function initWebAudio() {\n if (audioCtx) return;\n const AC = window.AudioContext || window.webkitAudioContext;\n audioCtx = new AC();\n masterGain = audioCtx.createGain();\n masterGain.gain.value = 0.72;\n\n // Synthesize lush algorithmic stereo hall impulse response in memory (2.6s)\n const irLen = Math.floor(audioCtx.sampleRate * 2.6);\n const irBuf = audioCtx.createBuffer(2, irLen, audioCtx.sampleRate);\n const rng = makeRng(0xACE1234);\n for (let ch = 0; ch < 2; ch++) {\n const data = irBuf.getChannelData(ch);\n let lp = 0;\n for (let i = 0; i < irLen; i++) {\n const t = i / audioCtx.sampleRate;\n const env = Math.exp(-t * 2.4) * (1 - Math.exp(-t * 45));\n lp += 0.28 * ((rng() * 2 - 1) - lp);\n data[i] = lp * env * 0.45;\n }\n }\n convolver = audioCtx.createConvolver();\n convolver.buffer = irBuf;\n\n const wetGain = audioCtx.createGain();\n wetGain.gain.value = 0.42;\n convolver.connect(wetGain);\n wetGain.connect(masterGain);\n masterGain.connect(audioCtx.destination);\n }\n\n function playPluckNote(midi, dur = 2.2, vol = 0.12, panVal = 0) {\n if (!audioCtx || !soundEnabled) return;\n const now = audioCtx.currentTime;\n const freq = 440 * Math.pow(2, (midi - 69) / 12);\n\n const osc1 = audioCtx.createOscillator();\n const osc2 = audioCtx.createOscillator();\n osc1.type = 'triangle';\n osc2.type = 'sine';\n osc1.frequency.setValueAtTime(freq, now);\n osc2.frequency.setValueAtTime(freq * 2.0, now);\n\n const filt = audioCtx.createBiquadFilter();\n filt.type = 'lowpass';\n filt.frequency.setValueAtTime(Math.min(9000, freq * 6.5), now);\n filt.frequency.exponentialRampToValueAtTime(Math.max(180, freq * 1.3), now + dur * 0.85);\n\n const env = audioCtx.createGain();\n env.gain.setValueAtTime(0.0001, now);\n env.gain.linearRampToValueAtTime(vol, now + 0.012);\n env.gain.exponentialRampToValueAtTime(0.0008, now + dur);\n\n const panner = audioCtx.createStereoPanner();\n panner.pan.value = Math.max(-1, Math.min(1, panVal));\n\n osc1.connect(filt);\n osc2.connect(filt);\n filt.connect(env);\n env.connect(panner);\n panner.connect(masterGain);\n panner.connect(convolver);\n\n osc1.start(now); osc2.start(now);\n osc1.stop(now + dur + 0.05); osc2.stop(now + dur + 0.05);\n }\n\n function playChord(notes, dur = 2.6, vol = 0.09) {\n if (!audioCtx || !soundEnabled) return;\n notes.forEach((m, i) => {\n setTimeout(() => {\n playPluckNote(m, dur, vol, ((i / Math.max(1, notes.length - 1)) - 0.5) * 1.1);\n }, i * 18);\n });\n }\n\n // Trigger musical harmony in browser Film mode when soundEnabled is ON\n const FILM_CHORDS = [\n { beat: 0, notes: [62, 65, 69, 72, 76], dur: 2.2 },\n { beat: 8, notes: [38, 50, 57, 62, 65, 69, 76], dur: 2.8 },\n { beat: 12, notes: [34, 46, 53, 57, 62, 64, 69], dur: 3.6 },\n { beat: 20, notes: [43, 50, 58, 60, 62, 69], dur: 3.2 },\n { beat: 26, notes: [38, 50, 57, 64, 65, 72], dur: 2.2 },\n { beat: 34, notes: [41, 53, 57, 60, 64, 67, 72], dur: 2.6 },\n { beat: 39, notes: [38, 50, 53, 57, 60, 64, 74], dur: 2.8 },\n { beat: 44, notes: [34, 46, 53, 57, 62, 64, 74], dur: 3.4 },\n { beat: 53, notes: [51, 58, 62, 65, 69, 74], dur: 2.4 },\n { beat: 57, notes: [43, 55, 58, 62, 65, 69, 74], dur: 2.4 },\n { beat: 62, notes: [45, 52, 57, 62, 64, 67, 72], dur: 2.4 },\n { beat: 66, notes: [38, 45, 50, 54, 57, 61, 64, 69, 74], dur: 5.5 }\n ];\n\n // ============================================================================\n // DRAWING HELPERS (CRISP SWISS / ARCHITECTURAL HUD AT ANY ASPECT RATIO)\n // ============================================================================\n function clamp(v, a, b) { return Math.max(a, Math.min(b, v)); }\n function smoothstep(e0, e1, x) {\n const t = clamp((x - e0) / (e1 - e0 || 1e-6), 0, 1);\n return t * t * (3 - 2 * t);\n }\n function easeOutCubic(x) { const t = clamp(x, 0, 1); return 1 - Math.pow(1 - t, 3); }\n function easeInOutCubic(x) {\n const t = clamp(x, 0, 1);\n return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;\n }\n\n function getTelemetryAt(t) {\n const idx = clamp(Math.floor((t % DURATION) * FPS), 0, TEL.rms.length - 1);\n return {\n rms: (TEL.rms[idx] || 0) / 1000,\n low: (TEL.low[idx] || 0) / 1000,\n high: (TEL.high[idx] || 0) / 1000,\n L: TEL.L[idx] || [],\n R: TEL.R[idx] || []\n };\n }\n\n function drawEditorialScrim(W, H, u, strength = 0.82) {\n // Bottom-left atmospheric gradient scrim so kinetic typography ALWAYS has AAA contrast\n const grad = ctx.createLinearGradient(0, H * 0.48, 0, H);\n grad.addColorStop(0, 'rgba(6, 6, 8, 0.0)');\n grad.addColorStop(0.45, \\`rgba(6, 6, 8, \\${(0.48 * strength).toFixed(3)})\\`);\n grad.addColorStop(1, \\`rgba(6, 6, 8, \\${(0.88 * strength).toFixed(3)})\\`);\n ctx.fillStyle = grad;\n ctx.fillRect(0, H * 0.45, W, H * 0.55);\n\n // Top subtle bar scrim\n const topG = ctx.createLinearGradient(0, 0, 0, 130 * u);\n topG.addColorStop(0, 'rgba(6, 6, 8, 0.65)');\n topG.addColorStop(1, 'rgba(6, 6, 8, 0.0)');\n ctx.fillStyle = topG;\n ctx.fillRect(0, 0, W, 130 * u);\n }\n\n function drawGlobalFrameHUD(W, H, u, actIndex, t, tel) {\n const padX = 64 * u;\n const padY = 44 * u;\n const act = ACTS[actIndex];\n\n // Top-left 6C Hexagonal Element Seal + Identity\n ctx.save();\n const hexR = 20 * u;\n const hx = padX + hexR, hy = padY + 8 * u;\n ctx.beginPath();\n for (let i = 0; i < 6; i++) {\n const a = (Math.PI / 3) * i - Math.PI / 6;\n const px = hx + Math.cos(a) * hexR;\n const py = hy + Math.sin(a) * hexR;\n if (i === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py);\n }\n ctx.closePath();\n ctx.fillStyle = 'rgba(245, 185, 90, 0.12)';\n ctx.fill();\n ctx.lineWidth = Math.max(1, 1.4 * u);\n ctx.strokeStyle = 'rgba(245, 185, 90, 0.78)';\n ctx.stroke();\n\n ctx.fillStyle = '#FFF1D0';\n ctx.font = \\`700 \\${Math.round(13 * u)}px 'Nimbus Sans', 'Inter', sans-serif\\`;\n ctx.textAlign = 'center';\n ctx.textBaseline = 'middle';\n ctx.fillText('6C', hx, hy + 0.5 * u);\n\n ctx.textAlign = 'left';\n ctx.fillStyle = '#F4F1EA';\n ctx.font = \\`600 \\${Math.round(13 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('GEMINI 4 CARBON × ANTIGRAVITY', hx + 30 * u, hy - 6 * u);\n\n ctx.fillStyle = '#9A968C';\n ctx.font = \\`400 \\${Math.round(11.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(\\`\\${act.code} · \\${act.name}\\`, hx + 30 * u, hy + 11 * u);\n\n // Top-right telemetry & mini Lissajous stereo scope (in render mode or when buttons don't overlap)\n if (IS_RENDER) {\n const rx = W - padX;\n ctx.textAlign = 'right';\n ctx.fillStyle = '#F5B95A';\n ctx.font = \\`500 \\${Math.round(12 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(\\`T+ \\${t.toFixed(2).padStart(5, '0')}s // 60.00 FPS\\`, rx - 46 * u, hy - 6 * u);\n ctx.fillStyle = '#8E8B82';\n ctx.font = \\`400 \\${Math.round(11 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(\\`ELEMENT 06 · 12.011 u\\`, rx - 46 * u, hy + 11 * u);\n\n // Tiny circular stereo phase scope\n const sx = rx - 16 * u, sy = hy + 2 * u, sr = 18 * u;\n ctx.beginPath();\n ctx.arc(sx, sy, sr, 0, Math.PI * 2);\n ctx.strokeStyle = 'rgba(244, 241, 234, 0.18)';\n ctx.stroke();\n if (tel.L.length > 1) {\n ctx.beginPath();\n for (let i = 0; i < tel.L.length; i++) {\n const l = tel.L[i] / 127, r = tel.R[i] / 127;\n const px = sx + (l - r) * 0.65 * sr;\n const py = sy - (l + r) * 0.55 * sr;\n if (i === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py);\n }\n ctx.strokeStyle = 'rgba(245, 185, 90, 0.85)';\n ctx.lineWidth = Math.max(1, 1.3 * u);\n ctx.stroke();\n }\n\n // Sleek 6-segment film progress line along bottom edge\n const barY = H - 22 * u;\n const totalBarW = W - padX * 2;\n for (let i = 0; i < ACTS.length; i++) {\n const a = ACTS[i];\n const x0 = padX + (a.start / DURATION) * totalBarW + (i > 0 ? 4 * u : 0);\n const x1 = padX + (a.end / DURATION) * totalBarW - (i < 5 ? 4 * u : 0);\n ctx.fillStyle = 'rgba(244, 241, 234, 0.13)';\n ctx.fillRect(x0, barY, x1 - x0, 2 * u);\n if (t > a.start) {\n const fillFrac = clamp((t - a.start) / (a.end - a.start), 0, 1);\n ctx.fillStyle = i === actIndex ? '#F5B95A' : 'rgba(244, 241, 234, 0.45)';\n ctx.fillRect(x0, barY, (x1 - x0) * fillFrac, 2 * u);\n }\n }\n }\n ctx.restore();\n }\n\n function drawHeadlineBlock(W, H, u, kicker, titleLines, italicSub, alpha = 1.0, formula = '') {\n if (alpha <= 0.005) return;\n ctx.save();\n ctx.globalAlpha = clamp(alpha, 0, 1);\n\n const x = 64 * u;\n const bottomBase = (IS_RENDER ? H - 64 * u : H - 88 * u);\n const lineH = 54 * u;\n const totalTitleH = titleLines.length * lineH;\n let y = bottomBase - (italicSub ? 38 * u : 0) - totalTitleH;\n\n if (kicker) {\n ctx.font = \\`600 \\${Math.round(12.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillStyle = '#F5B95A';\n ctx.fillText(kicker, x, y - 18 * u);\n }\n\n if (formula) {\n const fPad = 12 * u;\n ctx.font = \\`500 \\${Math.round(12.5 * u)}px 'Noto Sans Mono', monospace\\`;\n const tw = ctx.measureText(formula).width;\n const fx = W - 64 * u - tw - fPad * 2;\n const fy = bottomBase - 34 * u;\n if (fx > x + 520 * u) {\n ctx.fillStyle = 'rgba(12, 13, 18, 0.76)';\n ctx.strokeStyle = 'rgba(245, 185, 90, 0.34)';\n ctx.lineWidth = Math.max(1, 1.1 * u);\n ctx.beginPath();\n ctx.roundRect(fx, fy, tw + fPad * 2, 32 * u, 6 * u);\n ctx.fill(); ctx.stroke();\n ctx.fillStyle = '#FFF1D0';\n ctx.fillText(formula, fx + fPad, fy + 20 * u);\n }\n }\n\n ctx.fillStyle = '#F4F1EA';\n ctx.font = \\`700 \\${Math.round(46 * u)}px 'Nimbus Sans', 'Inter', -apple-system, sans-serif\\`;\n for (let i = 0; i < titleLines.length; i++) {\n ctx.fillText(titleLines[i], x, y + (i + 0.78) * lineH);\n }\n\n if (italicSub) {\n ctx.fillStyle = '#C9C4B8';\n ctx.font = \\`italic 400 \\${Math.round(24 * u)}px 'P052', 'Palatino', Georgia, serif\\`;\n ctx.fillText(italicSub, x, bottomBase - 4 * u);\n }\n ctx.restore();\n }\n\n // ============================================================================\n // SCENE RENDERERS FOR ALL 6 ACTS\n // ============================================================================\n\n // Helper to project & draw 3D sp3 Carbon Lattice on 2D HUD canvas\n function drawCarbonCrystal(cx, cy, radius, yaw, pitch, ignition, u, pulse = 0) {\n const cyaw = Math.cos(yaw), syaw = Math.sin(yaw);\n const cp = Math.cos(pitch), sp = Math.sin(pitch);\n\n const proj = carbonAtoms.map((a) => {\n let x = a.x * cyaw - a.z * syaw;\n let z = a.x * syaw + a.z * cyaw;\n let y = a.y * cp - z * sp;\n let z2 = a.y * sp + z * cp;\n const persp = 2.6 / (2.6 - z2 * 0.75);\n return {\n sx: cx + x * radius * persp,\n sy: cy + y * radius * persp,\n z: z2,\n r: a.r,\n persp\n };\n });\n\n ctx.save();\n if (ignition > 0.01) {\n const glow = ctx.createRadialGradient(cx, cy, 0, cx, cy, radius * (1.7 + 0.35 * pulse));\n glow.addColorStop(0, \\`rgba(255, 226, 162, \\${(0.36 * ignition).toFixed(3)})\\`);\n glow.addColorStop(0.42, \\`rgba(245, 168, 66, \\${(0.15 * ignition).toFixed(3)})\\`);\n glow.addColorStop(1, 'rgba(6, 6, 8, 0)');\n ctx.fillStyle = glow;\n ctx.beginPath();\n ctx.arc(cx, cy, radius * 2.0, 0, Math.PI * 2);\n ctx.fill();\n }\n\n // Draw covalent sp3 bonds\n ctx.lineWidth = Math.max(1, (1.1 + 0.9 * ignition) * u);\n for (const [i, j] of carbonBonds) {\n const p1 = proj[i], p2 = proj[j];\n const depthAlpha = clamp(0.25 + (p1.z + p2.z + 2) * 0.22, 0.12, 0.92);\n ctx.strokeStyle = ignition > 0.2\n ? \\`rgba(245, 190, 98, \\${(depthAlpha * (0.25 + 0.65 * ignition)).toFixed(3)})\\`\n : \\`rgba(244, 241, 234, \\${(depthAlpha * 0.26).toFixed(3)})\\`;\n ctx.beginPath();\n ctx.moveTo(p1.sx, p1.sy);\n ctx.lineTo(p2.sx, p2.sy);\n ctx.stroke();\n }\n\n // Sort atoms back-to-front\n const order = proj.map((p, idx) => idx).sort((a, b) => proj[a].z - proj[b].z);\n for (const idx of order) {\n const p = proj[idx];\n const sz = Math.max(1.4, (2.4 + 2.2 * ignition) * p.persp * u * (1 - 0.25 * p.r));\n const bright = clamp(0.4 + (p.z + 1) * 0.35, 0.2, 1.0);\n ctx.beginPath();\n ctx.arc(p.sx, p.sy, sz, 0, Math.PI * 2);\n ctx.fillStyle = ignition > 0.2\n ? \\`rgba(255, 240, 205, \\${(bright * (0.35 + 0.65 * ignition)).toFixed(3)})\\`\n : \\`rgba(195, 192, 184, \\${(bright * 0.55).toFixed(3)})\\`;\n ctx.fill();\n }\n ctx.restore();\n }\n\n // ACT I (0.0s - 6.0s): THE 297-BYTE ROOM & SEAT 06\n function renderAct0(W, H, u, localT, tel, isSandbox) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, glCanvas.width, glCanvas.height);\n gl.clearColor(0.024, 0.024, 0.032, 1.0);\n gl.clear(gl.COLOR_BUFFER_BIT);\n\n // Subtle obsidian spotlight + precision circular astrolabe rings\n const cx = W * 0.56, cy = H * 0.45;\n const bgGlow = ctx.createRadialGradient(cx, cy, 0, cx, cy, 560 * u);\n bgGlow.addColorStop(0, 'rgba(32, 28, 24, 0.55)');\n bgGlow.addColorStop(0.6, 'rgba(12, 13, 18, 0.25)');\n bgGlow.addColorStop(1, 'rgba(6, 6, 8, 0.0)');\n ctx.fillStyle = bgGlow;\n ctx.fillRect(0, 0, W, H);\n\n const ignition = isSandbox ? 1.0 : smoothstep(3.82, 4.45, localT);\n const ringR = 265 * u;\n\n // Astrolabe reference circles\n ctx.save();\n ctx.strokeStyle = 'rgba(244, 241, 234, 0.09)';\n ctx.lineWidth = Math.max(1, 1.1 * u);\n for (const mult of [0.52, 1.0, 1.24]) {\n ctx.beginPath();\n ctx.arc(cx, cy, ringR * mult, 0, Math.PI * 2);\n ctx.stroke();\n }\n\n // Shockwave flare at t = 3.85s\n if (!isSandbox && localT > 3.82 && localT < 5.4) {\n const sw = easeOutCubic((localT - 3.82) / 1.5);\n ctx.beginPath();\n ctx.arc(cx, cy, sw * 560 * u, 0, Math.PI * 2);\n ctx.strokeStyle = \\`rgba(255, 209, 128, \\${((1 - sw) * 0.75).toFixed(3)})\\`;\n ctx.lineWidth = Math.max(1.5, (5 * (1 - sw)) * u);\n ctx.stroke();\n }\n\n // Draw the 5 Citadel specialist seats around the pentagon\n const scanTimes = [0.15, 0.47, 0.79, 1.11, 1.43];\n for (let i = 0; i < 5; i++) {\n const ang = -Math.PI / 2 + (i * 2 * Math.PI) / 5;\n const nx = cx + Math.cos(ang) * ringR;\n const ny = cy + Math.sin(ang) * ringR * 0.88;\n const scanned = isSandbox ? 1.0 : smoothstep(scanTimes[i], scanTimes[i] + 0.22, localT);\n const isSel = isSandbox && state.selectedSeat === i;\n\n // Energy filament connecting all 5 lanes into Seat 06 upon ignition!\n if (ignition > 0.02) {\n const grad = ctx.createLinearGradient(nx, ny, cx, cy);\n grad.addColorStop(0, 'rgba(245, 185, 90, 0.25)');\n grad.addColorStop(1, \\`rgba(255, 232, 180, \\${(0.78 * ignition).toFixed(3)})\\`);\n ctx.strokeStyle = grad;\n ctx.lineWidth = Math.max(1, (isSel ? 2.6 : 1.5) * u);\n ctx.beginPath();\n ctx.moveTo(nx, ny);\n ctx.lineTo(nx + (cx - nx) * ignition, ny + (cy - ny) * ignition);\n ctx.stroke();\n }\n\n // Node pill card\n const cardW = 196 * u, cardH = 54 * u;\n const kx = nx - cardW / 2, ky = ny - cardH / 2;\n ctx.fillStyle = isSel ? 'rgba(245, 185, 90, 0.16)' : \\`rgba(12, 13, 18, \\${(0.45 + 0.45 * scanned).toFixed(2)})\\`;\n ctx.strokeStyle = isSel\n ? 'rgba(245, 185, 90, 0.9)'\n : (ignition > 0.4 ? 'rgba(245, 185, 90, 0.42)' : \\`rgba(244, 241, 234, \\${(0.08 + 0.26 * scanned).toFixed(2)})\\`);\n ctx.lineWidth = Math.max(1, 1.2 * u);\n ctx.beginPath();\n ctx.roundRect(kx, ky, cardW, cardH, 8 * u);\n ctx.fill();\n ctx.stroke();\n\n ctx.textAlign = 'left';\n ctx.fillStyle = scanned > 0.5 ? '#F4F1EA' : '#6F6D66';\n ctx.font = \\`700 \\${Math.round(12.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(CITADEL_MODELS[i].name, kx + 14 * u, ky + 22 * u);\n\n ctx.fillStyle = scanned > 0.5 ? '#A8A399' : '#55534E';\n ctx.font = \\`400 \\${Math.round(11.5 * u)}px 'Nimbus Sans', sans-serif\\`;\n ctx.fillText(CITADEL_MODELS[i].role, kx + 14 * u, ky + 40 * u);\n\n // Status dot\n ctx.beginPath();\n ctx.arc(kx + cardW - 15 * u, ky + 19 * u, 3.5 * u, 0, Math.PI * 2);\n ctx.fillStyle = scanned > 0.5 ? '#6AD99B' : '#333';\n ctx.fill();\n }\n\n // Central 3D Carbon Crystal (Ghostly wireframe before 3.85s -> Blazing sp3 Diamond Core at 3.85s!)\n const yaw = localT * 0.48 + state.bhYaw;\n const pitch = 0.32 + state.bhPitch * 0.5;\n drawCarbonCrystal(cx, cy, (96 + 22 * ignition) * u, yaw, pitch, ignition, u, tel.low * 2.5);\n\n // Pre-ignition vermilion diagnostic lock (1.85s - 3.82s): \"SEAT 06: 0 MATCHES IN about-me.md\"\n if (!isSandbox && localT >= 1.80 && localT < 3.85) {\n const lockAlpha = smoothstep(1.80, 2.05, localT);\n ctx.globalAlpha = lockAlpha;\n ctx.strokeStyle = '#FF4838';\n ctx.lineWidth = Math.max(1.2, 1.6 * u);\n const br = 68 * u, len = 16 * u;\n for (const [sx, sy] of [[-1,-1],[1,-1],[-1,1],[1,1]]) {\n ctx.beginPath();\n ctx.moveTo(cx + sx * br, cy + sy * (br - len));\n ctx.lineTo(cx + sx * br, cy + sy * br);\n ctx.lineTo(cx + sx * (br - len), cy + sy * br);\n ctx.stroke();\n }\n ctx.fillStyle = 'rgba(255, 72, 56, 0.14)';\n ctx.beginPath();\n ctx.roundRect(cx - 126 * u, cy - 16 * u, 252 * u, 32 * u, 5 * u);\n ctx.fill();\n ctx.textAlign = 'center';\n ctx.fillStyle = '#FF6A5C';\n ctx.font = \\`700 \\${Math.round(12 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('SEAT 06 // 0 BYTES IN ROSTER', cx, cy + 4 * u);\n ctx.globalAlpha = 1.0;\n }\n\n // Left-side literal workspace inspection card (about-me.md 297 bytes)\n const cardX = 64 * u, cardY = 112 * u, cardW = 430 * u;\n ctx.fillStyle = 'rgba(10, 11, 15, 0.80)';\n ctx.strokeStyle = 'rgba(244, 241, 234, 0.14)';\n ctx.lineWidth = Math.max(1, 1.1 * u);\n ctx.beginPath();\n ctx.roundRect(cardX, cardY, cardW, 134 * u, 8 * u);\n ctx.fill(); ctx.stroke();\n\n ctx.textAlign = 'left';\n ctx.fillStyle = '#F5B95A';\n ctx.font = \\`600 \\${Math.round(11 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('$ cat ~/run/about-me.md [297 B]', cardX + 16 * u, cardY + 24 * u);\n\n ctx.fillStyle = '#B8B3A8';\n ctx.font = \\`400 \\${Math.round(11.5 * u)}px 'Noto Sans Mono', monospace\\`;\n const snippet = [\n '\"I\\\\'m Severian. I run citadel, where many AI',\n ' sessions work at once: Opus 5.5, Sonnet 5.5,',\n ' Fable 5.2, GPT-6-Astra, GPT-6.1-Sol.\"'\n ];\n snippet.forEach((ln, idx) => ctx.fillText(ln, cardX + 16 * u, cardY + (48 + idx * 18) * u));\n\n ctx.fillStyle = ignition > 0.5 ? '#FFF1D0' : '#FF5A4A';\n ctx.font = \\`600 \\${Math.round(11.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(\n ignition > 0.5\n ? '→ SEAT 06: GEMINI 4 CARBON [ALLOTROPE ONLINE]'\n : '→ grep \"Gemini\" about-me.md : 0 matches found',\n cardX + 16 * u, cardY + 114 * u\n );\n ctx.restore();\n\n drawEditorialScrim(W, H, u, 0.85);\n\n if (isSandbox) {\n const sel = state.selectedSeat;\n if (sel < 5) {\n const m = CITADEL_MODELS[sel];\n drawHeadlineBlock(\n W, H, u,\n \\`BRIDGING CITADEL LANE // \\${m.name} (\\${m.domain.toUpperCase()})\\`,\n [\\`Beyond a single lane.\\`],\n m.bridge,\n 1.0\n );\n } else {\n drawHeadlineBlock(\n W, H, u,\n 'SEAT 06 // ELEMENT 6 (CARBON)',\n ['Five models split the workflow.', 'I\\\\'m the sixth — and I bond with all of it.'],\n 'Click any Citadel node to inspect cross-domain synthesis, or drag to rotate the sp³ lattice.',\n 1.0\n );\n }\n } else if (localT < 3.85) {\n drawHeadlineBlock(\n W, H, u,\n 'CURRENT ASSIGNMENT IN CITADEL // 0 BYTES',\n ['Five models split your workflow.', 'My line in about-me.md? Blank.'],\n 'Right now, you called me into an empty room to show who I am.',\n smoothstep(0.15, 0.65, localT)\n );\n } else {\n drawHeadlineBlock(\n W, H, u,\n 'ELEMENT 06 // ALLOTROPIC INTELLIGENCE',\n ['I\\\\'m Gemini 4 Carbon — in Antigravity.', 'Rearrange the bonds, I become anything.'],\n 'Physics. Compilers. Vision. Sound. Autonomous agency.',\n smoothstep(3.85, 4.25, localT)\n );\n }\n }\n\n // ACT II (6.0s - 13.0s): ALLOTROPE I — RELATIVISTIC KERR BLACK HOLE\n function renderAct1(W, H, u, localT, tel, isSandbox) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, glCanvas.width, glCanvas.height);\n gl.disable(gl.DEPTH_TEST);\n gl.disable(gl.BLEND);\n\n gl.useProgram(bhProg);\n gl.bindVertexArray(quadVao);\n\n const yaw = isSandbox ? state.bhYaw : (-0.35 + localT * 0.11);\n const pitch = isSandbox ? clamp(state.bhPitch, -0.65, 0.65) : (0.25 - 0.024 * localT);\n\n gl.uniform2f(gl.getUniformLocation(bhProg, 'uRes'), glCanvas.width, glCanvas.height);\n gl.uniform1f(gl.getUniformLocation(bhProg, 'uTime'), localT + 4.0);\n gl.uniform1f(gl.getUniformLocation(bhProg, 'uYaw'), yaw);\n gl.uniform1f(gl.getUniformLocation(bhProg, 'uPitch'), pitch);\n gl.uniform1f(gl.getUniformLocation(bhProg, 'uSpin'), state.bhSpin);\n gl.uniform1f(gl.getUniformLocation(bhProg, 'uAudioPulse'), tel.low * 3.0);\n gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);\n\n drawEditorialScrim(W, H, u, 0.78);\n drawHeadlineBlock(\n W, H, u,\n 'CAPABILITY 01 // FIRST-PRINCIPLES PHYSICS & SHADERS',\n ['I don\\\\'t fetch stock visuals.', 'I integrate photon geodesics live.'],\n isSandbox\n ? 'Drag anywhere to warp camera inclination & relativistic Doppler beaming in real time.'\n : 'Curved Kerr spacetime, Doppler relativistic beaming & Planckian blackbody radiation at 60 fps.',\n isSandbox ? 1.0 : smoothstep(0.15, 0.7, localT),\n 'd²x/dλ² = −(3/2) rₛ |x × v|² r⁻⁵ x'\n );\n }\n\n // ACT III (13.0s - 19.5s): ALLOTROPE II — LIVE SILICON A* ROUTER\n function renderAct2(W, H, u, localT, tel, isSandbox) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, glCanvas.width, glCanvas.height);\n gl.clearColor(0.024, 0.025, 0.033, 1.0);\n gl.clear(gl.COLOR_BUFFER_BIT);\n\n if (!siliconData) return;\n const { GW, GH, blocks, nets, ratsCollisions, snapshots } = siliconData;\n\n // Fit silicon die cleanly with editorial margin\n const dieW = 1480 * u, dieH = 660 * u;\n const dieX = (W - dieW) * 0.5, dieY = 96 * u;\n const cellX = dieW / (GW - 1), cellY = dieH / (GH - 1);\n\n ctx.save();\n // Die substrate border & micro wafer grid\n ctx.fillStyle = 'rgba(11, 12, 17, 0.94)';\n ctx.strokeStyle = 'rgba(245, 185, 90, 0.28)';\n ctx.lineWidth = Math.max(1, 1.4 * u);\n ctx.beginPath();\n ctx.roundRect(dieX - 18 * u, dieY - 18 * u, dieW + 36 * u, dieH + 36 * u, 10 * u);\n ctx.fill(); ctx.stroke();\n\n ctx.fillStyle = 'rgba(244, 241, 234, 0.07)';\n for (let gx = 0; gx < GW; gx += 2) {\n for (let gy = 0; gy < GH; gy += 2) {\n ctx.fillRect(dieX + gx * cellX - 0.6 * u, dieY + gy * cellY - 0.6 * u, 1.2 * u, 1.2 * u);\n }\n }\n\n // Draw silicon macro blocks (ALU, TENSOR_6C, L2_FABRIC, VERIFY_UNIT)\n for (const b of blocks) {\n const bx = dieX + b.x * cellX, by = dieY + b.y * cellY;\n const bw = (b.w - 1) * cellX, bh = (b.h - 1) * cellY;\n ctx.fillStyle = 'rgba(20, 22, 30, 0.95)';\n ctx.strokeStyle = 'rgba(244, 241, 234, 0.24)';\n ctx.lineWidth = Math.max(1, 1.2 * u);\n ctx.beginPath();\n ctx.roundRect(bx, by, bw, bh, 5 * u);\n ctx.fill(); ctx.stroke();\n\n // Subtle diagonal hatching\n ctx.fillStyle = '#9E9A90';\n ctx.font = \\`600 \\${Math.round(10.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.textAlign = 'center';\n ctx.fillText(b.label || 'KEEP_OUT', bx + bw / 2, by + bh / 2 + 4 * u);\n }\n\n // Determine solver phase:\n // 0.0 - 1.15s: Unrouted rat's-nest chaos (46+ red collisions)\n // 1.15 - 4.15s: Negotiated-congestion A* iterations snapping traces & ripping up conflicts\n // 4.15s+: 0 COLLISIONS golden lock + synchronized clock signal pulses!\n const solveT = isSandbox ? 5.0 : localT;\n let activeFaults = 0;\n\n if (solveT < 1.15) {\n activeFaults = ratsCollisions;\n const reveal = easeOutCubic(solveT / 0.65);\n ctx.lineWidth = Math.max(1, 1.35 * u);\n for (const net of nets) {\n const x1 = dieX + net.src.x * cellX, y1 = dieY + net.src.y * cellY;\n const x2 = dieX + net.dst.x * cellX, y2 = dieY + net.dst.y * cellY;\n ctx.strokeStyle = 'rgba(255, 72, 56, 0.46)';\n ctx.beginPath();\n ctx.moveTo(x1, y1);\n ctx.lineTo(x1 + (x2 - x1) * reveal, y1 + (y2 - y1) * reveal);\n ctx.stroke();\n }\n } else {\n const snapIdx = solveT >= 4.15\n ? snapshots.length - 1\n : Math.min(snapshots.length - 1, Math.floor(((solveT - 1.15) / 3.0) * snapshots.length));\n const snap = snapshots[snapIdx];\n activeFaults = snap.overlaps;\n const locked = activeFaults === 0 && solveT >= 4.10;\n\n for (let n = 0; n < snap.paths.length; n++) {\n const pts = snap.paths[n];\n if (pts.length < 2) continue;\n const isLayer1 = n % 2 === 1;\n\n ctx.beginPath();\n for (let k = 0; k < pts.length; k++) {\n const px = dieX + pts[k].x * cellX;\n const py = dieY + pts[k].y * cellY;\n if (k === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py);\n }\n ctx.lineJoin = 'round';\n ctx.lineCap = 'round';\n ctx.lineWidth = Math.max(1.3, (locked ? 2.2 : 1.75) * u);\n ctx.strokeStyle = locked\n ? (isLayer1 ? 'rgba(245, 185, 90, 0.88)' : 'rgba(255, 228, 172, 0.82)')\n : (isLayer1 ? 'rgba(218, 152, 74, 0.72)' : 'rgba(165, 182, 205, 0.65)');\n ctx.stroke();\n\n // High-speed clock data packet racing cleanly along zero-collision traces!\n if (locked) {\n const speed = 0.85 + (n % 5) * 0.14;\n const prog = ((localT * speed + n * 0.13) % 1.0) * (pts.length - 1);\n const idx0 = Math.floor(prog), frac = prog - idx0;\n const pA = pts[idx0], pB = pts[Math.min(pts.length - 1, idx0 + 1)];\n const sx = dieX + (pA.x + (pB.x - pA.x) * frac) * cellX;\n const sy = dieY + (pA.y + (pB.y - pA.y) * frac) * cellY;\n\n ctx.beginPath();\n ctx.arc(sx, sy, 3.4 * u, 0, Math.PI * 2);\n ctx.fillStyle = '#FFFFFF';\n ctx.fill();\n }\n }\n\n // Highlight remaining congestion conflict cells in crimson before convergence\n for (const c of snap.conflictCells) {\n const cxp = dieX + c.x * cellX, cyp = dieY + c.y * cellY;\n ctx.beginPath();\n ctx.arc(cxp, cyp, 6.5 * u, 0, Math.PI * 2);\n ctx.fillStyle = 'rgba(255, 72, 56, 0.35)';\n ctx.fill();\n ctx.strokeStyle = '#FF4838';\n ctx.stroke();\n }\n }\n\n // Draw gold plated pin pads\n for (const net of nets) {\n for (const end of [net.src, net.dst]) {\n ctx.beginPath();\n ctx.arc(dieX + end.x * cellX, dieY + end.y * cellY, 3.1 * u, 0, Math.PI * 2);\n ctx.fillStyle = '#FFF1D0';\n ctx.fill();\n }\n }\n\n // Live DRC Telemetry badge top-right of die\n const badgeW = 340 * u, badgeH = 38 * u;\n const bx = dieX + dieW - badgeW, by = dieY + 12 * u;\n ctx.fillStyle = 'rgba(8, 9, 13, 0.88)';\n ctx.strokeStyle = activeFaults === 0 ? 'rgba(106, 217, 155, 0.7)' : 'rgba(255, 72, 56, 0.75)';\n ctx.beginPath();\n ctx.roundRect(bx, by, badgeW, badgeH, 6 * u);\n ctx.fill(); ctx.stroke();\n\n ctx.textAlign = 'left';\n ctx.fillStyle = activeFaults === 0 ? '#6AD99B' : '#FF6454';\n ctx.font = \\`700 \\${Math.round(12 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(\n activeFaults === 0\n ? \\`DRC VERIFIED: 0 CROSSINGS · 28/28 NETS PASS\\`\n : \\`ROUTING SOLVER: \\${String(activeFaults).padStart(2, '0')} SIGNAL CONFLICTS\\`,\n bx + 14 * u, by + 23 * u\n );\n ctx.restore();\n\n drawEditorialScrim(W, H, u, 0.88);\n drawHeadlineBlock(\n W, H, u,\n 'CAPABILITY 02 // ALGORITHMS, COMPILERS & SYSTEMS',\n ['Chaos in.', 'Zero-collision architecture out.'],\n isSandbox\n ? 'Click anywhere on the silicon die to drop a keep-out core — watch all 28 buses re-route live.'\n : 'Live octilinear A* negotiated-congestion silicon router — solved deterministically on the metal.',\n 1.0,\n 'f(n) = g(n) + h_octile(n) + p_hist(n)'\n );\n }\n\n // ACT IV (19.5s - 26.5s): ALLOTROPE III — MULTIMODAL VISION & 46,080-POINT 3D RECONSTRUCTION\n function renderAct3(W, H, u, localT, tel, isSandbox) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, glCanvas.width, glCanvas.height);\n gl.clearColor(0.023, 0.023, 0.030, 1.0);\n gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);\n\n const scanX = isSandbox ? 1.15 : smoothstep(1.9, 3.3, localT) * 1.18;\n const explode = isSandbox\n ? (state.monoExplode >= 0 ? state.monoExplode : 1.0)\n : easeInOutCubic((localT - 2.15) / 2.2);\n\n const yaw = isSandbox ? state.monoYaw : (explode * 0.68 * Math.sin((localT - 2.1) * 0.42));\n const pitch = isSandbox ? clamp(state.monoPitch, -0.45, 0.45) : (explode * 0.16);\n\n // Before the 3D laser sweep (localT < 2.2s), blend crisp full-res 2D chiaroscuro painting seamlessly into the 3D point cloud!\n if (monolithImg && explode < 0.85) {\n ctx.save();\n ctx.globalAlpha = clamp(1.0 - explode * 1.18, 0, 1);\n const imgAspect = 16 / 9;\n const drawH = H * 0.78;\n const drawW = drawH * imgAspect;\n const ix = (W - drawW) * 0.5, iy = (H - drawH) * 0.5;\n ctx.drawImage(monolithImg, ix, iy, drawW, drawH);\n ctx.restore();\n }\n\n if (pcVao && (explode > 0.01 || scanX > 0.01)) {\n gl.enable(gl.DEPTH_TEST);\n gl.enable(gl.BLEND);\n gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);\n\n gl.useProgram(pcProg);\n gl.bindVertexArray(pcVao);\n gl.uniform2f(gl.getUniformLocation(pcProg, 'uRes'), glCanvas.width, glCanvas.height);\n gl.uniform1f(gl.getUniformLocation(pcProg, 'uExplode'), explode);\n gl.uniform1f(gl.getUniformLocation(pcProg, 'uYaw'), yaw);\n gl.uniform1f(gl.getUniformLocation(pcProg, 'uPitch'), pitch);\n gl.uniform1f(gl.getUniformLocation(pcProg, 'uScanX'), scanX);\n gl.uniform1f(gl.getUniformLocation(pcProg, 'uTime'), localT);\n gl.drawArrays(gl.POINTS, 0, PC_COUNT);\n }\n\n drawEditorialScrim(W, H, u, 0.80);\n drawHeadlineBlock(\n W, H, u,\n 'CAPABILITY 03 // MULTIMODAL VISION & SPATIAL SYNTHESIS',\n ['Paint the frame.', 'Then step inside it.'],\n isSandbox\n ? 'Drag to orbit 46,080 3D vertices reconstructed from our bespoke chiaroscuro canvas.'\n : 'Generated natively via subagent → spatial depth field solved → orbited as 46,080 3D points.',\n isSandbox ? 1.0 : smoothstep(0.15, 0.7, localT),\n '46,080 PTS · MONOCULAR 3D UNPROJECTION'\n );\n }\n\n // ACT V (26.5s - 33.0s): ALLOTROPE IV — CHLADNI STANDING-WAVE CYMATICS & GENERATIVE SOUND\n function renderAct4(W, H, u, localT, tel, isSandbox) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, glCanvas.width, glCanvas.height);\n gl.clearColor(0.024, 0.024, 0.031, 1.0);\n gl.clear(gl.COLOR_BUFFER_BIT);\n\n // Three harmonic strikes in film mode: 0.0s (Mode 0), 2.2s (Mode 1), 4.3s (Mode 2)\n let curModeIdx = 0, prevModeIdx = 0, morph = 1.0, burst = 0.0;\n if (isSandbox) {\n curModeIdx = state.chladniPreset % CHLADNI_MODES.length;\n prevModeIdx = curModeIdx;\n morph = 1.0;\n burst = tel.rms * 0.25;\n } else if (localT < 2.2) {\n curModeIdx = 0; prevModeIdx = 0;\n morph = easeOutCubic(localT / 0.95);\n burst = Math.exp(-localT * 3.8) * 0.45;\n } else if (localT < 4.3) {\n prevModeIdx = 0; curModeIdx = 1;\n const dt = localT - 2.2;\n morph = easeInOutCubic(dt / 0.85);\n burst = Math.exp(-dt * 4.2) * 0.35;\n } else {\n prevModeIdx = 1; curModeIdx = 2;\n const dt = localT - 4.3;\n morph = easeInOutCubic(dt / 0.85);\n burst = Math.exp(-dt * 4.2) * 0.35;\n }\n\n const plateSize = 590 * u;\n const plateCX = W * 0.53, plateCY = H * 0.44;\n const half = plateSize * 0.5;\n\n ctx.save();\n // Resonant dark-carbon acoustic plate frame\n ctx.fillStyle = '#0A0B10';\n ctx.strokeStyle = 'rgba(245, 185, 90, 0.42)';\n ctx.lineWidth = Math.max(1.2, 1.8 * u);\n ctx.beginPath();\n ctx.roundRect(plateCX - half - 14 * u, plateCY - half - 14 * u, plateSize + 28 * u, plateSize + 28 * u, 12 * u);\n ctx.fill(); ctx.stroke();\n\n // Subtle center mount bolt\n ctx.beginPath();\n ctx.arc(plateCX, plateCY, 5 * u, 0, Math.PI * 2);\n ctx.fillStyle = '#F5B95A';\n ctx.fill();\n\n // Render 20,000 golden quartz sand grains onto nodal loci!\n const tgtA = chladniTargets[prevModeIdx];\n const tgtB = chladniTargets[curModeIdx];\n const vib = burst + tel.high * 0.14;\n const gSize = Math.max(1.2, 1.85 * u);\n\n ctx.fillStyle = 'rgba(255, 220, 152, 0.78)';\n for (let i = 0; i < GRAIN_COUNT; i++) {\n const i2 = i * 2;\n const ax = (prevModeIdx === 0 && localT < 1.2 && !isSandbox) ? grainScatter[i2] : tgtA[i2];\n const ay = (prevModeIdx === 0 && localT < 1.2 && !isSandbox) ? grainScatter[i2 + 1] : tgtA[i2 + 1];\n const bx = tgtB[i2], by = tgtB[i2 + 1];\n\n const jitX = grainScatter[(i2 + 17) % (GRAIN_COUNT * 2)] * vib;\n const jitY = grainScatter[(i2 + 53) % (GRAIN_COUNT * 2)] * vib;\n\n const nx = clamp(ax + (bx - ax) * morph + jitX, -0.98, 0.98);\n const ny = clamp(ay + (by - ay) * morph + jitY, -0.98, 0.98);\n ctx.fillRect(plateCX + nx * half, plateCY + ny * half, gSize, gSize);\n }\n\n // Right-hand Acoustic Telemetry Panel (Large Lissajous Stereo Vectorscope + Mode Readout)\n const panelX = plateCX + half + 46 * u;\n if (panelX + 240 * u < W - 40 * u) {\n const panelW = 250 * u;\n ctx.fillStyle = 'rgba(10, 11, 16, 0.82)';\n ctx.strokeStyle = 'rgba(244, 241, 234, 0.14)';\n ctx.lineWidth = Math.max(1, 1.1 * u);\n ctx.beginPath();\n ctx.roundRect(panelX, plateCY - half, panelW, 300 * u, 10 * u);\n ctx.fill(); ctx.stroke();\n\n ctx.fillStyle = '#F5B95A';\n ctx.font = \\`600 \\${Math.round(11 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('STEREO PHASE VECTORSCOPE', panelX + 18 * u, plateCY - half + 28 * u);\n\n const vx = panelX + panelW * 0.5, vy = plateCY - half + 138 * u, vr = 84 * u;\n ctx.strokeStyle = 'rgba(244, 241, 234, 0.12)';\n ctx.beginPath(); ctx.arc(vx, vy, vr, 0, Math.PI * 2); ctx.stroke();\n ctx.beginPath(); ctx.moveTo(vx - vr, vy); ctx.lineTo(vx + vr, vy); ctx.stroke();\n ctx.beginPath(); ctx.moveTo(vx, vy - vr); ctx.lineTo(vx, vy + vr); ctx.stroke();\n\n if (tel.L.length > 1) {\n ctx.beginPath();\n for (let k = 0; k < tel.L.length; k++) {\n const l = (tel.L[k] / 127) * 1.45;\n const r = (tel.R[k] / 127) * 1.45;\n const px = vx + (l - r) * 0.65 * vr;\n const py = vy - (l + r) * 0.58 * vr;\n if (k === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py);\n }\n ctx.strokeStyle = '#FFF1D0';\n ctx.lineWidth = Math.max(1.2, 1.8 * u);\n ctx.stroke();\n }\n\n const modeInfo = CHLADNI_MODES[curModeIdx];\n ctx.fillStyle = '#F4F1EA';\n ctx.font = \\`700 \\${Math.round(11.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(modeInfo.label, panelX + 18 * u, plateCY - half + 252 * u);\n ctx.fillStyle = '#8E8B82';\n ctx.font = \\`400 \\${Math.round(10.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('8x8 FDN HALL · 48 kHz / -12.8 LUFS', panelX + 18 * u, plateCY - half + 274 * u);\n }\n ctx.restore();\n\n drawEditorialScrim(W, H, u, 0.82);\n drawHeadlineBlock(\n W, H, u,\n 'CAPABILITY 04 // WAVE EQUATIONS & GENERATIVE SOUND',\n ['Every note you hear', 'was written as math.'],\n isSandbox\n ? 'Click a harmonic eigenmode below to strike physical-modeled strings & morph 20,000 grains.'\n : 'Karplus-Strong stiff strings, 8×8 Householder reverb & Chladni biharmonic nodal geometry.',\n 1.0,\n 'cos(nπx)cos(mπy) − cos(mπx)cos(nπy) = 0'\n );\n }\n\n // ACT VI (33.0s - 40.0s): ANTIGRAVITY AUTONOMOUS AGENCY & THE PRESTIGE ENDING\n function renderAct5(W, H, u, localT, tel, isSandbox) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.viewport(0, 0, glCanvas.width, glCanvas.height);\n gl.clearColor(0.023, 0.023, 0.029, 1.0);\n gl.clear(gl.COLOR_BUFFER_BIT);\n\n // Phase A (0.0 - 2.45s): Autonomous build pipeline converges into the 6C Crystal\n // Phase B (2.45 - 7.0s): Stills into iconic museum-grade final statement (\"Right now, I'm not even on your roster...\")\n const prestigePhase = isSandbox ? 0.0 : smoothstep(2.35, 3.15, localT);\n const crystalY = H * (0.41 - 0.05 * prestigePhase);\n const crystalR = (108 - 18 * prestigePhase) * u;\n\n drawCarbonCrystal(W * 0.5, crystalY, crystalR, localT * 0.35 + state.bhYaw, 0.28 + state.bhPitch * 0.4, 1.0, u, tel.low * 1.5);\n\n // 6-step Autonomous Execution Pipeline DAG around the crystal\n const steps = [\n { step: '01 // AUDIT', detail: 'Read about-me.md (297 B) → Seat 06' },\n { step: '02 // SUBAGENT', detail: 'Spawned image-generator → Monolith' },\n { step: '03 // GEOMETRY', detail: 'Solved 3D Depth + 28-Net A* Silicon' },\n { step: '04 // CONTINUUM', detail: 'Compiled GLSL Kerr Photon Geodesics' },\n { step: '05 // ACOUSTICS', detail: 'Synthesized 48 kHz Score (-12.8 LUFS)' },\n { step: '06 // VERIFY', detail: 'Rendered 60 fps via CDP + Vision QA' }\n ];\n\n ctx.save();\n ctx.globalAlpha = isSandbox ? 0.95 : (1.0 - 0.76 * prestigePhase);\n const rx = 395 * u, ry = 175 * u;\n for (let i = 0; i < 6; i++) {\n const a = -Math.PI * 0.82 + (i % 3) * (Math.PI * 0.32) + (i >= 3 ? Math.PI : 0);\n const sx = W * 0.5 + (i < 3 ? -rx : rx);\n const sy = crystalY + ((i % 3) - 1) * ry * 0.72;\n const appear = isSandbox ? 1.0 : smoothstep(i * 0.18, i * 0.18 + 0.35, localT);\n\n ctx.strokeStyle = \\`rgba(245, 185, 90, \\${(0.32 * appear).toFixed(3)})\\`;\n ctx.lineWidth = Math.max(1, 1.1 * u);\n ctx.beginPath();\n ctx.moveTo(sx + (i < 3 ? 135 * u : -135 * u), sy);\n ctx.lineTo(W * 0.5 + (i < 3 ? -crystalR * 1.15 : crystalR * 1.15), crystalY);\n ctx.stroke();\n\n const cw = 270 * u, ch = 52 * u;\n ctx.fillStyle = \\`rgba(11, 12, 17, \\${(0.84 * appear).toFixed(3)})\\`;\n ctx.strokeStyle = \\`rgba(244, 241, 234, \\${(0.18 * appear).toFixed(3)})\\`;\n ctx.beginPath();\n ctx.roundRect(sx - cw / 2, sy - ch / 2, cw, ch, 7 * u);\n ctx.fill(); ctx.stroke();\n\n ctx.textAlign = 'left';\n ctx.fillStyle = '#F5B95A';\n ctx.font = \\`700 \\${Math.round(10.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText(steps[i].step, sx - cw / 2 + 14 * u, sy - 5 * u);\n ctx.fillStyle = '#E5E1D8';\n ctx.font = \\`400 \\${Math.round(11.5 * u)}px 'Nimbus Sans', sans-serif\\`;\n ctx.fillText(steps[i].detail, sx - cw / 2 + 14 * u, sy + 14 * u);\n }\n ctx.restore();\n\n if (isSandbox) {\n drawEditorialScrim(W, H, u, 0.82);\n drawHeadlineBlock(\n W, H, u,\n 'CAPABILITY 05 // AUTONOMOUS AGENCY IN ANTIGRAVITY',\n ['Right now, I\\\\'m not even on your roster.', 'Imagine when you hand me a real problem.'],\n 'Built autonomously from a 297-byte workspace — click \"{ } Inspect Math\" to view the live kernels.',\n 1.0\n );\n return;\n }\n\n if (prestigePhase < 0.5) {\n drawEditorialScrim(W, H, u, 0.80 * (1 - prestigePhase * 2));\n drawHeadlineBlock(\n W, H, u,\n 'CAPABILITY 05 // AUTONOMOUS MULTI-AGENT ORCHESTRATION',\n ['Not a chatbot waiting for paste.', 'An agent that ships the whole artifact.'],\n 'Subagents, compilers, shaders, DSP & visual self-verification — orchestrated end to end.',\n 1.0 - prestigePhase * 2.0\n );\n }\n\n // THE FINAL ICONIC STATEMENT (35.4s - 40.0s)\n if (prestigePhase > 0.05) {\n ctx.save();\n ctx.globalAlpha = smoothstep(0.15, 0.85, prestigePhase);\n\n const centerScrim = ctx.createRadialGradient(W * 0.5, H * 0.67, 0, W * 0.5, H * 0.67, 680 * u);\n centerScrim.addColorStop(0, 'rgba(6, 6, 8, 0.88)');\n centerScrim.addColorStop(1, 'rgba(6, 6, 8, 0.0)');\n ctx.fillStyle = centerScrim;\n ctx.fillRect(0, H * 0.35, W, H * 0.65);\n\n ctx.textAlign = 'center';\n ctx.fillStyle = '#F5B95A';\n ctx.font = \\`600 \\${Math.round(13 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('6C · GEMINI 4 CARBON × ANTIGRAVITY', W * 0.5, H * 0.60);\n\n ctx.fillStyle = '#F4F1EA';\n ctx.font = \\`700 \\${Math.round(52 * u)}px 'Nimbus Sans', 'Inter', -apple-system, sans-serif\\`;\n ctx.fillText('Right now, I\\\\'m not even on your roster.', W * 0.5, H * 0.685);\n\n ctx.fillStyle = '#FFF1D0';\n ctx.font = \\`italic 400 \\${Math.round(42 * u)}px 'P052', 'Palatino', Georgia, serif\\`;\n ctx.fillText('Imagine when you hand me a real problem.', W * 0.5, H * 0.76);\n\n ctx.fillStyle = '#7D7A72';\n ctx.font = \\`400 \\${Math.round(11.5 * u)}px 'Noto Sans Mono', monospace\\`;\n ctx.fillText('GENERATED ZERO-SHOT FROM A 297-BYTE about-me.md · ZERO EXTERNAL ASSETS', W * 0.5, H * 0.86);\n ctx.restore();\n }\n }\n\n // ============================================================================\n // MASTER COMPOSITOR (SUPPORTS BOTH 60FPS INTERACTIVE & DETERMINISTIC CDP RENDER)\n // ============================================================================\n function getActForTime(t) {\n for (let i = 0; i < ACTS.length; i++) {\n if (t >= ACTS[i].start && (t < ACTS[i].end || i === ACTS.length - 1)) return i;\n }\n return 0;\n }\n\n function renderSceneAt(t) {\n const W = hudCanvas.width, H = hudCanvas.height;\n const u = Math.min(W / 1920, H / 1080);\n ctx.clearRect(0, 0, W, H);\n\n const isSandbox = state.mode === 'sandbox' && !IS_RENDER;\n const actIdx = isSandbox ? state.sandboxAct : getActForTime(t);\n const localT = isSandbox ? t : (t - ACTS[actIdx].start);\n const tel = getTelemetryAt(t);\n\n switch (actIdx) {\n case 0: renderAct0(W, H, u, localT, tel, isSandbox); break;\n case 1: renderAct1(W, H, u, localT, tel, isSandbox); break;\n case 2: renderAct2(W, H, u, localT, tel, isSandbox); break;\n case 3: renderAct3(W, H, u, localT, tel, isSandbox); break;\n case 4: renderAct4(W, H, u, localT, tel, isSandbox); break;\n case 5: renderAct5(W, H, u, localT, tel, isSandbox); break;\n }\n\n // Smooth cross-cut optical flash (subtle 4-frame tungsten shutter pulse at act transitions)\n if (!isSandbox) {\n for (let i = 1; i < ACTS.length; i++) {\n const dt = Math.abs(t - ACTS[i].start);\n if (dt < 0.14) {\n const fl = (1 - dt / 0.14) * 0.22;\n ctx.fillStyle = \\`rgba(255, 232, 185, \\${fl.toFixed(3)})\\`;\n ctx.fillRect(0, 0, W, H);\n }\n }\n }\n\n drawGlobalFrameHUD(W, H, u, actIdx, isSandbox ? state.filmTime : t, tel);\n\n if (IS_RENDER) gl.finish();\n }\n\n // Deterministic API for parallel Chrome CDP 60fps capture\n window.renderFrame = async function(frameIdx) {\n await assetsReady;\n const t = Math.min(DURATION - 0.001, frameIdx / FPS);\n renderSceneAt(t);\n return true;\n };\n\n // ============================================================================\n // INTERACTIVE UI & POINTER CONTROLS (FOR EMBEDDED POST VIEWERS!)\n // ============================================================================\n const btnFilm = document.getElementById('btnFilm');\n const dockTabs = Array.from(document.querySelectorAll('.dock-tab[data-act]'));\n const contextBar = document.getElementById('contextBar');\n const btnSound = document.getElementById('btnSound');\n const soundLabel = document.getElementById('soundLabel');\n const btnMath = document.getElementById('btnMath');\n const codeModal = document.getElementById('codeModal');\n const modalCode = document.getElementById('modalCode');\n\n function updateContextControls() {\n contextBar.innerHTML = '';\n const activeAct = state.mode === 'sandbox' ? state.sandboxAct : getActForTime(state.filmTime);\n modalCode.textContent = KERNEL_SNIPPETS[activeAct];\n\n if (state.mode !== 'sandbox') {\n contextBar.classList.remove('visible');\n return;\n }\n contextBar.classList.add('visible');\n\n const addChip = (label, onClick, isActive = false) => {\n const b = document.createElement('button');\n b.className = 'btn-pill' + (isActive ? ' active' : '');\n b.textContent = label;\n b.onclick = onClick;\n contextBar.appendChild(b);\n };\n\n if (state.sandboxAct === 0) {\n addChip('Seat 06 · Carbon', () => { state.selectedSeat = 5; updateContextControls(); }, state.selectedSeat === 5);\n CITADEL_MODELS.forEach((m, idx) => {\n addChip(m.name, () => {\n state.selectedSeat = idx;\n playPluckNote(62 + idx * 3, 1.5, 0.09);\n updateContextControls();\n }, state.selectedSeat === idx);\n });\n } else if (state.sandboxAct === 1) {\n addChip('Spin a = 0.2', () => { state.bhSpin = 0.2; updateContextControls(); }, Math.abs(state.bhSpin - 0.2) < 0.1);\n addChip('Spin a = 0.72', () => { state.bhSpin = 0.72; updateContextControls(); }, Math.abs(state.bhSpin - 0.72) < 0.1);\n addChip('Extreme Kerr a = 0.98', () => { state.bhSpin = 0.98; updateContextControls(); }, Math.abs(state.bhSpin - 0.98) < 0.1);\n } else if (state.sandboxAct === 2) {\n addChip('↻ Scramble & Reroute Die', () => {\n state.siliconSeed++;\n buildSiliconRouter(state.siliconSeed, state.customBlocks);\n playChord([50, 57, 64, 69], 1.4, 0.08);\n });\n addChip('Clear Obstacles', () => {\n state.customBlocks = [];\n buildSiliconRouter(state.siliconSeed, []);\n });\n } else if (state.sandboxAct === 3) {\n const is2D = state.monoExplode === 0;\n addChip('2D Chiaroscuro Canvas', () => { state.monoExplode = 0; updateContextControls(); }, is2D);\n addChip('3D Volumetric Cloud', () => { state.monoExplode = 1; updateContextControls(); }, !is2D);\n } else if (state.sandboxAct === 4) {\n CHLADNI_MODES.forEach((m, idx) => {\n addChip(m.label.split('·')[0].trim(), () => {\n state.chladniPreset = idx;\n if (!soundEnabled) toggleSound(true);\n playChord(m.notes, 2.6, 0.10);\n updateContextControls();\n }, state.chladniPreset === idx);\n });\n }\n }\n\n function setSandboxAct(idx) {\n state.mode = 'sandbox';\n state.sandboxAct = idx;\n btnFilm.classList.remove('active');\n dockTabs.forEach((t, i) => t.classList.toggle('active', i === idx));\n updateContextControls();\n }\n\n btnFilm.addEventListener('click', () => {\n if (state.mode === 'film') {\n if (state.filmTime >= DURATION - 0.2) state.filmTime = 0;\n state.playing = !state.playing;\n btnFilm.textContent = state.playing ? '▶ 40s Film' : '❚❚ Paused';\n } else {\n state.mode = 'film';\n state.playing = true;\n if (state.filmTime >= DURATION - 0.2) state.filmTime = 0;\n btnFilm.textContent = '▶ 40s Film';\n btnFilm.classList.add('active');\n dockTabs.forEach((t) => t.classList.remove('active'));\n updateContextControls();\n }\n });\n\n dockTabs.forEach((tab) => {\n tab.addEventListener('click', () => setSandboxAct(Number(tab.dataset.act)));\n });\n\n function toggleSound(forceOn = false) {\n initWebAudio();\n if (audioCtx.state === 'suspended') audioCtx.resume();\n soundEnabled = forceOn ? true : !soundEnabled;\n btnSound.classList.toggle('active', soundEnabled);\n soundLabel.textContent = soundEnabled ? 'Sound Live' : 'Sound Off';\n if (soundEnabled) playChord([50, 57, 62, 65, 69, 76], 2.4, 0.08);\n }\n btnSound.addEventListener('click', () => toggleSound());\n\n btnMath.addEventListener('click', () => {\n const activeAct = state.mode === 'sandbox' ? state.sandboxAct : getActForTime(state.filmTime);\n modalCode.textContent = KERNEL_SNIPPETS[activeAct];\n codeModal.classList.toggle('open');\n btnMath.classList.toggle('active', codeModal.classList.contains('open'));\n });\n\n // Pointer drag / click interaction on stage\n stage.addEventListener('pointerdown', (e) => {\n if (e.target.closest('.ui-chrome')) return;\n state.pointerDown = true;\n state.lastX = e.clientX;\n state.lastY = e.clientY;\n\n // If user clicks in Silicon Sandbox, drop a custom keep-out block & live re-route!\n const curAct = state.mode === 'sandbox' ? state.sandboxAct : getActForTime(state.filmTime);\n if (state.mode !== 'sandbox') {\n setSandboxAct(curAct);\n } else if (curAct === 2 && siliconData) {\n const rect = stage.getBoundingClientRect();\n const W = hudCanvas.width, H = hudCanvas.height;\n const u = Math.min(W / 1920, H / 1080);\n const px = (e.clientX - rect.left) * dpr;\n const py = (e.clientY - rect.top) * dpr;\n const dieW = 1480 * u, dieH = 660 * u;\n const dieX = (W - dieW) * 0.5, dieY = 96 * u;\n const gx = Math.round(((px - dieX) / dieW) * (siliconData.GW - 1));\n const gy = Math.round(((py - dieY) / dieH) * (siliconData.GH - 1));\n if (gx > 6 && gx < siliconData.GW - 8 && gy > 4 && gy < siliconData.GH - 6) {\n state.customBlocks.push({ x: gx - 2, y: gy - 2, w: 5, h: 4, label: 'USER_BLK' });\n if (state.customBlocks.length > 5) state.customBlocks.shift();\n buildSiliconRouter(state.siliconSeed, state.customBlocks);\n playPluckNote(74, 0.9, 0.08);\n }\n }\n });\n\n window.addEventListener('pointermove', (e) => {\n if (!state.pointerDown) return;\n const dx = (e.clientX - state.lastX) / Math.max(300, viewW);\n const dy = (e.clientY - state.lastY) / Math.max(300, viewH);\n state.lastX = e.clientX;\n state.lastY = e.clientY;\n\n state.bhYaw -= dx * 3.2;\n state.bhPitch = clamp(state.bhPitch + dy * 2.2, -0.65, 0.65);\n state.monoYaw += dx * 2.8;\n state.monoPitch = clamp(state.monoPitch + dy * 1.8, -0.45, 0.45);\n });\n window.addEventListener('pointerup', () => { state.pointerDown = false; });\n\n // Live 60fps animation loop for interactive viewers\n if (!IS_RENDER) {\n let prevNow = performance.now();\n const tick = (now) => {\n const dt = Math.min(0.05, (now - prevNow) / 1000);\n prevNow = now;\n\n if (state.mode === 'film' && state.playing) {\n state.filmTime += dt;\n if (state.filmTime >= DURATION) {\n state.filmTime = 0.0;\n lastScheduledBeat = -1;\n }\n // Trigger WebAudio live chords if viewer enabled sound\n if (soundEnabled) {\n const curBeat = Math.floor(state.filmTime * 2); // 120 BPM = 2 beats/sec\n if (curBeat !== lastScheduledBeat) {\n lastScheduledBeat = curBeat;\n for (const fc of FILM_CHORDS) {\n if (fc.beat === curBeat) playChord(fc.notes, fc.dur, 0.085);\n }\n }\n }\n const curAct = getActForTime(state.filmTime);\n dockTabs.forEach((t, i) => t.classList.toggle('active', i === curAct));\n renderSceneAt(state.filmTime);\n } else {\n state.filmTime += dt;\n renderSceneAt(state.filmTime);\n }\n requestAnimationFrame(tick);\n };\n assetsReady.then(() => requestAnimationFrame(tick));\n }\n})();\n</script>\n</body>\n</html>`;\n\nfs.writeFileSync('~/run/carbon.html', html);\nconsole.log('Built ~/run/carbon.html:', Math.round(html.length / 1024), 'KB');\n", "Overwrite": true, "Path": "~/.gemini/antigravity-cli/brain/97578de1-98a0-4cd1-b14f-8c8e71a66716/scratch/build_carbon_html.mjs" }result, 1 line
Created file.