# Recreate this section/site as a single HTML file: Halfmoon Crate Digger

## What it is

A one-page record shop for a fictional independent label, **Halfmoon Pressing Co.**, built around a
scroll-pinned **CSS-3D wooden crate of eight LP sleeves** (no WebGL, no canvas). As you scroll, the
front record is lifted out of the crate on an arc, held up in front of it, and its **black vinyl disc
slides out of the sleeve** (sideways on desktop, upward on mobile); then it drops back and leans
forward onto the pile of records you have already flicked past, exactly like digging through a real
crate. A left column shows the held record's catalogue number, title, artist, year, genre, price
and tracklist; **"Drop the needle"** swings a tonearm onto the disc, spins it at 33⅓ rpm, runs a
track timer through the tracklist, and (only if the user turns Sound on) plays a soft synthesised
chord with vinyl crackle. A right-edge rail of ticks jumps to any record; arrow keys / PageUp /
PageDown flick one record; a working **bag** (add, remove, total, reserve) and a validated
newsletter form complete the page. Reduced-motion users (and browsers without CSS 3D) get a flat
**list view** of the same records, also reachable from a header toggle.
**Signature:** the flick-lift-pull cycle — each record rises out of the crate, its disc slides out
and the tonearm lands on it when played.

## Page shell & libraries

- One `index.html`, inline `<style>` and one inline `<script>` (IIFE, `'use strict'`). No frameworks,
  no JS libraries.
- Google Fonts only:
  `https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400..800;1,9..144,400..700&family=DM+Sans:opsz,wght@9..40,400..700&family=JetBrains+Mono:wght@400;600&display=swap`
  with preconnects to `fonts.googleapis.com` and `fonts.gstatic.com`.
- Local images in `assets/` (relative paths). Total images ≈ 0.5 MB.
- Expose `window.__crate = { goTo(i, smooth), active, playing, bag, setView(v) }` for testing.

## Tokens

- Ground `--ink #16120e`, raised surface `#231c16`, text `--paper #f3ead9`, secondary text
  `--muted #bcae96` (≥ 7:1 on ink), hairlines `--line rgba(243,234,217,.14)`.
- Per-record accent `--acc` (set on `<html>` from JS whenever the held record changes; transitions
  on logo, badge, rail, title italic, play button): `#ff8a4c, #ff6dbd, #f2c84f, #6f8cff, #8fe07a,
  #3fd6cf, #f5cd45, #c6ff3d`. Text on the accent is `#16120e`.
- Wood: `--wood-1 #8a5a34`, `--wood-2 #6d4426`, `--wood-3 #a86f42`.
- Club section ground `#f3ead9`, body text `#4d4132`, input bg `#fbf6ec`, input border `#b9aa90`,
  error `#a1231b`, success `#22512e`.
- Type: display **Fraunces** (h1 700, `clamp(38px, 4.6vw, 70px)/.95`, letter-spacing −.025em,
  `opsz 144`, the second word in italic 400 in the accent); artist line Fraunces italic
  `clamp(19px,1.7vw,24px)`; body **DM Sans** 16/1.55; labels, durations, catalogue numbers
  **JetBrains Mono** 12–13px, uppercase eyebrows with .16em tracking.
- Radii: pills 999px, popover 18px, inputs 12px, sleeves 3px. Header 64px tall; side gutter
  `clamp(16px, 3vw, 40px)`; info column left `clamp(20px, 5vw, 80px)`.

## Layout & structure

1. **Skip link** ("Skip to records"), then a **fixed header**: logo (30px disc mark drawn with a
   radial gradient whose ring uses `--acc`; "Halfmoon *Pressing Co.*"), and two pills: **List view**
   toggle (`aria-pressed`) and **Bag** (`aria-expanded`, `aria-controls="bag"`) with an accent count
   badge. Header background: `linear-gradient(to bottom, rgba(22,18,14,.96) 40%, transparent)`.
2. **Bag popover** (`role="dialog"`, fixed at top 70px / right gutter, width `min(360px, 100vw-32px)`):
   list rows (44px thumb, title, artist · price, "Remove"), empty message, total in mono, a
   **Reserve for pickup** button (disabled when empty) and a `role="status"` message.
3. **`<section id="crate">`** — the scroll track, height `100 + (N−1)·70` vh. Child `.pin` is
   `position: sticky; top: 0; height: 100svh; overflow: hidden` and holds:
   - `.backdrop`: `assets/shop-backdrop.webp` cover, opacity .42, saturate .85, with a darkening
     gradient (left 94% → 15% at 70% on desktop so the text column reads; top/bottom vignette;
     on mobile a vertical gradient going to 97% ink behind the info block). Parallax: translateY
     0 → −3% across the section.
   - A radial accent glow over the backdrop (`color-mix(var(--acc) 22%)` at 62% 34%), and a
     4.5%-opacity SVG fractal-noise grain.
   - `.stage` (`perspective` + `perspective-origin`, `aria-hidden`) → `.deck` (0×0 at the crate
     floor centre, `preserve-3d`) containing a floor shadow, the crate's back, left, right and
     front panels, and 8 `.rec` elements inserted before the front panel.
   - `.info` column (left, vertically centred, width `min(32vw, 440px)`): eyebrow (catalogue no. in
     accent + "03 of 08"), h1 title, artist, meta list (year · genre · €price · N tracks), controls
     (Play pill, Add-to-bag ghost pill, 46px round Sound icon button), tracklist `<ol>` of buttons
     (side/number A1…B2 in mono, title, duration right), keyboard hint.
   - `nav.rail` (right edge, vertically centred): "01 / 08" readout, an `<ol>` of 34px tick buttons
     (9px ring dots, active one filled with the accent and scaled 1.5), a 3px glowing accent fill
     line and a hover/focus label tooltip to the left of each tick.
   - "Scroll to dig ↓" cue at the bottom centre (fades out after the first record), and a
     visually-hidden `aria-live="polite"` paragraph.
4. **Each `.rec`** (size S×S, `left: −S/2; bottom: 0; transform-origin: 50% 100%; preserve-3d`):
   - `.disc-wrap` (inset 3%, `translate3d(var(--ox), var(--oy), −2px)`, rendered only when the
     record is near the crest) with `.disc` (repeating radial grooves `#121010`/`#1c1918` every
     1.1px, two faint band rings, the cover image as a 34%-inset centre label with a spindle hole),
     a static conic `.disc__sheen` and the `.arm` (pivot knob, brushed rod, black headshell with an
     accent stylus tip).
   - `.sleeve` (translateZ 1px, cover `<img alt="">`, a soft-light wear overlay with a ring-wear
     circle, the catalogue number chip top-left, and a `.sleeve__shade` black layer whose opacity
     is set per frame).
   - `.sleeve-back` (rotateY 180°): cream paper with catalogue number, artist and A1/A2/B1/B2 titles.
   - If the cover fails to load, the sleeve gets `.noimg`: a procedural cover from the record's
     three colours (two circles on a gradient).
5. **List view** `<section id="list">` (hidden by default): H2 "The whole crate", intro line, and a
   `repeat(auto-fill, minmax(240px, 1fr))` grid of items: square cover with a grooved disc peeking
   out of it (translateX 8%, 30% when playing), title, "artist · year · genre · €price", Play/Pause
   and Add-to-bag buttons (`aria-pressed`).
6. **The Listening Club** (cream section, 2 columns → 1 under 880px): heading with italic
   *Listening*, short pitch, form with Email (required, validated), "Send me mostly" select, black
   submit pill, inline error and success messages.
7. **Footer**: "Halfmoon Pressing Co. is a fictional label…" and "Cut at 33⅓ rpm" in mono.

## Behaviour & interaction

**Sizing (`layout()`, on load and resize).** `wide = innerWidth > 880`.
Wide: `S = min(vh·.47, vw·.27, 470)`, deck at left 62% / top 86%, perspective-origin 62% 20%.
Narrow: `S = min(vw·.6, vh·.3, 330)`, deck at 50% / `vh·.64` px, perspective-origin 50% 10%.
Perspective `max(1800, 5.4·S)px`. Tonearm vars: wide `--arm-len .66` (×S), rest −10°, play 19°,
pivot at 104% / 2%; narrow len .42, rest −4°, play 44°, pivot 104% / −2%.

**Crate panels** (all units ×S): front 1.3 wide × .44 tall at translateZ(.78), with "HALFMOON · DIG
HERE" stencilled in mono; sides 1.5 deep at translateX(±.65) translateZ(.03) rotateY(±90°),
brightness .72; back at translateZ(−.72), brightness .55. Wood = plank seams every .14S + grain
stripes + vertical gradient.

**Scroll → progress.** `raw = clamp(−crate.top / (crate.height − innerHeight), 0, 1) · (N−1)`.
Each record gets a hold: `dwell(x) = n + smoothstep(.19, .81, x − n)` (dwell .38).
`progress` follows the target with frame-rate independent easing
`progress += (target − progress)·(1 − e^(−9·dt))`, dt capped at .1 s; snap when within .0008; with
reduced motion `e = 1`. The rAF loop runs **only** while progress ≠ target and the section is
on-screen (IntersectionObserver); scroll and resize events kick it.

**Per-record pose**, `p = i − progress`, positions ×S:
- Held (`p = 0`): wide `x −.24, y −.52, z .98, rotateX −2°, rotateY 9°`; narrow `x 0, y −.4,
  z .98, rotateX −2°, rotateY 0`; shade 0.
