# Recreate this section as a single HTML file: Ullbreen Core Timeline

## What it is

A one-screen **history / timeline section** for *Ullbreen Ice Station*, a fictional glacier research station, titled "Sixty-four winters, read *from the top down*." The timeline is an **ice core**. One centimetre of core is one slice of time: the snow of 1961 sits 38.4 m down and the snow of 2024 is at the surface, at 0.6 m of snow a year. The station's six eras are bands in that core. **Signature:** a live three.js core (PBR ice: bump-mapped annual layers, clearcoat, sheen and a blue subsurface tint on the grazing edges) stands in the middle of the page. A **signal-orange probe** rides down it, and a metal **drill head**, a real GLB, hangs above the surface on its winch cable. Drag the probe, scroll the wheel over the core, click a band, press the arrow keys or use the buttons. When the probe enters a new era, **that section of core slides out of the column and turns** and the orange collar goes with it. The era photo opens through a **wavy strata-shaped mask** whose edges match the cut ends of that section. The huge year **rolls like an odometer** to the exact year under the probe, a depth gauge reads the metres, and the story, kicker, caption and three stats swap in, with the stats counting up. A **guided descent** autoplays one era every 5.2 s. It has a visible pause/play button with a progress ring and stops for good when you take the probe. Dating horizons that glaciologists really use (1963 bomb peak, 1992 sulphate, 2010 ash, 2012 melt lens) are drawn into the ice and labelled beside it. On phones the core lies **horizontal** across the screen and the drill head sits at its surface end. If there is no WebGL or the CDN fails, a 2D canvas core with the same strata, a pulled-out slab and a socket takes over, and the page loses nothing else.

## Page shell & libraries

- One `index.html` with inline CSS and JS, plus `assets/`. No framework. `<html lang="en">`, charset and viewport metas, `<title>`, meta description.
- **three.js r170** through an import map, both entries pinned:
  `{"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.170.0/build/three.module.js","three/addons/":"https://cdn.jsdelivr.net/npm/three@0.170.0/examples/jsm/"}}`.
  The addons used are `environments/RoomEnvironment.js`, `loaders/GLTFLoader.js` and `libs/meshopt_decoder.module.js`.
- **Google Fonts** (with preconnects): `family=IBM+Plex+Mono:wght@400;500&family=Newsreader:ital,opsz,wght@0,6..72,300;0,6..72,400;1,6..72,300;1,6..72,400&family=Public+Sans:wght@400;500;600&display=swap`.
- Two scripts:
  1. A classic script runs the whole section: data, the 2D core, the probe spring, input, era switching, the photo mask, the odometer, count-ups and autoplay. It exposes a small read-only API as `root.__tl`: `CFG, ERAS, SPAN, REDUCED, drawStrata(ctx, w, h, lit), bandS(i), sOf(v), eraOf(year)`, getters `L, T, horiz, cur, v, vel, version`, and the `core` and `rig` elements.
  2. A `<script type="module">` that only *reads* that API and draws the 3D layer. If it throws or the CDN fails, nothing else breaks.

## Tokens

- **Colour:** paper `#eceee9` (body and section), ink `#121a20`, ink-2 `#26323a` (body copy), muted `#4b5862` (≥ 6:1 on paper), rule `rgba(18,26,32,.16)`, rule-strong `rgba(18,26,32,.42)`, **signal `#d9480f`** (probe, collar, autoplay ring, active bracket, leader line; never used for small text), signal-ink `#a8360a` (small accent text and italics, ≥ 5.5:1), socket `#23313a`, photo frame `#d3dad6`. The section has a white radial wash at 70% 10% and a fixed SVG fractal-noise grain (multiply, 0.5 opacity).
- **Ice albedo** (the strata drawing): surface to depth, 2D `#f4f6f2 → #96bac9`, 3D (lit) `#d6e0e2 → #548098`, interpolated by depth^0.8 with ±7 jitter per year.
- **Type:** Newsreader 300/400 for display (h2 `clamp(2rem,3.1vw,3rem)` weight 300 with a signal-ink italic; year `clamp(6.5rem,10.5vw,10.5rem)` weight 300 tracking −.045em; h3 `clamp(1.5rem,2.1vw,2rem)`; stats `clamp(1.6rem,2.3vw,2.15rem)` weight 300 with tabular lining numerals). Public Sans 400–600 for text (16px body, .97rem story). IBM Plex Mono 400/500 at .75rem uppercase with .06em tracking for every instrument label (top bar, kicker, gauge, captions, counter).
- **Radii:** core 10px, buttons round, handle 16px, frame 4px. **Padding:** x `clamp(1rem,3.9vw,3.5rem)`, y `clamp(1.25rem,3vw,2.5rem)`.

## Layout & structure

`section.core-tl#core-timeline` (min-height 100svh) is a 3-column grid: `minmax(330px,1fr) 320px minmax(360px,1.05fr)`, column gap `clamp(1.5rem,3vw,3rem)`, rows `auto 1fr`.

1. **Top bar** (full width, mono, bottom rule): an orange dot, "**Ullbreen Ice Station** · Station history" on the left, and "Core UB-25 · top 38.4 m · 0.6 m of snow a year" on the right.
2. **Text column:** the h2 and a lede ("Every band in this core is one year of snow…"). Then, pushed to the bottom with `margin-top:auto`:
   - **Readout:** a 4-digit odometer year (each digit a 0–9 column strip, cell height 1.12em) and a mono depth block ("Probe depth / **0.3 m** / below surface").
   - **Story stack:** six `<article class="era">` in one grid cell. Each has a mono signal-ink kicker ("Era 03 · 1994–2007"), an h3, a body paragraph and a `<dl class="stats">` of three stats (3 columns, top rule).
   - **Controls:** a 52px ink play/pause button with an SVG progress ring, round 44px up (newer) and down (older) arrows, a two-line mono label ("**Guided descent** / stops when you drag") and a `03 / 06` counter.
3. **Core column (`.stage`):** a `.rig` grid `26px 48px 184px 1fr` × rows `196px 1fr`. The 196px row is air for the hanging drill. Row 2 holds:
   - **Brackets:** six `<button class="bracket">`, one per era. Each is a 3px bar spanning its era's band with a mono `01`–`06` label. The active one is a 5px signal bar.
   - **Gauge:** a tick every metre, a long tick every 5 m and a label every 10 m.
   - **Core:** a 2D `canvas.ice` plus the fallback `.socket`, `.slab` (a canvas copy of the active band) and `.reveal`. Horizon labels ("— 2010 ash") sit outside the core, 8px to its right.
   - **Probe:** a 2px signal line plus the `role="slider"` handle, an orange 32px pill with a grip and the live depth ("16.5 m").
   - `canvas.gl` covers the whole rig with pointer-events off. The captions are "**Surface** 2025 / 0.0 m" (right-aligned, above the core) and "**1961** · first snow 38.4 m" (below it).
4. **Photo column (`figure.plate`):** a full-height `.frame` with six stacked `<img>`, a "Plate 3 / 6" chip, and one shared grade over the archive (contrast 1.04, saturate .86, sepia .08, plus an overlay of SVG grain, vignette and faint warm halation). Below it is a `figcaption` stack of six mono captions. A 1px signal `.leader` line runs from the pulled-out slab to the frame edge.
5. A visually hidden `aria-live="polite"` region.

**Eras** (newest first = top of the core; probe target = key year + 0.5):

| # | Band | Key | Title | Stats |
|---|---|---|---|---|
| 01 | 2016–2025 | 2024 | Ice that leaves | 41 m surface lowered since 1961 · 2 replicate cores sent south · 9 people overwintering |
| 02 | 2008–2015 | 2010 | The ash came in April | 3 mm ash band, 9.0 m down · 11 mm melt lens, July 2012 · 34 labs sharing the slices |
| 03 | 1994–2007 | 1997 | Gravel in the teeth | 2,540 m drilled to bedrock · 118k years in the oldest ice · 11 drilling seasons |
| 04 | 1983–1993 | 1983 | A library made of cold | 6,800 m of core on the shelves · −25 °C in the trench · 212 m of trench, dug by hand |
| 05 | 1970–1982 | 1970 | The thermal drill | 412 m first deep core, 1974 · 1,900 sections logged by hand · 4 m/h melting speed |
| 06 | 1961–1969 | 1961 | Four tents and an auger | 18 m by hand auger, 1961 · 4 people, first winter · 11 sledge loads of kit |

The body copy is specific: dates, depths and objects such as "Bag 4,412", "the ledger in the radio hut" and "the 1963 bomb-test horizon". Write 45–55 words per era.

## Behaviour & interaction

**Axis.** `SPAN = 2025 − 1961 = 64` years over core length `L`. `sOf(v) = (2025 − v)/64 · L` is the distance from the surface. Depth in metres is `(2025 − v) · 0.6`, shown to one decimal. The probe value `v` is clamped to [1961.5, 2024.5], and the displayed year is `floor(v)`.

**Probe spring.** Stiffness 150, damping 24, mass 1, integrated in fixed 4 ms substeps (dt clamped to 250 ms, so slow devices stay real-time). It stops when |Δ| < .002 and |vel| < .01. Every frame it moves the probe, rolls the odometer, writes the depth and sets `aria-valuenow`/`aria-valuetext` ("1997, 16.5 metres down. Era 3 of 6: Gravel in the teeth"). When the era under the probe changes, the content switches immediately, mid-drag too.

**Inputs.**
- **Drag** the handle or anywhere on the core or gauge (pointer capture). A 4px threshold separates drags from clicks. Rubber band ×0.3 past either end. On release it projects the throw (velocity × 120 ms) and springs to that era's key year.
- **Click** a band to go to its era, or use the bracket buttons, the up/down arrows, or the **wheel** over the core (one era per notch, 600 ms gap, the page scrolls at the ends).
- **Keys** on the slider: ↑/← newer era, ↓/→ older era, Shift+arrows or PageUp/PageDown one year, Home/End surface/bottom.
- On the horizontal core, a mostly-vertical swipe is left to the page (`touch-action: pan-y`) unless it starts on the handle.

**Era switch.**
- The article, caption and bracket get `is-on`, and the bracket gets `aria-current="step"`.
- The kicker, h3, body and stats rise in with 14px/620ms `cubic-bezier(.2,.8,.2,1)`, staggered 60ms. The caption rises in 120ms later.
- The counter and plate chip update. The arrows disable at the ends.
- The stats count up over 900 ms (ease-out cubic, `en-US` grouping, real minus sign, unit kept).
- The live region announces only changes the visitor made.
- **Odometer:** each digit column translates to `−d × 1.12em` with 560ms `cubic-bezier(.3,1.35,.5,1)`, staggered 45ms from right to left.
- **Photo mask:** the new image goes on top and the old one stays under it. Its `clip-path: polygon()` has 23 points per edge, rebuilt every frame for 820 ms with ease-in-out cubic. The band opens from the centre line to half-height 0.62. The top and bottom edges wobble by `edge(seed,u)` (3 sines, integer frequencies 2/5/11, seeded per era) with amplitude 5% falling to 2%. Then the clip is removed.
- **Fallback slab:** a canvas copy of the band with the same wobble on its cut ends slides out 52px (680 ms, ease-out, drop shadow) and exposes a dark socket. The horizon label of that era fades out.

