I strongly believe that a lot of it is down to personality.
My 16yo is very happy and has sailed through the teen years thus far. Excelling at school and in her PT job. Tons of lovely friends. Hobbies that she loves. Bags of confidence, excellent mental health etc. And frankly a joy to be around.
I think a lot of it is luck tbh. She is certainly loved and valued, but so are some of her less stable friends. I have always treated her with respect, I don't do the whole I'm the parent so I'm in charge thing. We have a very close relationship, which definitely helps, but again, I think it's partly just luck that we happen to get on. I do think it helps that I'm pretty easy going and don't fuss about minutiae. I recognise that she is growing up, I give her a reasonable amount of freedom while ensuring that she is safe, I don't impose pointless rules for no good reason. She sees me as reasonable and supportive, whereas some of her friends perceive their parents as controlling and interfering. It's easy for me not to interfere though, because she's very sensible and I trust her.
I think it's important that we talk a lot - I listen a lot because I am genuinely interested, I love hearing about her friends, her teachers, her job and just her opinions. She is great company and she knows that I enjoy spending time with her. She also knows that I won't judge stuff, that I won't be dismissive about stuff and that I'm here to help if she needs it.
I think her hobbies have helped her a lot - drama which has helped to build her confidence and dance which boosts her because of the exercise. Having friends outside of school is also good.
I don't think social media is a major problem. It's more a symptom of problems than a cause imo. I did hold off on letting her have access to stuff too soon, but I also let her persuade me to let Instagram when I couldn't really find fault with her argument. I will take her opinions on board with these things, never do the "no, because I said so" thing. So she feels that her opinions count and that she has a say in the decisions that affect her, while understanding that there may be things that we say no to in order to keep her safe.
I don't think there are any magic formulas. Some kids just have an easier time than others. I think a lot of it boils down to confidence and self-esteem, which is developed when they are much younger, but I think a lot of it is down to innate temperament as well.