Lava lamp v1 · OpenCode24.11.2026 07:04

Source HungerG, Default effort

index.html · 40.5 KB · 1,142 lines. Exactly as the agent wrote it.

<!doctype html><html lang="en"><head>  <meta charset="utf-8">  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">  <meta name="theme-color" content="#17191c">  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='14' fill='%2317191c'/%3E%3Cpath d='M23 10h18l4 14-5 28H24l-5-28z' fill='%23e65b17'/%3E%3C/svg%3E">  <title>Lava Lamp</title>  <style>    :root {      color-scheme: dark;      --safe-top: env(safe-area-inset-top, 0px);      --safe-left: env(safe-area-inset-left, 0px);      --safe-right: env(safe-area-inset-right, 0px);      --safe-bottom: env(safe-area-inset-bottom, 0px);    }    * { box-sizing: border-box; }    html, body {      width: 100%;      height: 100%;      margin: 0;      overflow: hidden;      background: #17191c;    }    body {      font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;      color: #f7e9d7;      -webkit-font-smoothing: antialiased;      -webkit-tap-highlight-color: transparent;      user-select: none;    }    button { font: inherit; }    .scene {      position: relative;      width: 100%;      height: 100vh;      height: 100svh;      min-height: 280px;      overflow: hidden;      isolation: isolate;      background:        radial-gradient(ellipse at 50% 39%, rgba(93, 76, 62, .19), transparent 43%),        radial-gradient(ellipse at 16% 4%, rgba(72, 83, 91, .18), transparent 42%),        linear-gradient(180deg, #202328 0%, #191b1e 58%, #111315 100%);    }    .scene::before {      content: "";      position: absolute;      inset: 0;      z-index: 0;      pointer-events: none;      opacity: .28;      background:        linear-gradient(90deg, transparent 49.94%, rgba(255,255,255,.025) 50%, transparent 50.06%),        repeating-linear-gradient(90deg, transparent 0 119px, rgba(255,255,255,.013) 120px 121px);    }    .masthead {      position: absolute;      z-index: 8;      top: calc(22px + var(--safe-top));      left: calc(22px + var(--safe-left));      pointer-events: none;    }    .masthead h1 {      margin: 0;      font-size: 11px;      line-height: 1;      font-weight: 700;      letter-spacing: .28em;      color: rgba(247, 233, 215, .74);    }    .masthead p {      margin: 9px 0 0;      font-size: 10px;      line-height: 1.4;      letter-spacing: .08em;      color: rgba(247, 233, 215, .34);    }    .power-pill {      position: absolute;      z-index: 12;      top: calc(16px + var(--safe-top));      right: calc(16px + var(--safe-right));      display: flex;      align-items: center;      gap: 9px;      min-width: 94px;      height: 42px;      padding: 0 15px 0 12px;      border: 1px solid rgba(255, 224, 190, .14);      border-radius: 999px;      color: #ffd7a5;      background: rgba(30, 29, 28, .56);      box-shadow: inset 0 1px 0 rgba(255,255,255,.05), 0 8px 26px rgba(0,0,0,.16);      backdrop-filter: blur(14px);      -webkit-backdrop-filter: blur(14px);      cursor: pointer;      touch-action: manipulation;      transition: color .5s ease, border-color .5s ease, background .5s ease, transform .15s ease;    }    .power-pill:active { transform: scale(.96); }    .power-pill:focus-visible, .base-switch:focus-visible {      outline: 2px solid #ffb35c;      outline-offset: 4px;    }    .power-pill svg {      width: 17px;      height: 17px;      flex: 0 0 auto;      filter: drop-shadow(0 0 6px rgba(255, 145, 55, .45));    }    .power-pill span {      font-size: 10px;      font-weight: 700;      letter-spacing: .16em;      text-transform: uppercase;    }    body.is-off .power-pill {      color: rgba(235, 231, 224, .48);      border-color: rgba(255,255,255,.08);      background: rgba(25, 27, 29, .52);    }    body.is-off .power-pill svg { filter: none; }    .lamp-halo {      position: absolute;      z-index: 0;      left: 50%;      top: 42%;      width: min(88vw, 720px);      aspect-ratio: 1;      transform: translate(-50%, -50%);      border-radius: 50%;      pointer-events: none;      opacity: 1;      background: radial-gradient(circle, rgba(255, 132, 42, .16) 0%, rgba(231, 91, 24, .065) 35%, transparent 69%);      transition: opacity 1.3s ease;    }    body.is-off .lamp-halo { opacity: 0; }    .lamp-wrap {      position: absolute;      z-index: 4;      left: 50%;      bottom: max(18px, calc(4svh + var(--safe-bottom) * .35));      width: min(420px, 94vw, calc((100svh - 92px) * .5526316));      aspect-ratio: 420 / 760;      transform: translateX(-50%);    }    .lamp {      position: relative;      width: 100%;      height: 100%;    }    .lamp-art {      position: absolute;      inset: 0;      width: 100%;      height: 100%;      overflow: visible;      pointer-events: none;    }    .lamp-back { z-index: 1; }    .lamp-front { z-index: 3; }    #wax {      position: absolute;      z-index: 2;      inset: 0;      width: 100%;      height: 100%;      pointer-events: none;    }    .glass-fill { transition: opacity 1.2s ease; }    body.is-off .glass-fill { opacity: .38; }    .heat-coil {      opacity: .9;      filter: drop-shadow(0 0 7px rgba(255, 104, 25, .8));      transition: opacity 1s ease;    }    body.is-off .heat-coil { opacity: .08; filter: none; }    .base-switch {      position: absolute;      z-index: 6;      left: 50%;      bottom: 2.15%;      width: 17%;      height: 6.4%;      padding: 0;      transform: translateX(-50%);      border: 0;      border-radius: 8px;      background: transparent;      cursor: pointer;      touch-action: manipulation;    }    .rocker {      position: absolute;      left: 17%;      right: 17%;      top: 27%;      bottom: 27%;      display: block;      border: 1px solid rgba(255, 213, 163, .16);      border-radius: 4px;      background: linear-gradient(180deg, #0c0d0e, #262321);      box-shadow: inset 0 2px 4px rgba(0,0,0,.8), 0 1px 0 rgba(255,255,255,.09);      transition: background .35s ease, box-shadow .35s ease;    }    .rocker::before {      content: "";      position: absolute;      top: 19%;      left: 50%;      width: 12%;      aspect-ratio: 1;      transform: translateX(-50%);      border-radius: 50%;      background: #6b5a49;      box-shadow: inset 0 1px 1px rgba(0,0,0,.6);      transition: background .35s ease, box-shadow .35s ease;    }    .base-switch[aria-checked="true"] .rocker {      background: linear-gradient(180deg, #3a2418, #1b1512);      box-shadow: inset 0 2px 4px rgba(0,0,0,.65), 0 0 9px rgba(255, 117, 35, .12);    }    .base-switch[aria-checked="true"] .rocker::before {      background: #ffae5d;      box-shadow: 0 0 7px #ff6b1a, 0 0 2px #fff1c4;    }    .desk {      position: absolute;      z-index: 1;      left: 0;      right: 0;      bottom: 0;      height: 27svh;      min-height: 96px;      overflow: hidden;      background:        radial-gradient(ellipse at 50% -20%, rgba(159, 104, 64, .21), transparent 59%),        repeating-linear-gradient(2deg, transparent 0 7px, rgba(31, 15, 8, .075) 8px 9px, transparent 10px 19px),        repeating-linear-gradient(178deg, transparent 0 31px, rgba(255, 210, 158, .025) 32px 33px, transparent 34px 61px),        linear-gradient(180deg, #513422 0%, #3d281c 45%, #2b1d16 100%);      box-shadow: inset 0 1px 0 rgba(255, 209, 155, .15), inset 0 24px 50px rgba(0,0,0,.12);    }    .desk::before {      content: "";      position: absolute;      inset: 0;      background:        radial-gradient(ellipse at 50% 12%, transparent 0 30%, rgba(12, 8, 6, .16) 83%),        linear-gradient(90deg, rgba(0,0,0,.15), transparent 18% 82%, rgba(0,0,0,.15));    }    .desk-light {      position: absolute;      inset: -35% -12% 0;      pointer-events: none;      background: radial-gradient(ellipse at 50% 4%, rgba(255, 145, 60, .3), rgba(224, 91, 25, .09) 34%, transparent 65%);      mix-blend-mode: screen;      opacity: 1;      transition: opacity 1.25s ease;    }    body.is-off .desk-light { opacity: 0; }    .notebook {      position: absolute;      z-index: 2;      left: max(10px, 5vw);      bottom: 10%;      width: clamp(72px, 12vw, 154px);      aspect-ratio: 1.38;      transform: rotate(-8deg);      border-radius: 4px 7px 7px 4px;      background: linear-gradient(100deg, #162b2d, #294548 72%, #20383a);      box-shadow: 0 13px 22px rgba(0,0,0,.34), inset 3px 0 0 rgba(255,255,255,.05);    }    .notebook::before {      content: "";      position: absolute;      inset: 5px -5px -5px 7px;      z-index: -1;      border-radius: 3px 6px 6px 3px;      background: repeating-linear-gradient(180deg, #b8ab91 0 2px, #d4c7aa 2px 4px);      box-shadow: 0 9px 16px rgba(0,0,0,.3);    }    .notebook::after {      content: "";      position: absolute;      top: 17%;      bottom: 17%;      left: 20%;      width: 1px;      background: rgba(216, 231, 216, .14);      box-shadow: 5px 0 0 rgba(216, 231, 216, .07);    }    .cup {      position: absolute;      z-index: 2;      right: max(14px, 8vw);      bottom: 12%;      width: clamp(46px, 7vw, 78px);      aspect-ratio: .88;      border-radius: 5px 5px 17px 17px;      background: linear-gradient(100deg, #7c7469 0%, #c3b8a5 28%, #e0d5c1 53%, #a99d8b 82%, #6d655b 100%);      box-shadow: 0 15px 23px rgba(0,0,0,.32), inset 0 -7px 10px rgba(67,54,42,.18);    }    .cup::before {      content: "";      position: absolute;      z-index: 2;      left: 5%;      right: 5%;      top: -4%;      height: 17%;      border-radius: 50%;      background: radial-gradient(ellipse at 47% 43%, #5c3824 0 42%, #2d1c14 66%, #baac96 70%);      box-shadow: inset 0 2px 3px rgba(0,0,0,.55), 0 1px 0 rgba(255,255,255,.4);    }    .cup::after {      content: "";      position: absolute;      z-index: -1;      right: -28%;      top: 24%;      width: 43%;      height: 44%;      border: clamp(4px, .65vw, 7px) solid #b6aa97;      border-left-width: clamp(3px, .45vw, 5px);      border-radius: 12px 18px 18px 12px;      box-shadow: 2px 3px 5px rgba(0,0,0,.2), inset 1px 1px 0 rgba(255,255,255,.2);    }    .pencil {      position: absolute;      z-index: 2;      right: max(16px, 15vw);      bottom: 8.5%;      width: clamp(65px, 11vw, 130px);      height: 5px;      border-radius: 2px;      transform: rotate(-9deg);      background: linear-gradient(180deg, #d39a43, #a86623);      box-shadow: 0 4px 6px rgba(0,0,0,.25);    }    .pencil::before {      content: "";      position: absolute;      right: -10px;      border-top: 2.5px solid transparent;      border-bottom: 2.5px solid transparent;      border-left: 10px solid #d8c09a;    }    .pencil::after {      content: "";      position: absolute;      right: -11px;      top: 1.5px;      border-top: 1px solid transparent;      border-bottom: 1px solid transparent;      border-left: 3px solid #37312c;    }    .hint {      position: absolute;      z-index: 9;      left: 50%;      bottom: calc(7px + var(--safe-bottom));      transform: translateX(-50%);      margin: 0;      white-space: nowrap;      font-size: 9px;      font-weight: 600;      letter-spacing: .16em;      text-transform: uppercase;      color: rgba(246, 224, 198, .3);      pointer-events: none;      transition: opacity .8s ease;    }    .hint.is-hidden { opacity: 0; }    @media (max-width: 600px) {      .masthead p { display: none; }      .notebook { left: -2vw; opacity: .82; }      .cup { right: 3vw; bottom: 13%; }      .pencil { right: 9vw; bottom: 8%; }      .hint { font-size: 8px; }    }    @media (max-height: 480px) {      .masthead p, .hint { display: none; }      .desk { height: 25svh; }      .power-pill { height: 36px; min-width: 84px; }      .cup, .pencil { opacity: .8; }    }    @media (prefers-reduced-motion: reduce) {      .lamp-halo, .desk-light, .glass-fill, .heat-coil, .power-pill { transition-duration: .2s; }    }  </style></head><body>  <!-- All artwork and shading are inline; the page makes no network requests. -->  <svg width="0" height="0" aria-hidden="true" style="position:absolute;overflow:hidden">    <defs>      <linearGradient id="baseMetal" x1="0" y1="0" x2="1" y2=".15">        <stop offset="0" stop-color="#151311"/>        <stop offset=".12" stop-color="#514033"/>        <stop offset=".29" stop-color="#a17a53"/>        <stop offset=".43" stop-color="#574333"/>        <stop offset=".72" stop-color="#211c19"/>        <stop offset=".9" stop-color="#5e4735"/>        <stop offset="1" stop-color="#141212"/>      </linearGradient>      <linearGradient id="capMetal" x1="0" y1="0" x2="1" y2=".1">        <stop offset="0" stop-color="#151414"/>        <stop offset=".13" stop-color="#51443a"/>        <stop offset=".32" stop-color="#b08b63"/>        <stop offset=".47" stop-color="#63503f"/>        <stop offset=".75" stop-color="#211d1a"/>        <stop offset=".91" stop-color="#6b523c"/>        <stop offset="1" stop-color="#121111"/>      </linearGradient>      <linearGradient id="baseShade" x1="0" y1="0" x2="0" y2="1">        <stop offset="0" stop-color="#d7aa70" stop-opacity=".22"/>        <stop offset=".45" stop-color="#805733" stop-opacity=".04"/>        <stop offset="1" stop-color="#000" stop-opacity=".58"/>      </linearGradient>      <radialGradient id="glassFill" cx=".5" cy=".48" r=".72">        <stop offset="0" stop-color="#e39b52" stop-opacity=".045"/>        <stop offset=".6" stop-color="#65818a" stop-opacity=".07"/>        <stop offset="1" stop-color="#0a1418" stop-opacity=".34"/>      </radialGradient>      <linearGradient id="glassSheen" x1="0" y1="0" x2="1" y2="0">        <stop offset="0" stop-color="#d9f4f4" stop-opacity=".03"/>        <stop offset=".12" stop-color="#f2ffff" stop-opacity=".16"/>        <stop offset=".2" stop-color="#ffffff" stop-opacity=".025"/>        <stop offset=".72" stop-color="#ffffff" stop-opacity="0"/>        <stop offset=".9" stop-color="#cde7e8" stop-opacity=".09"/>        <stop offset="1" stop-color="#ffffff" stop-opacity=".02"/>      </linearGradient>      <linearGradient id="edgeGlow" x1="0" y1="0" x2="0" y2="1">        <stop offset="0" stop-color="#e9fbf8" stop-opacity=".5"/>        <stop offset=".38" stop-color="#b8d8d7" stop-opacity=".16"/>        <stop offset=".76" stop-color="#e7b487" stop-opacity=".14"/>        <stop offset="1" stop-color="#ffc18a" stop-opacity=".32"/>      </linearGradient>      <radialGradient id="lampShadow">        <stop offset="0" stop-color="#080706" stop-opacity=".68"/>        <stop offset=".55" stop-color="#080706" stop-opacity=".3"/>        <stop offset="1" stop-color="#080706" stop-opacity="0"/>      </radialGradient>      <radialGradient id="coilGlow">        <stop offset="0" stop-color="#ffd29a" stop-opacity=".95"/>        <stop offset=".35" stop-color="#ff8b35" stop-opacity=".75"/>        <stop offset="1" stop-color="#ff4e0a" stop-opacity="0"/>      </radialGradient>      <linearGradient id="glassBottom" x1="0" y1="0" x2="0" y2="1">        <stop offset="0" stop-color="#ffad66" stop-opacity="0"/>        <stop offset="1" stop-color="#ff9a4e" stop-opacity=".22"/>      </linearGradient>    </defs>  </svg>  <div class="scene">    <div class="lamp-halo" aria-hidden="true"></div>    <header class="masthead">      <h1>LAVA / 01</h1>      <p>A quiet study in heat &amp; motion</p>    </header>    <button class="power-pill" id="powerPill" type="button" role="switch" aria-checked="true" aria-label="Turn lava lamp off">      <svg viewBox="0 0 24 24" fill="none" aria-hidden="true">        <path d="M12 3v8" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>        <path d="M7.1 5.9a8 8 0 1 0 9.8 0" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>      </svg>      <span id="powerText">On</span>    </button>    <div class="desk" aria-hidden="true">      <div class="desk-light"></div>      <div class="notebook"></div>      <div class="pencil"></div>      <div class="cup"></div>    </div>    <main class="lamp-wrap" aria-label="Animated lava lamp">      <div class="lamp" id="lamp">        <svg class="lamp-art lamp-back" viewBox="0 0 420 760" aria-hidden="true">          <ellipse cx="210" cy="738" rx="139" ry="17" fill="url(#lampShadow)"/>          <!-- Metal base -->          <path d="M166 637 L148 700 Q145 719 126 730 Q123 734 132 736 L288 736 Q297 734 294 730 Q275 719 272 700 L254 637 Z" fill="url(#baseMetal)"/>          <path d="M166 637 L148 700 Q145 719 126 730 Q123 734 132 736 L288 736 Q297 734 294 730 Q275 719 272 700 L254 637 Z" fill="url(#baseShade)"/>          <path d="M161 648 Q210 655 259 648 L255 661 Q210 669 165 661 Z" fill="#171412" opacity=".72"/>          <path d="M157 660 Q210 668 263 660" fill="none" stroke="#d1a273" stroke-opacity=".24" stroke-width="1.2"/>          <ellipse cx="210" cy="733" rx="79" ry="6" fill="#0c0b0b" opacity=".72"/>          <path d="M143 716 Q210 728 277 716" fill="none" stroke="#e0b487" stroke-opacity=".1" stroke-width="1.5"/>          <!-- Glass vessel, behind the wax -->          <path class="glass-fill" d="M110 126 C101 205 112 268 117 302 C128 426 148 542 162 609 C175 638 192 652 210 655 C228 652 245 638 258 609 C272 542 292 426 303 302 C308 268 319 205 310 126 Z" fill="url(#glassFill)"/>          <ellipse class="heat-coil" cx="210" cy="625" rx="39" ry="12" fill="url(#coilGlow)"/>          <path d="M181 625 Q210 618 239 625" fill="none" stroke="#ff9a47" stroke-width="2" stroke-linecap="round" opacity=".56"/>          <!-- Top cap -->          <path d="M139 126 L148 47 Q150 28 169 25 L251 25 Q270 28 272 47 L281 126 Z" fill="url(#capMetal)"/>          <path d="M139 126 L148 47 Q150 28 169 25 L251 25 Q270 28 272 47 L281 126 Z" fill="url(#baseShade)" opacity=".6"/>          <ellipse cx="210" cy="27" rx="40" ry="5" fill="#1a1715"/>          <ellipse cx="210" cy="26" rx="31" ry="2.5" fill="#8f6c4b" opacity=".22"/>          <path d="M139 118 Q210 125 281 118 L281 129 Q210 137 139 129 Z" fill="#181512"/>          <path d="M141 119 Q210 126 279 119" fill="none" stroke="#e0b384" stroke-opacity=".3" stroke-width="1.4"/>          <path d="M158 45 Q154 71 153 108" fill="none" stroke="#ffe0b6" stroke-opacity=".14" stroke-width="3" stroke-linecap="round"/>        </svg>        <canvas id="wax" aria-hidden="true"></canvas>        <svg class="lamp-art lamp-front" viewBox="0 0 420 760" aria-hidden="true">          <!-- Glass edge and soft reflections -->          <path d="M110 126 C101 205 112 268 117 302 C128 426 148 542 162 609 C175 638 192 652 210 655 C228 652 245 638 258 609 C272 542 292 426 303 302 C308 268 319 205 310 126 Z" fill="url(#glassSheen)"/>          <path d="M110 126 C101 205 112 268 117 302 C128 426 148 542 162 609 C175 638 192 652 210 655 C228 652 245 638 258 609 C272 542 292 426 303 302 C308 268 319 205 310 126 Z" fill="none" stroke="url(#edgeGlow)" stroke-width="1.8"/>          <path d="M128 148 C120 213 130 264 126 309 C118 401 136 501 158 565 C168 598 181 623 196 638" fill="none" stroke="#e8ffff" stroke-opacity=".2" stroke-width="4.5" stroke-linecap="round"/>          <path d="M137 158 C132 214 140 262 137 308 C130 384 143 465 160 520" fill="none" stroke="#ffffff" stroke-opacity=".1" stroke-width="1.4" stroke-linecap="round"/>          <path d="M291 166 C300 222 290 267 294 310 C302 400 286 493 265 552" fill="none" stroke="#d7f4f3" stroke-opacity=".12" stroke-width="2.4" stroke-linecap="round"/>          <path d="M145 136 Q210 124 275 136" fill="none" stroke="#efffff" stroke-opacity=".3" stroke-width="1.6"/>          <path d="M154 616 Q181 646 210 648 Q239 646 266 616" fill="none" stroke="#ffd0a2" stroke-opacity=".2" stroke-width="2"/>          <path d="M177 606 Q210 631 243 606 Q236 646 210 651 Q184 646 177 606 Z" fill="url(#glassBottom)" opacity=".42"/>          <circle cx="151" cy="361" r="1.1" fill="#fff" opacity=".13"/>          <circle cx="278" cy="442" r=".8" fill="#fff" opacity=".1"/>          <circle cx="188" cy="214" r=".7" fill="#fff" opacity=".12"/>        </svg>        <button class="base-switch" id="baseSwitch" type="button" role="switch" aria-checked="true" aria-label="Turn lava lamp off">          <span class="rocker" aria-hidden="true"></span>        </button>      </div>    </main>    <p class="hint" id="hint">Tap the switch</p>  </div>  <script>    (() => {      'use strict';      const DESIGN_W = 420;      const DESIGN_H = 760;      const MAX_BLOBS = 12;      const TAU = Math.PI * 2;      let canvas = document.getElementById('wax');      const lamp = document.getElementById('lamp');      const powerPill = document.getElementById('powerPill');      const baseSwitch = document.getElementById('baseSwitch');      const powerText = document.getElementById('powerText');      const hint = document.getElementById('hint');      const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;      let isOn = true;      let power = 1;      let time = 0;      let lastFrame = performance.now();      let accumulator = 0;      let gl = null;      let ctx2d = null;      let program = null;      let buffer = null;      let locations = null;      let renderScale = 1;      let resolutionQuality = 1;      let slowFrames = 0;      const blobData = new Float32Array(MAX_BLOBS * 4);      const blobs = [];      let fallbackClip = null;      const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));      const rand = (lo, hi) => lo + Math.random() * (hi - lo);      function halfWidthAt(y) {        const t = clamp((y - 126) / 529, 0, 1);        const body = 100 - 18 * t - 42 * t * t + 2 * Math.sin(t * Math.PI);        const bottom = 1 - clamp((y - 610) / 45, 0, 1);        const roundedBottom = bottom * bottom * (3 - 2 * bottom);        return body * roundedBottom;      }      function makeBlob(x, y, r, temperature, seed = Math.random() * TAU) {        return {          x, y, r,          vx: rand(-2, 2),          vy: rand(-2, 2),          temp: temperature,          seed,          cooldown: rand(.4, 2.4),          splitIn: rand(3, 7)        };      }      function seedLamp() {        blobs.length = 0;        const seeds = [          [190, 594, 25, .72], [246, 557, 21, .62],          [205, 486, 29, .43], [263, 414, 19, .25],          [158, 362, 22, .31], [219, 292, 25, .2],          [271, 235, 17, .13], [157, 265, 19, .16],          [234, 498, 20, .38], [194, 195, 16, .08],          [279, 348, 15, .14]        ];        for (const [x, y, r, temp] of seeds) blobs.push(makeBlob(x, y, r, temp));        // Let the first touching pair coalesce right away, then split under heat.        blobs[2].cooldown = 0;        blobs[8].cooldown = 0;      }      function compileShader(type, source) {        const shader = gl.createShader(type);        gl.shaderSource(shader, source);        gl.compileShader(shader);        if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {          const message = gl.getShaderInfoLog(shader);          gl.deleteShader(shader);          throw new Error(message || 'Shader compilation failed');        }        return shader;      }      function switchToFallback() {        gl = null;        program = null;        if (ctx2d && ctx2d.canvas === canvas) return;        // A canvas cannot change context type, so replace it if WebGL was acquired.        let context = canvas.getContext('2d');        if (!context) {          const replacement = canvas.cloneNode(false);          canvas.replaceWith(replacement);          canvas = replacement;          context = canvas.getContext('2d');        }        ctx2d = context;      }      function initWebGL() {        gl = canvas.getContext('webgl', {          alpha: true,          antialias: false,          depth: false,          stencil: false,          premultipliedAlpha: false,          preserveDrawingBuffer: false,          powerPreference: 'low-power'        }) || canvas.getContext('experimental-webgl', { alpha: true, antialias: false });        if (!gl) {          switchToFallback();          return false;        }        const vertexSource = `          attribute vec2 a_position;          varying vec2 v_uv;          void main() {            v_uv = a_position * 0.5 + 0.5;            gl_Position = vec4(a_position, 0.0, 1.0);          }        `;        const fragmentSource = `          precision mediump float;          varying vec2 v_uv;          uniform vec2 u_design;          uniform vec4 u_blobs[${MAX_BLOBS}];          uniform float u_count;          uniform float u_power;          float glassHalfWidth(float y) {            float t = clamp((y - 126.0) / 529.0, 0.0, 1.0);            float body = 100.0 - 18.0 * t - 42.0 * t * t + 2.0 * sin(t * 3.14159265);            float b = clamp((y - 610.0) / 45.0, 0.0, 1.0);            float rounded = 1.0 - b * b * (3.0 - 2.0 * b);            return body * rounded;          }          void main() {            vec2 p = v_uv * u_design;            // Reject the transparent area around the vessel before the metaball loop.            float halfWidth = glassHalfWidth(p.y);            float edge = halfWidth - abs(p.x - 210.0);            float glassMask = smoothstep(-0.5, 1.8, edge);            glassMask *= smoothstep(123.0, 131.0, p.y);            glassMask *= 1.0 - smoothstep(649.0, 656.0, p.y);            if (glassMask < 0.01) discard;            float field = 0.0;            float heatField = 0.0;            vec2 grad = vec2(0.0);            for (int i = 0; i < ${MAX_BLOBS}; i++) {              if (float(i) >= u_count) break;              vec4 b = u_blobs[i];              vec2 delta = p - b.xy;              float stretch = 1.0 + 0.1 * b.w;              delta.y /= stretch;              float d2 = dot(delta, delta) + 3.0;              float r2 = b.z * b.z;              float influence = r2 / d2;              field += influence;              heatField += influence * b.w;              grad += -2.0 * r2 * delta / (d2 * d2);            }            if (field < 0.94) discard;            float surface = smoothstep(0.94, 1.035, field);            float warmth = clamp(heatField / max(field, 0.001), 0.0, 1.0);            vec3 normal = normalize(vec3(-grad * 12.0, 1.15));            vec3 lightDir = normalize(vec3(-0.48, 0.62, 1.0));            float diffuse = 0.48 + 0.52 * max(dot(normal, lightDir), 0.0);            float specular = pow(max(dot(reflect(-lightDir, normal), vec3(0.0, 0.0, 1.0)), 0.0), 20.0);            float rim = pow(1.0 - clamp(normal.z, 0.0, 1.0), 2.2);            float core = smoothstep(1.15, 3.4, field);            vec3 coolWax = vec3(0.64, 0.035, 0.006);            vec3 warmWax = vec3(1.0, 0.29, 0.012);            vec3 color = mix(coolWax, warmWax, 0.3 + 0.7 * warmth);            color *= diffuse;            color += vec3(0.3, 0.075, 0.005) * core;            color += vec3(1.0, 0.38, 0.08) * rim * 0.38;            color += vec3(1.0, 0.72, 0.4) * specular * 0.34;            float lowerGlow = exp(-max(p.y - 505.0, 0.0) * 0.008);            color += vec3(0.2, 0.045, 0.0) * lowerGlow * u_power;            color *= mix(0.31, 1.1, u_power);            float alpha = surface * glassMask * 0.97;            gl_FragColor = vec4(color, alpha);          }        `;        try {          const vertex = compileShader(gl.VERTEX_SHADER, vertexSource);          const fragment = compileShader(gl.FRAGMENT_SHADER, fragmentSource);          program = gl.createProgram();          gl.attachShader(program, vertex);          gl.attachShader(program, fragment);          gl.linkProgram(program);          gl.deleteShader(vertex);          gl.deleteShader(fragment);          if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {            throw new Error(gl.getProgramInfoLog(program) || 'Shader link failed');          }        } catch (error) {          console.warn('Using the canvas fallback:', error);          switchToFallback();          return false;        }        gl.useProgram(program);        buffer = gl.createBuffer();        gl.bindBuffer(gl.ARRAY_BUFFER, buffer);        gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);        const position = gl.getAttribLocation(program, 'a_position');        gl.enableVertexAttribArray(position);        gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);        locations = {          design: gl.getUniformLocation(program, 'u_design'),          blobs: gl.getUniformLocation(program, `u_blobs[0]`),          count: gl.getUniformLocation(program, 'u_count'),          power: gl.getUniformLocation(program, 'u_power')        };        gl.disable(gl.DEPTH_TEST);        gl.disable(gl.CULL_FACE);        gl.clearColor(0, 0, 0, 0);        return true;      }      function resize() {        const rect = canvas.getBoundingClientRect();        if (!rect.width || !rect.height) return;        if (gl) {          renderScale = Math.min(window.devicePixelRatio || 1, 1.25, 720 / rect.height) * resolutionQuality;          const width = Math.max(1, Math.round(rect.width * renderScale));          const height = Math.max(1, Math.round(rect.height * renderScale));          if (canvas.width !== width || canvas.height !== height) {            canvas.width = width;            canvas.height = height;            gl.viewport(0, 0, width, height);          }        } else if (ctx2d) {          renderScale = Math.min(window.devicePixelRatio || 1, 1.5) * resolutionQuality;          canvas.width = Math.max(1, Math.round(rect.width * renderScale));          canvas.height = Math.max(1, Math.round(rect.height * renderScale));        }      }      function constrainBlob(b) {        const top = 143 + Math.min(13, b.r * .28);        const bottom = 646 - Math.min(12, b.r * .32);        if (b.y < top) {          b.y = top;          b.vy = Math.abs(b.vy) * .18;          b.temp -= .025;        }        if (b.y > bottom) {          b.y = bottom;          b.vy = Math.min(0, b.vy) * .08;          b.vx *= .94;        }        const half = halfWidthAt(b.y);        const margin = Math.min(b.r * .48, half * .52);        const minX = 210 - Math.max(0, half - margin);        const maxX = 210 + Math.max(0, half - margin);        if (b.x < minX) {          b.x = minX;          b.vx = Math.abs(b.vx) * .32;        } else if (b.x > maxX) {          b.x = maxX;          b.vx = -Math.abs(b.vx) * .32;        }      }      function mergeBlobs(a, b, indexA, indexB) {        const massA = a.r * a.r;        const massB = b.r * b.r;        const mass = massA + massB;        const r = Math.sqrt(mass);        const merged = makeBlob(          (a.x * massA + b.x * massB) / mass,          (a.y * massA + b.y * massB) / mass,          r,          (a.temp * massA + b.temp * massB) / mass        );        merged.vx = (a.vx * massA + b.vx * massB) / mass;        merged.vy = (a.vy * massA + b.vy * massB) / mass;        merged.cooldown = 1.8;        merged.splitIn = rand(2.4, 5.4);        blobs[indexA] = merged;        blobs.splice(indexB, 1);      }      function resolveCollisions() {        for (let i = 0; i < blobs.length; i++) {          for (let j = i + 1; j < blobs.length; j++) {            const a = blobs[i];            const b = blobs[j];            let dx = a.x - b.x;            let dy = a.y - b.y;            let distance = Math.hypot(dx, dy);            const minDistance = (a.r + b.r) * .9;            if (distance >= minDistance) continue;            if (distance < .001) {              dx = .01;              dy = 0;              distance = .01;            }            const nx = dx / distance;            const ny = dy / distance;            const overlap = minDistance - distance;            const relativeSpeed = Math.hypot(a.vx - b.vx, a.vy - b.vy);            const combinedRadius = Math.sqrt(a.r * a.r + b.r * b.r);            const warmEnough = (a.temp + b.temp) * .5 > .16;            const shouldOfferMerge = isOn && a.cooldown <= 0 && b.cooldown <= 0 &&              combinedRadius < 48 && warmEnough && (overlap > 1.2 || relativeSpeed < 25);            if (shouldOfferMerge && (overlap > 5 || Math.random() < .72)) {              mergeBlobs(a, b, i, j);              return;            }            const massA = a.r * a.r;            const massB = b.r * b.r;            const totalMass = massA + massB;            const shiftA = overlap * (massB / totalMass) * .52;            const shiftB = overlap * (massA / totalMass) * .52;            a.x += nx * shiftA;            a.y += ny * shiftA;            b.x -= nx * shiftB;            b.y -= ny * shiftB;            const normalVelocity = (a.vx - b.vx) * nx + (a.vy - b.vy) * ny;            if (normalVelocity < 0) {              const impulse = -normalVelocity * 1.12 / (1 / massA + 1 / massB);              a.vx += impulse * nx / massA;              a.vy += impulse * ny / massA;              b.vx -= impulse * nx / massB;              b.vy -= impulse * ny / massB;            }            if (overlap > .4) {              a.cooldown = Math.max(a.cooldown, .38);              b.cooldown = Math.max(b.cooldown, .38);            }          }        }      }      function splitBlob(b, index) {        if (blobs.length >= MAX_BLOBS) return;        const angle = rand(0, TAU);        const nx = Math.cos(angle);        const ny = Math.sin(angle) * .65;        const childRadius = b.r / Math.Sqrt(2);        const offset = childRadius * .88;        const warmthDifference = rand(.055, .11);        const warm = makeBlob(          b.x + nx * offset,          b.y + ny * offset,          childRadius,          clamp(b.temp + warmthDifference, 0, 1),          b.seed + rand(.4, 1.2)        );        const cool = makeBlob(          b.x - nx * offset,          b.y - ny * offset,          childRadius,          clamp(b.temp - warmthDifference * .8, 0, 1),          b.seed + rand(2, 3)        );        warm.vx = b.vx + nx * 11;        warm.vy = b.vy + ny * 7;        cool.vx = b.vx - nx * 11;        cool.vy = b.vy - ny * 7;        warm.cooldown = cool.cooldown = 2.2;        warm.splitIn = cool.splitIn = rand(4, 8);        blobs[index] = warm;        blobs.splice(index + 1, 0, cool);      }      function simulate(dt) {        time += dt;        const motionScale = reduceMotion ? .35 : 1;        for (const b of blobs) {          b.cooldown -= dt;          b.splitIn -= dt;          const bottomHeat = Math.exp(-Math.pow((b.y - 602) / 82, 2));          const topCooling = Math.exp(-Math.pow((b.y - 178) / 105, 2));          if (isOn) {            b.temp += (.32 * bottomHeat - .26 * topCooling - .011) * dt;          } else {            b.temp -= (.052 + .065 * topCooling) * dt;          }          b.temp = clamp(b.temp, 0, 1);          const buoyancy = isOn ? (b.temp - .43) * 49 : -(14 + b.temp * 17);          b.vy += (buoyancy - b.vy) * Math.min(1, dt * 1.65);          const flow = (Math.sin(time * .63 + b.seed) * 3.2 +            Math.sin(b.y * .017 + time * .41 + b.seed * .7) * 2.1) * motionScale;          const targetFlow = isOn ? flow : flow * power * .3;          b.vx += (targetFlow - b.vx) * Math.min(1, dt * .72);          b.x += b.vx * dt;          b.y += b.vy * dt;          constrainBlob(b);        }        resolveCollisions();        for (let i = blobs.length - 1; i >= 0; i--) {          const b = blobs[i];          if (isOn && b.r > 33 && b.splitIn <= 0 && halfWidthAt(b.y) > b.r * 1.05) {            splitBlob(b, i);          }          constrainBlob(b);        }      }      function updateUniforms() {        blobData.fill(0);        for (let i = 0; i < blobs.length; i++) {          const b = blobs[i];          const offset = i * 4;          blobData[offset] = b.x;          blobData[offset + 1] = b.y;          blobData[offset + 2] = b.r;          blobData[offset + 3] = b.temp;        }        gl.uniform2f(locations.design, DESIGN_W, DESIGN_H);        gl.uniform4fv(locations.blobs, blobData);        gl.uniform1f(locations.count, blobs.length);        gl.uniform1f(locations.power, power);      }      function renderWebGL() {        gl.clear(gl.COLOR_BUFFER_BIT);        updateUniforms();        gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);      }      function renderFallback() {        const ctx = ctx2d;        const sx = canvas.width / DESIGN_W;        const sy = canvas.height / DESIGN_H;        ctx.setTransform(1, 0, 0, 1, 0, 0);        ctx.clearRect(0, 0, canvas.width, canvas.height);        ctx.setTransform(sx, 0, 0, sy, 0, 0);        ctx.save();        if (!fallbackClip) {          fallbackClip = new Path2D('M110 126 C101 205 112 268 117 302 C128 426 148 542 162 609 C175 638 192 652 210 655 C228 652 245 638 258 609 C272 542 292 426 303 302 C308 268 319 205 310 126 Z');        }        ctx.clip(fallbackClip);        ctx.globalCompositeOperation = 'source-over';        for (const b of blobs) {          const radius = b.r * 1.2;          const gradient = ctx.createRadialGradient(            b.x - b.r * .28, b.y - b.r * .34, b.r * .08,            b.x, b.y, radius          );          const brightness = .34 + power * .66;          const hot = b.temp;          gradient.addColorStop(0, `rgba(255, ${Math.round(75 + hot * 65)}, 12, ${.98 * brightness})`);          gradient.addColorStop(.58, `rgba(235, ${Math.round(35 + hot * 55)}, 3, ${.97 * brightness})`);          gradient.addColorStop(.82, `rgba(170, 18, 2, ${.94 * brightness})`);          gradient.addColorStop(1, 'rgba(120, 8, 1, 0)');          ctx.fillStyle = gradient;          ctx.beginPath();          ctx.arc(b.x, b.y, radius, 0, TAU);          ctx.fill();        }        ctx.restore();      }      function frame(now) {        const rawElapsed = Math.max(0, (now - lastFrame) / 1000);        const elapsed = Math.min(rawElapsed, .05);        lastFrame = now;        // Drop internal resolution before dropping frames on slower phones.        if (rawElapsed > .023 && rawElapsed < .12) slowFrames++;        else slowFrames = Math.max(0, slowFrames - 2);        if (slowFrames > 75 && resolutionQuality > .7) {          resolutionQuality = Math.max(.7, resolutionQuality - .15);          slowFrames = 0;          resize();        }        accumulator += elapsed;        power += ((isOn ? 1 : 0) - power) * Math.min(1, elapsed * 3.2);        let steps = 0;        while (accumulator >= 1 / 60 && steps < 3) {          simulate(1 / 60);          accumulator -= 1 / 60;          steps++;        }        if (gl) renderWebGL();        else if (ctx2d) renderFallback();        requestAnimationFrame(frame);      }      function setPower(next) {        isOn = next;        document.body.classList.toggle('is-off', !isOn);        for (const button of [powerPill, baseSwitch]) {          button.setAttribute('aria-checked', String(isOn));          button.setAttribute('aria-label', isOn ? 'Turn lava lamp off' : 'Turn lava lamp on');        }        powerText.textContent = isOn ? 'On' : 'Off';        hint.classList.add('is-hidden');        if (isOn) {          for (const b of blobs) {            if (b.r > 31) b.splitIn = Math.min(b.splitIn, 1.2);          }        }      }      powerPill.addEventListener('click', () => setPower(!isOn));      baseSwitch.addEventListener('click', () => setPower(!isOn));      canvas.addEventListener('webglcontextlost', event => {        event.preventDefault();        switchToFallback();        resize();      });      window.addEventListener('resize', resize, { passive: true });      if ('ResizeObserver' in window) new ResizeObserver(resize).observe(lamp);      document.addEventListener('visibilitychange', () => {        lastFrame = performance.now();        accumulator = 0;      });      seedLamp();      initWebGL();      resize();      requestAnimationFrame(frame);      setTimeout(() => hint.classList.add('is-hidden'), 6500);    })();  </script></body></html>