Shaders JS behaviour

Plasma gradient

A shader plasma simmering behind a product intro card; four ready palettes swap on swatches and the pointer bends the flow as it crosses. Raw WebGL1 with zero libraries — it parks off screen, freezes to a still frame under reduced motion and settles into a static gradient of the same palette without WebGL.

Documentation

Real scenarios

The component as it is used in a product — not a specimen grid.

A hero that boils

The plasma is one small fragment shader on a half-resolution canvas — four sine terms phase-shifted by time, the pointer and distance. Swap the palette, bend the flow with your mouse, and watch the card stay perfectly readable on top.

Solstice 3.0 · global launch

Every launch, everywhere, at once

From Frankfurt to Singapore, your launch dashboard is live from second zero — traffic, signups and error rates on one map.

Frankfurt 12ms Dublin 18ms Singapore 23ms

Workspace ready — the welcome email is on its way.

Half-resolution canvas · pauses off screen · a still frame under reduced motion · a static gradient without WebGL.

Important props

Important props
Prop Type Default What it does
palette uniform vec3 ×3 'aurora' Four palettes (aurora, sunset, ocean, magma) of three colours each; every swatch swaps all three uniforms at once.
u_time speed '0.9 rad/s' The simmer speed; the phase of the plasma’s four sine terms rotates with time.
u_mouse uniform vec2 'eased' The pointer bends the flow; its position is chased with easing and drifts back to centre once it leaves.
resolution scale '0.5×' The canvas renders at half CSS resolution and upscales — a cheap full-screen shader.
fallback state 'static gradient' Without WebGL the canvas hides and a static CSS gradient of the active palette shows instead.

Snippet

<div class="shpl" x-data="{ palette: 0 }">
<div class="shpl-stage" @pointermove="bend($event)">
<canvas class="shpl-cv" aria-hidden="true"></canvas>
<article class="shpl-card">
<small>Solstice 3.0 · global launch</small>
<h2>Every launch, everywhere, at once</h2>
<p>From Frankfurt to Singapore, your launch dashboard is live.</p>
<footer>
<button class="shpl-cta">Start free</button>
<button class="shpl-ghost">Watch the keynote</button>
</footer>
</article>
</div>
<div class="shpl-swatches" role="group" aria-label="Plasma palette">
<button aria-pressed="true">Aurora</button>
<button>Sunset</button>
<button>Ocean</button>
<button>Magma</button>
</div>
</div>

