My German students often have the same question, which is why I wrote blog this post to answer it. And since all three phases use the word "viel", it is easy to understand why they are puzzled. Keep reading below to learn why there is a difference.
To begin with, you need to understand when “viel” is used on its own and when it has an ending. As an adverb, "viel" translates as "much" and is used as it is, whereas "viel" as an adjective means "a lot" or "many" and needs to agree with the noun that follows.
Then you have to consider the case of the three nouns you mention. While both “Erfolg” and “Spaß” are in the nominative case, “Dank” is used in the accusative case. Why is that, you might wonder. “Viel Erfolg” and “viel Spaß” are standalone phrases, whereas “Vielen Dank” is the abbreviated form of the full phrase “Ich wünsche dir/Ihnen vielen Dank” oder the imperative “Haben Sie vielen Dank”. So “ich” and “Sie” act as the subject of the sentence, while “Dank” is the direct object, that is, it has the action of the verb done to it.
On the difference between subject and object as well as all four cases in German, you might want to check out my other blog posts to learn more. Of course, there are other ways to say thank you in German and many other grammar topics that are worth exploring on our German language blog "Auf Deutsch, bitte!".
I hope this helps!