Hmmm ...
The grammar/authenticity etc is fine...
The problem is what other people will classify as "the top". I imagine that many people will consider the blue cup to be the top, and therefore give you the yellow cup. I think that there will be always be potential confusion in this example, and the only way to avoid this is to clarify that you mean the red one. If you think about a ladder, the top is the highest point, but we can talk about the rungs (steps). In a three rung ladder, the second from the top is the closest to the floor.
You can use the verb 'to stack' - The cups are stacked upside down.