# Selection Box Animation

Motionboard shot name: Resize Reflow

A title, Captions that keep up, sits in a blue selection box with eight handles on a dotted canvas. A cursor drags the right handle in and the text re-wraps to two lines and then three, then drags the corner out and the text returns to two lines at a larger size. The box fades, the type shrinks into a tagline and the Glyph lockup settles.

- Position in a launch film: Opening
- Slug: selection-box-animation
- Preview video: https://media.motionboard.app/bounding-box.mp4
- Recipe page: https://motionboard.app/recipes/selection-box-animation/
- License: MIT. Free to use in your own projects, including commercial launch films. https://github.com/krisyangdev/motionboard/blob/main/LICENSE

## How to use this recipe

You are a coding agent. The user wants this shot for their own product. Follow these steps.

1. **Know the product.** If the product is clear from the user's repo or conversation, ask nothing and start. Otherwise ask once for: product name, logo file, brand colors.
2. **Pick the output.** If the user's message says a video or their website, do that. Otherwise ask once which one they want.
   - **Video (HyperFrames).** Create a folder named `bounding-box`. Download every file under "Source files" below with the curl commands, keeping relative paths. Adapt `index.html` (see "What to adapt"). Run `npx --yes hyperframes@0.8.209 check` on the untouched copy first and note its result. Preview with `npx --yes hyperframes@0.8.209 preview`, render an MP4 with `npx --yes hyperframes@0.8.209 render` (into `renders/`, named with a timestamp). The same commands are in `package.json` as `dev`, `check`, `render`; pass flags after `--`, as in `npm run render -- --quality draft`. Rendering needs network access for web fonts and GSAP.
   - **Website motion.** Port the GSAP timeline in `index.html` into the user's site, using their stack (React, Vue, Svelte, plain HTML). Build the same DOM structure, keep the timeline's durations, delays and easings exactly, and start it when the element scrolls into view (IntersectionObserver or ScrollTrigger). Respect `prefers-reduced-motion: reduce`: show the final frame as a static state and skip the movement.
3. **What to adapt.**
   - **Brand layer** (product name, logo, colors, fonts, copy): replace directly with the user's.
   - **UI layer** (the product screens, cards, windows, controls shown in the shot): rebuild the user's real UI as clean DOM, from their codebase (components, design tokens) or from a screenshot used as reference only. Never paste a screenshot into the shot.
   - **Motion** (timing, easing, camera moves, layering, stagger, order of events): keep exactly as in the source. This is what the recipe is.
   - The timeline targets UI elements by id and class, and camera moves land on fixed coordinates. Keep the ids the timeline uses, keep row counts and text lengths close to the source, and when the layout moves, update the target coordinates without changing the times.
4. **Fonts.** HyperFrames fetches Google Fonts such as Inter on its own. Some sources use macOS local fonts (PingFang, Songti via `local()`). Use the user's brand font when it can be bundled; for a system font such as SF Pro, use Inter. Check that text still fits its boxes.
5. **Verify.** Compare the render with the preview video above at the beat times in the Timing row. The beats, timing and camera should match; only brand and UI content differ.

## Spec

