Why are you crying?

For the sake of analysis, how would you rewrite the sentence “Why are you crying”?
My thought is “You are crying why”.

My dictionary says that “why” is an adverb here. However, can’t figure out which word it modifies.

P.S. Does it modify the WHOLE sentence?

To rewrite your sentence you could say: For what reason are you crying? Your sentence:

doesn’t work.

The function of ‘why’ in your original sentence

is that of a ‘question’ adverb and as such it modifies the verb

 If we change "why" to informal expression "how come", we'll get the following sentence:

    How come you are crying?

A question arises:
Why does the verb remain uninverted despite the fact that it’s an interrogative sentence?

The interrogative element is in 'How come …? ‘That you are crying’ is the dependent clause.

Thank you, Alan.

Is there a way to rewrite that sentence in a similar way as in the sentence below?

What are you doing?
=> You are doing what?

No, not really.