You're talking about a coordinate system with a horizontal defined by the inclined plane. I'm talking about a coordinate system with a horizontal being defined by the true horizontal, meaning that the inclined plane would be at an angle to the horizontal x-axis. But to make things easier to see using your argument, let's switch to your coordinate system.

The work done by gravity is still the same here. So let's draw the free body diagram like so:

You've defined the x-axis as the incline. That's fine. But the force of gravity is at an angle to that of the x-axis. The force of gravity is always exerted straight down towards the center of the Earth, as drawn. The magnitude does not change - it's always m*g pointing straight downwards to the center of the Earth, no matter how you define your coordinate system. As you can see in this picture, the

*net displacement in the direction of the force of gravity* is simply the height of the incline. You can repeat this exercise with any incline you want (any theta where 0 < theta < pi/2) and you will get the same result if the box always starts at the same height. Therefore,

*the work done by gravity does not change no matter the slope*. Does that make sense now? Defining your coordinate system with the x-axis along the incline actually complicates the problem in this case because it's asking specifically by the work done by gravity, which is a force that acts strictly in the vertical direction (in the coordinate system where the x-axis is the true horizontal and the y-axis is the vertical).

This then begs the (related) question of how you get horizontal displacement at all then (where horizontal is the true horizontal). Well, remember Newton's third law. The object is pressing down on the plane and the plane is pressing right back on the object. So immediately, as drawn in the picture, you can see that the normal force provides the impetus for displacement in the horizontal direction (true horizontal).