‘Growing up,” says Kayleigh Llewellyn, “my mum had bipolar disorder type one. So quite severe. The love you have for your mother or father is so deep-seated, there’s a contradiction: you love the person, but you also feel ashamed of them, because you’re a teenager and you don’t know any better.”

Llewellyn has poured this experience into In My Skin, an emotional rollercoaster of a TV drama about Bethan, a Welsh teenager coming of age and living a double life as she negotiates mental illness, friendships and her sexuality. Bethan’s mother Trina has bipolar disorder and is sectioned in a psychiatric ward. In an early episode, Trina says something so horrible to Bethan that I gasped out loud in my living room. At other times, the sympathy I feel for her has me weeping. But there are plenty of laughs along the way.

Bethan shoulders much of the burden of her mother’s illness alone, although her gran and a kindly but interfering PE teacher do try to help. She’s ambitious and dreams of being a writer, while trying to survive in a hostile and homophobic school. She also desperately wants to impress popular girl Poppy, on whom she has a crush, lying about her home life even to her closest friends, portraying it as secure and middle class.

“I lived in fear that kids in my school would find out my mum was frequently being sectioned,” says Llewellyn. “I thought they would make fun of me, ostracise me – or even worse, make fun of my mum.”

Facebook Twitter Pinterest ‘I just could not afford to live any more’ … Llewellyn. Photograph: Karla Gowlett

Llewellyn initially trained as an actor and didn’t start writing until she was 27. “Growing up, I didn’t know any actors, and I certainly didn’t know any writers. I didn’t know writing was a job.” It was only when she started acting and realised that the words were what really drew her that she began to write.

Another script, co-written with a friend, won the Bafta Rocliffe New Writing comedy award in 2012 and helped her secure an agent. “For once in my life I got really bloody lucky,” she says. “I went from not being a writer at all to having a commission for a primetime BBC One show.”

That series didn’t happen in the end: Llewellyn is keen to point out that her screenwriting journey hasn’t been an entirely easy one, even if she does now find herself in the writers’ room for Killing Eve. “About three years ago, I was so broke. I’d gone through six deaths in my family in the course of the year. And you really feel the weight of being an underclass person. I had no security blanket.

Within an hour of sending the pitch, I thought: 'Oh my God, I've exposed myself too much'

“I was continuing trying to write Casualty while dealing with the most intense grief and setting up funerals. I just could not afford to live any more. I thought: ‘I can’t be a writer right now.’ Luckily someone recommended this charity – the Film and TV Charity. They kept me going. They paid my rent for a few months, gave me subsistence.”

In late 2017, after another failed project, Llewellyn rattled off a one-page treatment based on her childhood experiences of caring for her mother – and emailed it to several producers. “Within about an hour, I had that feeling of regret, thinking: ‘Oh my God, I’ve exposed myself so much’.”

Seven out of 10 wanted to option it. Within a week, producer Nerys Evans – who is also Welsh with a working-class background – had persuaded the BBC to commission the pilot, which won two Bafta Cymru awards including best TV drama. The show was then greenlit for a full series.

In My Skin was shot in Cardiff, a few streets from where Llewellyn grew up. How does it feel to see her life played out on screen? Was it necessary to keep a bit of distance? “To a degree, I did have to,” she says, “so that I felt free to tell a good story.” She decided it would be too strange to film in her old school, and she made Bethan an only child. “Jo Hartley, who plays Trina, and I made a choice that she would never meet my mum. I didn’t even show her a photograph until after we finished shooting. We wanted to create this woman in her own right.”

Facebook Twitter Pinterest ‘I can’t hold my mum to account for the things she said when she was unwell’ … In My Skin. Photograph: Tommy Forbes/BBC/Expectation TV

Hartley’s performance has been praised for its authenticity. “I gave it everything, my heart and soul,” the actor says. “It’s the only job where I’ve gone to these lengths. It was such a responsibility. It was about visualisation, breath work, and lots and lots of research, and I was able to use emotional recall from personal experiences.”

