{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pennant",
  "type": "registry:block",
  "title": "Pennant",
  "description": "Announcement bar + cookie consent. Pennant is a slim top bar that rotates short messages with a vertical slide (paused on hover/focus, hairline progress meter), rolls an odometer countdown to a deadline and collapses on a height spring when dismissed, remembered via storageKey. Consent is a non-modal cookie card that rises into a bottom corner (full-width bar under 640px) with Accept / Reject / Customize; Customize grows the same card into per-category switches with Necessary locked on, reports onDecision, persists choices and reopens via ref from a footer link.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://crucibleui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/default/sections/pennant/pennant.tsx",
      "type": "registry:block",
      "target": "components/crucible/pennant.tsx",
      "content": "\"use client\";\n\nimport { AnimatePresence, motion, type Transition } from \"motion/react\";\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\n\n/* ================================================================ shared */\n\nconst DEFAULT_ACCENT = \"#818cf8\";\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\nconst INSTANT: Transition = { duration: 0 };\nconst HEIGHT_SPRING: Transition = { type: \"spring\", stiffness: 420, damping: 42, mass: 0.9 };\nconst RISE_SPRING: Transition = { type: \"spring\", stiffness: 340, damping: 32, mass: 0.9 };\n\n/** Black or white ink, whichever reads against the accent fill. */\nfunction readableOn(hex: string): string {\n  const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());\n  if (!m) return \"#0a0a0a\";\n  let s = m[1];\n  if (s.length === 3) s = s.replace(/./g, (c) => c + c);\n  const n = parseInt(s, 16);\n  const lum = 0.2126 * ((n >> 16) & 255) + 0.7152 * ((n >> 8) & 255) + 0.0722 * (n & 255);\n  return lum > 140 ? \"#0a0a0a\" : \"#ffffff\";\n}\n\nfunction storageGet(key: string | undefined): string | null {\n  if (!key) return null;\n  try {\n    return window.localStorage.getItem(key);\n  } catch {\n    return null;\n  }\n}\n\nfunction storageSet(key: string | undefined, value: string | null) {\n  if (!key) return;\n  try {\n    if (value === null) window.localStorage.removeItem(key);\n    else window.localStorage.setItem(key, value);\n  } catch {\n    /* storage blocked (private mode, sandbox) — state stays in memory */\n  }\n}\n\nconst FOCUS_RING =\n  \"outline-none focus-visible:ring-2 focus-visible:ring-[var(--pn-accent)] focus-visible:ring-offset-2 focus-visible:ring-offset-neutral-950\";\n\n/* ================================================================ Pennant */\n\nexport interface PennantLink {\n  /** Visible link text. */\n  label: string;\n  /** Destination href. */\n  href: string;\n}\n\nexport interface PennantMessage {\n  /** Short pill before the text (e.g. \"New\"). Omit for no pill. */\n  badge?: string;\n  /** The announcement copy. Keep it to one short sentence. */\n  text: React.ReactNode;\n  /** Inline call-to-action link after the text. */\n  link?: PennantLink;\n  /** Show a rolling countdown to this moment (Date, epoch ms or ISO string). */\n  endsAt?: Date | number | string;\n  /** Countdown target relative to mount, in milliseconds. Handy for demos; `endsAt` wins. */\n  endsIn?: number;\n}\n\n/** Imperative verbs exposed through the `ref` prop. */\nexport interface PennantHandle {\n  /** Bring the bar back (clears any persisted dismissal) and replay its intro. */\n  show: () => void;\n  /** Collapse the bar as if the dismiss button was pressed. */\n  dismiss: () => void;\n  /** Re-run the drop-in intro. */\n  replay: () => void;\n  /** Advance to the next rotating message. */\n  next: () => void;\n  /** Go back to the previous rotating message. */\n  prev: () => void;\n}\n\nexport interface PennantProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  /**\n   * Messages to rotate through with a vertical slide. One message renders\n   * static. Omit (and omit `text`) for a three-message sample set.\n   */\n  messages?: PennantMessage[];\n  /** Single-message shorthand: the announcement copy. Ignored when `messages` is set. */\n  text?: React.ReactNode;\n  /** Single-message shorthand: inline link. */\n  link?: PennantLink;\n  /** Single-message shorthand: pill before the text. */\n  badge?: string;\n  /** Single-message shorthand: rolling countdown target. */\n  endsAt?: Date | number | string;\n  /** Milliseconds each message holds before sliding to the next. @default 6000 */\n  interval?: number;\n  /** Show the dismiss button. @default true */\n  dismissible?: boolean;\n  /**\n   * localStorage key that remembers a dismissal across visits. Bump the key\n   * when you publish a new announcement. Omit to never persist.\n   */\n  storageKey?: string;\n  /** `\"subtle\"` is a near-black bar with accent details; `\"solid\"` fills it with the accent. @default \"subtle\" */\n  appearance?: \"subtle\" | \"solid\";\n  /** Accent hex for the pill, link, countdown and focus rings. @default \"#818cf8\" */\n  accentColor?: string;\n  /** Accessible name of the landmark region. @default \"Announcement\" */\n  label?: string;\n  /** Called after the bar is dismissed by the user or `dismiss()`. */\n  onDismiss?: () => void;\n  /** Called when the visible message changes (index into the message list). */\n  onMessageChange?: (index: number) => void;\n  /** Imperative handle (`show`, `dismiss`, `replay`, `next`, `prev`). React 19 ref-as-prop. */\n  ref?: React.Ref<PennantHandle>;\n  /** Extra classes for the outer region. */\n  className?: string;\n}\n\nconst DEFAULT_MESSAGES: PennantMessage[] = [\n  {\n    badge: \"New\",\n    text: \"Workflows 2.0 is here: branch, retry and schedule any step.\",\n    link: { label: \"See what's new\", href: \"#\" },\n  },\n  {\n    badge: \"Offer\",\n    text: \"Early-bird pricing ends in\",\n    endsIn: (2 * 24 * 60 + 14 * 60 + 7) * 60_000 + 31_000,\n    link: { label: \"Claim 30% off\", href: \"#\" },\n  },\n  {\n    badge: \"Live\",\n    text: \"Join Thursday's product walkthrough with the team.\",\n    link: { label: \"Save a seat\", href: \"#\" },\n  },\n];\n\nfunction toTime(v: Date | number | string | undefined): number | null {\n  if (v === undefined) return null;\n  const t = v instanceof Date ? v.getTime() : typeof v === \"number\" ? v : Date.parse(v);\n  return Number.isFinite(t) ? t : null;\n}\n\n/** One odometer digit: the new value rolls down in from above. */\nfunction RollDigit({ digit, reduced }: { digit: string; reduced: boolean }) {\n  return (\n    <span className=\"relative inline-flex h-[1.3em] w-[1ch] justify-center overflow-hidden\">\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        <motion.span\n          key={digit}\n          className=\"block leading-[1.3em]\"\n          initial={reduced ? { opacity: 0 } : { y: \"-100%\", opacity: 0 }}\n          animate={{ y: \"0%\", opacity: 1 }}\n          exit={reduced ? { opacity: 0 } : { y: \"100%\", opacity: 0 }}\n          transition={reduced ? { duration: 0.15 } : { type: \"spring\", stiffness: 520, damping: 40 }}\n        >\n          {digit}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\nfunction Countdown({ target, solid, reduced }: { target: number; solid: boolean; reduced: boolean }) {\n  const [now, setNow] = React.useState<number | null>(null);\n\n  React.useEffect(() => {\n    let timer = 0;\n    const tick = () => {\n      const t = Date.now();\n      setNow(t);\n      if (t < target) timer = window.setTimeout(tick, 1000 - (t % 1000) + 8);\n    };\n    tick();\n    return () => window.clearTimeout(timer);\n  }, [target]);\n\n  const left = Math.max(0, now === null ? 0 : target - now);\n  const s = Math.floor(left / 1000);\n  const parts: [string, string, string][] = [\n    [\"d\", \"days\", String(Math.min(99, Math.floor(s / 86400))).padStart(2, \"0\")],\n    [\"h\", \"hours\", String(Math.floor((s % 86400) / 3600)).padStart(2, \"0\")],\n    [\"m\", \"minutes\", String(Math.floor((s % 3600) / 60)).padStart(2, \"0\")],\n    [\"s\", \"seconds\", String(s % 60).padStart(2, \"0\")],\n  ];\n  const spoken =\n    now === null ? \"\" : parts.slice(0, 3).map(([, unit, v]) => `${Number(v)} ${unit}`).join(\", \") + \" left\";\n\n  return (\n    <span\n      role=\"timer\"\n      aria-label={spoken}\n      className={cn(\n        \"inline-flex shrink-0 items-center gap-1 font-mono text-[12px] font-medium tabular-nums\",\n        now === null && \"opacity-0\"\n      )}\n    >\n      {parts.map(([u, , v]) => (\n        <span\n          key={u}\n          aria-hidden\n          className={cn(\n            \"inline-flex items-baseline rounded-[5px] px-1 ring-1 ring-inset\",\n            solid ? \"bg-black/15 ring-black/10\" : \"bg-white/[0.06] text-white ring-white/[0.08]\"\n          )}\n        >\n          {v.split(\"\").map((d, i) => (\n            <RollDigit key={i} digit={d} reduced={reduced} />\n          ))}\n          <span className={cn(\"ml-px text-[10px]\", solid ? \"opacity-60\" : \"text-white/40\")}>{u}</span>\n        </span>\n      ))}\n    </span>\n  );\n}\n\n/**\n * Pennant — a slim top-of-page announcement bar. Rotates short messages with a\n * vertical slide (paused while hovered or focused, with a hairline progress\n * meter), rolls an odometer countdown when a message has a deadline, and\n * collapses on a height spring when dismissed — remembering it via\n * `storageKey`. Under reduced motion messages crossfade and only change on\n * demand.\n */\nexport function Pennant({\n  messages,\n  text,\n  link,\n  badge,\n  endsAt,\n  interval = 6000,\n  dismissible = true,\n  storageKey,\n  appearance = \"subtle\",\n  accentColor = DEFAULT_ACCENT,\n  label = \"Announcement\",\n  onDismiss,\n  onMessageChange,\n  ref,\n  className,\n  style,\n  ...rest\n}: PennantProps) {\n  const reduced = useReducedMotion();\n  const solid = appearance === \"solid\";\n  const ink = readableOn(accentColor);\n\n  const list = React.useMemo<PennantMessage[]>(() => {\n    if (messages && messages.length) return messages;\n    if (text !== undefined) return [{ text, link, badge, endsAt }];\n    return DEFAULT_MESSAGES;\n  }, [messages, text, link, badge, endsAt]);\n\n  // Hidden until mounted when persisting, so a stored dismissal never flashes.\n  const [visible, setVisible] = React.useState(!storageKey);\n  const [introKey, setIntroKey] = React.useState(0);\n  const [index, setIndex] = React.useState(0);\n  const [dir, setDir] = React.useState<1 | -1>(1);\n  const [hovered, setHovered] = React.useState(false);\n  const [focused, setFocused] = React.useState(false);\n  const [onscreen, setOnscreen] = React.useState(true);\n  const [mountedAt, setMountedAt] = React.useState<number | null>(null);\n  const rootRef = React.useRef<HTMLDivElement>(null);\n\n  React.useEffect(() => {\n    const raf = requestAnimationFrame(() => {\n      setMountedAt(Date.now());\n      if (storageKey) setVisible(storageGet(storageKey) !== \"dismissed\");\n    });\n    return () => cancelAnimationFrame(raf);\n  }, [storageKey]);\n\n  React.useEffect(() => {\n    const el = rootRef.current;\n    if (!el || typeof IntersectionObserver === \"undefined\") return;\n    const io = new IntersectionObserver(([e]) => setOnscreen(e.isIntersecting));\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  const count = list.length;\n  const current = Math.min(index, count - 1);\n  const rotating = count > 1 && !reduced;\n  const paused = hovered || focused || !onscreen;\n\n  const go = React.useCallback(\n    (step: 1 | -1) => {\n      if (count < 2) return;\n      setDir(step);\n      setIndex((i) => {\n        const n = (Math.min(i, count - 1) + step + count) % count;\n        onMessageChange?.(n);\n        return n;\n      });\n    },\n    [count, onMessageChange]\n  );\n\n  const dismiss = React.useCallback(() => {\n    setVisible(false);\n    storageSet(storageKey, \"dismissed\");\n    onDismiss?.();\n  }, [storageKey, onDismiss]);\n\n  React.useImperativeHandle(\n    ref,\n    () => ({\n      show: () => {\n        storageSet(storageKey, null);\n        setVisible(true);\n        setIntroKey((k) => k + 1);\n      },\n      dismiss,\n      replay: () => setIntroKey((k) => k + 1),\n      next: () => go(1),\n      prev: () => go(-1),\n    }),\n    [storageKey, dismiss, go]\n  );\n\n  const msg = list[current];\n  const target =\n    toTime(msg.endsAt) ?? (msg.endsIn !== undefined && mountedAt !== null ? mountedAt + msg.endsIn : null);\n\n  const slide = reduced\n    ? { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } }\n    : {\n        initial: { y: dir > 0 ? \"70%\" : \"-70%\", opacity: 0, filter: \"blur(2px)\" },\n        animate: { y: \"0%\", opacity: 1, filter: \"blur(0px)\" },\n        exit: { y: dir > 0 ? \"-70%\" : \"70%\", opacity: 0, filter: \"blur(2px)\" },\n      };\n\n  const ctrlBtn = cn(\n    \"grid size-7 shrink-0 place-items-center rounded-md transition-colors\",\n    FOCUS_RING,\n    solid ? \"opacity-70 hover:bg-black/10 hover:opacity-100\" : \"text-white/45 hover:bg-white/[0.06] hover:text-white\"\n  );\n\n  return (\n    <AnimatePresence initial={!reduced}>\n      {visible && (\n        <motion.div\n          key=\"pennant\"\n          {...(rest as Omit<typeof rest, \"onDrag\" | \"onDragStart\" | \"onDragEnd\" | \"onAnimationStart\">)}\n          ref={rootRef}\n          role=\"region\"\n          aria-label={label}\n          initial={{ height: 0, opacity: 0 }}\n          animate={{ height: \"auto\", opacity: 1 }}\n          exit={{ height: 0, opacity: 0 }}\n          transition={reduced ? { duration: 0.2 } : HEIGHT_SPRING}\n          onPointerEnter={(e) => e.pointerType === \"mouse\" && setHovered(true)}\n          onPointerLeave={() => setHovered(false)}\n          onFocus={() => setFocused(true)}\n          onBlur={(e) => {\n            if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setFocused(false);\n          }}\n          className={cn(\"@container relative w-full overflow-hidden\", className)}\n          style={\n            {\n              \"--pn-accent\": accentColor,\n              background: solid ? accentColor : undefined,\n              color: solid ? ink : undefined,\n              ...style,\n            } as React.CSSProperties\n          }\n        >\n          {!solid && (\n            <>\n              <div aria-hidden className=\"absolute inset-0 bg-neutral-950\" />\n              <div\n                aria-hidden\n                className=\"absolute inset-0\"\n                style={{\n                  background: `radial-gradient(60% 140% at 50% 0%, color-mix(in oklab, ${accentColor} 16%, transparent), transparent 70%)`,\n                }}\n              />\n              <div\n                aria-hidden\n                className=\"absolute inset-x-0 bottom-0 h-px\"\n                style={{\n                  background: `linear-gradient(90deg, rgba(255,255,255,0.06), color-mix(in oklab, ${accentColor} 55%, transparent) 50%, rgba(255,255,255,0.06))`,\n                }}\n              />\n            </>\n          )}\n\n          <motion.div\n            key={introKey}\n            initial={reduced ? { opacity: 0 } : { opacity: 0, y: -6 }}\n            animate={{ opacity: 1, y: 0 }}\n            transition={reduced ? { duration: 0.2 } : { duration: 0.5, ease: EASE, delay: 0.12 }}\n            className=\"relative flex min-h-11 items-center gap-2 px-2 @lg:px-3\"\n          >\n            {/* Left spacer mirrors the controls so the message stays optically centred. */}\n            <div aria-hidden className={cn(\"shrink-0\", count > 1 ? \"w-7 @2xl:w-[4.25rem]\" : \"w-7\", !dismissible && count < 2 && \"w-0\")} />\n\n            <div\n              className=\"relative grid min-w-0 flex-1 place-items-center overflow-hidden py-2\"\n              aria-roledescription={count > 1 ? \"carousel\" : undefined}\n            >\n              <AnimatePresence initial={false} mode=\"popLayout\" custom={dir}>\n                <motion.div\n                  key={current}\n                  aria-roledescription={count > 1 ? \"slide\" : undefined}\n                  aria-label={count > 1 ? `${current + 1} of ${count}` : undefined}\n                  initial={slide.initial}\n                  animate={slide.animate}\n                  exit={slide.exit}\n                  transition={reduced ? { duration: 0.2 } : { type: \"spring\", stiffness: 380, damping: 36 }}\n                  className=\"flex min-w-0 flex-wrap items-center justify-center gap-x-2.5 gap-y-1 text-center text-[12.5px] leading-snug @lg:text-[13px]\"\n                >\n                  {msg.badge && (\n                    <span\n                      className=\"hidden shrink-0 rounded-full px-2 py-px text-[10.5px] font-semibold uppercase tracking-[0.08em] @md:inline-block\"\n                      style={\n                        solid\n                          ? { background: \"rgba(0,0,0,0.14)\" }\n                          : {\n                              color: accentColor,\n                              background: `color-mix(in oklab, ${accentColor} 14%, transparent)`,\n                              boxShadow: `inset 0 0 0 1px color-mix(in oklab, ${accentColor} 30%, transparent)`,\n                            }\n                      }\n                    >\n                      {msg.badge}\n                    </span>\n                  )}\n                  <span className={cn(\"font-medium\", solid ? \"\" : \"text-white/80\")}>{msg.text}</span>\n                  {target !== null && <Countdown target={target} solid={solid} reduced={reduced} />}\n                  {msg.link && (\n                    <a\n                      href={msg.link.href}\n                      className={cn(\n                        \"group/link inline-flex shrink-0 items-center gap-1 rounded font-semibold underline-offset-4 hover:underline\",\n                        FOCUS_RING\n                      )}\n                      style={solid ? undefined : { color: accentColor }}\n                    >\n                      {msg.link.label}\n                      <svg\n                        aria-hidden\n                        viewBox=\"0 0 16 16\"\n                        className=\"size-3.5 transition-transform duration-200 group-hover/link:translate-x-0.5\"\n                        fill=\"none\"\n                      >\n                        <path d=\"M3 8h9m0 0L8.5 4.5M12 8l-3.5 3.5\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n                      </svg>\n                    </a>\n                  )}\n                </motion.div>\n              </AnimatePresence>\n            </div>\n\n            <div className=\"flex shrink-0 items-center gap-0.5\">\n              {count > 1 && (\n                <div className=\"hidden items-center gap-0.5 @2xl:flex\">\n                  <button type=\"button\" aria-label=\"Previous announcement\" onClick={() => go(-1)} className={ctrlBtn}>\n                    <svg aria-hidden viewBox=\"0 0 16 16\" className=\"size-3.5\" fill=\"none\">\n                      <path d=\"M10 3.5 5.5 8l4.5 4.5\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n                    </svg>\n                  </button>\n                  <button type=\"button\" aria-label=\"Next announcement\" onClick={() => go(1)} className={ctrlBtn}>\n                    <svg aria-hidden viewBox=\"0 0 16 16\" className=\"size-3.5\" fill=\"none\">\n                      <path d=\"M6 3.5 10.5 8 6 12.5\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n                    </svg>\n                  </button>\n                </div>\n              )}\n              {count > 1 && (\n                <button type=\"button\" aria-label=\"Next announcement\" onClick={() => go(1)} className={cn(ctrlBtn, \"@2xl:hidden\", dismissible && \"hidden\")}>\n                  <svg aria-hidden viewBox=\"0 0 16 16\" className=\"size-3.5\" fill=\"none\">\n                    <path d=\"M6 3.5 10.5 8 6 12.5\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n                  </svg>\n                </button>\n              )}\n              {dismissible && (\n                <button type=\"button\" aria-label=\"Dismiss announcement\" onClick={dismiss} className={ctrlBtn}>\n                  <svg aria-hidden viewBox=\"0 0 16 16\" className=\"size-3.5\" fill=\"none\">\n                    <path d=\"m4.5 4.5 7 7m0-7-7 7\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n                  </svg>\n                </button>\n              )}\n            </div>\n          </motion.div>\n\n          {/* Rotation meter: a hairline that fills over `interval`; its end advances the message. */}\n          {rotating && (\n            <div aria-hidden className=\"absolute inset-x-0 bottom-0 h-px\">\n              <div\n                key={`${current}-${introKey}`}\n                className=\"h-full origin-left\"\n                onAnimationEnd={() => go(1)}\n                style={{\n                  background: solid ? \"currentColor\" : accentColor,\n                  opacity: solid ? 0.35 : 0.9,\n                  animation: `pennant-meter ${interval}ms linear forwards`,\n                  animationPlayState: paused ? \"paused\" : \"running\",\n                }}\n              />\n              <style>{`@keyframes pennant-meter{from{transform:scaleX(0)}to{transform:scaleX(1)}}`}</style>\n            </div>\n          )}\n        </motion.div>\n      )}\n    </AnimatePresence>\n  );\n}\n\n/* ================================================================ Consent */\n\n/** The four consent categories. `necessary` is always `true`. */\nexport interface ConsentPreferences {\n  /** Strictly necessary cookies — always on. */\n  necessary: true;\n  /** Usage measurement. */\n  analytics: boolean;\n  /** Ads and attribution. */\n  marketing: boolean;\n  /** Remembered settings such as language or theme. */\n  preferences: boolean;\n}\n\nexport type ConsentCategory = Exclude<keyof ConsentPreferences, \"necessary\">;\n\nexport interface ConsentCategoryCopy {\n  /** Switch label. */\n  label: string;\n  /** One-line description under the label. */\n  description: string;\n}\n\n/** Imperative verbs exposed through the `ref` prop. */\nexport interface ConsentHandle {\n  /** Open the card (expanded to the saved choices if a decision exists) and move focus into it. */\n  open: () => void;\n  /** Close the card without recording a decision. */\n  close: () => void;\n  /** Forget the stored decision, restore default switches and reopen collapsed. */\n  reset: () => void;\n}\n\nexport interface ConsentProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\" | \"title\"> {\n  /** Controlled visibility. Pair with `onOpenChange`. */\n  open?: boolean;\n  /**\n   * Uncontrolled initial visibility. Omit to open automatically only when no\n   * decision is stored under `storageKey`.\n   */\n  defaultOpen?: boolean;\n  /** Called whenever the card asks to open or close. */\n  onOpenChange?: (open: boolean) => void;\n  /**\n   * Called with the final choices. Return a Promise to hold the pressed\n   * button in a pending state; a rejection shows its message inline and keeps\n   * the card open.\n   */\n  onDecision?: (preferences: ConsentPreferences) => void | Promise<unknown>;\n  /** localStorage key that remembers the decision (JSON). Omit to never persist. */\n  storageKey?: string;\n  /** Heading. @default \"We value your privacy\" */\n  title?: React.ReactNode;\n  /** Short body copy under the heading. */\n  description?: React.ReactNode;\n  /** Optional \"Cookie policy\" link appended to the copy. */\n  policyHref?: string;\n  /** Override labels and descriptions per category. */\n  categories?: Partial<Record<keyof ConsentPreferences, Partial<ConsentCategoryCopy>>>;\n  /** Initial switch values for the optional categories. @default all off */\n  defaultPreferences?: Partial<Record<ConsentCategory, boolean>>;\n  /** Which bottom corner the card rises into (≥640px). @default \"left\" */\n  side?: \"left\" | \"right\";\n  /**\n   * `\"fixed\"` pins to the viewport; `\"absolute\"` pins to the nearest\n   * positioned ancestor (previews, mock frames). @default \"fixed\"\n   */\n  strategy?: \"fixed\" | \"absolute\";\n  /** Seconds before an auto-open card rises in. @default 0.6 */\n  delay?: number;\n  /** Accent hex for the primary button, switches and focus rings. @default \"#818cf8\" */\n  accentColor?: string;\n  /** Imperative handle (`open`, `close`, `reset`). React 19 ref-as-prop. */\n  ref?: React.Ref<ConsentHandle>;\n  /** Extra classes for the card. */\n  className?: string;\n}\n\nconst CATEGORY_ORDER: (keyof ConsentPreferences)[] = [\"necessary\", \"analytics\", \"marketing\", \"preferences\"];\n\nconst CATEGORY_COPY: Record<keyof ConsentPreferences, ConsentCategoryCopy> = {\n  necessary: { label: \"Necessary\", description: \"Sign-in, security and load balancing. The site can't work without these.\" },\n  analytics: { label: \"Analytics\", description: \"Anonymous usage counts that show us which pages help and which don't.\" },\n  marketing: { label: \"Marketing\", description: \"Measures campaigns and limits how often you see the same ad elsewhere.\" },\n  preferences: { label: \"Preferences\", description: \"Remembers choices like language, region and theme between visits.\" },\n};\n\ntype Pending = \"accept\" | \"reject\" | \"save\" | null;\n\nfunction readStored(key: string | undefined): ConsentPreferences | null {\n  const raw = storageGet(key);\n  if (!raw) return null;\n  try {\n    const p = JSON.parse(raw) as { prefs?: Partial<ConsentPreferences> };\n    if (!p.prefs) return null;\n    return {\n      necessary: true,\n      analytics: !!p.prefs.analytics,\n      marketing: !!p.prefs.marketing,\n      preferences: !!p.prefs.preferences,\n    };\n  } catch {\n    return null;\n  }\n}\n\nfunction Switch({\n  checked,\n  locked,\n  onChange,\n  labelId,\n  descId,\n  reduced,\n}: {\n  checked: boolean;\n  locked?: boolean;\n  onChange: (v: boolean) => void;\n  labelId: string;\n  descId: string;\n  reduced: boolean;\n}) {\n  return (\n    <button\n      type=\"button\"\n      role=\"switch\"\n      aria-checked={checked}\n      aria-disabled={locked || undefined}\n      aria-labelledby={labelId}\n      aria-describedby={descId}\n      onClick={() => !locked && onChange(!checked)}\n      className={cn(\n        \"relative inline-flex h-5 w-9 shrink-0 items-center rounded-full p-0.5 transition-colors duration-200\",\n        FOCUS_RING,\n        locked ? \"cursor-not-allowed opacity-60\" : \"cursor-pointer\",\n        checked ? \"\" : \"bg-white/[0.12] hover:bg-white/[0.16]\"\n      )}\n      style={checked ? { background: \"var(--pn-accent)\" } : undefined}\n    >\n      <motion.span\n        aria-hidden\n        className=\"block size-4 rounded-full shadow-[0_1px_2px_rgba(0,0,0,0.4)]\"\n        style={{ background: checked ? \"var(--pn-ink)\" : \"#e5e5e5\" }}\n        animate={{ x: checked ? 16 : 0 }}\n        transition={reduced ? INSTANT : { type: \"spring\", stiffness: 700, damping: 38 }}\n      />\n    </button>\n  );\n}\n\nfunction Spinner() {\n  return (\n    <svg aria-hidden viewBox=\"0 0 16 16\" className=\"size-3.5 animate-spin motion-reduce:animate-none\" fill=\"none\">\n      <circle cx=\"8\" cy=\"8\" r=\"6\" stroke=\"currentColor\" strokeOpacity=\"0.25\" strokeWidth=\"2\" />\n      <path d=\"M14 8a6 6 0 0 0-6-6\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n\n/**\n * Consent — a cookie-consent card that rises into a bottom corner (a\n * full-width bar under 640px). \"Customize\" grows the same card into\n * per-category switches instead of opening a second modal. Non-modal dialog:\n * the page stays usable, Escape folds the details away, and opening it via\n * the ref (e.g. a footer \"Cookie settings\" link) moves focus into it and\n * returns focus when it closes.\n */\nexport function Consent({\n  open: openProp,\n  defaultOpen,\n  onOpenChange,\n  onDecision,\n  storageKey,\n  title = \"We value your privacy\",\n  description = \"We use cookies to keep the site secure, understand what's working and personalise what you see. Choose what you're comfortable with.\",\n  policyHref,\n  categories,\n  defaultPreferences,\n  side = \"left\",\n  strategy = \"fixed\",\n  delay = 0.6,\n  accentColor = DEFAULT_ACCENT,\n  ref,\n  className,\n  style,\n  ...rest\n}: ConsentProps) {\n  const reduced = useReducedMotion();\n  const ink = readableOn(accentColor);\n  const uid = React.useId();\n  const controlled = openProp !== undefined;\n\n  const initialPrefs = React.useCallback(\n    (): Omit<ConsentPreferences, \"necessary\"> => ({\n      analytics: !!defaultPreferences?.analytics,\n      marketing: !!defaultPreferences?.marketing,\n      preferences: !!defaultPreferences?.preferences,\n    }),\n    [defaultPreferences]\n  );\n\n  const [innerOpen, setInnerOpen] = React.useState(false);\n  const [expanded, setExpanded] = React.useState(false);\n  const [prefs, setPrefs] = React.useState(initialPrefs);\n  const [pending, setPending] = React.useState<Pending>(null);\n  const [error, setError] = React.useState<string | null>(null);\n  const [announce, setAnnounce] = React.useState(\"\");\n  const [autoDelay, setAutoDelay] = React.useState(true);\n\n  const isOpen = controlled ? !!openProp : innerOpen;\n  const cardRef = React.useRef<HTMLDivElement>(null);\n  const returnFocus = React.useRef<HTMLElement | null>(null);\n  const wantFocus = React.useRef(false);\n  const focusSwitch = React.useRef(false);\n  const decided = React.useRef(false);\n\n  // \"Customize\" unmounts itself — hand focus to the first optional switch.\n  React.useEffect(() => {\n    if (!expanded || !focusSwitch.current) return;\n    focusSwitch.current = false;\n    cardRef.current?.querySelector<HTMLElement>('[role=\"switch\"]:not([aria-disabled])')?.focus({ preventScroll: true });\n  }, [expanded]);\n\n  // Uncontrolled: decide on mount whether to show (never during SSR).\n  React.useEffect(() => {\n    const raf = requestAnimationFrame(() => {\n      const stored = readStored(storageKey);\n      if (stored) setPrefs({ analytics: stored.analytics, marketing: stored.marketing, preferences: stored.preferences });\n      if (!controlled) setInnerOpen(defaultOpen ?? !stored);\n    });\n    return () => cancelAnimationFrame(raf);\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [storageKey]);\n\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (!controlled) setInnerOpen(next);\n      onOpenChange?.(next);\n    },\n    [controlled, onOpenChange]\n  );\n\n  // Restore focus to wherever it came from when the card closes with focus inside.\n  const closeCard = React.useCallback(() => {\n    const card = cardRef.current;\n    if (card && card.contains(document.activeElement) && returnFocus.current?.isConnected) {\n      returnFocus.current.focus();\n    }\n    returnFocus.current = null;\n    setOpen(false);\n  }, [setOpen]);\n\n  const openCard = React.useCallback(\n    (opts: { expand: boolean }) => {\n      const active = document.activeElement;\n      if (active instanceof HTMLElement && !cardRef.current?.contains(active)) returnFocus.current = active;\n      wantFocus.current = true;\n      setAutoDelay(false);\n      setError(null);\n      setPending(null);\n      setExpanded(opts.expand);\n      setOpen(true);\n      if (cardRef.current) {\n        requestAnimationFrame(() => cardRef.current?.focus({ preventScroll: true }));\n        wantFocus.current = false;\n      }\n    },\n    [setOpen]\n  );\n\n  React.useImperativeHandle(\n    ref,\n    () => ({\n      open: () => {\n        const stored = readStored(storageKey);\n        if (stored) setPrefs({ analytics: stored.analytics, marketing: stored.marketing, preferences: stored.preferences });\n        openCard({ expand: !!stored || decided.current });\n      },\n      close: closeCard,\n      reset: () => {\n        decided.current = false;\n        storageSet(storageKey, null);\n        setPrefs(initialPrefs());\n        openCard({ expand: false });\n      },\n    }),\n    [storageKey, openCard, closeCard, initialPrefs]\n  );\n\n  const decide = async (kind: Exclude<Pending, null>) => {\n    if (pending) return;\n    const chosen: ConsentPreferences =\n      kind === \"accept\"\n        ? { necessary: true, analytics: true, marketing: true, preferences: true }\n        : kind === \"reject\"\n          ? { necessary: true, analytics: false, marketing: false, preferences: false }\n          : { necessary: true, ...prefs };\n    setError(null);\n    try {\n      const result = onDecision?.(chosen);\n      if (result && typeof (result as Promise<unknown>).then === \"function\") {\n        setPending(kind);\n        await result;\n      }\n    } catch (e) {\n      setPending(null);\n      setError(e instanceof Error && e.message ? e.message : \"Couldn't save your choices. Please try again.\");\n      return;\n    }\n    setPending(null);\n    decided.current = true;\n    setPrefs({ analytics: chosen.analytics, marketing: chosen.marketing, preferences: chosen.preferences });\n    storageSet(storageKey, JSON.stringify({ v: 1, prefs: chosen, at: new Date().toISOString() }));\n    setAnnounce(\n      kind === \"accept\" ? \"All cookies accepted.\" : kind === \"reject\" ? \"Optional cookies rejected.\" : \"Cookie choices saved.\"\n    );\n    closeCard();\n  };\n\n  const copy = (k: keyof ConsentPreferences): ConsentCategoryCopy => ({ ...CATEGORY_COPY[k], ...categories?.[k] });\n\n  const enterDelay = autoDelay && !reduced ? delay : 0;\n  const btnBase =\n    \"relative inline-flex h-9 items-center justify-center gap-1.5 rounded-lg px-3.5 text-[13px] font-medium transition-[background-color,color,box-shadow,opacity] duration-150 disabled:cursor-default\";\n  const btnGhost = cn(btnBase, FOCUS_RING, \"text-white/70 hover:bg-white/[0.06] hover:text-white\");\n  const btnSecondary = cn(\n    btnBase,\n    FOCUS_RING,\n    \"bg-white/[0.06] text-white ring-1 ring-inset ring-white/[0.08] hover:bg-white/[0.1]\"\n  );\n  const btnPrimary = cn(btnBase, FOCUS_RING, \"shadow-[0_1px_0_rgba(255,255,255,0.25)_inset] hover:opacity-90\");\n  const busy = pending !== null;\n  const label = (kind: Exclude<Pending, null>, text: string) => (\n    <>\n      {pending === kind && <Spinner />}\n      {text}\n    </>\n  );\n\n  return (\n    <>\n      <span role=\"status\" className=\"sr-only\">\n        {announce}\n      </span>\n      <AnimatePresence>\n        {isOpen && (\n          <motion.div\n            key=\"consent\"\n            {...(rest as Omit<typeof rest, \"onDrag\" | \"onDragStart\" | \"onDragEnd\" | \"onAnimationStart\">)}\n            ref={(el: HTMLDivElement | null) => {\n              cardRef.current = el;\n              if (el && wantFocus.current) {\n                wantFocus.current = false;\n                requestAnimationFrame(() => el.focus({ preventScroll: true }));\n              }\n            }}\n            role=\"dialog\"\n            aria-modal=\"false\"\n            aria-labelledby={`${uid}-title`}\n            aria-describedby={`${uid}-desc`}\n            tabIndex={-1}\n            onKeyDown={(e) => {\n              if (e.key === \"Escape\" && expanded && !busy) {\n                e.stopPropagation();\n                setExpanded(false);\n                cardRef.current?.focus({ preventScroll: true });\n              }\n            }}\n            initial={reduced ? { opacity: 0 } : { opacity: 0, y: 28, scale: 0.98 }}\n            animate={{ opacity: 1, y: 0, scale: 1 }}\n            exit={reduced ? { opacity: 0 } : { opacity: 0, y: 18, scale: 0.98 }}\n            transition={\n              reduced\n                ? { duration: 0.2 }\n                : { ...RISE_SPRING, delay: enterDelay, opacity: { duration: 0.35, ease: EASE, delay: enterDelay } }\n            }\n            className={cn(\n              strategy === \"fixed\" ? \"fixed\" : \"absolute\",\n              \"z-50 flex flex-col overflow-hidden bg-neutral-900/95 text-white shadow-[0_24px_60px_-12px_rgba(0,0,0,0.7)] outline-none backdrop-blur-xl\",\n              \"inset-x-0 bottom-0 max-h-[85%] rounded-t-2xl border-t border-white/[0.08]\",\n              \"sm:inset-x-auto sm:bottom-4 sm:w-[min(400px,calc(100%-2rem))] sm:rounded-2xl sm:border\",\n              side === \"left\" ? \"sm:left-4\" : \"sm:right-4\",\n              strategy === \"fixed\" && \"max-h-[85vh]\",\n              className\n            )}\n            style={{ \"--pn-accent\": accentColor, \"--pn-ink\": ink, ...style } as React.CSSProperties}\n          >\n            {/* Accent hairline along the top edge. */}\n            <div\n              aria-hidden\n              className=\"pointer-events-none absolute inset-x-6 top-0 h-px\"\n              style={{ background: `linear-gradient(90deg, transparent, color-mix(in oklab, ${accentColor} 70%, transparent), transparent)` }}\n            />\n\n            <div className={cn(\"min-h-0 flex-1 overflow-y-auto overscroll-contain p-5\", expanded ? \"pb-4\" : \"pb-0\")}>\n              <div className=\"flex items-start gap-3\">\n                <span\n                  aria-hidden\n                  className=\"mt-0.5 grid size-8 shrink-0 place-items-center rounded-lg\"\n                  style={{\n                    color: accentColor,\n                    background: `color-mix(in oklab, ${accentColor} 13%, transparent)`,\n                    boxShadow: `inset 0 0 0 1px color-mix(in oklab, ${accentColor} 26%, transparent)`,\n                  }}\n                >\n                  <svg viewBox=\"0 0 20 20\" className=\"size-4\" fill=\"none\">\n                    <path\n                      d=\"M10 2.75a7.25 7.25 0 1 0 7.2 6.4 2.4 2.4 0 0 1-3.1-2.2 2.4 2.4 0 0 1-2.85-2.85 2.4 2.4 0 0 1-1.25-1.35Z\"\n                      stroke=\"currentColor\"\n                      strokeWidth=\"1.5\"\n                      strokeLinejoin=\"round\"\n                    />\n                    <circle cx=\"7.25\" cy=\"9\" r=\"1\" fill=\"currentColor\" />\n                    <circle cx=\"11\" cy=\"12.75\" r=\"1\" fill=\"currentColor\" />\n                    <circle cx=\"7.5\" cy=\"13\" r=\"0.75\" fill=\"currentColor\" />\n                  </svg>\n                </span>\n                <div className=\"min-w-0\">\n                  <h2 id={`${uid}-title`} className=\"text-[15px] font-semibold tracking-tight text-white\">\n                    {title}\n                  </h2>\n                  <p id={`${uid}-desc`} className=\"mt-1 text-[13px] leading-relaxed text-white/55\">\n                    {description}\n                    {policyHref && (\n                      <>\n                        {\" \"}\n                        <a\n                          href={policyHref}\n                          className={cn(\"rounded font-medium text-white/80 underline decoration-white/25 underline-offset-4 hover:text-white\", FOCUS_RING)}\n                        >\n                          Cookie policy\n                        </a>\n                      </>\n                    )}\n                  </p>\n                </div>\n              </div>\n\n              <AnimatePresence initial={false}>\n                {expanded && (\n                  <motion.div\n                    key=\"details\"\n                    initial={{ height: 0, opacity: 0 }}\n                    animate={{ height: \"auto\", opacity: 1 }}\n                    exit={{ height: 0, opacity: 0 }}\n                    transition={reduced ? { duration: 0.15 } : { height: HEIGHT_SPRING, opacity: { duration: 0.25, ease: EASE } }}\n                    className=\"overflow-hidden\"\n                  >\n                    <ul\n                      aria-label=\"Cookie categories\"\n                      className=\"mt-4 divide-y divide-white/[0.06] rounded-xl border border-white/[0.07] bg-white/[0.02]\"\n                    >\n                      {CATEGORY_ORDER.map((k, i) => {\n                        const c = copy(k);\n                        const locked = k === \"necessary\";\n                        const checked = locked ? true : prefs[k as ConsentCategory];\n                        return (\n                          <motion.li\n                            key={k}\n                            initial={reduced ? false : { opacity: 0, y: 6 }}\n                            animate={{ opacity: 1, y: 0 }}\n                            transition={reduced ? INSTANT : { duration: 0.35, ease: EASE, delay: 0.05 + i * 0.045 }}\n                            className=\"flex items-start gap-3 px-3.5 py-3\"\n                          >\n                            <div className=\"min-w-0 flex-1\">\n                              <div className=\"flex items-center gap-2\">\n                                <span id={`${uid}-${k}-l`} className=\"text-[13px] font-medium text-white\">\n                                  {c.label}\n                                </span>\n                                {locked && (\n                                  <span className=\"rounded-full bg-white/[0.06] px-1.5 py-px text-[10px] font-medium uppercase tracking-[0.06em] text-white/45\">\n                                    Always on\n                                  </span>\n                                )}\n                              </div>\n                              <p id={`${uid}-${k}-d`} className=\"mt-0.5 text-[12px] leading-relaxed text-white/45\">\n                                {c.description}\n                              </p>\n                            </div>\n                            <div className=\"pt-0.5\">\n                              <Switch\n                                checked={checked}\n                                locked={locked}\n                                labelId={`${uid}-${k}-l`}\n                                descId={`${uid}-${k}-d`}\n                                reduced={reduced}\n                                onChange={(v) => setPrefs((p) => ({ ...p, [k]: v }))}\n                              />\n                            </div>\n                          </motion.li>\n                        );\n                      })}\n                    </ul>\n                  </motion.div>\n                )}\n              </AnimatePresence>\n\n              <AnimatePresence initial={false}>\n                {error && (\n                  <motion.p\n                    key=\"err\"\n                    role=\"alert\"\n                    initial={{ opacity: 0, height: 0 }}\n                    animate={{ opacity: 1, height: \"auto\" }}\n                    exit={{ opacity: 0, height: 0 }}\n                    transition={reduced ? INSTANT : { duration: 0.25, ease: EASE }}\n                    className=\"overflow-hidden text-[12px] text-rose-300\"\n                  >\n                    <span className=\"block pt-3\">{error}</span>\n                  </motion.p>\n                )}\n              </AnimatePresence>\n            </div>\n\n            <div className={cn(\"flex flex-wrap items-center gap-2 p-5 pt-4\", expanded && \"border-t border-white/[0.06] pt-4\")}>\n              {expanded ? (\n                <>\n                  <button type=\"button\" className={cn(btnGhost, \"-ml-2\")} disabled={busy} onClick={() => decide(\"reject\")}>\n                    {label(\"reject\", \"Reject all\")}\n                  </button>\n                  <div className=\"ml-auto flex gap-2\">\n                    <button type=\"button\" className={btnSecondary} disabled={busy} onClick={() => decide(\"accept\")}>\n                      {label(\"accept\", \"Accept all\")}\n                    </button>\n                    <button\n                      type=\"button\"\n                      className={btnPrimary}\n                      style={{ background: accentColor, color: ink }}\n                      disabled={busy}\n                      onClick={() => decide(\"save\")}\n                    >\n                      {label(\"save\", \"Save choices\")}\n                    </button>\n                  </div>\n                </>\n              ) : (\n                <>\n                  <button\n                    type=\"button\"\n                    className={cn(btnGhost, \"-ml-2\")}\n                    aria-expanded={false}\n                    disabled={busy}\n                    onClick={() => {\n                      focusSwitch.current = true;\n                      setExpanded(true);\n                    }}\n                  >\n                    Customize\n                  </button>\n                  <div className=\"ml-auto flex gap-2\">\n                    <button type=\"button\" className={btnSecondary} disabled={busy} onClick={() => decide(\"reject\")}>\n                      {label(\"reject\", \"Reject all\")}\n                    </button>\n                    <button\n                      type=\"button\"\n                      className={btnPrimary}\n                      style={{ background: accentColor, color: ink }}\n                      disabled={busy}\n                      onClick={() => decide(\"accept\")}\n                    >\n                      {label(\"accept\", \"Accept all\")}\n                    </button>\n                  </div>\n                </>\n              )}\n            </div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </>\n  );\n}\n"
    }
  ]
}