Do I have to work on the game within 3 hours or am I allowed to work on it for the duration of the competition?
If you want to compete for the leaderboard, you need to finish it in under 3 hours total. The only thing that counts is the time you spend actually making your game and the assets, not the planning time, build time or setting up the itch page. You can also split the 3 hours. You can work on it for 1 hour each day if you want, as long as the total time is under 3 hours.