Hello, Physics teacher here! Key to the concept of energy aka work is its definition:
Work done on an object = force X distance moved in the direction of the force. This can also apply when the force is in the opposite direction to the movement, i.e. gravitational force down, movement up. We say we're doing work against gravity.
So the slope introduces horizontal movement but the absence of horizontal forces makes this irrelevant to the problem here. It only becomes relevant when say, sliding and friction is introduced!
