> As I understand it, the terms "third", "fifth", "seventh", etc. all
> refer to the n-th white key relative to the root note.

This is not correct. The interval distance is determined by the letter name distance which is the number of letters you encounter between the two notes which is very easy to see on a staff. This loops if you go to an octave or above. An example on C would be:

<pre>
C to C (same octave) 1st (unison or prime)
C to D 2nd
C to E 3rd
C to F 4th
C to G 5th
C to A 6th
C to B 7th
C to C (next octave) 8th (octave)
</pre>

On the staff it looks like this for C:

    X: 1
    K: C  
    L: 1/4
    %%score (T1 T2)
    V:T1 clef=treble
    V:T2 clef=treble
    [V:T1] C D E F | G A B c
    [V:T2] "1st"C "2nd"C "3rd"C "4th"C | "5th"C "6th"C "7th"C "8th"C

So any C to any D has to be some kind of 2nd. C to F can't be a 3rd because its a letter distance of a 4th (C to F). To make it a 3rd, you have to convert it to it's enharmonic equivalent of E&sharp; which is a 3rd (a major 3rd to be specific).