- Back stack (`p ≥ 1`, k = p−1): `z −.06 − .085k`, `rotateX 9 + 3.2·min(k,5)`°, shade
  `min(.7, .18 + .12k)`, opacity fades from p 4.6 to 5.8 (then `display: none`).
- Pile (`p ≤ −1`, k = −p−1): `z .06 + .075·min(k,3)`, `rotateX −38 − 4·min(k,3)`° (leaning forward
  onto the front wall), shade `.42 + .08·min(k,3)`, opacity fades from q 2.4 to 3.3.
- Between (|p| < 1, u = |p|): interpolate held → back(1) or pile(1); x and z use `smoothstep(u)`,
  the rest linear; add an arc `y −= .42·sin(π·u)` so the record lifts over the crate wall.
- Transform: `translate3d(x,y,z) rotateX() rotateY()`. Shade is a child layer's opacity (never
  `filter` on 3D elements).

**Disc pull.** For |p| < .6 the record gets `.near`; `h = (1 − smoothstep(.02, .5, |p|))²`;
`--ox = .5·S·h` (wide) or `--oy = −.36·S·h` (narrow); arm opacity `smoothstep(.55, .9, h)`.

**Active record** = `round(progress)`. On change: set `--acc`, catalogue, "NN of 08", title HTML,
artist, meta, tracklist, Add button state, rail `aria-current`, readout, and the live region
("Record 3 of 8: Mesa Paper Sun by The Dune Choir, 1971."); replay a .5 s fade-up (`opacity 0,
translateY 10px` → none, `cubic-bezier(.2,.8,.2,1)`) on the info column. Changing record **lifts
the needle** (stops playback).

**Playback (simulated).** Play toggles `body.is-playing`: the held disc's `spin` animation
(1.8 s linear infinite = 33⅓ rpm) runs, the tonearm rotates from rest to play over
`.9s cubic-bezier(.5,0,.2,1)`, the label reads "Lift the needle", and a 250 ms interval advances a
timer shown as "0:12 / 5:12" on the current track with a 3-bar equaliser. At a track's end it moves
to the next; after the last it stops. Clicking any track starts it from 0:00. Hidden tab = timer
and spin pause (`paused-all`).

**Sound (off by default).** The round Sound button (`aria-pressed`) creates an AudioContext on
first press. While Sound is on and the needle is down: 4 oscillators at root × (1, 1.26, 1.5, 2)
(triangle + sines, ±6 cent detune, slow LFO on each gain) through a 900 Hz low-pass, plus a looped
2 s buffer of sparse crackle through a 1.2 kHz high-pass, into a bus whose gain glides to .05 (time
constant .2 s). The root is per record (130.8–233 Hz) and shifts per track by 0/3/5/7/10 semitones.
Turning Sound off, lifting the needle or hiding the tab glides the bus to 0 and stops the voices.

**Navigation.** Ticks and `goTo(i)` scroll the page to `crateTop + i/(N−1)·travel` (smooth unless
reduced motion). Keys, only while the pin fills the viewport and focus is not in a form field:
ArrowDown/ArrowRight/PageDown/j → next, ArrowUp/ArrowLeft/PageUp/k → previous (at either end the
key falls through to normal page scrolling), Home/End → first/last. Escape closes the bag.

**Bag.** Add toggles (`aria-pressed`, label "Add to bag · €28" ↔ "In your bag ✓"); the badge
pops (scale 1.3, 300 ms). The popover lists items sorted by catalogue, shows the total, Remove
returns focus to the Bag button, outside click closes it. Reserve shows "Reserved 2 records. Pick
up at the counter within 7 days." and empties the bag.

**List view.** The header toggle swaps crate ↔ list (label "List view" ↔ "Crate view"), scrolls to
top in list view and back to the active record in crate view. List Play buttons make that record
active and play it (its disc slides further out); playing state and bag state stay in sync with the
crate.

**Club form.** `novalidate`; on submit check `/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/`. Empty → "Add your
email so we know where to send the records."; malformed → "That email looks off. Check for a
typo."; set `aria-invalid`, focus the field. Valid → "You're in. First pressing ships with the next
new moon (jazz)." and reset. Typing clears the error.

## Responsive

- **1440**: info column left, crate centre-right (deck 62%), disc slides right, tonearm on the
  right of the disc, rail at the right edge; tracklist visible (rows 4+ hidden if height < 700px).
- **768**: narrow layout: crate centred in the top ~2/3, disc slides **up** out of the sleeve, info
  block pinned to the bottom (eyebrow, title `clamp(30px, 8.4vw, 46px)`, artist, meta, controls),
  tracklist and hint hidden, rail at right 6px / top 34% with 28×26 ticks and no readout.
- **390**: same as 768; header pills become icon-only (≤ 420px), the Add button drops its price,
  controls stay on one row; logo shows "Halfmoon" only. No horizontal scroll at any width
  (`.list` uses `overflow-x: clip`).

## Accessibility & reduced motion

- Semantic landmarks (header, main, sections with headings, nav, footer), skip link, visible
  2px accent focus rings, every control a real `<button>` with `aria-pressed`/`aria-expanded`/
  `aria-current` as appropriate; the 3D stage is `aria-hidden` (its content is all mirrored in the
  info column) and the live region announces each record.
- Text contrast ≥ 4.5:1 everywhere (muted `#bcae96` on `#16120e` ≈ 8:1; dark ink on every accent).
- `prefers-reduced-motion: reduce`: the page **opens in the list view**; animations and transitions
  are reduced to .001 ms, the disc and equaliser never spin, smooth scrolling is off, and if the
  user switches to the crate, progress snaps instead of easing.
- Audio never starts without an explicit press of Sound.

## Fallbacks

- No CSS 3D (`@supports not (transform-style: preserve-3d)` + JS check): crate hidden, list shown.
- Missing cover image: procedural sleeve and plain-colour disc label, list items get a gradient
  placeholder with `role="img"` and an aria-label.
- No Web Audio: the Sound toggle silently does nothing; playback visuals still work.
- The rAF loop stops off-screen and when settled; spin and timer pause in hidden tabs.

## Assets

All 1:1 covers are 720×720 WebP, no text or logos in the art:

- `assets/01-orange-hours.webp` — risograph print: overlapping orange and teal circles on grainy
  off-white paper with a thin black horizon line.
- `assets/02-spin-cycle.webp` — empty neon laundromat at night through a rain-streaked window,
  magenta and blue.
- `assets/03-mesa-paper-sun.webp` — torn-paper collage of desert mesas under a big yellow sun.
- `assets/04-bent-meridian.webp` — hard-edge op-art: black and cream stripes bending into a wave,
  one cobalt square.
- `assets/05-fiddlehead.webp` — macro of a dewy fern fiddlehead on dark emerald.
- `assets/06-motel-pool.webp` — faded instant-film photo of a red convertible by a seaside motel
  pool at dusk.
- `assets/07-lamp-swell.webp` — impasto oil painting of a stormy sea with a tiny lighthouse,
  yellow and prussian blue.
- `assets/08-mercury-bloom.webp` — chrome liquid-metal blob on a lilac-to-acid-lime gradient.
- `assets/shop-backdrop.webp` (1600×900) — dim record shop at night, heavily out of focus: pendant
  lamps, shelves of record spines, walnut and amber, dark lower half.

## Make it yours

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

1. **Label and catalogue.** Swap "Halfmoon Pressing Co." and the eight records for your own
   label, shop or artist: titles, artists, years, genres, prices and 4–5 tracks each. Keep 6–10
   records (fewer feels empty, more makes the scroll track tiresome) and two-word titles where the
   second word can go italic in the accent.
2. **What comes out of the sleeve.** The pulled disc and tonearm are the signature. Keep the
   lift-hold-drop cycle and the "pull" (`--ox`/`--oy`) but change what is pulled: a cassette from
   its J-card case, a CD from a jewel case (shorter slide, rainbow sheen instead of grooves), a
   print from a portfolio sleeve, a book from a slipcase, a wine bottle from a wooden box. Replace
   "Drop the needle" with the matching action (press play, open, pour).
3. **The crate.** Re-skin the container, not the geometry: a metal flight case with corner
   brackets, a cardboard banana box with a printed logo, a lacquered drawer, a library card
   catalogue. Keep the front panel at z .78S and ~.44S tall so the held item still clears it.
4. **Palette.** Replace the walnut ground (`#16120e`), paper (`#f3ead9`) and wood ramp with your
   own, and set one accent per item drawn from its cover. Keep `--muted` at ≥ 4.5:1 on the ground
   and dark text on every accent (check light accents like lime and yellow).
5. **Type pairing.** Swap Fraunces + DM Sans + JetBrains Mono for another expressive display face
   with an italic, a plain sans and a mono (for example Instrument Serif + Inter Tight + IBM Plex
   Mono, or Bricolage Grotesque + Manrope + Space Mono).
