Beginner needs help with debounce logic

You handle that typically in the state machine.

Here is a small introduction to the topic: Yet another Finite State Machine introduction - might be of interest ?