# Scroll Gyroscope Rings: Pinned Raymarched Gyroscope Whose Alignment Is Scrubbed by Scroll

## Goal
Build a black page with **50vh of space, a 100vh stage, and 50vh of space**. The stage is **pinned with ScrollTrigger** for 140% of the viewport. On it, a full-bleed `<canvas>` raymarches a **gyroscope of three nested hoops**, plus a hairline orbit and a bead, in a dependency-free WebGL1 fragment shader. The hoops **spin on their own over time**, and a **progress uniform `prog` (0.15 to 1) tied to the scroll** turns them into and out of alignment. In the same scrubbed timeline, **three numbered labels** around the gyroscope (right, left, right) rise into place one after another, starting from **opacity 0.75 and y 40**, never from invisible.

## Tech
Vanilla HTML/CSS/JS with ES module imports. `gsap` + `gsap/ScrollTrigger` (npm). Raw WebGL1. Font: **Inter** 500/700.

## Layout / HTML
```html
<div class="sg">
  <div class="sg-space"><p class="sg-hint">Scroll</p></div>
  <section class="sg-stage" data-sg-stage>
    <canvas class="sg-canvas" data-sg-canvas aria-hidden="true"></canvas>
    <div class="sg-note sg-note--1"><span class="sg-num">1</span><h3>Faster setup</h3></div>
    <div class="sg-note sg-note--2"><span class="sg-num">2</span><h3>Less manual work</h3></div>
    <div class="sg-note sg-note--3"><span class="sg-num">3</span><h3>Lower cost per result</h3></div>
  </section>
  <div class="sg-space"></div>
</div>
```

## Styling
`:root`: `--sg-bg:#000`, `--sg-ink:#fff`, `--sg-ring:#ff5a36` (the single accent).

- `.sg-space`: `height:50vh; display:grid; place-items:center`; `.sg-hint` 11px uppercase, `letter-spacing:.12em`, opacity .55.
- `.sg-stage`: `position:relative; height:100vh; overflow:hidden`. `.sg-canvas` absolute, inset 0, 100% × 100%.
- `.sg-note`: `position:absolute; max-width:240px; display:grid; gap:10px`; `h3` `clamp(1.1rem,1.8vw,1.5rem)`, 500, line-height 1.1.
- `.sg-num`: 18px white circle, black 10px bold digit, centred.
- Positions: `--1 right:6%; top:18%`, `--2 left:6%; top:46%`, `--3 right:6%; top:68%`. Below 760px: max-width 160px, `--1 top:10%`, `--3 top:80%`.

## The shader (be exact)
Full-screen triangle; context `{ premultipliedAlpha:true, alpha:true, antialias:true }`; DPR capped at 1.5. Ray: `uv = (gl_FragCoord.xy - .5*uRes)/uRes.y / uScale; ro=(0,0,4.2); rd=normalize(uv,-1.55)`; 90 steps, `t += d*.9`, hit `< .0012`, max `9`.

`sdHoop(p, r, w, h)`: rounded rectangle profile swept around Y: `q = (length(p.xz)-r, p.y); d = abs(q)-(w,h); min(max(d.x,d.y),0) + length(max(d,0)) - .012`.

`map(p)` with `t = uTime*.25`, `g = uProg*2π`, `q = p` rotated by pointer (`xz` by `x*.3`, `yz` by `y*.2`):
- outer: `a.yz *= rot(1.45 + .15*sin(g*.5)); a.xy *= rot(.1 + g*.15)`, `sdHoop(a, 1.55, .13, .07)` (mat 1)
- middle: `b.xy *= rot(-.55 + g*.6 + t*.4); b.yz *= rot(.9 + g*.35)`, `sdHoop(b, .95, .05, .11)` (mat 1)
- inner: `c.yz *= rot(1.2 - g*.5); c.xz *= rot(.7 + g*.8 + t*.6)`, `sdHoop(c, .72, .05, .09)` (mat 2)
- orbit: `o.yz *= rot(1.3)`, torus `(1.18, .004)`; bead at angle `t*1.4 + g` on that orbit, radius `.035` (mat 3)

Shading: `L = normalize(-.5,.8,.6)`, `fres = pow(1-dot(n,-rd),3)`, `spec = pow(...,60)`. Mat 3 returns `uRim` at alpha .55. Otherwise `base*(.25 + .95*dif) + uLight*spec*.9 + uRim*fres*.55`, alpha 1, with `base = uBase` (mat 1) or `uInner` (mat 2). Output `vec4(c*a, a)`.

Colours from `--sg-ring`: `uBase = ring`, `uInner = mix(ring, white, .18)`, `uLight = mix(ring, white, .85)`, `uRim = mix(ring, white, .55)`; re-read every 30 frames.

## Motion (be exact)
```js
const DEFAULTS = { pinLength: 140, scale: .36, progFrom: .15, scrub: .6 };
```
- Own rAF loop advances `uTime`; draws only while visible (IntersectionObserver). Below 760px use `scale*1.4`.
- Pointer: fine pointers only, smoothed 6% per frame.
- Timeline:
```js
const state = { prog: .15 };
const tl = gsap.timeline({ scrollTrigger: { trigger: stage, start: "top top", end: "+=140%", pin: true, scrub: .6 } });
tl.fromTo(state, { prog: .15 }, { prog: 1, ease: "none", duration: 3 }, 0);
notes.forEach((n, i) => tl.from(n, { y: 40, opacity: .75, duration: .4, ease: "power2.out" }, i * .7));
```
  The render loop reads `state.prog` every frame.
- `prefers-reduced-motion: reduce`: no timeline, no time advance, no pointer.

**destroy()**: stop rAF, disconnect observers, remove the listener, kill the timeline and its ScrollTrigger (this removes the pin spacer), `clearProps:"all"` on the notes, delete GL objects.

## Assets / images
None.

## Behavior notes
- The labels never start at opacity 0, so a screenshot or a slow scroll never shows an empty stage.
- `pinLength` is the only knob for how long the alignment lasts; the timeline stays 3 units long.
- Only the prefixed variables are global.

## Using this outside its demo page

This component is written as a complete page: that is how the demo is meant to look. If you are dropping it into an existing project, or combining it with other components, these are the things it declares at document level and that you need to move or reconcile first.

- **Palette on `:root`**: `--sg-bg`, `--sg-ink`, `--sg-ring`. Generic names like `--ink`, `--paper` or `--muted` are defined by many components in this catalogue with different values, and they will also collide with whatever your own project defines. Move them onto the component's wrapper (`.my-section { --ink: … }`) or keep the prefix.
- **Rules on `*, *::before, *::after`, `html, body`**: the demo owns the whole document, so these set the box model and resets. Dropped into an existing project they restyle the entire page, not just this section. Re-target them at the component's wrapper before using it.