<style>
.shpl-stage { position: relative; overflow: clip; border-radius: 1.25rem; min-block-size: 24rem;
              display: grid; place-items: center; background: #1e1b4b; }
.shpl-cv { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; }
.shpl-card { position: relative; z-index: 1; inline-size: min(100%, 34rem); padding: 1.75rem;
             border-radius: 1.25rem; background: #ffffffc8; backdrop-filter: blur(14px); text-align: center; }
.shpl-swatches button[aria-pressed='true'] { outline: 2px solid #7c3aed; outline-offset: 2px; }
</style>
// app/Pages/Launch.jsx — Inertia (React) page; renders the React
// snippet below unchanged, with Inertia's Link wired into the provider.
import { Link } from '@inertiajs/react';
import { NabuXUIProvider } from '@nabuxai/ui-react';
import PlasmaHero from '@/components/PlasmaHero';

export default function Launch() {
  return (
    <NabuXUIProvider locale="en" linkComponent={Link}>
      <main className="nx-page">
        <PlasmaHero />
      </main>
    </NabuXUIProvider>
  );
}
// PlasmaHero.jsx — shader plasma behind a product card, raw WebGL1
import { useEffect, useRef, useState } from 'react';

const PALETTES = [
  { id: 'aurora', hex: ['#1e1b4b', '#7c3aed', '#f472b6'] },
  { id: 'sunset', hex: ['#431407', '#ea580c', '#fbbf24'] },
  { id: 'ocean', hex: ['#082f49', '#0891b2', '#67e8f9'] },
  { id: 'magma', hex: ['#450a0a', '#dc2626', '#f59e0b'] },
];
const FRAG = `precision mediump float;
uniform vec2 u_res; uniform float u_time; uniform vec2 u_mouse;
uniform vec3 u_a; uniform vec3 u_b; uniform vec3 u_c;
void main() {
  vec2 uv = (gl_FragCoord.xy * 2.0 - u_res) / min(u_res.x, u_res.y);
  vec2 m = u_mouse * 0.45;
  float v = sin((uv.x + m.x) * 2.6 + u_time * 0.7) + sin((uv.y - m.y) * 2.2 - u_time * 0.45)
          + sin((uv.x + uv.y) * 1.9 + u_time * 0.3) + sin(length(uv - m) * 4.2 - u_time * 0.9);
  float t = v / 8.0 + 0.5;
  vec3 col = mix(u_a, u_b, smoothstep(0.0, 0.55, t));
  col = mix(col, u_c, smoothstep(0.55, 1.0, t));
  gl_FragColor = vec4(col, 1.0);
}`;
const rgb = (h) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16) / 255);

export default function PlasmaHero() {
  const canvasRef = useRef(null);
  const stageRef = useRef(null);
  const apiRef = useRef(null); // { redraw } — set once the GL effect runs
  const live = useRef({ palette: 0, mx: 0, my: 0, tx: 0, ty: 0 });
  const [pal, setPal] = useState(0);
  const [noGl, setNoGl] = useState(false);
  const [started, setStarted] = useState(false);

  useEffect(() => { live.current.palette = pal; apiRef.current?.redraw(); }, [pal]);

  useEffect(() => {
    const canvas = canvasRef.current;
    const gl = canvas.getContext('webgl', { antialias: false, powerPreference: 'low-power' });
    if (!gl) { setNoGl(true); return; }
    const sh = (type, src) => {
      const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); return s;
    };
    const prog = gl.createProgram();
    gl.attachShader(prog, sh(gl.VERTEX_SHADER, 'attribute vec2 a; void main() { gl_Position = vec4(a, 0.0, 1.0); }'));
    gl.attachShader(prog, sh(gl.FRAGMENT_SHADER, FRAG));
    gl.linkProgram(prog); gl.useProgram(prog);
    gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
    const a = gl.getAttribLocation(prog, 'a');
    gl.enableVertexAttribArray(a); gl.vertexAttribPointer(a, 2, gl.FLOAT, false, 0, 0);
    const U = {};
    for (const n of ['u_res', 'u_time', 'u_mouse', 'u_a', 'u_b', 'u_c']) U[n] = gl.getUniformLocation(prog, n);

    const mq = matchMedia('(prefers-reduced-motion: reduce)');
    const s = { raf: 0, visible: true, t0: performance.now(), last: 1 };
    const size = () => { // half resolution keeps the full-screen shader cheap
      canvas.width = Math.max(2, Math.round(canvas.clientWidth * 0.5));
      canvas.height = Math.max(2, Math.round(canvas.clientHeight * 0.5));
    };
    const draw = (t) => {
      const L = live.current;
      L.mx += (L.tx - L.mx) * 0.07; L.my += (L.ty - L.my) * 0.07; // the pointer eases through the flow
      gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
      gl.uniform2f(U.u_res, gl.drawingBufferWidth, gl.drawingBufferHeight);
      gl.uniform1f(U.u_time, t); gl.uniform2f(U.u_mouse, L.mx, L.my);
      const hex = PALETTES[L.palette].hex;
      gl.uniform3f(U.u_a, ...rgb(hex[0])); gl.uniform3f(U.u_b, ...rgb(hex[1])); gl.uniform3f(U.u_c, ...rgb(hex[2]));
      gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
    };
    const redraw = () => draw(mq.matches ? 4.2 : s.last); // still frame under reduced motion
    const run = () => {
      cancelAnimationFrame(s.raf);
      if (!s.visible) return;            // parked while off screen
      if (mq.matches) { redraw(); return; }
      const loop = (now) => { s.last = (now - s.t0) / 1000; draw(s.last); s.raf = requestAnimationFrame(loop); };
      s.raf = requestAnimationFrame(loop);
    };
    apiRef.current = { redraw };

    const io = new IntersectionObserver(([e]) => { s.visible = e.isIntersecting; run(); });
    io.observe(canvas);
    const ro = new ResizeObserver(() => { size(); redraw(); });
    ro.observe(canvas);
    const onMove = (e) => {
      const r = stageRef.current.getBoundingClientRect();
      live.current.tx = ((e.clientX - r.left) / r.width) * 2 - 1;
      live.current.ty = 1 - ((e.clientY - r.top) / r.height) * 2;
    };
    stageRef.current.addEventListener('pointermove', onMove);
    size(); run();

    return () => { // full cleanup — context included
      cancelAnimationFrame(s.raf); io.disconnect(); ro.disconnect();
      stageRef.current?.removeEventListener('pointermove', onMove);
      apiRef.current = null;
      gl.getExtension('WEBGL_lose_context')?.loseContext();
    };
  }, []);

  return (
    <>
      <style>{`
        .shpl-stage { position: relative; overflow: clip; border-radius: 1.25rem; min-block-size: 24rem;
                      display: grid; place-items: center; background: #1e1b4b; }
        .shpl-cv, .shpl-fallback { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; }
        .shpl-card { position: relative; z-index: 1; inline-size: min(100%, 34rem); margin: 2rem 1.25rem; padding: 1.75rem;
                     border-radius: 1.25rem; background: rgba(255, 255, 255, .8); backdrop-filter: blur(14px);
                     text-align: center; }
        .shpl-cta { block-size: 2.75rem; padding-inline: 1.5rem; border: none; border-radius: 999px;
                    background: #4f46e5; color: #fff; font: 600 .9rem system-ui; cursor: pointer; }
        .shpl-swatches { display: flex; gap: .75rem; justify-content: center; margin-block-start: 1rem; }
        .shpl-swatches button { inline-size: 2.5rem; block-size: 2.5rem; border-radius: 50%; cursor: pointer; }
        .shpl-swatches button[aria-pressed='true'] { outline: 2px solid #4f46e5; outline-offset: 3px; }
      `}</style>
      <div className="shpl-stage" ref={stageRef} onPointerMove={(e) => e.stopPropagation()}>
        {noGl
          ? <div className="shpl-fallback" style={{ background: `linear-gradient(135deg, ${PALETTES[pal].hex.join(', ')})` }} />
          : <canvas ref={canvasRef} className="shpl-cv" aria-hidden="true" />}
        <article className="shpl-card">
          <small>Solstice 3.0 · global launch</small>
          <h2>Every launch, everywhere, at once</h2>
          <p>Frankfurt 12ms · Dublin 18ms · Singapore 23ms — the dashboard is live from second zero.</p>
          <footer>
            <button type="button" className="shpl-cta" onClick={() => setStarted(true)}>Start free</button>
            {started && <p role="status">Workspace ready — the welcome email is on its way.</p>}
          </footer>
        </article>
      </div>
      <div className="shpl-swatches" role="group" aria-label="Plasma palette">
        {PALETTES.map((p, i) => (
          <button key={p.id} type="button" aria-pressed={pal === i} aria-label={p.id}
            onClick={() => setPal(i)}
            style={{ background: `linear-gradient(135deg, ${p.hex.join(', ')})` }} />
        ))}
      </div>
    </>
  );
}
<!-- PlasmaHero.vue — shader plasma behind a product card, raw WebGL1 -->
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from 'vue';

