{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cinema-chapter-select",
  "type": "registry:component",
  "title": "Cinema Chapter Select",
  "description": "A chapter menu with illustrated poster cards, watched progress and a backdrop that crossfades to the colors of the chosen chapter. Arrow keys move between chapters and the play button resumes where the viewer stopped.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "cinematic",
    "cinematic",
    "chapters",
    "posters",
    "menu",
    "streaming",
    "selector"
  ],
  "docs": "https://hyperblur.dev/effects/cinema-chapter-select",
  "files": [
    {
      "path": "registry/hyperblur/cinema-chapter-select.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/cinema-chapter-select.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type CinemaChapterMotif = \"sun\" | \"waves\" | \"peaks\" | \"stars\" | \"city\";\n\nexport interface CinemaChapter {\n  id: string;\n  title: string;\n  synopsis: string;\n  runtime: string;\n  start: string;\n  watched?: number;\n  motif: CinemaChapterMotif;\n  colors: [string, string];\n}\n\nexport interface CinemaChapterSelectProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\" | \"onSelect\" | \"onPlay\"> {\n  film?: string;\n  chapters?: CinemaChapter[];\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (id: string) => void;\n  onPlay?: (chapter: CinemaChapter) => void;\n  playLabel?: string;\n  headingAs?: \"h1\" | \"h2\";\n}\n\nconst defaultChapters: CinemaChapter[] = [\n  { id: \"arrival\", title: \"Arrival\", synopsis: \"A ferry, a borrowed key and a lighthouse that nobody on the island admits is still lit.\", runtime: \"18 min\", start: \"00:00\", watched: 1, motif: \"waves\", colors: [\"#0f3a5c\", \"#7cc6e8\"] },\n  { id: \"keeper\", title: \"The Keeper\", synopsis: \"Elena finds the logbook. Every entry for forty years ends with the same four numbers.\", runtime: \"22 min\", start: \"18:04\", watched: 0.6, motif: \"sun\", colors: [\"#5c1f0f\", \"#ffb35c\"] },\n  { id: \"crossing\", title: \"The Crossing\", synopsis: \"A storm closes the harbor and the radio starts answering questions nobody asked.\", runtime: \"26 min\", start: \"40:12\", watched: 0, motif: \"peaks\", colors: [\"#1d1c3a\", \"#9a8cff\"] },\n  { id: \"signal\", title: \"Signal\", synopsis: \"Tomas decodes the numbers. They are not coordinates. They are a date.\", runtime: \"19 min\", start: \"1:06:30\", watched: 0, motif: \"stars\", colors: [\"#04141a\", \"#4dffd2\"] },\n  { id: \"return\", title: \"Return\", synopsis: \"The last boat leaves at dawn, and only one of them is on it.\", runtime: \"24 min\", start: \"1:25:48\", watched: 0, motif: \"city\", colors: [\"#2a0c1c\", \"#ff6aa8\"] },\n];\n\nconst css = `\n.hb-vc12 {\n  position: relative;\n  box-sizing: border-box;\n  display: flex;\n  flex-direction: column;\n  justify-content: space-between;\n  gap: 28px;\n  width: 100%;\n  min-height: 600px;\n  padding: clamp(24px, 5cqi, 56px);\n  overflow: hidden;\n  isolation: isolate;\n  container-type: inline-size;\n  background: #050506;\n  color: #f2f2f2;\n  font-family: inherit;\n  -webkit-font-smoothing: antialiased;\n}\n.hb-vc12 *, .hb-vc12 *::before, .hb-vc12 *::after { box-sizing: border-box; }\n.hb-vc12-bg {\n  position: absolute;\n  inset: -10%;\n  z-index: -2;\n  opacity: 0;\n  transform: scale(1.08);\n  transition: opacity 1s ease, transform 2.4s cubic-bezier(.2, .7, .2, 1);\n}\n.hb-vc12-bg[data-on=\"true\"] { opacity: 1; transform: scale(1); }\n.hb-vc12-veil {\n  position: absolute;\n  inset: 0;\n  z-index: -1;\n  background: linear-gradient(90deg, rgba(5, 5, 6, .92) 0%, rgba(5, 5, 6, .55) 55%, rgba(5, 5, 6, .3)), linear-gradient(0deg, rgba(5, 5, 6, .95), transparent 55%);\n}\n.hb-vc12-info { max-width: 520px; }\n.hb-vc12-film {\n  margin: 0 0 18px;\n  color: rgba(242, 242, 242, .6);\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 11px;\n  letter-spacing: .26em;\n  text-transform: uppercase;\n}\n.hb-vc12-num {\n  display: block;\n  color: var(--hb-vc12-c);\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 12px;\n  letter-spacing: .2em;\n  text-transform: uppercase;\n  transition: color .6s ease;\n}\n.hb-vc12-title {\n  margin: 8px 0 0;\n  font-family: var(--font-grotesk, var(--font-sans, ui-sans-serif, system-ui, sans-serif));\n  font-size: clamp(40px, 7.6cqi, 92px);\n  font-weight: 700;\n  line-height: .92;\n  letter-spacing: -.04em;\n}\n.hb-vc12-swap { animation: hb-vc12-swap .7s cubic-bezier(.2, .8, .2, 1) both; }\n@keyframes hb-vc12-swap {\n  from { opacity: 0; transform: translate3d(0, 12px, 0); filter: blur(6px); }\n  to { opacity: 1; transform: none; filter: blur(0); }\n}\n.hb-vc12-syn {\n  max-width: 420px;\n  margin: 16px 0 0;\n  color: rgba(242, 242, 242, .74);\n  font-size: clamp(14px, 1.7cqi, 16px);\n  line-height: 1.55;\n}\n.hb-vc12-meta {\n  display: flex;\n  flex-wrap: wrap;\n  align-items: center;\n  gap: 14px;\n  margin-top: 22px;\n}\n.hb-vc12-play {\n  display: inline-flex;\n  align-items: center;\n  gap: 10px;\n  height: 46px;\n  padding: 0 22px 0 8px;\n  border: 0;\n  border-radius: 999px;\n  background: #f2f2f2;\n  color: #0a0a0a;\n  font: inherit;\n  font-size: 14px;\n  font-weight: 600;\n  cursor: pointer;\n  transition: transform .2s ease, background .25s ease;\n}\n.hb-vc12-play span {\n  display: grid;\n  place-items: center;\n  width: 32px;\n  height: 32px;\n  border-radius: 50%;\n  background: #0a0a0a;\n  color: #f2f2f2;\n}\n.hb-vc12-play:hover { background: #fff; }\n.hb-vc12-play:active { transform: scale(.97); }\n.hb-vc12-play:focus-visible, .hb-vc12-card:focus-visible { outline: 2px solid var(--hb-vc12-c); outline-offset: 3px; }\n.hb-vc12-facts {\n  color: rgba(242, 242, 242, .58);\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 11.5px;\n  letter-spacing: .08em;\n}\n.hb-vc12-row {\n  display: grid;\n  grid-template-columns: repeat(var(--hb-vc12-n), minmax(0, 1fr));\n  gap: clamp(8px, 1.4cqi, 16px);\n  align-items: end;\n  margin: 0;\n  padding: 0;\n}\n.hb-vc12-card {\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  min-width: 0;\n  padding: 0;\n  border: 0;\n  background: none;\n  color: inherit;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  border-radius: 10px;\n}\n.hb-vc12-poster {\n  position: relative;\n  display: block;\n  aspect-ratio: 2 / 3;\n  overflow: hidden;\n  border-radius: 10px;\n  box-shadow: 0 0 0 1px rgba(255, 255, 255, .08), 0 18px 40px -20px rgba(0, 0, 0, .9);\n  filter: saturate(.55) brightness(.7);\n  transform: translate3d(0, 0, 0);\n  transition: transform .6s cubic-bezier(.2, .8, .2, 1), filter .5s ease, box-shadow .5s ease;\n}\n.hb-vc12-poster svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-vc12-card:hover .hb-vc12-poster { filter: saturate(.85) brightness(.9); transform: translate3d(0, -4px, 0); }\n.hb-vc12-card[aria-checked=\"true\"] .hb-vc12-poster {\n  filter: none;\n  transform: translate3d(0, -12px, 0) scale(1.04);\n  box-shadow: 0 0 0 2px var(--hb-vc12-c), 0 30px 60px -24px var(--hb-vc12-c);\n}\n.hb-vc12-card[aria-checked=\"true\"] .hb-vc12-poster::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, .35) 50%, transparent 70%);\n  transform: translateX(-120%);\n  animation: hb-vc12-glint 1.1s .15s cubic-bezier(.2, .7, .2, 1) both;\n}\n@keyframes hb-vc12-glint {\n  to { transform: translateX(120%); }\n}\n.hb-vc12-pnum {\n  position: absolute;\n  left: 9%;\n  top: 6%;\n  color: rgba(255, 255, 255, .92);\n  font-family: var(--font-grotesk, var(--font-sans, ui-sans-serif, system-ui, sans-serif));\n  font-size: clamp(16px, 3.4cqi, 38px);\n  font-weight: 700;\n  letter-spacing: -.03em;\n}\n.hb-vc12-ptitle {\n  position: absolute;\n  left: 9%;\n  right: 9%;\n  bottom: 7%;\n  color: #fff;\n  font-size: clamp(8px, 1.15cqi, 12px);\n  font-weight: 600;\n  letter-spacing: .14em;\n  text-transform: uppercase;\n  white-space: nowrap;\n  overflow: hidden;\n  text-overflow: ellipsis;\n}\n.hb-vc12-prog {\n  display: block;\n  height: 2px;\n  margin-top: 10px;\n  border-radius: 2px;\n  background: rgba(255, 255, 255, .12);\n  overflow: hidden;\n}\n.hb-vc12-prog span { display: block; height: 100%; background: var(--hb-vc12-c); }\n.hb-vc12-time {\n  margin-top: 6px;\n  color: rgba(242, 242, 242, .5);\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 10.5px;\n}\n@container (max-width: 520px) {\n  .hb-vc12-time, .hb-vc12-ptitle { display: none; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-vc12-bg, .hb-vc12-poster, .hb-vc12-num { transition: none; }\n  .hb-vc12-swap, .hb-vc12-card[aria-checked=\"true\"] .hb-vc12-poster::after { animation: none; }\n}\n`;\n\nfunction Motif({ motif, colors }: { motif: CinemaChapterMotif; colors: [string, string] }) {\n  const [a, b] = colors;\n  return (\n    <svg viewBox=\"0 0 200 300\" preserveAspectRatio=\"xMidYMid slice\" aria-hidden=\"true\">\n      <rect width=\"200\" height=\"300\" fill={a} />\n      <rect width=\"200\" height=\"300\" fill={b} opacity=\".18\" />\n      {motif === \"sun\" ? (\n        <>\n          <circle cx=\"100\" cy=\"170\" r=\"56\" fill={b} />\n          {[0, 1, 2, 3, 4].map((i) => (\n            <rect key={i} x=\"30\" y={182 + i * 12} width=\"140\" height={5 - i * 0.6} fill={a} />\n          ))}\n          <path d=\"M0 240 L200 240 L200 300 L0 300Z\" fill={a} opacity=\".9\" />\n        </>\n      ) : null}\n      {motif === \"waves\" ? (\n        <>\n          <rect x=\"94\" y=\"80\" width=\"12\" height=\"110\" fill={b} opacity=\".85\" />\n          <path d=\"M88 80 L112 80 L106 64 L94 64Z\" fill={b} />\n          <path d=\"M100 66 L200 40 L200 92Z\" fill={b} opacity=\".25\" />\n          {[0, 1, 2, 3].map((i) => (\n            <path key={i} d={`M-10 ${200 + i * 22} Q25 ${190 + i * 22} 50 ${200 + i * 22} T110 ${200 + i * 22} T170 ${200 + i * 22} T230 ${200 + i * 22}`} stroke={b} strokeWidth=\"2.5\" fill=\"none\" opacity={(0.9 - i * 0.18).toFixed(2)} />\n          ))}\n        </>\n      ) : null}\n      {motif === \"peaks\" ? (\n        <>\n          <circle cx=\"140\" cy=\"90\" r=\"18\" fill={b} opacity=\".9\" />\n          <path d=\"M-10 230 L60 130 L100 180 L140 110 L210 230Z\" fill={b} opacity=\".45\" />\n          <path d=\"M-10 260 L40 190 L90 240 L150 170 L210 260 L210 300 L-10 300Z\" fill={a} />\n          <path d=\"M-10 260 L40 190 L90 240 L150 170 L210 260\" stroke={b} strokeWidth=\"1.5\" fill=\"none\" />\n        </>\n      ) : null}\n      {motif === \"stars\" ? (\n        <>\n          {Array.from({ length: 40 }, (_, i) => {\n            const h = Math.imul(i + 17, 2654435761) >>> 0;\n            return <circle key={i} cx={h % 200} cy={(h >>> 8) % 220} r={((h >>> 4) % 3) * 0.5 + 0.5} fill={b} opacity={(0.3 + ((h >>> 12) % 70) / 100).toFixed(2)} />;\n          })}\n          <circle cx=\"100\" cy=\"150\" r=\"40\" fill=\"none\" stroke={b} strokeWidth=\"1.5\" />\n          <circle cx=\"100\" cy=\"150\" r=\"64\" fill=\"none\" stroke={b} strokeWidth=\".8\" opacity=\".5\" />\n          <circle cx=\"100\" cy=\"150\" r=\"5\" fill={b} />\n        </>\n      ) : null}\n      {motif === \"city\" ? (\n        <>\n          <circle cx=\"60\" cy=\"110\" r=\"30\" fill={b} opacity=\".7\" />\n          {[[10, 190, 30], [44, 160, 26], [74, 200, 34], [112, 140, 28], [144, 180, 36], [184, 210, 20]].map(([x, y, w], i) => (\n            <rect key={i} x={x} y={y} width={w} height={300 - y} fill={a} stroke={b} strokeWidth=\".8\" strokeOpacity=\".5\" />\n          ))}\n        </>\n      ) : null}\n      <path d=\"M0 200 L200 200 L200 300 L0 300Z\" fill=\"#000\" opacity=\".25\" />\n    </svg>\n  );\n}\n\nexport function CinemaChapterSelect({\n  film = \"The Long Quiet · Director's cut\",\n  chapters = defaultChapters,\n  value,\n  defaultValue,\n  onValueChange,\n  onPlay,\n  playLabel = \"Play chapter\",\n  headingAs = \"h2\",\n  className,\n  style,\n  ...rest\n}: CinemaChapterSelectProps) {\n  const Heading = headingAs;\n  const [inner, setInner] = React.useState(defaultValue ?? chapters[1]?.id ?? chapters[0]?.id ?? \"\");\n  const current = value ?? inner;\n  const index = Math.max(0, chapters.findIndex((c) => c.id === current));\n  const chapter = chapters[index];\n  const refs = React.useRef<(HTMLButtonElement | null)[]>([]);\n\n  const select = (i: number, focus = false) => {\n    const c = chapters[(i + chapters.length) % chapters.length];\n    if (!c) return;\n    if (value === undefined) setInner(c.id);\n    onValueChange?.(c.id);\n    if (focus) refs.current[(i + chapters.length) % chapters.length]?.focus();\n  };\n\n  const onKey = (e: React.KeyboardEvent) => {\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") { e.preventDefault(); select(index + 1, true); }\n    else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") { e.preventDefault(); select(index - 1, true); }\n    else if (e.key === \"Home\") { e.preventDefault(); select(0, true); }\n    else if (e.key === \"End\") { e.preventDefault(); select(chapters.length - 1, true); }\n  };\n\n  if (!chapter) return null;\n  const vars = { \"--hb-vc12-c\": chapter.colors[1], \"--hb-vc12-n\": String(chapters.length), ...style } as React.CSSProperties;\n\n  return (\n    <section className={[\"hb-vc12\", className].filter(Boolean).join(\" \")} style={vars} {...rest}>\n      <style href=\"hb-cinema-chapter-select\" precedence=\"default\">{css}</style>\n      {chapters.map((c) => (\n        <div\n          key={c.id}\n          className=\"hb-vc12-bg\"\n          data-on={c.id === chapter.id ? \"true\" : \"false\"}\n          aria-hidden=\"true\"\n          style={{ background: `radial-gradient(60% 70% at 72% 40%, ${c.colors[1]}55, transparent 70%), radial-gradient(80% 80% at 90% 90%, ${c.colors[0]}, transparent 70%), ${c.colors[0]}33` }}\n        />\n      ))}\n      <div className=\"hb-vc12-veil\" aria-hidden=\"true\" />\n      <div className=\"hb-vc12-info\">\n        {film ? <p className=\"hb-vc12-film\">{film}</p> : null}\n        <div className=\"hb-vc12-swap\" key={chapter.id}>\n          <span className=\"hb-vc12-num\">Chapter {String(index + 1).padStart(2, \"0\")} of {String(chapters.length).padStart(2, \"0\")}</span>\n          <Heading className=\"hb-vc12-title\">{chapter.title}</Heading>\n          <p className=\"hb-vc12-syn\">{chapter.synopsis}</p>\n        </div>\n        <div className=\"hb-vc12-meta\">\n          <button type=\"button\" className=\"hb-vc12-play\" onClick={() => onPlay?.(chapter)}>\n            <span aria-hidden=\"true\">\n              <svg width=\"10\" height=\"11\" viewBox=\"0 0 8 9\"><path d=\"M0 0 L8 4.5 L0 9Z\" fill=\"currentColor\" /></svg>\n            </span>\n            {chapter.watched && chapter.watched > 0 && chapter.watched < 1 ? \"Resume chapter\" : playLabel}\n          </button>\n          <span className=\"hb-vc12-facts\">{chapter.runtime} · starts at {chapter.start}</span>\n        </div>\n      </div>\n      <div className=\"hb-vc12-row\" role=\"radiogroup\" aria-label=\"Chapters\" onKeyDown={onKey}>\n        {chapters.map((c, i) => (\n          <button\n            key={c.id}\n            ref={(node) => {\n              refs.current[i] = node;\n            }}\n            type=\"button\"\n            role=\"radio\"\n            aria-checked={c.id === chapter.id}\n            aria-label={`Chapter ${i + 1}: ${c.title}, ${c.runtime}`}\n            tabIndex={c.id === chapter.id ? 0 : -1}\n            className=\"hb-vc12-card\"\n            style={{ \"--hb-vc12-c\": c.colors[1] } as React.CSSProperties}\n            onClick={() => select(i)}\n          >\n            <span className=\"hb-vc12-poster\">\n              <Motif motif={c.motif} colors={c.colors} />\n              <span className=\"hb-vc12-pnum\">{String(i + 1).padStart(2, \"0\")}</span>\n              <span className=\"hb-vc12-ptitle\">{c.title}</span>\n            </span>\n            <span className=\"hb-vc12-prog\"><span style={{ width: `${Math.round((c.watched ?? 0) * 100)}%` }} /></span>\n            <span className=\"hb-vc12-time\">{c.start}</span>\n          </button>\n        ))}\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}