**3D layer (module).**
- WebGLRenderer with alpha, ACES Filmic, exposure .92, pixel ratio ≤ 1.75. RoomEnvironment PMREM at intensity .55.
- Lights: a key light `#fff4e8` 1.9 from upper left, a rim light `#bfe3ff` 2.2 from right/behind, and a hemisphere light at .35.
- An **orthographic camera in rig pixels** (0..W, 0..−H), so the 3D core lands exactly on the DOM core rect. The core is tilted .16 rad towards the viewer (phones: rotated 90° to lie horizontal, then yawed .24 rad). Its length is scaled by 1/cos(tilt), so bands still line up with the gauge.
- Each era is its own open `CylinderGeometry` (96 segments) whose UVs are remapped to its band of the strata texture, with two cap discs and a 1.4px saw-cut gap between eras.
- **Texture:** `drawStrata(ctx, 512, 2L, lit=true)` makes one band per year with a wavy dust line at its base, white bubbles (more with depth), firn grain near the top, and the horizons: a 2.6px dark ash line, a blue melt lens, an ochre sulphate band.
- **Ice material:** MeshPhysical with map, bump (same canvas, scale .9), roughness .34, clearcoat .6/.22, ior 1.31, sheen .6 `#9fd2e6`, specular `#e8f6ff`. An `onBeforeCompile` adds view-angle edge darkening (×0.58–1.0) plus a blue subsurface add `(0.05,0.16,0.23)` on grazing angles. Caps: MeshPhysical `#a9c9d6`.
- Each section has its own spring (k 170, c 22, 4 ms substeps). The active section moves out 52px (phones: 20px up) and turns 0.9 rad. The whole core drifts .12 rad/s around its axis.
- The **collar** (torus, radius 1.1 r, tube .032, signal colour, roughness .38, metalness .25) sits on the probe and moves with whichever section holds it.
- **Drill head:** `assets/drill-head.glb`, normalised to unit width and scaled to 0.82 r (max 80px; phones 0.7 r, max 28px). It hangs 22px above the surface on a dark metal cable, bobs ±2px on a 900 ms sine, and spins at 0.5 rad/s + 1.6 × |probe velocity| (capped at 14).
- **Intro:** the sections come up out of the borehole one after another, 140px over 900 ms each, 120 ms apart, surface first. The 2D fallback instead reveals the core with a paper cover that scales away over 1.3 s.
- **Adaptive:** if more than 5 of the first 90 frames take over 70 ms, the pixel ratio drops to 1 and the idle drift stops, and the scene then renders only when something changes. Rendering pauses off-screen (IntersectionObserver) and on hidden tabs. On `webglcontextlost` it falls back to 2D.

**Guided descent.** It runs while ≥ 25% of the section is in view, the tab is visible, the mouse is not over the section, focus is not inside it and nothing is being dragged. The progress ring fills over 5.2 s and the probe springs to the next era; after 06 it rises back to 01. Any input stops it for good, and the play button restarts it.

**Cursor sheen (2D fallback only):** a white band follows the pointer across the core.

## Responsive

- **≤1180px:** columns `minmax(300px,1fr) 216px minmax(300px,1fr)`, core 116px.
- **≤900px:** the section becomes a single column in this order: top bar (right side hidden), intro, core, readout, photo (aspect 4:3.3), story, controls. The core is **horizontal**: rig `70px 1fr` × rows `22px 26px 80px 48px` for brackets, gauge, core and handle. The surface is on the left, the drill head lies in the 70px lead-in, the handle sits below the core, the slab pulls up 20px and the horizon labels are hidden. Year `clamp(5rem,22vw,7.5rem)`.
- **≤420px:** stats at 1.45rem, the control label is hidden. It works at 320px. No horizontal scroll at 390, 768 or 1440.

## Accessibility & reduced motion

- Semantic `section` with `aria-labelledby`, `article` per era, `dl` stats, a `figure` with `figcaption`, and real `button`s.
- The probe is `role="slider"`, `aria-orientation="vertical"`, min 1961 / max 2024, with a spoken `aria-valuetext`. Brackets have full labels ("Era 3: 1994 to 2007, Gravel in the teeth") and `aria-current="step"`.
- The play button label switches between "Pause/Play the guided descent". The live region is polite and announces user changes only. Every photo has descriptive alt text.
- Focus-visible outline is 2px signal-ink (ink on the orange handle). Muted text is ≥ 6:1 and signal-ink ≥ 5.5:1. Orange is never used for small text.
- `prefers-reduced-motion`: no autoplay (the button shows Play), springs jump, no mask animation, no rise-ins, no intro, no drift/bob/spin, and the 3D renders only on change.

## Fallbacks

No WebGL, a failed CDN, a module error or a lost context leaves the 2D canvas core: the same strata with cylinder shading and saw cuts, a pulled-out slab copy with wavy ends, a dark socket and a cursor sheen. Every interaction works without the module. A missing GLB simply leaves the drill out.

## Assets

All relative, in `assets/`. Total page weight is about 1.4 MB.
- `2024-stilts.webp` — aerial of a red modular station on steel stilts above melting glacier ice (crisp digital).
- `2010-ash.webp` — a researcher with calipers at a band-saw cutting table, an ice core in a tray (early digital, flash).
- `1997-bedrock.webp` — gloved hands holding clear old ice over a light table, a log sheet beneath (35 mm colour).
- `1983-library.webp` — a bearded researcher in a snow tunnel lined with shelves of silver core tubes (colour negative).
- `1970-drill.webp` — a steel derrick in a snow trench with an orange winch (faded slide film).
- `1961-camp.webp` — four canvas tents, a sledge and two figures turning a hand auger (silver gelatin).
  Each photo is 860×1152 WebP at q72, 100–200 KB, generated with a consistent archival look that ages with the era.
- `drill-head.glb` — a stainless core-drill head with an orange collar and cutting teeth. It is Meshy image-to-3D, optimised with `gltf-transform optimize --compress meshopt --texture-compress webp --texture-size 1024` (≈ 700 KB).

## Make it yours

This prompt rebuilds one exact design. If everyone ships it unchanged, the sites will look alike. Change these lines before you paste it. Each change is one edit to the prompt, and the structure and interactions stay intact.

1. **Brand and story.** Swap Ullbreen Ice Station for your own long-running place: a family vineyard, a quarry, a lighthouse, an orchard, a coffee farm. Keep **5–7 eras** with uneven lengths (that is what makes the bands read as time) and exactly three stats per era. Rewrite the depth rule to fit your material (cm of soil a decade, metres of rock an era).
2. **The core.** The striped cylinder is the signature, so re-theme its material and keep the slide-out and the collar. Options: a **soil core** (loam, clay, gravel, a charcoal fire layer, roughness .8, no clearcoat), a **tree-ring log** lying horizontal (end grain on the cap, bark on the side), a **sediment tube** from a lake (varves, a pollen band), or a **stack of vinyl/paper** for a label or publisher. Replace the four horizons with real markers from your story.
3. **The object above it.** Replace `drill-head.glb` with the tool that made your record: a soil auger, a corer, a cooper's adze, a wine thief. Generate a clean product shot (centred, grey sweep, 3/4 view), convert it image-to-3D, and optimise it to ≤ 1 MB with meshopt and WebP textures.
4. **Palette.** Replace paper, ink, muted and **signal** (`#d9480f`). Signal must stay one loud working colour used only for the probe, collar, ring and leader. Keep muted and signal-ink text ≥ 4.5:1 on your ground, and retune the two strata albedo ramps to your material.
5. **Type.** Swap Newsreader / Public Sans / IBM Plex Mono for another serif display with a light weight (for the odometer), a plain sans and a mono for the instrument labels. Avoid Inter and Poppins.
6. **Photos.** Generate six new plates of your own eras with one lens and one light, and let the film stock age with the era (silver gelatin → slide film → colour negative → 35 mm → early digital → crisp digital). No text in the images. Keep the shared CSS grade so they read as one archive.
7. **Voice.** Write each era as a field note: a date, a number and one physical object people can picture ("gravel in the teeth at 2,540 m"). No "journey", no "legacy", no "unlock".

Tell your AI: *"Build exactly as specified, but with these changes: …"*, then list your edits.

---

## Reference implementation (use verbatim)

The complete working `index.html`. Every number in the spec above is in this file; if the two ever seem to differ, the code wins. Images and models referenced as `assets/...` can be downloaded from https://copytheprompt.design/demos/history-timeline-core-sample/assets/ or replaced with your own (see Make it yours).

````html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ullbreen Ice Station: sixty-four winters, read from the top down</title>
<meta name="description" content="The history of Ullbreen Ice Station, told through a core of its own ice. Drag the probe down through sixty-four winters of snow.">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Newsreader:ital,opsz,wght@0,6..72,300;0,6..72,400;1,6..72,300;1,6..72,400&family=Public+Sans:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root {
  --paper: #eceee9;
  --paper-2: #e2e6e1;
  --ink: #121a20;
  --ink-2: #26323a;
  --muted: #4b5862;
  --rule: rgba(18, 26, 32, 0.16);
  --rule-strong: rgba(18, 26, 32, 0.42);
  --signal: #d9480f;
  --signal-ink: #a8360a;
  --socket: #23313a;
  --frame: #d3dad6;

  --f-display: "Newsreader", "Iowan Old Style", Georgia, serif;
  --f-body: "Public Sans", "Helvetica Neue", Arial, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --text-year: clamp(6.5rem, 10.5vw, 10.5rem);
  --text-h2: clamp(2rem, 3.1vw, 3rem);
  --text-h3: clamp(1.5rem, 2.1vw, 2rem);
  --text-body: 1rem;
  --text-num: clamp(1.6rem, 2.3vw, 2.15rem);
  --text-mono: 0.75rem;

  --pad-x: clamp(1rem, 3.9vw, 3.5rem);
  --pad-y: clamp(1.25rem, 3vw, 2.5rem);
  --core-w: 184px;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-roll: cubic-bezier(0.3, 1.35, 0.5, 1);
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--f-body); font-size: var(--text-body); line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
.sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--signal-ink); outline-offset: 3px; }

/* ---------- Shell ---------- */
.core-tl {
  position: relative; min-height: 100vh; min-height: 100svh;
  padding: var(--pad-y) var(--pad-x);
  display: grid;
  grid-template-columns: minmax(330px, 1fr) 320px minmax(360px, 1.05fr);
  grid-template-rows: auto 1fr;
  column-gap: clamp(1.5rem, 3vw, 3rem);
  row-gap: 1.25rem;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 70% 10%, rgba(255,255,255,0.55), transparent 60%),
    var(--paper);
}
.core-tl::before { /* field-notebook grain */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0.5; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .07 0 0 0 0 .1 0 0 0 0 .12 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}
.topbar {
  grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  font-family: var(--f-mono); font-size: var(--text-mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--rule); padding-bottom: 0.75rem; position: relative; z-index: 2;
}
.topbar b { color: var(--ink); font-weight: 500; }
.topbar .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--signal); margin-right: 0.5rem; vertical-align: 1px; }

/* ---------- Text column ---------- */
.text { grid-column: 1; grid-row: 2; display: flex; flex-direction: column; min-width: 0; position: relative; z-index: 2; }
.h2 { font-family: var(--f-display); font-weight: 300; font-size: var(--text-h2); line-height: 1.02; letter-spacing: -0.02em; margin: 0.25rem 0 0.6rem; max-width: 14ch; }
.h2 em { font-style: italic; color: var(--signal-ink); }
.lede { margin: 0; color: var(--muted); max-width: 40ch; font-size: 0.94rem; }

