Easy rule of thumb
To make the distinction between "denn" and "dann" a bit clearer we should learn the most common translations for both:
denn: than, for, because
dann: then, afterwards
Of course - as always - there is an overlap in usage and sometimes a distinction is not clear. See also the various usages of "denn" as a intensifying particle in the usually not translated meaning of "then" as listed in the Pons Dictionary.
"Hast Du das denn nicht gesehen?" - Didn't you see this [then]?
Why is the distinction between "denn" and "dann" so difficult?
The reason why the distinction between "denn" and "dann" is diffcult even for Germans lies in their common etymology:
dann Adv. und denn Adv. und Konj. sind ursprünglich umlautlose und umgelautete Form eines Wortes und daher in älterer Zeit bedeutungsgleich. Ahd. thanne, thenni (8. Jh.), mhd. dan(ne), den(ne), frühnhd. dann, denn Adv. und Konj.
[...]
Im Dt. erfolgt im 18. Jh. die heute geltende semantische Differenzierung von dann und denn. Von den zunächst beiden Varianten gemeinsamen Verwendungen bewahrt dann den adverbiellen Gebrauch (dafür nur in nordd. und md. Umgangssprache noch denn);
[...]
Der Gebrauch als Konjunktion, durch den in älterer Zeit neben- und unterordnend verschiedenartige, namentlich temporale und kausale Zusammenhänge hergestellt werden, verengt sich und geht ganz auf denn über; [...] Als Adverb wird denn jetzt lediglich zur Intensivierung einer Frage oder Aussage verwendet. DWDS
By this we can see that the distinction between "dann" and "denn" occured as late as in the 18th Century. This was approximately the same in English (than vs. then).
The common meaning of denn or dann which is different than today may be preserved in some idiomatic expressions, and can also still be found in regional dialects.