How do you write a love song that’s also a lament for the impending end of the world?

That was the challenge for “Don’t Look Up” composer Nicholas Britell, lyricist Taura Stinson and their co-writers and performers, Ariana Grande and Kid Cudi, as they collaborated on “Just Look Up.” The song is performed in the film and is on the Oscar shortlist for possible nomination in February.

The idea came from writer-director Adam McKay, Britell reports. Grande had already been cast as Riley Bina, a pop star who reconciles with her rapper boyfriend (Kid Cudi, as DJ Chello) on the same morning talk show where astronomers (played by Leonardo DiCaprio and Jennifer Lawrence) reveal that a comet is on a collision course for Earth.

“I was imagining it as a power ballad in a sense, a very strong, very powerful song of hope about love, and then a rallying cry,” says Britell, a two-time Oscar nominee whose previous McKay films include “The Big Short” and “Vice” (and who is also on the shortlist for his “Don’t Look Up” score).

Britell visited Grande and “gave her the outline of the track,” the composer recalls, “and about 30 seconds later, she essentially laid down the entire top line vocal. It was one of the most remarkable things I’d ever seen.”

Popular on Variety

“He sent me into the booth to try a melody pass,” confirms Grande, “and that ended up being the pass that we wrote the lyrics to. It was really fun to hold up a mirror and acknowledge some of the ridiculousness that is so real in this world and what comes with it.”

The next step was enlisting Stinson, the Oscar-nominated songwriter (“Mighty River” from “Mudbound”) who had previously collaborated with Britell on a Florence + The Machine song for “Cruella.”

“A believable love song with the whole world ending in disaster — a bit of a challenge,” Stinson concedes. “But Ariana’s melody and Nick’s musical bed were so beautiful, and [the film] was such a great inspiration for everything that’s going on in the world, it was easier to write than a lot of songs.”

Grande improvised a few lines (including “you’re about to die soon everybody”), but Kid Cudi’s rap — “reconciling after a big breakup, and the world is ending [while] he’s having this special moment with the girl of his dreams,” he says – sets up Grande’s more serious plea: “get your head out of your ass and listen to the goddamn qualified scientists!”