I have the sentence
Ich fahre gerne, aber nicht dann, wenn viel Verkehr ist.
Translating this seems very simple - I like to drive, but not when there is lots of traffic.
I'm confused though.
I know that "dann" in German normally means then or afterwords but that would make no sense in this context.
What is the purpose of dann in this sentence?