.readout { display: flex; align-items: flex-end; gap: 1rem; margin-top: auto; padding-top: 1rem; }
.year {
  display: flex; font-family: var(--f-display); font-weight: 300; font-size: var(--text-year);
  line-height: 1; letter-spacing: -0.045em; height: 1.12em; overflow: hidden; margin-left: -0.04em;
  font-variant-numeric: lining-nums; user-select: none;
}
.yr { display: block; height: 1.12em; overflow: hidden; }
.yr span { display: flex; flex-direction: column; transform: translateY(calc(var(--d, 0) * -1.12em)); transition: transform 560ms var(--ease-roll); transition-delay: var(--dl, 0ms); }
.yr i { font-style: normal; display: block; height: 1.12em; line-height: 1.12; text-align: center; }
.depth { font-family: var(--f-mono); font-size: var(--text-mono); color: var(--muted); line-height: 1.45; padding-bottom: 0.9em; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
.depth b { display: block; font-size: 1.35rem; color: var(--ink); font-weight: 500; letter-spacing: -0.01em; text-transform: none; font-variant-numeric: tabular-nums; }

.stack { display: grid; margin-top: 0.75rem; }
.era { grid-area: 1 / 1; visibility: hidden; opacity: 0; }
.era.is-on { visibility: visible; opacity: 1; }
.era .kicker { font-family: var(--f-mono); font-size: var(--text-mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--signal-ink); margin: 0 0 0.35rem; }
.era h3 { font-family: var(--f-display); font-weight: 400; font-size: var(--text-h3); line-height: 1.05; letter-spacing: -0.015em; margin: 0 0 0.6rem; }
.era p.body { margin: 0; max-width: 46ch; font-size: 0.97rem; line-height: 1.55; color: var(--ink-2); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; margin: 1.1rem 0 0; border-top: 1px solid var(--rule); padding-top: 0.85rem; }
.stat { margin: 0; min-width: 0; }
.stat dd { margin: 0; font-family: var(--f-display); font-weight: 300; font-size: var(--text-num); line-height: 1; letter-spacing: -0.03em; white-space: nowrap; font-variant-numeric: tabular-nums lining-nums; }
.stat dd small { font-size: 0.5em; letter-spacing: 0; margin-left: 0.12em; color: var(--muted); }
.stat dt { margin-top: 0.4rem; font-size: 0.78rem; line-height: 1.35; color: var(--muted); }
.era.is-on > * { animation: rise 620ms var(--ease-out) both; }
.era.is-on > :nth-child(2) { animation-delay: 60ms; }
.era.is-on > :nth-child(3) { animation-delay: 120ms; }
.era.is-on > :nth-child(4) { animation-delay: 180ms; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.controls { display: flex; align-items: center; gap: 0.5rem; margin-top: 1.4rem; }
.btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--rule-strong); background: transparent;
  display: grid; place-items: center; cursor: pointer; position: relative; transition: background 200ms, color 200ms, border-color 200ms;
}
.btn:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn:disabled { opacity: 0.35; cursor: default; background: transparent; color: var(--ink); border-color: var(--rule-strong); }
.btn svg { width: 16px; height: 16px; }
.btn.play { width: 52px; height: 52px; border: 0; background: var(--ink); color: var(--paper); }
.btn.play:hover { background: var(--signal-ink); }
.btn.play .ring { position: absolute; inset: -5px; width: calc(100% + 10px); height: calc(100% + 10px); transform: rotate(-90deg); pointer-events: none; }
.btn.play .ring circle { fill: none; stroke-width: 2; }
.btn.play .ring .trk { stroke: var(--rule); }
.btn.play .ring .bar { stroke: var(--signal); stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: calc(100 - var(--p, 0) * 100); }
.btn.play .i-play { display: none; }
.btn.play[data-state="paused"] .i-play { display: block; }
.btn.play[data-state="paused"] .i-pause { display: none; }
.ctl-label { font-family: var(--f-mono); font-size: var(--text-mono); color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-left: 0.25rem; line-height: 1.4; }
.ctl-label b { color: var(--ink); font-weight: 500; }
.counter { white-space: nowrap; margin-left: auto; font-family: var(--f-mono); font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter b { color: var(--ink); font-weight: 500; }

/* ---------- Core column ---------- */
.stage { grid-column: 2; grid-row: 2; position: relative; display: flex; flex-direction: column; min-height: 520px; z-index: 3; }
.stage-cap { font-family: var(--f-mono); font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; padding-left: 74px; padding-right: 50px; }
.stage-cap.bot { white-space: nowrap; gap: 0.75rem; justify-content: flex-start; }
.stage-cap.top { position: absolute; top: 196px; left: 0; width: 70px; padding: 0; flex-direction: column; align-items: flex-end; text-align: right; transform: translateY(calc(-100% - 6px)); z-index: 2; pointer-events: none; line-height: 1.5; }
.stage-cap b { color: var(--ink); font-weight: 500; }
.rig {
  position: relative; flex: 1; margin: 0.5rem 0;
  display: grid; grid-template-columns: 26px 48px var(--core-w) 1fr; grid-template-rows: 196px 1fr;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.brackets { grid-column: 1; grid-row: 2; position: relative; }
.bracket {
  position: absolute; left: 0; width: 26px; border: 0; padding: 0; background: transparent; cursor: pointer;
  display: flex; justify-content: center;
}
.bracket::before { content: ""; position: absolute; left: 11px; top: 22px; bottom: 2px; width: 3px; border-radius: 2px; background: var(--rule-strong); transition: background 220ms, width 220ms, left 220ms; }
.bracket span { position: relative; margin-top: 4px; font-family: var(--f-mono); font-size: 0.62rem; background: var(--paper); line-height: 1.2; padding: 1px 0; color: var(--muted); }
.bracket:hover::before { background: var(--ink); }
.bracket.is-on::before { background: var(--signal); width: 5px; left: 10px; }
.bracket.is-on span { color: var(--ink); font-weight: 500; }
.gauge { grid-column: 2; grid-row: 2; position: relative; }
.gauge i { position: absolute; right: 0; height: 1px; width: 8px; background: var(--rule-strong); }
.gauge i.m5 { width: 16px; background: var(--ink); }
.gauge em { position: absolute; right: 20px; transform: translateY(-50%); font-style: normal; font-family: var(--f-mono); font-size: 0.62rem; color: var(--muted); }
.core { grid-column: 3; grid-row: 2; position: relative; border-radius: 10px; }
canvas.gl { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; opacity: 0; transition: opacity 700ms var(--ease-out); }
.has-3d canvas.gl { opacity: 1; }
.has-3d .core canvas.ice, .has-3d .core .sheen, .has-3d .socket, .has-3d .slab, .has-3d .core .reveal { visibility: hidden; }
.has-3d .core canvas.ice { visibility: visible; opacity: 0; }
.core canvas.ice { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 10px; box-shadow: 0 1px 0 rgba(255,255,255,0.7) inset, 0 18px 40px -18px rgba(18,26,32,0.45); cursor: pointer; }
.core .sheen { position: absolute; inset: 0; border-radius: 10px; pointer-events: none; mix-blend-mode: screen; opacity: 0.75;
  background: linear-gradient(90deg, transparent calc(var(--sx, 30%) - 14%), rgba(255,255,255,0.55) var(--sx, 30%), transparent calc(var(--sx, 30%) + 12%)); transition: --sx 0s; }
.core .reveal { position: absolute; inset: 0; border-radius: 10px; background: var(--paper); transform-origin: 50% 100%; pointer-events: none; }
.socket { position: absolute; left: 0; right: 0; background: var(--socket); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.3), inset 10px 0 18px rgba(0,0,0,0.55); opacity: 0; transition: opacity 300ms; pointer-events: none; }
.socket.is-on { opacity: 1; }
.slab { position: absolute; left: 0; right: 0; pointer-events: none; transform: translate(0, 0); transition: transform 680ms var(--ease-out), filter 680ms; will-change: transform; filter: drop-shadow(0 10px 14px rgba(18,26,32,0.35)); }
.slab canvas { display: block; width: 100%; height: 100%; }
.slab.is-out { transform: translateX(var(--out, 52px)); }
.horizon { position: absolute; left: calc(100% + 8px); white-space: nowrap; font-family: var(--f-mono); font-size: 0.6rem; color: var(--muted); transform: translateY(-50%); pointer-events: none; transition: opacity 250ms; }
.horizon::before { content: ""; display: inline-block; width: 8px; height: 1px; background: currentColor; margin-right: 4px; vertical-align: middle; }
.horizon.is-hidden { opacity: 0; }

.probe { position: absolute; left: 0; right: 0; top: 0; height: 0; pointer-events: none; z-index: 4; }
.has-3d .probe .line { left: 26px; width: 54px; }
.probe .line { position: absolute; left: 26px; width: calc(48px + var(--core-w) + 6px); top: -1px; height: 2px; background: var(--signal); box-shadow: 0 0 0 1px rgba(236,238,233,0.6); }
.probe .handle {
  pointer-events: auto; position: absolute; left: 6px; top: 0; transform: translateY(-50%);
  height: 32px; min-width: 70px; padding: 0 10px 0 8px; border-radius: 16px; background: var(--signal); color: #fff;
  display: flex; align-items: center; gap: 6px; cursor: grab; touch-action: none; white-space: nowrap;
  font-family: var(--f-mono); font-size: 0.75rem; font-weight: 500; font-variant-numeric: tabular-nums;
  box-shadow: 0 6px 14px -6px rgba(168,54,10,0.7); transition: transform 180ms var(--ease-out), background 180ms;
}
.probe .handle:hover, .probe .handle:focus-visible { transform: translateY(-50%) scale(1.06); }
.probe .handle:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.probe .handle.is-drag { cursor: grabbing; background: var(--signal-ink); }
.probe .grip { width: 10px; height: 12px; background: repeating-linear-gradient(180deg, rgba(255,255,255,0.9) 0 1.5px, transparent 1.5px 4px); }
.probe .handle .val { color: #fff; }

/* ---------- Photo column ---------- */
.plate { grid-column: 3; grid-row: 2; display: flex; flex-direction: column; min-width: 0; position: relative; z-index: 1; }
.leader { position: absolute; height: 1px; background: var(--signal); left: 0; top: 0; width: 0; transform-origin: left; transition: top 600ms var(--ease-out), width 600ms var(--ease-out); pointer-events: none; z-index: 2; }
.frame { position: relative; flex: 1; min-height: 360px; background: var(--frame); overflow: hidden; border-radius: 4px; }
.frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; visibility: hidden; user-select: none; filter: contrast(1.04) saturate(0.86) sepia(0.08); }
.frame::after { /* one grade for the whole archive: grain + halation + vignette */
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(18,26,32,0.38) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23g)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay; box-shadow: inset 0 0 40px rgba(255,140,90,0.10);
}
.frame img.is-prev { visibility: visible; z-index: 1; }
.frame img.is-on { visibility: visible; z-index: 2; }
.frame .plate-no { position: absolute; z-index: 4; top: 12px; left: 12px; font-family: var(--f-mono); font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; color: #fff; background: rgba(18,26,32,0.72); padding: 4px 8px; border-radius: 3px; }
.caption { display: grid; margin-top: 0.7rem; min-height: 2.6em; }
.caption p { grid-area: 1 / 1; margin: 0; font-family: var(--f-mono); font-size: var(--text-mono); color: var(--muted); line-height: 1.45; visibility: hidden; }
.caption p.is-on { visibility: visible; animation: rise 520ms var(--ease-out) both 120ms; }
.caption b { color: var(--ink); font-weight: 500; }

/* Intro: the core is drilled in from the surface */
.core-tl.is-intro .reveal { animation: drill 1300ms cubic-bezier(0.65, 0, 0.35, 1) 250ms both; }
@keyframes drill { from { transform: scaleY(1); } to { transform: scaleY(0); } }
.core-tl:not(.is-intro) .reveal { transform: scaleY(0); }

/* ---------- ≤1180: tighter ---------- */
@media (max-width: 1180px) {
  .core-tl { grid-template-columns: minmax(300px, 1fr) 216px minmax(300px, 1fr); }
  :root { --core-w: 116px; }
  .stats { gap: 0.5rem; }
}

/* ---------- ≤900: horizontal core ---------- */
@media (max-width: 900px) {
  :root { --text-year: clamp(5rem, 22vw, 7.5rem); --core-w: auto; }
  .core-tl { display: flex; flex-direction: column; gap: 0; min-height: 0; overflow: visible; }
  .topbar { order: 0; flex-wrap: wrap; row-gap: 0.25rem; }
  .topbar .r { display: none; }
  .text { display: contents; }
  .intro { order: 1; margin-top: 1rem; }
  .stage { order: 2; min-height: 0; margin-top: 1.25rem; }
  .readout { order: 3; margin-top: 0.5rem; padding-top: 0; }
  .plate { order: 4; }
  .stack { order: 5; margin-top: 1.25rem; }
  .controls { order: 6; }
  .stage-cap { padding: 0 0 0 70px; }
  .rig { margin: 0.4rem 0 0; display: grid; grid-template-columns: 70px 1fr; grid-template-rows: 22px 26px 80px 48px; touch-action: pan-y; }
  .stage-cap { padding-left: 70px; }
  .stage-cap.top { position: static; transform: none; width: auto; flex-direction: row; align-items: baseline; text-align: left; padding-left: 70px; }
  .brackets { grid-column: 2; grid-row: 1; }
  .bracket { top: 0; height: 26px; width: auto; }
  .bracket::before { left: 2px; right: 2px; top: 18px; bottom: auto; width: auto; height: 3px; }
  .bracket.is-on::before { left: 2px; width: auto; height: 5px; top: 17px; }
  .bracket span { margin-top: 0; padding: 0 3px; }
  .gauge { grid-column: 2; grid-row: 2; }
  .gauge i { right: auto; bottom: 0; width: 1px; height: 7px; }
  .gauge i.m5 { width: 1px; height: 13px; }
  .gauge em { right: auto; transform: translateX(-50%); top: 0; }
  .core { grid-column: 2; grid-row: 3; }
  .has-3d .probe .line { left: -1px; width: 2px; height: calc(26px + 8px); top: 22px; }
  .core .sheen { background: linear-gradient(180deg, transparent 12%, rgba(255,255,255,0.5) 32%, transparent 48%); }
  .core .reveal { transform-origin: 100% 50%; }
  .core-tl.is-intro .reveal { animation-name: drillx; }
  .core-tl:not(.is-intro) .reveal { transform: scaleX(0); }
  @keyframes drillx { from { transform: scaleX(1); } to { transform: scaleX(0); } }
  .socket { top: 0; bottom: 0; left: auto; right: auto; box-shadow: inset 0 -8px 14px rgba(0,0,0,0.55); }
  .slab { top: 0; bottom: 0; left: auto; right: auto; }
  .slab.is-out { transform: translateY(-20px); }
  .horizon { display: none; }
  .probe { left: 0; top: 0; bottom: 0; right: auto; width: 0; height: auto; }
  .probe .line { left: -1px; top: 22px; width: 2px; height: calc(26px + 80px + 8px); }
  .probe .handle { left: 0; top: auto; bottom: 0; transform: translateX(-50%); }
  .probe .handle:hover, .probe .handle:focus-visible { transform: translateX(-50%) scale(1.06); }
  .plate { margin-top: 1rem; }
  .frame { flex: none; aspect-ratio: 4 / 3.3; min-height: 0; }
  .leader { display: none; }
  .controls { margin-top: 1.25rem; }
}
@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; }
  .stat dd { font-size: 1.45rem; }
  .stat dt { font-size: 0.72rem; }
  .ctl-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .yr span, .slab, .leader, .socket, .probe .handle, .btn { transition: none !important; }
  .era.is-on > *, .caption p.is-on { animation: none !important; }
  .core-tl.is-intro .reveal { animation: none !important; transform: scale(0); }
}
</style>
</head>
<body>

