Strike Match

A dark room where you strike a match across the box with a fast swipe to light the screen. Hold the flame near the wick to unlock the scene and enter.

Drag the match quickly across the striker strip to ignite it, then hold the flame on the wick to unlock.

Download

What you can change

Change a number, save, and reload the page to see the difference.

STRIKE1.1

Head speed in px/ms needed to light the match. Lower is easier.

DARK0.94

How dark the room is before the fire.

REACH300

Radius of the match light, in pixels.

WICK_HOLD220

How long the flame must touch the wick, in ms.

Add it to your site

Use on teaser pages, secret drops, event invites or atmospheric entry gates.

  1. CSS

    Paste into your stylesheet, or inside a <style> tag in <head>.

    /* Strike Match by @codinvisual · t.me/CodinVisual · page shell, only while this file is the whole page */
  2. HTML

    Put it where the effect should appear on your page.

    <!-- stage start -->
    <div class="smt">
      <canvas class="smt-bg" aria-hidden="true"></canvas>
      <article class="smt-card" aria-label="Private invite">
        <p class="smt-kick">Private table</p>
        <h1 class="smt-h">Come in from the dark</h1>
        <p class="smt-p">Twelve seats, one long table and a menu we never print. Your seat is held until midnight.</p>
        <div class="smt-row">
          <span class="smt-wick" aria-hidden="true"><i class="cup"></i><i class="wax"></i><i class="thread"></i></span>
          <div class="smt-when"><b>Friday, 10 pm</b><span>Seat 7</span></div>
          <button class="smt-btn" type="button" aria-disabled="true">
            <svg class="smt-lock" viewBox="0 0 16 16" aria-hidden="true">
              <path class="shackle" d="M5 7V5.2a3 3 0 0 1 6 0V7" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"></path>
              <rect x="3" y="7" width="10" height="7.5" rx="2" fill="currentColor"></rect>
            </svg>
            <span class="smt-labels"><span class="a">Light to unlock</span><span class="b">Enter</span></span>
          </button>
        </div>
      </article>
      <canvas class="smt-obj" aria-hidden="true"></canvas>
      <canvas class="smt-dark" aria-hidden="true"></canvas>
      <canvas class="smt-fx" aria-hidden="true"></canvas>
      <canvas class="smt-gl" aria-hidden="true"></canvas>
      <div class="smt-haze" aria-hidden="true"></div>
      <div class="smt-grain" aria-hidden="true"></div>
      <button class="smt-match" type="button" aria-label="Match. Drag it fast along the side of the box to strike it, or press Enter."></button>
      <p class="smt-hint" aria-live="polite">Grab the match and strike it fast along the side of the box</p>
    </div>
    <!-- stage end -->
  3. JavaScript

    Paste right before the closing </body> tag, inside <script></script>.

    /* Strike Match by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
    const STRIKE = 1.1;
    const DARK = 0.94;
    const REACH = 300;
    const WICK_HOLD = 220;
    const SOUND = true;
    const ENTER_URL = '';
    
    const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
    const root = document.querySelector('.smt');
    const cvBg = root.querySelector('.smt-bg'), cvObj = root.querySelector('.smt-obj'), cvDark = root.querySelector('.smt-dark');
    const cvFx = root.querySelector('.smt-fx'), cvGl = root.querySelector('.smt-gl');
    const g0 = cvBg.getContext('2d'), g1 = cvObj.getContext('2d'), g2 = cvDark.getContext('2d'), g3 = cvFx.getContext('2d');
    const card = root.querySelector('.smt-card'), title = root.querySelector('.smt-h'), btn = root.querySelector('.smt-btn');
    const wickEl = root.querySelector('.smt-wick'), hintEl = root.querySelector('.smt-hint'), grip = root.querySelector('.smt-match');
    const haze = root.querySelector('.smt-haze'), grain = root.querySelector('.smt-grain');
    
    const clamp = (v, a = 0, b = 1) => v < a ? a : v > b ? b : v;
    const lerp = (a, b, k) => a + (b - a) * k;
    const eout = (k) => 1 - Math.pow(1 - clamp(k), 3);
    const rnd = (a, b) => a + Math.random() * (b - a);
    const OFF = 5000;
    
    let W = 0, H = 0, dpr = 1, T = performance.now(), lastT = T, raf = 0;
    const box = { x: 0, y: 0, w: 212, h: 124, d: 24 };
    /* the match: (x, y) is the tail, a is the angle toward the head, z is the height above the table */
    const M = { x: 0, y: 0, a: -0.13, va: 0, z: 3, len: 122, held: false, grab: 60, base: 0,
    lit: false, used: false, litAt: 0, outAt: 0, outSize: 0, charLen: 0, lean: 0, vlean: 0, touched: false };
    const P = { x: 0, y: 0, px: 0, id: 0, vx: 0 };
    let head = { x: 0, y: 0 }, prevHead = { x: 0, y: 0 }, headVx = 0, pass = null;
    let open = false, openAt = 0, wickT = 0, flash = 0, lastScratch = 0, smolderUntil = 0, revealed = false, studio = 0;
    let rects = null, floor = null, grit = null, gritCtx = null, paperPat = null;
    const sparks = [], smoke = [], ribbon = [];
    
    function noiseTile(n, lo, hi) {
    const c = document.createElement('canvas');
    c.width = c.height = n;
    const x = c.getContext('2d'), im = x.createImageData(n, n);
    for (let i = 0; i < im.data.length; i += 4) {
      const v = lo + Math.random() * (hi - lo);
      im.data[i] = im.data[i + 1] = im.data[i + 2] = v; im.data[i + 3] = 255;
    }
    x.putImageData(im, 0, 0);
    return c;
    }
    const tile = noiseTile(160, 0, 255);
    grain.style.backgroundImage = 'url(' + tile.toDataURL() + ')';
    
    function rr(g, x, y, w, h, r) { g.beginPath(); g.roundRect(x, y, w, h, r); }
    /* soft shadow without canvas filters: draw the shape far away and let its blurred shadow land in place */
    function softFill(g, path, ox, oy, blur, a) {
    if (a <= .004) return;
    g.save();
    g.shadowColor = 'rgba(0,0,0,' + a.toFixed(3) + ')';
    g.shadowBlur = blur * dpr; g.shadowOffsetX = (OFF + ox) * dpr; g.shadowOffsetY = oy * dpr;
    g.translate(-OFF, 0); path(g); g.fillStyle = '#000'; g.fill();
    g.restore();
    }
    function softLine(g, a, b, w, ox, oy, blur, al) {
    if (al <= .004) return;
    g.save();
    g.shadowColor = 'rgba(0,0,0,' + al.toFixed(3) + ')';
    g.shadowBlur = blur * dpr; g.shadowOffsetX = (OFF + ox) * dpr; g.shadowOffsetY = oy * dpr;
    g.translate(-OFF, 0); g.strokeStyle = '#000'; g.lineWidth = w; g.lineCap = 'round';
    g.beginPath(); g.moveTo(a.x, a.y); g.lineTo(b.x, b.y); g.stroke();
    g.restore();
    }
    
    /* sound, made on the fly from noise. Starts only after the first touch */
    let ac = null, noiseBuf = null;
    function audio() {
    if (!SOUND) return null;
    if (!ac) {
      const A = window.AudioContext || window.webkitAudioContext;
      if (!A) return null;
      ac = new A();
      noiseBuf = ac.createBuffer(1, ac.sampleRate, ac.sampleRate);
      const d = noiseBuf.getChannelData(0);
      for (let i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1;
    }
    if (ac.state === 'suspended') ac.resume();
    return ac;
    }
    function hiss(freq, q, gain, attack, decay, sweep) {
    const a = ac; if (!a || a.state !== 'running') return;
    const t = a.currentTime, s = a.createBufferSource(), f = a.createBiquadFilter(), g = a.createGain();
    s.buffer = noiseBuf; s.loop = true;
    f.type = 'bandpass'; f.Q.value = q; f.frequency.setValueAtTime(freq, t);
    if (sweep) f.frequency.exponentialRampToValueAtTime(sweep, t + attack + decay);
    g.gain.setValueAtTime(.0001, t);
    g.gain.exponentialRampToValueAtTime(gain, t + attack);
    g.gain.exponentialRampToValueAtTime(.0001, t + attack + decay);
    s.connect(f).connect(g).connect(a.destination);
    s.start(t, Math.random() * .5); s.stop(t + attack + decay + .05);
    }
    function tick() {
    const a = ac; if (!a || a.state !== 'running') return;
    const t = a.currentTime, o = a.createOscillator(), g = a.createGain();
    o.type = 'triangle'; o.frequency.setValueAtTime(1700, t); o.frequency.exponentialRampToValueAtTime(900, t + .08);
    g.gain.setValueAtTime(.08, t); g.gain.exponentialRampToValueAtTime(.0001, t + .12);
    o.connect(g).connect(a.destination); o.start(t); o.stop(t + .14);
    }
    
    /* the flame: a small WebGL2 shader drawn only on a bent strip around each fire */
    const VS = `#version 300 es
    in vec2 aP;
    uniform vec2 uRes, uBase, uSize;
    uniform float uLean;
    out vec2 vUv;
    void main() {
    vUv = aP;
    vec2 p = vec2((aP.x - .5) * uSize.x, (aP.y - .15) * uSize.y);
    float k = max(p.y, 0.) / uSize.y;
    p.x += uLean * uSize.y * k * k;
    vec2 pix = uBase + vec2(p.x, -p.y);
    vec2 n = pix / uRes * 2. - 1.;
    gl_Position = vec4(n.x, -n.y, 0., 1.);
    }`;
    const FS = `#version 300 es
    precision highp float;
    in vec2 vUv;
    uniform float uT, uSeed, uI, uCalm;
    out vec4 fragColor;
    float h21(vec2 p) { p = fract(p * vec2(123.34, 456.21)); p += dot(p, p + 45.32); return fract(p.x * p.y); }
    float vnoise(vec2 p) {
    vec2 i = floor(p), f = fract(p); f = f * f * (3. - 2. * f);
    return mix(mix(h21(i), h21(i + vec2(1, 0)), f.x), mix(h21(i + vec2(0, 1)), h21(i + vec2(1, 1)), f.x), f.y);
    }
    float fbm(vec2 p) { float s = 0., a = .5; for (int i = 0; i < 4; i++) { s += a * vnoise(p); p = p * 2.03 + vec2(1.7, 9.2); a *= .5; } return s; }
    void main() {
    float x = (vUv.x - .5) * 2.;
    float y = (vUv.y - .15) / .85;
    float n = fbm(vec2(x * 1.6 + uSeed, y * 2.4 - uT * 3.1));
    float m = vnoise(vec2(x * 3.5 - uSeed, y * 5. - uT * 6.3));
    x -= (n - .5) * .55 * smoothstep(0., 1., y) * (1. - uCalm * .6) + (m - .5) * .12 * y;
    float yy = y + (n - .5) * .22 * y;
    float body = .62 * pow(clamp(1. - yy, 0., 1.), .75) * smoothstep(-.2, .22, yy);
    float r = abs(x) / max(body, 1e-3);
    float a = smoothstep(1., .5, r) * smoothstep(1., .76, yy) * smoothstep(-.22, -.02, yy);
    float core = smoothstep(.75, .1, r) * smoothstep(.6, .04, yy) * smoothstep(-.14, .08, yy);
    float blue = smoothstep(.95, .35, r) * smoothstep(.2, -.02, yy) * smoothstep(-.2, 0., yy);
    vec3 col = mix(vec3(1., .3, .06), vec3(1., .62, .2), smoothstep(.95, .4, r));
    col = mix(col, vec3(1., .86, .55), core);
    col = mix(col, vec3(1., .97, .9), core * core);
    col = mix(col, vec3(.35, .55, 1.), blue * .6 * (1. - core));
    float al = clamp(a * (.8 + .2 * m) + core * .3, 0., 1.) * uI;
    al *= 1. - smoothstep(.68, 1., yy) * .55;
    fragColor = vec4(col * al * 1.12, al);
    }`;
    const gl = cvGl.getContext('webgl2', { premultipliedAlpha: true, alpha: true, antialias: false });
    let glp = null, glu = {}, glN = 0;
    if (gl) {
    const sh = (type, src) => {
      const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s);
      if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) { console.warn(gl.getShaderInfoLog(s)); return null; }
      return s;
    };
    const vs = sh(gl.VERTEX_SHADER, VS), fs = sh(gl.FRAGMENT_SHADER, FS);
    if (vs && fs) {
      glp = gl.createProgram(); gl.attachShader(glp, vs); gl.attachShader(glp, fs); gl.linkProgram(glp);
      if (!gl.getProgramParameter(glp, gl.LINK_STATUS)) glp = null;
    }
    if (glp) {
      const ROWS = 12, v = [];
      for (let r = 0; r <= ROWS; r++) v.push(0, r / ROWS, 1, r / ROWS);
      glN = v.length / 2;
      const buf = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, buf);
      gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(v), gl.STATIC_DRAW);
      const vao = gl.createVertexArray(); gl.bindVertexArray(vao);
      const loc = gl.getAttribLocation(glp, 'aP');
      gl.enableVertexAttribArray(loc); gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);
      for (const n of ['uRes', 'uBase', 'uSize', 'uLean', 'uT', 'uSeed', 'uI', 'uCalm']) glu[n] = gl.getUniformLocation(glp, n);
      gl.enable(gl.BLEND); gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
    }
    }
    function flamesBegin() {
    if (!glp) { return; }
    gl.viewport(0, 0, cvGl.width, cvGl.height);
    gl.clearColor(0, 0, 0, 0); gl.clear(gl.COLOR_BUFFER_BIT);
    }
    function drawFlame(x, y, w, h, lean, i, seed, calm) {
    if (glp) {
      gl.useProgram(glp);
      gl.uniform2f(glu.uRes, W, H); gl.uniform2f(glu.uBase, x, y); gl.uniform2f(glu.uSize, w, h);
      gl.uniform1f(glu.uLean, lean); gl.uniform1f(glu.uT, reduce ? T / 4000 : T / 1000);
      gl.uniform1f(glu.uSeed, seed); gl.uniform1f(glu.uI, i); gl.uniform1f(glu.uCalm, calm);
      gl.drawArrays(gl.TRIANGLE_STRIP, 0, glN);
      return;
    }
    /* canvas fallback: a teardrop with a hot core */
    const g = g3, tipX = x + lean * h * .7, tipY = y - h * .85;
    g.save(); g.globalCompositeOperation = 'lighter'; g.globalAlpha = clamp(i);
    const grd = g.createRadialGradient(x, y - h * .2, 1, x, y - h * .25, h * .6);
    grd.addColorStop(0, 'rgba(255,248,225,1)'); grd.addColorStop(.3, 'rgba(255,190,90,.9)'); grd.addColorStop(1, 'rgba(255,90,20,0)');
    g.fillStyle = grd; g.beginPath(); g.moveTo(tipX, tipY);
    g.bezierCurveTo(x + w * .45, y - h * .35, x + w * .3, y + h * .08, x, y + h * .08);
    g.bezierCurveTo(x - w * .3, y + h * .08, x - w * .45, y - h * .35, tipX, tipY);
    g.fill(); g.restore();
    }
    
    /* size, textures and where everything sits */
    function relRect(el) {
    const r = el.getBoundingClientRect(), o = root.getBoundingClientRect();
    return { x: r.left - o.left, y: r.top - o.top, w: r.width, h: r.height, cx: r.left - o.left + r.width / 2, cy: r.top - o.top + r.height / 2 };
    }
    function bakeFloor() {
    floor = document.createElement('canvas');
    floor.width = Math.round(W * dpr); floor.height = Math.round(H * dpr);
    const g = floor.getContext('2d'); g.setTransform(dpr, 0, 0, dpr, 0, 0);
    g.fillStyle = '#0d0a08'; g.fillRect(0, 0, W, H);
    const c = rects.card, wash = g.createRadialGradient(c.cx, c.cy + 60, 20, c.cx, c.cy + 60, Math.max(W, H) * .7);
    wash.addColorStop(0, 'rgba(78,54,34,.42)'); wash.addColorStop(.5, 'rgba(40,28,18,.25)'); wash.addColorStop(1, 'rgba(0,0,0,0)');
    g.fillStyle = wash; g.fillRect(0, 0, W, H);
    g.globalAlpha = .045; g.fillStyle = g.createPattern(tile, 'repeat'); g.fillRect(0, 0, W, H); g.globalAlpha = 1;
    }
    function bakeBox() {
    grit = document.createElement('canvas');
    grit.width = Math.round(box.w * 2); grit.height = Math.round(box.d * 2);
    gritCtx = grit.getContext('2d'); const g = gritCtx; g.scale(2, 2);
    const base = g.createLinearGradient(0, 0, 0, box.d);
    base.addColorStop(0, '#3e2c25'); base.addColorStop(1, '#251a16');
    g.fillStyle = base; g.fillRect(0, 0, box.w, box.d);
    for (let i = 0; i < box.w * box.d * 1.1; i++) {
      const lt = Math.random() < .55;
      g.fillStyle = lt ? 'rgba(170,140,118,' + rnd(.08, .35).toFixed(2) + ')' : 'rgba(0,0,0,' + rnd(.2, .5).toFixed(2) + ')';
      const s = rnd(.4, 1.2); g.fillRect(rnd(0, box.w), rnd(0, box.d), s, s);
    }
    paperPat = g1.createPattern(tile, 'repeat');
    }
    function layout() {
    const r = root.getBoundingClientRect();
    W = r.width; H = r.height; dpr = Math.min(2, devicePixelRatio || 1);
    for (const c of [cvBg, cvObj, cvDark, cvFx, cvGl]) { c.width = Math.round(W * dpr); c.height = Math.round(H * dpr); }
    box.w = W < 420 ? 196 : 212;
    const ch = card.offsetHeight, gap = Math.min(84, Math.max(52, H * .07));
    const total = ch + gap + box.h + box.d + 50;
    const top = Math.max(20, (H - total) / 2);
    card.style.top = (top + ch / 2) + 'px';
    box.x = Math.round(W / 2 - box.w / 2 - 6); box.y = Math.round(top + ch + gap);
    hintEl.style.top = (box.y + box.h + box.d + 22) + 'px';
    rects = { card: relRect(card), title: relRect(title), btn: relRect(btn), wick: relRect(wickEl) };
    rects.wickP = { x: rects.wick.cx + 1, y: rects.wick.y + rects.wick.h - 26 };
    if (!M.touched) { M.x = box.x + 30; M.y = box.y + box.h * .8; M.a = -0.13; }
    bakeFloor(); bakeBox();
    wake();
    }
    
    /* the box: oxblood sleeve, rough striker on the front side, tray pushed out a little */
    function drawBox(g) {
    const { x, y, w, h, d } = box;
    g.fillStyle = '#6f573e'; rr(g, x + w - 8, y + 9, 24, h - 18, 3); g.fill();
    g.fillStyle = '#a78a63'; rr(g, x + w - 6, y + 12, 19, h - 24, 2); g.fill();
    for (let i = 0; i < 6; i++) {
      const yy = y + 20 + i * (h - 40) / 5;
      g.fillStyle = '#d9bf93'; g.fillRect(x + w - 6, yy - 1.3, 12, 2.6);
      g.fillStyle = '#7a2219'; g.beginPath(); g.ellipse(x + w + 8.5, yy, 4.4, 3.1, 0, 0, 7); g.fill();
      g.fillStyle = 'rgba(255,170,140,.28)'; g.beginPath(); g.ellipse(x + w + 7.6, yy - 1.1, 1.7, 1, 0, 0, 7); g.fill();
    }
    g.save(); rr(g, x, y + h - 4, w, d + 4, [0, 0, 5, 5]); g.clip();
    g.drawImage(grit, x, y + h - 4, w, d + 4);
    const sd = g.createLinearGradient(0, y + h - 4, 0, y + h + d);
    sd.addColorStop(0, 'rgba(0,0,0,.55)'); sd.addColorStop(.3, 'rgba(0,0,0,0)'); sd.addColorStop(1, 'rgba(0,0,0,.35)');
    g.fillStyle = sd; g.fillRect(x, y + h - 4, w, d + 4);
    g.restore();
    g.fillStyle = 'rgba(255,215,180,.10)'; g.fillRect(x + 2, y + h + d - 1, w - 4, 1);
    const tg = g.createLinearGradient(x, y, x + w * .3, y + h);
    tg.addColorStop(0, '#64281f'); tg.addColorStop(1, '#3d1611');
    rr(g, x, y, w, h, 5); g.fillStyle = tg; g.fill();
    g.save(); g.globalAlpha = .08; g.fillStyle = paperPat; g.fill(); g.restore();
    g.strokeStyle = 'rgba(236,212,176,.36)'; g.lineWidth = 1; rr(g, x + 9.5, y + 9.5, w - 19, h - 19, 3); g.stroke();
    g.fillStyle = 'rgba(255,224,196,.16)'; g.fillRect(x + 4, y + .5, w - 8, 1);
    const ex = x + w / 2, ey = y + 34;
    g.strokeStyle = 'rgba(236,212,176,.7)'; g.lineWidth = 1.3; g.lineJoin = 'round';
    g.beginPath(); g.moveTo(ex, ey - 12);
    g.bezierCurveTo(ex + 7, ey - 4, ex + 7, ey + 5, ex, ey + 7);
    g.bezierCurveTo(ex - 7, ey + 5, ex - 7, ey - 4, ex, ey - 12); g.stroke();
    g.fillStyle = 'rgba(236,212,176,.72)'; g.font = '600 11px system-ui, sans-serif'; g.textAlign = 'center'; g.textBaseline = 'middle';
    g.fillText('Safety matches', ex, ey + 22);
    }
    function charNow() { return M.lit ? Math.min(46, 6 + (T - M.litAt) / 1000 * 1.6) : M.charLen; }
    function drawMatch(g) {
    g.save(); g.translate(M.x, M.y); g.rotate(M.a);
    const L = M.len;
    if (M.z < 12) { g.fillStyle = 'rgba(0,0,0,' + (.4 * (1 - (M.z - 3) / 9)).toFixed(3) + ')'; rr(g, 1.5, -1, L + 8, 6.5, 3); g.fill(); }
    const wood = g.createLinearGradient(0, -2.7, 0, 2.7);
    wood.addColorStop(0, '#f1d8a8'); wood.addColorStop(.45, '#d3ae76'); wood.addColorStop(1, '#957140');
    rr(g, 0, -2.6, L, 5.2, 1.4); g.fillStyle = wood; g.fill();
    g.strokeStyle = 'rgba(120,84,44,.28)'; g.lineWidth = .5;
    g.beginPath(); g.moveTo(8, -1); g.lineTo(L * .45, -1); g.moveTo(L * .3, 1.1); g.lineTo(L * .8, 1.1); g.stroke();
    const cl = charNow();
    if (cl > 0) {
      const cg = g.createLinearGradient(L - cl, 0, L, 0);
      cg.addColorStop(0, 'rgba(30,21,16,0)'); cg.addColorStop(.55, 'rgba(30,21,16,.9)'); cg.addColorStop(1, '#130e0b');
      rr(g, L - cl, -2.6, cl, 5.2, 1.2); g.fillStyle = cg; g.fill();
    }
    const burnt = M.used || M.lit;
    const hg = g.createRadialGradient(L + 1.5, -1.8, .5, L + 3, 0, 8.5);
    if (burnt) { hg.addColorStop(0, '#4d4038'); hg.addColorStop(.5, '#231b16'); hg.addColorStop(1, '#0f0b09'); }
    else { hg.addColorStop(0, '#de7a62'); hg.addColorStop(.35, '#a3352a'); hg.addColorStop(1, '#4f140e'); }
    g.beginPath(); g.ellipse(L + 3, 0, 7.6, 5.3, 0, 0, Math.PI * 2); g.fillStyle = hg; g.fill();
    g.restore();
    }
    
    /* sparks, smoke and the fire itself */
    function say(t) {
    if (hintEl.dataset.t === t) return;
    hintEl.dataset.t = t; hintEl.classList.add('swap');
    setTimeout(() => { hintEl.textContent = t; hintEl.classList.remove('swap'); }, 200);
    }
    function spark(x, y, dir, power) {
    const sp = rnd(85, 220) * (.65 + power), ang = -Math.PI / 2 + dir * rnd(.25, 1.15) + rnd(-.3, .3);
    sparks.push({ x, y, vx: Math.cos(ang) * sp, vy: Math.sin(ang) * sp, life: 0, max: rnd(.26, .52) * (.75 + power * .4) });
    }
    function puff(x, y, n, size) {
    for (let i = 0; i < n; i++) smoke.push({ x: x + rnd(-3, 3), y: y + rnd(-3, 3), vx: rnd(-8, 8), vy: rnd(-46, -26), r: size * rnd(.7, 1.2), life: 0, max: rnd(1.1, 1.9), s: rnd(0, 6) });
    }
    function markStriker(ax, ay, bx, by, hot) {
    const ox = box.x, oy = box.y + box.h;
    const cy = (v) => clamp(v - oy, 3, box.d - 3);
    gritCtx.strokeStyle = hot ? 'rgba(70,46,34,.45)' : 'rgba(14,9,7,.22)';
    gritCtx.lineWidth = hot ? 2.4 : 1.6; gritCtx.lineCap = 'round';
    gritCtx.beginPath(); gritCtx.moveTo(ax - ox, cy(ay)); gritCtx.lineTo(bx - ox, cy(by)); gritCtx.stroke();
    }
    function flameSize(now) {
    if (M.lit) {
      const t = (now - M.litAt) / 1000;
      return t < .09 ? t / .09 * 1.9 : 1 + .9 * Math.exp(-(t - .09) / .22);
    }
    if (M.outAt) {
      const t = (now - M.outAt) / 1000;
      return t < .35 ? M.outSize * (1 - eout(t / .35)) : 0;
    }
    return 0;
    }
    function flick(now) {
    if (reduce) return 1;
    const t = now / 1000;
    return 1 + .06 * Math.sin(t * 12.7) + .045 * Math.sin(t * 21.3 + 1.7) + .035 * Math.sin(t * 5.9 + .4);
    }
    function ignite(now) {
    M.lit = true; M.litAt = now; flash = 1; pass = null;
    const dir = headVx >= 0 ? 1 : -1;
    for (let i = 0; i < 14; i++) spark(head.x, head.y, dir * rnd(-.4, 1), 1.3);
    puff(head.x, head.y - 4, 3, 7);
    hiss(900, .7, .5, .01, .55, 3200); hiss(240, .9, .3, .02, .7);
    if (navigator.vibrate) navigator.vibrate(14);
    root.classList.add('is-lit');
    grip.setAttribute('aria-label', 'Burning match. Bring the flame to the wick on the card, or press Enter.');
    say('Bring the fire close to the card');
    }
    function extinguish(now) {
    M.outSize = flameSize(now); M.charLen = charNow();
    M.lit = false; M.used = true; M.outAt = now; smolderUntil = now + 4500;
    hiss(520, .6, .12, .02, .5, 180);
    root.classList.remove('is-lit');
    grip.setAttribute('aria-label', 'Burnt match');
    }
    function unlock(now) {
    if (open) return;
    open = true; openAt = now; wickT = 0;
    root.classList.add('is-open');
    btn.removeAttribute('aria-disabled');
    for (let i = 0; i < 6; i++) spark(rects.wickP.x, rects.wickP.y, rnd(-1, 1), .5);
    tick(); hiss(700, .8, .12, .01, .35, 2400);
    say('');
    root.dispatchEvent(new CustomEvent('unlock'));
    }
    function lights(now) {
    const ms = flameSize(now), fl = flick(now);
    let i = Math.min(1.15, ms) * fl;
    if (!M.lit && M.used) i = Math.max(i, .07 * clamp(1 - (now - M.outAt) / 1600));
    const Lm = { x: head.x, y: head.y - 14 * Math.max(ms, .3), i, size: ms };
    const ws = open ? eout((now - openAt) / 500) : 0;
    const Lw = { x: rects.wickP.x, y: rects.wickP.y - 12, i: .6 * ws * flick(now * 1.3 + 400) };
    return { Lm, Lw };
    }
    function lightAt(x, y, Lm) { return Lm.i * Math.pow(clamp(1 - Math.hypot(x - Lm.x, y - Lm.y) / REACH), 1.2); }
    
    /* the stroke: the head's path between two frames, checked against the striker */
    function strike(now, dtMs) {
    if (!M.held || M.lit || M.used) { pass = null; return; }
    const sx0 = box.x + 6, sx1 = box.x + box.w - 6, sy0 = box.y + box.h - 10, sy1 = box.y + box.h + box.d + 12;
    const ax = prevHead.x, ay = prevHead.y, bx = head.x, by = head.y;
    const lo = Math.max(Math.min(ax, bx), sx0), hi = Math.min(Math.max(ax, bx), sx1);
    const touch = hi > lo - .5 && Math.max(ay, by) > sy0 && Math.min(ay, by) < sy1;
    if (touch) {
      const dx = Math.max(0, hi - lo), sp = Math.hypot(bx - ax, by - ay) / Math.max(8, dtMs);
      if (!pass) pass = { d: 0, sparks: 0, top: 0, spd: 0, nextSpark: 14, nextPuff: 28 };
      pass.d += dx;
      pass.spd = pass.spd ? lerp(pass.spd, sp, .45) : sp * .65;
      pass.top = Math.max(pass.top, pass.spd);
      if (dx > .5) markStriker(ax, ay, bx, by, pass.spd > .6);
      if (pass.spd > STRIKE && pass.d > 28) { ignite(now); return; }
      if (sp > .04 && dx > .4) {
        if (now - lastScratch > 55) { lastScratch = now; hiss(1700 + sp * 1500, 1.1, Math.min(.16, .03 + sp * .11), .005, .07); }
        const cap = pass.spd > .55 ? 5 : 3;
        if (pass.sparks < cap && pass.d >= pass.nextSpark) {
          spark(bx, by, Math.sign(bx - ax) || 1, Math.max(.35, pass.spd));
          pass.sparks++;
          pass.nextSpark = pass.d + rnd(22, 38);
        }
        if (pass.d >= pass.nextPuff) {
          puff(bx, by - 3, 1, 5);
          pass.nextPuff = pass.d + rnd(36, 54);
        }
      }
    } else if (pass) {
      if (pass.d > 16) {
        puff(ax, ay - 2, 2, 4);
        say(pass.top > .55 ? 'Almost. One sharp stroke' : 'Too slow. Strike it like you mean it');
      }
      pass = null;
    }
    }
    
    /* one step of the world */
    function update(now, dtMs) {
    const dt = Math.min(.05, dtMs / 1000);
    if (M.held) {
      const vx = P.x - P.px; P.px = P.x; P.vx = lerp(P.vx, vx, .35);
      const aT = M.base + clamp(-P.vx * .018, -.3, .3);
      M.va = (M.va + (aT - M.a) * .2) * .74; M.a += M.va;
      M.x = P.x - Math.cos(M.a) * M.grab; M.y = P.y - Math.sin(M.a) * M.grab;
      M.z = lerp(M.z, 40, .25);
    } else {
      M.va *= .8; M.a += M.va; M.z = lerp(M.z, 3, .2);
      if (M.used && !reduce) {
        const rx = box.x + 26, ry = box.y + box.h * .82;
        M.x = lerp(M.x, rx, .09); M.y = lerp(M.y, ry, .09); M.a = lerp(M.a, -0.14, .09);
      }
    }
    prevHead = head;
    head = { x: M.x + Math.cos(M.a) * (M.len + 3), y: M.y + Math.sin(M.a) * (M.len + 3) };
    headVx = head.x - prevHead.x;
    strike(now, dtMs);
    const lt = clamp(-headVx * .05, -1, 1);
    M.vlean = (M.vlean + (lt - M.lean) * .15) * .8; M.lean += M.vlean;
    
    if (M.lit && !open) {
      const d = Math.hypot(head.x - rects.wickP.x, head.y - 12 - rects.wickP.y);
      wickT = d < 32 ? wickT + dtMs : Math.max(0, wickT - dtMs * 2);
      if (wickT > WICK_HOLD) unlock(now);
    }
    if (open && M.lit && now - openAt > 450) extinguish(now);
    studio = open ? eout((now - openAt - 150) / 1700) : 0;
    flash = Math.max(0, flash - dt * 6);
    
    if (M.lit && !reduce && Math.random() < dt * 2.2) {
      sparks.push({ x: head.x + rnd(-3, 3), y: head.y - 30, vx: rnd(-14, 14), vy: rnd(-70, -40), life: 0, max: rnd(.5, .9), ember: 1 });
    }
    if (M.lit && Math.random() < dt * 1.5) puff(head.x + M.lean * 30, head.y - 56, 1, 5);
    if (M.used && now < smolderUntil) {
      const k = (smolderUntil - now) / 4500;
      ribbon.push({ x: head.x, y: head.y - 2, life: 0, max: 1.5 + k * .9, s: now / 280 });
    }
    for (let i = sparks.length - 1; i >= 0; i--) {
      const s = sparks[i]; s.life += dt;
      if (s.life > s.max) { sparks.splice(i, 1); continue; }
      if (!s.ember) s.vy += 700 * dt;
      s.vx *= .985; s.x += s.vx * dt; s.y += s.vy * dt;
    }
    for (let i = smoke.length - 1; i >= 0; i--) {
      const s = smoke[i]; s.life += dt;
      if (s.life > s.max) { smoke.splice(i, 1); continue; }
      s.x += (s.vx + Math.sin(s.life * 2.4 + s.s) * 9) * dt; s.y += s.vy * dt; s.r += 9 * dt; s.vy *= .995;
    }
    for (let i = ribbon.length - 1; i >= 0; i--) {
      const p = ribbon[i]; p.life += dt;
      if (p.life > p.max) { ribbon.splice(i, 1); continue; }
      p.y -= 34 * dt; p.x += Math.sin(p.life * 2.6 + p.s) * 14 * dt;
    }
    }
    
    /* drawing, back to front */
    function drawBg(Lm) {
    const g = g0; g.setTransform(1, 0, 0, 1, 0, 0); g.drawImage(floor, 0, 0); g.setTransform(dpr, 0, 0, dpr, 0, 0);
    const boxPath = (c) => rr(c, box.x, box.y, box.w + 14, box.h + box.d, 6);
    softFill(g, boxPath, 0, 10, 26, .6);
    const hf = M.z + 34;
    if (Lm.i > .02) {
      const cx = box.x + box.w / 2, cy = box.y + (box.h + box.d) / 2;
      const k = clamp(26 / Math.max(6, hf - 26), .1, 1.6);
      let ox = (cx - Lm.x) * k, oy = (cy - Lm.y) * k; const l = Math.hypot(ox, oy);
      if (l > 140) { ox *= 140 / l; oy *= 140 / l; }
      const fall = clamp(1 - Math.hypot(cx - Lm.x, cy - Lm.y) / (REACH * 1.6));
      softFill(g, boxPath, ox, oy, 6 + Math.hypot(ox, oy) * .25, .7 * Math.min(1, Lm.i) * fall);
    }
    const tail = { x: M.x, y: M.y };
    if (M.z > 6) softLine(g, tail, head, 5, 0, M.z * .35, 2 + M.z * .4, .35);
    if (Lm.i > .02 && M.z > 6) {
      const k = clamp(M.z / (hf - M.z), .05, 1.2);
      const pj = (p) => ({ x: p.x + (p.x - Lm.x) * k, y: p.y + (p.y - Lm.y) * k });
      softLine(g, pj(tail), pj(head), 5 + k * 3, 0, 0, 2 + k * 10, .55 * Math.min(1, Lm.i));
    }
    }
    function drawObj() {
    const g = g1; g.setTransform(dpr, 0, 0, dpr, 0, 0); g.clearRect(0, 0, W, H);
    drawBox(g); drawMatch(g);
    }
    function hole(g, x, y, r, a) {
    const h = g.createRadialGradient(x, y, 0, x, y, r);
    h.addColorStop(0, 'rgba(0,0,0,' + a + ')'); h.addColorStop(.45, 'rgba(0,0,0,' + a * .9 + ')'); h.addColorStop(1, 'rgba(0,0,0,0)');
    g.fillStyle = h; g.fillRect(x - r, y - r, r * 2, r * 2);
    }
    function warm(g, x, y, r, a) {
    const h = g.createRadialGradient(x, y, 0, x, y, r);
    h.addColorStop(0, 'rgba(255,150,70,' + a + ')'); h.addColorStop(1, 'rgba(255,150,70,0)');
    g.fillStyle = h; g.fillRect(x - r, y - r, r * 2, r * 2);
    }
    function drawDark(Lm, Lw) {
    const g = g2; g.setTransform(dpr, 0, 0, dpr, 0, 0);
    g.globalCompositeOperation = 'source-over'; g.clearRect(0, 0, W, H);
    g.fillStyle = 'rgba(9,7,6,' + (DARK * (1 - .9 * studio)).toFixed(3) + ')'; g.fillRect(0, 0, W, H);
    g.globalCompositeOperation = 'destination-out';
    hole(g, box.x + box.w / 2, box.y + box.h / 2, 230, .42 * (1 - studio));
    if (Lm.i > .01) hole(g, Lm.x, Lm.y, REACH * (.8 + .2 * clamp(Lm.i)), clamp(Lm.i));
    if (Lw.i > .01) hole(g, Lw.x, Lw.y, 170, .85 * Lw.i);
    g.globalCompositeOperation = 'lighter';
    if (Lm.i > .01) warm(g, Lm.x, Lm.y, REACH * 1.1, .14 * Lm.i);
    if (Lw.i > .01) warm(g, Lw.x, Lw.y, 200, .12 * Lw.i);
    if (studio > 0) {
      const s = g.createLinearGradient(0, 0, 0, H);
      s.addColorStop(0, 'rgba(255,170,100,' + (.08 * studio) + ')'); s.addColorStop(1, 'rgba(255,170,100,0)');
      g.fillStyle = s; g.fillRect(0, 0, W, H);
    }
    g.globalCompositeOperation = 'source-over';
    }
    
    function drawFx(Lm, Lw) {
    const g = g3; g.setTransform(dpr, 0, 0, dpr, 0, 0); g.clearRect(0, 0, W, H);
    g.globalCompositeOperation = 'lighter';
    const glow = (x, y, r, rgb, a) => {
      if (a <= .004) return;
      const h = g.createRadialGradient(x, y, 0, x, y, r);
      h.addColorStop(0, 'rgba(' + rgb + ',' + a + ')'); h.addColorStop(1, 'rgba(' + rgb + ',0)');
      g.fillStyle = h; g.fillRect(x - r, y - r, r * 2, r * 2);
    };
    if (Lm.size > .01) {
      glow(Lm.x, Lm.y - 6, 110, '255,170,90', .26 * Lm.i);
      glow(Lm.x, Lm.y, 28, '255,220,160', .35 * Lm.i);
      glow(head.x, head.y, 9, '255,140,60', .7 * clamp(Lm.size));
    }
    if (flash > 0) glow(head.x, head.y - 8, 170 * (1.2 - flash * .4), '255,236,190', .75 * flash);
    if (M.used && !M.lit) glow(head.x, head.y, 7, '255,110,40', .85 * clamp(1 - (T - M.outAt) / 1600));
    if (Lw.i > .01) glow(Lw.x, Lw.y - 4, 70, '255,170,90', .3 * Lw.i);
    g.lineCap = 'round';
    for (const s of sparks) {
      const k = s.life / s.max, a = (1 - k) * (s.ember ? .8 : 1);
      if (s.ember) { glow(s.x, s.y, 2.6, '255,170,80', a); continue; }
      g.strokeStyle = k < .3 ? 'rgba(255,244,200,' + a + ')' : k < .65 ? 'rgba(255,180,80,' + a + ')' : 'rgba(255,100,30,' + a + ')';
      g.lineWidth = 1.5 * (1 - k * .5);
      g.beginPath(); g.moveTo(s.x, s.y); g.lineTo(s.x - s.vx * .02, s.y - s.vy * .02); g.stroke();
    }
    g.globalCompositeOperation = 'source-over';
    for (const s of smoke) {
      const k = s.life / s.max, b = .25 + .75 * Math.max(lightAt(s.x, s.y, Lm), studio);
      const c = Math.round(lerp(60, 205, clamp(b))), a = .13 * Math.sin(Math.PI * k) * (.5 + .5 * b);
      const h = g.createRadialGradient(s.x, s.y, 0, s.x, s.y, s.r);
      h.addColorStop(0, 'rgba(' + c + ',' + Math.round(c * .95) + ',' + Math.round(c * .9) + ',' + a.toFixed(3) + ')');
      h.addColorStop(1, 'rgba(' + c + ',' + c + ',' + c + ',0)');
      g.fillStyle = h; g.fillRect(s.x - s.r, s.y - s.r, s.r * 2, s.r * 2);
    }
    if (ribbon.length > 1) {
      g.lineCap = 'round';
      for (let i = 1; i < ribbon.length; i++) {
        const p = ribbon[i - 1], q = ribbon[i];
        if (Math.hypot(q.x - p.x, q.y - p.y) > 28) continue;
        const k = q.life / q.max, a = .42 * Math.sin(Math.PI * clamp(k * 1.15)) * (1 - k * .65);
        if (a <= .005) continue;
        g.strokeStyle = 'rgba(220,212,202,' + (a * .35).toFixed(3) + ')';
        g.lineWidth = 4 + k * 5;
        g.beginPath(); g.moveTo(p.x, p.y); g.lineTo(q.x, q.y); g.stroke();
        g.strokeStyle = 'rgba(235,228,218,' + a.toFixed(3) + ')';
        g.lineWidth = 1.3 + k * .8;
        g.beginPath(); g.moveTo(p.x, p.y); g.lineTo(q.x, q.y); g.stroke();
      }
    }
    }
    function drawGl(Lm, Lw) {
    flamesBegin();
    if (Lm.size > .01) {
      const st = Math.min(.6, Math.abs(headVx) * .04);
      const s = Lm.size * (reduce ? 1 : flick(T * 1.7));
      drawFlame(head.x, head.y - 1, 34 * s * (1 - st * .3), 74 * s * (1 + st * .5), M.lean, clamp(.9 * flick(T)), 1.3, 0);
    }
    if (Lw.i > .01) drawFlame(rects.wickP.x, rects.wickP.y + 2, 20, 42 * (.85 + .15 * Lw.i / .6), Math.sin(T / 900) * .08, clamp(Lw.i / .6), 7.1, .6);
    }
    
    /* light and shadow on the real card */
    const css = (ox, oy, blur, spread, a) => ox.toFixed(1) + 'px ' + oy.toFixed(1) + 'px ' + blur.toFixed(1) + 'px ' + spread.toFixed(1) + 'px rgba(0,0,0,' + a.toFixed(3) + ')';
    function cast(c, z, L, hf) {
    const k = clamp(z / Math.max(8, hf - z), 0, 1);
    let ox = (c.x - L.x) * k, oy = (c.y - L.y) * k; const l = Math.hypot(ox, oy);
    if (l > 70) { ox *= 70 / l; oy *= 70 / l; }
    const fall = clamp(1 - Math.hypot(c.x - L.x, c.y - L.y) / (REACH * 1.5));
    return { ox, oy, blur: 6 + Math.hypot(ox, oy) * .7, a: Math.min(1, L.i) * fall };
    }
    function shade(Lm, Lw) {
    const cr = rects.card, hf = M.z + 34;
    const nx = clamp(Lm.x, cr.x, cr.x + cr.w), ny = clamp(Lm.y, cr.y, cr.y + cr.h);
    const near = Lm.i * clamp(1 - Math.hypot(Lm.x - nx, Lm.y - ny) / REACH);
    const L = near > Lw.i * .8 ? Lm : Lw;
    card.style.setProperty('--lx', (L.i > .01 ? L.x - cr.x : cr.w / 2).toFixed(1) + 'px');
    card.style.setProperty('--ly', (L.i > .01 ? L.y - cr.y : -cr.h * .6).toFixed(1) + 'px');
    card.style.setProperty('--li', clamp(near + Lw.i * .8 + studio * .25, 0, 1.2).toFixed(3));
    const parts = ['0 24px 50px -28px rgba(0,0,0,.85)'];
    if (Lm.i > .02) { const c = cast({ x: cr.cx, y: cr.cy }, 16, Lm, hf); parts.push(css(c.ox, c.oy, c.blur, 3, .84 * c.a)); }
    if (studio > 0) parts.push('0 46px 80px -24px rgba(0,0,0,' + (.55 * studio).toFixed(3) + ')', '0 0 0 1px rgba(255,200,140,' + (.1 * studio).toFixed(3) + ')');
    parts.push('inset 0 1px 0 rgba(255,236,210,.06)');
    card.style.boxShadow = parts.join(',');
    const ts = [];
    if (Lm.i > .02) { const c = cast({ x: rects.title.cx, y: rects.title.cy }, 5, Lm, hf); ts.push(css(c.ox, c.oy, 2 + Math.hypot(c.ox, c.oy) * .3, 0, .85 * c.a).replace(' 0.0px rgba', ' rgba')); }
    if (Lw.i > .01) { const c = cast({ x: rects.title.cx, y: rects.title.cy }, 3, Lw, 30); ts.push(css(c.ox, c.oy, 3, 0, .5 * c.a).replace(' 0.0px rgba', ' rgba')); }
    title.style.textShadow = ts.join(',');
    const bc = { x: rects.btn.cx, y: rects.btn.cy };
    const bs = [];
    if (Lm.i > .02) { const c = cast(bc, 6, Lm, hf); bs.push(css(c.ox, c.oy, c.blur * .6, 0, .7 * c.a)); }
    if (Lw.i > .01) { const c = cast(bc, 4, Lw, 30); bs.push(css(c.ox, c.oy, 6, 0, .45 * c.a)); }
    if (open) bs.push('inset 0 1px 0 rgba(255,248,232,.45)');
    btn.style.boxShadow = bs.join(',') || 'none';
    const wc = cast({ x: rects.wick.cx, y: rects.wick.cy }, 8, Lm, hf);
    wickEl.style.filter = Lm.i > .02 ? 'drop-shadow(' + wc.ox.toFixed(1) + 'px ' + wc.oy.toFixed(1) + 'px 3px rgba(0,0,0,' + (.8 * wc.a).toFixed(3) + '))' : '';
    const rv = open ? 1 : clamp(Lm.i * clamp(1 - Math.hypot(Lm.x - bc.x, Lm.y - bc.y) / (REACH * .75)) * 1.6);
    btn.style.setProperty('--rv', rv.toFixed(3));
    const can = open || (M.lit && rv > .3);
    if (can !== revealed) {
      revealed = can;
      if (can) btn.removeAttribute('aria-disabled'); else btn.setAttribute('aria-disabled', 'true');
      if (can && !open) say('Touch the wick with the flame, or press the lock');
    }
    }
    
    /* sync invisible grab handle & heat haze, then run the frame loop */
    function syncUi(Lm) {
    const mx = M.x + Math.cos(M.a) * (M.len / 2);
    const my = M.y + Math.sin(M.a) * (M.len / 2);
    grip.style.width = (M.len + 28) + 'px';
    grip.style.transform = 'translate3d(' + (mx - (M.len + 28) / 2).toFixed(1) + 'px,' + my.toFixed(1) + 'px,0) rotate(' + M.a.toFixed(4) + 'rad)';
    if (!reduce && Lm.size > .08) {
      haze.style.opacity = clamp(Lm.i * .85).toFixed(3);
      haze.style.transform = 'translate3d(' + (head.x + M.lean * 22).toFixed(1) + 'px,' + (head.y - 68 * Lm.size).toFixed(1) + 'px,0)';
    } else {
      haze.style.opacity = '0';
    }
    }
    
    function isLive(now) {
    if (M.held || M.lit || open || flash > 0) return true;
    if (sparks.length || smoke.length || ribbon.length) return true;
    if (Math.abs(M.va) > .001 || Math.abs(M.vlean) > .001 || M.z > 3.2) return true;
    if (M.outAt && now - M.outAt < 2800) return true;
    return false;
    }
    
    function wake() {
    if (!raf) { raf = requestAnimationFrame(frame); }
    }
    
    function frame(now) {
    raf = 0;
    const dtMs = clamp(now - lastT, 8, 50);
    T = now;
    lastT = now;
    update(now, dtMs);
    const { Lm, Lw } = lights(now);
    drawBg(Lm);
    drawObj();
    drawDark(Lm, Lw);
    drawFx(Lm, Lw);
    drawGl(Lm, Lw);
    shade(Lm, Lw);
    syncUi(Lm);
    if (isLive(now)) raf = requestAnimationFrame(frame);
    }
    
    /* pointer & keyboard controls */
    function toStage(e) {
    const r = root.getBoundingClientRect();
    return { x: e.clientX - r.left, y: e.clientY - r.top };
    }
    
    grip.addEventListener('pointerdown', (e) => {
    if (e.button > 0 || P.id) return;
    e.preventDefault();
    audio();
    const pt = toStage(e);
    P.id = e.pointerId; P.x = P.px = pt.x; P.y = pt.y; P.vx = 0;
    const dx = pt.x - M.x, dy = pt.y - M.y;
    const proj = dx * Math.cos(M.a) + dy * Math.sin(M.a);
    M.grab = clamp(proj, 18, M.len - 18);
    M.base = M.a; M.held = true; M.touched = true;
    root.classList.add('is-holding');
    grip.setPointerCapture(e.pointerId);
    wake();
    });
    
    window.addEventListener('pointermove', (e) => {
    if (!M.held || e.pointerId !== P.id) return;
    const pt = toStage(e);
    P.x = clamp(pt.x, 12, W - 12);
    P.y = clamp(pt.y, 12, H - 12);
    wake();
    });
    
    function releaseMatch(e) {
    if (!M.held || e.pointerId !== P.id) return;
    P.id = 0; M.held = false; pass = null;
    root.classList.remove('is-holding');
    wake();
    }
    window.addEventListener('pointerup', releaseMatch);
    window.addEventListener('pointercancel', releaseMatch);
    
    grip.addEventListener('click', (e) => {
    if (e.detail !== 0) return;
    audio();
    const now = performance.now();
    M.touched = true;
    if (!M.lit && !M.used) {
      M.x = box.x + box.w * .45; M.y = box.y + box.h + box.d * .5; M.a = -0.18; M.z = 26;
      head = { x: M.x + Math.cos(M.a) * (M.len + 3), y: M.y + Math.sin(M.a) * (M.len + 3) };
      prevHead = head;
      markStriker(box.x + 28, box.y + box.h + 12, box.x + box.w - 30, box.y + box.h + 12, true);
      ignite(now);
      wake();
    } else if (M.lit && !open) {
      M.a = -0.32; M.z = 36;
      M.x = rects.wickP.x - Math.cos(M.a) * (M.len + 3);
      M.y = rects.wickP.y + 8 - Math.sin(M.a) * (M.len + 3);
      head = { x: rects.wickP.x, y: rects.wickP.y + 8 };
      prevHead = head;
      unlock(now);
      wake();
    }
    });
    
    btn.addEventListener('click', () => {
    if (btn.getAttribute('aria-disabled') === 'true') return;
    audio();
    if (!open) {
      unlock(performance.now());
      wake();
      return;
    }
    root.dispatchEvent(new CustomEvent('enter'));
    if (ENTER_URL) location.href = ENTER_URL;
    });
    
    new ResizeObserver(layout).observe(root);
    layout();

Connect it to your backend

Set ENTER_URL to redirect after unlock or listen for the custom enter event.

Good to know

Tilda, Webflow, WordPress

Press Copy all code at the top and paste it into one HTML block.

Tilda

Add block, Other, T123 HTML code. Paste and save. Check the published page, the editor preview does not run scripts.

Webflow

Add panel, Embed. Paste, then Save & Close. Custom code runs on the published site.

WordPress

Add block, Custom HTML. Paste and press Update.

More in Particles & fun

See all
Copied