In the Box Model, z-index is an ordering of overlapping two-dimensional objects. Geometrically speaking, z-index is the perpendicular z-axis that intersects the coordinates y-axis and x-axis.
The visibility of stack order elements depends on their values. The elements with high value has high precedence of visibility and therefore it overlaps other elements in the Box Model and the element with lower precedence will yield. However, this requires the positoning of elements in the Document Object Model (DOM).
The DOM can only render an element with the relative, absolute and fixed position property not static.
It does not require the element to be placed on top for higher visibility nor does it require to be at the bottom for lower visibility. As long as the element has a high value the z-index order, all the other elements will yield. Meaning it will have the high precendence to be displayed on top of the others. For example the z-index of the value of 1 has a high precedence on the one with value of 0.
If the element-1 has z-index of 1 and element-2 has a z-index of 0, the element-1 will have the higher precedence and it will be on top of the order and the element-2 will yield because of its lower precedence.
This is the answer of your question. You are asking:
"Element number 1 is above element number 2. How is that possible?"
As I said above. It does not matter what is above or what is below. What matters is the value of the z-index precendence.
In your case, you placed the element-1 with z-index: 3 above and the element-2 with z-index: 1000 below thinking that the element-1 will have the high precence because of its DOM position. That's wrong. You have to understand that HTML Sementic structures the DOM but CSS styles it or gives it a new look and feel.
With z-index we are dealing with CSS not HTML. Here we don't structure elements, we style them instead.
With your codes above, the element-2 with z-index: 1000 has the higher precedence and it is the one that must be on top of the other regardless its DOM position.