Sitting in a sweltering marquee in Avilés, Spain, at July’s Celsius 232 sci-fi festival, Margaret Stohl is telling a packed audience, made up almost entirely of teenage girls, that in comics at least, it’s a great time to be a woman.

She’s here to talk about The Life of Captain Marvel, her five-part comic series that is set to reveal the origin of the complex and contradictory character before her movie hits screens in 2019. But right now, what Stohl really wants to do is make all the women in this room understand what a superhero is.

“What makes a character strong is not necessarily physical power,” she says to the excitable crowd. “I feel the human sentiment in our stories very strongly. We still have a lot of work to do for representation in heroes but I’m convinced our teams and our fans will demand it – we must. That’s why it’s one of the best times to be a woman hero, to be a trans hero, to be a gay hero.” The whole tent erupts into cheers and applause. Stohl slumps back in her chair, smiling and satisfied.

Stohl has spent her whole life quietly shaking up patriarchies. Born in Los Angeles into a staunchly conservative Mormon household, as a child she was “not exactly encouraged to be a writer”. But after falling in love with Susan Cooper’s The Dark Is Rising series, she was determined to write regardless, studying literature at Amherst college, creative writing at UEA in England and then gaining a literature master’s at Stanford.

‘Not exactly encouraged to be a writer’ … Margaret Stohl

Now best known as the co-author of the Beautiful Creatures young adult novels, Stohl got her break writing video games, including Activision’s much-loved Spider-Man tie-in, then ran her own development studio for 10 gruelling years (“Every day was an acid bath; you’re just trying to make payroll.”) In 2016, Marvel approached her to write a couple of novels based on the Avengers’ pitiless assassin Black Widow. But Sana Amanat, Marvel’s director of content and character development who was also overseeing the studio’s diversity record, had bigger plans for her. “Under her purview, they’ve gone from having zero female-led titles to more than 20,” says Stohl. “She called me and said, ‘I think you should write a monthly comic and I think it should be Captain Marvel.’ Marvel wanted to set out a clear origin story – that was my job.”

Created by Stan Lee and Gene Colan, the original Captain Marvel was a man – or more accurately a male, alien soldier – named Mar-Vell, who was sent to Earth to observe humanity at the dawn of its space-travel ambitions. With super-strength and the ability to fly, he was the closest Marvel came to DC’s Superman – and like Superman, the character caught the romantic attention of Earthling women, including one US air force major named Carol Danvers. Danvers later gained her own super-powers when she was caught in an explosion involving an alien artefact, and in 1977, amid the rise of second-wave feminism, she resurfaced in a new comic series as Ms Marvel, before finally taking on the title Captain Marvel in 2012.

As any woman will tell you, there’s almost a biological response to seeing Rey in Star Wars wielding a lightsaber

It’s the Danvers version of Captain Marvel that we’ll see portrayed by Oscar-winner Brie Larson on screen next year. While her powers are impressive (flight, super-strength, the ability to project energy with the force of a nuclear explosion), it’s her story that is interesting. Danvers grew up with an abusive father who forbade her from attending university, and after joining the Avengers, she was abducted and raped by a supervillain named Marcus Immortus, in one of the most controversial storylines in Marvel’s history. Later, she lost her powers, regained them, and battled alcoholism and anxiety. If any character symbolises the troubled history of women in mainstream comics, it’s Danvers.

“I’m interested in this idea of who gets to be the hero,” says Stohl. “Carol was literally a side character. She was there to be a pretty girl. She has a very messy hero’s journey, but then that’s also the journey of women in comics. That’s what it was like for me and a lot of other women writers – you don’t necessarily come in to the scene thinking you’re a star or even a main character. As any woman will tell you, there’s almost a biological response to seeing something like Rey in Star Wars wielding a lightsaber or Wonder Woman doing Matrix-style bullet-dodging. We don’t get those experiences very often.”

‘I never know if I’m beating the memories’ … a page from The Life of Captain Marvel. Illustration: Marvel

But Stohl won’t be shying away from the underlying vulnerability of the character. The Life of Captain Marvel begins with Danvers suffering a panic attack – triggered by Fathers’ Day – and then heading back to her family home to confront her past. “I think people who are vulnerable but still rise to the challenge are more heroic,” she says. “Marvel is very good at this: Tony Stark is one of my favourite characters to write, and he’s as cracked as they come. Peter Parker is a mess, Thor is a mess, Hulk is a mess. The second I took over the Captain Marvel run, I sent Carol to therapy on board the Alpha Flight space station. I feel like, my God, you’d be in therapy the rest of your life if you had to do half the things these people do!”

After her Celsius talk, Stohl spends a long time chatting with fans, signing copies of her books and making herself available for selfies. Elsewhere, she runs two major young adult fiction festivals in the US, and lectures on creative writing at schools around the world: when she talks about empowering young women writers, she really lives it.

As both she and her interpretation of Captain Marvel move into the spotlight, she knows she’s likely to face a rocky time. Progressive ideas and creators aren’t always welcome in comics: the arrival of a Pakistani Ms Marvel and a female Thor in 2014 generated an intense online backlash. In 2016, Marvel writer Chelsea Cain was hounded off Twitter when her character Mockingbird wore a T-shirt bearing the phrase, “Ask me about my feminist agenda.”

But to this, she shrugs. “It’s a great time to be a female creator, but that doesn’t make it an easy time,” she says. “I’m getting through to people in vulnerable populations every time I write a strong girl or a strong LGBT character. Kids are seeing themselves as Wonder Woman, they’ll see themselves as Captain Marvel. Even if there is a backlash, young people are listening, they want it. This is for them.”

• The Life of Captain Marvel #1 is out now, with monthly issues to follow.