{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "space-invaders-game",
  "title": "Space Invaders Game",
  "description": "A canvas Space Invaders, a descending grid of pixel-drawn invaders that shoot back, three difficulty levels, keyboard controls on desktop and on-screen move/fire buttons on mobile, with a win/lose end screen.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/space-invaders-game/space-invaders-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 Difficulty = \"easy\" | \"medium\" | \"hard\";\nexport type SpaceInvadersTrigger = \"manual\" | \"delay\" | \"scroll\";\nexport type SpaceInvadersWidgetPosition = \"bottom-right\" | \"bottom-left\";\n\ninterface Vec {\n  x: number;\n  y: number;\n}\ninterface Size {\n  width: number;\n  height: number;\n}\n\nexport interface SpaceInvadersGameProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  lightMode?: boolean;\n  accentColor?: string;\n  asPopup?: boolean;\n  trigger?: SpaceInvadersTrigger;\n  delaySeconds?: number;\n  widgetPosition?: SpaceInvadersWidgetPosition;\n  widgetIcon?: string;\n}\n\nexport function SpaceInvadersGame({\n  lightMode = false,\n  accentColor = \"#ffffff\",\n  asPopup = false,\n  trigger = \"manual\",\n  delaySeconds = 4,\n  widgetPosition = \"bottom-right\",\n  widgetIcon,\n  className,\n  style,\n  ...props\n}: SpaceInvadersGameProps) {\n  const uid = React.useId();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const containerRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const widgetTriggerRef = React.useRef<HTMLButtonElement>(null);\n  const delayTimerRef = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n  const isVisibleRef = React.useRef(true);\n  // The wave waits for the first move or shot, so the board doesn't play itself to \"You lost\"\n  // before anyone has touched it.\n  const startedRef = React.useRef(false);\n  const wasPopupOpenRef = React.useRef(false);\n  const keysRef = React.useRef({ left: false, right: false, space: false });\n\n  const [difficulty, setDifficulty] = React.useState<Difficulty>(\"medium\");\n  const [gameKey, setGameKey] = React.useState(0);\n  const [isMobile, setIsMobile] = React.useState(false);\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 widgetOnRight = widgetPosition !== \"bottom-left\";\n  const resolvedAccent = accentColor || \"#ffffff\";\n\n  const mode = lightMode\n    ? {\n        ink: \"#171a21\",\n        inkSoft: \"rgba(23,26,33,0.7)\",\n        inkFaint: \"rgba(23,26,33,0.4)\",\n        divider: \"rgba(23,26,33,0.18)\",\n        surface: \"rgba(255,255,255,0.65)\",\n        surfaceBorder: \"rgba(23,26,33,0.1)\",\n        cardBorder: \"rgba(23,26,33,0.08)\",\n        overlayBg: \"rgba(0,0,0,0.45)\",\n        chromeBg: \"#ffffff\",\n        chromeBorder: \"rgba(23,26,33,0.1)\",\n        pageBg: \"linear-gradient(160deg, #f4f6fa 0%, #dfe6f0 100%)\",\n        canvasBg: \"rgba(23,26,33,0.04)\",\n        endOverlay: \"rgba(255,255,255,0.72)\",\n      }\n    : {\n        ink: \"#ffffff\",\n        inkSoft: \"rgba(255,255,255,0.7)\",\n        inkFaint: \"rgba(255,255,255,0.4)\",\n        divider: \"rgba(255,255,255,0.3)\",\n        surface: \"rgba(255,255,255,0.06)\",\n        surfaceBorder: \"rgba(255,255,255,0.12)\",\n        cardBorder: \"rgba(255,255,255,0.08)\",\n        overlayBg: \"rgba(0,0,0,0.7)\",\n        chromeBg: \"rgba(10,10,15,0.92)\",\n        chromeBorder: \"rgba(255,255,255,0.16)\",\n        pageBg: \"linear-gradient(160deg, #07080b 0%, #101319 100%)\",\n        canvasBg: \"rgba(255,255,255,0.04)\",\n        endOverlay: \"rgba(4,4,6,0.72)\",\n      };\n\n  const resetGame = React.useCallback(() => setGameKey((k) => k + 1), []);\n\n  React.useEffect(() => {\n    const el = containerRef.current;\n    if (!el) return;\n    // Touch controls for touch screens (and very narrow boards), not for every desktop column\n    // under 900px.\n    const coarse = window.matchMedia(\"(pointer: coarse)\").matches;\n    const ro = new ResizeObserver(([entry]) => setIsMobile(coarse || entry.contentRect.width < 520));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, [popupOpen]);\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    if (!rootRef.current) return;\n    const observer = new IntersectionObserver(([entry]) => {\n      isVisibleRef.current = entry.isIntersecting;\n    }, { threshold: 0 });\n    observer.observe(rootRef.current);\n    return () => observer.disconnect();\n  }, []);\n\n  React.useEffect(() => {\n    if (!asPopup) return;\n    if (!popupOpen && wasPopupOpenRef.current) widgetTriggerRef.current?.focus();\n    wasPopupOpenRef.current = popupOpen;\n  }, [asPopup, popupOpen]);\n\n  const onRootKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if (e.key === \"Escape\" && asPopup) {\n      setPopupOpen(false);\n      return;\n    }\n    if (e.key === \"ArrowLeft\" || e.key === \"ArrowRight\" || e.key === \" \") startedRef.current = true;\n    if (e.key === \"ArrowLeft\") {\n      keysRef.current.left = true;\n      e.preventDefault();\n    }\n    if (e.key === \"ArrowRight\") {\n      keysRef.current.right = true;\n      e.preventDefault();\n    }\n    if (e.key === \" \") {\n      keysRef.current.space = true;\n      e.preventDefault();\n    }\n  };\n\n  const onRootKeyUp = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if (e.key === \"ArrowLeft\") keysRef.current.left = false;\n    if (e.key === \"ArrowRight\") keysRef.current.right = false;\n    if (e.key === \" \") keysRef.current.space = false;\n  };\n\n  React.useEffect(() => {\n    const canvas = canvasRef.current;\n    const host = containerRef.current;\n    if (!canvas || !host) return;\n    const screen = canvas.getContext(\"2d\");\n    if (!screen) return;\n\n    let gameSize = { width: 720, height: 400 };\n    let game: Game;\n    const invaderSize = 22;\n    let invaderAttackRate = 0.995;\n    let kills = 0;\n    let isDestroyed = false;\n    let playerSpeed = 2.6;\n    let shotSpeed = 7;\n\n    if (difficulty === \"easy\") {\n      invaderAttackRate = 0.998;\n      playerSpeed = 3.4;\n      shotSpeed = 8.5;\n    } else if (difficulty === \"hard\") {\n      invaderAttackRate = 0.982;\n      playerSpeed = 2.1;\n      shotSpeed = 6;\n    }\n\n    const blocks = [\n      [3, 4, 8, 9, 10, 15, 16],\n      [2, 4, 7, 11, 14, 16],\n      [1, 4, 7, 11, 13, 16],\n      [1, 2, 3, 4, 5, 7, 11, 13, 14, 15, 16, 17],\n      [4, 7, 11, 16],\n      [4, 8, 9, 10, 16],\n    ];\n\n    const spriteLight = lightMode ? \"#171a21\" : \"#e8e8ea\";\n    const spriteDark = lightMode ? \"#f4f6fa\" : \"#0a0a0f\";\n    const playerOuter = lightMode ? \"#171a21\" : \"#f4f5f7\";\n    const playerInner = lightMode ? \"#f4f6fa\" : \"#0a0a0f\";\n    const shotPlayer = lightMode ? \"#171a21\" : \"#ffffff\";\n    const shotEnemy = lightMode ? \"#6b7280\" : \"#9a9aa0\";\n\n    function drawClawd(ctx: CanvasRenderingContext2D, x: number, y: number, size: number) {\n      const s = size / 8;\n      ctx.fillStyle = spriteLight;\n      ctx.fillRect(x + s * 1.5, y + s * 2, s * 5, s * 4);\n      ctx.fillRect(x + s * 0.2, y + s * 3, s * 1.5, s * 1.8);\n      ctx.fillRect(x + s * 6.3, y + s * 3, s * 1.5, s * 1.8);\n      ctx.fillRect(x + s * 2, y + s * 1, s * 1.5, s * 1.5);\n      ctx.fillRect(x + s * 4.5, y + s * 1, s * 1.5, s * 1.5);\n      ctx.fillStyle = spriteDark;\n      ctx.fillRect(x + s * 2.5, y + s * 2.8, s * 1.1, s * 1.1);\n      ctx.fillRect(x + s * 4.4, y + s * 2.8, s * 1.1, s * 1.1);\n    }\n\n    function drawShip(ctx: CanvasRenderingContext2D, x: number, y: number, size: number) {\n      const cx = x + size / 2;\n      const cy = y + size / 2;\n      const r = size / 2 - 1;\n      ctx.beginPath();\n      ctx.arc(cx, cy, r, 0, Math.PI * 2);\n      ctx.fillStyle = playerOuter;\n      ctx.fill();\n      ctx.beginPath();\n      ctx.arc(cx, cy, r * 0.55, 0, Math.PI * 2);\n      ctx.fillStyle = playerInner;\n      ctx.fill();\n      ctx.beginPath();\n      ctx.arc(cx, cy, r * 0.78, -0.8, 2.6);\n      ctx.lineWidth = r * 0.28;\n      ctx.strokeStyle = playerOuter;\n      ctx.lineCap = \"round\";\n      ctx.stroke();\n    }\n\n    class Projectile {\n      active = true;\n      coordinates: Vec;\n      size: Size = { width: 3, height: 5 };\n      velocity: Vec;\n      constructor(coordinates: Vec, velocity: Vec) {\n        this.coordinates = coordinates;\n        this.velocity = velocity;\n      }\n      update() {\n        this.coordinates.x += this.velocity.x;\n        this.coordinates.y += this.velocity.y;\n        if (this.coordinates.y > gameSize.height || this.coordinates.y < 0) this.active = false;\n      }\n      draw() {\n        if (!this.active) return;\n        screen!.fillStyle = this.velocity.y < 0 ? shotPlayer : shotEnemy;\n        screen!.fillRect(this.coordinates.x, this.coordinates.y, this.size.width, this.size.height);\n      }\n    }\n\n    function collides(a: { coordinates: Vec; size: Size }, b: { coordinates: Vec; size: Size }) {\n      return a.coordinates.x < b.coordinates.x + b.size.width && a.coordinates.x + a.size.width > b.coordinates.x && a.coordinates.y < b.coordinates.y + b.size.height && a.coordinates.y + a.size.height > b.coordinates.y;\n    }\n\n    class Invader {\n      active = true;\n      coordinates: Vec;\n      size: Size = { width: invaderSize, height: invaderSize };\n      constructor(coordinates: Vec) {\n        this.coordinates = coordinates;\n      }\n      update() {\n        if (Math.random() > invaderAttackRate) {\n          game.invaderShots.push(new Projectile({ x: this.coordinates.x + this.size.width / 2, y: this.coordinates.y + this.size.height }, { x: 0, y: 2.3 }));\n        }\n      }\n      draw() {\n        if (this.active) drawClawd(screen!, this.coordinates.x, this.coordinates.y, invaderSize);\n      }\n      destroy() {\n        this.active = false;\n        kills += 1;\n      }\n    }\n\n    class Player {\n      active = true;\n      size: Size = { width: 28, height: 28 };\n      shooterHeat = -5;\n      coordinates: Vec = { x: (gameSize.width / 2 - this.size.width / 2) | 0, y: gameSize.height - this.size.height - 16 };\n      projectile: Projectile[] = [];\n      update() {\n        this.projectile.forEach((p) => p.update());\n        this.projectile = this.projectile.filter((p) => p.active);\n        if (!this.active) return;\n        if (keysRef.current.left && this.coordinates.x > 0) this.coordinates.x -= playerSpeed;\n        if (keysRef.current.right && this.coordinates.x < gameSize.width - this.size.width) this.coordinates.x += playerSpeed;\n        if (keysRef.current.space) {\n          this.shooterHeat += 1;\n          if (this.shooterHeat < 0) {\n            this.projectile.push(new Projectile({ x: this.coordinates.x + this.size.width / 2 - 1.5, y: this.coordinates.y - 4 }, { x: 0, y: -shotSpeed }));\n          } else if (this.shooterHeat > 9) this.shooterHeat = -5;\n        } else this.shooterHeat = -5;\n      }\n      draw() {\n        if (this.active) drawShip(screen!, this.coordinates.x, this.coordinates.y, this.size.width);\n        this.projectile.forEach((p) => p.draw());\n      }\n      destroy() {\n        this.active = false;\n        game.lost = true;\n      }\n    }\n\n    function createInvaders() {\n      const invaders: Invader[] = [];\n      const mult = gameSize.width > 700 ? 1 : 0.9;\n      const totalWidth = 18 * invaderSize * mult;\n      const offsetX = (gameSize.width - totalWidth) / 2;\n      for (let row = 0; row < blocks.length; row++) {\n        for (const col of blocks[row]) {\n          invaders.push(new Invader({ x: offsetX + col * invaderSize * mult, y: 30 + row * invaderSize * 1.3 }));\n        }\n      }\n      return invaders;\n    }\n\n    class Game {\n      lost = false;\n      won = false;\n      player = new Player();\n      invaders = createInvaders();\n      invaderShots: Projectile[] = [];\n      update() {\n        if (!this.lost && !this.won) {\n          this.player.projectile.forEach((p) => {\n            this.invaders.forEach((inv) => {\n              if (collides(p, inv)) {\n                inv.destroy();\n                p.active = false;\n              }\n            });\n          });\n          this.invaderShots.forEach((s) => {\n            if (collides(s, this.player)) this.player.destroy();\n          });\n          this.invaders.forEach((inv) => inv.update());\n        }\n        this.player.update();\n        this.invaderShots.forEach((s) => s.update());\n        this.invaders = this.invaders.filter((i) => i.active);\n        this.invaderShots = this.invaderShots.filter((s) => s.active);\n        if (this.invaders.length === 0) this.won = true;\n      }\n      draw() {\n        screen!.clearRect(0, 0, gameSize.width, gameSize.height);\n        if (this.lost || this.won) {\n          screen!.fillStyle = mode.endOverlay;\n          screen!.fillRect(0, 0, gameSize.width, gameSize.height);\n          screen!.font = \"400 34px Georgia, 'Times New Roman', serif\";\n          screen!.textAlign = \"center\";\n          screen!.fillStyle = mode.ink;\n          screen!.fillText(this.won ? \"You won\" : \"You lost\", gameSize.width / 2, gameSize.height / 2 - 14);\n          screen!.font = \"600 11px 'Helvetica Neue', Helvetica, Arial, sans-serif\";\n          screen!.fillStyle = mode.inkFaint;\n          screen!.fillText(`POINTS  ${kills}`, gameSize.width / 2, gameSize.height / 2 + 18);\n        } else if (!startedRef.current) {\n          screen!.font = \"600 11px 'Helvetica Neue', Helvetica, Arial, sans-serif\";\n          screen!.textAlign = \"center\";\n          screen!.fillStyle = mode.inkFaint;\n          screen!.fillText(\"PRESS SPACE OR AN ARROW KEY TO START\", gameSize.width / 2, gameSize.height - 70);\n        } else {\n          screen!.font = \"700 10px 'Helvetica Neue', Helvetica, Arial, sans-serif\";\n          screen!.textAlign = \"right\";\n          screen!.fillStyle = mode.inkFaint;\n          screen!.fillText(`POINTS  ${kills}`, gameSize.width - 16, gameSize.height - 14);\n        }\n        this.player.draw();\n        this.invaders.forEach((i) => i.draw());\n        this.invaderShots.forEach((s) => s.draw());\n      }\n    }\n\n    function initGame() {\n      const width = host!.clientWidth || 720;\n      if (width > 1000) gameSize = { width: 980, height: 480 };\n      else if (width > 700) gameSize = { width: Math.max(320, width - 40), height: 440 };\n      else gameSize = { width: Math.max(280, width - 24), height: 360 };\n      // Backing store at the device pixel ratio (sharp sprites on high-density screens); the game\n      // keeps drawing in CSS px.\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      canvas!.width = Math.round(gameSize.width * dpr);\n      canvas!.height = Math.round(gameSize.height * dpr);\n      canvas!.style.width = `${gameSize.width}px`;\n      canvas!.style.height = `${gameSize.height}px`;\n      screen!.setTransform(dpr, 0, 0, dpr, 0, 0);\n      kills = 0;\n      game = new Game();\n      game.draw();\n    }\n\n    let rafId = 0;\n    function loop() {\n      if (isDestroyed) return;\n      if (isVisibleRef.current) {\n        if (startedRef.current) game.update();\n        game.draw();\n      }\n      rafId = requestAnimationFrame(loop);\n    }\n\n    startedRef.current = false;\n    initGame();\n    rafId = requestAnimationFrame(loop);\n\n    const ro = new ResizeObserver(() => {\n      if (isDestroyed) return;\n      initGame();\n    });\n    ro.observe(host);\n\n    return () => {\n      isDestroyed = true;\n      ro.disconnect();\n      cancelAnimationFrame(rafId);\n    };\n  }, [difficulty, gameKey, lightMode, popupOpen, mode.endOverlay, mode.ink, mode.inkFaint]);\n\n  const handleTouch = (type: \"left\" | \"right\" | \"space\", active: boolean) => {\n    keysRef.current[type] = active;\n    if (active) startedRef.current = true;\n  };\n\n  const gameCard = (\n    <section\n      ref={containerRef}\n      aria-labelledby={`${uid}-title`}\n      aria-describedby={`${uid}-desc`}\n      className=\"box-border flex w-full flex-col items-center overflow-auto rounded-[22px] px-6.5 py-8 font-sans select-none\"\n      style={{ background: mode.pageBg, border: `1px solid ${mode.cardBorder}` }}\n    >\n      <header className=\"mb-5.5 max-w-[640px] text-center\">\n        <h2 id={`${uid}-title`} className=\"m-0 font-serif text-[25px] font-normal tracking-[-0.02em]\" style={{ color: mode.ink }}>\n          Space404 Game\n        </h2>\n        <div className=\"mx-auto my-3 h-px w-8\" style={{ background: mode.divider }} />\n        <p className=\"m-0 text-[10px] font-semibold tracking-[0.18em] uppercase\" style={{ color: mode.inkFaint }}>\n          Take revenge on the Clawds\n        </p>\n        <p id={`${uid}-desc`} className=\"m-0 mt-2.5 text-[13px] leading-[1.5] font-normal\" style={{ color: mode.inkSoft }}>\n          Play Space404 Game online. Move with arrow keys, shoot with Space. Defeat the Clawd invaders to score points.\n        </p>\n        <div role=\"group\" aria-label=\"Difficulty\" className=\"mt-4 flex flex-wrap justify-center gap-2\">\n          {([\"easy\", \"medium\", \"hard\"] as Difficulty[]).map((level) => {\n            const on = difficulty === level;\n            return (\n              <button\n                key={level}\n                type=\"button\"\n                aria-pressed={on}\n                onClick={() => {\n                  setDifficulty(level);\n                  resetGame();\n                }}\n                className=\"cursor-pointer rounded-full px-3.5 py-2 text-[10px] font-bold tracking-[0.12em] uppercase\"\n                style={{ border: `1px solid ${mode.surfaceBorder}`, background: on ? resolvedAccent : mode.surface, color: on ? (lightMode ? \"#171a21\" : \"#0a0a0f\") : mode.inkSoft }}\n              >\n                {level}\n              </button>\n            );\n          })}\n          <button\n            type=\"button\"\n            onClick={resetGame}\n            className=\"cursor-pointer rounded-full px-3.5 py-2 text-[10px] font-bold tracking-[0.12em] uppercase\"\n            style={{ border: `1px solid ${mode.surfaceBorder}`, background: mode.surface, color: mode.inkSoft }}\n          >\n            Restart\n          </button>\n        </div>\n      </header>\n\n      <canvas\n        ref={canvasRef}\n        role=\"img\"\n        aria-label=\"Space404 Game game board. Take revenge on the Clawds\"\n        className=\"block max-w-full touch-none rounded-[14px]\"\n        style={{ background: mode.canvasBg, border: `1px solid ${mode.surfaceBorder}` }}\n      />\n\n      {isMobile && (\n        <div role=\"group\" aria-label=\"Touch controls\" className=\"mt-5 flex w-full max-w-[420px] justify-center gap-4\">\n          <button\n            type=\"button\"\n            aria-label=\"Move left\"\n            onTouchStart={() => handleTouch(\"left\", true)}\n            onTouchEnd={() => handleTouch(\"left\", false)}\n            onMouseDown={() => handleTouch(\"left\", true)}\n            onMouseUp={() => handleTouch(\"left\", false)}\n            onMouseLeave={() => handleTouch(\"left\", false)}\n            className=\"flex h-16 w-16 touch-manipulation items-center justify-center rounded-2xl text-[22px] select-none\"\n            style={{ border: `1px solid ${mode.surfaceBorder}`, background: mode.surface, color: mode.ink }}\n          >\n            ←\n          </button>\n          <button\n            type=\"button\"\n            aria-label=\"Fire\"\n            onTouchStart={() => handleTouch(\"space\", true)}\n            onTouchEnd={() => handleTouch(\"space\", false)}\n            onMouseDown={() => handleTouch(\"space\", true)}\n            onMouseUp={() => handleTouch(\"space\", false)}\n            onMouseLeave={() => handleTouch(\"space\", false)}\n            className=\"flex h-[76px] w-[76px] touch-manipulation items-center justify-center rounded-full border-none text-[11px] font-bold tracking-[0.12em] uppercase select-none\"\n            style={{ background: resolvedAccent, color: lightMode ? \"#171a21\" : \"#0a0a0f\" }}\n          >\n            Fire\n          </button>\n          <button\n            type=\"button\"\n            aria-label=\"Move right\"\n            onTouchStart={() => handleTouch(\"right\", true)}\n            onTouchEnd={() => handleTouch(\"right\", false)}\n            onMouseDown={() => handleTouch(\"right\", true)}\n            onMouseUp={() => handleTouch(\"right\", false)}\n            onMouseLeave={() => handleTouch(\"right\", false)}\n            className=\"flex h-16 w-16 touch-manipulation items-center justify-center rounded-2xl text-[22px] select-none\"\n            style={{ border: `1px solid ${mode.surfaceBorder}`, background: mode.surface, color: mode.ink }}\n          >\n            →\n          </button>\n        </div>\n      )}\n    </section>\n  );\n\n  if (!asPopup) {\n    return (\n      <div ref={rootRef} tabIndex={0} onKeyDown={onRootKeyDown} onKeyUp={onRootKeyUp} className={cn(\"w-full outline-none\", className)} style={style} {...props}>\n        {gameCard}\n      </div>\n    );\n  }\n\n  return (\n    <div ref={rootRef} tabIndex={0} onKeyDown={onRootKeyDown} onKeyUp={onRootKeyUp} className={cn(\"relative w-full outline-none\", 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-label=\"Open Space404 Game\"\n          className=\"flex items-center gap-3 rounded-full border border-[rgba(23,26,33,0.08)] bg-white py-1.5 pr-5 pl-1.5\"\n        >\n          <span className=\"flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-[#121212] text-lg text-white\">\n            {widgetIcon ? (\n              // eslint-disable-next-line @next/next/no-img-element\n              <img src={widgetIcon} alt=\"\" className=\"h-6 w-6 rounded-full object-cover\" />\n            ) : (\n              \"▣\"\n            )}\n          </span>\n          <span className=\"flex 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\">Space404 Game</span>\n            <span className=\"text-[13px] font-bold tracking-[0.02em] whitespace-nowrap 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            onClick={(e) => {\n              if (e.target === e.currentTarget) setPopupOpen(false);\n            }}\n            className=\"fixed inset-0 z-[9999] flex items-center justify-center p-5\"\n            style={{ background: mode.overlayBg }}\n          >\n            <motion.div\n              initial={{ scale: 0.94, y: 16 }}\n              animate={{ scale: 1, y: 0 }}\n              exit={{ scale: 0.96, opacity: 0 }}\n              transition={{ duration: 0.35, ease: [0.16, 1, 0.3, 1] }}\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-labelledby={`${uid}-title`}\n              className=\"relative w-full\"\n              style={{ maxWidth: 980 }}\n            >\n              {gameCard}\n              <button\n                type=\"button\"\n                onClick={() => setPopupOpen(false)}\n                aria-label=\"Close game\"\n                className=\"absolute -top-3.5 -right-3.5 z-[100] flex h-8 w-8 items-center justify-center rounded-full border text-[17px] leading-[30px]\"\n                style={{ background: mode.chromeBg, borderColor: mode.chromeBorder, color: mode.ink }}\n              >\n                ×\n              </button>\n            </motion.div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}