From left, Lili Reinhart, KJ Apa, Cole Sprouse, Ashleigh Murray, Madelaine Petsch and Camila Mendes play younger versions of their TV parents in the flashback episode of "Riverdale." (Dean Buscher/The CW)

Warning: This post contains spoilers for “The Midnight Club,” an episode of “Riverdale” that aired Wednesday.

There is little about “Riverdale,” the CW drama based loosely on the Archie comics, that feels planned. Since it wrapped the first season’s murder mystery, the show has veered off course with little consequence — somehow, each random thing that gets thrown our way only contributes to the delightful absurdity of it all. (Remember when Veronica suspects Sheriff Keller is the Black Hood but then flirts with him? Or the entire Red Circle subplot?)

But it turns out Wednesday night’s flashback episode was in the works for quite some time. Showrunner Roberto Aguirre-Sacasa recently revealed the writers had planned to do one since the very beginning. The overall aesthetic of “Riverdale” is already quite retro, exhibited by everything from Betty’s frequent overalls to the gang’s neon hangout spot, Pop’s Diner. The show even plucked the actors who play Riverdale’s concerned and sometimes-conniving parents from ’90s hits like “Twin Peaks” and “Beverly Hills, 90210.”

The “Midnight Club” episode pays homage to that era by having the main cast members play younger versions of their TV parents. Flashbacks, narrated by Alice Cooper (Mädchen Amick), take place in her junior year of high school: “Phones had cords, Winona had Johnny and everything smelled like Teen Spirit,” she says. They depict what happened when her generation first discovered Gryphons and Gargoyles, an addictive board game that resurfaced more than 20 years later and led two current Riverdale High students to kill themselves. Her story begins with Saturday detention and, in a nod to “The Breakfast Club,” features characters from different cliques who bond during their time together.

Here’s a closer look at the characters — whose names are paired with how Alice describes them — and how the actors modeled them after their TV parents' former roles.

Lili Reinhart as Alice Smith (“The Bad Girl”)

Lili Reinhart as Alice Smith. (Katie Yu/The CW)

Before she married Hal Cooper, Alice was a tough, secretive and probably foul-mouthed member of the Southside Serpents. (Network television doesn’t allow for much certainty on that last one, but it feels right.) In the episode, she does things like get into fights in the school bathroom but eventually exhibits the strong moral compass she shares with her daughter Betty.

“Riverdale” has long been compared with “Twin Peaks” because of the first season’s plot and overall similar imagery, but the most solid commonalities are the existence of determined Coopers and the presence of Amick. The actress was 19 years old when she started playing Double R Diner waitress Shelly Johnson — just a couple of years younger than Reinhart, who studied Amick’s mannerisms in the David Lynch series to prepare for “The Midnight Club.”

Dark lipstick, perfect hair and an air of confidence? Check, check and check.

KJ Apa as Fred Andrews (“The Artist-Athlete”)

Camila Mendes as Hermione Gomez, left, and KJ Apa as Fred Andrews. (Dean Buscher/The CW)

Luke Perry, who plays Fred Andrews, is among the most low-key members of the “Riverdale” cast when it comes to his off-screen presence. But at the show’s start, he ranked high in star power. Perry rose to fame playing bad boy Dylan McKay throughout the ’90s on the incredibly popular “Beverly Hills, 90210.”

That character contrasts starkly with Fred, who is the most rational character on the show and seems to have always been a good egg. His character’s main struggle — before Gryphons and Gargoyles, at least — is choosing between sports and music. Not too different from his boy Archie, eh?

Apa nails Perry’s smolder and head tilts, while the hair and wardrobe departments perfected the slicked-back hairdo and blue-on-blue outfit.

While neither she nor her character appear in this episode, it’s worth noting that Molly Ringwald, queen of ’80s teen cinema, regularly appears on the show as Archie’s mother and Fred’s estranged wife, Mary Andrews.

Cole Sprouse as Forsythe Pendleton Jones Jr. (“The Ladies Man”)

Camila Mendes as Hermione Gomez and Cole Sprouse as FP Jones. (Katie Yu/The CW)

Yes, that is FP Jones leaning into Hermione. Weird, right? But don’t worry, he and Alice still share a number of scenes.

Cole Sprouse refrains from yelling “BOY!” at anyone in the same tone FP (Skeet Ulrich) uses to scold Jughead, but he has the look of quiet desperation down pat. Young FP looks remarkably similar to Ulrich’s “Scream” character Billy Loomis, complete with the casual T-shirt and greasy hair — but without the bloody hands.

Camila Mendes as Hermione Gomez (“The Rebelling Catholic”)

From left, Madelaine Petsch as Penelope Blossom, Lili Reinhart as Alice Smith, Ashleigh Murray as Sierra Samuels and Camila Mendes as Hermione Gomez. (Katie Yu/The CW)

Marisol Nichols wasn’t as high-profile a ’90s star as some of her “Riverdale” peers, though she did star as Audrey Griswold in the 1997 movie “Vegas Vacation.” A quick IMDb search shows that she coincidentally also appeared in an episode of “Beverly Hills, 90210” and “Scream 2.” Young Hermione looks more like a lost backup dancer from the “ . . . Baby One More Time” video than anything, which Camila Mendes alluded to on Instagram.

(Side note: Who used lipstick to write “End Apartheid” on that mirror?)

Ashleigh Murray as Sierra Samuels (“The Political Animal”) and Madelaine Petsch as Penelope Blossom (“The Teacher’s Pet”)

From left, Ashleigh Murray as Sierra Samuels, Madelaine Petsch as Penelope Blossom and Camila Mendes as Hermione Gomez. (Dean Buscher/The CW)

Robin Givens normally plays Sierra McCoy, the hardheaded former mayor of Riverdale, and Ashleigh Murray plays her daughter, Josie. Givens starred in a few major roles, such as the spoiled Darlene Merriman in “Head of the Class,” but Murray still had quite a challenge ahead of her.

Nathalie Boltt, a South African actress American viewers would likely only recognize as Penelope Blossom, wasn’t active in film and television until the 2000s. But we simply couldn’t leave the spectacled Madelaine Petsch off this list.

Michael Consuelos as Hiram Lodge, and everyone else

Charles Melton as Marty Mantle and Michael Consuelos as Hiram Lodge. (Katie Yu/The CW)

Charles Melton plays his character Reggie’s dad, whose name is apparently Marty and who “Riverdale” fans don’t really care about because we barely know anything about Reggie himself. Casey Cott also shows up as Sierra’s secret boyfriend, a sack lunch-toting Tom Keller. (Yes, Kevin’s dad has a first name, and it isn’t Sheriff.)

Michael Consuelos guest stars as Hiram Lodge, who is normally played by the actor’s father, Mark Consuelos. Kelly Ripa, matriarch of the Consuelos family, announced on Instagram Tuesday that she would soon appear on the show as Hiram’s mistress. Looks like “Riverdale” has become the family business. How very Lodge of them!

The episode’s most exciting guest star, however, is one whom younger viewers might not recognize as quickly: Anthony Michael Hall. The “Breakfast Club” star plays Principal Featherhead, the Mr. Vernon equivalent whose last name rivals the Riverdale-ness of Principal Weatherbee’s. See for yourself:

Anthony Michael Hall as Principal Featherhead. (Katie Yu/The CW)

Read more:

Netflix’s ‘Élite’ is the scandalous teen drama you deserve

From ‘Riverdale’ to ‘Scrubs,’ here’s what makes a good musical episode

How teen drama ‘The O.C.’ launched indie bands into musical stardom