{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "snake-game",
  "title": "Snake Game",
  "description": "A canvas-rendered Snake game with three difficulty speeds, keyboard and swipe controls, a directional-eyes snake head, high-score tracking, and ready/game-over overlays.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/snake-game/snake-game.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ntype Direction = \"UP\" | \"DOWN\" | \"LEFT\" | \"RIGHT\";\ntype Point = { x: number; y: number };\ntype GameState = \"ready\" | \"playing\" | \"gameover\";\nexport type SnakeDifficulty = \"easy\" | \"medium\" | \"hard\";\nexport type SnakeTheme = \"classic\" | \"violet\" | \"retro\";\nexport type SnakeTrigger = \"manual\" | \"delay\" | \"scroll\";\nexport type SnakeWidgetPosition = \"bottom-right\" | \"bottom-left\";\n\ninterface ThemeConfig {\n  title: string;\n  subtitle: string;\n  triggerText: string;\n  cardBackground: string;\n  boardBackground: string;\n  gridColor: string;\n  snakeHead: string;\n  snakeBody: string;\n  foodColor: string;\n  accentColor: string;\n  glow: string;\n}\n\nconst THEMES: Record<SnakeTheme, ThemeConfig> = {\n  classic: {\n    title: \"Snake\",\n    subtitle: \"Eat, grow, don't crash\",\n    triggerText: \"Play Snake\",\n    cardBackground: \"linear-gradient(160deg, #f4f6fa 0%, #e8edf4 100%)\",\n    boardBackground: \"#ffffff\",\n    gridColor: \"#ececec\",\n    snakeHead: \"#111111\",\n    snakeBody: \"#333333\",\n    foodColor: \"#ef4444\",\n    accentColor: \"#111111\",\n    glow: \"rgba(17,17,17,0.12)\",\n  },\n  violet: {\n    title: \"Violet Snake\",\n    subtitle: \"Soft arcade high score hunt\",\n    triggerText: \"Play Violet Snake\",\n    cardBackground: \"linear-gradient(160deg, #eef2ff 0%, #e0e7ff 100%)\",\n    boardBackground: \"#ffffff\",\n    gridColor: \"#e4e7fb\",\n    snakeHead: \"#4338ca\",\n    snakeBody: \"#6366f1\",\n    foodColor: \"#db2777\",\n    accentColor: \"#4f46e5\",\n    glow: \"rgba(79,70,229,0.18)\",\n  },\n  retro: {\n    title: \"Pixel Snake\",\n    subtitle: \"Old-school high score hunt\",\n    triggerText: \"Play Pixel Snake\",\n    cardBackground: \"linear-gradient(160deg, #fff7ed 0%, #fde8cf 100%)\",\n    boardBackground: \"#fffdf8\",\n    gridColor: \"#f3e6d4\",\n    snakeHead: \"#3f6212\",\n    snakeBody: \"#65a30d\",\n    foodColor: \"#ea580c\",\n    accentColor: \"#3f6212\",\n    glow: \"rgba(63,98,18,0.16)\",\n  },\n};\n\nconst GAME_KEYS = [\"arrowup\", \"arrowdown\", \"arrowleft\", \"arrowright\", \"w\", \"a\", \"s\", \"d\", \" \"];\n\nexport interface SnakeGameProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  theme?: SnakeTheme;\n  asPopup?: boolean;\n  trigger?: SnakeTrigger;\n  delaySeconds?: number;\n  widgetPosition?: SnakeWidgetPosition;\n  defaultDifficulty?: SnakeDifficulty;\n  gridSize?: number;\n  storageKey?: string;\n}\n\nexport function SnakeGame({\n  theme = \"classic\",\n  asPopup = false,\n  trigger = \"manual\",\n  delaySeconds = 4,\n  widgetPosition = \"bottom-right\",\n  defaultDifficulty = \"medium\",\n  gridSize = 15,\n  storageKey = \"\",\n  className,\n  style,\n  ...props\n}: SnakeGameProps) {\n  const uid = React.useId();\n  const titleId = `${uid}-title`;\n  const hintId = `${uid}-hint`;\n  const statusId = `${uid}-status`;\n\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const gameRootRef = React.useRef<HTMLDivElement>(null);\n  const popupCardRef = React.useRef<HTMLDivElement>(null);\n  const widgetTriggerRef = React.useRef<HTMLButtonElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const boardWrapRef = React.useRef<HTMLDivElement>(null);\n  const isVisibleRef = React.useRef(true);\n  const wasPopupOpenRef = React.useRef(false);\n  const delayTimerRef = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n  const [popupOpen, setPopupOpen] = React.useState(!asPopup);\n  const [scrollTriggered, setScrollTriggered] = React.useState(false);\n  const [prevAsPopup, setPrevAsPopup] = React.useState(asPopup);\n\n  if (asPopup !== prevAsPopup) {\n    setPrevAsPopup(asPopup);\n    setPopupOpen(!asPopup);\n  }\n\n  const activeTheme = THEMES[theme];\n  const widgetOnRight = widgetPosition !== \"bottom-left\";\n  const suffix = storageKey.trim() ? `-${storageKey.trim()}` : \"\";\n  const highScoreKey = `snake-highscore${suffix}`;\n  const cells = Math.max(8, Math.min(24, gridSize));\n\n  const [score, setScore] = React.useState(0);\n  const [highScore, setHighScore] = React.useState(() => {\n    if (typeof window === \"undefined\") return 0;\n    try {\n      const saved = localStorage.getItem(highScoreKey);\n      return saved ? Number(saved) : 0;\n    } catch {\n      return 0;\n    }\n  });\n  const [gameState, setGameState] = React.useState<GameState>(\"ready\");\n  const [difficulty, setDifficulty] = React.useState<SnakeDifficulty>(defaultDifficulty);\n\n  const snakeRef = React.useRef<Point[]>([{ x: Math.floor(cells / 2), y: Math.floor(cells / 2) }]);\n  const directionRef = React.useRef<Direction>(\"RIGHT\");\n  const nextDirectionRef = React.useRef<Direction>(\"RIGHT\");\n  const foodRef = React.useRef<Point>({ x: 3, y: 3 });\n  const cellSizeRef = React.useRef(24);\n  const speedRef = React.useRef(110);\n  const lastTimeRef = React.useRef(0);\n  const animationRef = React.useRef(0);\n  const touchStartRef = React.useRef<{ x: number; y: number } | null>(null);\n  const scoreRef = React.useRef(0);\n  const highScoreRef = React.useRef(highScore);\n  const gameStateRef = React.useRef<GameState>(\"ready\");\n\n  React.useEffect(() => {\n    scoreRef.current = score;\n  }, [score]);\n  React.useEffect(() => {\n    highScoreRef.current = highScore;\n  }, [highScore]);\n  React.useEffect(() => {\n    gameStateRef.current = gameState;\n  }, [gameState]);\n\n  React.useEffect(() => {\n    if (difficulty === \"easy\") speedRef.current = 160;\n    else if (difficulty === \"medium\") speedRef.current = 110;\n    else speedRef.current = 70;\n  }, [difficulty]);\n\n  React.useEffect(() => () => clearTimeout(delayTimerRef.current), []);\n\n  React.useEffect(() => {\n    if (!asPopup || trigger !== \"delay\") return;\n    clearTimeout(delayTimerRef.current);\n    delayTimerRef.current = setTimeout(() => setPopupOpen(true), delaySeconds * 1000);\n    return () => clearTimeout(delayTimerRef.current);\n  }, [asPopup, trigger, delaySeconds]);\n\n  React.useEffect(() => {\n    if (!asPopup || trigger !== \"scroll\" || !rootRef.current) return;\n    const el = rootRef.current;\n    const observer = new IntersectionObserver(\n      ([entry]) => {\n        if (entry.isIntersecting && !scrollTriggered) {\n          setScrollTriggered(true);\n          setPopupOpen(true);\n        }\n      },\n      { threshold: 0.4 },\n    );\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, [asPopup, trigger, scrollTriggered]);\n\n  React.useEffect(() => {\n    isVisibleRef.current = true;\n    const el = gameRootRef.current ?? boardWrapRef.current ?? rootRef.current;\n    if (!el) return;\n    const observer = new IntersectionObserver(([entry]) => {\n      isVisibleRef.current = entry.isIntersecting;\n    }, { threshold: 0 });\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, [popupOpen, asPopup]);\n\n  React.useEffect(() => {\n    if (asPopup && popupOpen) {\n      // Remember it was open, so closing it hands focus back to the launcher button below.\n      wasPopupOpenRef.current = true;\n      const focusTimer = setTimeout(() => gameRootRef.current?.focus(), 30);\n      const body = document.body;\n      const html = document.documentElement;\n      const prevBodyOverflow = body.style.overflow;\n      const prevHtmlOverflow = html.style.overflow;\n      const prevBodyPad = body.style.paddingRight;\n      const scrollbar = window.innerWidth - html.clientWidth;\n      body.style.overflow = \"hidden\";\n      html.style.overflow = \"hidden\";\n      if (scrollbar > 0) body.style.paddingRight = `${scrollbar}px`;\n\n      return () => {\n        clearTimeout(focusTimer);\n        body.style.overflow = prevBodyOverflow;\n        html.style.overflow = prevHtmlOverflow;\n        body.style.paddingRight = prevBodyPad;\n      };\n    }\n\n    if (asPopup && !popupOpen && wasPopupOpenRef.current) {\n      widgetTriggerRef.current?.focus();\n    }\n    wasPopupOpenRef.current = popupOpen;\n  }, [asPopup, popupOpen]);\n\n  const placeFood = (snake: Point[]) => {\n    let newFood: Point;\n    do {\n      newFood = { x: Math.floor(Math.random() * cells), y: Math.floor(Math.random() * cells) };\n    } while (snake.some((s) => s.x === newFood.x && s.y === newFood.y));\n    foodRef.current = newFood;\n  };\n\n  const resetGame = React.useCallback(() => {\n    const mid = Math.floor(cells / 2);\n    snakeRef.current = [{ x: mid, y: mid }];\n    directionRef.current = \"RIGHT\";\n    nextDirectionRef.current = \"RIGHT\";\n    placeFood(snakeRef.current);\n    scoreRef.current = 0;\n    setScore(0);\n    setGameState(\"ready\");\n    gameStateRef.current = \"ready\";\n  }, [cells]);\n\n  const startGame = React.useCallback(() => {\n    if (gameStateRef.current === \"gameover\") resetGame();\n    setGameState(\"playing\");\n    gameStateRef.current = \"playing\";\n    isVisibleRef.current = true;\n    gameRootRef.current?.focus();\n  }, [resetGame]);\n\n  const endGame = React.useCallback(() => {\n    setGameState(\"gameover\");\n    gameStateRef.current = \"gameover\";\n    const current = scoreRef.current;\n    if (current > highScoreRef.current) {\n      highScoreRef.current = current;\n      setHighScore(current);\n      try {\n        localStorage.setItem(highScoreKey, String(current));\n      } catch {\n        /* ignore */\n      }\n    }\n  }, [highScoreKey]);\n\n  const draw = React.useCallback(() => {\n    const canvas = canvasRef.current;\n    if (!canvas) return;\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n    const size = cellSizeRef.current;\n    const w = cells * size;\n    const h = cells * size;\n\n    ctx.fillStyle = activeTheme.boardBackground;\n    ctx.fillRect(0, 0, w, h);\n\n    ctx.strokeStyle = activeTheme.gridColor;\n    ctx.lineWidth = 1;\n    for (let i = 0; i <= cells; i++) {\n      ctx.beginPath();\n      ctx.moveTo(i * size, 0);\n      ctx.lineTo(i * size, h);\n      ctx.stroke();\n      ctx.beginPath();\n      ctx.moveTo(0, i * size);\n      ctx.lineTo(w, i * size);\n      ctx.stroke();\n    }\n\n    const food = foodRef.current;\n    ctx.fillStyle = activeTheme.foodColor;\n    ctx.beginPath();\n    ctx.roundRect(food.x * size + 3, food.y * size + 3, size - 6, size - 6, 6);\n    ctx.fill();\n\n    snakeRef.current.forEach((segment, index) => {\n      const isHead = index === 0;\n      ctx.fillStyle = isHead ? activeTheme.snakeHead : activeTheme.snakeBody;\n      ctx.beginPath();\n      ctx.roundRect(segment.x * size + 2, segment.y * size + 2, size - 4, size - 4, isHead ? 8 : 5);\n      ctx.fill();\n\n      if (isHead) {\n        ctx.fillStyle = \"#ffffff\";\n        const eyeSize = Math.max(2, size * 0.12);\n        let eye1 = { x: 0, y: 0 };\n        let eye2 = { x: 0, y: 0 };\n        if (directionRef.current === \"RIGHT\") {\n          eye1 = { x: segment.x * size + size - size * 0.36, y: segment.y * size + size * 0.28 };\n          eye2 = { x: segment.x * size + size - size * 0.36, y: segment.y * size + size - size * 0.4 };\n        } else if (directionRef.current === \"LEFT\") {\n          eye1 = { x: segment.x * size + size * 0.24, y: segment.y * size + size * 0.28 };\n          eye2 = { x: segment.x * size + size * 0.24, y: segment.y * size + size - size * 0.4 };\n        } else if (directionRef.current === \"UP\") {\n          eye1 = { x: segment.x * size + size * 0.28, y: segment.y * size + size * 0.24 };\n          eye2 = { x: segment.x * size + size - size * 0.4, y: segment.y * size + size * 0.24 };\n        } else {\n          eye1 = { x: segment.x * size + size * 0.28, y: segment.y * size + size - size * 0.36 };\n          eye2 = { x: segment.x * size + size - size * 0.4, y: segment.y * size + size - size * 0.36 };\n        }\n        ctx.beginPath();\n        ctx.arc(eye1.x, eye1.y, eyeSize, 0, Math.PI * 2);\n        ctx.arc(eye2.x, eye2.y, eyeSize, 0, Math.PI * 2);\n        ctx.fill();\n      }\n    });\n  }, [activeTheme, cells]);\n\n  React.useEffect(() => {\n    const canvas = canvasRef.current;\n    if (!canvas) return;\n    const applySize = () => {\n      const containerW = boardWrapRef.current?.clientWidth || 320;\n      const maxSize = Math.min(containerW, 340);\n      const size = Math.max(8, Math.floor(maxSize / cells));\n      cellSizeRef.current = size;\n      canvas.width = cells * size;\n      canvas.height = cells * size;\n      draw();\n    };\n    applySize();\n    const target = boardWrapRef.current;\n    if (!target) return;\n    const ro = new ResizeObserver(() => applySize());\n    ro.observe(target);\n    return () => ro.disconnect();\n  }, [cells, draw, popupOpen]);\n\n  React.useEffect(() => {\n    const tick = (time: number) => {\n      if (!isVisibleRef.current) {\n        animationRef.current = requestAnimationFrame(tick);\n        return;\n      }\n      if (gameStateRef.current !== \"playing\") {\n        draw();\n        animationRef.current = requestAnimationFrame(tick);\n        return;\n      }\n      if (time - lastTimeRef.current > speedRef.current) {\n        lastTimeRef.current = time;\n        directionRef.current = nextDirectionRef.current;\n        const snake = [...snakeRef.current];\n        const head = { ...snake[0] };\n        if (directionRef.current === \"UP\") head.y -= 1;\n        if (directionRef.current === \"DOWN\") head.y += 1;\n        if (directionRef.current === \"LEFT\") head.x -= 1;\n        if (directionRef.current === \"RIGHT\") head.x += 1;\n        if (head.x < 0 || head.x >= cells || head.y < 0 || head.y >= cells || snake.some((s) => s.x === head.x && s.y === head.y)) {\n          endGame();\n          animationRef.current = requestAnimationFrame(tick);\n          return;\n        }\n        snake.unshift(head);\n        if (head.x === foodRef.current.x && head.y === foodRef.current.y) {\n          const next = scoreRef.current + 1;\n          scoreRef.current = next;\n          setScore(next);\n          placeFood(snake);\n        } else {\n          snake.pop();\n        }\n        snakeRef.current = snake;\n      }\n      draw();\n      animationRef.current = requestAnimationFrame(tick);\n    };\n    animationRef.current = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(animationRef.current);\n  }, [cells, draw, endGame, popupOpen]);\n\n  const applyDirection = (next: Direction) => {\n    const dir = directionRef.current;\n    if (next === \"UP\" && dir !== \"DOWN\") nextDirectionRef.current = \"UP\";\n    if (next === \"DOWN\" && dir !== \"UP\") nextDirectionRef.current = \"DOWN\";\n    if (next === \"LEFT\" && dir !== \"RIGHT\") nextDirectionRef.current = \"LEFT\";\n    if (next === \"RIGHT\" && dir !== \"LEFT\") nextDirectionRef.current = \"RIGHT\";\n  };\n\n  const handleGameKeyDown = (e: React.KeyboardEvent) => {\n    const key = e.key.toLowerCase();\n\n    if (key === \"escape\" && asPopup) {\n      e.preventDefault();\n      setPopupOpen(false);\n      return;\n    }\n\n    if (GAME_KEYS.includes(key)) {\n      e.preventDefault();\n      e.stopPropagation();\n    }\n\n    if (gameStateRef.current !== \"playing\") {\n      if (key === \" \" || key.startsWith(\"arrow\") || [\"w\", \"a\", \"s\", \"d\"].includes(key)) startGame();\n      return;\n    }\n\n    if (key === \"arrowup\" || key === \"w\") applyDirection(\"UP\");\n    else if (key === \"arrowdown\" || key === \"s\") applyDirection(\"DOWN\");\n    else if (key === \"arrowleft\" || key === \"a\") applyDirection(\"LEFT\");\n    else if (key === \"arrowright\" || key === \"d\") applyDirection(\"RIGHT\");\n  };\n\n  const trapFocus = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if (e.key !== \"Tab\" || !popupCardRef.current) return;\n    const nodes = popupCardRef.current.querySelectorAll<HTMLElement>('button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])');\n    const list = Array.from(nodes).filter((el) => !el.hasAttribute(\"disabled\") && el.tabIndex !== -1);\n    if (list.length === 0) {\n      e.preventDefault();\n      gameRootRef.current?.focus();\n      return;\n    }\n    const first = list[0];\n    const last = list[list.length - 1];\n    if (e.shiftKey && document.activeElement === first) {\n      e.preventDefault();\n      last.focus();\n    } else if (!e.shiftKey && document.activeElement === last) {\n      e.preventDefault();\n      first.focus();\n    }\n  };\n\n  const handleTouchStart = (e: React.TouchEvent) => {\n    const touch = e.touches[0];\n    touchStartRef.current = { x: touch.clientX, y: touch.clientY };\n  };\n\n  const handleTouchEnd = (e: React.TouchEvent) => {\n    if (!touchStartRef.current) return;\n    const touch = e.changedTouches[0];\n    const dx = touch.clientX - touchStartRef.current.x;\n    const dy = touch.clientY - touchStartRef.current.y;\n    const absDx = Math.abs(dx);\n    const absDy = Math.abs(dy);\n    if (Math.max(absDx, absDy) < 30) {\n      if (gameState !== \"playing\") startGame();\n      touchStartRef.current = null;\n      return;\n    }\n    if (gameState !== \"playing\") {\n      startGame();\n      touchStartRef.current = null;\n      return;\n    }\n    if (absDx > absDy) applyDirection(dx > 0 ? \"RIGHT\" : \"LEFT\");\n    else applyDirection(dy > 0 ? \"DOWN\" : \"UP\");\n    touchStartRef.current = null;\n  };\n\n  const statusText =\n    gameState === \"playing\"\n      ? `Playing. Score ${score}.`\n      : gameState === \"gameover\"\n        ? `Game over. Score ${score}. Press Space or Start to play again.`\n        : \"Ready. Press arrow keys, WASD, or Start to play.\";\n\n  const gameCard = (\n    <div\n      ref={gameRootRef}\n      tabIndex={0}\n      role=\"application\"\n      aria-labelledby={titleId}\n      aria-describedby={`${hintId} ${statusId}`}\n      onKeyDown={handleGameKeyDown}\n      onClick={() => gameRootRef.current?.focus()}\n      className=\"box-border flex w-full flex-col items-center overflow-hidden rounded-[22px] border border-[rgba(23,26,33,0.08)] px-4.5 pt-7 pb-4 font-sans text-[#111111] outline-none select-none\"\n      style={{ background: activeTheme.cardBackground }}\n    >\n      <div className=\"mb-3.5 w-full text-center\">\n        <h2 id={titleId} className=\"m-0 font-serif text-2xl font-normal text-[#111111]\">\n          {activeTheme.title}\n        </h2>\n        <div className=\"mx-auto my-2.5 h-px w-8 bg-[rgba(17,17,17,0.18)]\" />\n        <p className=\"m-0 text-[10px] font-semibold tracking-[0.16em] text-[#888888] uppercase\">{activeTheme.subtitle}</p>\n        <div className=\"mt-3 flex justify-center gap-6 text-[13px] text-[#666666]\" aria-hidden=\"true\">\n          <span>\n            Score <b>{score}</b>\n          </span>\n          <span>\n            Best <b>{highScore}</b>\n          </span>\n        </div>\n        <div id={statusId} role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n          {statusText} Best {highScore}.\n        </div>\n        <div role=\"radiogroup\" aria-label=\"Difficulty\" className=\"mt-3.5 flex flex-wrap justify-center gap-2\">\n          {([\"easy\", \"medium\", \"hard\"] as const).map((level) => {\n            const on = difficulty === level;\n            return (\n              <button\n                key={level}\n                type=\"button\"\n                role=\"radio\"\n                aria-checked={on}\n                onClick={() => {\n                  setDifficulty(level);\n                  if (gameState === \"playing\") resetGame();\n                  gameRootRef.current?.focus();\n                }}\n                className=\"cursor-pointer rounded-[8px] border px-3 py-1.5 text-xs font-semibold capitalize transition-colors\"\n                style={{ background: on ? activeTheme.accentColor : \"#ffffff\", color: on ? \"#ffffff\" : \"#111111\", borderColor: on ? activeTheme.accentColor : \"#e5e5e5\" }}\n              >\n                {level}\n              </button>\n            );\n          })}\n        </div>\n      </div>\n\n      <div ref={boardWrapRef} onTouchStart={handleTouchStart} onTouchEnd={handleTouchEnd} className=\"relative w-full max-w-[340px] overflow-hidden rounded-2xl\">\n        <canvas ref={canvasRef} role=\"img\" aria-label={`${activeTheme.title} board. Score ${score}. Best ${highScore}.`} className=\"block h-auto w-full touch-none\" />\n        {gameState !== \"playing\" && (\n          <div className=\"absolute inset-0 flex flex-col items-center justify-center text-center\" style={{ background: \"rgba(250,250,250,0.92)\" }}>\n            <div className=\"mb-1.5 text-xl font-semibold text-[#111111]\">{gameState === \"gameover\" ? \"Game Over\" : \"Ready?\"}</div>\n            <div className=\"mb-4 text-[13px] text-[#888888]\">{gameState === \"gameover\" ? `Score ${score}` : \"Arrow keys, WASD, or swipe\"}</div>\n            <button type=\"button\" onClick={startGame} className=\"cursor-pointer rounded-lg border-none px-5.5 py-2.5 text-[13px] font-semibold text-white transition-transform\" style={{ background: activeTheme.accentColor }}>\n              {gameState === \"gameover\" ? \"Play Again\" : \"Start Game\"}\n            </button>\n          </div>\n        )}\n      </div>\n      <p id={hintId} className=\"mt-3 text-center text-xs text-[#999999]\">\n        Use arrow keys or WASD to move. Escape closes the widget.\n      </p>\n    </div>\n  );\n\n  if (!asPopup) {\n    return (\n      <div ref={rootRef} className={cn(\"w-full\", className)} style={style} {...props}>\n        {gameCard}\n      </div>\n    );\n  }\n\n  return (\n    <div ref={rootRef} className={cn(\"relative w-full\", className)} style={style} {...props}>\n      <div className={cn(\"flex\", widgetOnRight ? \"justify-end\" : \"justify-start\")}>\n        <motion.button\n          ref={widgetTriggerRef}\n          type=\"button\"\n          onClick={() => setPopupOpen(true)}\n          whileHover={{ scale: 1.04 }}\n          whileTap={{ scale: 0.97 }}\n          aria-haspopup=\"dialog\"\n          aria-expanded={popupOpen}\n          aria-controls={`${uid}-dialog`}\n          aria-label={activeTheme.triggerText}\n          className=\"box-border flex max-w-full items-center gap-3 rounded-full border border-[rgba(23,26,33,0.08)] bg-white py-1.5 pr-4.5 pl-1.5\"\n          style={{ boxShadow: `0 8px 30px ${activeTheme.glow}, 0 4px 16px rgba(0,0,0,0.12)` }}\n        >\n          <span className=\"flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-[#121212]\" aria-hidden=\"true\">\n            <span className=\"block h-2 w-2 shrink-0 rounded-full bg-white\" />\n          </span>\n          <span className=\"flex min-w-0 flex-col gap-0.5 text-left\">\n            <span className=\"text-[9px] font-bold tracking-[0.1em] whitespace-nowrap text-[rgba(23,26,33,0.4)] uppercase\">{activeTheme.triggerText}</span>\n            <span className=\"text-[13px] font-bold text-[#171a21] uppercase\">Play now</span>\n          </span>\n        </motion.button>\n      </div>\n\n      <AnimatePresence>\n        {popupOpen && (\n          <motion.div\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0 }}\n            onWheel={(e) => e.preventDefault()}\n            onClick={(e) => {\n              if (e.target === e.currentTarget) setPopupOpen(false);\n            }}\n            onTouchMove={(e) => {\n              if (e.target === e.currentTarget) e.preventDefault();\n            }}\n            className=\"fixed inset-0 z-[9999] box-border flex items-center justify-center overscroll-none p-6\"\n            style={{ background: \"rgba(0,0,0,0.55)\", touchAction: \"none\" }}\n          >\n            <motion.div\n              id={`${uid}-dialog`}\n              ref={popupCardRef}\n              initial={{ scale: 0.96, y: 12 }}\n              animate={{ scale: 1, y: 0 }}\n              exit={{ scale: 0.98, opacity: 0 }}\n              transition={{ duration: 0.3, ease: [0.16, 1, 0.3, 1] }}\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-labelledby={titleId}\n              aria-describedby={hintId}\n              tabIndex={-1}\n              onKeyDown={(e) => {\n                trapFocus(e);\n                handleGameKeyDown(e);\n              }}\n              className=\"relative box-border w-full max-w-[400px] overflow-auto overscroll-contain rounded-[22px] outline-none\"\n              style={{ maxHeight: \"min(640px, calc(100dvh - 48px))\" }}\n            >\n              <button\n                type=\"button\"\n                onClick={() => setPopupOpen(false)}\n                aria-label=\"Close snake game\"\n                className=\"absolute top-3 right-3 z-20 flex h-8 w-8 items-center justify-center rounded-full border border-[rgba(23,26,33,0.12)] bg-white p-0 text-[#111111]\"\n              >\n                <svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" fill=\"none\" aria-hidden=\"true\" focusable=\"false\">\n                  <path d=\"M2 2l8 8M10 2L2 10\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n                </svg>\n              </button>\n              {gameCard}\n            </motion.div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}