<section class="core-tl is-intro" id="core-timeline" aria-labelledby="ct-h">
  <div class="topbar">
    <span><span class="dot" aria-hidden="true"></span><b>Ullbreen Ice Station</b> &middot; Station history</span>
    <span class="r">Core UB-25 &middot; top 38.4 m &middot; 0.6 m of snow a year</span>
  </div>

  <div class="text">
    <div class="intro">
      <h2 class="h2" id="ct-h">Sixty-four winters, read <em>from the top down</em>.</h2>
      <p class="lede">Every band in this core is one year of snow. Pull the probe down and the station's history comes up in the order the ice keeps it: newest at the surface, the first tents at the bottom.</p>
    </div>

    <div class="readout">
      <div class="year" aria-hidden="true" data-year>
        <span class="yr"><span><i>0</i><i>1</i><i>2</i><i>3</i><i>4</i><i>5</i><i>6</i><i>7</i><i>8</i><i>9</i></span></span>
        <span class="yr"><span><i>0</i><i>1</i><i>2</i><i>3</i><i>4</i><i>5</i><i>6</i><i>7</i><i>8</i><i>9</i></span></span>
        <span class="yr"><span><i>0</i><i>1</i><i>2</i><i>3</i><i>4</i><i>5</i><i>6</i><i>7</i><i>8</i><i>9</i></span></span>
        <span class="yr"><span><i>0</i><i>1</i><i>2</i><i>3</i><i>4</i><i>5</i><i>6</i><i>7</i><i>8</i><i>9</i></span></span>
      </div>
      <div class="depth" aria-hidden="true">Probe depth<b data-depth>0.3 m</b>below surface</div>
    </div>

    <div class="stack" data-stack>
      <article class="era is-on" data-era="0">
        <p class="kicker">Era 01 &middot; 2016&ndash;2025</p>
        <h3>Ice that leaves</h3>
        <p class="body">The surface under Camp One has dropped 41 metres since the first tents. In 2016 the station was rebuilt on steel legs that are jacked up every spring. In 2023 two replicate cores went south in a freezer ship, to be kept where no summer can reach them.</p>
        <dl class="stats">
          <div class="stat"><dd data-count="41">41<small>m</small></dd><dt>surface lowered since 1961</dt></div>
          <div class="stat"><dd data-count="2">2</dd><dt>replicate cores sent south</dt></div>
          <div class="stat"><dd data-count="9">9</dd><dt>people over&shy;wintering</dt></div>
        </dl>
      </article>
      <article class="era" data-era="1">
        <p class="kicker">Era 02 &middot; 2008&ndash;2015</p>
        <h3>The ash came in April</h3>
        <p class="body">On 19 April 2010 the wind brought ash from Iceland. It is still there: a grey line three millimetres thick, nine metres down. Two summers later the whole surface melted for four days and refroze into a glassy lens. Thirty-four labs asked for a slice of both.</p>
        <dl class="stats">
          <div class="stat"><dd data-count="3">3<small>mm</small></dd><dt>ash band, 9.0 m down</dt></div>
          <div class="stat"><dd data-count="11">11<small>mm</small></dd><dt>melt lens, July 2012</dt></div>
          <div class="stat"><dd data-count="34">34</dd><dt>labs sharing the slices</dt></div>
        </dl>
      </article>
      <article class="era" data-era="2">
        <p class="kicker">Era 03 &middot; 1994&ndash;2007</p>
        <h3>Gravel in the teeth</h3>
        <p class="body">Eleven seasons, one hole. On 2 August 1997 the drill came up with gravel in its teeth at 2,540 metres. The ice just above bedrock fell as snow 118,000 years ago. Bag 4,412 from that run still lies on the light table for visitors.</p>
        <dl class="stats">
          <div class="stat"><dd data-count="2540">2,540<small>m</small></dd><dt>drilled to bedrock</dt></div>
          <div class="stat"><dd data-count="118" data-suffix="k">118k</dd><dt>years in the oldest ice</dt></div>
          <div class="stat"><dd data-count="11">11</dd><dt>drilling seasons</dt></div>
        </dl>
      </article>
      <article class="era" data-era="3">
        <p class="kicker">Era 04 &middot; 1983&ndash;1993</p>
        <h3>A library made of cold</h3>
        <p class="body">Core needs a cold that never breaks, so the crew dug one. A 212-metre trench under the snow became the library: shelves of silver tubes at &minus;25&nbsp;&deg;C, summer and winter. In 1992 they found Pinatubo's sulphate in the newest snow, a year after the eruption.</p>
        <dl class="stats">
          <div class="stat"><dd data-count="6800">6,800<small>m</small></dd><dt>of core on the shelves</dt></div>
          <div class="stat"><dd data-count="-25" data-unit="°C">&minus;25<small>&deg;C</small></dd><dt>in the trench, all year</dt></div>
          <div class="stat"><dd data-count="212">212<small>m</small></dd><dt>of trench, dug by hand</dt></div>
        </dl>
      </article>
      <article class="era" data-era="4">
        <p class="kicker">Era 05 &middot; 1970&ndash;1982</p>
        <h3>The thermal drill</h3>
        <p class="body">A heated ring melted its way through the ice at four metres an hour. The first deep core reached 412 metres in 1974 and came up in 1,900 numbered sections, each one logged by hand in a ledger that still sits in the radio hut.</p>
        <dl class="stats">
          <div class="stat"><dd data-count="412">412<small>m</small></dd><dt>first deep core, 1974</dt></div>
          <div class="stat"><dd data-count="1900">1,900</dd><dt>sections logged by hand</dt></div>
          <div class="stat"><dd data-count="4">4<small>m/h</small></dd><dt>melting speed</dt></div>
        </dl>
      </article>
      <article class="era" data-era="5">
        <p class="kicker">Era 06 &middot; 1961&ndash;1969</p>
        <h3>Four tents and an auger</h3>
        <p class="body">Four overwinterers, four tents and an auger turned by hand. They reached 18 metres in the first season, deep enough to find the 1963 bomb-test horizon a few winters later and prove the snow was keeping dates. Everything came in on eleven sledge loads.</p>
        <dl class="stats">
          <div class="stat"><dd data-count="18">18<small>m</small></dd><dt>by hand auger, 1961</dt></div>
          <div class="stat"><dd data-count="4">4</dd><dt>people, first winter</dt></div>
          <div class="stat"><dd data-count="11">11</dd><dt>sledge loads of kit</dt></div>
        </dl>
      </article>
    </div>

    <div class="controls">
      <button class="btn play" type="button" data-play data-state="playing" aria-label="Pause the guided descent">
        <svg class="ring" viewBox="0 0 62 62" aria-hidden="true"><circle class="trk" cx="31" cy="31" r="29" pathLength="100"/><circle class="bar" cx="31" cy="31" r="29" pathLength="100"/></svg>
        <svg class="i-pause" viewBox="0 0 16 16" aria-hidden="true"><rect x="3.5" y="2.5" width="3" height="11" fill="currentColor"/><rect x="9.5" y="2.5" width="3" height="11" fill="currentColor"/></svg>
        <svg class="i-play" viewBox="0 0 16 16" aria-hidden="true"><path d="M4 2.5v11l9.5-5.5z" fill="currentColor"/></svg>
      </button>
      <button class="btn" type="button" data-step="-1" aria-label="Up one era (newer)"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 13V3M3.5 7.5 8 3l4.5 4.5" fill="none" stroke="currentColor" stroke-width="1.6"/></svg></button>
      <button class="btn" type="button" data-step="1" aria-label="Down one era (older)"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 3v10M3.5 8.5 8 13l4.5-4.5" fill="none" stroke="currentColor" stroke-width="1.6"/></svg></button>
      <span class="ctl-label" data-ctl-label><b>Guided descent</b><br>stops when you drag</span>
      <span class="counter" aria-hidden="true"><b data-counter>01</b> / 06</span>
    </div>
  </div>

  <div class="stage">
    <div class="stage-cap top"><span><b>Surface</b> 2025</span><span>0.0 m</span></div>
    <div class="rig" data-rig>
      <canvas class="gl" data-gl aria-hidden="true"></canvas>
      <div class="brackets" data-brackets></div>
      <div class="gauge" data-gauge aria-hidden="true"></div>
      <div class="core" data-core>
        <canvas class="ice" data-ice aria-hidden="true"></canvas>
        <div class="sheen" aria-hidden="true"></div>
        <div class="socket" data-socket aria-hidden="true"></div>
        <div class="slab" data-slab aria-hidden="true"><canvas data-slab-canvas></canvas></div>
        <div class="reveal" aria-hidden="true"></div>
        <div data-horizons aria-hidden="true"></div>
      </div>
      <div class="probe" data-probe>
        <div class="line" aria-hidden="true"></div>
        <div class="handle" data-handle role="slider" tabindex="0" aria-label="Core probe: year of snow" aria-orientation="vertical"
             aria-valuemin="1961" aria-valuemax="2024" aria-valuenow="2024" aria-valuetext="2024">
          <span class="grip" aria-hidden="true"></span><span class="val" data-handle-val aria-hidden="true">0.3 m</span>
        </div>
      </div>
    </div>
    <div class="stage-cap bot"><span><b>1961</b> &middot; first snow</span><span>38.4 m</span></div>
  </div>

  <figure class="plate" style="margin:0">
    <div class="leader" data-leader aria-hidden="true"></div>
    <div class="frame" data-frame>
      <img data-i="0" class="is-on" src="assets/2024-stilts.webp" alt="Aerial view of a small station of dark red modules raised on steel legs above a melting glacier, meltwater channels running through grey ice." width="860" height="1152" decoding="async">
      <img data-i="1" src="assets/2010-ash.webp" alt="A researcher in a hairnet and blue gloves measures a white ice core with calipers on a cutting table beside a band saw." width="860" height="1152" decoding="async">
      <img data-i="2" src="assets/1997-bedrock.webp" alt="Gloved hands hold a metre of perfectly clear old ice over a lit light table, a handwritten log sheet beneath it." width="860" height="1152" decoding="async">
      <img data-i="3" src="assets/1983-library.webp" alt="A bearded researcher with a clipboard in a snow tunnel lined with wooden shelves of silver core tubes, lit by bare bulbs." width="860" height="1152" decoding="async">
      <img data-i="4" src="assets/1970-drill.webp" alt="Faded colour photo of a steel drilling derrick rising from a deep snow trench, an orange winch at its base and a researcher in red on a ladder." width="860" height="1152" decoding="async">
      <img data-i="5" src="assets/1961-camp.webp" alt="Black and white photo of four canvas tents on flat glacier ice, two hooded figures turning a hand auger beside a loaded sledge." width="860" height="1152" decoding="async">
      <span class="plate-no" data-plate-no aria-hidden="true">Plate 1 / 6</span>
    </div>
    <figcaption class="caption" data-caption>
      <p class="is-on"><b>Plate 1</b> &middot; Station on stilts, east margin, August 2024. Drone frame, digital.</p>
      <p><b>Plate 2</b> &middot; Cutting room, core UB-10, bag 15. Flash, early digital, 2010.</p>
      <p><b>Plate 3</b> &middot; Light table, run 97/4, bag 4,412. 35&nbsp;mm colour, 1997.</p>
      <p><b>Plate 4</b> &middot; The core library trench at &minus;25&nbsp;&deg;C, winter 1983. Colour negative.</p>
      <p><b>Plate 5</b> &middot; Thermal drill derrick in the north trench, 1970. Slide film, faded.</p>
      <p><b>Plate 6</b> &middot; Camp One, first season, 1961. Silver gelatin print, station archive.</p>
    </figcaption>
  </figure>

  <p class="sr" aria-live="polite" data-live></p>