Hartley watched videos of people with hypomania, and had in-depth chats with Llewellyn and others who had experience of bipolar disorder. On set, she was isolated from most of the cast and crew and didn’t wash her hair, staying in character for the duration. “We came up with a scale of one to five,” says Llewellyn. “Bipolar has stages– you’re not just hypomanic all time. So Jo could be given this number for the level of her mania. And then we had an amazing doctor based in Cardiff who specialises in bipolar patients, who read all of our scripts and gave advice.”

Llewellyn’s sister also read all the scripts and gave her blessing, but her mother was very ill when they were shooting the pilot, and did not watch it until two weeks after it was first shown on BBC Three. “She was in Wales and I was in London and I was on the edge of my seat feeling sick waiting for the phone to ring. Eventually she called and said, ‘I’m so proud of you’.”

Was there a temptation to dial down some of the more shocking things Trina says, to give a more sympathetic portrayal? Llewellyn says not. “I want people to have the takeaway that Trina is a kind woman and a good mother who’s very ill. I hope I struck that balance. But to give an accurate representation of what it is to care for someone who’s mentally ill, you have to show it warts and all.

We wanted to recreate the Wales we knew: you can be on a grotty street, but the vista around you is beautiful hills

“We all know there is something we can each say to our mother, our sister, our partner, that would cripple them, but of course you love them, you don’t want to hurt them. When you’re with someone who is ill, they don’t have that filter. I can’t, when my mum is well, hold her to account for the things she said when she was completely unwell and that she has no memory of. You just have to absorb it. I’m sure that there are lots of people who struggle to, and I have, to a degree. But you won’t ever get an apology.”

Llewellyn’s father died in 2015. They had been estranged for 10 years. In the show, Bethan also faces occasional cruelty from her dysfunctional father, an alcoholic Hell’s Angel who drives a rag and bone truck. He’s played by Rhodri Meilir.

Having grown up in Wales, which has some of the poorest estates in western Europe, seeing the poverty and deprivation she knew portrayed accurately on screen was a new experience for Llewellyn. She says you either have the comedies, such as Gavin and Stacey and Stella, or dramas such as Sex Education and The End of the F***ing World, which are shot in Wales but look like America.

“No disrespect to those shows, but Nerys and I talked a lot about wanting to recreate accurately the Wales we knew. You can be on a really grotty disgusting street that has old mattresses thrown out and litter everywhere, but the vista around you is the most beautiful green hills. The two live side by side. And the things that Gavin and Stacey and Stella captured, those warm, broad characters, that to me is real. We wanted that, but also the grittier side – people struggling on the breadline and struggling to find good mental health care.”

In My Skin has plenty of comic relief, particularly from Bethan’s gran. “I love the phrase ‘Make ’em laugh, make ’em cry’,” says Llewellyn. “Mostly because I think that is life. And it comes naturally to me. Like lots of people who’ve been marginalised or have something to hide, you deflect with comedy. I’ve done that my whole life.”

Facebook Twitter Pinterest Assassin … Llewellyn is also a writer on Killing Eve. Photograph: Robert Viglasky/Sid Gentle Films

She’s influenced by Jill Soloway, whose show Transparent perfected that mixture of belly laughs and gut punches. She thinks diversity in the TV industry is slowly improving and that, as a working-class lesbian Welsh woman, it’s a good time to be “a box tick” because broadcasters are now interested in diverse stories. “People are talking so much more about mental health issues, which is such a big part of the battle – that people feel able to discuss it and not hide in the shadows. But there is a long way to go.”

She adds: “My mum, to this day, having been a mental health patient for over 30 years, has still never been offered talking therapy. It’s just extreme medication. I love the NHS. It’s kept my mum alive. But they’re spread so thin, they can’t offer something that would be so useful.”

As for the show, she says: “I hope that anyone who has either mental health issues or has been a carer for a mentally ill person just feels seen. That they watch it and say ‘Someone gets me’ – and feel a hand on their shoulder.”

• In My Skin will be available on BBC Three and iPlayer on 29 March. The series starts on BBC One and BBC One Wales on 1 April at 10.45pm. It airs on Hulu in the US from 30 July