const PALETTES = [
  { id: 'aurora', hex: ['#1e1b4b', '#7c3aed', '#f472b6'] },
  { id: 'sunset', hex: ['#431407', '#ea580c', '#fbbf24'] },
  { id: 'ocean', hex: ['#082f49', '#0891b2', '#67e8f9'] },
  { id: 'magma', hex: ['#450a0a', '#dc2626', '#f59e0b'] },
];
const FRAG = `precision mediump float;
uniform vec2 u_res; uniform float u_time; uniform vec2 u_mouse;
uniform vec3 u_a; uniform vec3 u_b; uniform vec3 u_c;
void main() {
  vec2 uv = (gl_FragCoord.xy * 2.0 - u_res) / min(u_res.x, u_res.y);
  vec2 m = u_mouse * 0.45;
  float v = sin((uv.x + m.x) * 2.6 + u_time * 0.7) + sin((uv.y - m.y) * 2.2 - u_time * 0.45)
          + sin((uv.x + uv.y) * 1.9 + u_time * 0.3) + sin(length(uv - m) * 4.2 - u_time * 0.9);
  float t = v / 8.0 + 0.5;
  vec3 col = mix(u_a, u_b, smoothstep(0.0, 0.55, t));
  col = mix(col, u_c, smoothstep(0.55, 1.0, t));
  gl_FragColor = vec4(col, 1.0);
}`;
const rgb = (h: string) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16) / 255);

const canvas = ref<HTMLCanvasElement | null>(null);
const stage = ref<HTMLElement | null>(null);
const pal = ref(0);
const noGl = ref(false);
const started = ref(false);
let stop: (() => void) | null = null;