| Item | Value |
| --- | --- |
| Timing | Film 11s. Words rise 0.15–1.25s (0.85s each, 0.1s stagger); outline draws 0.55–1.4s, fill fades in 1.0–1.5s; eight handles pop 1.25–2.0s (0.4s each, 0.05s stagger); size label fades in 1.7–2.1s; cursor flies in 1.5–2.1s and presses the right-middle handle at 2.1s; drag A 2.3–3.0s (W 1280→980, one line to two lines); drag B 4.0–4.7s (W 980→690, two lines to three); release at 4.8s; cursor moves to the bottom-right corner 4.95–5.6s and presses at 5.6s; drag C 5.85–6.65s (W 690→1260, text grows 1.0x→1.45x and returns to two lines around 6.3s); release 6.7s, cursor leaves 6.7–7.3s; box fades 7.3–7.7s; chrome fades 7.9–8.3s; title shrinks into the tagline 7.9–8.5s; mark 8.3–8.75s, wordmark letters 8.28–8.74s; the lockup holds still 8.75–11s |
| Easing | Drags A and B use power2.inOut and drag C uses power1.inOut; a line-break change eases each word with power3.inOut over 0.4s; words rise and settle with expo.out; the outline draws with power2.inOut; handles pop with back.out(2.4); cursor approach uses power3.out, the corner move power2.inOut and the exit power2.in; title to tagline uses expo.inOut over 0.6s; the mark uses back.out(1.8) and the wordmark letters power3.out |
| Camera | Locked, flat 2D with no camera move. The box always scales from its centre at (960, 520), so both edges move when a handle is dragged and the composition stays centred. The font size itself grows 1.45x during drag C and the box height follows the line count |
| Subject | Title Captions that keep up in Inter 700, tracking −0.04em, line height 1.04, sized so one line fits a 1150px measure (about 116px); box starts at 1280x255px with 60px side padding and 66px top and bottom padding; 3px #2f6bff outline, fill rgba(47,107,255,0.055), eight 18px white handles with a 3px blue border and 3px radius; label pill under the box with 28px 600 white text, W 1280 · H 255, rewritten every frame; cursor a 46x64px black arrow with a white outline, scale 0.86 while pressed; final box 1260x488px with the title at about 170px; tagline 44px #5d5d66 centred at y 650; mark 150px blue squircle with a white G, wordmark Glyph at 140px weight 700 and −0.045em tracking, gap 38px, row centred at y 450 |
| Sync | Width, line breaks, font size, box height, label text and handle positions are all computed from one render(t), so they change on the same frame; the cursor tip is locked to its handle through every drag; the line break changes the moment the inner width (W − 120px) no longer fits the line; the handle turns solid blue 0.02s after the press; the box is gone at 7.7s before the title starts to move at 7.9s, and the mark lands at 8.3s after the tagline words have arrived |
| Style | Background `#eceef1` with a 40px grid of dots `rgba(30,44,74,0.2)`, a faint white centre glow and a vignette reaching 10% at the edges; one accent blue `#2f6bff`, ink `#0e1014`, grey `#5d5d66`; Inter throughout; white tool chrome (breadcrumb, zoom pill, Share button, six-tool bar) with 16–24px corners and soft shadows; no film grain |

## Why it works

The box works as a small layout engine: one width W goes in, and the line breaks, font size, box height, size label and cursor position all come out of it on the same frame, so the viewer reads a real design tool resizing a text layer. Each state is held for at least 1.2s: one line, two lines (Captions that / keep up), three lines (Captions / that keep / up), then two lines again at 1.45x the size. A word never jumps. When a break changes, every word eases to its new place over 0.4s and the box height follows the line count. The cursor tip stays on the handle it grabbed, the handle turns solid blue while it is held, and the W and H label counts down and up with the drag, so cause and effect sit in the same place on screen. The wrap rule is short enough to describe in one sentence: one line if it fits, two lines if both halves fit, otherwise fill each line greedily. The film uses one accent color, blue #2f6bff, on a light dotted canvas, so the outline and the handles are the only saturated marks. After the last drag the box fades, the title shrinks into the 44px tagline line and the Glyph mark and wordmark settle above it, so the same type carries the film from start to end.

## Prompt

