{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "phosphor",
  "type": "registry:ui",
  "title": "Phosphor",
  "description": "A themed panel styled as a monochrome CRT monitor: a dark vignetted screen with glowing selectable monospace text, fine scanlines, a slow refresh-bar roll, and a blinking block caret. The built-in switcher recoats the tube between amber, green, and paper-white phosphor. Pure CSS; reduced motion holds a steady glow.",
  "dependencies": [],
  "registryDependencies": [
    "https://crucibleui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/default/themes/phosphor/phosphor.tsx",
      "type": "registry:ui",
      "target": "components/crucible/phosphor.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\nimport { cn } from \"@/lib/utils\";\n\n/** The three phosphor coatings a monochrome CRT could be built with. */\nexport type PhosphorColor = \"amber\" | \"green\" | \"white\";\n\nexport interface PhosphorProps\n  extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"color\"> {\n  /** Controlled phosphor coating. Pair with `onPhosphorChange`. */\n  phosphor?: PhosphorColor;\n  /** Initial phosphor when uncontrolled. @default \"amber\" */\n  defaultPhosphor?: PhosphorColor;\n  /** Fires with the next coating whenever the switcher changes it. */\n  onPhosphorChange?: (phosphor: PhosphorColor) => void;\n  /** Render the built-in amber / green / white switcher strip. @default true */\n  switcher?: boolean;\n  /** Terminal content. Falls back to a boot readout when omitted. */\n  children?: React.ReactNode;\n  /** Show the blinking block caret after the content. @default true */\n  caret?: boolean;\n  /** Scanline + vignette strength, 0–1. @default 1 */\n  intensity?: number;\n  /** Blink / flicker / roll rate multiplier. @default 1 */\n  speed?: number;\n  /** Freeze all motion — steady glow, solid caret, no flicker. @default false */\n  paused?: boolean;\n  /** Override the three phosphor text hues (any CSS hex color). */\n  colors?: Partial<Record<PhosphorColor, string>>;\n  /** Accessible label for the switcher radiogroup. @default \"Phosphor coating\" */\n  switcherLabel?: string;\n}\n\nconst ORDER: PhosphorColor[] = [\"amber\", \"green\", \"white\"];\n\n/** Deliberately amber-first — the coating every terminal clone forgets exists. */\nconst DEFAULT_HUES: Record<PhosphorColor, string> = {\n  amber: \"#ffb000\",\n  green: \"#38ff7b\",\n  white: \"#eef2ff\",\n};\n\nconst LABELS: Record<PhosphorColor, string> = {\n  amber: \"Amber\",\n  green: \"Green\",\n  white: \"White\",\n};\n\n/** Default boot readout — generic terminal copy, no brand names. */\nconst DEFAULT_CONTENT = `PHOSPHOR TERMINAL  v1.0\nMEMORY ......... 64K OK\nDISPLAY ........ ONLINE\nREADY.\n> `;\n\n/** Parse a #rgb/#rrggbb hex into a space-separated \"r g b\" for modern rgb(). */\nfunction hexToRgbTriplet(hex: string): string {\n  const h = hex.replace(\"#\", \"\");\n  const full =\n    h.length === 3\n      ? h\n          .split(\"\")\n          .map((c) => c + c)\n          .join(\"\")\n      : h;\n  const n = Number.parseInt(full, 16);\n  if (Number.isNaN(n)) return \"255 176 0\";\n  return `${(n >> 16) & 255} ${(n >> 8) & 255} ${n & 255}`;\n}\n\n/**\n * Phosphor — a themed panel styled as a monochrome CRT monitor. A dark,\n * vignetted screen carries glowing selectable monospace text over fine\n * scanlines, a slow refresh bar rolls down the glass, and a hard block caret\n * blinks at the prompt. The built-in switcher recoats the tube between the\n * three classic phosphors — amber, green, and paper-white — driving one hue\n * through every layer via a CSS variable. All content is real, selectable\n * text; the effect layers are `aria-hidden` and never intercept the pointer.\n * Pure CSS. Reduced motion (or `paused`) holds a steady glow with a solid\n * caret and no flicker.\n */\nexport function Phosphor({\n  phosphor,\n  defaultPhosphor = \"amber\",\n  onPhosphorChange,\n  switcher = true,\n  children,\n  caret = true,\n  intensity = 1,\n  speed = 1,\n  paused = false,\n  colors,\n  switcherLabel = \"Phosphor coating\",\n  className,\n  style,\n  ...rest\n}: PhosphorProps) {\n  const reducedMotion = useReducedMotion();\n  const animate = !reducedMotion && !paused;\n\n  const isControlled = phosphor !== undefined;\n  const [internal, setInternal] = React.useState<PhosphorColor>(defaultPhosphor);\n  const active = isControlled ? phosphor : internal;\n\n  const hues = { ...DEFAULT_HUES, ...colors };\n  const hue = hues[active] ?? DEFAULT_HUES[active];\n  const rgb = hexToRgbTriplet(hue);\n\n  const i = Math.min(Math.max(intensity, 0), 1);\n  const spd = Math.min(Math.max(speed, 0.1), 4);\n\n  const radioRefs = React.useRef<(HTMLButtonElement | null)[]>([]);\n\n  const select = React.useCallback(\n    (next: PhosphorColor) => {\n      if (!isControlled) setInternal(next);\n      onPhosphorChange?.(next);\n    },\n    [isControlled, onPhosphorChange]\n  );\n\n  const handleRadioKey = React.useCallback(\n    (event: React.KeyboardEvent<HTMLButtonElement>, index: number) => {\n      let next = index;\n      switch (event.key) {\n        case \"ArrowRight\":\n        case \"ArrowDown\":\n          next = (index + 1) % ORDER.length;\n          break;\n        case \"ArrowLeft\":\n        case \"ArrowUp\":\n          next = (index - 1 + ORDER.length) % ORDER.length;\n          break;\n        case \"Home\":\n          next = 0;\n          break;\n        case \"End\":\n          next = ORDER.length - 1;\n          break;\n        default:\n          return;\n      }\n      event.preventDefault();\n      select(ORDER[next]);\n      radioRefs.current[next]?.focus();\n    },\n    [select]\n  );\n\n  return (\n    <div\n      data-crucible=\"phosphor\"\n      data-phosphor={active}\n      data-animate={animate ? \"on\" : \"off\"}\n      className={cn(\n        \"inline-flex flex-col overflow-hidden rounded-2xl\",\n        \"bg-neutral-900 p-2.5 shadow-[0_1px_0_rgba(255,255,255,0.05)_inset,0_20px_50px_-20px_rgba(0,0,0,0.9)]\",\n        \"ring-1 ring-white/5\",\n        className\n      )}\n      style={\n        {\n          \"--phos\": hue,\n          \"--phos-rgb\": rgb,\n          \"--phos-i\": i,\n          \"--phos-speed\": spd,\n          ...style,\n        } as React.CSSProperties\n      }\n      {...rest}\n    >\n      <style>{`\n        @keyframes crucible-phosphor-blink {\n          0%, 49.9% { opacity: 1; }\n          50%, 99.9% { opacity: 0; }\n        }\n        @keyframes crucible-phosphor-flicker {\n          0%, 100% { opacity: 0.5; }\n          8%   { opacity: 0.85; }\n          9%   { opacity: 0.35; }\n          20%  { opacity: 0.6; }\n          50%  { opacity: 1; }\n          52%  { opacity: 0.45; }\n          70%  { opacity: 0.7; }\n          88%  { opacity: 0.9; }\n        }\n        @keyframes crucible-phosphor-roll {\n          0%   { transform: translateY(-140%); }\n          100% { transform: translateY(140%); }\n        }\n        [data-crucible=\"phosphor\"] .cru-phos-caret {\n          animation: crucible-phosphor-blink calc(1.05s / var(--phos-speed, 1)) linear infinite;\n        }\n        [data-crucible=\"phosphor\"] .cru-phos-flicker {\n          animation: crucible-phosphor-flicker calc(5.5s / var(--phos-speed, 1)) linear infinite;\n        }\n        [data-crucible=\"phosphor\"] .cru-phos-bar {\n          animation: crucible-phosphor-roll calc(7s / var(--phos-speed, 1)) linear infinite;\n        }\n        [data-crucible=\"phosphor\"][data-animate=\"off\"] .cru-phos-caret,\n        [data-crucible=\"phosphor\"][data-animate=\"off\"] .cru-phos-flicker,\n        [data-crucible=\"phosphor\"][data-animate=\"off\"] .cru-phos-bar {\n          animation: none;\n        }\n      `}</style>\n\n      {/* The screen — a stacking context so the -z effect layers stay behind text. */}\n      <div\n        className=\"relative isolate min-h-[180px] min-w-[240px] overflow-hidden rounded-xl bg-black\"\n        style={{\n          backgroundImage: `radial-gradient(120% 100% at 50% 42%, rgb(var(--phos-rgb) / calc(0.12 * var(--phos-i))), transparent 62%)`,\n        }}\n      >\n        {/* Selectable terminal content. */}\n        <div className=\"relative z-10 h-full w-full p-5\">\n          <div\n            className=\"font-mono text-[13px] leading-relaxed whitespace-pre-wrap [word-break:break-word]\"\n            style={{\n              color: \"var(--phos)\",\n              textShadow:\n                \"0 0 1px currentColor, 0 0 6px rgb(var(--phos-rgb) / 0.55), 0 0 16px rgb(var(--phos-rgb) / 0.28)\",\n            }}\n          >\n            {children ?? DEFAULT_CONTENT}\n            {caret && (\n              <span\n                aria-hidden\n                className=\"cru-phos-caret ml-0.5 inline-block h-[1.05em] w-[0.6em] translate-y-[0.18em] align-baseline\"\n                style={{\n                  background: \"currentColor\",\n                  boxShadow: \"0 0 8px rgb(var(--phos-rgb) / 0.7)\",\n                }}\n              />\n            )}\n          </div>\n        </div>\n\n        {/* Fine scanlines. */}\n        <div\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0 z-20\"\n          style={{\n            backgroundImage: `repeating-linear-gradient(to bottom, rgb(0 0 0 / calc(0.34 * var(--phos-i))) 0 1px, transparent 1px 3px)`,\n          }}\n        />\n        {/* Slow refresh bar rolling down the glass. */}\n        <div\n          aria-hidden\n          className=\"cru-phos-bar pointer-events-none absolute inset-x-0 top-0 z-20 h-1/3\"\n          style={{\n            background: `linear-gradient(to bottom, transparent, rgb(255 255 255 / calc(0.05 * var(--phos-i))), transparent)`,\n          }}\n        />\n        {/* Phosphor bloom flicker. */}\n        <div\n          aria-hidden\n          className=\"cru-phos-flicker pointer-events-none absolute inset-0 z-20 mix-blend-screen\"\n          style={{\n            background: `rgb(var(--phos-rgb) / calc(0.05 * var(--phos-i)))`,\n          }}\n        />\n        {/* Vignette + curved-glass edge darkening. */}\n        <div\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0 z-30 rounded-xl\"\n          style={{\n            background: `radial-gradient(120% 120% at 50% 50%, transparent 52%, rgb(0 0 0 / calc(0.6 * var(--phos-i))) 100%)`,\n            boxShadow: `inset 0 0 40px rgb(0 0 0 / 0.7), inset 0 0 3px rgb(var(--phos-rgb) / 0.3)`,\n          }}\n        />\n      </div>\n\n      {/* Switcher — recoat the tube. A real radiogroup with roving focus. */}\n      {switcher && (\n        <div\n          role=\"radiogroup\"\n          aria-label={switcherLabel}\n          className=\"mt-2.5 flex items-center justify-center gap-1.5\"\n        >\n          {ORDER.map((p, index) => {\n            const on = p === active;\n            const swatch = hues[p] ?? DEFAULT_HUES[p];\n            return (\n              <button\n                key={p}\n                ref={(el) => {\n                  radioRefs.current[index] = el;\n                }}\n                type=\"button\"\n                role=\"radio\"\n                aria-checked={on}\n                tabIndex={on ? 0 : -1}\n                onClick={() => select(p)}\n                onKeyDown={(event) => handleRadioKey(event, index)}\n                className={cn(\n                  \"inline-flex cursor-pointer items-center gap-1.5 rounded-md px-2.5 py-1\",\n                  \"font-mono text-[11px] tracking-wide uppercase transition-colors outline-none\",\n                  \"focus-visible:ring-2 focus-visible:ring-white/70 focus-visible:ring-offset-2 focus-visible:ring-offset-neutral-900\",\n                  on\n                    ? \"bg-white/10 text-neutral-100\"\n                    : \"text-neutral-500 hover:text-neutral-300\"\n                )}\n              >\n                <span\n                  aria-hidden\n                  className=\"h-2.5 w-2.5 rounded-full\"\n                  style={{\n                    background: swatch,\n                    boxShadow: on ? `0 0 7px ${swatch}` : \"none\",\n                  }}\n                />\n                {LABELS[p]}\n              </button>\n            );\n          })}\n        </div>\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}