{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notfound-maze",
  "type": "registry:component",
  "title": "404 Maze",
  "description": "A dark 404 section where a tiny pixel explorer wanders a grid maze looking for the exit. Point anywhere on the grid, or use the arrow keys, and it finds a path toward you.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "not-found",
    "404",
    "maze",
    "pixel",
    "interactive",
    "pointer",
    "game"
  ],
  "docs": "https://hyperblur.dev/effects/notfound-maze",
  "files": [
    {
      "path": "registry/hyperblur/notfound-maze.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/notfound-maze.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface NotfoundMazeLink {\n  label: string;\n  href: string;\n}\n\nexport interface NotfoundMazeProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\"> {\n  code?: string;\n  title?: string;\n  subtitle?: string;\n  hint?: string;\n  primary?: NotfoundMazeLink;\n  secondary?: NotfoundMazeLink;\n  cols?: number;\n  rows?: number;\n  speed?: number;\n  accent?: string;\n  onExitReached?: () => void;\n}\n\ntype Cell = { x: number; y: number };\n\nfunction hash(n: number) {\n  let h = Math.imul(n ^ 0x9e3779b9, 0x85ebca6b);\n  h ^= h >>> 13;\n  h = Math.imul(h, 0xc2b2ae35);\n  h ^= h >>> 16;\n  return h >>> 0;\n}\n\nfunction buildWalls(cols: number, rows: number, start: Cell, exit: Cell) {\n  const walls: boolean[] = [];\n  for (let y = 0; y < rows; y++) {\n    for (let x = 0; x < cols; x++) {\n      const pillar = x % 2 === 1 && y % 2 === 1;\n      const extra = hash(y * 131 + x * 17 + 7) % 100 < 13;\n      const keep = (x === start.x && y === start.y) || (x === exit.x && y === exit.y);\n      walls.push(!keep && (pillar || extra));\n    }\n  }\n  return walls;\n}\n\nfunction nextStep(from: Cell, target: Cell, cols: number, rows: number, walls: boolean[]): Cell {\n  const total = cols * rows;\n  const prev = new Int32Array(total).fill(-1);\n  const seen = new Uint8Array(total);\n  const startIdx = from.y * cols + from.x;\n  const queue = [startIdx];\n  seen[startIdx] = 1;\n  let best = startIdx;\n  let bestScore = Math.abs(from.x - target.x) + Math.abs(from.y - target.y);\n  for (let q = 0; q < queue.length; q++) {\n    const idx = queue[q];\n    const x = idx % cols;\n    const y = (idx - x) / cols;\n    const score = Math.abs(x - target.x) + Math.abs(y - target.y);\n    if (score < bestScore) {\n      bestScore = score;\n      best = idx;\n    }\n    const around = [\n      [x + 1, y],\n      [x - 1, y],\n      [x, y + 1],\n      [x, y - 1],\n    ];\n    for (const [nx, ny] of around) {\n      if (nx < 0 || ny < 0 || nx >= cols || ny >= rows) continue;\n      const n = ny * cols + nx;\n      if (seen[n] || walls[n]) continue;\n      seen[n] = 1;\n      prev[n] = idx;\n      queue.push(n);\n    }\n  }\n  if (best === startIdx) return from;\n  let cur = best;\n  while (prev[cur] !== startIdx && prev[cur] !== -1) cur = prev[cur];\n  return { x: cur % cols, y: Math.floor(cur / cols) };\n}\n\nconst css = `\n.hb-yj1 {\n  --hb-yj1-accent: #34d399;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  overflow: hidden;\n  isolation: isolate;\n  container-type: inline-size;\n  background: #0a0a0a;\n  color: #ededed;\n  font-family: inherit;\n  -webkit-font-smoothing: antialiased;\n}\n.hb-yj1 *, .hb-yj1 *::before, .hb-yj1 *::after { box-sizing: border-box; }\n.hb-yj1::before {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  z-index: -1;\n  background:\n    radial-gradient(50% 70% at 78% 40%, color-mix(in srgb, var(--hb-yj1-accent) 13%, transparent), transparent 70%),\n    radial-gradient(40% 50% at 10% 100%, rgba(255, 255, 255, .04), transparent 70%);\n  pointer-events: none;\n}\n.hb-yj1-inner {\n  display: grid;\n  gap: 44px;\n  align-items: center;\n  max-width: 1120px;\n  margin: 0 auto;\n  padding: 72px 20px;\n}\n@container (min-width: 760px) {\n  .hb-yj1-inner { grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 56px; padding: 104px 32px; }\n}\n.hb-yj1-code {\n  display: inline-flex;\n  align-items: center;\n  gap: 10px;\n  padding: 6px 12px 6px 8px;\n  border: 1px solid rgba(255, 255, 255, .08);\n  border-radius: 999px;\n  background: rgba(255, 255, 255, .03);\n  color: #a1a1a1;\n  font: 500 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;\n  letter-spacing: .04em;\n}\n.hb-yj1-code b {\n  padding: 4px 7px;\n  border-radius: 999px;\n  background: color-mix(in srgb, var(--hb-yj1-accent) 18%, transparent);\n  color: var(--hb-yj1-accent);\n  font-weight: 600;\n}\n.hb-yj1-title {\n  margin: 22px 0 0;\n  font-size: clamp(34px, 6.4cqw, 58px);\n  line-height: 1.02;\n  letter-spacing: -.035em;\n  font-weight: 650;\n  text-wrap: balance;\n}\n.hb-yj1-sub {\n  margin: 18px 0 0;\n  max-width: 440px;\n  color: #8f8f8f;\n  font-size: 16px;\n  line-height: 1.6;\n}\n.hb-yj1-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 30px; }\n.hb-yj1-btn {\n  display: inline-flex;\n  align-items: center;\n  gap: 8px;\n  height: 42px;\n  padding: 0 18px;\n  border-radius: 999px;\n  border: 1px solid rgba(255, 255, 255, .1);\n  color: #ededed;\n  font-size: 14px;\n  font-weight: 500;\n  text-decoration: none;\n  transition: background .2s ease, border-color .2s ease, transform .2s ease;\n}\n.hb-yj1-btn:hover { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .18); }\n.hb-yj1-btn:focus-visible, .hb-yj1-board:focus-visible { outline: 2px solid var(--hb-yj1-accent); outline-offset: 3px; }\n.hb-yj1-btn-primary { background: #ededed; color: #0a0a0a; border-color: #ededed; }\n.hb-yj1-btn-primary:hover { background: #fff; transform: translateY(-1px); }\n.hb-yj1-hint {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  margin-top: 26px;\n  color: #6b6b6b;\n  font-size: 13px;\n}\n.hb-yj1-key {\n  display: inline-grid;\n  place-items: center;\n  min-width: 22px;\n  height: 22px;\n  padding: 0 5px;\n  border: 1px solid rgba(255, 255, 255, .12);\n  border-bottom-width: 2px;\n  border-radius: 6px;\n  color: #a1a1a1;\n  font: 500 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;\n}\n.hb-yj1-frame {\n  position: relative;\n  padding: 14px;\n  border: 1px solid rgba(255, 255, 255, .08);\n  border-radius: 22px;\n  background: linear-gradient(180deg, #131313, #0d0d0d);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05), 0 30px 80px -30px rgba(0, 0, 0, .8);\n}\n.hb-yj1-bar {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  padding: 2px 4px 12px;\n  color: #6b6b6b;\n  font: 500 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;\n  letter-spacing: .06em;\n  text-transform: uppercase;\n}\n.hb-yj1-live { display: inline-flex; align-items: center; gap: 7px; color: var(--hb-yj1-accent); }\n.hb-yj1-live::before {\n  content: \"\";\n  width: 6px;\n  height: 6px;\n  border-radius: 50%;\n  background: currentColor;\n  box-shadow: 0 0 10px currentColor;\n  animation: hb-yj1-blink 1.6s ease-in-out infinite;\n}\n.hb-yj1-board {\n  position: relative;\n  display: grid;\n  gap: 3px;\n  padding: 3px;\n  border-radius: 12px;\n  background: #0a0a0a;\n  touch-action: none;\n  cursor: crosshair;\n}\n.hb-yj1-cell {\n  aspect-ratio: 1;\n  border-radius: 4px;\n  background: rgba(255, 255, 255, .025);\n}\n.hb-yj1-wall {\n  background: linear-gradient(180deg, #262626, #1b1b1b);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);\n}\n.hb-yj1-crumb { background: color-mix(in srgb, var(--hb-yj1-accent) 16%, transparent); transition: background .6s ease; }\n.hb-yj1-exit {\n  position: relative;\n  background: color-mix(in srgb, var(--hb-yj1-accent) 22%, transparent);\n  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hb-yj1-accent) 60%, transparent);\n}\n.hb-yj1-exit::after {\n  content: \"\";\n  position: absolute;\n  inset: -4px;\n  border-radius: 7px;\n  border: 1px solid var(--hb-yj1-accent);\n  animation: hb-yj1-ping 2s ease-out infinite;\n}\n.hb-yj1-target {\n  position: absolute;\n  border: 1.5px dashed color-mix(in srgb, var(--hb-yj1-accent) 70%, transparent);\n  border-radius: 5px;\n  pointer-events: none;\n  transition: left .25s ease, top .25s ease, opacity .25s ease;\n}\n.hb-yj1-hero {\n  position: absolute;\n  display: grid;\n  place-items: center;\n  pointer-events: none;\n  transition: left .17s linear, top .17s linear;\n}\n.hb-yj1-hero svg {\n  width: 74%;\n  height: 74%;\n  overflow: visible;\n  animation: hb-yj1-bob .34s steps(2) infinite;\n  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--hb-yj1-accent) 55%, transparent));\n}\n.hb-yj1-flip { transform: scaleX(-1); }\n.hb-yj1-found {\n  position: absolute;\n  left: 50%;\n  bottom: 14px;\n  padding: 7px 12px;\n  border-radius: 999px;\n  background: var(--hb-yj1-accent);\n  color: #04120c;\n  font-size: 12px;\n  font-weight: 600;\n  transform: translate(-50%, 0);\n  animation: hb-yj1-pop .4s cubic-bezier(.2, .9, .3, 1.3);\n  pointer-events: none;\n}\n.hb-yj1-legend {\n  display: flex;\n  gap: 16px;\n  padding: 12px 4px 0;\n  color: #6b6b6b;\n  font-size: 12px;\n}\n.hb-yj1-legend span { display: inline-flex; align-items: center; gap: 6px; }\n.hb-yj1-legend i { width: 10px; height: 10px; border-radius: 3px; }\n@keyframes hb-yj1-bob { 0% { transform: translateY(0); } 100% { transform: translateY(-8%); } }\n@keyframes hb-yj1-ping { 0% { opacity: .9; transform: scale(.9); } 100% { opacity: 0; transform: scale(1.5); } }\n@keyframes hb-yj1-blink { 50% { opacity: .35; } }\n@keyframes hb-yj1-pop { from { opacity: 0; transform: translate(-50%, 8px) scale(.9); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-yj1 *, .hb-yj1 *::before, .hb-yj1 *::after { animation: none !important; transition: none !important; }\n}\n`;\n\nconst waypointsFor = (cols: number, rows: number): Cell[] => [\n  { x: cols - 1, y: 0 },\n  { x: Math.floor(cols / 2), y: rows - 1 },\n  { x: 0, y: 0 },\n  { x: cols - 1, y: rows - 1 },\n  { x: Math.floor(cols / 2), y: Math.floor(rows / 2) },\n];\n\nexport function NotfoundMaze({\n  code = \"404\",\n  title = \"You wandered off the map\",\n  subtitle = \"This page moved, or it never existed. Our little explorer is looking for it too. Point anywhere on the grid to guide the search.\",\n  hint = \"Move the pointer, or use the arrow keys\",\n  primary = { label: \"Take me home\", href: \"/\" },\n  secondary = { label: \"Browse the docs\", href: \"/docs\" },\n  cols = 15,\n  rows = 9,\n  speed = 1,\n  accent = \"#34d399\",\n  onExitReached,\n  className,\n  style,\n  ...rest\n}: NotfoundMazeProps) {\n  const c = Math.max(5, Math.round(cols));\n  const r = Math.max(5, Math.round(rows));\n  const start = React.useMemo<Cell>(() => ({ x: 0, y: Math.floor(r / 2) }), [r]);\n  const exit = React.useMemo<Cell>(() => ({ x: c - 1, y: r - 1 }), [c, r]);\n  const walls = React.useMemo(() => buildWalls(c, r, start, exit), [c, r, start, exit]);\n  const [pos, setPos] = React.useState<Cell>(start);\n  const [trail, setTrail] = React.useState<Cell[]>([]);\n  const [target, setTarget] = React.useState<Cell>(() => waypointsFor(c, r)[0]);\n  const [manual, setManual] = React.useState(false);\n  const [flip, setFlip] = React.useState(false);\n  const [found, setFound] = React.useState(false);\n  const boardRef = React.useRef<HTMLDivElement>(null);\n  const state = React.useRef({ pos: start, target, manual: false, wp: 0, found: false });\n  const exitCb = React.useRef(onExitReached);\n\n  React.useEffect(() => {\n    exitCb.current = onExitReached;\n  }, [onExitReached]);\n\n  React.useEffect(() => {\n    state.current.target = target;\n    state.current.manual = manual;\n  }, [target, manual]);\n\n  React.useEffect(() => {\n    const wps = waypointsFor(c, r);\n    const id = window.setInterval(() => {\n      const s = state.current;\n      if (!s.manual && s.pos.x === s.target.x && s.pos.y === s.target.y) {\n        s.wp = (s.wp + 1) % wps.length;\n        s.target = wps[s.wp];\n        setTarget(s.target);\n      }\n      const next = nextStep(s.pos, s.target, c, r, walls);\n      if (next.x === s.pos.x && next.y === s.pos.y) {\n        if (!s.manual) {\n          s.wp = (s.wp + 1) % wps.length;\n          s.target = wps[s.wp];\n          setTarget(s.target);\n        }\n        return;\n      }\n      if (next.x !== s.pos.x) setFlip(next.x < s.pos.x);\n      const prevPos = s.pos;\n      s.pos = next;\n      setPos(next);\n      setTrail((t) => [prevPos, ...t].slice(0, 7));\n      const atExit = next.x === exit.x && next.y === exit.y;\n      if (atExit && !s.found) {\n        s.found = true;\n        setFound(true);\n        exitCb.current?.();\n      } else if (!atExit && s.found) {\n        s.found = false;\n        setFound(false);\n      }\n    }, Math.round(170 / Math.max(0.2, speed)));\n    return () => window.clearInterval(id);\n  }, [c, r, walls, exit, speed]);\n\n  const cellFromPointer = (e: React.PointerEvent<HTMLDivElement>): Cell | null => {\n    const el = boardRef.current;\n    if (!el) return null;\n    const box = el.getBoundingClientRect();\n    const x = Math.floor(((e.clientX - box.left) / box.width) * c);\n    const y = Math.floor(((e.clientY - box.top) / box.height) * r);\n    return { x: Math.min(c - 1, Math.max(0, x)), y: Math.min(r - 1, Math.max(0, y)) };\n  };\n\n  const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n    const cell = cellFromPointer(e);\n    if (!cell) return;\n    setManual(true);\n    setTarget((t) => (t.x === cell.x && t.y === cell.y ? t : cell));\n  };\n\n  const onPointerLeave = () => setManual(false);\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    const moves: Record<string, [number, number]> = { ArrowRight: [1, 0], ArrowLeft: [-1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] };\n    const m = moves[e.key];\n    if (e.key === \"Escape\") {\n      setManual(false);\n      return;\n    }\n    if (!m) return;\n    e.preventDefault();\n    setManual(true);\n    setTarget((t) => ({ x: Math.min(c - 1, Math.max(0, t.x + m[0])), y: Math.min(r - 1, Math.max(0, t.y + m[1])) }));\n  };\n\n  const pad = 3;\n  const cellW = `((100% - ${pad * 2}px - ${(c - 1) * 3}px) / ${c})`;\n  const cellH = `((100% - ${pad * 2}px - ${(r - 1) * 3}px) / ${r})`;\n  const place = (cell: Cell) => ({\n    left: `calc(${pad}px + ${cell.x} * (${cellW} + 3px))`,\n    top: `calc(${pad}px + ${cell.y} * (${cellH} + 3px))`,\n    width: `calc(${cellW})`,\n    height: `calc(${cellH})`,\n  });\n  const crumbSet = new Set(trail.map((t) => t.y * c + t.x));\n\n  return (\n    <section\n      className={[\"hb-yj1\", className].filter(Boolean).join(\" \")}\n      style={{ \"--hb-yj1-accent\": accent, ...style } as React.CSSProperties}\n      {...rest}\n    >\n      <style href=\"hb-notfound-maze\" precedence=\"default\">{css}</style>\n      <div className=\"hb-yj1-inner\">\n        <div>\n          <span className=\"hb-yj1-code\">\n            <b>{code}</b>\n            Page not found\n          </span>\n          <h1 className=\"hb-yj1-title\">{title}</h1>\n          <p className=\"hb-yj1-sub\">{subtitle}</p>\n          <div className=\"hb-yj1-actions\">\n            <a className=\"hb-yj1-btn hb-yj1-btn-primary\" href={primary.href}>\n              {primary.label}\n              <svg width=\"14\" height=\"14\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\">\n                <path d=\"M3 8h10m-4-4 4 4-4 4\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n              </svg>\n            </a>\n            <a className=\"hb-yj1-btn\" href={secondary.href}>\n              {secondary.label}\n            </a>\n          </div>\n          <div className=\"hb-yj1-hint\">\n            <span className=\"hb-yj1-key\">←</span>\n            <span className=\"hb-yj1-key\">→</span>\n            {hint}\n          </div>\n        </div>\n        <div className=\"hb-yj1-frame\">\n          <div className=\"hb-yj1-bar\">\n            <span>Sector {code}</span>\n            <span className=\"hb-yj1-live\">{manual ? \"Following you\" : \"Searching\"}</span>\n          </div>\n          <div\n            ref={boardRef}\n            className=\"hb-yj1-board\"\n            style={{ gridTemplateColumns: `repeat(${c}, minmax(0, 1fr))` }}\n            role=\"application\"\n            tabIndex={0}\n            aria-label=\"Maze. Use the arrow keys to move the target the explorer walks toward.\"\n            onPointerMove={onPointerMove}\n            onPointerDown={onPointerMove}\n            onPointerLeave={onPointerLeave}\n            onBlur={onPointerLeave}\n            onKeyDown={onKeyDown}\n          >\n            {walls.map((w, i) => {\n              const isExit = i === exit.y * c + exit.x;\n              const cls = w ? \"hb-yj1-cell hb-yj1-wall\" : isExit ? \"hb-yj1-cell hb-yj1-exit\" : crumbSet.has(i) ? \"hb-yj1-cell hb-yj1-crumb\" : \"hb-yj1-cell\";\n              return <div key={i} className={cls} />;\n            })}\n            <div className=\"hb-yj1-target\" style={{ ...place(target), opacity: manual ? 1 : 0.45 }} />\n            <div className={flip ? \"hb-yj1-hero hb-yj1-flip\" : \"hb-yj1-hero\"} style={place(pos)}>\n              <svg viewBox=\"0 0 8 8\" shapeRendering=\"crispEdges\" aria-hidden=\"true\">\n                <rect x=\"2\" y=\"0\" width=\"4\" height=\"1\" fill=\"var(--hb-yj1-accent)\" />\n                <rect x=\"1\" y=\"1\" width=\"6\" height=\"3\" fill=\"var(--hb-yj1-accent)\" />\n                <rect x=\"4\" y=\"2\" width=\"1\" height=\"1\" fill=\"#04120c\" />\n                <rect x=\"6\" y=\"2\" width=\"1\" height=\"1\" fill=\"#04120c\" />\n                <rect x=\"2\" y=\"4\" width=\"4\" height=\"2\" fill=\"#ededed\" />\n                <rect x=\"1\" y=\"4\" width=\"1\" height=\"1\" fill=\"#ededed\" />\n                <rect x=\"6\" y=\"4\" width=\"1\" height=\"1\" fill=\"#ededed\" />\n                <rect x=\"2\" y=\"6\" width=\"1\" height=\"2\" fill=\"#ededed\" />\n                <rect x=\"5\" y=\"6\" width=\"1\" height=\"2\" fill=\"#ededed\" />\n              </svg>\n            </div>\n            {found ? <div className=\"hb-yj1-found\">Exit found. Still no page here.</div> : null}\n          </div>\n          <div className=\"hb-yj1-legend\">\n            <span>\n              <i style={{ background: \"#262626\" }} />\n              Walls\n            </span>\n            <span>\n              <i style={{ background: \"color-mix(in srgb, var(--hb-yj1-accent) 30%, transparent)\" }} />\n              Exit\n            </span>\n            <span>\n              <i style={{ border: \"1.5px dashed var(--hb-yj1-accent)\" }} />\n              Target\n            </span>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}