{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"cinema-hero","type":"registry:block","title":"Cinema hero","description":"A video-first hero: a film-leader countdown cuts to your film playing with subtitles, the screen lights the room, and a 35mm chapter strip scrubs and jumps through it.","author":"Hairline UI","dependencies":["lucide-react"],"files":[{"path":"registry/cinema-hero.tsx","type":"registry:component","content":"// Hairline UI · cinema-hero · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\nimport { ArrowRight, ArrowUpRight, Menu, Pause, Play, Volume2, VolumeX, X } from \"lucide-react\";\n\n/* ─────────────────────────────────────────────────────────\n * CINEMA HERO: the screening\n *\n *   leader    on load the screen runs a film-leader countdown, 3·2·1,\n *             in CSS, then cuts to the film playing muted with its\n *             subtitles burned in.\n *   room      the screen is the only light. Its colour, sampled from the\n *             playing frame, falls on the wall behind it and shows in a\n *             reflection on the floor under it.\n *   strip     a 35mm strip runs edge to edge under the screen. Each frame\n *             is a chapter still with its number, timecode and title\n *             printed in the margins. It pulls down a frame as the film\n *             crosses a chapter; drag it to scrub, click a frame to jump.\n *   sound     \"Watch with sound\" (or a click on the screen) plays the\n *             real film with sound, in place.\n *\n * Every colour is a --ch-* variable on the root (tone \"dark\" or\n * \"light\"); type comes from --ch-display and --ch-sans.\n * ───────────────────────────────────────────────────────── */\n\nexport interface CinemaHeroLink {\n  label: string;\n  href: string;\n}\n\nexport interface CinemaHeroAction {\n  label: string;\n  href?: string;\n  onClick?: () => void;\n}\n\nexport interface CinemaHeroVideo {\n  /** An mp4 (H.264) the browser can play inline. */\n  src: string;\n  poster?: string;\n  /** Where the muted preview starts, in seconds (skip a slow cold open). */\n  start?: number;\n  /** Length in seconds, shown before the metadata loads. */\n  duration?: number;\n}\n\nexport interface CinemaHeroChapter {\n  title: string;\n  /** Start of the chapter, in seconds. */\n  time: number;\n  /** A still from the chapter (16:9). */\n  still: string;\n}\n\nexport interface CinemaHeroCaption {\n  start: number;\n  end: number;\n  text: string;\n}\n\nexport interface CinemaHeroProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\"> {\n  brand: string;\n  logo?: React.ReactNode;\n  navLinks?: CinemaHeroLink[];\n  navSecondaryAction?: CinemaHeroAction;\n  navPrimaryAction?: CinemaHeroAction;\n  eyebrow?: string;\n  /** One or two headline lines. */\n  headline: string[];\n  /** A phrase inside the headline painted in the signal colour. */\n  highlight?: string;\n  subheadline: string;\n  primaryAction: CinemaHeroAction;\n  /** Label of the button that plays the film with sound from the top. */\n  watchLabel?: string;\n  video: CinemaHeroVideo;\n  chapters: CinemaHeroChapter[];\n  /** Subtitles burned into the screen. */\n  captions?: CinemaHeroCaption[];\n  /** Run the 3·2·1 leader before the film. */\n  countdown?: boolean;\n  tone?: \"dark\" | \"light\";\n}\n\nconst TONES: Record<\"dark\" | \"light\", Record<string, string>> = {\n  dark: {\n    \"--ch-room\": \"#0b0d12\",\n    \"--ch-wall\": \"#11141b\",\n    \"--ch-ink\": \"#f2f0ea\",\n    \"--ch-ink-2\": \"#a9abb3\",\n    \"--ch-ink-3\": \"#686c76\",\n    \"--ch-rule\": \"rgba(242, 240, 234, 0.1)\",\n    \"--ch-hover\": \"#1a1e27\",\n    \"--ch-signal\": \"#f5d142\",\n    \"--ch-on-signal\": \"#15120a\",\n    \"--ch-film\": \"#16120e\",\n    \"--ch-film-edge\": \"#211b15\",\n    \"--ch-mask\": \"#050608\",\n    \"--ch-hole\": \"#35302a\",\n    \"--ch-signal-text\": \"#f5d142\",\n    \"--ch-spill-amount\": \"0.42\",\n  },\n  light: {\n    \"--ch-room\": \"#e4e5e8\",\n    \"--ch-wall\": \"#d9dbe0\",\n    \"--ch-ink\": \"#101115\",\n    \"--ch-ink-2\": \"#4f525a\",\n    \"--ch-ink-3\": \"#8a8d95\",\n    \"--ch-rule\": \"rgba(16, 17, 21, 0.1)\",\n    \"--ch-hover\": \"#d4d6db\",\n    \"--ch-signal\": \"#f2c919\",\n    \"--ch-on-signal\": \"#15120a\",\n    \"--ch-film\": \"#17130f\",\n    \"--ch-film-edge\": \"#241d16\",\n    \"--ch-mask\": \"#0b0c0f\",\n    \"--ch-hole\": \"#e4e5e8\",\n    \"--ch-signal-text\": \"#7a5f00\",\n    \"--ch-spill-amount\": \"0.22\",\n  },\n};\n\nconst DEFAULT_LINKS: CinemaHeroLink[] = [\n  { label: \"Components\", href: \"#components\" },\n  { label: \"Templates\", href: \"#templates\" },\n  { label: \"Pricing\", href: \"#pricing\" },\n  { label: \"Docs\", href: \"#docs\" },\n];\n\nconst EASE = \"cubic-bezier(0.16, 1, 0.3, 1)\";\n/** A projector pulls a frame down hard and lets it settle. */\nconst PULLDOWN = \"cubic-bezier(0.22, 1.25, 0.36, 1)\";\nconst LEADER_FRAMES = 4;\nconst NO_CAPTIONS: CinemaHeroCaption[] = [];\n\nconst FOCUS =\n  \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--ch-signal)] focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--ch-room)]\";\n\nconst CSS = `\n@property --ch-sweep { syntax: '<angle>'; inherits: false; initial-value: 0deg; }\n@keyframes ch-sweep { from { --ch-sweep: 0deg; } to { --ch-sweep: 360deg; } }\n@keyframes ch-num { 0%, 100% { opacity: 0; } 2%, 98% { opacity: 1; } }\n@keyframes ch-cut { to { opacity: 0; visibility: hidden; } }\n@keyframes ch-flicker { 0%, 100% { opacity: 1; } 50% { opacity: 0.93; } }\n@keyframes ch-rise { from { transform: translate3d(0, 105%, 0); } to { transform: none; } }\n@keyframes ch-fade { from { opacity: 0; transform: translate3d(0, 10px, 0); } to { opacity: 1; transform: none; } }\n@keyframes ch-sub { from { opacity: 0; } to { opacity: 1; } }\n[data-ch] .ch-leader { animation: ch-cut 1ms linear 1.86s forwards; }\n[data-ch] .ch-sweep { animation: ch-sweep 0.62s linear 3; background: conic-gradient(from 0deg, rgba(255,255,255,0.2) var(--ch-sweep), transparent 0); }\n[data-ch] .ch-leader-inner { animation: ch-flicker 0.12s steps(2) infinite; }\n[data-ch] .ch-num { opacity: 0; animation: ch-num 0.62s linear both; }\n[data-ch] .ch-rise { animation: ch-rise 900ms ${EASE} both; }\n[data-ch] .ch-fade { animation: ch-fade 800ms ${EASE} both; }\n[data-ch] .ch-sub { animation: ch-sub 140ms linear both; }\n@media (prefers-reduced-motion: reduce) {\n  [data-ch] .ch-leader { display: none; }\n  [data-ch] .ch-rise, [data-ch] .ch-fade, [data-ch] .ch-sub, [data-ch] .ch-leader-inner { animation: none; }\n}\n`;\n\nconst reducedQuery = \"(prefers-reduced-motion: reduce)\";\nfunction subscribeReduced(cb: () => void) {\n  const mq = window.matchMedia(reducedQuery);\n  mq.addEventListener(\"change\", cb);\n  return () => mq.removeEventListener(\"change\", cb);\n}\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(subscribeReduced, () => window.matchMedia(reducedQuery).matches, () => false);\n}\n\nfunction clock(seconds: number) {\n  const s = Math.max(0, Math.floor(seconds));\n  return `${String(Math.floor(s / 60)).padStart(2, \"0\")}:${String(s % 60).padStart(2, \"0\")}`;\n}\n\nfunction chapterAt(chapters: CinemaHeroChapter[], t: number) {\n  let idx = 0;\n  for (let i = 0; i < chapters.length; i++) if (t + 0.05 >= chapters[i].time) idx = i;\n  return idx;\n}\n\n/* ── pieces ─────────────────────────────────────────────── */\n\nfunction ActionLink({ action, className, children }: { action: CinemaHeroAction; className: string; children: React.ReactNode }) {\n  if (action.href && !action.onClick) {\n    return (\n      <a href={action.href} className={className}>\n        {children}\n      </a>\n    );\n  }\n  return (\n    <button type=\"button\" onClick={action.onClick} className={className}>\n      {children}\n    </button>\n  );\n}\n\nfunction ReelMark() {\n  return (\n    <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" className=\"size-[22px] shrink-0\">\n      <rect x=\"2\" y=\"4\" width=\"20\" height=\"16\" rx=\"2.5\" fill=\"currentColor\" />\n      {[5.5, 9.5, 13.5, 17.5].map((x) => (\n        <React.Fragment key={x}>\n          <rect x={x} y=\"5.6\" width=\"2\" height=\"1.8\" rx=\".5\" fill=\"var(--ch-room)\" />\n          <rect x={x} y=\"16.6\" width=\"2\" height=\"1.8\" rx=\".5\" fill=\"var(--ch-room)\" />\n        </React.Fragment>\n      ))}\n      <rect x=\"4.5\" y=\"8.8\" width=\"15\" height=\"6.4\" rx=\"1\" fill=\"var(--ch-signal)\" />\n    </svg>\n  );\n}\n\nfunction SignalButton({ action, small = false, className = \"\" }: { action: CinemaHeroAction; small?: boolean; className?: string }) {\n  return (\n    <ActionLink\n      action={action}\n      className={`group inline-flex shrink-0 cursor-pointer touch-manipulation items-center justify-center gap-2 whitespace-nowrap rounded-[6px] bg-[var(--ch-signal)] font-semibold tracking-[-0.005em] text-[var(--ch-on-signal)] transition-transform duration-150 active:scale-[0.97] ${\n        small ? \"h-9 px-3.5 text-[13px]\" : \"h-12 px-5 text-[15px]\"\n      } ${FOCUS} ${className}`}\n    >\n      <span>{action.label}</span>\n      <ArrowUpRight\n        className=\"size-4 transition-transform duration-300 group-hover:-translate-y-px group-hover:translate-x-0.5\"\n        strokeWidth={2.2}\n        style={{ transitionTimingFunction: EASE }}\n      />\n    </ActionLink>\n  );\n}\n\nfunction HeadlineLine({ line, highlight, marker }: { line: string; highlight?: string; marker: boolean }) {\n  const idx = highlight ? line.indexOf(highlight) : -1;\n  if (!highlight || idx === -1) return <>{line}</>;\n  return (\n    <>\n      {line.slice(0, idx)}\n      <span\n        className={\n          marker\n            ? \"box-decoration-clone bg-[var(--ch-signal)] px-[0.06em] text-[var(--ch-on-signal)]\"\n            : \"text-[var(--ch-signal)]\"\n        }\n      >\n        {highlight}\n      </span>\n      {line.slice(idx + highlight.length)}\n    </>\n  );\n}\n\n/** Film-leader countdown: grey leader, rings, crosshair, a sweep and 3·2·1. */\nfunction Leader({ ref }: { ref?: React.Ref<HTMLDivElement> }) {\n  return (\n    <div ref={ref} aria-hidden=\"true\" className=\"ch-leader absolute inset-0 z-20 overflow-hidden bg-[#3a3a38]\">\n      <div className=\"ch-leader-inner absolute inset-0\">\n        <div className=\"ch-sweep absolute left-1/2 top-1/2 aspect-square w-[150%] -translate-x-1/2 -translate-y-1/2\" />\n        <div className=\"absolute inset-x-0 top-1/2 h-px bg-white/45\" />\n        <div className=\"absolute inset-y-0 left-1/2 w-px bg-white/45\" />\n        <div className=\"absolute left-1/2 top-1/2 aspect-square h-[78%] -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white/70\" />\n        <div className=\"absolute left-1/2 top-1/2 aspect-square h-[62%] -translate-x-1/2 -translate-y-1/2 rounded-full border border-white/55\" />\n        {[\"3\", \"2\", \"1\"].map((n, i) => (\n          <span\n            key={n}\n            className=\"ch-num absolute inset-0 grid place-items-center text-[clamp(56px,16cqw,170px)] font-semibold leading-none text-white\"\n            style={{ animationDelay: `${i * 0.62}s`, fontFamily: \"var(--ch-display, inherit)\" }}\n          >\n            {n}\n          </span>\n        ))}\n      </div>\n    </div>\n  );\n}\n\n/* ── the hero ───────────────────────────────────────────── */\n\ntype Phase = \"leader\" | \"preview\" | \"sound\" | \"paused\" | \"still\";\n\nexport function CinemaHero({\n  brand,\n  logo,\n  navLinks = DEFAULT_LINKS,\n  navSecondaryAction,\n  navPrimaryAction,\n  eyebrow,\n  headline,\n  highlight,\n  subheadline,\n  primaryAction,\n  watchLabel = \"Watch with sound\",\n  video,\n  chapters,\n  captions = NO_CAPTIONS,\n  countdown = true,\n  tone = \"dark\",\n  className = \"\",\n  style,\n  ...props\n}: CinemaHeroProps) {\n  const reduced = useReducedMotion();\n  const rootRef = React.useRef<HTMLElement>(null);\n  const videoRef = React.useRef<HTMLVideoElement>(null);\n  const leaderRef = React.useRef<HTMLDivElement>(null);\n  const reflectRef = React.useRef<HTMLCanvasElement>(null);\n  const spillRef = React.useRef<HTMLDivElement>(null);\n  const trackRef = React.useRef<HTMLDivElement>(null);\n\n  const [menuOpen, setMenuOpen] = React.useState(false);\n  const [phase, setPhase] = React.useState<Phase>(countdown ? \"leader\" : \"still\");\n  const [chapter, setChapter] = React.useState(0);\n  const [caption, setCaption] = React.useState<string | null>(null);\n  const [now, setNow] = React.useState(0);\n  const [duration, setDuration] = React.useState(video.duration ?? 0);\n  const [scrubbing, setScrubbing] = React.useState<number | null>(null);\n\n  const phaseRef = React.useRef(phase);\n  phaseRef.current = phase;\n  const captionsRef = React.useRef(captions);\n  captionsRef.current = captions;\n  const chaptersRef = React.useRef(chapters);\n  chaptersRef.current = chapters;\n  const dragRef = React.useRef<{ id: number; x: number; fw: number; from: number; moved: boolean } | null>(null);\n\n  const start = video.start ?? 0;\n  const shownChapter = scrubbing ?? chapter;\n\n  /* the film loop: subtitles, chapter, clock, the room's light */\n  React.useEffect(() => {\n    const v = videoRef.current;\n    const root = rootRef.current;\n    if (!v || !root) return;\n\n    const canvas = reflectRef.current;\n    const ctx = canvas?.getContext(\"2d\", { willReadFrequently: true }) ?? null;\n    let canRead = true;\n    const spill = [40, 48, 70];\n    const target = [40, 48, 70];\n    let frame = 0;\n    let raf = 0;\n    let lastCap = -2;\n    let lastChapter = -1;\n    let lastSecond = -1;\n\n    const paintRoom = () => {\n      if (!ctx || !canvas) return;\n      try {\n        if (v.readyState >= 2) ctx.drawImage(v, 0, 0, canvas.width, canvas.height);\n      } catch {\n        return;\n      }\n      if (canRead && frame % 12 === 0) {\n        try {\n          const d = ctx.getImageData(0, 0, canvas.width, canvas.height).data;\n          let r = 0, g = 0, b = 0, n = 0;\n          for (let i = 0; i < d.length; i += 16) {\n            r += d[i];\n            g += d[i + 1];\n            b += d[i + 2];\n            n++;\n          }\n          if (n) {\n            // keep the hue, lift it a little: the screen is a light, not a swatch\n            const m = Math.max(r, g, b) / n || 1;\n            const lift = Math.min(1.8, 150 / m);\n            target[0] = Math.min(255, (r / n) * lift);\n            target[1] = Math.min(255, (g / n) * lift);\n            target[2] = Math.min(255, (b / n) * lift);\n          }\n        } catch {\n          canRead = false; // a cross-origin film without CORS: the reflection still draws, the light stays neutral\n        }\n      }\n      let changed = false;\n      for (let i = 0; i < 3; i++) {\n        const next = spill[i] + (target[i] - spill[i]) * 0.06;\n        if (Math.abs(next - spill[i]) > 0.4) changed = true;\n        spill[i] = next;\n      }\n      if (changed && spillRef.current) {\n        spillRef.current.style.setProperty(\"--ch-spill\", `${spill[0] | 0} ${spill[1] | 0} ${spill[2] | 0}`);\n      }\n    };\n\n    const step = () => {\n      raf = 0;\n      const t = v.currentTime;\n      const captions = captionsRef.current;\n      const chapters = chaptersRef.current;\n      // subtitles: the line under the playhead, if any\n      let cap = -1;\n      for (let i = 0; i < captions.length; i++) {\n        if (t >= captions[i].start && t < captions[i].end) {\n          cap = i;\n          break;\n        }\n        if (captions[i].start > t) break;\n      }\n      if (cap !== lastCap) {\n        lastCap = cap;\n        setCaption(cap >= 0 ? captions[cap].text : null);\n      }\n      const c = chapterAt(chapters, t);\n      if (c !== lastChapter) {\n        lastChapter = c;\n        setChapter(c);\n      }\n      const sec = Math.floor(t);\n      if (sec !== lastSecond) {\n        lastSecond = sec;\n        setNow(t);\n      }\n      frame++;\n      paintRoom();\n      if (!v.paused && !v.ended) raf = requestAnimationFrame(step);\n    };\n\n    const kick = () => {\n      if (!raf) raf = requestAnimationFrame(step);\n    };\n    const onMeta = () => {\n      if (Number.isFinite(v.duration) && v.duration > 0) setDuration(v.duration);\n    };\n    const onEnded = () => {\n      if (phaseRef.current === \"preview\") {\n        v.currentTime = start;\n        void v.play();\n      } else {\n        setPhase(\"paused\");\n      }\n    };\n    const onSeeked = () => kick();\n    v.addEventListener(\"play\", kick);\n    v.addEventListener(\"seeked\", onSeeked);\n    v.addEventListener(\"loadedmetadata\", onMeta);\n    v.addEventListener(\"loadeddata\", kick);\n    v.addEventListener(\"ended\", onEnded);\n    onMeta();\n\n    // the poster lights the room before the film runs\n    if (video.poster && ctx && canvas) {\n      const img = new Image();\n      img.onload = () => {\n        if (v.readyState >= 2) return;\n        try {\n          ctx.drawImage(img, 0, 0, canvas.width, canvas.height);\n        } catch {\n          /* ignore */\n        }\n      };\n      img.src = video.poster;\n    }\n\n    // a muted preview only runs while the screen is on screen\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        if (!entry) return;\n        if (!entry.isIntersecting && phaseRef.current === \"preview\" && !v.paused) v.pause();\n        if (entry.isIntersecting && phaseRef.current === \"preview\" && v.paused) void v.play().catch(() => setPhase(\"still\"));\n      },\n      { threshold: 0.15 },\n    );\n    io.observe(v);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      v.removeEventListener(\"play\", kick);\n      v.removeEventListener(\"seeked\", onSeeked);\n      v.removeEventListener(\"loadedmetadata\", onMeta);\n      v.removeEventListener(\"loadeddata\", kick);\n      v.removeEventListener(\"ended\", onEnded);\n    };\n  }, [start, video.poster]);\n\n  /* the leader runs in CSS on load; when it ends, the film starts muted */\n  React.useEffect(() => {\n    const v = videoRef.current;\n    if (!v) return;\n    if (reduced || !countdown) {\n      setPhase(\"still\");\n      return;\n    }\n    let cancelled = false;\n    const begin = () => {\n      if (cancelled || phaseRef.current !== \"leader\") return;\n      v.muted = true;\n      if (v.currentTime < start) v.currentTime = start;\n      v.play()\n        .then(() => !cancelled && setPhase(\"preview\"))\n        .catch(() => !cancelled && setPhase(\"still\"));\n    };\n    const anims = (leaderRef.current?.getAnimations?.() ?? []).filter(\n      (a) => (a as Animation & { animationName?: string }).animationName === \"ch-cut\",\n    );\n    if (anims.length) {\n      Promise.all(anims.map((a) => a.finished)).then(begin, begin);\n    } else {\n      begin();\n    }\n    return () => {\n      cancelled = true;\n    };\n  }, [reduced, countdown, start]);\n\n  const playWithSound = (from?: number) => {\n    const v = videoRef.current;\n    if (!v) return;\n    v.muted = false;\n    if (from != null) v.currentTime = from;\n    setPhase(\"sound\");\n    void v.play().catch(() => setPhase(\"paused\"));\n  };\n\n  const onScreenClick = () => {\n    const v = videoRef.current;\n    if (!v) return;\n    if (phase === \"preview\" || phase === \"leader\") return playWithSound();\n    if (phase === \"sound\") {\n      v.pause();\n      setPhase(\"paused\");\n      return;\n    }\n    playWithSound(phase === \"still\" && v.currentTime < start ? 0 : undefined);\n  };\n\n  const toggleMute = (e: React.MouseEvent) => {\n    e.stopPropagation();\n    const v = videoRef.current;\n    if (!v) return;\n    if (phase === \"preview\") return playWithSound();\n    v.muted = !v.muted;\n    setPhase(v.muted ? \"preview\" : \"sound\");\n  };\n\n  const jumpTo = (i: number) => {\n    const v = videoRef.current;\n    const c = chapters[i];\n    if (!v || !c) return;\n    setChapter(i);\n    v.currentTime = c.time;\n    if (phase === \"sound\" || phase === \"paused\" || phase === \"still\") {\n      if (phase !== \"sound\") playWithSound(c.time);\n    } else {\n      void v.play().catch(() => setPhase(\"still\"));\n    }\n  };\n\n  /* drag the strip: the screen shows the still under the gate, release jumps */\n  const onStripDown = (e: React.PointerEvent<HTMLDivElement>) => {\n    if (e.button !== 0) return;\n    const frameEl = trackRef.current?.querySelector<HTMLElement>(\"[data-frame]\");\n    const fw = frameEl?.getBoundingClientRect().width ?? 180;\n    dragRef.current = { id: e.pointerId, x: e.clientX, fw, from: chapter, moved: false };\n  };\n  const onStripMove = (e: React.PointerEvent<HTMLDivElement>) => {\n    const d = dragRef.current;\n    if (!d || d.id !== e.pointerId) return;\n    const dx = e.clientX - d.x;\n    if (!d.moved && Math.abs(dx) < 6) return;\n    if (!d.moved) {\n      d.moved = true;\n      e.currentTarget.setPointerCapture(e.pointerId);\n    }\n    const pos = Math.max(-0.45, Math.min(chapters.length - 0.55, d.from - dx / d.fw));\n    trackRef.current?.style.setProperty(\"--ch-pos\", String(pos));\n    const nearest = Math.round(Math.max(0, Math.min(chapters.length - 1, pos)));\n    setScrubbing((s) => (s === nearest ? s : nearest));\n  };\n  const onStripUp = (e: React.PointerEvent<HTMLDivElement>) => {\n    const d = dragRef.current;\n    dragRef.current = null;\n    if (!d || !d.moved) return;\n    const target = scrubbing ?? d.from;\n    setScrubbing(null);\n    trackRef.current?.style.removeProperty(\"--ch-pos\");\n    jumpTo(target);\n    e.preventDefault();\n  };\n\n  const onStripKey = (e: React.KeyboardEvent, i: number) => {\n    let next: number | null = null;\n    if (e.key === \"ArrowRight\") next = Math.min(chapters.length - 1, i + 1);\n    if (e.key === \"ArrowLeft\") next = Math.max(0, i - 1);\n    if (next !== null) {\n      e.preventDefault();\n      jumpTo(next);\n      trackRef.current?.querySelector<HTMLElement>(`[data-frame=\"${next}\"]`)?.focus();\n    }\n  };\n\n  const display: React.CSSProperties = { fontFamily: \"var(--ch-display, inherit)\" };\n  const rootStyle = { ...TONES[tone], fontFamily: \"var(--ch-sans, inherit)\", ...style } as React.CSSProperties;\n  const playing = phase === \"preview\" || phase === \"sound\";\n  const total = duration || video.duration || 0;\n  const progress = total ? Math.min(1, now / total) : 0;\n  const active = chapters[shownChapter];\n\n  const leaderTail = Array.from({ length: LEADER_FRAMES }, (_, i) => i);\n\n  return (\n    <section\n      ref={rootRef}\n      data-ch=\"\"\n      data-tone={tone}\n      aria-label={`${brand} hero`}\n      style={rootStyle}\n      className={`@container relative isolate flex w-full flex-col overflow-clip rounded-[14px] bg-[var(--ch-room)] text-[var(--ch-ink)] [-webkit-tap-highlight-color:transparent] ${className}`}\n      {...props}\n    >\n      <style>{CSS}</style>\n\n      {/* the screen's light on the wall and floor */}\n      <div\n        ref={spillRef}\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0 -z-10\"\n        style={{\n          [\"--ch-spill\" as string]: \"40 48 70\",\n          background:\n            \"radial-gradient(70% 46% at 50% 56%, rgb(var(--ch-spill) / var(--ch-spill-amount)), transparent 72%), linear-gradient(180deg, var(--ch-wall), var(--ch-room) 58%)\",\n        }}\n      />\n\n      {/* nav */}\n      <header className=\"relative z-20 flex h-16 shrink-0 items-center gap-4 px-4 @[768px]:px-8\">\n        <a href=\"#top\" className={`inline-flex items-center gap-2 rounded-[6px] text-[18px] font-semibold uppercase tracking-[0.01em] ${FOCUS}`} style={display}>\n          {logo ?? <ReelMark />}\n          <span>{brand}</span>\n        </a>\n        <nav aria-label=\"Primary\" className=\"ml-6 hidden items-center gap-0.5 @[900px]:flex\">\n          {navLinks.map((l) => (\n            <a\n              key={l.label}\n              href={l.href}\n              className={`inline-flex h-9 items-center rounded-[6px] px-3 text-[14px] font-medium text-[var(--ch-ink-2)] transition-colors hover:bg-[var(--ch-hover)] hover:text-[var(--ch-ink)] ${FOCUS}`}\n            >\n              {l.label}\n            </a>\n          ))}\n        </nav>\n        <div className=\"ml-auto flex items-center gap-1.5\">\n          {navSecondaryAction && (\n            <ActionLink\n              action={navSecondaryAction}\n              className={`hidden h-9 items-center rounded-[6px] px-3 text-[14px] font-medium text-[var(--ch-ink-2)] transition-colors hover:bg-[var(--ch-hover)] hover:text-[var(--ch-ink)] @[600px]:inline-flex ${FOCUS}`}\n            >\n              {navSecondaryAction.label}\n            </ActionLink>\n          )}\n          {navPrimaryAction && <SignalButton action={navPrimaryAction} small className=\"hidden @[600px]:inline-flex\" />}\n          <button\n            type=\"button\"\n            aria-expanded={menuOpen}\n            aria-label={menuOpen ? \"Close menu\" : \"Open menu\"}\n            onClick={() => setMenuOpen((o) => !o)}\n            className={`inline-flex size-10 cursor-pointer touch-manipulation items-center justify-center rounded-[8px] transition-colors hover:bg-[var(--ch-hover)] @[900px]:hidden ${FOCUS}`}\n          >\n            {menuOpen ? <X className=\"size-5\" strokeWidth={1.8} /> : <Menu className=\"size-5\" strokeWidth={1.8} />}\n          </button>\n        </div>\n      </header>\n\n      <div\n        className=\"relative z-20 grid shrink-0 @[900px]:hidden\"\n        style={{ gridTemplateRows: menuOpen ? \"1fr\" : \"0fr\", transition: reduced ? \"none\" : `grid-template-rows 320ms ${EASE}` }}\n        inert={!menuOpen}\n      >\n        <div className=\"min-h-0 overflow-clip\">\n          <div className=\"mx-4 mb-3 rounded-[10px] bg-[var(--ch-hover)] p-2 @[768px]:mx-8\">\n            {navLinks.map((l) => (\n              <a\n                key={l.label}\n                href={l.href}\n                onClick={() => setMenuOpen(false)}\n                className={`flex h-12 items-center justify-between rounded-[6px] px-3 text-[20px] font-semibold uppercase tracking-[0.01em] ${FOCUS}`}\n                style={display}\n              >\n                {l.label}\n                <ArrowRight className=\"size-4 text-[var(--ch-ink-3)]\" strokeWidth={2} />\n              </a>\n            ))}\n            {(navPrimaryAction || navSecondaryAction) && (\n              <div className=\"mt-1 flex flex-col gap-2 p-1 @[600px]:hidden\">\n                {navPrimaryAction && <SignalButton action={navPrimaryAction} className=\"w-full\" />}\n                {navSecondaryAction && (\n                  <ActionLink\n                    action={navSecondaryAction}\n                    className={`inline-flex h-11 items-center justify-center rounded-[6px] text-[15px] font-medium text-[var(--ch-ink-2)] ${FOCUS}`}\n                  >\n                    {navSecondaryAction.label}\n                  </ActionLink>\n                )}\n              </div>\n            )}\n          </div>\n        </div>\n      </div>\n\n      {/* the bill: headline, one line, the actions */}\n      <div className=\"relative z-10 flex shrink-0 flex-col items-center px-4 pt-6 text-center @[768px]:px-8 @[768px]:pt-8\">\n        {eyebrow && (\n          <p className=\"ch-fade mb-3 text-[13px] font-medium text-[var(--ch-ink-2)] @[768px]:text-[14px]\" style={{ animationDelay: \"80ms\" }}>\n            {eyebrow}\n          </p>\n        )}\n        <h1\n          className=\"max-w-[18ch] text-[40px] font-semibold uppercase leading-[0.95] tracking-[0.005em] @[480px]:text-[50px] @[768px]:max-w-none @[768px]:text-[62px] @[1400px]:text-[74px]\"\n          style={display}\n        >\n          {headline.map((line, i) => (\n            <span key={i} className={`block overflow-clip pb-[0.04em] @[1100px]:inline-block ${i > 0 ? \"@[1100px]:ml-[0.24em]\" : \"\"}`}>\n              <span className=\"ch-rise block\" style={{ animationDelay: `${60 + i * 80}ms` }}>\n                <HeadlineLine line={line} highlight={highlight} marker={tone === \"light\"} />\n              </span>\n            </span>\n          ))}\n        </h1>\n        <p className=\"ch-fade mt-4 max-w-[52ch] text-[15px] @[1100px]:max-w-[66ch] leading-[1.55] text-[var(--ch-ink-2)] @[768px]:text-[16px]\" style={{ animationDelay: \"260ms\" }}>\n          {subheadline}\n        </p>\n        <div className=\"ch-fade mt-6 flex w-full flex-col items-center gap-2 @[480px]:w-auto @[480px]:flex-row\" style={{ animationDelay: \"340ms\" }}>\n          <SignalButton action={primaryAction} className=\"w-full @[480px]:w-auto\" />\n          <button\n            type=\"button\"\n            onClick={() => playWithSound(0)}\n            className={`group inline-flex h-12 w-full cursor-pointer touch-manipulation items-center justify-center gap-2.5 whitespace-nowrap rounded-[6px] px-4 text-[15px] font-medium text-[var(--ch-ink)] transition-colors hover:bg-[var(--ch-hover)] @[480px]:w-auto ${FOCUS}`}\n          >\n            <span className=\"grid size-6 place-items-center rounded-full bg-[var(--ch-ink)] text-[var(--ch-room)]\">\n              <Play className=\"size-3 translate-x-px fill-current\" strokeWidth={0} />\n            </span>\n            {watchLabel}\n            <span className=\"tabular-nums text-[var(--ch-ink-3)]\">{clock(total)}</span>\n          </button>\n        </div>\n      </div>\n\n      {/* the screen */}\n      <div className=\"relative z-10 mt-8 flex shrink-0 flex-col items-center px-4 @[768px]:mt-10 @[768px]:px-8\">\n        <div className=\"relative w-full max-w-[980px] @container/screen @[1100px]:max-w-[clamp(720px,calc((100svh-400px)*16/9),980px)]\">\n          <div\n            className=\"relative aspect-video w-full overflow-hidden rounded-[4px] bg-[var(--ch-mask)] ring-1 ring-black/40\"\n            style={{ cursor: \"pointer\" }}\n            onClick={onScreenClick}\n          >\n            <video\n              ref={videoRef}\n              src={video.src}\n              poster={video.poster}\n              muted\n              playsInline\n              preload=\"metadata\"\n              className=\"absolute inset-0 size-full object-cover\"\n              aria-label={`${brand} film`}\n            />\n\n            {/* a dragged frame shows in the gate before the jump */}\n            {scrubbing !== null && active && (\n              // eslint-disable-next-line @next/next/no-img-element\n              <img src={active.still} alt=\"\" className=\"absolute inset-0 size-full object-cover\" />\n            )}\n\n            {countdown && <Leader ref={leaderRef} />}\n\n            {/* burned-in subtitles */}\n            {caption && phase !== \"leader\" && scrubbing === null && (\n              <p\n                key={caption}\n                className=\"ch-sub pointer-events-none absolute inset-x-[6%] bottom-[7%] z-10 text-center text-[clamp(13px,3.4cqw,26px)] font-semibold leading-[1.2] text-white [text-shadow:0_1px_0_rgba(0,0,0,0.9),0_0_6px_rgba(0,0,0,0.75)]\"\n                style={display}\n              >\n                {caption}\n              </p>\n            )}\n\n            {/* paused / blocked autoplay: one play mark */}\n            {(phase === \"paused\" || phase === \"still\") && (\n              <span className=\"pointer-events-none absolute left-1/2 top-1/2 z-10 grid size-16 -translate-x-1/2 -translate-y-1/2 place-items-center rounded-full bg-[var(--ch-signal)] text-[var(--ch-on-signal)] @[600px]/screen:size-20\">\n                <Play className=\"size-7 translate-x-0.5 fill-current\" strokeWidth={0} />\n              </span>\n            )}\n\n            {/* sound, bottom right */}\n            {phase !== \"leader\" && (\n              <button\n                type=\"button\"\n                onClick={toggleMute}\n                aria-label={phase === \"sound\" ? \"Mute\" : \"Play with sound\"}\n                className={`absolute bottom-2.5 right-2.5 z-10 inline-flex h-8 cursor-pointer items-center gap-1.5 rounded-[6px] bg-black/55 px-2.5 text-[12px] font-medium text-white transition-colors hover:bg-black/70 ${FOCUS}`}\n              >\n                {phase === \"sound\" ? <Volume2 className=\"size-4\" strokeWidth={2} /> : <VolumeX className=\"size-4\" strokeWidth={2} />}\n                <span className=\"hidden @[520px]/screen:inline\">{phase === \"sound\" ? \"Sound on\" : \"Tap for sound\"}</span>\n              </button>\n            )}\n\n            {/* how far through the film */}\n            <span\n              aria-hidden=\"true\"\n              className=\"absolute bottom-0 left-0 z-10 h-[3px] bg-[var(--ch-signal)]\"\n              style={{ width: `${progress * 100}%`, transition: playing ? \"width 1s linear\" : \"none\" }}\n            />\n          </div>\n\n                    {/* samples the playing frame for the room's light */}\n          <canvas ref={reflectRef} width={32} height={18} aria-hidden=\"true\" className=\"hidden\" />\n\n          {/* the slate: chapter and time */}\n          <div className=\"relative mt-3 flex items-baseline justify-between gap-4 text-[12px] font-medium uppercase tracking-[0.06em] text-[var(--ch-ink-2)] @[768px]:text-[13px]\" style={display}>\n            <span className=\"truncate\">\n              <span className=\"text-[var(--ch-signal-text)] tabular-nums\">CH {String(shownChapter + 1).padStart(2, \"0\")}</span>\n              <span className=\"mx-2 text-[var(--ch-ink-3)]\">/</span>\n              {active?.title}\n            </span>\n            <span className=\"shrink-0 tabular-nums\">\n              {clock(now)} <span className=\"text-[var(--ch-ink-3)]\">/ {clock(total)}</span>\n            </span>\n          </div>\n        </div>\n      </div>\n\n      {/* the strip: one frame per chapter, edge to edge */}\n      <div\n        className=\"relative z-10 mt-4 mb-6 shrink-0 h-[calc(var(--ch-fw)*0.5625+52px)] select-none overflow-hidden [--ch-fw:150px] @[600px]:[--ch-fw:190px] @[1100px]:[--ch-fw:224px] @[768px]:mb-8\"\n        style={{ touchAction: \"pan-y\" }}\n        onPointerDown={onStripDown}\n        onPointerMove={onStripMove}\n        onPointerUp={onStripUp}\n        onPointerCancel={onStripUp}\n        role=\"group\"\n        aria-label=\"Chapters\"\n      >\n        <div\n          ref={trackRef}\n          className=\"absolute left-1/2 top-0 flex h-full\"\n          style={{\n            transform: `translate3d(calc((var(--ch-pos, ${chapter}) + ${LEADER_FRAMES} + 0.5) * var(--ch-fw) * -1), 0, 0)`,\n            transition: scrubbing !== null || reduced ? \"none\" : `transform 560ms ${PULLDOWN}`,\n          }}\n        >\n          {leaderTail.map((i) => (\n            <FilmFrame key={`h${i}`} kind=\"leader\" label={`${LEADER_FRAMES - i + 4}`} />\n          ))}\n          {chapters.map((c, i) => (\n            <FilmFrame\n              key={c.time}\n              kind=\"chapter\"\n              index={i}\n              chapter={c}\n              active={i === shownChapter}\n              onSelect={() => {\n                if (!dragRef.current?.moved) jumpTo(i);\n              }}\n              onKeyDown={(e) => onStripKey(e, i)}\n            />\n          ))}\n          {leaderTail.map((i) => (\n            <FilmFrame key={`t${i}`} kind=\"leader\" label={i === 0 ? \"END\" : \"\"} />\n          ))}\n        </div>\n      </div>\n    </section>\n  );\n}\n\nfunction FilmFrame({\n  kind,\n  index = 0,\n  chapter,\n  active = false,\n  label,\n  onSelect,\n  onKeyDown,\n}: {\n  kind: \"chapter\" | \"leader\";\n  index?: number;\n  chapter?: CinemaHeroChapter;\n  active?: boolean;\n  label?: string;\n  onSelect?: () => void;\n  onKeyDown?: (e: React.KeyboardEvent) => void;\n}) {\n  const holes: React.CSSProperties = {\n    backgroundImage:\n      \"linear-gradient(90deg, var(--ch-hole) 0 9px, transparent 9px), linear-gradient(90deg, var(--ch-hole) 0 9px, transparent 9px)\",\n    backgroundSize: \"calc(var(--ch-fw) / 8) 7px, calc(var(--ch-fw) / 8) 7px\",\n    backgroundPosition: \"4px 4px, 4px calc(100% - 4px)\",\n    backgroundRepeat: \"repeat-x, repeat-x\",\n  };\n  const print = \"text-[9.5px] font-semibold uppercase leading-none tracking-[0.12em] @[600px]:text-[10.5px]\";\n\n  if (kind === \"leader\") {\n    return (\n      <div aria-hidden=\"true\" className=\"relative h-full w-[var(--ch-fw)] shrink-0 bg-[var(--ch-film)]\" style={holes}>\n        <div className=\"absolute inset-x-[7px] bottom-[26px] top-[26px] grid place-items-center rounded-[3px] bg-[var(--ch-film-edge)]\">\n          {label && (\n            <span className=\"text-[22px] font-semibold text-white/25\" style={{ fontFamily: \"var(--ch-display, inherit)\" }}>\n              {label}\n            </span>\n          )}\n        </div>\n      </div>\n    );\n  }\n\n  const c = chapter!;\n  return (\n    <div className=\"relative h-full w-[var(--ch-fw)] shrink-0 bg-[var(--ch-film)]\" style={holes}>\n      <button\n        type=\"button\"\n        data-frame={index}\n        onClick={onSelect}\n        onKeyDown={onKeyDown}\n        aria-label={`Chapter ${index + 1}: ${c.title}, ${clock(c.time)}`}\n        aria-current={active ? \"true\" : undefined}\n        className={`group absolute inset-0 cursor-pointer touch-manipulation ${FOCUS}`}\n      >\n        <span\n          className={`absolute inset-x-[9px] top-[14px] flex justify-between ${print} ${active ? \"text-[var(--ch-signal)]\" : \"text-[#8b7a5a]\"}`}\n          style={{ fontFamily: \"var(--ch-display, inherit)\" }}\n        >\n          <span className=\"tabular-nums\">CH {String(index + 1).padStart(2, \"0\")}</span>\n          <span className=\"tabular-nums\">{clock(c.time)}</span>\n        </span>\n        <span className=\"absolute inset-x-[7px] bottom-[26px] top-[26px] overflow-hidden rounded-[3px] bg-black\">\n          {/* eslint-disable-next-line @next/next/no-img-element */}\n          <img\n            src={c.still}\n            alt=\"\"\n            draggable={false}\n            loading=\"lazy\"\n            className=\"size-full object-cover transition-[filter] duration-300\"\n            style={{ filter: active ? \"none\" : \"brightness(0.5) saturate(0.7)\" }}\n          />\n        </span>\n        <span\n          className={`absolute inset-x-[9px] bottom-[14px] truncate text-left ${print} ${active ? \"text-[var(--ch-signal)]\" : \"text-[#8b7a5a] group-hover:text-[#b9a57c]\"}`}\n          style={{ fontFamily: \"var(--ch-display, inherit)\" }}\n        >\n          {c.title}\n        </span>\n      </button>\n    </div>\n  );\n}\n\nexport default CinemaHero;\n"}],"css":{},"docs":"Docs and live preview: https://hairlineui.com/blocks/cinema-hero. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}