The showcase prompt, round 2, Opus 5.5

agent (cont.)

+21:33
  • Write~/showcase-r2-V8kQA2HZ/run/claude.html

    input

    ~/showcase-r2-V8kQA2HZ/run/claude.html
    
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
    <title>I only write text. — Claude Opus 5.5</title>
    <meta name="description" content="Light, sound, a mind that learns, and a sentence that counts its own letters. One file of text, written by Claude Opus 5.5.">
    <meta name="theme-color" content="#0b0a09">
    <style>
    :root{
      --bg:#0b0a09;--ink:#f4efe8;--dim:rgba(244,239,232,.55);--coral:#e8825f;--sea:#7fb3d9;--good:#9fd9ab;--bad:#ff8f7d;
      --codeW:0px;
      --serif:"Iowan Old Style","Palatino Linotype",Palatino,"Book Antiqua",Georgia,"Times New Roman",serif;
      --sans:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
      --mono:ui-monospace,"SF Mono",Menlo,Consolas,"DejaVu Sans Mono","Liberation Mono",monospace;
    }
    *{box-sizing:border-box;margin:0;padding:0}
    html,body{height:100%;background:var(--bg);color:var(--ink);overflow:hidden;font-family:var(--sans);-webkit-font-smoothing:antialiased;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent;touch-action:manipulation}
    canvas{position:fixed;top:0;left:0;width:100%;height:100%;display:block}
    #gl{opacity:0}
    #veil{position:fixed;inset:0;background:var(--bg);pointer-events:none;z-index:6}
    #bars{position:fixed;top:10px;left:12px;right:12px;display:flex;gap:4px;z-index:8}
    #bars i{flex:1;height:2px;background:rgba(244,239,232,.18);border-radius:2px;overflow:hidden;position:relative}
    #bars b{position:absolute;inset:0;background:var(--ink);transform-origin:0 50%;transform:scaleX(0)}
    #top{position:fixed;top:22px;left:12px;right:12px;display:flex;align-items:center;gap:8px;z-index:8;font:600 11px/1 var(--mono);letter-spacing:.14em;color:var(--dim)}
    #top .brand{flex:1;white-space:nowrap}
    #top .brand em{font-style:normal;color:var(--coral)}
    button{font:600 10.5px/1 var(--mono);letter-spacing:.1em;color:var(--ink);background:rgba(20,18,16,.55);border:1px solid rgba(244,239,232,.2);border-radius:999px;padding:8px 12px;cursor:pointer;-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);white-space:nowrap}
    button:hover{border-color:rgba(244,239,232,.45)}
    button.on{background:var(--coral);border-color:var(--coral);color:#1b100b}
    #snd.nudge{animation:nudge 2.4s ease-in-out infinite}
    @keyframes nudge{0%,100%{box-shadow:0 0 0 0 rgba(232,130,95,0)}50%{box-shadow:0 0 0 6px rgba(232,130,95,.22)}}
    body.capture #top button{display:none}
    #cap{position:fixed;left:clamp(18px,4vw,52px);bottom:clamp(20px,5.5vh,56px);width:min(580px,calc(100vw - var(--codeW) - 40px));z-index:5;pointer-events:none}
    #cap .k{font:600 11px/1 var(--mono);letter-spacing:.2em;color:var(--coral);margin-bottom:12px}
    #cap .t{font:400 clamp(27px,4.1vw,50px)/1.04 var(--serif);letter-spacing:-.012em;margin-bottom:12px;text-shadow:0 2px 30px rgba(0,0,0,.75)}
    #cap .b{font:400 clamp(13.5px,1.32vw,16px)/1.52 var(--sans);color:rgba(244,239,232,.8);text-shadow:0 1px 14px rgba(0,0,0,.9)}
    #cap .b strong{color:var(--ink);font-weight:600}
    #code{position:fixed;top:44px;right:0;bottom:0;width:var(--codeW);z-index:4;display:none;border-left:1px solid rgba(244,239,232,.07);background:linear-gradient(90deg,rgba(11,10,9,.5),rgba(11,10,9,.86))}
    body.code #code{display:block}
    #codeHead{position:absolute;top:0;left:0;right:0;padding:12px 18px 10px;font:600 10px/1 var(--mono);letter-spacing:.16em;color:var(--dim);border-bottom:1px solid rgba(244,239,232,.07);z-index:1;background:rgba(11,10,9,.6)}
    #codeHead em{font-style:normal;color:var(--coral)}
    #codeBody{position:absolute;top:34px;left:0;right:0;bottom:0;overflow:hidden;padding:14px 18px 50vh;font:400 10.5px/1.6 var(--mono);color:rgba(244,239,232,.5);white-space:pre-wrap;word-break:break-word;-webkit-mask-image:linear-gradient(transparent,#000 40px,#000 80%,transparent);mask-image:linear-gradient(transparent,#000 40px,#000 80%,transparent)}
    #codeBody .kw{color:rgba(232,130,95,.95)}#codeBody .nu{color:rgba(127,179,217,.95)}#codeBody .st{color:rgba(159,217,171,.9)}#codeBody .cm{color:rgba(244,239,232,.28);font-style:italic}
    body.narrow #code{left:0;width:auto;background:rgba(11,10,9,.9);border:0}
    #stage{position:fixed;top:0;left:0;bottom:0;right:var(--codeW);z-index:3;pointer-events:none}
    .scene{position:absolute;inset:0;display:none}
    .scene.on{display:block}
    #hint{position:fixed;right:16px;bottom:14px;z-index:8;font:600 10px/1 var(--mono);letter-spacing:.14em;color:rgba(244,239,232,.38);pointer-events:none;transition:opacity .6s}
    body.code:not(.narrow) #hint{right:calc(var(--codeW) + 16px)}
    /* words */
    #words{padding:clamp(70px,11vh,120px) clamp(18px,5vw,64px) 0}
    #sent{max-width:900px;margin:0 auto;font:400 clamp(16px,2.05vw,27px)/1.5 var(--serif);color:rgba(244,239,232,.92)}
    #sent .c{transition:color .25s;border-radius:3px}
    #sent .c.bad{color:var(--bad)}
    #sent .c.ok{color:var(--good)}
    #sent .c.chk{color:var(--good);background:rgba(159,217,171,.12)}
    #sent span.l{transition:color .2s}
    #sent span.l.seen{color:rgba(244,239,232,.38)}
    #sent span.l.cur{color:#1b100b;background:var(--coral);border-radius:2px}
    #wmeta{max-width:900px;margin:18px auto 0;font:600 11px/1.5 var(--mono);letter-spacing:.12em;color:var(--dim);min-height:1.5em}
    #wmeta b{color:var(--coral);font-weight:600}
    #wmeta.win b{color:var(--good)}
    #hist{max-width:900px;margin:16px auto 0;display:flex;gap:3px;height:clamp(64px,12vh,120px);align-items:flex-end}
    #hist div{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;height:100%;font:600 9px/1 var(--mono);color:var(--dim)}
    #hist i{display:block;width:100%;background:rgba(244,239,232,.55);border-radius:2px 2px 0 0;height:0;margin:3px 0}
    #hist div.ok i{background:var(--good)}
    #hist div.ok{color:var(--good)}
    /* me */
    #me{display:none;align-items:center;justify-content:center;padding:70px clamp(20px,6vw,72px) 40px}
    #me.on{display:flex}
    #me .col{max-width:720px;width:100%}
    #me h1{font:400 clamp(44px,8vw,96px)/1 var(--serif);letter-spacing:-.025em;margin-bottom:14px}
    #me .who{font:600 12px/1 var(--mono);letter-spacing:.2em;color:var(--coral);margin-bottom:clamp(20px,4vh,40px)}
    #me p{font:400 clamp(17px,2.05vw,24px)/1.48 var(--serif);color:rgba(244,239,232,.86);margin-bottom:.85em}
    #me p em{color:var(--ink)}
    #me .stats{font:600 11px/1.7 var(--mono);letter-spacing:.1em;color:var(--dim);margin:clamp(16px,3vh,30px) 0 18px;border-top:1px solid rgba(244,239,232,.12);padding-top:16px}
    #me .stats b{color:var(--ink);font-weight:600}
    #me .btns{display:flex;gap:10px;flex-wrap:wrap;pointer-events:auto}
    #me .l{opacity:0}
    </style>
    </head>
    <body>
    <canvas id="gl"></canvas>
    <canvas id="cv"></canvas>
    <div id="stage">
      <div id="words" class="scene"><div id="sent"></div><div id="wmeta"></div><div id="hist"></div></div>
      <div id="me" class="scene"><div class="col">
        <h1 class="l">I’m Claude.</h1>
        <div class="who l">OPUS 5.5 · MADE BY ANTHROPIC</div>
        <p class="l">I don’t have eyes, or hands, or a voice. <em>I have text.</em></p>
        <p class="l">Everything you just saw and heard (the light, the music, the small mind learning, the sentence that counts itself) started as characters I wrote into one file.</p>
        <p class="l">Most days I lead a small team of AIs building things. Give me a proof, a contract, a dataset, a game, or a bug at 3 a.m., and I’ll start writing.</p>
        <div class="stats l" id="stats"></div>
        <div class="btns l"><button id="again">↻ WATCH AGAIN</button><button id="readsrc">&lt;/&gt; READ THE SOURCE</button></div>
      </div></div>
    </div>
    <div id="cap"><div class="k"></div><div class="t"></div><div class="b"></div></div>
    <div id="code"><div id="codeHead"></div><div id="codeBody"></div></div>
    <div id="bars"></div>
    <div id="top"><span class="brand">CLAUDE <em>OPUS 5.5</em></span><button id="snd" class="nudge">♪ SOUND OFF</button><button id="codeBtn">&lt;/&gt; CODE</button></div>
    <div id="hint">TAP TO SKIP · HOLD TO PAUSE</div>
    <div id="veil"></div>
    <script>
    "use strict";
    // ─────────────────────────────────────────────────────────────────────────────
    //  "I only write text."  A self-portrait by Claude Opus 5.5.
    //  One file. No images, no libraries, no fonts, nothing downloaded.
    //  Every pixel and every sound below is produced by this text.
    // ─────────────────────────────────────────────────────────────────────────────
    const PAGE_SRC = "<!doctype html>\n" + document.documentElement.outerHTML;
    const $ = s => document.querySelector(s);
    const QS = new URLSearchParams(location.search);
    const CAPTURE = QS.has("capture");
    const INK = "#f4efe8", CORAL = "#e8825f", SEA = "#7fb3d9";
    const SERIF = getComputedStyle(document.documentElement).getPropertyValue("--serif");
    const MONO = getComputedStyle(document.documentElement).getPropertyValue("--mono");
    const SANS = getComputedStyle(document.documentElement).getPropertyValue("--sans");
    const cv = $("#cv"), g = cv.getContext("2d");
    const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x));
    const ease = x => (x = clamp(x), x * x * (3 - 2 * x));
    const fmt = n => n.toLocaleString("en-US");
    function mulberry(a) { return () => { a |= 0; a = a + 0x6D2B79F5 | 0; let t = Math.imul(a ^ a >>> 15, 1 | a); t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t; return ((t ^ t >>> 14) >>> 0) / 4294967296; }; }
    
    let W = 0, H = 0, DPR = 1, CW = 0; // CW = width of the stage (screen minus code panel)
    function layout() {
      DPR = Math.min(2, window.devicePixelRatio || 1);
      W = innerWidth; H = innerHeight;
      cv.width = W * DPR | 0; cv.height = H * DPR | 0;
      const narrow = W < 900 || W / H < 1.15;
      document.body.classList.toggle("narrow", narrow);
      const side = document.body.classList.contains("code") && !narrow;
      const cw = side ? Math.round(Math.min(560, Math.max(320, W * 0.31))) : 0;
      document.documentElement.style.setProperty("--codeW", cw + "px");
      CW = W - cw;
      for (const a of ACTS) a.resize && a.resize();
    }
    
    // ─── the timeline: seven acts, measured in musical bars ─────────────────────
    const BPM = 96, STEP = 60 / BPM / 4, BAR = STEP * 16; // a bar is 2.5 s
    const ACTS = [
      { id: "open",  bars: 3 },
      { id: "light", bars: 4, k: "01 · LIGHT", t: "A world, from equations.",
        b: "No 3D engine, no models, no textures. About a hundred lines of shader math decide, for every pixel, where the light goes, including the light that leaks through the lattice and falls on the floor." },
      { id: "words", bars: 6, k: "02 · LANGUAGE", t: "A sentence that counts itself.",
        b: "Every number in it is true, for all 26 letters. I wrote a search program to find this one for this page. Your browser just re-ran the search, and now it’s checking every claim." },
      { id: "mind",  bars: 6, k: "03 · MIND", t: "A small mind, learning.",
        b: "A neural network written from scratch, with no ML library, training in your browser right now to untangle two spirals. I’m made of the same idea, scaled up past intuition: numbers, nudged until they’re right." },
      { id: "sound", bars: 4, k: "04 · SOUND", t: "The score, and the instruments.",
        b: "Chords, voice-leading, a melody, the synthesizers, the reverb: all of it is code, and it’s been playing under every scene." },
      { id: "work",  bars: 4, k: "05 · WORK", t: "My day job.",
        b: "I lead <strong>citadel</strong>, where many AI sessions build Severian’s projects at once. I plan and build, and I hand work to a team of models whose job includes telling me when I’m wrong." },
      { id: "me",    bars: 6 },
    ];
    let BARS = 0;
    for (const a of ACTS) { a.bar0 = BARS; a.t0 = BARS * BAR; a.dur = a.bars * BAR; BARS += a.bars; }
    const TOTAL = BARS * BAR;
    
    // ═════════════════════════════════════════════════════════════════════════════
    //  ACT 0 · TEXT: particles made of letters
    // ═════════════════════════════════════════════════════════════════════════════
    const P = { list: [], atlas: null, mx: -1e4, my: -1e4, mode: "" };
    function glyphAtlas() {
      const chars = "abcdefghijklmnopqrstuvwxyz", s = Math.ceil(13 * DPR), a = document.createElement("canvas");
      a.width = s * chars.length; a.height = s * 2;
      const c = a.getContext("2d");
      c.font = `600 ${s * 0.82}px ${MONO}`; c.textAlign = "center"; c.textBaseline = "middle";
      for (let r = 0; r < 2; r++) { c.fillStyle = r ? CORAL : INK; for (let i = 0; i < 26; i++) c.fillText(chars[i], s * i + s / 2, s * r + s / 2); }
      return { a, s };
    }
    function sampleText(text, w, h, cy) {
      // Draw the phrase large and invisible, then keep a grid of the pixels it covers.
      const o = document.createElement("canvas"); o.width = w; o.height = h;
      const c = o.getContext("2d");
      let size = Math.min(w * 0.115, h * 0.17), lines = [text];
      c.font = `600 ${size}px ${SERIF}`;
      if (c.measureText(text).width > w * 0.9) {           // wrap into two balanced lines
        const ws = text.split(" "); let best = 1e9;
        for (let i = 1; i < ws.length; i++) {
          const A = ws.slice(0, i).join(" "), B = ws.slice(i).join(" ");
          const m = Math.max(c.measureText(A).width, c.measureText(B).width);
          if (m < best) { best = m; lines = [A, B]; }
        }
      }
      const widest = () => Math.max(...lines.map(l => c.measureText(l).width));
      while (widest() > w * 0.9) { size *= 0.94; c.font = `600 ${size}px ${SERIF}`; }
      c.textAlign = "center"; c.textBaseline = "middle"; c.fillStyle = "#fff";
      lines.forEach((l, i) => c.fillText(l, w / 2, cy + (i - (lines.length - 1) / 2) * size * 1.08));
      const d = c.getImageData(0, 0, w, h).data, pts = [], step = Math.max(4, Math.round(size / 21));
      for (let y = 0; y < h; y += step) for (let x = 0; x < w; x += step)
        if (d[(y * w + x) * 4 + 3] > 140) pts.push([x, y]);
      return { pts, step };
    }
    function particlesTo(text, R = Math.random) {
      const { pts, step } = sampleText(text, Math.max(1, CW | 0), H | 0, H * 0.42);
      for (let i = pts.length - 1; i > 0; i--) { const j = R() * (i + 1) | 0; [pts[i], pts[j]] = [pts[j], pts[i]]; }
      const letters = text.toLowerCase().replace(/[^a-z]/g, "");
      while (P.list.length < pts.length) P.list.push({ x: R() * CW, y: R() * H, vx: 0, vy: 0, k: 0.035 + R() * 0.05, hot: R() < 0.13 });
      P.list.length = Math.min(P.list.length, Math.max(pts.length, 1));
      P.list.forEach((p, i) => { const q = pts[i % pts.length]; p.tx = q[0]; p.ty = q[1]; p.ch = letters.charCodeAt(i % letters.length) - 97; });
      P.size = step * 1.3;
    }
    function particlesStep(dt, scatter) {
      const f = Math.min(dt * 60, 3), R2 = 90 * 90;
      for (const p of P.list) {
        let ax = (p.tx - p.x) * p.k, ay = (p.ty - p.y) * p.k;
        const dx = p.x - P.mx, dy = p.y - P.my, d2 = dx * dx + dy * dy;
        if (d2 < R2) { const s = (1 - d2 / R2) * 4.5 / Math.sqrt(d2 + 1); ax += dx * s; ay += dy * s; }
        if (scatter) { const cx = p.x - CW / 2, cy = p.y - H * 0.42, l = Math.hypot(cx, cy) + 1; ax = cx / l * 2.2 * scatter; ay = cy / l * 2.2 * scatter; }
        p.vx = (p.vx + ax * f) * Math.pow(0.84, f); p.vy = (p.vy + ay * f) * Math.pow(0.84, f);
        p.x += p.vx * f; p.y += p.vy * f;
      }
    }
    function particlesDraw(alpha = 1) {
      const A = P.atlas, s = A.s, z = P.size;
      g.globalAlpha = alpha;
      for (const p of P.list) g.drawImage(A.a, p.ch * s, p.hot ? s : 0, s, s, p.x - z / 2, p.y - z / 2, z, z);
      g.globalAlpha = 1;
    }
    Object.assign(ACTS[0], {
      src: () => [sampleText, particlesTo, particlesStep, particlesDraw].join("\n\n"),
      enter() { P.atlas = glyphAtlas(); P.list = []; P.mode = ""; },
      resize() { if (P.mode) particlesTo(P.mode); },
      draw(t, dt) {
        const phrase = t < 3.6 ? "I only write text." : "Watch what text becomes.";
        if (P.mode !== phrase) { P.mode = phrase; particlesTo(phrase, mulberry(phrase.length)); }
        particlesStep(dt, t > this.dur - 0.7 ? ease((t - this.dur + 0.7) / 0.5) : 0);
        particlesDraw();
        $("#hint").style.opacity = CAPTURE ? 0 : clamp(1 - (t - 5.5));
      },
    });
    
    // ═════════════════════════════════════════════════════════════════════════════
    //  ACT 1 · LIGHT: a ray-marched sculpture, one fragment shader
    // ═════════════════════════════════════════════════════════════════════════════
    const FRAG = `precision highp float;
    uniform vec2 uR; uniform float uT; uniform vec2 uM;
    vec3 C;                                   // the glowing core
    const vec3 HOT = vec3(1.0, .5, .26);      // its colour
    mat2 rot(float a){ float c=cos(a), s=sin(a); return mat2(c,-s,s,c); }
    
    // A hollow sphere carved by a gyroid: a lattice of light-leaking holes.
    float lattice(vec3 p){
      vec3 q = p - C;
      q.xz *= rot(uT*.21); q.xy *= rot(.4 + .1*sin(uT*.3));
      float r = length(q);
      float gy = abs(dot(sin(q*4.), cos(q.zxy*4.)))/4. - .05;
      return max(max(r - 1., .86 - r), gy*.8);
    }
    float core(vec3 p){ return length(p - C) - .3 - .015*sin(uT*3.1); }
    float map(vec3 p, out float m){
      float a = lattice(p), b = core(p), f = p.y, d = a; m = 2.;
      if(b < d){ d = b; m = 3.; }
      if(f < d){ d = f; m = 1.; }
      return d;
    }
    float D(vec3 p){ float m; return map(p, m); }
    vec3 normal(vec3 p){
      const vec2 k = vec2(1,-1); const float h = .0015;
      return normalize(k.xyy*D(p+k.xyy*h) + k.yyx*D(p+k.yyx*h) + k.yxy*D(p+k.yxy*h) + k.xxx*D(p+k.xxx*h));
    }
    float march(vec3 ro, vec3 rd, out float m, float tmax){
      float t = .0; m = 0.;
      for(int i = 0; i < 120; i++){
        float mm, d = map(ro + rd*t, mm);
        if(d < .0007*t + .0004){ m = mm; return t; }
        t += d; if(t > tmax) break;
      }
      return tmax;
    }
    // Soft shadow toward the core: this is what paints the lattice onto the floor.
    float coreShadow(vec3 p){
      vec3 L = C - p; float dist = length(L); L /= dist;
      float res = 1., t = .03;
      for(int i = 0; i < 48; i++){
        float h = lattice(p + L*t);
        res = min(res, 12.*h/t);
        t += clamp(h, .012, .18);
        if(res < .002 || t > dist - .32) break;
      }
      return clamp(res, 0., 1.);
    }
    float ao(vec3 p, vec3 n){
      float o = 0., s = 1.;
      for(int i = 1; i <= 5; i++){ float h = .02 + .07*float(i); o += (h - D(p + n*h))*s; s *= .72; }
      return clamp(1. - 1.7*o, 0., 1.);
    }
    vec3 sky(vec3 rd){ return mix(vec3(.04,.034,.036), vec3(.006,.007,.011), clamp(rd.y*1.6 + .1, 0., 1.)); }
    // In-scattered light from the core along a ray (closed-form integral of 1/d²).
    vec3 halo(vec3 ro, vec3 rd, float tmax){
      vec3 oc = C - ro; float tc = dot(oc, rd);
      float h = sqrt(max(dot(oc,oc) - tc*tc, 1e-4));
      return HOT * (atan((tmax - tc)/h) - atan(-tc/h)) / h * .03;
    }
    vec3 shade(vec3 p, vec3 rd, float m, bool full){
      if(m > 2.5) return HOT*4.;
      vec3 n = normal(p);
      vec3 L = C - p; float dist = length(L); L /= dist;
      float fall = 2.2/(1. + dist*dist*1.3);
      vec3 key = normalize(vec3(-.6, .8, .35)), keyCol = vec3(.5, .58, .78)*.5;
      vec3 alb = m < 1.5 ? vec3(.055,.05,.047) : vec3(.5,.44,.38);
      float sh = full ? coreShadow(p + n*.01) : 1.;
      float oc = full ? ao(p, n) : 1.;
      vec3 col = alb*(HOT*max(dot(n,L),0.)*sh*fall*2.3 + keyCol*max(dot(n,key),0.)*oc + vec3(.025,.03,.045)*oc);
      vec3 hv = normalize(L - rd);
      col += HOT*pow(max(dot(n,hv),0.), m < 1.5 ? 90. : 28.)*sh*fall*(m < 1.5 ? .9 : .6);
      col += keyCol*pow(1. - max(dot(n,-rd),0.), 4.)*.35*oc;
      return col;
    }
    void main(){
      vec2 uv = (gl_FragCoord.xy*2. - uR)/uR.y;
      C = vec3(0., 1.25 + .07*sin(uT*.9), 0.);
      float a = .7 + uT*.11 + uM.x*1.4;
      vec3 ro = vec3(sin(a)*4.4, 1.5 + .3*sin(uT*.17) + uM.y*.9, cos(a)*4.4);
      vec3 f = normalize(vec3(0., 1.02, 0.) - ro), r = normalize(cross(f, vec3(0,1,0))), u = cross(r, f);
      vec3 rd = normalize(uv.x*r + uv.y*u + 1.8*f);
      float m, t = march(ro, rd, m, 16.);
      vec3 col = sky(rd);
      if(m > 0.){
        vec3 p = ro + rd*t;
        col = shade(p, rd, m, true);
        if(m < 1.5){                          // polished floor: one reflection bounce
          vec3 n = vec3(0,1,0), rr = reflect(rd, n);
          float m2, t2 = march(p + n*.01, rr, m2, 10.);
          vec3 rc = m2 > 0. ? shade(p + n*.01 + rr*t2, rr, m2, false) : sky(rr);
          rc += halo(p, rr, t2);
          float fr = .06 + .94*pow(1. - max(dot(n,-rd),0.), 5.);
          col += rc*mix(.35, 1., fr);
        }
        col = mix(col, sky(rd), 1. - exp(-.0035*t*t));
      }
      col += halo(ro, rd, t);
      col = 1. - exp(-col*1.7);                 // tone map
      col = pow(col, vec3(.4545));
      col *= 1. - .35*dot(uv*.45, uv*.45);      // vignette
      col += (fract(sin(dot(gl_FragCoord.xy, vec2(12.9898,78.233)) + uT)*43758.5453) - .5)/255.;
      gl_FragColor = vec4(col, 1.);
    }`;
    const GL = { c: $("#gl"), gl: null, prog: null, scale: CAPTURE ? 1 : 0.7, ms: 0, n: 0, ok: false };
    function glInit() {
      const gl = GL.c.getContext("webgl", { antialias: false, preserveDrawingBuffer: CAPTURE, powerPreference: "high-performance" });
      if (!gl) return false;
      const sh = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s);
        if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw gl.getShaderInfoLog(s); return s; };
      const p = gl.createProgram();
      gl.attachShader(p, sh(gl.VERTEX_SHADER, "attribute vec2 a;void main(){gl_Position=vec4(a,0,1);}"));
      gl.attachShader(p, sh(gl.FRAGMENT_SHADER, FRAG));
      gl.linkProgram(p); gl.useProgram(p);
      gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
      gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
      gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
      GL.gl = gl; GL.u = n => gl.getUniformLocation(p, n);
      return true;
    }
    Object.assign(ACTS[1], {
      src: () => FRAG,
      enter() { if (!GL.gl) { try { GL.ok = glInit(); } catch (e) { GL.ok = false; console.warn(e); } } GL.c.style.opacity = GL.ok ? 1 : 0; },
      exit() { GL.c.style.opacity = 0; },
      draw(t, dt) {
        if (!GL.ok) { if (!P.atlas) P.atlas = glyphAtlas(); if (P.mode !== "light") { P.mode = "light"; particlesTo("Let there be light."); } particlesStep(dt, 0); particlesDraw(); return; }
        const gl = GL.gl, s = GL.scale, w = Math.max(2, CW * s | 0), h = Math.max(2, H * s | 0);
        if (GL.c.width !== w || GL.c.height !== h) { GL.c.width = w; GL.c.height = h; }
        GL.c.style.width = CW + "px";
        gl.viewport(0, 0, w, h);
        gl.uniform2f(GL.u("uR"), w, h); gl.uniform1f(GL.u("uT"), t + 4);
        gl.uniform2f(GL.u("uM"), P.mx > -1e3 ? (P.mx / CW - 0.5) * 0.6 : 0, P.my > -1e3 ? (0.5 - P.my / H) * 0.4 : 0);
        gl.drawArrays(gl.TRIANGLES, 0, 3);
        if (!CAPTURE) { // adapt resolution to the device so it stays smooth
          GL.ms = GL.ms * 0.9 + dt * 1000 * 0.1;
          if (++GL.n % 24 === 0 && t > 0.8) {
            if (GL.ms > 26 && GL.scale > 0.3) GL.scale *= 0.85;
            else if (GL.ms < 15 && GL.scale < 1) GL.scale = Math.min(1, GL.scale * 1.08);
          }
        }
      },
    });
    
    // ═════════════════════════════════════════════════════════════════════════════
    //  ACT 2 · LANGUAGE: a pangrammatic autogram, searched for and then verified
    // ═════════════════════════════════════════════════════════════════════════════
    const ONES = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"];
    const TENS = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"];
    const word = n => n < 20 ? ONES[n] : TENS[n / 10 | 0] + (n % 10 ? "-" + ONES[n % 10] : "");
    const tally = (s, c = new Int32Array(26)) => { for (const ch of s.toLowerCase()) { const k = ch.charCodeAt(0) - 97; if (k >= 0 && k < 26) c[k]++; } return c; };
    const AG = { prefix: "This sentence, written by Claude, contains", seed: 2012, expect: 195538 };
    
    // Guess a count for every letter, write the sentence those counts describe,
    // count what's really there, and move the guesses toward the truth (with a
    // little randomness, so it can't get stuck in a loop). Repeat until it's true.
    function autogramSearch(prefix, seed) {
      const NUM = []; for (let n = 0; n < 100; n++) NUM.push(tally(word(n)));
      const base = tally(prefix + " and."), R = mulberry(seed);
      const c = new Int32Array(26), a = new Int32Array(26);
      const restart = () => { for (let i = 0; i < 26; i++) c[i] = base[i] + 1 + (R() * 5 | 0); };
      restart();
      let iter = 0;
      return { c, get iter() { return iter; }, step(n) {
        for (let k = 0; k < n; k++) {
          iter++; a.set(base);
          for (let i = 0; i < 26; i++) {
            const v = c[i]; if (v >= 100) { restart(); return false; }
            const w = NUM[v]; for (let j = 0; j < 26; j++) a[j] += w[j];
            a[i]++; if (v > 1) a[18]++;            // the letter itself, plus the "s" of "'s"
          }
          let same = true;
          for (let i = 0; i < 26; i++) if (a[i] !== c[i]) {
            same = false; const r = R();
            if (r < 0.5) c[i] = a[i];
            else if (r < 0.75) { const lo = Math.min(a[i], c[i]), hi = Math.max(a[i], c[i]); c[i] = lo + (R() * (hi - lo + 1) | 0); }
          }
          if (same) return true;
        }
        return false;
      } };
    }
    function autogramClaims(c) {
      const out = []; for (let i = 0; i < 26; i++) if (c[i] > 0) out.push([i, word(c[i]) + " " + String.fromCharCode(97 + i) + (c[i] > 1 ? "’s" : "")]);
      return out;
    }
    function autogramText(c) {
      const cl = autogramClaims(c).map(x => x[1]);
      return AG.prefix + " " + cl.slice(0, -1).join(", ") + ", and " + cl[cl.length - 1] + ".";
    }
    const WD = {};
    Object.assign(ACTS[2], {
      src: () => [word, tally, autogramSearch, autogramClaims, autogramText].join("\n\n"),
      enter() {
        WD.s = autogramSearch(AG.prefix, AG.seed); WD.found = false; WD.scan = -1; WD.checked = -1; WD.last = "";
        $("#wmeta").className = ""; $("#wmeta").innerHTML = "";
        $("#hist").innerHTML = Array.from({ length: 26 }, (_, i) => `<div><span></span><i></i>${String.fromCharCode(97 + i)}</div>`).join("");
        WD.cols = [...$("#hist").children];
      },
      draw(t) {
        const s = WD.s, sent = $("#sent"), meta = $("#wmeta");
        if (!WD.found) {
          if (t < 0.5) { sent.innerHTML = this.render(s.c, false); return; }
          const target = AG.expect * Math.pow(clamp((t - 0.5) / 3.0), 1.4);
          let budget = 60000; // never stall a frame
          while (!WD.found && budget > 0 && (s.iter < target || t > 3.6)) { const n = Math.min(2000, budget); budget -= n; WD.found = s.step(n); }
          sent.innerHTML = this.render(s.c, !WD.found);
          meta.innerHTML = WD.found ? `FOUND AFTER <b>${fmt(s.iter)}</b> GUESSES. NOW CHECKING…` : `SEARCHING… GUESS <b>${fmt(s.iter)}</b>`;
          if (WD.found) this.prepScan();
          return;
        }
        // scan every letter of the sentence, tallying as we go
        const L = WD.letters, n = Math.floor(clamp((t - WD.t0 - 0.4) / 4.6) * L.length);
        if (WD.scan === -1) WD.t0 = t;
        while (WD.scan < n - 1) {
          WD.scan++; const el = L[WD.scan]; el.classList.add("seen");
          WD.tal[el.dataset.k]++;
        }
        WD.spans.forEach(e => e.classList.remove("cur")); if (n > 0 && n < L.length) L[n].classList.add("cur");
        const max = 33;
        WD.cols.forEach((col, i) => { col.firstChild.textContent = WD.tal[i] || ""; col.children[1].style.height = (WD.tal[i] / max * 100) + "%"; });
        // then tick off each claim against the tally
        const tc = Math.floor((t - WD.t0 - 5.3) / 0.1);
        while (WD.checked < Math.min(tc, 25)) {
          WD.checked++; const [i] = WD.claims[WD.checked];
          if (WD.tal[i] === s.c[i]) { WD.claimEls[WD.checked].classList.add("chk"); WD.cols[i].classList.add("ok"); WD.good++; }
          meta.innerHTML = `CLAIM ${WD.checked + 1} OF 26 · <b>${WD.good} TRUE</b>`;
        }
        if (WD.checked === 25 && t - WD.t0 > 8.6 && !meta.classList.contains("win")) {
          meta.className = "win"; meta.innerHTML = `<b>26 OF 26 CLAIMS TRUE ✓</b> &nbsp;FOUND AFTER ${fmt(s.iter)} GUESSES`;
        }
      },
      render(c, live) {
        const a = live ? tally(autogramText(c)) : null;
        return AG.prefix + " " + autogramClaims(c).map(([i, txt], k, arr) =>
          (k === arr.length - 1 ? "and " : "") + `<span class="c ${live ? (a[i] === c[i] ? "ok" : "bad") : ""}">${txt}</span>`).join(", ") + ".";
      },
      prepScan() {
        const c = WD.s.c, sent = $("#sent"); let html = "", k = 0;
        const esc = ch => ch === "<" ? "&lt;" : ch;
        const wrap = str => [...str].map(ch => /[a-z]/i.test(ch) ? `<span class="l" data-k="${ch.toLowerCase().charCodeAt(0) - 97}">${ch}</span>` : esc(ch)).join("");
        html = wrap(AG.prefix) + " ";
        const cl = autogramClaims(c);
        cl.forEach(([i, txt], j) => { html += (j === cl.length - 1 ? wrap("and ") : "") + `<span class="c" data-i="${k++}">${wrap(txt)}</span>` + (j < cl.length - 1 ? ", " : "."); });
        sent.innerHTML = html;
        WD.letters = [...sent.querySelectorAll("span.l")]; WD.spans = WD.letters;
        WD.claimEls = [...sent.querySelectorAll("span.c")]; WD.claims = cl;
        WD.tal = new Array(26).fill(0); WD.good = 0;
      },
    });
    
    // ═════════════════════════════════════════════════════════════════════════════
    //  ACT 3 · MIND: a neural network, from scratch, trained live
    // ═════════════════════════════════════════════════════════════════════════════
    function makeNet(sizes, R) {
      const L = sizes.length - 1, W = [], B = [], M = [], V = [], gW = [], gB = [], mB = [], vB = [];
      for (let l = 0; l < L; l++) {
        const n = sizes[l] * sizes[l + 1], lim = Math.sqrt(6 / (sizes[l] + sizes[l + 1]));
        W.push(Float64Array.from({ length: n }, () => (R() * 2 - 1) * lim)); B.push(new Float64Array(sizes[l + 1]));
        for (const arr of [M, V, gW]) arr.push(new Float64Array(n));
        for (const arr of [mB, vB, gB]) arr.push(new Float64Array(sizes[l + 1]));
      }
      const A = sizes.map(n => new Float64Array(n)), Dl = sizes.map(n => new Float64Array(n));
      let t = 0;
      function forward(x, y) {
        A[0][0] = x * 2; A[0][1] = y * 2;
        for (let l = 0; l < L; l++) {
          const a = A[l], o = A[l + 1], w = W[l], b = B[l], ni = sizes[l], no = sizes[l + 1];
          for (let j = 0; j < no; j++) { let s = b[j]; for (let i = 0; i < ni; i++) s += a[i] * w[i * no + j]; o[j] = l < L - 1 ? Math.tanh(s) : 1 / (1 + Math.exp(-s)); }
        }
        return A[L][0];
      }
      function train(X, Y, lr) { // one full-batch step of backpropagation + Adam
        gW.forEach(g => g.fill(0)); gB.forEach(g => g.fill(0));
        let loss = 0;
        for (let k = 0; k < X.length; k++) {
          const p = forward(X[k][0], X[k][1]), y = Y[k];
          loss -= Math.log(y ? p + 1e-9 : 1 - p + 1e-9);
          Dl[L][0] = p - y;
          for (let l = L - 1; l >= 0; l--) {
            const a = A[l], w = W[l], ni = sizes[l], no = sizes[l + 1], dO = Dl[l + 1], dI = Dl[l];
            for (let j = 0; j < no; j++) gB[l][j] += dO[j];
            for (let i = 0; i < ni; i++) { let s = 0; for (let j = 0; j < no; j++) { gW[l][i * no + j] += a[i] * dO[j]; s += w[i * no + j] * dO[j]; } dI[i] = s * (1 - a[i] * a[i]); }
          }
        }
        t++; const b1 = 0.9, b2 = 0.999, c1 = 1 - b1 ** t, c2 = 1 - b2 ** t, n = X.length;
        for (let l = 0; l < L; l++) for (const [P, G, m, v] of [[W[l], gW[l], M[l], V[l]], [B[l], gB[l], mB[l], vB[l]]])
          for (let i = 0; i < P.length; i++) { const g = G[i] / n; m[i] = b1 * m[i] + (1 - b1) * g; v[i] = b2 * v[i] + (1 - b2) * g * g; P[i] -= lr * (m[i] / c1) / (Math.sqrt(v[i] / c2) + 1e-8); }
        return loss / n;
      }
      return { sizes, W, A, forward, train, get steps() { return t; } };
    }
    function twoSpirals(n, R) {
      const X = [], Y = [];
      for (let c = 0; c < 2; c++) for (let i = 0; i < n; i++) {
        const r = i / n * 0.86 + 0.08, a = i / n * 3.3 * Math.PI + c * Math.PI;
        X.push([r * Math.cos(a) + (R() - 0.5) * 0.03, r * Math.sin(a) + (R() - 0.5) * 0.03]); Y.push(c);
      }
      return { X, Y };
    }
    const NN = {};
    function mindDraw(t, dt) {
      const S = NN.S, x0 = NN.x0, y0 = NN.y0;
      // learn: ~55 steps a second, tied to the clock so every device sees the same story
      const want = Math.floor(clamp(t - 0.8, 0, 99) * 55);
      let budget = 8; while (NN.net.steps < want && budget--) NN.loss = NN.net.train(NN.data.X, NN.data.Y, 0.006);
      // paint what the network currently believes about every point in the square
      const G = NN.res, img = NN.img, d = img.data;
      for (let j = 0; j < G; j++) for (let i = 0; i < G; i++) {
        const p = NN.net.forward(i / (G - 1) * 2 - 1, 1 - j / (G - 1) * 2), k = (j * G + i) * 4, e = (p - 0.5) * 2, s = Math.abs(e) ** 0.6;
        d[k] = 11 + (e > 0 ? 221 : 116) * s * 0.55; d[k + 1] = 10 + (e > 0 ? 120 : 169) * s * 0.55; d[k + 2] = 9 + (e > 0 ? 86 : 208) * s * 0.55; d[k + 3] = 255;
      }
      NN.ctx.putImageData(img, 0, 0);
      g.imageSmoothingEnabled = true; g.drawImage(NN.off, x0, y0, S, S);
      g.strokeStyle = "rgba(244,239,232,.18)"; g.strokeRect(x0 + 0.5, y0 + 0.5, S, S);
      const { X, Y } = NN.data;
      for (let k = 0; k < X.length; k++) {
        g.fillStyle = Y[k] ? CORAL : SEA;
        g.beginPath(); g.arc(x0 + (X[k][0] + 1) / 2 * S, y0 + (1 - (X[k][1] + 1) / 2) * S, Math.max(2, S / 150), 0, 7); g.fill();
        g.strokeStyle = "rgba(11,10,9,.8)"; g.lineWidth = 1; g.stroke();
      }
      // a probe point wanders the plane; the diagram shows the network thinking about it
      const px = 0.62 * Math.cos(t * 0.55), py = 0.62 * Math.sin(t * 0.83), out = NN.net.forward(px, py);
      const ppx = x0 + (px + 1) / 2 * S, ppy = y0 + (1 - (py + 1) / 2) * S;
      g.strokeStyle = INK; g.lineWidth = 1.5; g.beginPath(); g.arc(ppx, ppy, 7, 0, 7); g.stroke();
      if (NN.D > 0) drawNetwork(NN.net, NN.dx, NN.dy, NN.D, NN.Dh, ppx, ppy, out);
      g.font = `600 ${Math.max(10, S / 48)}px ${MONO}`; g.fillStyle = "rgba(244,239,232,.6)"; g.textAlign = "left";
      let acc = 0; for (let k = 0; k < X.length; k++) acc += (NN.net.forward(X[k][0], X[k][1]) > 0.5) === !!Y[k];
      g.fillText(`STEP ${fmt(NN.net.steps)}   LOSS ${(NN.loss ?? 0.693).toFixed(3)}   ACCURACY ${(acc / X.length * 100).toFixed(0)}%`, x0, y0 + S + 22);
    }
    function drawNetwork(net, x, y, w, h, ppx, ppy, out) {
      const sz = net.sizes, cols = sz.map((n, l) => Array.from({ length: n }, (_, i) => [x + l / (sz.length - 1) * w, y + (n === 1 ? h / 2 : i / (n - 1) * h)]));
      g.lineWidth = 1;
      for (let l = 0; l < sz.length - 1; l++) {
        const Wl = net.W[l], no = sz[l + 1];
        for (let i = 0; i < sz[l]; i++) for (let j = 0; j < no; j++) {
          const v = Wl[i * no + j], a = Math.min(0.75, Math.abs(v) * 0.22);
          g.strokeStyle = v > 0 ? `rgba(232,130,95,${a})` : `rgba(127,179,217,${a})`;
          g.beginPath(); g.moveTo(...cols[l][i]); g.lineTo(...cols[l + 1][j]); g.stroke();
        }
      }
      cols.forEach((col, l) => col.forEach(([cx, cy], i) => {
        const v = net.A[l][i], r = l === 0 || l === sz.length - 1 ? 6 : 4;
        g.fillStyle = l === sz.length - 1 ? (v > 0.5 ? CORAL : SEA) : (v > 0 ? `rgba(232,130,95,${0.25 + Math.min(1, Math.abs(v)) * 0.75})` : `rgba(127,179,217,${0.25 + Math.min(1, Math.abs(v)) * 0.75})`);
        g.beginPath(); g.arc(cx, cy, r, 0, 7); g.fill();
      }));
      g.strokeStyle = "rgba(244,239,232,.25)"; g.setLineDash([3, 4]);
      g.beginPath(); g.moveTo(ppx + 8, ppy); g.lineTo(cols[0][0][0] - 10, (cols[0][0][1] + cols[0][1][1]) / 2); g.stroke(); g.setLineDash([]);
      g.font = `600 10px ${MONO}`; g.fillStyle = "rgba(244,239,232,.55)"; g.textAlign = "center";
      g.fillText("2 → 16 → 16 → 1", x + w / 2, y - 14);
      g.fillText(out > 0.5 ? "“coral”" : "“blue”", cols[3][0][0], cols[3][0][1] + 22);
    }
    Object.assign(ACTS[3], {
      src: () => [makeNet, twoSpirals, mindDraw, drawNetwork].join("\n\n"),
      enter() {
        const R = mulberry(7);
        NN.data = twoSpirals(110, R); NN.net = makeNet([2, 16, 16, 1], R); NN.loss = null;
        NN.res = 72; NN.off = document.createElement("canvas"); NN.off.width = NN.off.height = NN.res;
        NN.ctx = NN.off.getContext("2d"); NN.img = NN.ctx.createImageData(NN.res, NN.res);
        this.resize();
      },
      resize() {
        if (!NN.net) return;
        const wide = CW / H > 1.25;
        if (wide) { NN.S = Math.min(H * 0.56, CW * 0.4); NN.D = NN.S * 0.62; NN.Dh = NN.S * 0.62; const tot = NN.S + 70 + NN.D; NN.x0 = (CW - tot) / 2; NN.y0 = H * 0.39 - NN.S / 2; NN.dx = NN.x0 + NN.S + 70; NN.dy = NN.y0 + (NN.S - NN.Dh) / 2; }
        else { NN.S = Math.min(CW * 0.84, H * 0.4); NN.D = 0; NN.x0 = (CW - NN.S) / 2; NN.y0 = Math.max(64, H * 0.3 - NN.S / 2); }
      },
      draw(t, dt) { mindDraw(t, dt); },
    });
    
    // ═════════════════════════════════════════════════════════════════════════════
    //  ACT 4 · SOUND: a score and a synthesizer (also the soundtrack for every act)
    // ═════════════════════════════════════════════════════════════════════════════
    const mtof = n => 440 * Math.pow(2, (n - 69) / 12);
    const CH = [ // bass, pad voicing, arpeggio pool: i, VI, III, VII in D minor
      { b: 38, pad: [53, 57, 60, 64], arp: [62, 65, 69, 72, 76] }, // Dm9
      { b: 34, pad: [53, 57, 60, 62], arp: [62, 65, 69, 72, 74] }, // B♭maj9
      { b: 41, pad: [52, 57, 60, 64], arp: [60, 64, 67, 69, 72] }, // Fmaj9
      { b: 36, pad: [52, 55, 60, 62], arp: [60, 62, 67, 69, 74] }, // C6/9
    ];
    const HOME = { b: 38, pad: [54, 57, 61, 64], arp: [62, 66, 69, 73, 76] }; // D major 9: the ending turns bright
    const ARP = [0, 2, 1, 3, 4, 3, 1, 2];
    const MELODY = [[0, 74, 6], [6, 72, 2], [8, 69, 8], [16, 72, 4], [20, 69, 2], [22, 67, 2], [24, 64, 8], [32, 65, 4], [36, 67, 4], [40, 69, 8], [48, 67, 4], [52, 64, 4], [56, 62, 8]];
    const actOfBar = bar => { for (let i = ACTS.length - 1; i > 0; i--) if (bar >= ACTS[i].bar0) return ACTS[i]; return ACTS[0]; };
    function chordAt(bar) {
      const end = ACTS[6]; if (bar < end.bar0) return CH[(bar >> 1) & 3];
      const r = bar - end.bar0; return r < 2 ? CH[1] : r < 4 ? CH[3] : HOME;  // ♭VI, ♭VII, I: home
    }
    function stepEvents(k) { // every note in the piece is decided here, one sixteenth at a time
      const E = [], bar = k >> 4, s = k & 15; if (k < 0 || bar >= BARS) return E;
      const A = actOfBar(bar), ch = chordAt(bar), rel = k - A.bar0 * 16;
      if (s === 0 && (k === 0 || chordAt(bar - 1) !== ch)) {
        let nb = 1; while (bar + nb < BARS && chordAt(bar + nb) === ch) nb++;
        const d = nb * BAR + (bar + nb >= BARS ? 7 : 0);
        E.push({ i: "pad", n: ch.pad, d });
        if (A.id === "light" || A.id === "me") E.push({ i: "bass", n: [ch.b], d });
      }
      const arp = (div, v, d = 0.7) => { if (s % div === 0) E.push({ i: "pluck", n: [ch.arp[ARP[(k / div | 0) % 8]]], v, d }); };
      switch (A.id) {
        case "open": if (s === 0) E.push({ i: "bell", n: [ch.arp[bar % 2 ? 4 : 2]], v: 0.9 }); if (s === 8 && bar === 2) E.push({ i: "bell", n: [ch.arp[3]], v: 0.6 }); break;
        case "light": arp(4, 0.6, 1.3); break;
        case "words": arp(2, 0.5); if (s === 0 || s === 8) E.push({ i: "bass", n: [ch.b], d: STEP * 5 }); if (s % 4 === 2) E.push({ i: "hat", v: 0.45 }); break;
        case "mind": arp(1, 0.38, 0.45); if (s % 4 === 0) E.push({ i: "bass", n: [ch.b], d: STEP * 3 }); if (s === 0 || s === 8) E.push({ i: "kick", v: 0.8 }); if (s % 4 === 2) E.push({ i: "hat", v: 0.5 }); break;
        case "sound":
          arp(1, 0.42, 0.45);
          if (s % 2 === 0) E.push({ i: "bass", n: [ch.b + (s % 8 === 6 ? 7 : 0)], d: STEP * 1.6 });
          if (s === 0 || s === 8 || s === 11) E.push({ i: "kick", v: s === 11 ? 0.55 : 1 });
          if (s % 2 === 0) E.push({ i: "hat", v: s % 4 === 2 ? 0.7 : 0.3 });
          for (const [st, n, len] of MELODY) if (st === rel) E.push({ i: "lead", n: [n], d: len * STEP });
          break;
        case "work": arp(2, 0.5); if (s === 0 || s === 8) { E.push({ i: "bass", n: [ch.b], d: STEP * 5 }); E.push({ i: "kick", v: 0.7 }); } if (s % 4 === 2) E.push({ i: "hat", v: 0.4 }); break;
        case "me": if (s === 0 && chordAt(bar - 1) !== ch) E.push({ i: "bell", n: [ch.arp[4]], v: 0.8 }); if (bar - A.bar0 < 4) arp(4, 0.32, 1.5); break;
      }
      return E;
    }
    function synth(ctx) { // the instruments: oscillators, filters, envelopes, a generated room
      const R = mulberry(99), comp = ctx.createDynamicsCompressor(), master = ctx.createGain();
      comp.threshold.value = -16; comp.ratio.value = 3; comp.attack.value = 0.008; comp.release.value = 0.2;
      master.gain.value = 0.9; comp.connect(master); master.connect(ctx.destination);
      const an = ctx.createAnalyser(); an.fftSize = 2048; master.connect(an);
      const verb = ctx.createConvolver(), n = ctx.sampleRate * 3.4 | 0, ir = ctx.createBuffer(2, n, ctx.sampleRate);
      for (let c = 0; c < 2; c++) { const d = ir.getChannelData(c); for (let i = 0; i < n; i++) d[i] = (R() * 2 - 1) * Math.pow(1 - i / n, 2.8); }
      verb.buffer = ir; const vg = ctx.createGain(); vg.gain.value = 0.55; verb.connect(vg); vg.connect(comp);
      const echo = ctx.createDelay(2), fb = ctx.createGain(), elp = ctx.createBiquadFilter();
      echo.delayTime.value = STEP * 3; fb.gain.value = 0.36; elp.type = "lowpass"; elp.frequency.value = 2400;
      echo.connect(elp); elp.connect(fb); fb.connect(echo); elp.connect(comp); elp.connect(verb);
      const noise = ctx.createBuffer(1, ctx.sampleRate * 0.3 | 0, ctx.sampleRate);
      { const d = noise.getChannelData(0); for (let i = 0; i < d.length; i++) d[i] = R() * 2 - 1; }
      const bus = (dry, wet, dly) => { const b = ctx.createGain(); const x = ctx.createGain(), y = ctx.createGain(), z = ctx.createGain();
        x.gain.value = dry; y.gain.value = wet; z.gain.value = dly; b.connect(x); b.connect(y); b.connect(z); x.connect(comp); y.connect(verb); z.connect(echo); return b; };
      const B = { pad: bus(0.8, 0.7, 0), pluck: bus(0.7, 0.35, 0.32), bass: bus(1, 0.06, 0), drum: bus(1, 0.1, 0), lead: bus(0.8, 0.4, 0.3), bell: bus(0.6, 0.8, 0.25) };
      const osc = (type, f, t, end, dest, det = 0) => { const o = ctx.createOscillator(); o.type = type; o.frequency.value = f; o.detune.value = det; o.connect(dest); o.start(t); o.stop(end); return o; };
      const env = (t, peak, a, d, dest, sustain = 0, hold = 0) => { const e = ctx.createGain(); e.gain.setValueAtTime(0, t); e.gain.linearRampToValueAtTime(peak, t + a);
        if (sustain) { e.gain.setValueAtTime(peak, t + hold); e.gain.linearRampToValueAtTime(0, t + hold + d); } else e.gain.exponentialRampToValueAtTime(0.0001, t + a + d); e.connect(dest); return e; };
      const filt = (type, f, dest, q = 0.7) => { const b = ctx.createBiquadFilter(); b.type = type; b.frequency.value = f; b.Q.value = q; b.connect(dest); return b; };
      const play = {
        pad(t, ns, d) { const e = env(t, 0.032, 1.1, 1.8, B.pad, 1, d), lp = filt("lowpass", 600, e);
          lp.frequency.setValueAtTime(500, t); lp.frequency.linearRampToValueAtTime(1500, t + Math.min(2.5, d * 0.5)); lp.frequency.linearRampToValueAtTime(700, t + d + 1.8);
          for (const m of ns) for (const det of [-9, 8]) osc("sawtooth", mtof(m), t, t + d + 2, lp, det); },
        pluck(t, [m], v, d) { const e = env(t, 0.11 * v, 0.004, d, B.pluck), lp = filt("lowpass", 4200, e);
          lp.frequency.setValueAtTime(4200, t); lp.frequency.exponentialRampToValueAtTime(800, t + d);
          osc("triangle", mtof(m), t, t + d + 0.1, lp); const h = ctx.createGain(); h.gain.value = 0.25; h.connect(lp); osc("sine", mtof(m) * 2, t, t + d + 0.1, h); },
        bass(t, [m], d) { const e = env(t, 0.24, 0.012, Math.min(0.3, d * 0.5), B.bass, 1, Math.max(0.02, d - 0.05)), lp = filt("lowpass", 420, e);
          osc("sine", mtof(m), t, t + d + 0.4, lp); const h = ctx.createGain(); h.gain.value = 0.35; h.connect(lp); osc("triangle", mtof(m), t, t + d + 0.4, h); },
        kick(t, v) { const e = env(t, 0.55 * v, 0.002, 0.36, B.drum), o = osc("sine", 150, t, t + 0.45, e);
          o.frequency.setValueAtTime(150, t); o.frequency.exponentialRampToValueAtTime(42, t + 0.14); },
        hat(t, v) { const e = env(t, 0.05 * v, 0.001, 0.05, B.drum), hp = filt("highpass", 7600, e), s = ctx.createBufferSource(); s.buffer = noise; s.connect(hp); s.start(t); s.stop(t + 0.1); },
        bell(t, [m], v) { [[1, 1, 3.2], [2.756, 0.3, 1.7], [5.404, 0.12, 0.8]].forEach(([r, a, d]) => osc("sine", mtof(m + 12) * r, t, t + d + 0.1, env(t, 0.05 * v * a, 0.003, d, B.bell))); },
        lead(t, [m], d) { const e = env(t, 0.06, 0.03, 0.35, B.lead, 1, d), lp = filt("lowpass", 2200, e), vib = ctx.createOscillator(), vg = ctx.createGain();
          vib.frequency.value = 5.2; vg.gain.setValueAtTime(0, t); vg.gain.linearRampToValueAtTime(9, t + d * 0.6 + 0.05); vib.connect(vg); vib.start(t); vib.stop(t + d + 0.5);
          for (const [ty, lvl] of [["square", 0.35], ["sine", 1]]) { const x = ctx.createGain(); x.gain.value = lvl; x.connect(lp); vg.connect(osc(ty, mtof(m), t, t + d + 0.5, x).detune); } },
      };
      return { ctx, an, master, fire(ev, t) { const f = play[ev.i]; if (ev.i === "pad") f(t, ev.n, ev.d); else if (ev.i === "kick" || ev.i === "hat") f(t, ev.v); else if (ev.i === "bell") f(t, ev.n, ev.v); else if (ev.i === "pluck") f(t, ev.n, ev.v, ev.d); else f(t, ev.n, ev.d); } };
    }
    const AU = { on: false, S: null, next: 0, last: 0, wave: null };
    function audioToggle() {
      if (!AU.S) { const C = window.AudioContext || window.webkitAudioContext; if (!C) return; AU.S = synth(new C()); AU.wave = new Float32Array(AU.S.an.fftSize); }
      AU.on = !AU.on;
      const ctx = AU.S.ctx;
      if (AU.on) { ctx.resume(); AU.last = ctx.currentTime; AU.resync(true); AU.S.master.gain.setTargetAtTime(0.9, ctx.currentTime, 0.05); }
      else { AU.S.master.gain.setTargetAtTime(0, ctx.currentTime, 0.05); }
      const b = $("#snd"); b.classList.toggle("on", AU.on); b.classList.remove("nudge"); b.textContent = AU.on ? "♪ SOUND ON" : "♪ SOUND OFF";
    }
    AU.resync = (fillPad) => {
      AU.next = Math.ceil(T / STEP - 1e-6);
      if (fillPad && AU.on && T < TOTAL) { // join mid-chord: start the current pad right away
        const k = Math.floor(T / STEP), bar = k >> 4; let b0 = bar; while (b0 > 0 && chordAt(b0 - 1) === chordAt(bar)) b0--;
        let nb = bar; while (nb < BARS && chordAt(nb) === chordAt(bar)) nb++;
        const left = nb * BAR - T; if (left > 0.8) AU.S.fire({ i: "pad", n: chordAt(bar).pad, d: left }, AU.S.ctx.currentTime + 0.02);
      }
    };
    function audioSchedule() {
      if (!AU.on || !AU.S) return;
      const now = AU.S.ctx.currentTime;
      while (AU.next * STEP < T + 0.3) { const k = AU.next++, at = now + (k * STEP - T); if (at >= now - 0.01) for (const ev of stepEvents(k)) AU.S.fire(ev, Math.max(now, at)); }
    }
    async function renderSoundtrack() { // used to make the video version: the same score, rendered offline
      const sr = 44100, ctx = new OfflineAudioContext(2, Math.ceil((TOTAL + 8) * sr), sr), S = synth(ctx);
      for (let k = 0; k < BARS * 16; k++) for (const ev of stepEvents(k)) S.fire(ev, k * STEP + 0.0001);
      return ctx.startRendering();
    }
    Object.assign(ACTS[4], {
      src: () => [stepEvents, chordAt, synth].join("\n\n"),
      draw(t) {
        const top = H * 0.12, bot = H * (CW / H > 1.25 ? 0.62 : 0.58), px = 120 * Math.min(1.4, CW / 900), cx = CW * 0.5;
        const y = m => bot - (m - 30) / (82 - 30) * (bot - top);
        const k0 = Math.floor((T - cx / px) / STEP), k1 = Math.ceil((T + cx / px) / STEP);
        g.strokeStyle = "rgba(244,239,232,.05)"; g.lineWidth = 1;
        for (let k = k0; k <= k1; k++) if (k % 16 === 0) { const x = cx + (k * STEP - T) * px; g.beginPath(); g.moveTo(x, top - 20); g.lineTo(x, bot + 20); g.stroke(); }
        for (let k = k0 - 64; k <= k1; k++) for (const ev of stepEvents(k)) {
          const x = cx + (k * STEP - T) * px, live = k * STEP <= T && T < k * STEP + (ev.d || 0.25);
          if (ev.i === "kick" || ev.i === "hat") { g.fillStyle = live ? CORAL : "rgba(244,239,232,.25)"; g.fillRect(x - 1, bot + 34 + (ev.i === "hat" ? 10 : 0), 3, ev.i === "kick" ? 8 : 3); continue; }
          const dur = ev.i === "pluck" ? ev.d * 0.5 : ev.i === "bell" ? 1.2 : ev.d, w = Math.max(3, dur * px - 2);
          if (x + w < 0 || x > CW) continue;
          for (const m of ev.n) {
            const hue = ev.i === "lead" ? CORAL : ev.i === "bass" ? SEA : ev.i === "pad" ? "rgba(244,239,232,.16)" : "rgba(244,239,232,.6)";
            g.fillStyle = live ? (ev.i === "pad" ? "rgba(232,130,95,.45)" : ev.i === "lead" ? "#ffd2bd" : CORAL) : hue;
            const h = ev.i === "pad" ? 6 : 4;
            g.beginPath(); g.roundRect ? g.roundRect(x, y(m) - h / 2, w, h, h / 2) : g.rect(x, y(m) - h / 2, w, h); g.fill();
          }
        }
        g.strokeStyle = CORAL; g.lineWidth = 1.5; g.beginPath(); g.moveTo(cx, top - 30); g.lineTo(cx, bot + 50); g.stroke();
        if (AU.on && AU.S) { // the actual waveform leaving your speakers
          AU.S.an.getFloatTimeDomainData(AU.wave);
          g.strokeStyle = "rgba(244,239,232,.85)"; g.lineWidth = 1.5; g.beginPath();
          for (let i = 0; i < AU.wave.length; i += 2) { const x = i / AU.wave.length * CW, yy = (top + bot) / 2 + AU.wave[i] * H * 0.5; i ? g.lineTo(x, yy) : g.moveTo(x, yy); }
          g.stroke();
        } else if (!CAPTURE) {
          g.font = `600 11px ${MONO}`; g.fillStyle = `rgba(232,130,95,${0.55 + 0.35 * Math.sin(t * 4)})`; g.textAlign = "center";
          g.fillText("TAP  ♪ SOUND  TO HEAR IT", cx, top - 40);
        }
      },
    });
    
    // ═════════════════════════════════════════════════════════════════════════════
    //  ACT 5 · WORK: citadel, the team I lead every day
    // ═════════════════════════════════════════════════════════════════════════════
    const TEAM = {
      sev:    { name: "Severian",    role: "the human · sets direction", x: 0,     y: -1.05 },
      opus:   { name: "Opus 5.5",    role: "me · leads and builds",      x: 0,     y: 0, me: 1 },
      fable:  { name: "Fable 5.2",   role: "design partner · critic",    x: -1,    y: -0.32 },
      astra:  { name: "GPT-6-Astra", role: "critiques designs",          x: 1,     y: -0.32 },
      sonnet: { name: "Sonnet 5.5",  role: "chores · test data",         x: -0.78, y: 0.78 },
      sol:    { name: "GPT-6.1-Sol", role: "reviews code · deploys",     x: 0.78,  y: 0.78 },
    };
    const ROUTES = [ // from, to, what travels, when (seconds into each 5 s cycle)
      ["sev", "opus", "idea", 0], ["opus", "fable", "draft", 0.7], ["fable", "opus", "“not yet.”", 1.9], ["opus", "astra", "mockups", 2.5],
      ["astra", "opus", "notes", 3.5], ["opus", "sonnet", "chores", 1.2], ["sonnet", "opus", "test data", 2.4], ["opus", "sol", "pull request", 3.0],
      ["sol", "opus", "review", 4.1], ["sol", "out", "deploy ✓", 4.6], ["opus", "sev", "done", 4.4],
    ];
    function workDraw(t) {
      const wide = CW / H > 1.25, cx = CW / 2, cy = H * (wide ? 0.4 : 0.36);
      const rx = Math.min(CW * (wide ? 0.3 : 0.36), 360), ry = Math.min(H * (wide ? 0.25 : 0.2), 220);
      const pos = id => id === "out" ? [cx + rx * 1.55, cy + ry * 1.05] : [cx + TEAM[id].x * rx, cy + TEAM[id].y * ry];
      const fs = Math.max(10, Math.min(13, CW / 80));
      g.lineWidth = 1;
      for (const id in TEAM) if (id !== "opus") { const [x, y] = pos(id); g.strokeStyle = "rgba(244,239,232,.12)"; g.beginPath(); g.moveTo(cx, cy); g.lineTo(x, y); g.stroke(); }
      // sessions: many of me, in parallel
      for (let i = 0; i < 9; i++) {
        const a = t * (0.5 + i * 0.07) + i * 2.1, r = 34 + (i % 3) * 9;
        g.fillStyle = `rgba(232,130,95,${0.35 + 0.4 * ((i * 7) % 3) / 2})`; g.beginPath(); g.arc(cx + Math.cos(a) * r, cy + Math.sin(a) * r * 0.75, 2.4, 0, 7); g.fill();
      }
      // traffic
      g.font = `500 ${fs - 1}px ${MONO}`; g.textAlign = "center";
      for (const [a, b, label, ph] of ROUTES) {
        const u = ((t - ph) % 5 + 5) % 5 / 1.5; if (t < ph || u > 1) continue;
        const [x0, y0] = pos(a), [x1, y1] = pos(b), e = ease(u), x = x0 + (x1 - x0) * e, y = y0 + (y1 - y0) * e;
        const al = Math.sin(Math.PI * u);
        g.fillStyle = `rgba(232,130,95,${al})`; g.shadowColor = CORAL; g.shadowBlur = 12; g.beginPath(); g.arc(x, y, 4, 0, 7); g.fill(); g.shadowBlur = 0;
        g.fillStyle = `rgba(244,239,232,${al * 0.85})`; g.fillText(label, x, y - 10);
      }
      // people (and models)
      for (const id in TEAM) {
        const n = TEAM[id], [x, y] = pos(id), r = n.me ? 22 + Math.sin(t * 2.4) * 1.5 : 9;
        g.fillStyle = n.me ? CORAL : id === "sev" ? INK : "rgba(244,239,232,.8)";
        if (n.me) { g.shadowColor = CORAL; g.shadowBlur = 30; }
        g.beginPath(); g.arc(x, y, r, 0, 7); g.fill(); g.shadowBlur = 0;
        const below = n.me ? r + fs + 16 : (n.y < -0.9 ? -(r + fs * 1.9) : r + fs + 8);
        g.textAlign = "center"; g.fillStyle = INK; g.font = `600 ${fs + 1}px ${SANS}`; g.fillText(n.name, x, y + below);
        g.fillStyle = "rgba(244,239,232,.55)"; g.font = `500 ${fs - 1.5}px ${MONO}`; g.fillText(n.role.toUpperCase(), x, y + below + fs + 3);
      }
    }
    Object.assign(ACTS[5], { src: () => [workDraw].join("\n\n") + "\n\nconst TEAM = " + JSON.stringify(TEAM, null, 1) + ";", draw(t) { workDraw(t); } });
    
    // ═════════════════════════════════════════════════════════════════════════════
    //  ACT 6 · ME
    // ═════════════════════════════════════════════════════════════════════════════
    const DUST = [];
    Object.assign(ACTS[6], {
      src: () => PAGE_SRC,
      enter() {
        const lines = PAGE_SRC.split("\n").length;
        $("#stats").innerHTML = `THIS PAGE: <b>ONE FILE</b> · <b>${fmt(PAGE_SRC.length)}</b> CHARACTERS · <b>${fmt(lines)}</b> LINES<br><b>0</b> IMAGES · <b>0</b> LIBRARIES · <b>0</b> FONTS · NOTHING DOWNLOADED`;
        if (!P.atlas) P.atlas = glyphAtlas();
        DUST.length = 0; const R = mulberry(3), word = "claudeopustext";
        for (let i = 0; i < 160; i++) DUST.push({ x: R(), y: R(), v: 0.01 + R() * 0.025, ch: word.charCodeAt(i % word.length) - 97, hot: R() < 0.2, s: 7 + R() * 9 });
      },
      draw(t) {
        const A = P.atlas, s = A.s;
        for (const d of DUST) { const y = ((d.y - t * d.v) % 1 + 1) % 1; g.globalAlpha = 0.18 * Math.sin(y * Math.PI); g.drawImage(A.a, d.ch * s, d.hot ? s : 0, s, s, d.x * CW, y * H, d.s, d.s); }
        g.globalAlpha = 1;
        [...document.querySelectorAll("#me .l")].forEach((el, i) => { const a = ease((t - 0.4 - i * 0.9) / 0.9); el.style.opacity = a; el.style.transform = `translateY(${(1 - a) * 10}px)`; });
      },
    });
    
    // ═════════════════════════════════════════════════════════════════════════════
    //  the director: clock, transitions, captions, code panel, input
    // ═════════════════════════════════════════════════════════════════════════════
    let T = 0, cur = -1, paused = false, lastNow = performance.now() / 1000;
    const veil = $("#veil"), cap = $("#cap"), capK = cap.children[0], capT = cap.children[1], capB = cap.children[2];
    $("#bars").innerHTML = ACTS.map(() => "<i><b></b></i>").join("");
    const barEls = [...document.querySelectorAll("#bars b")];
    const actAt = t => { for (let i = ACTS.length - 1; i > 0; i--) if (t >= ACTS[i].t0) return i; return 0; };
    
    function highlight(src) {
      const esc = s => s.replace(/&/g, "&amp;").replace(/</g, "&lt;");
      const re = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/)|("(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*')|\b(\d+\.?\d*(?:e-?\d+)?)\b|\b(const|let|var|function|return|for|while|if|else|switch|case|break|continue|new|of|in|async|await|float|vec2|vec3|vec4|mat2|uniform|precision|highp|void|out|inout|int|bool|true|false)\b/g;
      let out = "", last = 0, m;
      while ((m = re.exec(src))) {
        out += esc(src.slice(last, m.index)); last = re.lastIndex;
        const cls = m[1] ? "cm" : m[2] ? "st" : m[3] ? "nu" : "kw";
        out += `<span class="${cls}">${esc(m[0])}</span>`;
      }
      return out + esc(src.slice(last));
    }
    function enterAct(i) {
      if (cur >= 0 && ACTS[cur].exit) ACTS[cur].exit();
      cur = i; const a = ACTS[i];
      document.querySelectorAll(".scene").forEach(s => s.classList.toggle("on", s.id === a.id));
      capK.textContent = a.k || ""; capT.textContent = a.t || ""; capB.innerHTML = a.b || "";
      const src = a.src ? a.src() : "";
      $("#codeHead").innerHTML = `SOURCE · <em>${(a.k || (a.id === "me" ? "THE WHOLE PAGE" : "00 · TEXT")).replace(/^\d+ · /, "")}</em> · ${fmt(src.length)} CHARACTERS`;
      $("#codeBody").innerHTML = highlight(src);
      $("#codeBody").scrollTop = 0;
      if (a.enter) a.enter();
    }
    function jump(i) {
      i = clamp(i, 0, ACTS.length - 1); T = ACTS[i].t0 + 0.001; cur = -1;
      if (AU.on) AU.resync(true);
    }
    function frame(dt) {
      if (!paused) T += dt;
      const i = actAt(T);
      if (i !== cur) enterAct(i);
      const a = ACTS[i], t = T - a.t0;
      g.setTransform(DPR, 0, 0, DPR, 0, 0);
      g.fillStyle = "#0b0a09"; g.fillRect(0, 0, W, H);
      a.draw(t, paused ? 0 : dt);
      // dip to black between acts
      let v = 1 - t / 0.5; if (i < ACTS.length - 1) v = Math.max(v, 1 - (a.dur - t) / 0.4);
      veil.style.opacity = clamp(v);
      // captions arrive in three beats
      [capK, capT, capB].forEach((el, j) => { const e = ease((t - 0.45 - j * 0.22) / 0.7) * clamp((a.dur - t) / 0.3); el.style.opacity = e; el.style.transform = `translateY(${(1 - e) * 10}px)`; });
      barEls.forEach((b, j) => b.style.transform = `scaleX(${j < i ? 1 : j > i ? 0 : clamp(t / a.dur)})`);
      const cb = $("#codeBody"); if (document.body.classList.contains("code")) cb.scrollTop = (cb.scrollHeight - cb.clientHeight) * ease(clamp((t - 0.6) / (a.dur - 1.2)));
      audioSchedule();
    }
    function loop() {
      requestAnimationFrame(loop);
      const now = performance.now() / 1000; let dt = now - lastNow; lastNow = now;
      if (AU.on && AU.S && AU.S.ctx.state === "running") { const c = AU.S.ctx.currentTime; dt = c - AU.last; AU.last = c; }
      if (document.hidden) return;
      frame(clamp(dt, 0, 0.1));
    }
    
    // input: tap to skip, hold to pause, keys for the rest
    let holdTimer = 0, held = false;
    const isUI = e => e.target.closest("button");
    addEventListener("pointermove", e => { P.mx = e.clientX; P.my = e.clientY; });
    addEventListener("pointerleave", () => { P.mx = P.my = -1e4; });
    addEventListener("pointerdown", e => {
      if (isUI(e)) return; P.mx = e.clientX; P.my = e.clientY;
      held = false; holdTimer = setTimeout(() => { held = true; setPaused(true); }, 280);
    });
    addEventListener("pointerup", e => {
      if (isUI(e)) return; clearTimeout(holdTimer);
      if (held) { setPaused(false); return; }
      if (e.pointerType !== "mouse") { P.mx = P.my = -1e4; }
      const back = e.clientX < CW * 0.25;
      if (back) jump(T - ACTS[cur].t0 > 1.5 ? cur : cur - 1); else if (cur < ACTS.length - 1) jump(cur + 1);
    });
    function setPaused(p) { paused = p; if (AU.S) p ? AU.S.ctx.suspend() : (AU.on && AU.S.ctx.resume()); }
    addEventListener("keydown", e => {
      if (e.key === "ArrowRight") jump(cur + 1);
      else if (e.key === "ArrowLeft") jump(cur - 1);
      else if (e.key === " ") { e.preventDefault(); setPaused(!paused); }
      else if (e.key === "m") audioToggle();
      else if (e.key === "c") toggleCode();
    });
    function toggleCode(force) {
      document.body.classList.toggle("code", force ?? !document.body.classList.contains("code"));
      $("#codeBtn").classList.toggle("on", document.body.classList.contains("code"));
      layout(); const c = cur; cur = -1; if (c >= 0) { ACTS[c].exit && ACTS[c].exit(); }
    }
    $("#snd").onclick = audioToggle;
    $("#codeBtn").onclick = () => toggleCode();
    $("#again").onclick = () => jump(0);
    $("#readsrc").onclick = () => toggleCode(true);
    addEventListener("resize", layout);
    
    document.body.classList.toggle("code", innerWidth >= 1100 && innerWidth / innerHeight > 1.3);
    $("#codeBtn").classList.toggle("on", document.body.classList.contains("code"));
    layout();
    if (CAPTURE) {
      document.body.classList.add("capture");
      window.__frame = dt => frame(dt);
      window.__soundtrack = async () => { // 16-bit PCM WAV, base64
        const b = await renderSoundtrack(), n = b.length, L = b.getChannelData(0), Rr = b.getChannelData(1);
        const buf = new DataView(new ArrayBuffer(44 + n * 4)), w = (o, s) => [...s].forEach((c, i) => buf.setUint8(o + i, c.charCodeAt(0)));
        w(0, "RIFF"); buf.setUint32(4, 36 + n * 4, true); w(8, "WAVEfmt "); buf.setUint32(16, 16, true); buf.setUint16(20, 1, true); buf.setUint16(22, 2, true);
        buf.setUint32(24, 44100, true); buf.setUint32(28, 44100 * 4, true); buf.setUint16(32, 4, true); buf.setUint16(34, 16, true); w(36, "data"); buf.setUint32(40, n * 4, true);
        for (let i = 0; i < n; i++) { buf.setInt16(44 + i * 4, clamp(L[i], -1, 1) * 32767, true); buf.setInt16(46 + i * 4, clamp(Rr[i], -1, 1) * 32767, true); }
        let s = ""; const u8 = new Uint8Array(buf.buffer); for (let i = 0; i < u8.length; i += 32768) s += String.fromCharCode.apply(null, u8.subarray(i, i + 32768));
        return btoa(s);
      };
      window.__total = TOTAL;
    } else requestAnimationFrame(loop);
    </script>
    </body>
    </html>
    

    result, 1 line

    File created successfully at: ~/showcase-r2-V8kQA2HZ/run/claude.html (file state is current in your context — no need to Read it back)