onMounted(() => {
  const cv = canvas.value!;
  const gl = cv.getContext('webgl', { antialias: false, powerPreference: 'low-power' });
  if (!gl) { noGl.value = true; return; }
  const sh = (type: number, src: string) => {
    const s = gl.createShader(type)!; gl.shaderSource(s, src); gl.compileShader(s); return s;
  };
  const prog = gl.createProgram()!;
  gl.attachShader(prog, sh(gl.VERTEX_SHADER, 'attribute vec2 a; void main() { gl_Position = vec4(a, 0.0, 1.0); }'));
  gl.attachShader(prog, sh(gl.FRAGMENT_SHADER, FRAG));
  gl.linkProgram(prog); gl.useProgram(prog);
  gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
  const a = gl.getAttribLocation(prog, 'a');
  gl.enableVertexAttribArray(a); gl.vertexAttribPointer(a, 2, gl.FLOAT, false, 0, 0);
  const U: Record<string, WebGLUniformLocation | null> = {};
  for (const n of ['u_res', 'u_time', 'u_mouse', 'u_a', 'u_b', 'u_c']) U[n] = gl.getUniformLocation(prog, n);

  const mq = matchMedia('(prefers-reduced-motion: reduce)');
  const live = { mx: 0, my: 0, tx: 0, ty: 0 };
  let raf = 0, visible = true, last = 1;
  const t0 = performance.now();
  const size = () => { // half resolution keeps the full-screen shader cheap
    cv.width = Math.max(2, Math.round(cv.clientWidth * 0.5));
    cv.height = Math.max(2, Math.round(cv.clientHeight * 0.5));
  };
  const draw = (t: number) => {
    live.mx += (live.tx - live.mx) * 0.07; live.my += (live.ty - live.my) * 0.07; // eased pointer
    gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
    gl.uniform2f(U.u_res, gl.drawingBufferWidth, gl.drawingBufferHeight);
    gl.uniform1f(U.u_time!, t); gl.uniform2f(U.u_mouse!, live.mx, live.my);
    const hex = PALETTES[pal.value].hex;
    gl.uniform3f(U.u_a!, ...rgb(hex[0])); gl.uniform3f(U.u_b!, ...rgb(hex[1])); gl.uniform3f(U.u_c!, ...rgb(hex[2]));
    gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
  };
  const redraw = () => draw(mq.matches ? 4.2 : last); // still frame under reduced motion
  const run = () => {
    cancelAnimationFrame(raf);
    if (!visible) return;            // parked while off screen
    if (mq.matches) { redraw(); return; }
    const loop = (now: number) => { last = (now - t0) / 1000; draw(last); raf = requestAnimationFrame(loop); };
    raf = requestAnimationFrame(loop);
  };

  const io = new IntersectionObserver(([e]) => { visible = e.isIntersecting; run(); });
  io.observe(cv);
  const ro = new ResizeObserver(() => { size(); redraw(); });
  ro.observe(cv);
  const onMove = (e: PointerEvent) => {
    const r = stage.value!.getBoundingClientRect();
    live.tx = ((e.clientX - r.left) / r.width) * 2 - 1;
    live.ty = 1 - ((e.clientY - r.top) / r.height) * 2;
  };
  stage.value!.addEventListener('pointermove', onMove);
  size(); run();

  stop = () => { // full cleanup — context included
    cancelAnimationFrame(raf); io.disconnect(); ro.disconnect();
    stage.value?.removeEventListener('pointermove', onMove);
    gl.getExtension('WEBGL_lose_context')?.loseContext();
  };
});
onBeforeUnmount(() => stop?.());
</script>

<template>
  <div class="shpl-stage" ref="stage">
    <div v-if="noGl" class="shpl-fallback"
         :style="{ background: 'linear-gradient(135deg, ' + PALETTES[pal].hex.join(', ') + ')' }"></div>
    <canvas v-else ref="canvas" class="shpl-cv" aria-hidden="true"></canvas>
    <article class="shpl-card">
      <small>Solstice 3.0 · global launch</small>
      <h2>Every launch, everywhere, at once</h2>
      <p>Frankfurt 12ms · Dublin 18ms · Singapore 23ms — the dashboard is live from second zero.</p>
      <footer>
        <button type="button" class="shpl-cta" @click="started = true">Start free</button>
        <p v-if="started" role="status">Workspace ready — the welcome email is on its way.</p>
      </footer>
    </article>
  </div>
  <div class="shpl-swatches" role="group" aria-label="Plasma palette">
    <button v-for="(p, i) in PALETTES" :key="p.id" type="button" :aria-pressed="pal === i"
            :aria-label="p.id" @click="pal = i"
            :style="{ background: 'linear-gradient(135deg, ' + p.hex.join(', ') + ')' }"></button>
  </div>
