The fantasy hit Rachel Bloom a few months ago as she was taking a midnight Epsom salt bath in her Los Angeles home.
"We were searching for an emotional high type of song toward the beginning of episode [three of Season 2]," the co-creator and star of the CW musical comedy "Crazy Ex-Girlfriend" recalled of her late-night brainstorming/bathing session.
Now in its second season, "Crazy Ex-Girlfriend," follows the travails of high-powered New York lawyer Rebecca Bunch (Bloom), who impulsively moves to West Covina to pursue her former summer camp beau, Josh Chan. As the first season unraveled, she developed feelings for Josh's best friend Greg, and things ended on a complicated note.
"There was kind of a self-indulgent hubris, where she truly thinks she has two men in love with her," said Bloom of her quest to capture the sound of that romantic delusion musically. "She thinks she is the center of everything. That's 'Diamonds Are a Girl's Best Friend.' That's Marilyn Monroe. That's a '40s song where you're surrounded by boys."
So when inspiration struck, she did what any good songwriter on a deadline would do: She reached for her laptop that sat on her bamboo bath caddy and started jotting down lyrics.
It wasn't long before the show's music producer, Adam Schlesinger, received a voicemail with Bloom's bare-bones rendition of this week's big musical number, "The Math of Love Triangles," which finds Rebecca cooing in a baby-doll voice — a la Monroe in "Diamonds" — about what a hardship it is to have two guys in love with her.
Though it has a modest following, "Crazy Ex-Girlfriend" has charmed critics with its inventive use of songs that offer sharp commentary and satire (e.g. "The Sexy Getting Ready Song" about the unmitigated un-sexiness of making oneself sexy, and "I'm the Villain," a Disney send-up that confronts Rebecca's anti-heroinedom).
The razzle-dazzle of the show's musical moments has not gone unnoticed — the show won an Emmy for choreography and received nominations for original main title theme music and original music and lyrics.
The comedy, which now airs Fridays at 9 p.m., has featured more than 50 original compositions — with a mix of styles that include rap, jazz, pop, and R&B — that work both as stuck-in-your-head, sing-along pop song and as parody.
Two digital compilations of music from the first season are available on iTunes and Spotify, as well as tracks that have appeared thus far in Season 2. Producers are even working on karaoke versions of the songs for fans who want to get in on the quirky fun of the world that Bloom has created with Aline Brosh McKenna.
There are typically two to three musical numbers per episode — a drastic increase since Bloom's days of creating incisive and goofy viral tunes on YouTube.
"That was a different, much smaller animal," said Bloom during a break from production on the musical sequence from the show's North Hollywood set. "This is a lot. A lot on limited schedule."
Music producer Steven M. Gold said, "It takes maybe a couple of weeks between the demo phase and the orchestration. We listen to a demo of the orchestration with synthesizers and we make changes on that. And then we also make changes on the fly when we do the recording."
But it's a process the show's songwriting team — Bloom, Schlesinger (formerly of the pop music group Fountains of Wayne of "Stacy's Mom" fame), co-producer Jack Dolgen, who collaborated with Bloom on her YouTube catalog — has worked hard at perfecting.
First things first: The story has to be formed. Songs are crafted to suit the plot, not the other way around.
"We spend most of our time figuring out where the song should be in the episode, which character should have the moment," Dolgen said, "and what style the song should be."
Sometimes the process is arduous. "Women Gotta Stick Together" was a third or fourth attempt at finding Valencia, Josh's girlfriend and Rebecca's nemesis, a song in episode nine of the first season. Other times it's a snap. A number from the second season premiere, "We Should Definitely Not Have Sex Right Now," was written in less than 20 minutes — replacing a ditty about the symbol of drawers in a relationship that had been painstakingly belabored.
"The hardest part of writing these songs is landing on the specific idea," Bloom said. "Once we've landed on it, then stuff starts rolling. And there's editing and there's tweaking and there's rewriting. But there's a kind of rolling down the hill that you feel once you hit on the right comedy premise."
And given that the show airs on the CW, a bit of creativity is sometimes needed when trying to get certain aspects of those premises to pass Broadcast Standards and Practices. For example, with "The Math of Love Triangles," the line, "Are you erect?" could only pass muster if Bloom's Rebecca was physically adjusting the posture of a dancer.
While it's important to craft a tune that is catchy and can stand on its own, the real goal is to have the comedy land without competing with the music or choreography for attention.
"When you do comedy music, it's a different head space than if you're just doing music," Schlesinger said. "Because there's a lot of really interesting and awesome sounds, that if you're just making a record, you would keep. We're mostly thinking: Is something going to distract from the joke? You don't want anybody to mostly be thinking about the music at all. It's the straight man of the joke."
Choreographer Kathryn Burns, who also worked with Bloom during her YouTube days, said all the choreography on the show is catered to the jokes.
"The funny is always going to beat out the dance," she said. "You have to think of what the camera is going to focus on at what point and what the facial expressions are going to be. It all has to be very specific."
On the day of production of "The Math of Love Triangles," Bloom was concerned that she might be revealing too much side boob because of her blue strapless gown or that the male dancers should be more expressive with their facial reactions.
After a take was complete, she slipped out of her character's strappy heels and into some slippers to watch a playback.
"I think it's great," Bloom said. "It all came together!"
Translation: "Crazy Ex-Girlfriend" fans might have another earworm come Friday.
When: 9 p.m. Friday
Rating: TV-14-DL (may be unsuitable for children under the age of 14 with advisories for suggestive dialogue and coarse language)