So I'm learning this piece, and just posted it up what i've done so far for feedback; and decided to post about this as well. I'm wanting to delve as far into composition as i can, and trying to understand the classical style... it's tough through self study.
So in Motzart's piano sonata k 545, it's in C major. The opening clearly defines the tonic, modulating occasionally between F and G, but still clearly in C major. Then the right hand runs begin. To me as i'm playing and listening to this piece, the tonality of it becomes quite undefined here, and it seems to be much more modal in nature than in a specific key.
The first run is essentially the A minor scale, followed by ascending runs down the keyboard to D. On this run, Motzart chose to sharp the tonic, C (which obviously works beautifully, and I think it also sounds like it belongs because the piece here has lost it's sense of a solid key, as it moves towards G major in the next little section). I hear the power and the intensity that the D minor scale creates here, but I'm wondering what the compositional principal is behind it?
The C sharp from what I can tell, doesn't lend itself to the immediate following modulation into G major, since C# is not a note in the G major scale (I'm speaking based on my level of understanding, if there is some principal I'm missing... please fill me in

), yet it still 'feels' like the absolute perfect note.
The C sharp also doesn't seem to be repeating anywhere else. The major recapitulation I've seen in the piece is in F major, so i'm not sure what the C# is moving towards. but again, I "feel" it's natural movement when i listen to the piece. Why is that?
Sorry if I'm talking about things way over my head, just trying to get some solid footing on what i've been studying.