> Build an 11-second, 1920x1080, 30 fps light film called Selection Box Animation for a fictional product, Glyph (an AI captions tool), with HyperFrames and one paused GSAP timeline. Canvas #eceef1 with a 40px grid of faint dots rgba(30,44,74,0.2) and a soft vignette; one accent color, blue #2f6bff; ink #0e1014; font Inter. The title Captions that keep up is four absolutely positioned word spans, Inter 700, tracking −0.04em, line height 1.04, sized so the whole line fits a 1150px measure (about 116px). Measure each word once per frame with offsetWidth at 400px and scale it. Put all state in one render(t) function driven by a linear proxy tween from 0 to 11s, with no CSS animations. Box: centred at (960, 520), width W(t), height = lines x 1.04 x font size + 132px, drawn as an SVG rect with a 3px stroke, pathLength 1 and stroke-dashoffset, a fill rgba(47,107,255,0.055), eight 18px white handles with a 3px blue border, and under it a blue pill label with 28px 600 white text, W 1280 · H 255, rewritten every frame from W and H. W(t): 1280 until 2.3s; to 980 over 2.3–3.0s (power2.inOut); hold; to 690 over 4.0–4.7s (power2.inOut); hold; to 1260 over 5.85–6.65s (power1.inOut) while the font scale k = 1 + 0.45c² grows to 1.45, where c is the eased drag progress. Wrap rule from W and k with inner width W − 120: one line if it fits; else two lines Captions that / keep up if both fit; else fill lines greedily, which gives Captions / that keep / up. When the breaks change, find the latest change in the last 0.4s by evaluating the rule at earlier times, and ease each word from its old to its new place with power3.inOut over 0.4s; the box height follows the blended line count. Timeline: words rise 0.15–1.25s (y 38→0, blur 12→0, expo.out, 0.1s stagger); outline draws 0.55–1.4s, fill fades in 1.0–1.5s; handles pop 1.25–2.0s (back.out(2.4), 0.05s stagger, clockwise from top left); label fades in 1.7–2.1s. Cursor: a 46x64px black arrow with a white outline flies in 1.5–2.1s on a curved path (power3.out) to the right-middle handle, presses at 2.1s (scale 0.86, the handle turns solid blue and grows 1.35x), stays locked to the handle through both drags and releases at 4.8s; it moves to the bottom-right corner 4.95–5.6s (power2.inOut), presses at 5.6s, rides the corner through the last drag, releases at 6.7s and leaves by 7.3s. Hold each state at least 1.2s. The box fades 7.3–7.7s and the tool chrome (breadcrumb, zoom, Share, bottom bar of six tools) fades 7.9–8.3s. During 7.9–8.5s the four words move and shrink into one 44px line in #5d5d66 centred at y 650 (expo.inOut): that line is the tagline. The lockup lands after it: a 150px blue squircle mark with a white G pops in 8.3–8.75s (back.out(1.8)) and the word Glyph at 140px, weight 700, tracking −0.045em, rises letter by letter 8.28–8.74s (power3.out, 0.025s stagger), 38px gap, row centred at y 450. Everything is still from 8.75s to the end. Soft shadows on the chrome cards, no film grain.

## Often confused with

