{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"floppy-drive-save-indicator-with-a-disk-that-slides-in-a-flickering-busy-lamp-and-a-spring-eject","type":"registry:component","title":"Floppy Drive Save Indicator with a Disk That Slides In, a Flickering Busy Lamp and a Spring Eject","description":"Save indicator on a canvas: a disk is pushed into a drive, a lamp flickers while it writes, then the disk springs back out. Free React and HTML to copy.","dependencies":[],"files":[{"path":"components/we-inc/floppy-drive-save-indicator-with-a-disk-that-slides-in-a-flickering-busy-lamp-and-a-spring-eject.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// What is being saved, the words on the paper label, and the three status lines.\nconst file = { label: [\"homepage\", \"v12 final\"], maker: \"ORBITA\", model: \"D-35\" };\nconst words = { dirty: \"Unsaved changes\", busy: \"Writing to disk\", done: \"All changes saved\" };\nconst DISK = [236, 98, 42]; // disk shell, as red, green, blue\nconst CASE = [205, 208, 202]; // drive case plastic\nconst WRITE_SECONDS = 2.1; // how long the lamp flickers\nconst W = 440, H = 500;\nconst DX = 106, DW = 228, DH = 238, SLOT = 246, OUT = 0.29, IN = 0.975;\n\ntype Phase = \"done\" | \"dirty\" | \"busy\";\n\nexport default function FloppyDriveSaveIndicator() {\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const [phase, setPhase] = useState<Phase>(\"done\");\n  const api = useRef<{ save: () => void } | null>(null);\n\n  useEffect(() => {\n    const cv = canvas.current;\n    if (!cv) return;\n    const ctx = cv.getContext(\"2d\");\n    if (!ctx) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const dpr = Math.min(2, window.devicePixelRatio || 1) * 1.25;\n    cv.width = W * dpr; cv.height = H * dpr;\n    const tone = (rgb: number[], k: number, a = 1) => `rgba(${Math.min(255, rgb[0] * k) | 0},${Math.min(255, rgb[1] * k) | 0},${Math.min(255, rgb[2] * k) | 0},${a})`;\n    const rr = (c: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number | number[]) => {\n      const [a, b, d, e] = typeof r === \"number\" ? [r, r, r, r] : r;\n      c.beginPath(); c.moveTo(x + a, y); c.lineTo(x + w - b, y); c.arcTo(x + w, y, x + w, y + b, b); c.lineTo(x + w, y + h - d); c.arcTo(x + w, y + h, x + w - d, y + h, d); c.lineTo(x + e, y + h); c.arcTo(x, y + h, x, y + h - e, e); c.lineTo(x, y + a); c.arcTo(x, y, x + a, y, a); c.closePath();\n    };\n    let seed = 41;\n    const rand = () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; };\n    const grain = (c: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, n: number, light: string, dark: string, amt: number) => {\n      for (let i = 0; i < n; i++) { const v = rand(); c.fillStyle = v > 0.5 ? light.replace(\"A\", String((v - 0.5) * amt)) : dark.replace(\"A\", String((0.5 - v) * amt)); c.fillRect(x + rand() * w, y + rand() * h, 0.9, 0.9); }\n    };\n    // A blurred shadow with nothing drawn on top of it: the shape itself is parked far above the canvas.\n    const shade = (c: CanvasRenderingContext2D, path: () => void, color: string, blur: number, dx: number, dy: number) => {\n      c.save(); c.shadowColor = color; c.shadowBlur = blur * dpr; c.shadowOffsetX = dx * dpr; c.shadowOffsetY = (dy + 3000) * dpr; c.translate(0, -3000); path(); c.fillStyle = \"#000\"; c.fill(); c.restore();\n    };\n\n    // ---------- The drive: cable, case top, front face, slot ----------\n    const still = document.createElement(\"canvas\");\n    still.width = cv.width; still.height = cv.height;\n    const sc = still.getContext(\"2d\");\n    if (sc) {\n      sc.scale(dpr, dpr);\n      // Cable and its ribbed boot, leaving the back of the case.\n      sc.lineCap = \"round\";\n      const cab = sc.createLinearGradient(290, 0, 320, 0); cab.addColorStop(0, \"#8c908b\"); cab.addColorStop(0.4, \"#d9dcd6\"); cab.addColorStop(1, \"#7c807b\");\n      sc.strokeStyle = \"#a9ada7\"; sc.lineWidth = 10; sc.beginPath(); sc.moveTo(300, 36); sc.bezierCurveTo(300, 8, 336, 12, 368, -10); sc.stroke();\n      sc.strokeStyle = \"rgba(255,255,255,0.45)\"; sc.lineWidth = 2; sc.beginPath(); sc.moveTo(298, 34); sc.bezierCurveTo(298, 6, 334, 9, 366, -12); sc.stroke();\n      sc.lineCap = \"butt\";\n      sc.fillStyle = cab; rr(sc, 291, 18, 18, 24, 3); sc.fill();\n      for (let y = 21; y < 40; y += 4) { sc.fillStyle = \"rgba(0,0,0,0.28)\"; sc.fillRect(291, y, 18, 1.2); }\n\n      // Shadow the whole case throws on the table.\n      shade(sc, () => rr(sc, 66, 60, 308, 222, 12), \"rgba(2,16,16,0.75)\", 22, 6, 16);\n      shade(sc, () => rr(sc, 62, 240, 316, 42, 6), \"rgba(2,16,16,0.8)\", 7, 1, 5);\n\n      // Front face.\n      const ff = sc.createLinearGradient(0, 214, 0, 282); ff.addColorStop(0, tone(CASE, 0.93)); ff.addColorStop(0.5, tone(CASE, 0.84)); ff.addColorStop(1, tone(CASE, 0.68));\n      rr(sc, 60, 206, 320, 76, [0, 0, 7, 7]); sc.fillStyle = ff; sc.fill();\n      sc.save(); rr(sc, 60, 206, 320, 76, [0, 0, 7, 7]); sc.clip();\n      grain(sc, 60, 214, 320, 68, 5200, \"rgba(255,255,255,A)\", \"rgba(40,44,40,A)\", 0.3);\n      const ends = sc.createLinearGradient(60, 0, 380, 0); ends.addColorStop(0, \"rgba(255,255,255,0.3)\"); ends.addColorStop(0.03, \"rgba(255,255,255,0)\"); ends.addColorStop(0.96, \"rgba(0,0,0,0)\"); ends.addColorStop(1, \"rgba(0,0,0,0.3)\");\n      sc.fillStyle = ends; sc.fillRect(60, 214, 320, 68);\n      sc.fillStyle = \"rgba(0,0,0,0.3)\"; sc.fillRect(60, 280.6, 320, 1.4);\n      sc.restore();\n\n      // Top of the case.\n      const top = () => rr(sc, 60, 36, 320, 180, [15, 15, 3, 3]);\n      const tg = sc.createLinearGradient(60, 36, 300, 216); tg.addColorStop(0, tone(CASE, 0.96)); tg.addColorStop(0.5, tone(CASE, 1.06)); tg.addColorStop(1, tone(CASE, 1.13));\n      top(); sc.fillStyle = tg; sc.fill();\n      sc.save(); top(); sc.clip();\n      grain(sc, 60, 36, 320, 180, 15000, \"rgba(255,255,255,A)\", \"rgba(40,44,40,A)\", 0.34);\n      // Rolled edges: light along the front, shade along the back and right.\n      const fr = sc.createLinearGradient(0, 196, 0, 216); fr.addColorStop(0, \"rgba(255,255,255,0)\"); fr.addColorStop(0.75, \"rgba(255,255,255,0.55)\"); fr.addColorStop(1, \"rgba(255,255,255,0.2)\");\n      sc.fillStyle = fr; sc.fillRect(60, 196, 320, 20);\n      const bk = sc.createLinearGradient(0, 36, 0, 54); bk.addColorStop(0, \"rgba(30,34,30,0.42)\"); bk.addColorStop(1, \"rgba(30,34,30,0)\");\n      sc.fillStyle = bk; sc.fillRect(60, 36, 320, 18);\n      const rt = sc.createLinearGradient(364, 0, 380, 0); rt.addColorStop(0, \"rgba(30,34,30,0)\"); rt.addColorStop(1, \"rgba(30,34,30,0.36)\");\n      sc.fillStyle = rt; sc.fillRect(364, 36, 16, 180);\n      const lf = sc.createLinearGradient(60, 0, 72, 0); lf.addColorStop(0, \"rgba(255,255,255,0.5)\"); lf.addColorStop(1, \"rgba(255,255,255,0)\");\n      sc.fillStyle = lf; sc.fillRect(60, 36, 12, 180);\n      sc.restore();\n      // Raised panel over the mechanism: a soft step all the way round.\n      const panel = (x: number, y: number, w: number, h: number, r: number, raise: boolean) => {\n        sc.save(); rr(sc, x, y, w, h, r); sc.clip();\n        sc.lineWidth = 3; sc.strokeStyle = raise ? \"rgba(255,255,255,0.75)\" : \"rgba(20,24,20,0.5)\"; rr(sc, x + 1, y + 1.2, w, h, r); sc.stroke();\n        sc.strokeStyle = raise ? \"rgba(20,24,20,0.42)\" : \"rgba(255,255,255,0.8)\"; rr(sc, x - 1, y - 1.2, w, h, r); sc.stroke();\n        sc.restore();\n      };\n      sc.fillStyle = \"rgba(255,255,255,0.1)\"; rr(sc, 82, 104, 276, 92, 9); sc.fill();\n      panel(82, 104, 276, 92, 9, true);\n      // Shallow grooves moulded across the panel.\n      for (let y = 118; y < 188; y += 11) { sc.fillStyle = \"rgba(30,34,30,0.2)\"; sc.fillRect(96, y, 248, 1.1); sc.fillStyle = \"rgba(255,255,255,0.75)\"; sc.fillRect(96, y + 1.1, 248, 0.9); }\n      // Vent slots.\n      for (let i = 0; i < 9; i++) {\n        const x = 258 + i * 11;\n        rr(sc, x, 54, 5, 34, 2.5); sc.fillStyle = \"#1c1f1c\"; sc.fill();\n        sc.fillStyle = \"rgba(255,255,255,0.75)\"; sc.fillRect(x + 5, 56, 0.9, 30);\n        sc.fillStyle = \"rgba(0,0,0,0.5)\"; sc.fillRect(x - 0.8, 56, 0.8, 30);\n        const inner = sc.createLinearGradient(0, 54, 0, 88); inner.addColorStop(0, \"rgba(0,0,0,0.9)\"); inner.addColorStop(1, \"rgba(110,116,110,0.5)\");\n        rr(sc, x + 0.6, 54.6, 3.8, 32.8, 2); sc.fillStyle = inner; sc.fill();\n      }\n      // Recessed badge with the maker's name.\n      rr(sc, 82, 56, 112, 30, 4); sc.fillStyle = tone(CASE, 0.9); sc.fill(); panel(82, 56, 112, 30, 4, false);\n      sc.fillStyle = \"#2b302c\"; sc.textBaseline = \"middle\";\n      sc.font = '800 12.5px \"Helvetica Neue\", Helvetica, Arial, sans-serif';\n      let lx = 92; for (const ch of file.maker) { sc.fillText(ch, lx, 71.5); lx += sc.measureText(ch).width + 2.4; }\n      sc.fillStyle = \"#d9442a\"; sc.fillRect(lx + 3, 65, 3, 13);\n      sc.fillStyle = \"#4a504b\"; sc.font = '600 8.5px \"Helvetica Neue\", Helvetica, Arial, sans-serif'; sc.fillText(file.model, lx + 11, 72);\n      // Four screws in wells.\n      for (const [x, y] of [[74, 50], [366, 50], [74, 201], [366, 201]]) {\n        sc.beginPath(); sc.arc(x, y, 4.6, 0, Math.PI * 2); sc.fillStyle = \"rgba(24,28,24,0.75)\"; sc.fill();\n        sc.beginPath(); sc.arc(x + 0.5, y + 0.7, 4.6, 0, Math.PI * 2); sc.lineWidth = 0.8; sc.strokeStyle = \"rgba(255,255,255,0.7)\"; sc.stroke();\n        const sg = sc.createRadialGradient(x - 1, y - 1, 0, x, y, 3.4); sg.addColorStop(0, \"#e9ecee\"); sg.addColorStop(1, \"#6b7177\");\n        sc.beginPath(); sc.arc(x, y, 3.2, 0, Math.PI * 2); sc.fillStyle = sg; sc.fill();\n        sc.strokeStyle = \"rgba(20,22,24,0.85)\"; sc.lineWidth = 0.9; sc.beginPath(); sc.moveTo(x - 2, y - 0.6); sc.lineTo(x + 2, y + 0.6); sc.moveTo(x + 0.6, y - 2); sc.lineTo(x - 0.6, y + 2); sc.stroke();\n      }\n      // Front edge of the lid: the bright line where top meets face.\n      sc.fillStyle = \"rgba(255,255,255,0.85)\"; sc.fillRect(63, 214.6, 314, 1);\n      sc.fillStyle = \"rgba(30,34,30,0.28)\"; sc.fillRect(62, 216.2, 316, 1.2);\n\n      // Slot: a dished surround, then the dark mouth with a sprung flap just inside.\n      rr(sc, 96, 235, 248, 19, 6); sc.fillStyle = tone(CASE, 0.72); sc.fill(); panel(96, 235, 248, 19, 6, false);\n      const mouth = sc.createLinearGradient(0, 240, 0, 250); mouth.addColorStop(0, \"#040504\"); mouth.addColorStop(0.55, \"#1b1e1b\"); mouth.addColorStop(1, \"#3a3f3a\");\n      rr(sc, 100, 240, 240, 10, 2.5); sc.fillStyle = mouth; sc.fill();\n      sc.fillStyle = \"rgba(255,255,255,0.14)\"; sc.fillRect(102, 248.2, 236, 0.8);\n      // Lamp window, unlit.\n      rr(sc, 72, 259, 17, 9, 2); sc.fillStyle = \"#0d1a0e\"; sc.fill(); panel(72, 259, 17, 9, 2, false);\n      // Well the eject button lives in.\n      rr(sc, 345, 252, 26, 18, 3); sc.fillStyle = \"#141614\"; sc.fill(); panel(345, 252, 26, 18, 3, false);\n      // Small moulded legend under the slot, left of the button.\n      sc.fillStyle = \"rgba(40,46,40,0.6)\"; sc.font = '700 5.6px \"Helvetica Neue\", Helvetica, Arial, sans-serif'; sc.fillText(\"BUSY\", 72.5, 274.5); sc.fillText(\"EJECT\", 348, 276);\n    }\n\n    // ---------- The disk, drawn once ----------\n    const M = 8;\n    const disk = document.createElement(\"canvas\");\n    disk.width = (DW + M * 2) * dpr; disk.height = (DH + M * 2 + 6) * dpr;\n    const dc = disk.getContext(\"2d\");\n    if (dc) {\n      dc.scale(dpr, dpr); dc.translate(M, M);\n      const shell = (grow = 0) => { dc.beginPath(); dc.moveTo(5, -grow); dc.lineTo(DW - 13, -grow); dc.lineTo(DW + grow, 13); dc.lineTo(DW + grow, DH - 4); dc.arcTo(DW + grow, DH + grow, DW - 4, DH + grow, 4); dc.lineTo(4, DH + grow); dc.arcTo(-grow, DH + grow, -grow, DH - 4, 4); dc.lineTo(-grow, 5); dc.arcTo(-grow, -grow, 5, -grow, 5); dc.closePath(); };\n      // Front edge: the thickness of the shell, with the paper label wrapped over it.\n      dc.save(); dc.translate(0, 5.2); shell(); dc.fillStyle = tone(DISK, 0.5); dc.fill(); dc.restore();\n      dc.fillStyle = \"#b9b3a3\"; dc.fillRect(17, DH, 194, 5.2);\n      dc.fillStyle = \"rgba(0,0,0,0.25)\"; dc.fillRect(0, DH + 4.2, DW, 1);\n      const bg = dc.createLinearGradient(0, 0, DW, DH); bg.addColorStop(0, tone(DISK, 1.07)); bg.addColorStop(1, tone(DISK, 0.9));\n      shell(); dc.fillStyle = bg; dc.fill();\n      dc.save(); shell(); dc.clip();\n      grain(dc, 0, 0, DW, DH, 12000, \"rgba(255,230,210,A)\", \"rgba(70,14,0,A)\", 0.3);\n      // Shutter track, sunk a little below the shell.\n      dc.fillStyle = tone(DISK, 0.8); dc.fillRect(26, 0, 176, 72);\n      dc.fillStyle = \"rgba(60,10,0,0.5)\"; dc.fillRect(26, 72, 176, 1); dc.fillRect(26, 0, 1, 72);\n      dc.fillStyle = \"rgba(255,225,200,0.5)\"; dc.fillRect(26, 73, 176, 0.8); dc.fillRect(202, 0, 0.8, 72);\n      // Label recess running off the front edge.\n      rr(dc, 14, 86, 200, DH - 80, [7, 7, 0, 0]); dc.fillStyle = tone(DISK, 0.78); dc.fill();\n      dc.strokeStyle = \"rgba(60,10,0,0.5)\"; dc.lineWidth = 1; rr(dc, 14.5, 86.5, 199, DH - 80, [7, 7, 0, 0]); dc.stroke();\n      // Bevel all round the shell.\n      dc.lineWidth = 2.4; dc.strokeStyle = \"rgba(255,226,204,0.6)\"; dc.save(); dc.translate(1.1, 1.1); shell(); dc.stroke(); dc.restore();\n      dc.strokeStyle = \"rgba(70,14,0,0.5)\"; dc.save(); dc.translate(-1.1, -1.1); shell(); dc.stroke(); dc.restore();\n      dc.restore();\n      // Moulded arrow that shows which way in.\n      dc.beginPath(); dc.moveTo(13, 20); dc.lineTo(19, 30); dc.lineTo(15, 30); dc.lineTo(15, 40); dc.lineTo(11, 40); dc.lineTo(11, 30); dc.lineTo(7, 30); dc.closePath(); dc.fillStyle = tone(DISK, 0.72); dc.fill();\n      dc.strokeStyle = \"rgba(255,226,204,0.55)\"; dc.lineWidth = 0.7; dc.beginPath(); dc.moveTo(19.4, 30.6); dc.lineTo(15.4, 30.6); dc.lineTo(15.4, 40.6); dc.lineTo(11, 40.6); dc.stroke();\n      // Steel shutter with its window.\n      dc.save(); dc.shadowColor = \"rgba(50,8,0,0.6)\"; dc.shadowBlur = 3 * dpr; dc.shadowOffsetY = 1.5 * dpr; dc.fillStyle = \"#9aa1a7\"; dc.fillRect(64, 0, 114, 68); dc.restore();\n      const steel = dc.createLinearGradient(64, 0, 178, 0); steel.addColorStop(0, \"#aeb5ba\"); steel.addColorStop(0.2, \"#f3f5f6\"); steel.addColorStop(0.45, \"#c5cbd0\"); steel.addColorStop(0.7, \"#e7eaec\"); steel.addColorStop(1, \"#8d949a\");\n      dc.fillStyle = steel; dc.fillRect(64, 0, 114, 68);\n      for (let y = 0.4; y < 68; y += 0.9) { dc.fillStyle = `rgba(${rand() > 0.5 ? \"255,255,255\" : \"40,46,52\"},${0.05 + rand() * 0.11})`; dc.fillRect(64, y, 114, 0.5); }\n      dc.fillStyle = \"#17191b\"; dc.fillRect(84, 10, 26, 50);\n      dc.fillStyle = tone(DISK, 0.5); dc.fillRect(85, 11, 24, 48);\n      dc.fillStyle = \"rgba(255,255,255,0.8)\"; dc.fillRect(84, 60, 26, 0.8); dc.fillRect(64, 67.2, 114, 0.8);\n      dc.fillStyle = \"rgba(0,0,0,0.3)\"; dc.fillRect(64, 0, 0.8, 68); dc.fillRect(177.2, 0, 0.8, 68);\n      // Corner holes at the label end: the left one has its write tab closed.\n      for (const x of [5, 215]) { rr(dc, x, DH - 22, 8, 9, 1); dc.fillStyle = \"#0c1413\"; dc.fill(); dc.fillStyle = \"rgba(255,226,204,0.6)\"; dc.fillRect(x, DH - 12.6, 8, 0.7); }\n      dc.fillStyle = \"#26292b\"; dc.fillRect(5.6, DH - 21.4, 6.8, 5);\n      // Paper label: a colour band, ruled lines, a name in marker.\n      const paper = dc.createLinearGradient(17, 89, 211, DH); paper.addColorStop(0, \"#fbf7ec\"); paper.addColorStop(1, \"#ebe4d2\");\n      dc.save(); dc.shadowColor = \"rgba(50,8,0,0.45)\"; dc.shadowBlur = 2 * dpr; dc.shadowOffsetY = 1 * dpr; rr(dc, 17, 89, 194, DH - 88, [5, 5, 0, 0]); dc.fillStyle = paper; dc.fill(); dc.restore();\n      dc.save(); rr(dc, 17, 89, 194, DH - 88, [5, 5, 0, 0]); dc.clip();\n      grain(dc, 17, 89, 194, DH - 88, 2600, \"rgba(255,255,255,A)\", \"rgba(90,70,30,A)\", 0.22);\n      dc.fillStyle = \"#17605c\"; dc.fillRect(17, 89, 194, 19);\n      dc.fillStyle = \"#f6f1e4\"; dc.font = '700 6.6px \"Helvetica Neue\", Helvetica, Arial, sans-serif'; dc.textBaseline = \"middle\";\n      let tx = 25; for (const ch of `${file.maker}  2HD`) { dc.fillText(ch, tx, 99); tx += dc.measureText(ch).width + 1.6; }\n      dc.textAlign = \"right\"; dc.fillText(\"1.44 MB\", 203, 99); dc.textAlign = \"left\";\n      for (let y = 141; y < DH - 6; y += 26) { dc.fillStyle = \"rgba(60,110,150,0.4)\"; dc.fillRect(25, y, 178, 0.7); }\n      dc.translate(28, 136); dc.rotate(-0.035);\n      dc.fillStyle = \"#1c2a55\"; dc.font = '400 25px \"Marker Felt\", \"Bradley Hand\", \"Segoe Print\", \"Comic Sans MS\", cursive'; dc.textBaseline = \"alphabetic\";\n      dc.fillText(file.label[0], 0, 0);\n      dc.font = '400 19px \"Marker Felt\", \"Bradley Hand\", \"Segoe Print\", \"Comic Sans MS\", cursive'; dc.fillStyle = \"#b5321f\";\n      dc.fillText(file.label[1], 2, 28);\n      dc.restore();\n    }\n\n    // p: how far in the disk is (0 out on the table, 1 swallowed). e: how far the eject button stands out.\n    const s = { p: OUT, pv: 0, e: 0, ev: 0, lamp: 0, mode: \"done\" as \"done\" | \"push\" | \"write\" | \"eject\", clock: 0, jit: 0 };\n\n    const draw = () => {\n      ctx.setTransform(1, 0, 0, 1, 0, 0);\n      ctx.clearRect(0, 0, cv.width, cv.height);\n      ctx.drawImage(still, 0, 0);\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      const yTop = SLOT - s.p * DH, bottom = yTop + DH, vis = bottom - SLOT;\n\n      // Disk shadow, on the table only: the disk floats at slot height.\n      if (vis > 2) {\n        ctx.save(); ctx.beginPath(); ctx.rect(0, 282, W, H - 282); ctx.clip();\n        shade(ctx, () => rr(ctx, DX + 5, SLOT - 6, DW - 8, vis + 8, 6), \"rgba(2,14,14,0.62)\", 15, 7, 34);\n        ctx.restore();\n        // And a tighter one on the face of the drive under the slot.\n        ctx.save(); ctx.beginPath(); ctx.rect(60, 250, 320, 32); ctx.clip();\n        shade(ctx, () => rr(ctx, DX, SLOT, DW, Math.min(vis, 36), 2), \"rgba(10,14,10,0.5)\", 5, 3, 3);\n        ctx.restore();\n      }\n      // Disk, clipped at the mouth of the slot.\n      ctx.save(); ctx.beginPath(); ctx.rect(0, SLOT, W, H - SLOT); ctx.clip();\n      ctx.drawImage(disk, 0, 0, disk.width, disk.height, DX - M + s.jit, yTop - M, disk.width / dpr, disk.height / dpr);\n      const lip = ctx.createLinearGradient(0, SLOT, 0, SLOT + 13); lip.addColorStop(0, \"rgba(0,0,0,0.6)\"); lip.addColorStop(1, \"rgba(0,0,0,0)\");\n      if (vis > 0) { ctx.fillStyle = lip; ctx.fillRect(DX, SLOT, DW, Math.min(13, vis)); }\n      // A broad soft sheen that slides over the shell as it moves.\n      if (vis > 8) {\n        ctx.beginPath(); ctx.rect(DX, SLOT, DW, vis); ctx.clip();\n        const sh = ctx.createLinearGradient(DX - 40, SLOT + 40 + s.p * 120, DX + 200, SLOT + 250 + s.p * 120);\n        sh.addColorStop(0, \"rgba(255,255,255,0)\"); sh.addColorStop(0.45, \"rgba(255,255,255,0)\"); sh.addColorStop(0.55, \"rgba(255,255,255,0.13)\"); sh.addColorStop(0.66, \"rgba(255,255,255,0)\"); sh.addColorStop(1, \"rgba(255,255,255,0)\");\n        ctx.fillStyle = sh; ctx.fillRect(DX, SLOT, DW, vis);\n      }\n      ctx.restore();\n\n      // Eject button: its top shows as it stands out of the face.\n      const out = Math.max(-0.5, s.e) * 5.5, bx = 347, by = 254 + out;\n      if (out > 0.2) { ctx.fillStyle = tone(CASE, 1.1); rr(ctx, bx, 254, 22, out + 3, 2); ctx.fill(); }\n      shade(ctx, () => rr(ctx, bx, by, 22, 14, 2), \"rgba(0,0,0,0.6)\", 2 + Math.max(0, out) * 0.8, 0.8, 1 + Math.max(0, out) * 0.5);\n      const bf = ctx.createLinearGradient(0, by, 0, by + 14); bf.addColorStop(0, tone(CASE, 0.98)); bf.addColorStop(1, tone(CASE, 0.74));\n      rr(ctx, bx, by, 22, 14, 2); ctx.fillStyle = bf; ctx.fill();\n      ctx.fillStyle = \"rgba(255,255,255,0.7)\"; ctx.fillRect(bx + 1, by + 0.3, 20, 0.8);\n      ctx.fillStyle = \"rgba(30,34,30,0.45)\"; ctx.fillRect(bx + 6, by + 6.6, 10, 1.2);\n\n      // Busy lamp.\n      const L = s.lamp;\n      const lens = ctx.createLinearGradient(0, 260, 0, 267);\n      lens.addColorStop(0, `rgb(${(40 + 180 * L) | 0},${(70 + 185 * L) | 0},${(40 + 130 * L) | 0})`); lens.addColorStop(1, `rgb(${(14 + 70 * L) | 0},${(34 + 200 * L) | 0},${(16 + 60 * L) | 0})`);\n      rr(ctx, 73.2, 260.2, 14.6, 6.6, 1.4); ctx.fillStyle = lens; ctx.fill();\n      ctx.fillStyle = `rgba(255,255,255,${0.22 + 0.4 * L})`; ctx.fillRect(74.4, 261, 12, 1.2);\n      if (L > 0.02) {\n        ctx.save(); ctx.globalCompositeOperation = \"lighter\";\n        const g = ctx.createRadialGradient(80.5, 263.5, 0, 80.5, 263.5, 44); g.addColorStop(0, `rgba(150,255,130,${0.75 * L})`); g.addColorStop(0.25, `rgba(90,240,90,${0.26 * L})`); g.addColorStop(1, \"rgba(60,220,80,0)\");\n        ctx.fillStyle = g; ctx.fillRect(36, 219, 90, 90); ctx.restore();\n      }\n    };\n\n    let raf = 0, last = 0, seen = true, touched = -1e9, t0 = 0, nextEdit = 2.95, nextSave = 1e9;\n    const begin = () => { if (s.mode !== \"done\") return; s.mode = \"push\"; s.clock = 0; setPhase(\"busy\"); nextSave = 1e9; };\n    const step = (dt: number, t: number) => {\n      s.clock += dt;\n      if (s.mode === \"push\") {\n        s.pv += (95 * (IN + 0.03 - s.p) - 15 * s.pv) * dt; s.p += s.pv * dt;\n        if (s.p >= IN) { s.p = IN; s.pv = 0; s.mode = \"write\"; s.clock = 0; }\n      } else if (s.mode === \"write\") {\n        // The lamp follows a made-up pattern of head activity: bursts, with short rests.\n        const n = Math.sin(t * 31) + Math.sin(t * 17.3 + 1) + Math.sin(t * 7.1 + 2);\n        const on = s.clock < 0.18 ? 0 : n > -0.5 ? 1 : 0;\n        s.lamp += (on - s.lamp) * Math.min(1, dt * 60);\n        s.jit = on ? Math.sin(t * 190) * 0.25 : 0;\n        if (s.clock > WRITE_SECONDS) { s.mode = \"eject\"; s.clock = 0; s.jit = 0; s.pv = -1.5; setPhase(\"done\"); }\n      } else if (s.mode === \"eject\") {\n        s.lamp += (0 - s.lamp) * Math.min(1, dt * 14);\n        s.pv += (130 * (OUT - s.p) - 9.5 * s.pv) * dt; s.p += s.pv * dt;\n        if (s.clock > 0.5 && Math.abs(s.pv) < 0.01 && Math.abs(s.p - OUT) < 0.003) { s.p = OUT; s.pv = 0; s.mode = \"done\"; nextEdit = t + 3.2; }\n      }\n      // The button stands out while a disk is seated, and dips as it throws the disk back.\n      const want = s.mode === \"write\" ? 1 : s.mode === \"eject\" && s.clock < 0.13 ? -0.45 : 0;\n      s.ev += (420 * (want - s.e) - 19 * s.ev) * dt; s.e += s.ev * dt;\n    };\n    const frame = (now: number) => {\n      raf = 0;\n      if (!t0) { t0 = now; last = now; }\n      const dt = Math.min(0.033, (now - last) / 1000); last = now;\n      const t = (now - t0) / 1000;\n      if (now - touched > 7000 && s.mode === \"done\") {\n        if (t > nextEdit && nextSave > 1e8) { setPhase(\"dirty\"); nextSave = t + 1.3; }\n        if (t > nextSave) begin();\n      }\n      step(dt / 2, t); step(dt / 2, t);\n      draw();\n      if (seen && !document.hidden) raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { if (!raf && !reduce) { last = performance.now(); raf = requestAnimationFrame(frame); } };\n\n    let quiet = 0;\n    api.current = {\n      save: () => {\n        touched = performance.now();\n        if (!reduce) { begin(); wake(); return; }\n        // Reduced motion: no travel, just the three states in turn.\n        if (s.mode !== \"done\") return;\n        s.mode = \"write\"; s.p = IN; s.e = 1; s.lamp = 1; setPhase(\"busy\"); draw();\n        quiet = window.setTimeout(() => { s.mode = \"done\"; s.p = OUT; s.e = 0; s.lamp = 0; setPhase(\"done\"); draw(); }, WRITE_SECONDS * 1000);\n      },\n    };\n    if (reduce) draw(); else wake();\n\n    const io = new IntersectionObserver(([entry]) => { seen = entry.isIntersecting; if (seen) wake(); });\n    io.observe(cv);\n    const onVis = () => { if (!document.hidden) wake(); };\n    document.addEventListener(\"visibilitychange\", onVis);\n    return () => { cancelAnimationFrame(raf); window.clearTimeout(quiet); api.current = null; io.disconnect(); document.removeEventListener(\"visibilitychange\", onVis); };\n  }, []);\n\n  const busy = phase === \"busy\";\n\n  return (\n    <div className=\"flex min-h-[640px] w-full flex-col items-center justify-center bg-[#143a39] bg-[radial-gradient(85%_65%_at_50%_40%,#216260_0%,#143a39_72%)] px-4 py-8 sm:min-h-[800px]\">\n      <div className=\"relative h-[375px] w-[330px] sm:h-[600px] sm:w-[528px]\">\n        <canvas ref={canvas} aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full\" />\n        <button\n          type=\"button\"\n          tabIndex={-1}\n          aria-label=\"Push the disk in to save\"\n          onClick={() => api.current?.save()}\n          className=\"absolute left-[24%] top-[49%] h-[32%] w-[52%] cursor-pointer touch-manipulation outline-none\"\n        />\n      </div>\n      <div className=\"mt-1 flex flex-col items-center gap-4 sm:mt-0\">\n        <button\n          type=\"button\"\n          onClick={() => api.current?.save()}\n          aria-disabled={busy}\n          className={`h-11 rounded-full px-6 font-mono text-[12px] font-semibold uppercase tracking-[0.18em] outline-none transition-colors focus-visible:ring-2 focus-visible:ring-[#f4efe2] focus-visible:ring-offset-2 focus-visible:ring-offset-[#143a39] ${busy ? \"cursor-default bg-[#f4efe2]/20 text-[#f4efe2]\" : \"bg-[#f4efe2] text-[#143a39] hover:bg-white\"}`}\n        >\n          {busy ? \"Saving\" : \"Save changes\"}\n        </button>\n        <p role=\"status\" className=\"flex items-center gap-2 font-mono text-[11px] uppercase tracking-[0.2em] text-[#d5e4e1]\">\n          <span aria-hidden=\"true\" className={`inline-block h-1.5 w-1.5 rounded-full ${phase === \"dirty\" ? \"bg-[#ffb347]\" : busy ? \"bg-[#8dff7a]\" : \"bg-[#d5e4e1]/60\"}`} />\n          {words[phase]}\n        </p>\n      </div>\n    </div>\n  );\n}\n"}]}
