{
  "id": "light-trails-canvas",
  "kind": "element",
  "title": "Light trails canvas",
  "summary": "Streaks of coloured light rushing toward you along a night road, drawn with additive blending on a 2D canvas.",
  "url": "https://enrichr.dev/elements/light-trails-canvas.html",
  "section": "background",
  "techniques": [
    "parallax",
    "pointer-interaction"
  ],
  "stack": [
    "Vanilla JS",
    "Canvas"
  ],
  "frameworks": [
    "React",
    "Next.js",
    "Vanilla"
  ],
  "mood": [
    "energetic",
    "cinematic"
  ],
  "intents": [
    "light trails background",
    "highway speed lines animation",
    "hyperspace streaks canvas",
    "night road light streaks",
    "hold to accelerate effect"
  ],
  "status": "tested",
  "params": [
    {
      "key": "speed",
      "label": "Speed",
      "type": "range",
      "min": 0.2,
      "max": 3,
      "step": 0.1,
      "value": 1
    },
    {
      "key": "density",
      "label": "Light groups",
      "type": "range",
      "min": 10,
      "max": 200,
      "step": 5,
      "value": 90
    },
    {
      "key": "boost",
      "label": "Hold boost",
      "type": "range",
      "min": 1,
      "max": 4,
      "step": 0.1,
      "value": 2.4
    },
    {
      "key": "colorA",
      "label": "Right lane colour",
      "type": "color",
      "value": "#e6ff55"
    },
    {
      "key": "colorB",
      "label": "Left lane colour",
      "type": "color",
      "value": "#4de8b5"
    }
  ],
  "license": "Free to use in personal and client projects during the preview. Final licence terms will be published here before any paid tier starts; ask before reselling the code as a collection.",
  "contract": "function mount(root, opts) -> { update(partialOpts), destroy() }; root must contain the element markup",
  "exports": {
    "claude": "Add the \"Light trails canvas\" element to this project.\n\nThis is the \"Light trails canvas\" element from the Enrichr Library: Streaks of coloured light rushing toward you along a night road, drawn with additive blending on a 2D canvas.\nPage: https://enrichr.dev/elements/light-trails-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/light-trails-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nSteps:\n1. Look at the project first to see its framework and where components, styles and static files live. Follow its conventions.\n2. Fetch https://enrichr.dev/elements/light-trails-canvas.json if you can read URLs (fields: source.markup, source.css, source.js, params); otherwise use the source at the end of this message.\n3. Add the files, mount it where I tell you (default: the top of the home page), and pass the settings below as the opts.\n4. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n5. Run the dev server and check it. with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "chatgpt": "I want the \"Light trails canvas\" element on my website. Below is its complete source. Please:\n1. Build one self-contained index.html that I can open locally to see it working (put the CSS in a <style> tag and the JavaScript in a <script> tag, with the markup in the body).\n2. Then explain, step by step, which parts go where in my own site, and how to mount it. My stack is: [tell me yours, or say \"plain HTML\"].\n3. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nThis is the \"Light trails canvas\" element from the Enrichr Library: Streaks of coloured light rushing toward you along a night road, drawn with additive blending on a 2D canvas.\nPage: https://enrichr.dev/elements/light-trails-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/light-trails-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.",
    "cursor": "Add the \"Light trails canvas\" element to this codebase.\n\nThis is the \"Light trails canvas\" element from the Enrichr Library: Streaks of coloured light rushing toward you along a night road, drawn with additive blending on a 2D canvas.\nPage: https://enrichr.dev/elements/light-trails-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/light-trails-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nUse Composer / agent mode. First search the repo for how components, styles and scripts are organised, then add the files in the matching places, mount it on the page I name, and run the app to confirm it works. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.\n\nOptional: save this as .cursor/rules/enrichr-light-trails-canvas.mdc so the rule stays with the project:\n---\ndescription: How to use the Enrichr Light trails canvas element\nalwaysApply: false\n---\nmount(root, opts) expects the element markup inside root and returns { update, destroy }. Always call destroy() on unmount and never edit the ef- class names.",
    "v0": "Create a Next.js (App Router) client component for the \"Light trails canvas\" element. Tailwind is available but this component needs no utility classes.\n\nThis is the \"Light trails canvas\" element from the Enrichr Library: Streaks of coloured light rushing toward you along a night road, drawn with additive blending on a 2D canvas.\nPage: https://enrichr.dev/elements/light-trails-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/light-trails-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles to create:\n- light-trails-canvas.js : the JavaScript below, with one line appended at the end: export { mount };  (and the markup exported as: export const markup = \"<the markup string>\";). If the project uses TypeScript and does not allow JS imports, put // @ts-nocheck on the first line.\n- the CSS below goes in your global stylesheet (or a plain .css file imported once at the app root). The class names are global and start with ef-.\n\nUse this component as the wrapper (adjust the import paths):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./light-trails-canvas\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function LightTrailsCanvas(props: Record<string, unknown>) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n```\n\nRender it on the home page so I can see it. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "lovable": "Add the \"Light trails canvas\" element to this React + Vite + TypeScript + Tailwind project. Do not install any packages.\n\nThis is the \"Light trails canvas\" element from the Enrichr Library: Streaks of coloured light rushing toward you along a night road, drawn with additive blending on a 2D canvas.\nPage: https://enrichr.dev/elements/light-trails-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/light-trails-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles to create:\n- light-trails-canvas.js : the JavaScript below, with one line appended at the end: export { mount };  (and the markup exported as: export const markup = \"<the markup string>\";). If the project uses TypeScript and does not allow JS imports, put // @ts-nocheck on the first line.\n- the CSS below goes in your global stylesheet (or a plain .css file imported once at the app root). The class names are global and start with ef-.\n\nWrapper component (src/components/LightTrailsCanvas.tsx):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./light-trails-canvas\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function LightTrailsCanvas(props: Record<string, unknown>) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n```\n\nRemove the \"use client\" line if it is not needed. Show it on the home page. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "bolt": "Create a small Vite project (vanilla JavaScript, no framework unless I already have one) that shows the \"Light trails canvas\" element.\n\nThis is the \"Light trails canvas\" element from the Enrichr Library: Streaks of coloured light rushing toward you along a night road, drawn with additive blending on a 2D canvas.\nPage: https://enrichr.dev/elements/light-trails-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/light-trails-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles: index.html (a container element, then a script tag), style.css (the CSS below), light-trails-canvas.js (the JavaScript below) and main.js that sets the container's innerHTML to the markup and calls mount(container, opts) with the settings below. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.",
    "replit": "Create a new HTML, CSS and JavaScript Repl that shows the \"Light trails canvas\" element. No packages, no server code.\n\nThis is the \"Light trails canvas\" element from the Enrichr Library: Streaks of coloured light rushing toward you along a night road, drawn with additive blending on a 2D canvas.\nPage: https://enrichr.dev/elements/light-trails-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/light-trails-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles: index.html (a container element, link style.css, load light-trails-canvas.js and then main.js), style.css (the CSS below), light-trails-canvas.js (the JavaScript below), main.js (sets the container's innerHTML to the markup, then calls mount(container, opts) with the settings below). Press Run to preview. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "figma": "Designer handoff notes for the \"Light trails canvas\" element (Enrichr Library). Figma cannot run this JavaScript inside a design file, so use it as a motion reference and hand the code to a developer.\n\nThis is the \"Light trails canvas\" element from the Enrichr Library: Streaks of coloured light rushing toward you along a night road, drawn with additive blending on a 2D canvas.\nPage: https://enrichr.dev/elements/light-trails-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/light-trails-canvas.json\n\nWhat it does: Every light has a position on a flat road and a distance from the viewer. Each frame the distance shrinks, and a simple perspective divide turns the head and the tail of the light into two screen points that are joined with a gradient stroke. Strokes use the lighter composite mode so overlapping streaks add up to brighter light, and each one is drawn twice, wide and faint then thin and bright, for a cheap glow. Holding the pointer, or Space or Enter while the element has focus, eases a speed multiplier up and releasing eases it back.\nAccessibility: The canvas is decorative and carries a text description, including how to hold to accelerate. The element is focusable so keyboard users can speed it up with Space or Enter. Reduced motion draws one still frame, hides the hint and ignores holding.\n\nTunable settings:\n- Speed: range 0.2 to 3, step 0.1, default 1\n- Light groups: range 10 to 200, step 5, default 90\n- Hold boost: range 1 to 4, step 0.1, default 2.4\n- Right lane colour: color, default #e6ff55\n- Left lane colour: color, default #4de8b5\n\nCurrent settings:\n{{SETTINGS}}\n\nFor the developer: Element contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nIn Figma:\n- Draw the resting state as a frame and the end state as a second frame; link them with Smart Animate to show the motion in a prototype.\n- Put the settings above in the frame's notes or Dev Mode annotations so the developer matches them.\n- Link https://enrichr.dev/elements/light-trails-canvas.html in the handoff: the live demo and the copy-ready code are there. Developers can paste the prompts for Claude, Cursor or v0 from the Export menu.\nNothing is copied from another designer's file; this is original code from Enrichr.",
    "framer": "Add the \"Light trails canvas\" element to Framer as a code component. Framer code components are React, so wrap the vanilla code like this. Check it in the Framer editor, as Framer's component API can change.\n\nThis is the \"Light trails canvas\" element from the Enrichr Library: Streaks of coloured light rushing toward you along a night road, drawn with additive blending on a 2D canvas.\nPage: https://enrichr.dev/elements/light-trails-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/light-trails-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\n1. In Framer: Assets > Code > New component. Name it LightTrailsCanvas.\n2. Paste the JavaScript below into a separate code file named light-trails-canvas.js in the same project, with  export { mount };  and  export const markup = \"<the markup string>\";  added. Put the CSS into the component as a <style> tag.\n3. Component:\n```tsx\nimport { addPropertyControls, ControlType } from \"framer\"\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./light-trails-canvas\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function LightTrailsCanvas(props: any) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n\naddPropertyControls(LightTrailsCanvas, {\n  speed: { type: ControlType.Number, title: \"Speed\", min: 0.2, max: 3, step: 0.1, defaultValue: 1 },\n  density: { type: ControlType.Number, title: \"Light groups\", min: 10, max: 200, step: 5, defaultValue: 90 },\n  boost: { type: ControlType.Number, title: \"Hold boost\", min: 1, max: 4, step: 0.1, defaultValue: 2.4 },\n  colorA: { type: ControlType.Color, title: \"Right lane colour\", defaultValue: \"#e6ff55\" },\n  colorB: { type: ControlType.Color, title: \"Left lane colour\", defaultValue: \"#4de8b5\" },\n})\n```\n4. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "webflow": "Add the \"Light trails canvas\" element to a Webflow site with an Embed element. Test it on the published or preview site: scripts in embeds may not run inside the Designer canvas.\n\nThis is the \"Light trails canvas\" element from the Enrichr Library: Streaks of coloured light rushing toward you along a night road, drawn with additive blending on a 2D canvas.\nPage: https://enrichr.dev/elements/light-trails-canvas.html\nMachine-readable spec: https://enrichr.dev/elements/light-trails-canvas.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\n1. Add an Embed element where it should appear. Paste a <style> block with the CSS, one container <div id=\"enrichr-light-trails-canvas\"></div>, and a <script> block with the JavaScript followed by:\n   mount(document.getElementById(\"enrichr-light-trails-canvas\"), { ...your settings... });\n   (set the container's innerHTML to the markup first, as in the contract).\n2. Embed elements have a size limit (check Webflow's current number). If the code is longer, host the JS and CSS as files and link them from Custom code in the page settings, then keep only the container and the mount call in the Embed.\n3. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}"
  },
  "exportTools": [
    "claude",
    "chatgpt",
    "cursor",
    "v0",
    "lovable",
    "bolt",
    "replit",
    "figma",
    "framer",
    "webflow"
  ],
  "accessibility": "The canvas is decorative and carries a text description, including how to hold to accelerate. The element is focusable so keyboard users can speed it up with Space or Enter. Reduced motion draws one still frame, hides the hint and ignores holding.",
  "performance": "Roughly two strokes and one gradient per light per frame, so the default 90 groups is a few hundred draw calls on a 2D canvas. Pixel ratio is capped at 1.5 and the loop pauses off screen. Lower the density on low-end phones.",
  "dependencies": [],
  "source": {
    "markup": "<div class=\"ef-lt\" tabindex=\"0\" role=\"img\" aria-label=\"Streaks of coloured light rushing toward you along a night road. Hold the pointer or press and hold Space to speed up.\">\n  <canvas class=\"ef-lt__c\" aria-hidden=\"true\"></canvas>\n  <span class=\"ef-lt__hint\" aria-hidden=\"true\">Hold to accelerate</span>\n</div>",
    "css": "/* Enrichr Library · https://enrichr.dev */\n.ef-lt { position: relative; width: 100%; min-height: 20rem; overflow: hidden; border-radius: 1rem; background: #0c1e18; outline: none; cursor: pointer; touch-action: pan-y; user-select: none; -webkit-user-select: none; font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; }\n.ef-lt:focus-visible { box-shadow: inset 0 0 0 3px #e6ff55; }\n.ef-lt__c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }\n.ef-lt__hint { position: absolute; left: 50%; bottom: 0.9rem; transform: translateX(-50%); padding: 0.25rem 0.7rem; border-radius: 999px; border: 1px solid rgba(251, 248, 241, 0.35); color: rgba(251, 248, 241, 0.85); background: rgba(12, 30, 24, 0.5); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; pointer-events: none; transition: opacity 0.4s; }\n.ef-lt.is-held .ef-lt__hint { opacity: 0; }",
    "js": "// Enrichr Library · https://enrichr.dev\n// Light trails canvas: streaks of coloured light rush toward the viewer along a night road in simple perspective, drawn on a 2D canvas with additive blending.\n// Hold the pointer (or press and hold Space or Enter while it has focus) to accelerate; releasing eases back. Reduced motion draws one still frame and ignores holding.\n// mount(root, { speed (0.2-3), density (number of light groups, 10-200), boost (hold speed multiplier, 1-4), colorA (right lane lights), colorB (left lane lights) })\nfunction mount(root, o) {\n  var reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  var wrap = root.querySelector(\".ef-lt\");\n  var canvas = root.querySelector(\".ef-lt__c\");\n  var ctx = canvas.getContext(\"2d\");\n  var opts = {}, cars = [], raf = 0, visible = true, io = null, ro = null, held = false, cur = 1, dist = 0, last = 0, destroyed = false;\n  var W = 1, H = 1, f = 300, cx = 0, cy = 0, dpr = 1, seed = 20261106;\n  var ZMAX = 2.6, GR = 0.5;\n\n  function rnd() { seed = (seed * 1664525 + 1013904223) >>> 0; return seed / 4294967296; }\n  function rgb(h, d) {\n    var m = /^#?([0-9a-f]{6})$/i.exec(h || \"\"); var v = parseInt(m ? m[1] : d, 16);\n    return [v >> 16, (v >> 8) & 255, v & 255];\n  }\n  function pre(c) { return \"rgba(\" + c[0] + \",\" + c[1] + \",\" + c[2] + \",\"; }\n  function hot(c) { return \"rgba(\" + Math.round(c[0] + (255 - c[0]) * 0.65) + \",\" + Math.round(c[1] + (255 - c[1]) * 0.65) + \",\" + Math.round(c[2] + (255 - c[2]) * 0.65) + \",\"; }\n\n  function respawn(c, initial) {\n    var r = rnd(), side = rnd() < 0.5 ? -1 : 1, col = side < 0 ? opts._b : opts._a;\n    if (rnd() < 0.12) col = [251, 248, 241];\n    if (r < 0.22) {\n      c.X = (rnd() * 2 - 1) * 5.5; c.Y = -0.7 + rnd() * 1.0; c.pair = 0; c.v = 0.9 + rnd() * 0.9; c.L = 0.7 + rnd() * 0.8; c.thick = 0.45 + rnd() * 0.4;\n    } else {\n      c.X = side * (0.55 + Math.floor(rnd() * 3) * 0.95 + (rnd() - 0.5) * 0.08); c.Y = GR - 0.05 - rnd() * 0.12; c.pair = 0.2; c.v = 0.7 + rnd() * 0.75; c.L = 0.4 + rnd() * 0.7; c.thick = 1;\n    }\n    c.col = pre(col); c.hot = hot(col);\n    c.z = initial ? 0.07 + rnd() * (ZMAX - 0.07) : ZMAX + rnd() * 0.8;\n  }\n  function build() {\n    var n = Math.round(opts.density);\n    while (cars.length > n) cars.pop();\n    while (cars.length < n) { var c = {}; respawn(c, true); cars.push(c); }\n    cars.forEach(function (c, i) { var side = c.X < 0 ? opts._b : opts._a; if (c.col.indexOf(\"251,248,241\") < 0) { c.col = pre(side); c.hot = hot(side); } });\n  }\n  function size() {\n    dpr = Math.min(window.devicePixelRatio || 1, 1.5);\n    W = Math.max(1, wrap.clientWidth); H = Math.max(1, wrap.clientHeight);\n    canvas.width = Math.round(W * dpr); canvas.height = Math.round(H * dpr);\n    f = Math.max(W * 0.32, H * 0.55); cx = W / 2; cy = H * 0.42;\n    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n  }\n\n  function drawRoad(A, spd) {\n    var bg = ctx.createLinearGradient(0, 0, 0, H);\n    bg.addColorStop(0, \"#06110d\"); bg.addColorStop(cy / H, \"#0e2820\"); bg.addColorStop(Math.min(1, cy / H + 0.02), \"#0a1d17\"); bg.addColorStop(1, \"#040b08\");\n    ctx.globalCompositeOperation = \"source-over\";\n    ctx.globalAlpha = 1; ctx.fillStyle = bg; ctx.fillRect(0, 0, W, H);\n    ctx.globalCompositeOperation = \"lighter\";\n    var glow = ctx.createRadialGradient(cx, cy, 0, cx, cy, Math.max(W, H) * 0.55);\n    var ga = 0.2 + Math.min(0.25, (spd - 0.6) * 0.1);\n    glow.addColorStop(0, pre(A) + ga + \")\"); glow.addColorStop(0.35, pre(A) + ga * 0.3 + \")\"); glow.addColorStop(1, pre(A) + \"0)\");\n    ctx.fillStyle = glow; ctx.fillRect(0, 0, W, H);\n    ctx.lineCap = \"butt\";\n    var zn = 0.25, ex, ey, gr, k, lw, i, P = 0.32, z0, za, zb, x1, y1, x2, y2;\n    for (i = -1; i <= 1; i += 2) {\n      ex = cx + i * 3.1 / zn * f; ey = cy + GR / zn * f;\n      gr = ctx.createLinearGradient(cx, cy, ex, ey); gr.addColorStop(0, pre(A) + \"0)\"); gr.addColorStop(1, pre(A) + \"0.5)\");\n      ctx.strokeStyle = gr; ctx.lineWidth = 1.5; ctx.beginPath(); ctx.moveTo(cx, cy); ctx.lineTo(ex, ey); ctx.stroke();\n    }\n    z0 = (((-dist % P) + P) % P) + 0.1;\n    ctx.strokeStyle = \"rgba(251,248,241,0.5)\";\n    var divs = [-2, -1, 1, 2];\n    for (k = 0; k < divs.length; k++) {\n      var bx = divs[k];\n      for (za = z0; za < 3.4; za += P) {\n        zb = za + P * 0.42;\n        x1 = cx + bx / za * f; y1 = cy + GR / za * f; x2 = cx + bx / zb * f; y2 = cy + GR / zb * f;\n        lw = Math.max(0.5, 0.014 * f / za);\n        ctx.globalAlpha = Math.min(0.5, 0.8 / (za * 2.2)) * (Math.abs(bx) > 1 ? 0.6 : 1);\n        ctx.lineWidth = lw; ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke();\n      }\n    }\n    ctx.globalAlpha = 1;\n  }\n  function render() {\n    var A = opts._a, lenScale = 0.65 + 0.35 * cur;\n    drawRoad(A, opts.speed * cur);\n    ctx.globalCompositeOperation = \"lighter\";\n    ctx.lineCap = \"round\";\n    for (var i = 0; i < cars.length; i++) {\n      var c = cars[i], zh = c.z, zt = c.z + c.L * lenScale, n = c.pair ? 2 : 1;\n      var a = Math.min(1, Math.max(0.12, 1.3 - zh * 0.45));\n      for (var j = 0; j < n; j++) {\n        var X = c.pair ? c.X + (j ? c.pair : -c.pair) : c.X;\n        var hx = cx + X / zh * f, hy = cy + c.Y / zh * f, tx = cx + X / zt * f, ty = cy + c.Y / zt * f;\n        var lw = Math.max(0.7, c.thick * 0.011 * f / zh);\n        var g = ctx.createLinearGradient(hx, hy, tx, ty);\n        g.addColorStop(0, c.hot + a + \")\"); g.addColorStop(0.28, c.col + a * 0.8 + \")\"); g.addColorStop(1, c.col + \"0)\");\n        ctx.strokeStyle = g;\n        ctx.beginPath(); ctx.moveTo(hx, hy); ctx.lineTo(tx, ty);\n        ctx.lineWidth = lw * 3.4; ctx.globalAlpha = 0.18; ctx.stroke();\n        ctx.lineWidth = lw; ctx.globalAlpha = 1; ctx.stroke();\n      }\n    }\n    ctx.globalAlpha = 1; ctx.globalCompositeOperation = \"source-over\";\n  }\n  function step(dt) {\n    var target = held ? opts.boost : 1;\n    cur += (target - cur) * Math.min(1, dt * (held ? 2.2 : 1.6));\n    var s = opts.speed * cur * 0.55 * dt;\n    dist += s;\n    for (var i = 0; i < cars.length; i++) {\n      var c = cars[i]; c.z -= c.v * s;\n      if (c.z < 0.07 || Math.abs(c.X / c.z * f) > W * 0.9 + 80) respawn(c, false);\n    }\n  }\n  function loop(now) {\n    raf = requestAnimationFrame(loop);\n    var dt = Math.min(0.05, (now - last) / 1000 || 0.016); last = now;\n    if (!visible || document.hidden) return;\n    step(dt); render();\n  }\n  function setHeld(v) { if (reduce) return; held = v; wrap.classList.toggle(\"is-held\", v); }\n  function down(e) { if (e.button !== undefined && e.button > 0) return; setHeld(true); }\n  function up() { setHeld(false); }\n  function kd(e) { if (e.key === \" \" || e.key === \"Enter\") { setHeld(true); e.preventDefault(); } }\n  function ku(e) { if (e.key === \" \" || e.key === \"Enter\") setHeld(false); }\n  function update(next) {\n    opts = Object.assign({ speed: 1, density: 90, boost: 2.4, colorA: \"#e6ff55\", colorB: \"#4de8b5\" }, opts, next || {});\n    opts._a = rgb(opts.colorA, \"e6ff55\"); opts._b = rgb(opts.colorB, \"4de8b5\");\n    build();\n    if (reduce && !destroyed) render();\n  }\n\n  size();\n  update(o);\n  if (reduce) { render(); var h = root.querySelector(\".ef-lt__hint\"); if (h) h.style.display = \"none\"; }\n  else {\n    wrap.addEventListener(\"pointerdown\", down);\n    window.addEventListener(\"pointerup\", up);\n    window.addEventListener(\"pointercancel\", up);\n    wrap.addEventListener(\"keydown\", kd);\n    wrap.addEventListener(\"keyup\", ku);\n    wrap.addEventListener(\"blur\", up);\n    wrap.addEventListener(\"contextmenu\", up);\n    if (\"IntersectionObserver\" in window) { io = new IntersectionObserver(function (e) { visible = e[0].isIntersecting; }); io.observe(wrap); }\n    last = performance.now(); raf = requestAnimationFrame(loop);\n  }\n  if (\"ResizeObserver\" in window) {\n    ro = new ResizeObserver(function () { if (destroyed) return; size(); if (reduce) render(); });\n    ro.observe(wrap);\n  }\n  return {\n    update: update,\n    destroy: function () {\n      destroyed = true; cancelAnimationFrame(raf);\n      wrap.removeEventListener(\"pointerdown\", down); window.removeEventListener(\"pointerup\", up); window.removeEventListener(\"pointercancel\", up);\n      wrap.removeEventListener(\"keydown\", kd); wrap.removeEventListener(\"keyup\", ku); wrap.removeEventListener(\"blur\", up); wrap.removeEventListener(\"contextmenu\", up);\n      if (io) io.disconnect();\n      if (ro) ro.disconnect();\n    }\n  };\n}"
  }
}