</section>

<script>
(() => {
  'use strict';
  /* ---------- Fixed data ---------- */
  const CFG = {
    surface: 2025,        // top of the core
    bottom: 1961,         // first logged winter
    snow: 0.6,            // metres of snow per year (depth = (2025 - y) * 0.6)
    autoplay: 5200,       // ms per era in the guided descent
    wheelGap: 600,        // ms between wheel steps
    revealMs: 820,        // strata mask reveal
    countMs: 900,         // stat count-up
    digitGap: 45,         // odometer stagger, right to left
    spring: { k: 150, c: 24 },  // probe spring (stiffness, damping), mass 1
    slabOut: 52           // px the active slab slides out (desktop)
  };
  const ERAS = [ // newest first = top of the core
    { from: 2016, to: 2024, key: 2024 },
    { from: 2008, to: 2015, key: 2010 },
    { from: 1994, to: 2007, key: 1997 },
    { from: 1983, to: 1993, key: 1983 },
    { from: 1970, to: 1982, key: 1970 },
    { from: 1961, to: 1969, key: 1961 }
  ];
  const TITLES = ['Ice that leaves', 'The ash came in April', 'Gravel in the teeth', 'A library made of cold', 'The thermal drill', 'Four tents and an auger'];
  const HORIZONS = [ // real dating horizons glaciologists use
    { y: 2012, label: 'melt lens', kind: 'melt' },
    { y: 2010, label: 'ash', kind: 'ash' },
    { y: 1992, label: 'sulphate', kind: 'sulph' },
    { y: 1963, label: 'bomb peak', kind: 'bomb' }
  ];
  const SPAN = CFG.surface - CFG.bottom; // 64 years
  const VMIN = CFG.bottom + 0.5, VMAX = CFG.surface - 0.5;

  const root = document.getElementById('core-timeline');
  const $ = (s, el = root) => el.querySelector(s);
  const $$ = (s, el = root) => Array.from(el.querySelectorAll(s));
  const REDUCED = matchMedia('(prefers-reduced-motion: reduce)').matches;
  const mqH = matchMedia('(max-width: 900px)');

  const rig = $('[data-rig]'), coreEl = $('[data-core]'), ice = $('[data-ice]');
  const slab = $('[data-slab]'), slabC = $('[data-slab-canvas]'), socket = $('[data-socket]');
  const probe = $('[data-probe]'), handle = $('[data-handle]'), handleVal = $('[data-handle-val]');
  const gauge = $('[data-gauge]'), bracketsEl = $('[data-brackets]'), horizonsEl = $('[data-horizons]');
  const yrCols = $$('.yr > span'), depthEl = $('[data-depth]');
  const eras = $$('.era'), caps = $$('[data-caption] p'), imgs = $$('[data-frame] img');
  const counterEl = $('[data-counter]'), plateNo = $('[data-plate-no]'), live = $('[data-live]');
  const playBtn = $('[data-play]'), leader = $('[data-leader]'), frame = $('[data-frame]');

  /* ---------- Seeded noise ---------- */
  function rng(seed) { let s = seed >>> 0; return () => { s = (s + 0x6D2B79F5) >>> 0; let t = s; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; }
  // Wavy edge shared by the slab cut and the photo mask: -1..1
  function edge(seed, u) {
    const r = rng(seed * 977 + 13); const p1 = r() * 6.28, p2 = r() * 6.28, p3 = r() * 6.28;
    return 0.55 * Math.sin(6.283 * u * 2 + p1) + 0.3 * Math.sin(6.283 * u * 5 + p2) + 0.15 * Math.sin(6.283 * u * 11 + p3);
  }

  /* ---------- Geometry ---------- */
  let horiz = mqH.matches, L = 0, T = 0; // L: length along time axis, T: thickness across
  const sOf = (v) => (CFG.surface - v) / SPAN * L;          // position along the axis for a year value
  const vOf = (s) => CFG.surface - (s / L) * SPAN;
  const eraOf = (yr) => { for (let i = 0; i < ERAS.length; i++) if (yr >= ERAS[i].from) return i; return ERAS.length - 1; };
  const bandS = (i) => [sOf(ERAS[i].to + 1), sOf(ERAS[i].from)];

  /* ---------- Draw the ice ---------- */
  const lerp = (a, b, t) => a + (b - a) * t;
  function drawIce() {
    const r = coreEl.getBoundingClientRect();
    horiz = mqH.matches;
    L = horiz ? r.width : r.height; T = horiz ? r.height : r.width;
    if (L < 10 || T < 10) return;
    const dpr = Math.min(2, window.devicePixelRatio || 1);
    ice.width = Math.round(r.width * dpr); ice.height = Math.round(r.height * dpr);
    const ctx = ice.getContext('2d');
    // Work in "vertical" coordinates: x across (0..T), y along (0..L). Horizontal = transpose.
    if (horiz) ctx.setTransform(0, dpr, dpr, 0, 0, 0); else ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
    drawStrata(ctx, T, L);
    // Cylinder shading across the core
    const cg = ctx.createLinearGradient(0, 0, T, 0);
    cg.addColorStop(0, 'rgba(20,40,52,0.38)'); cg.addColorStop(0.18, 'rgba(20,40,52,0.06)'); cg.addColorStop(0.32, 'rgba(255,255,255,0.22)');
    cg.addColorStop(0.55, 'rgba(255,255,255,0)'); cg.addColorStop(0.85, 'rgba(20,40,52,0.16)'); cg.addColorStop(1, 'rgba(20,40,52,0.42)');
    ctx.fillStyle = cg; ctx.fillRect(0, 0, T, L);
    // Saw cuts between core sections (every 1 m of core)
    ctx.strokeStyle = 'rgba(18,26,32,0.18)'; ctx.lineWidth = 0.7;
    const mPx = L / (SPAN * CFG.snow);
    for (let m = 1; m < SPAN * CFG.snow; m++) { ctx.beginPath(); ctx.moveTo(0, m * mPx); ctx.lineTo(T * 0.14, m * mPx); ctx.moveTo(T * 0.86, m * mPx); ctx.lineTo(T, m * mPx); ctx.stroke(); }
    if (horiz) { probe.style.left = coreEl.offsetLeft + 'px'; probe.style.top = ''; } else { probe.style.top = coreEl.offsetTop + 'px'; probe.style.left = ''; }
    buildGauge(); buildBrackets(); buildHorizons(); drawSlab(cur);
    version++;
  }
  let version = 0;
  // Annual strata, dust lines, grain, bubbles and dating horizons. x across (0..T), y along (0..Lc).
  // Used by the 2D fallback and, unwrapped, as the texture of the 3D core.
  function drawStrata(ctx, T, Lc, lit) {
    const sO = (v) => (CFG.surface - v) / SPAN * Lc;
    const rand = rng(1961);
    // the 3D core is lit by real lights, so its albedo starts darker and bluer
    const top = lit ? [214, 224, 226] : [244, 246, 242], deep = lit ? [84, 128, 152] : [150, 186, 201];
    const dust = lit ? 0.2 : 0.16;
    const perYear = Lc / SPAN;
    for (let y = CFG.surface - 1; y >= CFG.bottom; y--) {
      const s0 = sO(y + 1), s1 = sO(y), t = (CFG.surface - y) / SPAN;
      const jit = (rand() - 0.5) * 14;
      const c = top.map((v, k) => Math.round(lerp(v, deep[k], Math.pow(t, 0.8)) + jit * (k === 2 ? 0.4 : 1)));
      ctx.fillStyle = `rgb(${c[0]},${c[1]},${c[2]})`;
      ctx.fillRect(0, s0, T, s1 - s0 + 0.6);
      // Summer dust line at the base of each annual band, slightly wavy
      ctx.beginPath();
      const seed = y * 31;
      for (let x = 0; x <= T; x += 4) { const yy = s1 - 0.8 + edge(seed, x / T) * Math.min(2.2, perYear * 0.18); x === 0 ? ctx.moveTo(x, yy) : ctx.lineTo(x, yy); }
      ctx.strokeStyle = `rgba(92, 84, 66, ${dust + rand() * 0.18})`; ctx.lineWidth = 0.6 + rand() * 0.9; ctx.stroke();
      // Grain and bubbles (more bubbles deeper, firn grain near the top)
      const n = Math.round((s1 - s0) * T / 60);
      for (let k = 0; k < n; k++) {
        const bx = rand() * T, by = s0 + rand() * (s1 - s0);
        if (rand() < t) { ctx.fillStyle = `rgba(255,255,255,${0.35 + rand() * 0.45})`; ctx.beginPath(); ctx.ellipse(bx, by, 0.6 + rand() * 1.3, 0.5 + rand() * 0.9, 0, 0, 6.283); ctx.fill(); }
        else { ctx.fillStyle = `rgba(120,130,130,${0.08 + rand() * 0.12})`; ctx.fillRect(bx, by, 1, 1); }
      }
    }
    // Horizons drawn into the ice
    for (const h of HORIZONS) {
      const sm = sO(h.y + 0.5);
      if (h.kind === 'ash') {
        ctx.beginPath(); for (let x = 0; x <= T; x += 3) { const yy = sm + edge(7, x / T) * 1.6; x === 0 ? ctx.moveTo(x, yy) : ctx.lineTo(x, yy); }
        ctx.strokeStyle = 'rgba(58, 60, 62, 0.85)'; ctx.lineWidth = 2.6; ctx.stroke();
      } else if (h.kind === 'melt') {
        const g = ctx.createLinearGradient(0, sm - 3, 0, sm + 3); g.addColorStop(0, 'rgba(160,205,222,0)'); g.addColorStop(0.5, 'rgba(120,180,206,0.85)'); g.addColorStop(1, 'rgba(160,205,222,0)');
        ctx.fillStyle = g; ctx.fillRect(0, sm - 3, T, 6);
      } else if (h.kind === 'sulph') {
        ctx.fillStyle = 'rgba(196, 170, 96, 0.35)'; ctx.fillRect(0, sm - 1.5, T, 3);
      }
    }
  }

  function buildGauge() {
    gauge.textContent = '';
    const total = SPAN * CFG.snow, frag = document.createDocumentFragment();
    for (let m = 0; m <= Math.floor(total); m++) {
      const p = m / total * L, i = document.createElement('i');
      if (m % 5 === 0) i.className = 'm5';
      if (horiz) i.style.left = p + 'px'; else i.style.top = p + 'px';
      frag.appendChild(i);
      if (m % 10 === 0 && m > 0 && m < total - 2) {
        const em = document.createElement('em'); em.textContent = m + (horiz ? '' : ' m');
        if (horiz) em.style.left = p + 'px'; else em.style.top = p + 'px';
        frag.appendChild(em);
      }
    }
    gauge.appendChild(frag);
  }
  function buildBrackets() {
    bracketsEl.textContent = '';
    ERAS.forEach((e, i) => {
      const [a, b] = bandS(i), btn = document.createElement('button');
      btn.type = 'button'; btn.className = 'bracket' + (i === cur ? ' is-on' : ''); btn.dataset.go = i;
      btn.setAttribute('aria-label', `Era ${i + 1}: ${e.from} to ${e.to}, ${TITLES[i]}`);
      if (i === cur) btn.setAttribute('aria-current', 'step');
      btn.innerHTML = `<span aria-hidden="true">0${i + 1}</span>`;
      if (horiz) { btn.style.left = a + 'px'; btn.style.width = (b - a) + 'px'; } else { btn.style.top = a + 'px'; btn.style.height = (b - a) + 'px'; }
      bracketsEl.appendChild(btn);
    });
  }
  function buildHorizons() {
    horizonsEl.textContent = '';
    if (horiz) return;
    HORIZONS.forEach((h) => {
      const el = document.createElement('span'); el.className = 'horizon'; el.dataset.era = eraOf(h.y);
      el.style.top = sOf(h.y + 0.5) + 'px'; el.textContent = `${h.y} ${h.label}`;
      horizonsEl.appendChild(el);
    });
  }

  /* ---------- Slab: the active era pulled out of the core ---------- */
  function drawSlab(i) {
    if (!L) return;
    const [a, b] = bandS(i), len = b - a, dpr = ice.width / (horiz ? L : T);
    if (horiz) { slab.style.left = socket.style.left = a + 'px'; slab.style.width = socket.style.width = len + 'px'; slab.style.top = socket.style.top = ''; slab.style.height = socket.style.height = ''; }
    else { slab.style.top = socket.style.top = a + 'px'; slab.style.height = socket.style.height = len + 'px'; slab.style.left = socket.style.left = ''; slab.style.width = socket.style.width = ''; }
    const w = horiz ? len : T, h = horiz ? T : len;
    slabC.width = Math.round(w * dpr); slabC.height = Math.round(h * dpr);
    const c = slabC.getContext('2d');
    if (horiz) c.drawImage(ice, a * dpr, 0, len * dpr, T * dpr, 0, 0, slabC.width, slabC.height);
    else c.drawImage(ice, 0, a * dpr, T * dpr, len * dpr, 0, 0, slabC.width, slabC.height);
    // Saw-cut ends with the era's own wobble (the same wobble the photo mask uses)
    const amp = 3, pts = [], N = 18;
    if (!horiz) {
      for (let k = 0; k <= N; k++) pts.push(`${(k / N * 100).toFixed(2)}% ${(amp + edge(i * 2 + 1, k / N) * amp).toFixed(1)}px`);
      for (let k = N; k >= 0; k--) pts.push(`${(k / N * 100).toFixed(2)}% calc(100% - ${(amp + edge(i * 2 + 2, k / N) * amp).toFixed(1)}px)`);
    } else {
      for (let k = 0; k <= N; k++) pts.push(`${(amp + edge(i * 2 + 1, k / N) * amp).toFixed(1)}px ${(k / N * 100).toFixed(2)}%`);
      for (let k = N; k >= 0; k--) pts.push(`calc(100% - ${(amp + edge(i * 2 + 2, k / N) * amp).toFixed(1)}px) ${(k / N * 100).toFixed(2)}%`);
    }
    slab.style.clipPath = `polygon(${pts.join(',')})`;
    placeLeader();
  }
  function pullSlab(i) {
    slab.classList.remove('is-out'); socket.classList.remove('is-on');
    drawSlab(i);
    if (REDUCED) { slab.style.transition = 'none'; }
    void slab.offsetWidth;
    slab.classList.add('is-out'); socket.classList.add('is-on');
    $$('.horizon').forEach((el) => el.classList.toggle('is-hidden', +el.dataset.era === i));
  }
  function placeLeader() {
    if (horiz || !L) return;
    const [a, b] = bandS(cur), rr = root.getBoundingClientRect(), cr = coreEl.getBoundingClientRect(), fr = frame.getBoundingClientRect();
    const plate = frame.parentElement.getBoundingClientRect();
    const x0 = cr.right + CFG.slabOut - plate.left;
    const y = cr.top + (a + b) / 2 - plate.top;
    leader.style.left = x0 + 'px'; leader.style.top = Math.max(0, Math.min(fr.height, y)) + 'px';
    leader.style.width = Math.max(0, fr.left - plate.left - x0 + 18) + 'px';
  }

  /* ---------- Photo: strata-shaped reveal ---------- */
  let revealRaf = 0, onImg = 0;
  function revealPhoto(i) {
    if (i === onImg) return;
    imgs.forEach((im) => im.classList.remove('is-prev'));
    imgs[onImg].classList.remove('is-on'); imgs[onImg].classList.add('is-prev');
    const img = imgs[i]; img.classList.add('is-on'); onImg = i;
    cancelAnimationFrame(revealRaf);
    if (REDUCED) { img.style.clipPath = 'none'; imgs.forEach((im) => im !== img && im.classList.remove('is-prev')); return; }
    const t0 = performance.now(), N = 22;
    const step = (now) => {
      let t = Math.min(1, (now - t0) / CFG.revealMs);
      const e = t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
      const half = e * 0.62, amp = 0.05 * (1 - e * 0.6) + 0.012;
      const top = [], bot = [];
      for (let k = 0; k <= N; k++) {
        const u = k / N;
        top.push(`${(u * 100).toFixed(2)}% ${((0.5 - half - edge(i * 2 + 1, u) * amp) * 100).toFixed(2)}%`);
        bot.unshift(`${(u * 100).toFixed(2)}% ${((0.5 + half + edge(i * 2 + 2, u) * amp) * 100).toFixed(2)}%`);
      }
      img.style.clipPath = `polygon(${top.concat(bot).join(',')})`;
      if (t < 1) revealRaf = requestAnimationFrame(step);
      else { img.style.clipPath = 'none'; imgs.forEach((im) => im !== img && im.classList.remove('is-prev')); }
    };
    img.style.clipPath = 'polygon(0 50%,100% 50%,100% 50%,0 50%)';
    revealRaf = requestAnimationFrame(step);
  }

  /* ---------- Odometer year + depth ---------- */
  let shownYear = null;
  function setYear(yr) {
    if (yr === shownYear) return;
    const prev = shownYear; shownYear = yr;
    const d = String(yr).split('');
    yrCols.forEach((col, k) => {
      col.style.setProperty('--dl', (prev === null ? 0 : (3 - k) * CFG.digitGap) + 'ms');
      col.style.setProperty('--d', d[k]);
    });
  }
  function fmtDepth(v) { return ((CFG.surface - v) * CFG.snow).toFixed(1) + ' m'; }

  /* ---------- Count up ---------- */
  function countUp(article) {
    $$('dd[data-count]', article).forEach((dd) => {
      const end = +dd.dataset.count, unit = dd.querySelector('small'), suffix = dd.dataset.suffix || '';
      const unitHTML = unit ? unit.outerHTML : '';
      const fmt = (n) => (n < 0 ? '−' : '') + Math.abs(n).toLocaleString('en-US') + suffix;
      if (REDUCED) { dd.innerHTML = fmt(end) + unitHTML; return; }
      const t0 = performance.now();
      const tick = (now) => {
        const t = Math.min(1, (now - t0) / CFG.countMs), e = 1 - Math.pow(1 - t, 3);
        dd.innerHTML = fmt(Math.round(end * e)) + unitHTML;
        if (t < 1) requestAnimationFrame(tick);
      };
      requestAnimationFrame(tick);
    });
  }

  /* ---------- Era switch ---------- */
  let cur = 0;
  function showEra(i, announce) {
    if (i === cur) return;
    cur = i;
    eras.forEach((a, k) => a.classList.toggle('is-on', k === i));
    caps.forEach((p, k) => p.classList.toggle('is-on', k === i));
    $$('.bracket').forEach((b, k) => { b.classList.toggle('is-on', k === i); if (k === i) b.setAttribute('aria-current', 'step'); else b.removeAttribute('aria-current'); });
    counterEl.textContent = '0' + (i + 1); plateNo.textContent = `Plate ${i + 1} / 6`;
    $('[data-step="-1"]').disabled = i === 0; $('[data-step="1"]').disabled = i === ERAS.length - 1;
    revealPhoto(i); pullSlab(i); countUp(eras[i]);
    if (announce) live.textContent = `${ERAS[i].from} to ${ERAS[i].to}: ${TITLES[i]}`;
  }

  /* ---------- Probe spring ---------- */
  const P = { v: VMAX, vel: 0, target: VMAX, mode: 'spring' };
  let raf = 0, last = 0;
  function renderProbe() {
    const s = sOf(P.v);
    probe.style.transform = horiz ? `translateX(${s}px)` : `translateY(${s}px)`;
    const yr = Math.max(CFG.bottom, Math.min(CFG.surface - 1, Math.floor(P.v)));
    setYear(yr);
    const dtxt = fmtDepth(P.v); handleVal.textContent = dtxt; depthEl.textContent = dtxt;
    handle.setAttribute('aria-valuenow', yr);
    const e = eraOf(yr);
    handle.setAttribute('aria-valuetext', `${yr}, ${dtxt.replace(' m', ' metres')} down. Era ${e + 1} of 6: ${TITLES[e]}`);
    if (e !== cur) showEra(e, userActed);
  }
  function loop(now) {
    let dt = Math.min(0.25, (now - last) / 1000 || 0.016); last = now;
    if (P.mode === 'spring') {
      // fixed 4 ms substeps: stable at any frame rate, and real-time on slow machines
      while (dt > 0) { const h = Math.min(0.004, dt); dt -= h;
        const a = -CFG.spring.k * (P.v - P.target) - CFG.spring.c * P.vel;
        P.vel += a * h; P.v += P.vel * h; }
      if (Math.abs(P.v - P.target) < 0.002 && Math.abs(P.vel) < 0.01) { P.v = P.target; P.vel = 0; renderProbe(); raf = 0; return; }
    }
    renderProbe();
    raf = requestAnimationFrame(loop);
  }
  function kick() { if (!raf) { last = performance.now(); raf = requestAnimationFrame(loop); } }
  function goVal(v, jump) {
    P.target = Math.max(VMIN, Math.min(VMAX, v));
    if (REDUCED || jump) { P.v = P.target; P.vel = 0; renderProbe(); return; }
    P.mode = 'spring'; kick();
  }
  const goEra = (i) => goVal(ERAS[Math.max(0, Math.min(ERAS.length - 1, i))].key + 0.5);

  /* ---------- User input ---------- */
  let userActed = false;
  function acted() { userActed = true; stopTour(); }

  // Drag along the core (handle, ice, gauge)
  let drag = null;
  function sFromEvent(ev) { const r = coreEl.getBoundingClientRect(); return horiz ? ev.clientX - r.left : ev.clientY - r.top; }
  rig.addEventListener('pointerdown', (ev) => {
    if (ev.button !== 0 || ev.target.closest('.bracket')) return;
    const onHandle = !!ev.target.closest('[data-handle]');
    drag = { id: ev.pointerId, x: ev.clientX, y: ev.clientY, moved: false, onHandle, off: onHandle ? sFromEvent(ev) - sOf(P.v) : 0, lastS: sFromEvent(ev), lastT: performance.now(), vel: 0 };
    if (onHandle || !horiz) { ev.preventDefault(); rig.setPointerCapture(ev.pointerId); }
    if (onHandle) { handle.classList.add('is-drag'); handle.focus({ preventScroll: true }); }
  });
  rig.addEventListener('pointermove', (ev) => {
    if (sheenOk) coreEl.style.setProperty('--sx', (horiz ? 30 : Math.max(18, Math.min(70, (ev.clientX - coreEl.getBoundingClientRect().left) / T * 100))) + '%');
    if (!drag || ev.pointerId !== drag.id) return;
    const dx = ev.clientX - drag.x, dy = ev.clientY - drag.y;
    if (!drag.moved) {
      if (Math.hypot(dx, dy) < 4) return;
      // On the horizontal core a mostly-vertical swipe is a page scroll, not a drag
      if (horiz && !drag.onHandle && Math.abs(dy) > Math.abs(dx)) { drag = null; return; }
      drag.moved = true; acted(); handle.classList.add('is-drag');
      if (!rig.hasPointerCapture(ev.pointerId)) rig.setPointerCapture(ev.pointerId);
    }
    const s = sFromEvent(ev) - drag.off, now = performance.now();
    drag.vel = (s - drag.lastS) / Math.max(1, now - drag.lastT); drag.lastS = s; drag.lastT = now;
    let v = vOf(s);
    if (v > VMAX) v = VMAX + (v - VMAX) * 0.3; if (v < VMIN) v = VMIN - (VMIN - v) * 0.3; // rubber band
    P.mode = 'drag'; P.v = v; P.vel = 0; kick();
  });
  function endDrag(ev) {
    if (!drag || ev.pointerId !== drag.id) return;
    handle.classList.remove('is-drag');
    if (drag.moved) {
      // project the throw, then settle on that era's headline year
      const s = sOf(Math.max(VMIN, Math.min(VMAX, P.v))) + drag.vel * 120;
      const yr = Math.floor(Math.max(VMIN, Math.min(VMAX, vOf(s))));
      P.mode = 'spring'; goEra(eraOf(yr));
    } else if (!drag.onHandle && ev.type === 'pointerup') {
      // a click on a layer opens that era
      acted(); const yr = Math.floor(Math.max(VMIN, Math.min(VMAX, vOf(sFromEvent(ev))))); goEra(eraOf(yr)); showEra(eraOf(yr), true);
    }
    drag = null;
  }
  rig.addEventListener('pointerup', endDrag);
  rig.addEventListener('pointercancel', endDrag);
  let sheenOk = matchMedia('(hover: hover)').matches && !REDUCED;

  bracketsEl.addEventListener('click', (ev) => { const b = ev.target.closest('.bracket'); if (!b) return; acted(); goEra(+b.dataset.go); });
  $$('[data-step]').forEach((b) => b.addEventListener('click', () => { acted(); goEra(cur + +b.dataset.step); }));

  // Wheel over the core: one era per notch; lets the page scroll at the ends
  let wheelAt = 0;
  rig.addEventListener('wheel', (ev) => {
    const d = Math.abs(ev.deltaY) > Math.abs(ev.deltaX) ? ev.deltaY : ev.deltaX;
    if (!d) return;
    const dir = d > 0 ? 1 : -1, next = cur + dir;
    if (next < 0 || next >= ERAS.length) return;
    ev.preventDefault();
    const now = performance.now(); if (now - wheelAt < CFG.wheelGap) return; wheelAt = now;
    acted(); goEra(next);
  }, { passive: false });

  // Keyboard on the slider: arrows = era, Shift+arrows / PageUp/PageDown = one year, Home/End
  handle.addEventListener('keydown', (ev) => {
    const yr = Math.floor(P.target);
    let handled = true;
    switch (ev.key) {
      case 'ArrowUp': case 'ArrowLeft': ev.shiftKey ? goVal(yr + 1.5) : goEra(cur - 1); break;
      case 'ArrowDown': case 'ArrowRight': ev.shiftKey ? goVal(yr - 0.5) : goEra(cur + 1); break;
      case 'PageUp': goVal(yr + 1.5); break;
      case 'PageDown': goVal(yr - 0.5); break;
      case 'Home': goEra(0); break;
      case 'End': goEra(ERAS.length - 1); break;
      default: handled = false;
    }
    if (handled) { ev.preventDefault(); acted(); }
  });

  /* ---------- Guided descent (autoplay) ---------- */
  let touring = !REDUCED, fill = 0, tourRaf = 0, tourLast = 0, inView = false, hovered = false, focusedIn = false;
  function setPlayUI() {
    playBtn.dataset.state = touring ? 'playing' : 'paused';
    playBtn.setAttribute('aria-label', touring ? 'Pause the guided descent' : 'Play the guided descent');
    playBtn.style.setProperty('--p', touring ? fill : 0);
  }
  function stopTour() { touring = false; fill = 0; setPlayUI(); }
  const tourLive = () => touring && inView && !document.hidden && !hovered && !focusedIn && !drag;
  function tourLoop(now) {
    const dt = Math.min(64, now - tourLast); tourLast = now;
    if (tourLive()) {
      fill += dt / CFG.autoplay;
      if (fill >= 1) { fill = 0; goEra(cur + 1 >= ERAS.length ? 0 : cur + 1); }
      playBtn.style.setProperty('--p', fill.toFixed(4));
    }
    tourRaf = (touring && inView && !document.hidden) ? requestAnimationFrame(tourLoop) : 0;
  }
  function wakeTour() { if (!tourRaf && touring && inView && !document.hidden) { tourLast = performance.now(); tourRaf = requestAnimationFrame(tourLoop); } }
  playBtn.addEventListener('click', () => {
    touring = !touring; fill = 0; setPlayUI();
    if (touring) { focusedIn = false; wakeTour(); }
  });
  root.addEventListener('pointerenter', (e) => { if (e.pointerType === 'mouse') hovered = true; });
  root.addEventListener('pointerleave', () => { hovered = false; });
  root.addEventListener('focusin', (e) => { if (e.target !== playBtn) focusedIn = true; });
  root.addEventListener('focusout', (e) => { if (!root.contains(e.relatedTarget)) focusedIn = false; });
  document.addEventListener('visibilitychange', wakeTour);
  new IntersectionObserver((ents) => { inView = ents[0].intersectionRatio >= 0.25; if (inView) wakeTour(); }, { threshold: [0, 0.25, 0.5] }).observe(root);

  /* ---------- Hand-off to the 3D layer (module below) ---------- */
  root.__tl = {
    CFG, ERAS, SPAN, REDUCED, drawStrata, bandS, sOf, eraOf,
    get L() { return L; }, get T() { return T; }, get horiz() { return horiz; }, get cur() { return cur; },
    get v() { return P.v; }, get vel() { return P.vel; }, get version() { return version; },
    core: coreEl, rig
  };
  root.dispatchEvent(new CustomEvent('tl:ready'));

  /* ---------- Boot ---------- */
  let rT = 0;
  function layout() { drawIce(); renderProbe(); }
  window.addEventListener('resize', () => { clearTimeout(rT); rT = setTimeout(() => { layout(); }, 120); });
  mqH.addEventListener('change', layout);
  if ('ResizeObserver' in window) new ResizeObserver(() => { clearTimeout(rT); rT = setTimeout(layout, 120); }).observe(coreEl);
  $('[data-step="-1"]').disabled = true;
  setPlayUI();
  layout();
  pullSlab(0);
  root.addEventListener('animationend', (e) => { if (e.animationName.startsWith('drill')) root.classList.remove('is-intro'); });
  if (REDUCED) root.classList.remove('is-intro');
  // Ready the images after first paint so plate 1 wins the bandwidth
  if (document.fonts && document.fonts.ready) document.fonts.ready.then(layout);
})();
</script>
<script type="importmap">
{ "imports": {
  "three": "https://cdn.jsdelivr.net/npm/three@0.170.0/build/three.module.js",
  "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.170.0/examples/jsm/"
} }
</script>
<script type="module">
/* Live 3D core: one PBR ice cylinder per era, the active one pulled out of the core and turned,
   a signal-orange collar at the probe, the drill head that cut it hanging above the surface.
   If WebGL or the CDN fails, the 2D canvas core underneath stays and nothing else changes. */
import * as THREE from 'three';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';

const root = document.getElementById('core-timeline');
const tl = root.__tl;
const canvas = root.querySelector('[data-gl]');

function main() {
  if (!tl || !canvas) return;
  let renderer;
  try {
    renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true, powerPreference: 'high-performance' });
  } catch (e) { return; }
  if (!renderer.getContext()) return;
  renderer.setPixelRatio(Math.min(1.75, window.devicePixelRatio || 1));
  renderer.outputColorSpace = THREE.SRGBColorSpace;
  renderer.toneMapping = THREE.ACESFilmicToneMapping;
  renderer.toneMappingExposure = 0.92;

  const scene = new THREE.Scene();
  const pmrem = new THREE.PMREMGenerator(renderer);
  scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
  scene.environmentIntensity = 0.55;
  const camera = new THREE.OrthographicCamera(0, 1, 0, -1, -3000, 3000);
  camera.position.z = 1000;

  const key = new THREE.DirectionalLight(0xfff4e8, 1.9);
  const rim = new THREE.DirectionalLight(0xbfe3ff, 2.2);
  scene.add(key, key.target, rim, rim.target, new THREE.HemisphereLight(0xf4f7f5, 0x6c7a80, 0.35));


  // Ice: map + bump from the same strata drawing, a touch of transmission and attenuation for the subsurface glow
  const tex = document.createElement('canvas');
  const map = new THREE.CanvasTexture(tex);
  map.colorSpace = THREE.SRGBColorSpace; map.wrapS = THREE.RepeatWrapping; map.anisotropy = renderer.capabilities.getMaxAnisotropy();
  const bump = new THREE.CanvasTexture(tex); bump.wrapS = THREE.RepeatWrapping;
  const iceMat = new THREE.MeshPhysicalMaterial({
    map, bumpMap: bump, bumpScale: 0.9, roughness: 0.34, metalness: 0,
    clearcoat: 0.6, clearcoatRoughness: 0.22, ior: 1.31, sheen: 0.6, sheenColor: new THREE.Color(0x9fd2e6), sheenRoughness: 0.5,
    specularIntensity: 0.8, specularColor: new THREE.Color(0xe8f6ff)
  });
  // cheap subsurface: light that has travelled through ice comes back blue on the shadow side
  iceMat.onBeforeCompile = (sh) => {
    sh.fragmentShader = sh.fragmentShader.replace('#include <opaque_fragment>', `
      float ndv = abs(normalize(vNormal).z);
      float sss = pow(1.0 - ndv, 1.6);
      outgoingLight = outgoingLight * (0.58 + 0.42 * sqrt(ndv)) + vec3(0.05, 0.16, 0.23) * sss * 0.7;
      #include <opaque_fragment>`);
  };
  const capMat = new THREE.MeshPhysicalMaterial({ color: 0xa9c9d6, roughness: 0.6, clearcoat: 0.4, clearcoatRoughness: 0.4, sheen: 0.4, sheenColor: new THREE.Color(0xd9f0f8) });
  const ringMat = new THREE.MeshStandardMaterial({ color: 0xd9480f, roughness: 0.38, metalness: 0.25, emissive: 0x5a1400, emissiveIntensity: 0.25 });

  const DIR_V = new THREE.Vector3(1, 0, 0), DIR_H = new THREE.Vector3(0, 1, 0);
  let segs = [], ring = null, drill = null, cable = null, drillPivot = null, drillModel = null, built = -1, W = 0, H = 0;
  let r = 0, k = 1, Lw = 0, center = new THREE.Vector3(), quat = new THREE.Quaternion();
  const springs = tl.ERAS.map((_, i) => ({ x: i === tl.cur ? 1 : 0, v: 0 }));

  function axisQuat(horiz) {
    const q = new THREE.Quaternion();
    if (horiz) {
      const yaw = 0.24; k = 1 / Math.cos(yaw);
      q.setFromEuler(new THREE.Euler(0, yaw, 0)).multiply(new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 0, 1), Math.PI / 2));
    } else {
      const tilt = 0.16; k = 1 / Math.cos(tilt);
      q.setFromEuler(new THREE.Euler(tilt, 0, 0));
    }
    return q;
  }

  function build() {
    const L = tl.L, T = tl.T; if (!L) return false;
    W = tl.rig.clientWidth; H = tl.rig.clientHeight;
    renderer.setSize(W, H, false);
    camera.left = 0; camera.right = W; camera.top = 0; camera.bottom = -H; camera.updateProjectionMatrix();
    const c = tl.core;
    center.set(c.offsetLeft + c.offsetWidth / 2, -(c.offsetTop + c.offsetHeight / 2), 0);
    r = T / 2; quat = axisQuat(tl.horiz); Lw = L * k;

    // texture: strata unwrapped around the circumference
    tex.width = 512; tex.height = Math.max(512, Math.min(4096, Math.round(L * 2)));
    const ctx = tex.getContext('2d'); ctx.setTransform(1, 0, 0, 1, 0, 0);
    tl.drawStrata(ctx, tex.width, tex.height, true);
    map.needsUpdate = true; bump.needsUpdate = true;

    segs.forEach((s) => { scene.remove(s.pivot); s.pivot.traverse((o) => o.geometry && o.geometry.dispose()); });
    segs = tl.ERAS.map((e, i) => {
      const [a, b] = tl.bandS(i), len = (b - a) * k - 1.4;
      const g = new THREE.CylinderGeometry(r, r, len, 96, 1, true);
      const uv = g.attributes.uv, vTop = 1 - a / L, vBot = 1 - b / L;
      for (let n = 0; n < uv.count; n++) uv.setY(n, vBot + uv.getY(n) * (vTop - vBot));
      const side = new THREE.Mesh(g, iceMat);
      const capT = new THREE.Mesh(new THREE.CircleGeometry(r, 96), capMat); capT.rotation.x = -Math.PI / 2; capT.position.y = len / 2;
      const capB = new THREE.Mesh(new THREE.CircleGeometry(r, 96), capMat); capB.rotation.x = Math.PI / 2; capB.position.y = -len / 2;
      const seg = new THREE.Group(); seg.add(side, capT, capB);
      seg.position.y = (L / 2 - (a + b) / 2) * k;
      const pivot = new THREE.Group(); pivot.quaternion.copy(quat); pivot.add(seg); scene.add(pivot);
      return { pivot, seg };
    });

    if (!ring) {
      ring = new THREE.Group();
      const t = new THREE.Mesh(new THREE.TorusGeometry(1, 0.032, 16, 120), ringMat); t.rotation.x = Math.PI / 2;
      ring.add(t); ring.userData.inner = new THREE.Group(); scene.add(ring);
    }
    ring.quaternion.copy(quat); ring.scale.setScalar(r * 1.1);

    // lights aimed at the core
    key.position.set(center.x - 900, center.y + 520, 520); key.target.position.copy(center);
    rim.position.set(center.x + 700, center.y + 200, -200); rim.target.position.copy(center);

    placeDrill();
    built = tl.version;
    return true;
  }

  // Drill head (GLB, Meshy image-to-3D, meshopt + webp): hangs above the surface on desktop,
  // lies at the surface end on phones; spins with the probe's speed.
  function placeDrill() {
    if (!drillModel) return;
    if (!drillPivot) {
      // normalise once: unit width, centred on its own axis
      const box = new THREE.Box3().setFromObject(drillModel), size = box.getSize(new THREE.Vector3()), c = box.getCenter(new THREE.Vector3());
      const u = 1 / Math.max(size.x, size.z);
      drillModel.position.copy(c).multiplyScalar(-u); drillModel.scale.setScalar(u);
      drillModel.userData.h = size.y * u;
      drillPivot = new THREE.Group(); drill = new THREE.Group(); drill.add(drillModel); drillPivot.add(drill); scene.add(drillPivot);
      // the winch cable it hangs from
      cable = new THREE.Mesh(new THREE.CylinderGeometry(1, 1, 1, 8), new THREE.MeshStandardMaterial({ color: 0x2a3238, roughness: 0.4, metalness: 0.8 }));
      drillPivot.add(cable);
    }
    const want = tl.horiz ? Math.min(28, r * 0.7) : Math.min(r * 0.82, 80);
    drill.scale.setScalar(want);
    drillPivot.quaternion.copy(quat);
    const gap = tl.horiz ? 10 : 22;
    drillPivot.userData.y = Lw / 2 + gap + drillModel.userData.h * want / 2;
    const cl = 1200; cable.scale.set(tl.horiz ? 0.9 : 1.2, cl, tl.horiz ? 0.9 : 1.2); cable.position.y = drillModel.userData.h * want / 2 + cl / 2 - 2;
  }

  new GLTFLoader().setMeshoptDecoder(MeshoptDecoder).load('assets/drill-head.glb', (gltf) => {
    drillModel = gltf.scene;
    drillModel.traverse((o) => { if (o.isMesh) { if (o.material) { o.material.envMapIntensity = 1.1; } } });
    placeDrill(); root.dataset.drill = 'ready';
  }, undefined, () => { root.dataset.drill = 'missing'; });

  const tmp = new THREE.Vector3();
  function axisPoint(y, out) { return out.set(0, y, 0).applyQuaternion(quat).add(center); }
  const INTRO_V = new THREE.Vector3(0, -140, 0), INTRO_H = new THREE.Vector3(140, 0, 0);
  let introT0 = tl.REDUCED ? null : performance.now() + 200, lastT = performance.now(), spin = 0, drillSpin = 0, inView = true;

  // Adaptive: if frames come slower than ~20 fps (software GL, weak GPU), drop to 1x pixels and
  // stop the idle drift; the scene then only renders while something actually moves.
  let lowPower = false, slowN = 0, sampleN = 0, lastSig = '';
  function frame(now) {
    const gap = now - lastT;
    if (!lowPower && sampleN < 90) { sampleN++; if (sampleN > 3 && gap > 70) slowN++; if (slowN > 5) { lowPower = true; renderer.setPixelRatio(1); built = -1; } }
    const dt = Math.min(0.25, gap / 1000); lastT = now;
    if (built !== tl.version || W !== tl.rig.clientWidth || H !== tl.rig.clientHeight) { if (!build()) return; }
    const reduced = tl.REDUCED || lowPower, still = tl.REDUCED, dir = tl.horiz ? DIR_H : DIR_V, out = tl.horiz ? 20 : tl.CFG.slabOut;
    if (!reduced) spin += dt * 0.12;
    segs.forEach((s, i) => {
      const sp = springs[i], target = i === tl.cur ? 1 : 0;
      if (still) { sp.x = target; sp.v = 0; }
      else { for (let t = dt; t > 0; t -= 0.004) { const h = Math.min(0.004, t), a = -170 * (sp.x - target) - 22 * sp.v; sp.v += a * h; sp.x += sp.v * h; } }
      s.pivot.position.copy(center).addScaledVector(dir, out * sp.x);
      // intro: the sections come up out of the borehole one after another, surface first
      if (introT0 !== null) {
        const p = Math.min(1, Math.max(0, (now - introT0 - i * 120) / 900)), e = 1 - Math.pow(1 - p, 3);
        s.pivot.position.addScaledVector(tl.horiz ? INTRO_H : INTRO_V, 1 - e);
        s.pivot.visible = p > 0;
      }
      s.seg.rotation.y = spin + sp.x * 0.9 + (reduced ? 0 : Math.sin(now / 1400 + i) * 0.04 * sp.x);
    });
    if (introT0 !== null && now - introT0 > 900 + 120 * segs.length) introT0 = null;
    // collar rides with the slab that holds the probe
    const v = tl.v, yr = Math.floor(Math.max(tl.CFG.bottom, Math.min(tl.CFG.surface - 1, v)));
    const e = tl.eraOf(yr), s = tl.sOf(v);
    axisPoint((tl.L / 2 - s) * k, ring.position).addScaledVector(dir, out * springs[e].x);
    ring.rotation.set(0, 0, 0); ring.quaternion.copy(quat);
    if (drillPivot) {
      drillSpin += dt * (reduced ? 0 : 0.5 + Math.min(14, Math.abs(tl.vel) * 1.6));
      axisPoint(drillPivot.userData.y + (reduced ? 0 : Math.sin(now / 900) * 2), drillPivot.position);
      drill.rotation.y = drillSpin;
    }
    // skip identical frames (always the case when idle under reduced motion or low power)
    const sig = reduced ? `${tl.v.toFixed(3)}|${springs.map((q) => q.x.toFixed(3)).join(',')}|${built}|${drillModel ? 1 : 0}` : '';
    if (reduced && introT0 === null && sig === lastSig) return;
    lastSig = sig;
    renderer.render(scene, camera);
  }

  let raf = 0;
  const loop = (now) => { frame(now); raf = (inView && !document.hidden) ? requestAnimationFrame(loop) : 0; };
  const wake = () => { if (!raf && inView && !document.hidden) { lastT = performance.now(); raf = requestAnimationFrame(loop); } };
  new IntersectionObserver((ents) => { inView = ents[0].isIntersecting; wake(); }).observe(root);
  document.addEventListener('visibilitychange', wake);
  canvas.addEventListener('webglcontextlost', (ev) => { ev.preventDefault(); root.classList.remove('has-3d'); cancelAnimationFrame(raf); raf = 0; inView = false; });

  if (!build()) return;
  frame(performance.now());
  root.classList.add('has-3d');
  wake();
}
try { main(); } catch (e) { root.classList.remove('has-3d'); }
</script>
</body>
</html>

````