</template>

<style scoped>
.shpl-stage { position: relative; overflow: clip; border-radius: 1.25rem; min-block-size: 24rem;
              display: grid; place-items: center; background: #1e1b4b; }
.shpl-cv, .shpl-fallback { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; }
.shpl-card { position: relative; z-index: 1; inline-size: min(100%, 34rem); margin: 2rem 1.25rem; padding: 1.75rem;
             border-radius: 1.25rem; background: rgba(255, 255, 255, .8); backdrop-filter: blur(14px); text-align: center; }
.shpl-cta { block-size: 2.75rem; padding-inline: 1.5rem; border: none; border-radius: 999px;
            background: #4f46e5; color: #fff; font: 600 .9rem system-ui; cursor: pointer; }
.shpl-swatches { display: flex; gap: .75rem; justify-content: center; margin-block-start: 1rem; }
.shpl-swatches button { inline-size: 2.5rem; block-size: 2.5rem; border-radius: 50%; cursor: pointer; }
.shpl-swatches button[aria-pressed='true'] { outline: 2px solid #4f46e5; outline-offset: 3px; }
</style>
<!-- PlasmaHero.svelte — shader plasma behind a product card, raw WebGL1 -->
<script lang="ts">
  import { onMount } from 'svelte';

  const PALETTES = [
    { id: 'aurora', hex: ['#1e1b4b', '#7c3aed', '#f472b6'] },
    { id: 'sunset', hex: ['#431407', '#ea580c', '#fbbf24'] },
    { id: 'ocean', hex: ['#082f49', '#0891b2', '#67e8f9'] },
    { id: 'magma', hex: ['#450a0a', '#dc2626', '#f59e0b'] },
  ];
  const FRAG = `precision mediump float;
  uniform vec2 u_res; uniform float u_time; uniform vec2 u_mouse;
  uniform vec3 u_a; uniform vec3 u_b; uniform vec3 u_c;
  void main() {
    vec2 uv = (gl_FragCoord.xy * 2.0 - u_res) / min(u_res.x, u_res.y);
    vec2 m = u_mouse * 0.45;
    float v = sin((uv.x + m.x) * 2.6 + u_time * 0.7) + sin((uv.y - m.y) * 2.2 - u_time * 0.45)
            + sin((uv.x + uv.y) * 1.9 + u_time * 0.3) + sin(length(uv - m) * 4.2 - u_time * 0.9);
    float t = v / 8.0 + 0.5;
    vec3 col = mix(u_a, u_b, smoothstep(0.0, 0.55, t));
    col = mix(col, u_c, smoothstep(0.55, 1.0, t));
    gl_FragColor = vec4(col, 1.0);
  }`;
  const rgb = (h: string) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16) / 255);

  let canvas: HTMLCanvasElement;
  let stage: HTMLElement;
  let pal = $state(0);
  let noGl = $state(false);
  let started = $state(false);

  onMount(() => {
    const gl = canvas.getContext('webgl', { antialias: false, powerPreference: 'low-power' });
    if (!gl) { noGl = true; return; }
    const sh = (type: number, src: string) => {
      const s = gl.createShader(type)!; gl.shaderSource(s, src); gl.compileShader(s); return s;
    };
    const prog = gl.createProgram()!;
    gl.attachShader(prog, sh(gl.VERTEX_SHADER, 'attribute vec2 a; void main() { gl_Position = vec4(a, 0.0, 1.0); }'));
    gl.attachShader(prog, sh(gl.FRAGMENT_SHADER, FRAG));
    gl.linkProgram(prog); gl.useProgram(prog);
    gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
    const a = gl.getAttribLocation(prog, 'a');
    gl.enableVertexAttribArray(a); gl.vertexAttribPointer(a, 2, gl.FLOAT, false, 0, 0);
    const U: Record<string, WebGLUniformLocation | null> = {};
    for (const n of ['u_res', 'u_time', 'u_mouse', 'u_a', 'u_b', 'u_c']) U[n] = gl.getUniformLocation(prog, n);

    const mq = matchMedia('(prefers-reduced-motion: reduce)');
    const live = { mx: 0, my: 0, tx: 0, ty: 0 };
    let raf = 0, visible = true, last = 1;
    const t0 = performance.now();
    const size = () => { // half resolution keeps the full-screen shader cheap
      canvas.width = Math.max(2, Math.round(canvas.clientWidth * 0.5));
      canvas.height = Math.max(2, Math.round(canvas.clientHeight * 0.5));
    };
    const draw = (t: number) => {
      live.mx += (live.tx - live.mx) * 0.07; live.my += (live.ty - live.my) * 0.07; // eased pointer
      gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
      gl.uniform2f(U.u_res!, gl.drawingBufferWidth, gl.drawingBufferHeight);
      gl.uniform1f(U.u_time!, t); gl.uniform2f(U.u_mouse!, live.mx, live.my);
      const hex = PALETTES[pal].hex;
      gl.uniform3f(U.u_a!, ...rgb(hex[0])); gl.uniform3f(U.u_b!, ...rgb(hex[1])); gl.uniform3f(U.u_c!, ...rgb(hex[2]));
      gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
    };
    const redraw = () => draw(mq.matches ? 4.2 : last); // still frame under reduced motion
    const run = () => {
      cancelAnimationFrame(raf);
      if (!visible) return;            // parked while off screen
      if (mq.matches) { redraw(); return; }
      const loop = (now: number) => { last = (now - t0) / 1000; draw(last); raf = requestAnimationFrame(loop); };
      raf = requestAnimationFrame(loop);
    };

    const io = new IntersectionObserver(([e]) => { visible = e.isIntersecting; run(); });
    io.observe(canvas);
    const ro = new ResizeObserver(() => { size(); redraw(); });
    ro.observe(canvas);
    const onMove = (e: PointerEvent) => {
      const r = stage.getBoundingClientRect();
      live.tx = ((e.clientX - r.left) / r.width) * 2 - 1;
      live.ty = 1 - ((e.clientY - r.top) / r.height) * 2;
    };
    stage.addEventListener('pointermove', onMove);
    size(); run();

    return () => { // full cleanup — context included
      cancelAnimationFrame(raf); io.disconnect(); ro.disconnect();
      stage.removeEventListener('pointermove', onMove);
      gl.getExtension('WEBGL_lose_context')?.loseContext();
    };
  });
</script>

<div class="shpl-stage" bind:this={stage}>
  {#if noGl}
    <div class="shpl-fallback" style={`background: linear-gradient(135deg, ${PALETTES[pal].hex.join(', ')})`}></div>
  {:else}
    <canvas bind:this={canvas} class="shpl-cv" aria-hidden="true"></canvas>
  {/if}
  <article class="shpl-card">
    <small>Solstice 3.0 · global launch</small>
    <h2>Every launch, everywhere, at once</h2>
    <p>Frankfurt 12ms · Dublin 18ms · Singapore 23ms — the dashboard is live from second zero.</p>
    <footer>
      <button type="button" class="shpl-cta" onclick={() => (started = true)}>Start free</button>
      {#if started}<p role="status">Workspace ready — the welcome email is on its way.</p>{/if}
    </footer>
  </article>
</div>
<div class="shpl-swatches" role="group" aria-label="Plasma palette">
  {#each PALETTES as p, i (p.id)}
    <button type="button" aria-pressed={pal === i} aria-label={p.id} onclick={() => (pal = i)}
            style={`background: linear-gradient(135deg, ${p.hex.join(', ')})`}></button>
  {/each}
</div>

<style>
.shpl-stage { position: relative; overflow: clip; border-radius: 1.25rem; min-block-size: 24rem;
              display: grid; place-items: center; background: #1e1b4b; }
.shpl-cv, .shpl-fallback { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; }
.shpl-card { position: relative; z-index: 1; inline-size: min(100%, 34rem); margin: 2rem 1.25rem; padding: 1.75rem;
             border-radius: 1.25rem; background: rgba(255, 255, 255, .8); backdrop-filter: blur(14px); text-align: center; }
.shpl-cta { block-size: 2.75rem; padding-inline: 1.5rem; border: none; border-radius: 999px;
            background: #4f46e5; color: #fff; font: 600 .9rem system-ui; cursor: pointer; }
.shpl-swatches { display: flex; gap: .75rem; justify-content: center; margin-block-start: 1rem; }
.shpl-swatches button { inline-size: 2.5rem; block-size: 2.5rem; border-radius: 50%; cursor: pointer; }
.shpl-swatches button[aria-pressed='true'] { outline: 2px solid #4f46e5; outline-offset: 3px; }
</style>