Keep logic resolution fixed; scale visuals with CSS.
Fixed internal resolution
Run physics at a constant resolution (e.g., 900×520). Scale display with CSS for devices.
Clamp positions
Always clamp entity positions to the internal width/height to avoid out-of-bounds issues.
HiDPI considerations
If desired, render to a 2× buffer for crispness on retina displays.