Nancy Drew is on the case! But this time, the beloved teen detective is solving mysteries while having casual sex, dating an ex-con and — perhaps the most shocking twist of all — battling supernatural spooks.

Premiering on The CW on Wednesday, “Nancy Drew” is the latest take on the young-adult classic. Gritty, dark and salacious, it’s more like the sexy teen drama “Riverdale” than “The Secret of the Old Clock,” the 1930 tale that launched the almost 90-year-old series.

In other words, this isn’t your mom’s — or your grandma’s — Nancy Drew. But it may not be further off than you think.

“Nancy was brash, bold and disrespectful to authority,” said historian Jennifer Fisher of the original girl gumshoe who dominated bookshelves from the 1930s to ’50s. She was breaking into private property, stealing evidence and even outrunning the cops in her trusty blue roadster, going far above the speed limit.

And that’s not all. Nancy Drew has had her fair share of controversies in her nearly nine decades, from the two women who claimed to be the original books’ author, Caroline Keene; to an attempt — in the 1950s and ’60s — to whitewash some of the original series’ racism; to a Playboy magazine centerfold homage.

As Fisher said, “The history of Nancy Drew is almost like a Nancy Drew mystery,” with twists and turns and thrills along the way.

The mystery of Carolyn Keene

In 1942, the teen magazine Calling All Girls ran a poll asking readers to pick their favorite author. At the No. 1 spot? Carolyn Keene, who beat runner-up Louisa May Alcott with twice as many votes. Never mind that Carolyn Keene wasn’t a real person.

Keene — and Nancy Drew — were created by Edward Stratemeyer. A prolific children’s author who couldn’t meet the demands for his thrilling page-turners, Stratemeyer started the Stratemeyer Syndicate, which hired ghostwriters to churn out books based on outlines for series such as the Hardy Boys and Bobbsey Twins. In the late 1920s, he hired a go-getting young woman named Mildred Wirt (later Benson), who was studying journalism at the University of Iowa, to draft a compelling mystery out of a 3¹/₂-page outline about a 16-year-old sleuth named Nancy Drew.

“She was a 1930s newspaper reporter with a very wry sense of humor,” journalism professor Carolyn Dyer says of Benson, whom she befriended. “She was an appealing character herself.”

Benson imbued Nancy with her own pluckiness, spunk and bravery. Benson, who died in 2002, was not only a reporter, but an aviator and amateur archeologist who was once kidnapped during an expedition to Guatemala. “She told me she got out of it by thinking, ‘What would Nancy Drew do?’ ” Fisher said.

Benson ended up writing 23 of the first 30 volumes in the series, long after Edward Stratemeyer died in 1930.

Yet by the 1970s, several newspapers and magazines were touting another woman — Stratemeyer’s oldest daughter, Harriet Adams — as the original Carolyn Keene.

Adams had taken over for her father, supplying all her “ghosts” with detailed outlines and — once Benson quit in 1953 — taking over as Carolyn Keene herself. As Nancy Drew grew more and more popular, Adams began to give interviews referring to the character as her “daughter,” and taking credit for her creation, much to Benson’s chagrin.

“I don’t think [Adams] did it maliciously,” said Melanie Rehak, author of “Girl Sleuth: Nancy Drew and the Women Who Created Her.” “I think she felt that she had shepherded this series, which she did, and … that she rightfully owned the character.”

“By the same token, I think Mildred was perfectly fine not letting anyone know [she wrote the early books] until it suddenly became a story,” said Rehak, adding that the feud is ongoing among Nancy Drew fans. “There’s still a whole ‘whose side are you on’ thing.”

It all came to a head in 1980, when Benson appeared in a court case involving Nancy Drew’s two rival publishers, brandishing documents proving that she wrote the original series.

When Adams saw her feisty nemesis, she turned white. “I thought you were dead,” she said.

The hidden cleanup

However, many young women encountering those classic yellow-spine editions for the first time aren’t actually reading Benson’s unabridged versions.

In 1959, Grosset & Dunlap, which published the Stratemeyer books, asked Adams to revise the original Nancy Drews — not only to make them shorter and snappier (they had to compete with television) but to update Nancy’s clothes and cars, as well as her casual racism.

Gone were the cloche hats, as well as slurs like “colored” and “darky” (which Nancy’s sometime boyfriend, Ned, calls someone in 1939’s original “Clue of the Tapping Heels”), as well as the portrayals of black people as “alcoholic” and “lazy” and Jews as “shifty” and “miserly.” In “The Mystery at Lilac Inn,” from 1931, Nancy realizes a “dark-complexioned” character’s involvement in a crime when she sees her at a fancy dress shop. “Surely a girl in her circumstances cannot afford to buy dresses at such a place as this,” she thinks.

Although instead of imbuing these minority characters with some dignity, Adams just made them white or cut them out completely.

Adams also made Nancy more like her and less like Benson.

“The books became more educational, and Nancy more wholesome,” said Fisher. “She was more controlled and more deferential to authority figures.” Instead of speeding like a bat out of hell to escape the cops in her roadster, she would drive her little blue convertible “as fast as the law would allow.”

Oh, and she no longer carried a gun.

Benson complained that Adams “took the spice out.”

The secret of Nancy Drew, centerfold

The effort to sanitize Nancy’s image backfired in the 1970s. In 1977, a new Nancy Drew TV show debuted, starring the young ingenue Pamela Sue Martin, and Adams fought hard to remove even the slightest whiff of sex, drugs or violence.

“Nancy Drew never cried or experienced an inordinate amount of pain,” Martin would later complain. “Never a kissing scene or any sign that she would indulge in the opposite sex.” The most exciting thing allowed, she added, “was coming across an old skeleton in a dungeon and screaming.”

Viewers didn’t watch it. When the network decided to combine the Nancy Drew TV show with the Hardy Boys, thus reducing Martin’s role, the actress quit — and posed for Playboy in a strategically tied trenchcoat, and nothing else. She also told the reporter that she found Nancy Drew “bulls- -t.”

Adams “had an apoplectic fit,” said Fisher. She wrote to Playboy threatening legal action for using Nancy Drew’s name in such a salacious way. She then took out a costly ad in Time magazine reprinting the apology from Playboy and doubling down on Nancy’s niceness. The show was canceled in 1979.

But Nancy Drew’s newfound moxie stuck. Since Adams’ death in 1982, the character’s books have gotten racier. “The Nancy Drew Files” in the 1980s had grisly murders. “Nancy Drew on Campus” in the ’90s had a lot of partying and very little sleuthing. Even Martin, who complained of the character’s one-dimensionality to Playboy, is on board for the CW show, playing a mystic who helps Nancy in her quest to solve a murder in the pilot.

“There’s certainly a lot of other choices for brave, strong girl characters [than there were] in 1930, yet Nancy Drew is weirdly more relevant than ever,” Rehak said. “She’s a brave, smart, independent girl, and she still embodies [those qualities] that are still so important to women.”