Your next state process is only sensitive to state_reg
. As a combinational process it needs all of its inputs listed in the sensitivity list (or all
with VHDL-2008).
process(state_reg, level, level_detected_reg)
begin
...
You are also missing an unconditional else on the assignment to q which will create a latch in synthesis.