6. **Covers and backdrop.** Generate your own square covers in one consistent series (one medium or
   one photographer's eye works better than eight random styles), no text in the art, ≤ 120 KB
   each at 720px WebP; regenerate the backdrop as an out-of-focus photo of your own space (studio,
   shop, venue) with a dark lower half.
7. **Sound and copy voice.** Change the synth chord to your genre (lower root and saw waves for
   techno, sparse sine bells for ambient) or drop the Sound button; rewrite the club pitch, bag
   messages and hint line in your own voice, specific to what you sell ("first dibs on test
   pressings", not "exclusive perks").

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/record-label-crate-digger/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>Halfmoon Pressing Co. — Dig the Crate</title>
<meta name="description" content="Flick through the Halfmoon Pressing Co. crate: eight records from a fictional independent label, pulled from a scroll-driven 3D crate.">
<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=Fraunces:ital,opsz,wght@0,9..144,400..800;1,9..144,400..700&family=DM+Sans:opsz,wght@9..40,400..700&family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet">
<style>
  *, *::before, *::after { box-sizing: border-box; }
  :root {
    --ink: #16120e;        /* page ground: walnut-black */
    --ink-2: #211a14;
    --paper: #f3ead9;      /* sleeve paper / main text */
    --muted: #bcae96;      /* secondary text (AA on ink) */
    --line: rgba(243,234,217,.14);
    --acc: #ff7a3d;        /* per-record accent, set from JS */
    --acc-ink: #16120e;
    --wood-1: #8a5a34; --wood-2: #6d4426; --wood-3: #a86f42;
    --display: 'Fraunces', Georgia, serif;
    --sans: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
    --r: 14px;
    --ease-out: cubic-bezier(.2,.8,.2,1);
  }
  html { -webkit-text-size-adjust: 100%; }
  html, body { margin: 0; }
  body {
    background: var(--ink); color: var(--paper);
    font: 16px/1.55 var(--sans); -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
  }
  img { max-width: 100%; display: block; }
  button, input, select { font: inherit; color: inherit; }
  :focus-visible { outline: 2px solid var(--acc); outline-offset: 3px; border-radius: 6px; }
  .sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
  .skip { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--paper); color: var(--ink); padding: 10px 14px; border-radius: 10px; font-weight: 700; text-decoration: none; }
  .skip:focus { top: 12px; }

  /* ---------- header ---------- */
  .top {
    position: fixed; inset: 0 0 auto 0; z-index: 50; height: 64px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 0 clamp(16px, 3vw, 40px);
    background: linear-gradient(to bottom, rgba(22,18,14,.96) 40%, rgba(22,18,14,0));
  }
  .logo { display: flex; align-items: center; gap: 10px; color: var(--paper); text-decoration: none; }
  .logo__mark { width: 30px; height: 30px; border-radius: 50%; background:
      radial-gradient(circle at 50% 50%, var(--ink) 0 14%, var(--acc) 15% 34%, #0d0b09 35% 100%);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); transition: background .6s; }
  .logo__name { font: 600 17px/1 var(--display); letter-spacing: -.01em; }
  .logo__name i { font-weight: 400; color: var(--muted); }
  .top__actions { display: flex; gap: 8px; }
  .pill {
    display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
    border-radius: 999px; border: 1px solid var(--line); background: rgba(33,26,20,.7);
    cursor: pointer; font-size: 14px; font-weight: 500; white-space: nowrap;
    transition: background .2s, border-color .2s, color .2s;
  }
  .pill:hover { border-color: rgba(243,234,217,.4); }
  .pill[aria-pressed="true"] { background: var(--paper); color: var(--ink); }
  .pill svg { width: 16px; height: 16px; flex: none; }
  .badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; background: var(--acc); color: var(--acc-ink);
    font: 700 12px/22px var(--mono); text-align: center; transition: background .6s, transform .3s var(--ease-out); }
  .badge.bump { transform: scale(1.3); }

  /* ---------- bag popover ---------- */
  .bag {
    position: fixed; z-index: 60; top: 70px; right: clamp(16px, 3vw, 40px); width: min(360px, calc(100vw - 32px));
    background: #231c16; border: 1px solid var(--line); border-radius: 18px; padding: 18px;
    box-shadow: 0 30px 60px -20px rgba(0,0,0,.7);
  }
  .bag[hidden] { display: none; }
  .bag h2 { margin: 0 0 10px; font: 600 20px/1.2 var(--display); }
  .bag ul { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; }
  .bag li { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
  .bag li img, .bag li .ph { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; }
  .bag li b { display: block; font-size: 14px; line-height: 1.25; }
  .bag li span { font-size: 13px; color: var(--muted); }
  .bag .rm { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 13px; text-decoration: underline; padding: 6px; }
  .bag__empty { color: var(--muted); font-size: 14px; margin: 0; }
  .bag__foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); gap: 10px; }
  .bag__msg { margin: 10px 0 0; font-size: 14px; color: var(--paper); }

  /* ---------- buttons ---------- */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 9px; height: 46px; padding: 0 18px;
    border-radius: 999px; border: 1px solid transparent; cursor: pointer; font-weight: 600; font-size: 15px;
    transition: transform .2s var(--ease-out), background .3s, color .3s, border-color .3s;
  }
  .btn:active { transform: scale(.97); }
  .btn--solid { background: var(--acc); color: var(--acc-ink); }
  .btn--ghost { background: transparent; border-color: rgba(243,234,217,.28); }
  .btn--ghost:hover { border-color: var(--paper); }
  .btn--ghost[aria-pressed="true"] { background: rgba(243,234,217,.12); border-color: var(--paper); }
  .btn svg { width: 18px; height: 18px; flex: none; }
  .btn--icon { width: 46px; padding: 0; }
  .btn--icon[aria-pressed="true"] { background: var(--paper); color: var(--ink); }
  .btn:disabled { opacity: .45; cursor: not-allowed; }
  .ico-pause { display: none; }
  [aria-pressed="true"] > .ico-play { display: none; }
  [aria-pressed="true"] > .ico-pause { display: block; }

  /* ---------- crate section (scroll track) ---------- */
  #crate { position: relative; }
  .pin {
    position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden;
    background:
      radial-gradient(90% 70% at 62% 34%, color-mix(in srgb, var(--acc) 22%, transparent) 0%, transparent 62%),
      radial-gradient(120% 90% at 50% 110%, #2a2018 0%, var(--ink) 60%);
    transition: background .8s;
  }
  .pin::after { /* paper grain */
    content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .045;
    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='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  }
  .backdrop { position: absolute; inset: -4% 0; background: url("assets/shop-backdrop.webp") center 40%/cover no-repeat; opacity: .42;
    transform: translate3d(0, var(--bdy, 0px), 0) scale(1.04); filter: saturate(.85); }
  .backdrop::after { content: ""; position: absolute; inset: 0;
    background: linear-gradient(90deg, rgba(22,18,14,.94) 0%, rgba(22,18,14,.72) 34%, rgba(22,18,14,.15) 70%, rgba(22,18,14,.5) 100%),
                linear-gradient(to bottom, rgba(22,18,14,.55), transparent 30%, transparent 60%, rgba(22,18,14,.9)); }
  @media (max-width: 880px) { .backdrop::after { background: linear-gradient(to bottom, rgba(22,18,14,.6), rgba(22,18,14,.2) 30%, rgba(22,18,14,.7) 62%, rgba(22,18,14,.97) 74%); } }
  .stage { position: absolute; inset: 0; perspective: var(--persp, 2200px); perspective-origin: var(--vx, 58%) var(--vy, 24%); }
  .deck { position: absolute; left: var(--dx, 58%); top: var(--dy, 86%); width: 0; height: 0; transform-style: preserve-3d; }
  /* floor shadow */
  .floor { position: absolute; left: calc(var(--S) * -.9); top: calc(var(--S) * -.2); width: calc(var(--S) * 1.8); height: calc(var(--S) * .5);
    background: radial-gradient(closest-side, rgba(0,0,0,.6), transparent); transform: translateZ(calc(var(--S) * .1)) rotateX(90deg); }

  /* wooden crate panels */
  .wood {
    position: absolute; bottom: 0; height: calc(var(--S) * .44);
    background:
      linear-gradient(to bottom, rgba(255,255,255,.10) 0 2px, transparent 2px 100%),
      repeating-linear-gradient(to bottom, transparent 0 calc(var(--S) * .14), rgba(0,0,0,.35) calc(var(--S) * .14) calc(var(--S) * .147)),
      repeating-linear-gradient(92deg, rgba(255,255,255,.04) 0 3px, transparent 3px 11px),
      linear-gradient(to bottom, var(--wood-3), var(--wood-1) 40%, var(--wood-2));
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.25), inset 0 -18px 30px -10px rgba(0,0,0,.45);
    backface-visibility: visible;
  }
  .wood--front { width: calc(var(--S) * 1.3); left: calc(var(--S) * -.65); transform: translateZ(calc(var(--S) * .78)); }
  .wood--front::after { content: "HALFMOON · DIG HERE"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    font: 600 calc(var(--S) * .036)/1 var(--mono); letter-spacing: .3em; color: rgba(22,18,14,.55); white-space: nowrap; }
  .wood--side { width: calc(var(--S) * 1.5); left: calc(var(--S) * -.75); filter: brightness(.72); }
  .wood--l { transform: translateX(calc(var(--S) * -.65)) translateZ(calc(var(--S) * .03)) rotateY(90deg); }
  .wood--r { transform: translateX(calc(var(--S) * .65)) translateZ(calc(var(--S) * .03)) rotateY(-90deg); }
  .wood--back { width: calc(var(--S) * 1.3); left: calc(var(--S) * -.65); transform: translateZ(calc(var(--S) * -.72)); filter: brightness(.55); }

  /* each record (sleeve + disc) */
  .rec {
    position: absolute; left: calc(var(--S) / -2); bottom: 0; width: var(--S); height: var(--S);
    transform-origin: 50% 100%; transform-style: preserve-3d; will-change: transform;
  }
  .sleeve, .sleeve-back {
    position: absolute; inset: 0; border-radius: 3px; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden;
    box-shadow: 0 1px 0 rgba(255,255,255,.15) inset, 0 30px 50px -24px rgba(0,0,0,.8);
  }
  .sleeve { background: var(--c1, #333); transform: translateZ(1px); }
  .sleeve img { width: 100%; height: 100%; object-fit: cover; }
  .sleeve.noimg { background:
      radial-gradient(circle at 30% 35%, var(--c2) 0 22%, transparent 23%),
      radial-gradient(circle at 68% 62%, var(--c3) 0 28%, transparent 29%),
      linear-gradient(160deg, var(--c1), color-mix(in srgb, var(--c1) 60%, #000)); }
  .sleeve.noimg img { display: none; }
  .sleeve__cat { position: absolute; left: 6%; top: 6%; font: 600 calc(var(--S) * .032)/1 var(--mono); letter-spacing: .14em;
    color: #fff; background: rgba(0,0,0,.38); padding: .45em .6em; border-radius: 4px; }
  .sleeve__shade { position: absolute; inset: 0; background: #0b0806; opacity: var(--shade, 0); pointer-events: none; }
  .sleeve__wear { position: absolute; inset: 0; pointer-events: none;
    background: radial-gradient(circle at 50% 50%, transparent 0 44%, rgba(255,255,255,.07) 45% 46.5%, transparent 47.5%),
                linear-gradient(130deg, rgba(255,255,255,.18), transparent 35%, rgba(0,0,0,.18)); mix-blend-mode: soft-light; }
  .sleeve-back { transform: rotateY(180deg) translateZ(1px); background:
      linear-gradient(to bottom, transparent 0 82%, rgba(0,0,0,.1) 82%), #e7dcc6; color: #3a2f24; padding: 9%;
      font: 500 calc(var(--S) * .034)/1.6 var(--mono); }

  .disc-wrap { position: absolute; left: 3%; top: 3%; width: 94%; height: 94%;
    transform: translate3d(var(--ox, 0px), var(--oy, 0px), -2px); display: none; }
  .rec.near .disc-wrap { display: block; }
  .disc { position: absolute; inset: 0; border-radius: 50%;
    background:
      radial-gradient(circle, transparent 0 31%, rgba(255,255,255,.05) 31.5% 32%, transparent 32.5% 47%, rgba(255,255,255,.06) 47.5% 48%, transparent 48.5%),
      repeating-radial-gradient(circle, #121010 0 1.1px, #1c1918 1.1px 2.2px);
    box-shadow: 0 18px 40px -12px rgba(0,0,0,.85), inset 0 0 0 2px #0a0909;
    animation: spin 1.8s linear infinite; animation-play-state: paused; }
  .disc__label { position: absolute; inset: 33%; border-radius: 50%; background: var(--c2) center/cover;
    box-shadow: inset 0 0 0 2px rgba(0,0,0,.25); }
  .disc__label::after { content: ""; position: absolute; left: 50%; top: 50%; width: 9%; height: 9%; margin: -4.5% 0 0 -4.5%; border-radius: 50%; background: var(--ink); }
  .disc__sheen { position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
    background: conic-gradient(from 200deg, transparent 0 8%, rgba(255,255,255,.16) 12%, transparent 18% 55%, rgba(255,255,255,.12) 61%, transparent 67%); }
  @keyframes spin { to { transform: rotate(360deg); } }
  .is-playing .rec.cur .disc { animation-play-state: running; }
  .paused-all .disc { animation-play-state: paused !important; }

  /* tonearm, rides with the disc */
  .arm { position: absolute; left: var(--arm-x, 104%); top: var(--arm-y, 4%); width: 0; height: 0;
    transform: rotate(var(--arm-rest, -8deg)); transition: transform .9s cubic-bezier(.5,0,.2,1); z-index: 2; opacity: var(--armo, 0); }
  .arm__base { position: absolute; width: 18%; aspect-ratio: 1; }
  .arm i { position: absolute; display: block; }
  .arm__pivot { left: calc(var(--S) * -.05); top: calc(var(--S) * -.05); width: calc(var(--S) * .1); height: calc(var(--S) * .1); border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, #d9d2c4, #7c7468 60%, #3d3832); box-shadow: 0 6px 14px rgba(0,0,0,.6); }
  .arm__rod { left: calc(var(--S) * -.007); top: 0; width: calc(var(--S) * .014); height: calc(var(--S) * var(--arm-len, .66));
    background: linear-gradient(to right, #8d867b, #e6e0d4 45%, #8d867b); border-radius: 4px; box-shadow: 4px 8px 10px rgba(0,0,0,.45); }
  .arm__head { left: calc(var(--S) * -.026); top: calc(var(--S) * (var(--arm-len, .66) - .02)); width: calc(var(--S) * .052); height: calc(var(--S) * .085);
    background: linear-gradient(#2b2724, #121010); border-radius: 3px 3px 6px 6px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15), 3px 6px 8px rgba(0,0,0,.5); }
  .arm__head::after { content: ""; position: absolute; left: 30%; bottom: -12%; width: 40%; height: 20%; background: var(--acc); border-radius: 2px; }
  .is-playing .rec.cur .arm { transform: rotate(var(--arm-play, 18deg)); }

  /* ---------- info column ---------- */
  .info {
    position: absolute; z-index: 5; left: clamp(20px, 5vw, 80px); top: 50%; transform: translateY(-46%);
    width: min(32vw, 440px);
  }
  .eyebrow { display: flex; gap: 10px; align-items: center; margin: 0 0 14px; font: 600 12px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
  .eyebrow b { color: var(--acc); font-weight: 600; transition: color .6s; }
  .info h1 { margin: 0; font: 700 clamp(38px, 4.6vw, 70px)/.95 var(--display); letter-spacing: -.025em; font-variation-settings: "opsz" 144; text-wrap: balance; }
  .info h1 em { font-style: italic; font-weight: 400; color: var(--acc); transition: color .6s; }
  .info .artist { margin: 12px 0 0; font: 400 italic clamp(19px, 1.7vw, 24px)/1.25 var(--display); }
  .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 10px 0 0; padding: 0; list-style: none; font: 500 13px/1.4 var(--mono); color: var(--muted); }
  .meta li + li::before { content: "·"; margin-right: 14px; color: rgba(243,234,217,.35); }
  .controls { display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0 0; }
  .tracks { list-style: none; margin: 22px 0 0; padding: 0; border-top: 1px solid var(--line); counter-reset: t; }
  .tracks li { border-bottom: 1px solid var(--line); }
  .tracks button {
    width: 100%; display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: center; text-align: left;
    padding: 9px 4px; border: 0; background: none; cursor: pointer; font-size: 15px; color: var(--paper); border-radius: 6px;
  }
  .tracks button:hover { background: rgba(243,234,217,.05); }
  .tracks .n { font: 500 12px/1 var(--mono); color: var(--muted); }
  .tracks .d { font: 500 12px/1 var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
  .tracks [aria-current="true"] { color: var(--acc); }
  .tracks [aria-current="true"] .n { color: var(--acc); }
  .tracks [aria-current="true"] .d { color: var(--paper); }
  .eq { display: inline-flex; gap: 2px; align-items: flex-end; height: 12px; vertical-align: -1px; }
  .eq i { width: 3px; background: currentColor; height: 40%; animation: eq .8s ease-in-out infinite alternate; animation-play-state: paused; }
  .eq i:nth-child(2) { animation-delay: -.3s; } .eq i:nth-child(3) { animation-delay: -.55s; }
  .is-playing .eq i { animation-play-state: running; }
  @keyframes eq { from { height: 20%; } to { height: 100%; } }
  .hint { margin: 18px 0 0; font: 500 12px/1.5 var(--mono); color: var(--muted); }
  kbd { font: 600 11px/1 var(--mono); padding: 3px 6px; border: 1px solid var(--line); border-radius: 5px; color: var(--paper); }
  .swap { animation: swapIn .5s var(--ease-out); }
  @keyframes swapIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

  /* ---------- rail ---------- */
  .rail { position: absolute; z-index: 6; right: clamp(14px, 2.2vw, 34px); top: 50%; transform: translateY(-50%);
    display: flex; flex-direction: column; align-items: center; gap: 12px; }
  .rail__count { font: 600 12px/1 var(--mono); letter-spacing: .1em; color: var(--muted); }
  .rail__count b { color: var(--paper); font-weight: 600; }
  .rail ol { position: relative; list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
  .rail ol::before { content: ""; position: absolute; left: 50%; top: 10px; bottom: 10px; width: 1px; background: var(--line); }
  .rail__fill { position: absolute; left: calc(50% - 1px); top: 10px; width: 3px; height: 0; border-radius: 2px; background: var(--acc); box-shadow: 0 0 12px var(--acc); transition: background .6s; pointer-events: none; }
  .tick { position: relative; width: 34px; height: 34px; border: 0; padding: 0; background: none; cursor: pointer; display: grid; place-items: center; }
  .tick span { width: 9px; height: 9px; border-radius: 50%; background: var(--ink); border: 2px solid rgba(243,234,217,.45); transition: transform .3s var(--ease-out), background .3s, border-color .3s; }
  .tick:hover span { border-color: var(--paper); }
  .tick[aria-current="true"] span { background: var(--acc); border-color: var(--acc); transform: scale(1.5); }
  .tick em { position: absolute; right: 40px; top: 50%; transform: translateY(-50%); white-space: nowrap; font: 600 11px/1 var(--mono); letter-spacing: .08em;
    color: var(--paper); background: #231c16; border: 1px solid var(--line); padding: 6px 8px; border-radius: 6px; opacity: 0; pointer-events: none; transition: opacity .2s; font-style: normal; }
  .tick:hover em, .tick:focus-visible em { opacity: 1; }

  .scrollcue { position: absolute; z-index: 5; left: 50%; bottom: 18px; transform: translateX(-50%); font: 600 11px/1 var(--mono); letter-spacing: .2em; text-transform: uppercase; color: var(--muted); transition: opacity .4s; }

  /* ---------- list view ---------- */
  .list { overflow-x: clip; padding: 110px clamp(16px, 5vw, 80px) 60px; }
  .list[hidden] { display: none; }
  .list h2, .club h2 { margin: 0 0 8px; font: 700 clamp(34px, 5vw, 60px)/1 var(--display); letter-spacing: -.02em; }
  .list > p { margin: 0 0 30px; color: var(--muted); max-width: 52ch; }
  .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 28px 22px; list-style: none; margin: 0; padding: 0; }
  .item { position: relative; }
  .item__art { position: relative; aspect-ratio: 1; }
  .item__art img, .item__art .ph { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: cover; border-radius: 3px; box-shadow: 0 20px 40px -20px rgba(0,0,0,.8); }
  .item__disc { position: absolute; z-index: 0; top: 3%; left: 3%; width: 94%; height: 94%; border-radius: 50%;
    background: radial-gradient(circle, var(--c2) 0 17%, transparent 17.5%), repeating-radial-gradient(circle, #1d1a19 0 1.2px, #2a2624 1.2px 2.4px); box-shadow: inset 0 0 0 1px rgba(255,255,255,.18), 0 10px 30px rgba(0,0,0,.6); transform: translateX(8%); transition: transform .5s var(--ease-out); }
  .item.on .item__disc { transform: translateX(30%); }
  .item h3 { margin: 14px 0 0; font: 600 21px/1.15 var(--display); }
  .item p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
  .item__row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
  .item__row .btn { height: 40px; padding: 0 14px; font-size: 14px; }
  .ph { background: linear-gradient(150deg, var(--c1), var(--c3)); }

  /* ---------- club + footer ---------- */
  .club { position: relative; z-index: 2; background: var(--paper); color: var(--ink); padding: clamp(56px, 9vw, 120px) clamp(16px, 5vw, 80px); display: grid; grid-template-columns: 1.1fr 1fr; gap: 40px; align-items: end; }
  .club p { margin: 0; color: #4d4132; max-width: 46ch; font-size: 17px; }
  .club em { font-style: italic; font-weight: 400; }
  .form { display: grid; gap: 12px; }
  .form label { font: 600 12px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: #4d4132; }
  .field { display: grid; gap: 7px; }
  .form input, .form select { height: 50px; border-radius: 12px; border: 1.5px solid #b9aa90; background: #fbf6ec; padding: 0 14px; color: var(--ink); font-size: 16px; }
  .form input[aria-invalid="true"] { border-color: #b3261e; }
  .form :focus-visible { outline-color: var(--ink); }
  .err { min-height: 1.3em; margin: 0; font-size: 14px; color: #a1231b; }
  .ok { margin: 0; font-size: 15px; font-weight: 600; color: #22512e; min-height: 1.4em; }
  .form .btn--solid { background: var(--ink); color: var(--paper); justify-self: start; }
  footer { padding: 28px clamp(16px, 5vw, 80px); display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; font: 500 13px/1.5 var(--mono); color: var(--muted); border-top: 1px solid var(--line); }

  /* ---------- responsive ---------- */
  @media (max-width: 880px) {
    .info { left: 16px; right: 16px; width: auto; top: auto; bottom: max(14px, env(safe-area-inset-bottom)); transform: none; }
    .info h1 { font-size: clamp(30px, 8.4vw, 46px); }
    .info .artist { margin-top: 6px; font-size: 18px; }
    .eyebrow { margin-bottom: 8px; }
    .controls { margin-top: 14px; }
    .controls .btn { height: 42px; padding: 0 14px; font-size: 14px; }
    .controls .btn--icon { width: 42px; padding: 0; }
    .tracks, .hint { display: none; }
    .rail { top: 34%; right: 6px; gap: 6px; }
    .rail__count { display: none; }
    .tick { width: 28px; height: 26px; }
    .scrollcue { display: none; }
    .club { grid-template-columns: 1fr; }
    .logo__name i { display: none; }
  }
  @media (max-width: 420px) {
    .controls .pr { display: none; }
    .controls { flex-wrap: nowrap; }
    .pill .lbl { display: none; }
    .pill { padding: 0 12px; }
  }
  @media (max-height: 700px) and (min-width: 881px) {
    .tracks li:nth-child(n+4) { display: none; }
  }

  /* reduced motion: no spinning, no swaps; JS also defaults to the list view */
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
    .disc, .eq i { animation: none !important; }
  }
  /* no CSS 3D? fall back to the list */
  @supports not (transform-style: preserve-3d) { #crate { display: none !important; } .list[hidden] { display: block !important; } }
</style>
</head>
<body>
<a class="skip" href="#main">Skip to records</a>

<header class="top">
  <a class="logo" href="#main" aria-label="Halfmoon Pressing Co., home">
    <span class="logo__mark" aria-hidden="true"></span>
    <span class="logo__name">Halfmoon <i>Pressing Co.</i></span>
  </a>
  <div class="top__actions">
    <button class="pill" id="viewBtn" type="button" aria-pressed="false">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M4 6h16M4 12h16M4 18h16"/></svg>
      <span class="lbl">List view</span>
    </button>
    <button class="pill" id="bagBtn" type="button" aria-expanded="false" aria-controls="bag">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M5 8h14l-1 12H6L5 8Z"/><path d="M9 8a3 3 0 0 1 6 0"/></svg>
      <span class="lbl">Bag</span><span class="badge" id="bagCount">0</span>
      <span class="sr">records in bag</span>
    </button>
  </div>
</header>

<div class="bag" id="bag" role="dialog" aria-label="Your bag" hidden>
  <h2>Your bag</h2>
  <ul id="bagList"></ul>
  <p class="bag__empty" id="bagEmpty">Nothing yet. Pull a record from the crate and hit <b>Add to bag</b>.</p>
  <div class="bag__foot">
    <span id="bagTotal" style="font: 600 15px/1 var(--mono)">€0</span>
    <button class="btn btn--solid" id="reserveBtn" type="button" disabled>Reserve for pickup</button>
  </div>
  <p class="bag__msg" id="bagMsg" role="status"></p>
</div>

<main id="main">
  <section id="crate" aria-roledescription="record crate" aria-label="Halfmoon crate: eight records">
    <div class="pin" id="pin">
      <div class="backdrop" id="backdrop" aria-hidden="true"></div>
      <div class="stage" id="stage" aria-hidden="true">
        <div class="deck" id="deck">
          <div class="floor"></div>
          <div class="wood wood--back"></div>
          <div class="wood wood--side wood--l"></div>
          <div class="wood wood--side wood--r"></div>
          <div class="wood wood--front"></div>
        </div>
      </div>

      <div class="info" id="info">
        <p class="eyebrow"><b id="iCat">HMP-001</b><span id="iNum">01 of 08</span></p>
        <h1 id="iTitle">Orange Hours</h1>
        <p class="artist" id="iArtist">Tamsin Okoro Quartet</p>
        <ul class="meta" id="iMeta"></ul>
        <div class="controls">
          <button class="btn btn--solid" id="playBtn" type="button" aria-pressed="false">
            <svg class="ico-play" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M7 4.5v15l13-7.5z"/></svg>
            <svg class="ico-pause" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M6 4h4v16H6zM14 4h4v16h-4z"/></svg>
            <span id="playLbl">Drop the needle</span>
          </button>
          <button class="btn btn--ghost" id="addBtn" type="button" aria-pressed="false"><span id="addLbl">Add to bag</span></button>
          <button class="btn btn--ghost btn--icon" id="soundBtn" type="button" aria-pressed="false" aria-label="Sound" title="Sound: plays a soft synthesised loop while the needle is down (off by default)">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M4 9v6h4l5 4V5L8 9H4z"/><path d="M16.5 8.5a5 5 0 0 1 0 7"/></svg>
            <span class="sr" id="soundLbl">off</span>
          </button>
        </div>
        <ol class="tracks" id="iTracks" aria-label="Tracklist"></ol>
        <p class="hint">Scroll, or press <kbd>↑</kbd> <kbd>↓</kbd> to flick through the crate.</p>
      </div>

      <nav class="rail" aria-label="Jump to a record">
        <div class="rail__count"><b id="rCur">01</b> / <span id="rTot">08</span></div>
        <ol id="ticks"><span class="rail__fill" id="rFill"></span></ol>
      </nav>
      <div class="scrollcue" id="cue" aria-hidden="true">Scroll to dig ↓</div>
      <p class="sr" id="live" aria-live="polite"></p>
    </div>
  </section>

  <section class="list" id="list" aria-labelledby="listH" hidden>
    <h2 id="listH">The whole crate</h2>
    <p>Eight pressings from the Halfmoon catalogue, laid flat. Same records, no flicking.</p>
    <ul class="grid" id="grid"></ul>
  </section>

  <section class="club" aria-labelledby="clubH">
    <div>
      <h2 id="clubH">The <em>Listening</em> Club</h2>
      <p>One new pressing a month, mailed in a hand-stamped sleeve. Members hear test pressings first and get first dibs on the crate.</p>
    </div>
    <form class="form" id="clubForm" novalidate>
      <div class="field">
        <label for="email">Email</label>
        <input id="email" name="email" type="email" autocomplete="email" placeholder="you@example.com" aria-describedby="emailErr" required>
        <p class="err" id="emailErr"></p>
      </div>
      <div class="field">
        <label for="genre">Send me mostly</label>
        <select id="genre" name="genre">
          <option>A bit of everything</option><option>Jazz</option><option>Ambient &amp; electronic</option><option>Folk &amp; psych</option><option>Post-rock</option>
        </select>
      </div>
      <button class="btn btn--solid" type="submit">Join the club</button>
      <p class="ok" id="clubOk" role="status"></p>
    </form>
  </section>
</main>
<footer>
  <span>Halfmoon Pressing Co. is a fictional label. All artists and records are invented.</span>
  <span>Cut at 33⅓ rpm</span>
</footer>

<script>
(() => {
  'use strict';
  const RECORDS = [
    { cat: 'HMP-001', title: 'Orange <em>Hours</em>', plain: 'Orange Hours', artist: 'Tamsin Okoro Quartet', year: 1974, genre: 'Spiritual jazz', price: 28, img: 'assets/01-orange-hours.webp',
      c: ['#e9e2d0', '#ff7a3d', '#1aa39a'], acc: '#ff8a4c', root: 196,
      tracks: [['Morning Dial', 312], ['Half Past Amber', 427], ['Okoro Steps', 268], ['Tangerine Psalm', 540]] },
    { cat: 'HMP-002', title: 'Spin Cycle <em>Lullabies</em>', plain: 'Spin Cycle Lullabies', artist: 'Night Laundry', year: 2019, genre: 'Ambient electronic', price: 26, img: 'assets/02-spin-cycle.webp',
      c: ['#1b1f4a', '#ff4fae', '#3e7bff'], acc: '#ff6dbd', root: 174,
      tracks: [['Coin-Op', 244], ['Rinse (Slow)', 391], ['Fluorescent', 302], ['Dryer Heat', 288], ['4 a.m. Fold', 455]] },
    { cat: 'HMP-003', title: 'Mesa <em>Paper Sun</em>', plain: 'Mesa Paper Sun', artist: 'The Dune Choir', year: 1971, genre: 'Folk psych', price: 30, img: 'assets/03-mesa-paper-sun.webp',
      c: ['#b6502e', '#f2d36b', '#d99a9a'], acc: '#f2c84f', root: 220,
      tracks: [['Kraft Horizon', 233], ['Torn Edges', 287], ['Ochre Hymn', 351], ['Paper Sun', 402]] },
    { cat: 'HMP-004', title: 'Bent <em>Meridian</em>', plain: 'Bent Meridian', artist: 'Ilse Varga Trio', year: 1966, genre: 'Modal jazz', price: 32, img: 'assets/04-bent-meridian.webp',
      c: ['#efe6d2', '#1f45d6', '#141414'], acc: '#6f8cff', root: 164.8,
      tracks: [['Cobalt Square', 376], ['Stripe Theory', 298], ['Meridian (Bent)', 512], ['Varga Blues', 330]] },
    { cat: 'HMP-005', title: '<em>Fiddlehead</em>', plain: 'Fiddlehead', artist: 'Moss & Wren', year: 2008, genre: 'Ambient', price: 24, img: 'assets/05-fiddlehead.webp',
      c: ['#0f2a1c', '#7fd36a', '#1f5a39'], acc: '#8fe07a', root: 146.8,
      tracks: [['Uncurl', 284], ['Dew Point', 342], ['Understorey', 415], ['Spore Song', 266]] },
    { cat: 'HMP-006', title: 'Motel Pool, <em>8 PM</em>', plain: 'Motel Pool, 8 PM', artist: 'Cassette Weather', year: 1986, genre: 'Synth pop', price: 27, img: 'assets/06-motel-pool.webp',
      c: ['#f3b28f', '#2ec4c0', '#d6334a'], acc: '#3fd6cf', root: 233,
      tracks: [['Vacancy', 221], ['Chlorine Kiss', 248], ['Red Convertible', 263], ['Ice Machine', 239], ['Checkout Time', 301]] },
    { cat: 'HMP-007', title: 'Lamp Against <em>the Swell</em>', plain: 'Lamp Against the Swell', artist: 'Grey Harbour', year: 2003, genre: 'Post-rock', price: 29, img: 'assets/07-lamp-swell.webp',
      c: ['#16324f', '#f2c230', '#2b5a7a'], acc: '#f5cd45', root: 130.8,
      tracks: [['Keeper', 498], ['Prussian Blue', 612], ['The Swell', 731], ['Lamp', 404]] },
    { cat: 'HMP-008', title: 'Mercury <em>Bloom</em>', plain: 'Mercury Bloom', artist: 'Ultraviolet Office', year: 2024, genre: 'Experimental club', price: 26, img: 'assets/08-mercury-bloom.webp',
      c: ['#b8a2ff', '#c6ff3d', '#7a6ad8'], acc: '#c6ff3d', root: 207.7,
      tracks: [['Liquid Badge', 256], ['Chrome Lilac', 318], ['Acid Lime', 287], ['Bloom', 344]] },
  ];
  const N = RECORDS.length;
  const $ = (id) => document.getElementById(id);
  const clamp = (x, a, b) => Math.min(b, Math.max(a, x));
  const lerp = (a, b, t) => a + (b - a) * t;
  const sstep = (a, b, x) => { const t = clamp((x - a) / (b - a), 0, 1); return t * t * (3 - 2 * t); };
  const pad = (n) => String(n).padStart(2, '0');
  const fmt = (s) => Math.floor(s / 60) + ':' + pad(Math.floor(s % 60));
  const mqReduce = matchMedia('(prefers-reduced-motion: reduce)');
  let reduce = mqReduce.matches;
  const supports3d = CSS.supports('transform-style', 'preserve-3d');

  const CONFIG = {
    perRecordVh: 70,     // scroll distance per record
    ease: 9,             // progress smoothing rate per second, frame-rate independent (snaps when reduced motion)
    dwell: 0.38,         // fraction of each segment where the pulled record holds still
  };

  const crate = $('crate'), pin = $('pin'), stage = $('stage'), deck = $('deck'), ticksEl = $('ticks');
  const front = deck.querySelector('.wood--front');

  /* ---------- build sleeves ---------- */
  const recs = RECORDS.map((r, i) => {
    const el = document.createElement('div');
    el.className = 'rec';
    el.style.setProperty('--c1', r.c[0]); el.style.setProperty('--c2', r.c[1]); el.style.setProperty('--c3', r.c[2]);
    el.innerHTML = `
      <div class="disc-wrap"><div class="disc"><div class="disc__label" style="background-image:url('${r.img}')"></div></div><div class="disc__sheen"></div>
        <div class="arm"><i class="arm__rod"></i><i class="arm__head"></i><i class="arm__pivot"></i></div></div>
      <div class="sleeve"><img src="${r.img}" alt="" decoding="async" draggable="false"><span class="sleeve__wear"></span><span class="sleeve__cat">${r.cat}</span><span class="sleeve__shade"></span></div>
      <div class="sleeve-back">${r.cat}<br>${r.artist}<br>${r.tracks.map((t, k) => (k < 2 ? 'A' : 'B') + (k % 2 + 1) + ' ' + t[0]).join('<br>')}</div>`;
    const img = el.querySelector('img');
    img.addEventListener('error', () => { el.querySelector('.sleeve').classList.add('noimg'); el.querySelector('.disc__label').style.backgroundImage = 'none'; });
    deck.insertBefore(el, front);
    return el;
  });

  /* ---------- rail ---------- */
  $('rTot').textContent = pad(N);
  const ticks = RECORDS.map((r, i) => {
    const li = document.createElement('li');
    const b = document.createElement('button');
    b.type = 'button'; b.className = 'tick';
    b.setAttribute('aria-label', `Record ${i + 1}: ${r.plain} by ${r.artist}`);
    b.innerHTML = `<span></span><em aria-hidden="true">${pad(i + 1)} ${r.plain}</em>`;
    b.addEventListener('click', () => goTo(i, true));
    li.appendChild(b); ticksEl.appendChild(li);
    return b;
  });

  /* ---------- layout ---------- */
  let S = 380, wide = true;
  const G = {};
  function layout() {
    const vw = innerWidth, vh = innerHeight;
    wide = vw > 880;
    if (wide) S = Math.round(Math.min(vh * 0.47, vw * 0.27, 470));
    else S = Math.round(Math.min(vw * 0.6, vh * 0.3, 330));
    stage.style.setProperty('--S', S + 'px');
    stage.style.setProperty('--persp', Math.round(Math.max(1800, S * 5.4)) + 'px');
    stage.style.setProperty('--dx', wide ? '62%' : '50%');
    stage.style.setProperty('--vx', wide ? '62%' : '50%');
    stage.style.setProperty('--dy', wide ? '86%' : (Math.round(vh * 0.64) + 'px'));
    stage.style.setProperty('--vy', wide ? '20%' : '10%');
    // tonearm geometry
    stage.style.setProperty('--arm-x', '104%'); stage.style.setProperty('--arm-y', wide ? '2%' : '-2%');
    stage.style.setProperty('--arm-len', wide ? '.66' : '.42');
    stage.style.setProperty('--arm-rest', wide ? '-10deg' : '-4deg');
    stage.style.setProperty('--arm-play', wide ? '19deg' : '44deg');
    Object.assign(G, wide
      ? { heldX: -0.24, heldY: -0.52, heldZ: 0.98, heldRY: 9, outX: 0.5, outY: 0 }
      : { heldX: 0, heldY: -0.4, heldZ: 0.98, heldRY: 0, outX: 0, outY: -0.36 });
    crate.style.height = (100 + (N - 1) * CONFIG.perRecordVh) + 'vh';
    kick();
  }

  /* ---------- per-record placement: p = i - progress ---------- */
  function back(p) {   // p >= 1: standing in the crate, leaning back
    const k = p - 1;
    return { x: 0, y: 0, z: -0.06 - 0.085 * k, rx: 9 + 3.2 * Math.min(k, 5), ry: 0, shade: clamp(0.18 + 0.12 * k, 0, 0.7), o: 1 - clamp((p - 4.6) / 1.2, 0, 1) };
  }
  function pile(q) {   // q >= 1: already flicked, leaning forward onto the front wall
    const k = q - 1;
    return { x: 0, y: 0, z: 0.06 + 0.075 * Math.min(k, 3), rx: -38 - 4 * Math.min(k, 3), ry: 0, shade: 0.42 + 0.08 * Math.min(k, 3), o: 1 - clamp((q - 2.4) / 0.9, 0, 1) };
  }
  function held() { return { x: G.heldX, y: G.heldY, z: G.heldZ, rx: -2, ry: G.heldRY, shade: 0, o: 1 }; }
  function stateAt(p) {
    if (p >= 1) return back(p);
    if (p <= -1) return pile(-p);
    const from = held(), to = p >= 0 ? back(1) : pile(1), u = Math.abs(p);
    const ez = sstep(0, 1, u), ey = u;
    const s = {};
    for (const key in from) s[key] = lerp(from[key], to[key], key === 'z' || key === 'x' ? ez : ey);
    s.y -= 0.42 * Math.sin(Math.PI * u);   // arc up over the crate wall
    s.o = 1;
    return s;
  }
  function place(el, p) {
    const s = stateAt(p);
    if (s.o <= 0.001) { if (el.style.display !== 'none') el.style.display = 'none'; return; }
    if (el.style.display === 'none') el.style.display = '';
    el.style.opacity = s.o.toFixed(3);
    el.style.setProperty('--shade', s.shade.toFixed(3));
    el.style.transform = `translate3d(${(s.x * S).toFixed(1)}px,${(s.y * S).toFixed(1)}px,${(s.z * S).toFixed(1)}px) rotateX(${s.rx.toFixed(2)}deg) rotateY(${s.ry.toFixed(2)}deg)`;
    const near = Math.abs(p) < 0.6;
    el.classList.toggle('near', near);
    if (near) {
      const h = Math.pow(1 - sstep(0.02, 0.5, Math.abs(p)), 2);
      el.style.setProperty('--ox', (G.outX * S * h).toFixed(1) + 'px');
      el.style.setProperty('--oy', (G.outY * S * h).toFixed(1) + 'px');
      el.style.setProperty('--armo', sstep(0.55, 0.9, h).toFixed(3));
    }
  }

  /* ---------- scroll → progress with a dwell plateau per record ---------- */
  let progress = 0, target = 0, raf = 0, active = -1, inView = true;
  const sectionTop = () => crate.getBoundingClientRect().top + scrollY;
  const travel = () => Math.max(1, crate.offsetHeight - innerHeight);
  function dwellMap(x) {   // x in [0, N-1] raw → eased with flat holds around each integer
    const n = Math.floor(x), f = x - n, d = CONFIG.dwell / 2;
    return n + sstep(d, 1 - d, f);
  }
  function readTarget() {
    const raw = clamp(-crate.getBoundingClientRect().top / travel(), 0, 1) * (N - 1);
    target = dwellMap(raw);
  }
  let lastF = 0;
  function frame(now) {
    raf = 0;
    readTarget();
    const dt = lastF ? Math.min(0.1, (now - lastF) / 1000) : 1 / 60; lastF = now;
    const e = reduce ? 1 : 1 - Math.exp(-CONFIG.ease * dt);
    progress += (target - progress) * e;
    if (Math.abs(target - progress) < 0.0008) progress = target;
    for (let i = 0; i < N; i++) place(recs[i], i - progress);
    $('rFill').style.height = `calc(${(progress / (N - 1) * 100).toFixed(2)}% - ${(progress / (N - 1) * 20).toFixed(1)}px)`;
    $('cue').style.opacity = progress > 0.2 ? 0 : 1;
    $('backdrop').style.setProperty('--bdy', (-progress / (N - 1) * 3).toFixed(2) + '%');
    const a = clamp(Math.round(progress), 0, N - 1);
    if (a !== active) setActive(a);
    if (progress !== target && inView) raf = requestAnimationFrame(frame); else lastF = 0;
  }
  function kick() { if (!raf && inView) raf = requestAnimationFrame(frame); }
  addEventListener('scroll', kick, { passive: true });
  addEventListener('resize', layout);

  // pause everything when the crate is off-screen or the tab is hidden
  new IntersectionObserver(([en]) => { inView = en.isIntersecting; pin.classList.toggle('paused-all', !inView); if (inView) kick(); }, { threshold: 0 }).observe(crate);
  document.addEventListener('visibilitychange', () => { document.body.classList.toggle('paused-all', document.hidden); syncAudio(); });

  function goTo(i, smooth) {
    i = clamp(i, 0, N - 1);
    if (view === 'list') return;
    const y = sectionTop() + (N > 1 ? i / (N - 1) : 0) * travel();
    scrollTo({ top: y, behavior: smooth && !reduce ? 'smooth' : 'auto' });
  }

  /* ---------- info panel ---------- */
  const info = $('info');
  function setActive(a) {
    const changed = active !== -1;
    active = a;
    const r = RECORDS[a];
    if (playing) stopPlay();
    track = 0; elapsed = 0;
    document.documentElement.style.setProperty('--acc', r.acc);
    recs.forEach((el, i) => el.classList.toggle('cur', i === a));
    $('iCat').textContent = r.cat;
    $('iNum').textContent = `${pad(a + 1)} of ${pad(N)}`;
    $('iTitle').innerHTML = r.title;
    $('iArtist').textContent = r.artist;
    $('iMeta').innerHTML = `<li>${r.year}</li><li>${r.genre}</li><li>€${r.price}</li><li>${r.tracks.length} tracks</li>`;
    renderTracks();
    syncAdd();
    ticks.forEach((t, i) => t.setAttribute('aria-current', i === a ? 'true' : 'false'));
    $('rCur').textContent = pad(a + 1);
    $('live').textContent = `Record ${a + 1} of ${N}: ${r.plain} by ${r.artist}, ${r.year}.`;
    if (changed && !reduce) { info.classList.remove('swap'); void info.offsetWidth; info.classList.add('swap'); }
  }
  function renderTracks() {
    const r = RECORDS[active];
    $('iTracks').innerHTML = r.tracks.map((t, k) => `<li><button type="button" data-k="${k}" aria-current="${k === track && (playing || elapsed > 0) ? 'true' : 'false'}">
      <span class="n">${k < Math.ceil(r.tracks.length / 2) ? 'A' : 'B'}${k < Math.ceil(r.tracks.length / 2) ? k + 1 : k + 1 - Math.ceil(r.tracks.length / 2)}</span>
      <span>${t[0]} ${k === track && playing ? '<span class="eq" aria-hidden="true"><i></i><i></i><i></i></span>' : ''}</span>
      <span class="d">${k === track && (playing || elapsed > 0) ? fmt(elapsed) + ' / ' : ''}${fmt(t[1])}</span></button></li>`).join('');
  }
  $('iTracks').addEventListener('click', (e) => {
    const b = e.target.closest('button[data-k]'); if (!b) return;
    track = +b.dataset.k; elapsed = 0; startPlay();
  });

  /* ---------- playback (simulated; optional synth loop) ---------- */
  let playing = false, track = 0, elapsed = 0, timer = 0, lastT = 0;
  const playBtn = $('playBtn');
  function startPlay() {
    playing = true; document.body.classList.add('is-playing');
    playBtn.setAttribute('aria-pressed', 'true'); $('playLbl').textContent = 'Lift the needle';
    lastT = performance.now();
    clearInterval(timer); timer = setInterval(tickPlay, 250);
    renderTracks(); syncList(); syncAudio();
  }
  function stopPlay() {
    playing = false; document.body.classList.remove('is-playing');
    playBtn.setAttribute('aria-pressed', 'false'); $('playLbl').textContent = 'Drop the needle';
    clearInterval(timer);
    renderTracks(); syncList(); syncAudio();
  }
  function tickPlay() {
    const now = performance.now(), dt = (now - lastT) / 1000; lastT = now;
    if (document.hidden) return;
    elapsed += dt;
    const r = RECORDS[active];
    if (elapsed >= r.tracks[track][1]) { elapsed = 0; track++; if (track >= r.tracks.length) { track = 0; stopPlay(); return; } renderTracks(); syncAudio(); return; }
    const d = $('iTracks').querySelector('[aria-current="true"] .d');
    if (d) d.textContent = fmt(elapsed) + ' / ' + fmt(r.tracks[track][1]);
  }
  playBtn.addEventListener('click', () => (playing ? stopPlay() : startPlay()));

  let actx = null, bus = null, voices = [];
  const soundBtn = $('soundBtn'); let soundOn = false;
  soundBtn.addEventListener('click', () => {
    soundOn = !soundOn;
    soundBtn.setAttribute('aria-pressed', String(soundOn));
    $('soundLbl').textContent = soundOn ? 'on' : 'off';
    if (soundOn && !actx) {
      try {
        actx = new (window.AudioContext || window.webkitAudioContext)();
        bus = actx.createGain(); bus.gain.value = 0; bus.connect(actx.destination);
      } catch (e) { actx = null; }
    }
    syncAudio();
  });
  function syncAudio() {
    if (!actx) return;
    const on = soundOn && playing && !document.hidden;
    voices.forEach((v) => { try { v.stop(actx.currentTime + 0.6); } catch (e) {} });
    voices = [];
    bus.gain.cancelScheduledValues(actx.currentTime);
    bus.gain.setTargetAtTime(on ? 0.05 : 0, actx.currentTime, 0.2);
    if (!on) return;
    if (actx.state === 'suspended') actx.resume();
    const root = RECORDS[active].root * Math.pow(2, [0, 3, 5, 7, 10][track % 5] / 12);
    const lp = actx.createBiquadFilter(); lp.type = 'lowpass'; lp.frequency.value = 900; lp.connect(bus);
    [1, 1.26, 1.5, 2].forEach((m, k) => {
      const o = actx.createOscillator(); o.type = k ? 'sine' : 'triangle'; o.frequency.value = root * m; o.detune.value = (k - 1.5) * 6;
      const g = actx.createGain(); g.gain.value = k ? 0.25 : 0.5;
      const lfo = actx.createOscillator(); lfo.frequency.value = 0.12 + k * 0.07; const lg = actx.createGain(); lg.gain.value = 0.18; lfo.connect(lg); lg.connect(g.gain);
      o.connect(g); g.connect(lp); o.start(); lfo.start(); voices.push(o, lfo);
    });
    // vinyl crackle
    const len = actx.sampleRate * 2, buf = actx.createBuffer(1, len, actx.sampleRate), d = buf.getChannelData(0);
    for (let i = 0; i < len; i++) d[i] = Math.random() < 0.0009 ? (Math.random() * 2 - 1) * 0.9 : (Math.random() * 2 - 1) * 0.012;
    const src = actx.createBufferSource(); src.buffer = buf; src.loop = true;
    const hp = actx.createBiquadFilter(); hp.type = 'highpass'; hp.frequency.value = 1200;
    const cg = actx.createGain(); cg.gain.value = 0.9; src.connect(hp); hp.connect(cg); cg.connect(bus); src.start(); voices.push(src);
  }

  /* ---------- bag ---------- */
  const bag = new Set();
  const addBtn = $('addBtn');
  function toggleBag(i) {
    bag.has(i) ? bag.delete(i) : bag.add(i);
    $('bagMsg').textContent = '';
    renderBag(); syncAdd(); syncList();
    const b = $('bagCount'); b.classList.remove('bump'); void b.offsetWidth; b.classList.add('bump'); setTimeout(() => b.classList.remove('bump'), 300);
  }
  function syncAdd() {
    const on = bag.has(active);
    addBtn.setAttribute('aria-pressed', String(on));
    $('addLbl').innerHTML = on ? 'In your bag ✓' : `Add to bag<span class="pr"> · €${RECORDS[active].price}</span>`;
  }
  addBtn.addEventListener('click', () => toggleBag(active));
  function renderBag() {
    const items = [...bag].sort((a, b) => a - b);
    $('bagCount').textContent = items.length;
    $('bagEmpty').hidden = items.length > 0;
    $('reserveBtn').disabled = items.length === 0;
    $('bagTotal').textContent = '€' + items.reduce((s, i) => s + RECORDS[i].price, 0);
    $('bagList').innerHTML = items.map((i) => { const r = RECORDS[i]; return `<li style="--c1:${r.c[0]};--c3:${r.c[2]}"><img src="${r.img}" alt="" onerror="this.outerHTML='<span class=ph></span>'"><div><b>${r.plain}</b><span>${r.artist} · €${r.price}</span></div><button class="rm" type="button" data-rm="${i}" aria-label="Remove ${r.plain}">Remove</button></li>`; }).join('');
  }
  $('bagList').addEventListener('click', (e) => { const b = e.target.closest('[data-rm]'); if (b) { toggleBag(+b.dataset.rm); $('bagBtn').focus(); } });
  const bagEl = $('bag'), bagBtn = $('bagBtn');
  function openBag(open) { bagEl.hidden = !open; bagBtn.setAttribute('aria-expanded', String(open)); if (open) bagEl.querySelector('h2').setAttribute('tabindex', '-1'), bagEl.querySelector('h2').focus(); }
  bagBtn.addEventListener('click', () => openBag(bagEl.hidden));
  document.addEventListener('click', (e) => { if (!bagEl.hidden && !bagEl.contains(e.target) && !bagBtn.contains(e.target)) openBag(false); });
  $('reserveBtn').addEventListener('click', () => {
    const n = bag.size;
    $('bagMsg').textContent = `Reserved ${n} record${n > 1 ? 's' : ''}. Pick up at the counter within 7 days.`;
    bag.clear(); renderBag(); syncAdd(); syncList();
  });

  /* ---------- list view ---------- */
  let view = 'crate';
  const grid = $('grid');
  grid.innerHTML = RECORDS.map((r, i) => `<li class="item" data-i="${i}" style="--c1:${r.c[0]};--c2:${r.c[1]};--c3:${r.c[2]}">
      <div class="item__art"><span class="item__disc" aria-hidden="true"></span><img src="${r.img}" alt="Cover of ${r.plain} by ${r.artist}" loading="lazy" onerror="this.outerHTML='<span class=ph role=img aria-label=&quot;Cover of ${r.plain}&quot;></span>'"></div>
      <h3>${r.plain}</h3><p>${r.artist} · ${r.year} · ${r.genre} · €${r.price}</p>
      <div class="item__row"><button class="btn btn--solid" type="button" data-play="${i}" aria-pressed="false">Play</button>
      <button class="btn btn--ghost" type="button" data-add="${i}" aria-pressed="false">Add to bag</button></div></li>`).join('');
  grid.addEventListener('click', (e) => {
    const p = e.target.closest('[data-play]'), a = e.target.closest('[data-add]');
    if (p) { const i = +p.dataset.play; if (i === active && playing) stopPlay(); else { setActive(i); startPlay(); } }
    if (a) toggleBag(+a.dataset.add);
  });
  function syncList() {
    grid.querySelectorAll('.item').forEach((li) => {
      const i = +li.dataset.i, on = playing && i === active;
      li.classList.toggle('on', on);
      const pb = li.querySelector('[data-play]'); pb.setAttribute('aria-pressed', String(on)); pb.textContent = on ? 'Pause' : 'Play';
      const ab = li.querySelector('[data-add]'); ab.setAttribute('aria-pressed', String(bag.has(i))); ab.textContent = bag.has(i) ? 'In bag ✓' : 'Add to bag';
    });
  }
  const viewBtn = $('viewBtn');
  function setView(v) {
    view = v;
    const list = v === 'list';
    crate.hidden = list; $('list').hidden = !list;
    viewBtn.setAttribute('aria-pressed', String(list));
    viewBtn.querySelector('.lbl').textContent = list ? 'Crate view' : 'List view';
    viewBtn.setAttribute('aria-label', list ? 'Switch to crate view' : 'Switch to list view');
    if (!list) { layout(); goTo(Math.max(0, active), false); } else { scrollTo({ top: 0, behavior: 'auto' }); }
  }
  viewBtn.addEventListener('click', () => setView(view === 'list' ? 'crate' : 'list'));

  /* ---------- keyboard ---------- */
  document.addEventListener('keydown', (e) => {
    if (e.key === 'Escape' && !bagEl.hidden) { openBag(false); bagBtn.focus(); return; }
    if (view !== 'crate' || e.altKey || e.ctrlKey || e.metaKey) return;
    const t = e.target; if (t && (t.tagName === 'INPUT' || t.tagName === 'SELECT' || t.tagName === 'TEXTAREA')) return;
    const r = crate.getBoundingClientRect();
    const engaged = r.top <= 2 && r.bottom >= innerHeight - 2;
    if (!engaged) return;
    const next = ['ArrowDown', 'ArrowRight', 'PageDown', 'j'].includes(e.key);
    const prev = ['ArrowUp', 'ArrowLeft', 'PageUp', 'k'].includes(e.key);
    const cur = clamp(Math.round(target), 0, N - 1);
    if (next && cur < N - 1) { e.preventDefault(); goTo(cur + 1, true); }
    else if (prev && cur > 0) { e.preventDefault(); goTo(cur - 1, true); }
    else if (e.key === 'Home') { e.preventDefault(); goTo(0, true); }
    else if (e.key === 'End') { e.preventDefault(); goTo(N - 1, true); }
  });

  /* ---------- club form ---------- */
  $('clubForm').addEventListener('submit', (e) => {
    e.preventDefault();
    const em = $('email'), v = em.value.trim();
    const ok = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(v);
    em.setAttribute('aria-invalid', String(!ok));
    $('emailErr').textContent = ok ? '' : (v ? 'That email looks off. Check for a typo.' : 'Add your email so we know where to send the records.');
    $('clubOk').textContent = ok ? `You're in. First pressing ships with the next new moon (${$('genre').value.toLowerCase()}).` : '';
    if (!ok) em.focus(); else e.target.reset();
  });
  $('email').addEventListener('input', () => { if ($('email').getAttribute('aria-invalid') === 'true') { $('email').removeAttribute('aria-invalid'); $('emailErr').textContent = ''; } });

  mqReduce.addEventListener('change', (e) => { reduce = e.matches; });

  /* ---------- boot ---------- */
  renderBag();
  layout();
  readTarget(); progress = target; frame(performance.now());
  if (reduce || !supports3d) setView('list');
  window.__crate = { goTo, get progress() { return [progress, target, inView, raf]; }, get active() { return active; }, get playing() { return playing; }, get bag() { return [...bag]; }, setView };
})();
</script>
</body>
</html>

````