- [Wireframe Re-layout](https://motionboard.app/r/wireframe-re-layout.md): Wireframe Re-layout swaps a whole layout: frames drift into a new grid and then fill with content. Selection Box Animation keeps one text layer, and the width of its box drives the line breaks and the font size.
- [Multiplayer Cursor Animation](https://motionboard.app/r/multiplayer-cursor-animation.md): Multiplayer Cursor Animation shows named cursors selecting, commenting and reordering items. Here one cursor grabs resize handles, and the dragged width changes the text inside the box.

## Source files

Runnable HyperFrames project, 3 files.

- https://motionboard.app/source/bounding-box/hyperframes.json (318 B)
- https://motionboard.app/source/bounding-box/index.html (19.3 KB)
- https://motionboard.app/source/bounding-box/package.json (301 B)

Download all of them:

```sh
curl -fsSL --create-dirs -o "bounding-box/hyperframes.json" "https://motionboard.app/source/bounding-box/hyperframes.json"
curl -fsSL --create-dirs -o "bounding-box/index.html" "https://motionboard.app/source/bounding-box/index.html"
curl -fsSL --create-dirs -o "bounding-box/package.json" "https://motionboard.app/source/bounding-box/package.json"
```

## index.html

```html
<!doctype html>
<html lang="en" data-resolution="landscape">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=1920, height=1080" />
    <script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
    <style>
      :root {
        --paper: #eceef1;
        --ink: #0e1014;
        --mute: #5d5d66;
        --accent: #2f6bff;
        --font-ui: "Inter", sans-serif;
      }
      * { margin: 0; padding: 0; box-sizing: border-box; }
      html, body { width: 1920px; height: 1080px; overflow: hidden; background: var(--paper); }
      #root {
        position: relative; width: 1920px; height: 1080px; overflow: hidden;
        background: var(--paper); color: var(--ink); font-family: var(--font-ui);
        -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
      }
      .full { position: absolute; left: 0; top: 0; width: 1920px; height: 1080px; }
      svg { display: block; overflow: visible; }

      /* ---------- canvas: soft light, dot grid, vignette ---------- */
      #paper {
        background-color: var(--paper);
        background-image:
          radial-gradient(circle, rgba(30, 44, 74, 0.2) 1.7px, transparent 2.3px),
          radial-gradient(ellipse 70% 65% at 50% 46%, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0) 72%),
          radial-gradient(ellipse 60% 50% at 88% 90%, rgba(200, 214, 255, 0.35), rgba(200, 214, 255, 0) 70%),
          radial-gradient(ellipse 55% 45% at 8% 8%, rgba(255, 232, 224, 0.4), rgba(255, 232, 224, 0) 70%);
        background-size: 40px 40px, 100% 100%, 100% 100%, 100% 100%;
        background-position: 20px 20px, 0 0, 0 0, 0 0;
      }
      #vig {
        pointer-events: none;
        background: radial-gradient(ellipse 75% 75% at 50% 50%, rgba(0, 0, 0, 0) 62%, rgba(28, 40, 66, 0.1) 100%);
      }

      /* ---------- design-tool chrome ---------- */
      #chrome { opacity: 0; }
      #crumb {
        position: absolute; left: 48px; top: 40px; height: 56px; padding: 0 22px 0 14px;
        display: flex; align-items: center; gap: 14px;
        background: #fff; border-radius: 16px; font-size: 26px; font-weight: 500; color: #8a8f9c;
        box-shadow: 0 1px 0 rgba(255,255,255,0.9) inset, 0 10px 28px rgba(40, 56, 96, 0.12), 0 0 0 1px rgba(40, 56, 96, 0.07);
      }
      #crumb .mini { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); position: relative; }
      #crumb .mini::after { content: ""; position: absolute; left: 8px; top: 8px; width: 14px; height: 14px; border: 3px solid #fff; border-radius: 4px; }
      #crumb b { color: var(--ink); font-weight: 600; }
      #topr { position: absolute; right: 48px; top: 40px; height: 56px; display: flex; align-items: center; gap: 14px; }
      #zoom {
        height: 56px; padding: 0 22px; display: flex; align-items: center;
        background: #fff; border-radius: 16px; font-size: 26px; font-weight: 600; color: #3a3f4b;
        box-shadow: 0 10px 28px rgba(40, 56, 96, 0.12), 0 0 0 1px rgba(40, 56, 96, 0.07);
      }
      #share {
        height: 56px; padding: 0 26px; display: flex; align-items: center;
        background: var(--accent); border-radius: 16px; font-size: 26px; font-weight: 600; color: #fff;
        box-shadow: 0 10px 28px rgba(47, 107, 255, 0.3);
      }
      #toolbar {
        position: absolute; left: 690px; top: 962px; width: 540px; height: 80px;
        display: flex; align-items: center; justify-content: center; gap: 14px;
        background: #fff; border-radius: 24px;
        box-shadow: 0 1px 0 rgba(255,255,255,0.9) inset, 0 18px 44px rgba(40, 56, 96, 0.16), 0 0 0 1px rgba(40, 56, 96, 0.07);
      }
      .tool { width: 56px; height: 56px; border-radius: 16px; display: flex; align-items: center; justify-content: center; color: #6b7080; }
      .tool.on { background: #e8efff; color: var(--accent); }
      .tool svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

      /* ---------- title words ---------- */
      .tw { font-weight: 700; letter-spacing: -0.04em; white-space: nowrap; }
      .m { position: absolute; left: 0; top: 0; visibility: hidden; font-size: 400px; }
      .w { position: absolute; left: 0; top: 0; opacity: 0; color: var(--ink); font-size: 118px; line-height: 123px; }

      /* ---------- selection box ---------- */
      #boxwrap { opacity: 1; }
      #bfill { fill: rgba(47, 107, 255, 0.055); opacity: 0; }
      #bline { fill: none; stroke: var(--accent); stroke-width: 3px; opacity: 0; }
      .hd { position: absolute; left: 0; top: 0; width: 0; height: 0; }
      .hi {
        position: absolute; left: -9px; top: -9px; width: 18px; height: 18px;
        background: #fff; border: 3px solid var(--accent); border-radius: 3px;
        box-shadow: 0 2px 6px rgba(30, 60, 140, 0.25); opacity: 0;
      }
      #lab { position: absolute; left: 0; top: 0; width: 360px; text-align: center; }
      #labin {
        display: inline-block; opacity: 0; background: var(--accent); color: #fff; border-radius: 10px;
        padding: 7px 18px; font-size: 28px; line-height: 36px; font-weight: 600; letter-spacing: 0.01em; white-space: nowrap;
      }

      /* ---------- cursor ---------- */
      #cur { position: absolute; left: 0; top: 0; width: 0; height: 0; }
      #curi { position: absolute; left: -3px; top: -3px; width: 46px; height: 64px; opacity: 0; filter: drop-shadow(0 4px 6px rgba(20, 30, 60, 0.3)); }

      /* ---------- lockup ---------- */
      #lockrow {
        position: absolute; left: 0; top: 375px; width: 1920px; height: 150px;
        display: flex; align-items: center; justify-content: center; gap: 38px;
      }
      #mkbox { width: 150px; height: 150px; flex: none; opacity: 0; }
      #mkbox svg { width: 150px; height: 150px; }
      #wm { font-size: 140px; line-height: 1; font-weight: 700; letter-spacing: -0.045em; white-space: nowrap; display: flex; color: var(--ink); }
      .wl { display: inline-block; opacity: 0; }
    </style>
  </head>
  <body>
    <div id="root" data-composition-id="main" data-start="0" data-duration="11" data-width="1920" data-height="1080">

      <div id="paper" class="clip full" data-start="0" data-duration="11" data-track-index="0" data-layout-ignore></div>

      <!-- design-tool chrome -->
      <div id="chrome" class="clip full" data-start="0" data-duration="11" data-track-index="1" data-layout-allow-overlap>
        <div id="crumb"><span class="mini"></span><span>Glyph Studio</span><span>/</span><b>Launch hero</b></div>
        <div id="topr"><div id="zoom">100%</div><div id="share">Share</div></div>
        <div id="toolbar">
          <span class="tool on"><svg viewBox="0 0 24 24"><path d="M5 3.5 L5 19 L9.3 15 L12.2 21 L14.8 19.8 L12 14 L18 14 Z" /></svg></span>
          <span class="tool"><svg viewBox="0 0 24 24"><path d="M7 3 V21 M17 3 V21 M3 7 H21 M3 17 H21" /></svg></span>
          <span class="tool"><svg viewBox="0 0 24 24"><rect x="4" y="5" width="16" height="14" rx="2.5" /></svg></span>
          <span class="tool"><svg viewBox="0 0 24 24"><path d="M5 6 V4 H19 V6 M12 4 V20 M9 20 H15" /></svg></span>
          <span class="tool"><svg viewBox="0 0 24 24"><path d="M4 20 L8 19 L19 8 L16 5 L5 16 Z" /></svg></span>
          <span class="tool"><svg viewBox="0 0 24 24"><path d="M5 5 H19 V16 H11 L7 20 V16 H5 Z" /></svg></span>
        </div>
      </div>

      <!-- stage: title words, selection box, cursor -->
      <div id="stage" class="clip full" data-start="0" data-duration="11" data-track-index="2" data-layout-allow-overlap>
        <div id="meas">
          <span class="tw m">Captions</span><span class="tw m">that</span><span class="tw m">keep</span><span class="tw m">up</span>
        </div>
        <div id="words">
          <span class="tw w">Captions</span><span class="tw w">that</span><span class="tw w">keep</span><span class="tw w">up</span>
        </div>
        <div id="boxwrap" class="full">
          <svg class="full" viewBox="0 0 1920 1080" xmlns="http://www.w3.org/2000/svg">
            <rect id="bfill" x="0" y="0" width="10" height="10" />
            <rect id="bline" x="0" y="0" width="10" height="10" pathLength="1" stroke-dasharray="1 1" stroke-dashoffset="1" />
          </svg>
          <div class="hd" id="d0"><div class="hi" id="h0"></div></div>
          <div class="hd" id="d1"><div class="hi" id="h1"></div></div>
          <div class="hd" id="d2"><div class="hi" id="h2"></div></div>
          <div class="hd" id="d3"><div class="hi" id="h3"></div></div>
          <div class="hd" id="d4"><div class="hi" id="h4"></div></div>
          <div class="hd" id="d5"><div class="hi" id="h5"></div></div>
          <div class="hd" id="d6"><div class="hi" id="h6"></div></div>
          <div class="hd" id="d7"><div class="hi" id="h7"></div></div>
          <div id="lab"><span id="labin">W 1280 · H 260</span></div>
        </div>
        <div id="cur">
          <svg id="curi" viewBox="0 0 30 42" xmlns="http://www.w3.org/2000/svg">
            <path d="M3 3 L3 33 L10.5 26 L16 38.5 L22 36 L16.5 23.5 L27 23.5 Z" fill="#111318" stroke="#fff" stroke-width="2.6" stroke-linejoin="round" />
          </svg>
        </div>
      </div>

      <!-- lockup -->
      <div id="lockc" class="clip full" data-start="0" data-duration="11" data-track-index="3" data-layout-allow-overlap>
        <div id="lockrow">
          <div id="mkbox">
            <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
              <rect x="0" y="0" width="100" height="100" rx="28" fill="#2f6bff" />
              <path d="M65.6 34.4 A22 22 0 1 0 72 50 L53 50" fill="none" stroke="#fff" stroke-width="11" stroke-linecap="round" stroke-linejoin="round" />
            </svg>
          </div>
          <div id="wm"><span class="wl">G</span><span class="wl">l</span><span class="wl">y</span><span class="wl">p</span><span class="wl">h</span></div>
        </div>
      </div>

      <div id="vig" class="clip full" data-start="0" data-duration="11" data-track-index="4" data-layout-ignore></div>
    </div>

    <script>
      const tl = gsap.timeline({ paused: true });

      /* ================= layout engine (all state computed from timeline time) ================= */
      const CX = 960, CY = 520, PADX = 60, PADY = 66, LH = 1.04, GAP = 0.24, TAG = 44, TAGY = 650, BLEND = 0.4;
      const wEls = Array.prototype.slice.call(document.querySelectorAll(".w"));
      const mEls = Array.prototype.slice.call(document.querySelectorAll(".m"));
      const hEls = [0, 1, 2, 3, 4, 5, 6, 7].map(function (i) { return document.getElementById("d" + i); });
      const bline = document.getElementById("bline");
      const bfill = document.getElementById("bfill");
      const lab = document.getElementById("lab");
      const labin = document.getElementById("labin");
      const cur = document.getElementById("cur");

      const UW = [4.0, 1.8, 2.25, 1.1]; // per-pixel word widths; replaced by measurement
      let FS0 = 118;

      const P2 = gsap.parseEase("power2.inOut");
      const P1 = gsap.parseEase("power1.inOut");
      const P3 = gsap.parseEase("power3.inOut");
      const EXP = gsap.parseEase("expo.inOut");
      const OUT = gsap.parseEase("power3.out");
      const CIN = gsap.parseEase("power2.in");
      const clamp01 = function (v) { return v < 0 ? 0 : v > 1 ? 1 : v; };
      const lerp = function (a, b, u) { return a + (b - a) * u; };

      function measure() {
        let ok = true;
        mEls.forEach(function (e, i) { const w = e.offsetWidth / 400; if (w > 0) UW[i] = w; else ok = false; });
        const tot = UW[0] + UW[1] + UW[2] + UW[3] + 3 * GAP;
        if (ok && tot > 0) FS0 = Math.floor(1150 / tot);
      }

      // box width W and font scale k: three drags, each eased
      const T = { a0: 2.3, a1: 3.0, b0: 4.0, b1: 4.7, c0: 5.85, c1: 6.65 };
      function params(t) {
        const a = t <= T.a0 ? 0 : t >= T.a1 ? 1 : P2((t - T.a0) / (T.a1 - T.a0));
        const b = t <= T.b0 ? 0 : t >= T.b1 ? 1 : P2((t - T.b0) / (T.b1 - T.b0));
        const c = t <= T.c0 ? 0 : t >= T.c1 ? 1 : P1((t - T.c0) / (T.c1 - T.c0));
        return { W: 1280 + (980 - 1280) * a + (690 - 980) * b + (1260 - 690) * c, k: 1 + 0.45 * c * c };
      }

      function lines(k, W) {
        const fs = FS0 * k, I = W - 2 * PADX, g = GAP * fs;
        const seg = function (a, b) { let s = 0; for (let i = a; i <= b; i++) s += UW[i] * fs + (i > a ? g : 0); return s; };
        if (seg(0, 3) <= I) return [[0, 1, 2, 3]];
        if (seg(0, 1) <= I && seg(2, 3) <= I) return [[0, 1], [2, 3]];
        const out = []; let c = [];
        for (let i = 0; i < 4; i++) {
          if (c.length && seg(c[0], i) > I) { out.push(c); c = [i]; } else c.push(i);
        }
        out.push(c);
        return out;
      }

      function rel(ln, fs) {
        const n = ln.length, x = [], y = [];
        ln.forEach(function (L, li) {
          let w = 0;
          L.forEach(function (i, j) { w += UW[i] * fs + (j ? GAP * fs : 0); });
          let cx = -w / 2;
          L.forEach(function (i) { x[i] = cx; y[i] = (li - n / 2) * LH * fs; cx += UW[i] * fs + GAP * fs; });
        });
        return { x: x, y: y, n: n };
      }

      // stateless: the most recent line-break change within BLEND seconds eases words from old to new places
      function geom(t) {
        const p = params(t), fs = FS0 * p.k, ln = lines(p.k, p.W), sig = ln.join("|");
        let prev = null, s = 1;
        for (let i = 0; i < 25; i++) {
          const tt = t - (i + 1) / 60;
          if (tt < 0) break;
          const q = params(tt), l = lines(q.k, q.W);
          if (l.join("|") !== sig) { prev = l; s = P3(clamp01((i / 60) / BLEND)); break; }
        }
        const c = rel(ln, fs);
        let x = c.x, y = c.y, nB = c.n;
        if (prev) {
          const pr = rel(prev, fs);
          x = c.x.map(function (v, i) { return lerp(pr.x[i], v, s); });
          y = c.y.map(function (v, i) { return lerp(pr.y[i], v, s); });
          nB = lerp(pr.n, c.n, s);
        }
        return { W: p.W, H: nB * LH * fs + 2 * PADY, fs: fs, x: x, y: y };
      }

      function hp(g, fx, fy) { return { x: CX - g.W / 2 + fx * g.W, y: CY - g.H / 2 + fy * g.H }; }
      function path(a, b, u, bow) { return { x: lerp(a.x, b.x, u), y: lerp(a.y, b.y, u) - Math.sin(Math.PI * u) * bow }; }

      function cursorPos(t, g) {
        if (t < 2.1) return path({ x: 1790, y: 910 }, hp(geom(2.1), 1, 0.5), OUT(clamp01((t - 1.5) / 0.6)), 50);
        if (t < 4.95) return hp(g, 1, 0.5);
        if (t < 5.6) return path(hp(geom(4.95), 1, 0.5), hp(geom(5.6), 1, 1), P2(clamp01((t - 4.95) / 0.65)), -30);
        if (t < 6.7) return hp(g, 1, 1);
        return path(hp(geom(6.7), 1, 1), { x: 1580, y: 970 }, CIN(clamp01((t - 6.7) / 0.6)), 0);
      }

      const HF = [[0, 0], [0.5, 0], [1, 0], [1, 0.5], [1, 1], [0.5, 1], [0, 1], [0, 0.5]];

      function render(t) {
        measure();
        const g = geom(t);

        // title words, and their move into the tagline
        const m = EXP(clamp01((t - 7.9) / 0.6));
        const tw = (UW[0] + UW[1] + UW[2] + UW[3]) * TAG + 3 * GAP * TAG;
        let sx = CX - tw / 2;
        const sy = TAGY - (LH * TAG) / 2;
        for (let i = 0; i < 4; i++) {
          let left = CX + g.x[i], top = CY + g.y[i], fs = g.fs;
          if (m > 0) {
            left = lerp(left, sx, m); top = lerp(top, sy, m); fs = lerp(fs, TAG, m);
          }
          sx += UW[i] * TAG + GAP * TAG;
          const el = wEls[i];
          el.style.left = left + "px";
          el.style.top = top + "px";
          el.style.fontSize = fs + "px";
          el.style.lineHeight = LH * fs + "px";
          el.style.color = "rgb(" + Math.round(lerp(14, 93, m)) + "," + Math.round(lerp(16, 93, m)) + "," + Math.round(lerp(20, 102, m)) + ")";
        }

        // selection box
        const bx = CX - g.W / 2, by = CY - g.H / 2;
        [bline, bfill].forEach(function (r) {
          r.setAttribute("x", bx); r.setAttribute("y", by); r.setAttribute("width", g.W); r.setAttribute("height", g.H);
        });
        for (let i = 0; i < 8; i++) {
          hEls[i].style.left = bx + HF[i][0] * g.W + "px";
          hEls[i].style.top = by + HF[i][1] * g.H + "px";
        }
        lab.style.left = CX - 180 + "px";
        lab.style.top = by + g.H + 26 + "px";
        labin.textContent = "W " + Math.round(g.W) + " · H " + Math.round(g.H);

        // cursor
        const c = cursorPos(t, g);
        cur.style.left = c.x + "px";
        cur.style.top = c.y + "px";
      }

      /* ================= baselines (one set per element) ================= */
      tl.set(".w", { y: 38, filter: "blur(12px)" }, 0);
      tl.set(".hi", { scale: 0 }, 0);
      tl.set("#curi", { scale: 1, transformOrigin: "5px 5px" }, 0);
      tl.set("#mkbox", { scale: 0.7, transformOrigin: "50% 50%" }, 0);
      tl.set(".wl", { y: 56 }, 0);

      /* ================= driver: recompute layout from timeline time ================= */
      const S = { v: 0 };
      tl.to(S, { v: 11, duration: 11, ease: "none", onUpdate: function () { render(S.v); } }, 0);

      /* ================= beat 1: canvas, title, box draws in ================= */
      tl.to("#chrome", { opacity: 1, duration: 0.7, ease: "power2.out" }, 0);
      tl.to(".w", { y: 0, opacity: 1, filter: "blur(0px)", duration: 0.85, ease: "expo.out", stagger: 0.1 }, 0.15);
      tl.to("#bline", { opacity: 1, duration: 0.01, ease: "none" }, 0.55);
      tl.to("#bline", { attr: { "stroke-dashoffset": 0 }, duration: 0.85, ease: "power2.inOut" }, 0.55);
      tl.to("#bfill", { opacity: 1, duration: 0.5, ease: "power2.out" }, 1.0);
      tl.to(".hi", { scale: 1, opacity: 1, duration: 0.4, ease: "back.out(2.4)", stagger: 0.05 }, 1.25);
      tl.to("#labin", { opacity: 1, duration: 0.4, ease: "power2.out" }, 1.7);

      /* ================= beat 2: cursor grabs the handles ================= */
      tl.to("#curi", { opacity: 1, duration: 0.3, ease: "power2.out" }, 1.5);
      // right-middle handle: press, drag A (2.3-3.0), drag B (4.0-4.7), release
      tl.to("#curi", { scale: 0.86, duration: 0.12, ease: "power2.out" }, 2.1);
      tl.to("#h3", { scale: 1.35, backgroundColor: "#2f6bff", duration: 0.15, ease: "power2.out" }, 2.12);
      tl.to("#curi", { scale: 1, duration: 0.18, ease: "power2.out" }, 4.8);
      tl.to("#h3", { scale: 1, backgroundColor: "#ffffff", duration: 0.2, ease: "power2.out" }, 4.8);
      // bottom-right corner: press, drag C (5.85-6.65), release
      tl.to("#curi", { scale: 0.86, duration: 0.12, ease: "power2.out" }, 5.6);
      tl.to("#h4", { scale: 1.35, backgroundColor: "#2f6bff", duration: 0.15, ease: "power2.out" }, 5.62);
      tl.to("#curi", { scale: 1, duration: 0.18, ease: "power2.out" }, 6.7);
      tl.to("#h4", { scale: 1, backgroundColor: "#ffffff", duration: 0.2, ease: "power2.out" }, 6.7);
      // cursor leaves
      tl.to("#curi", { opacity: 0, duration: 0.3, ease: "power2.in" }, 7.0);

      /* ================= beat 3: box clears, type becomes the tagline, lockup ================= */
      tl.to("#boxwrap", { opacity: 0, duration: 0.4, ease: "power2.inOut" }, 7.3);
      tl.to("#chrome", { opacity: 0, duration: 0.4, ease: "power2.inOut" }, 7.9);
      tl.to("#mkbox", { scale: 1, opacity: 1, duration: 0.45, ease: "back.out(1.8)" }, 8.3);
      tl.to(".wl", { y: 0, opacity: 1, duration: 0.36, ease: "power3.out", stagger: 0.025 }, 8.28);

      tl.set({}, {}, 11);
      window.__timelines = window.__timelines || {};
      window.__timelines["main"] = tl;

      render(0);
      if (document.fonts && document.fonts.ready) document.fonts.ready.then(function () { render(S.v); });
    </script>
  </body>
</html>
```
