How should I prevent duplicate animation loops and input listeners when restarting a small HTML canvas brick-breaker game? Give a minimal lifecycle pattern, list the game state that must reset, and provide four checks that expose restart bugs. Do not produce a complete game or claim the pattern has been run.
Reset: ball position/velocity, paddle position, brick layout/hit points, score, lives, level, win/loss/pause flags, pressed keys, pointer/touch state, power-ups, cooldowns and physics timing accumulators. Clear held input on window blur too. Four checks: Restart rapidly 20 times: instrument frame updates; movement must not accelerate or multiply. Restart while holding a direction, then release: no stuck movement; one handler invocation per event. Restart after win/loss: bricks, lives, score and ball return to initial values. Stop/unmount and dispatch input: no updates or input effects; remount creates exactly one session.


