The first two phases of the Marvel Cinematic Universe were extremely grounded in reality. Indeed, the key to the very first phase of the MCU was basing almost every superpower in technology, not the supernatural. As Thor notes in 2011’s Thor, “what you call magic we call science.” The limits of that constraint were stretched a bit with 2014’s Guardians of the Galaxy, which took the MCU cosmic, but the truest test of audiences’ willingness to accept the impossible would come with an adaptation of Doctor Strange. The Marvel Comics character created by Steve Ditko and Stan Lee trafficked heavily in the realm of the mystic, marking a significant shift away from the science-based MCU origins. This is the story of how Marvel Studios crafted a mind-bending Doctor Strange movie that still somehow felt like it fit right into the existing MCU.

Given the inherent cinematic quality of the source material, a feature film adaptation of Doctor Strange pre-dates the MCU. One of the earliest incarnations was a screenplay by Back to the Future co-writer Bob Gale, written in the mid-1980s. By 1989, Stan Lee was co-writing a screenplay adaptation with Alex Cox, but that iteration of the project would be undone by studio politics. Then in 1992, fresh off The People Under the Stairs, Savoy Pictures signed Wes Craven to write and direct a Doctor Strange movie. That version eventually fell by the wayside, giving way to an adaptation by David S. Goyer (Batman Begins) that would hang around for quite some time. Goyer was onboard to direct Doctor Strange as late as 2001, but would eventually depart the film in 2002.

By the time Marvel Studios decided to forge ahead with its own adaptations, Paramount Pictures had acquired the Doctor Strange rights from Miramax and it remained an intriguing prospect for the future MCU lineup. While reports swirled that filmmaker Guillermo del Toro and author Neil Gaiman approached Marvel about adapting Doctor Strange themselves only to be turned down, del Toro later contended that their version of this comic book adaptation was nothing more than a “what if” conversation between friends:

“When Neil Gaiman was visiting Hellboy II, he literally said, ‘Wouldn’t it be cool to do Doctor Strange together?’ and I said, ‘Yeah that would be cool.’ (laughs) That was the extent of the discussion, and then four or five weeks later it was like ‘Neil Gaiman and Guillermo Developing Doctor Strange for Marvel,’ and Marvel had never heard of that development and neither have I.”

Meanwhile, Marvel Studios was on the hunt for a director. Those reportedly in the mix included Jonathan Levine (50/50) and Mark Andrews, the latter of whom helmed the Pixar movie Brave, but it was horror director Scott Derrickson who came away with the job in June 2014. Derrickson was coming off the success of his small-scale horror film Sinister and had just directed the horror-tinged crime thriller Deliver Us from Evil. In order to land the job, he spent his own money to create an animatic of an original set piece that Marvel ended up buying and putting into the film:

“I spent a lot more money than was reasonable to get the job… I designed several set pieces. The one that’s in the movie, it was a 12-page scene of the astral fight with Rachel McAdams saving his life [based on a scene from the comic Doctor Strange: The Oath]. So I wrote a 12-page version of that scene, and then storyboarded the whole thing, and then created what’s called an animatic which is a moving storyboard. And then I also created a whole bunch of concept art for other sequences in the movie to try to give an example of what I wanted the visuals to be like.”

When Derrickson was first hired, he wanted to co-write the script with his Sinister co-writer C. Robert Cargill. However, Marvel was insistent upon meeting the film’s planned July 2016 release date and didn’t think Derrickson had time to write the script and direct, especially for someone who’d never made a movie this big before. So Marvel instead hired Jon Spaihts (Passengers) to start working on the script while Derrickson prepped the movie.

The ideal actor in mind to fill the role of Doctor Strange, at least in Derrickson and Marvel’s eyes, was Benedict Cumberbatch. The actor was approached early on, but had to turn the film down due to scheduling conflicts with Sherlock and his on-stage run in Hamlet in London. Marvel needed to get Doctor Strange in front of cameras in 2015, and unfortunately it didn’t appear as though Cumberbatch could fit the film—and its lengthy prep schedule—in.

So Derrickson and Marvel looked elsewhere, and other names considered for the lead role included Tom Hardy, Ryan Gosling, and Jared Leto. By July 2014, just after Comic-Con, word broke that Marvel had entered talks with Joaquin Phoenix to star in Doctor Strange. Negotiations continued, and it looked as though Phoenix was a done deal—until he abruptly pulled out in early October. Phoenix later said he was uncomfortable with the compromises necessary to make a film like that, and reports surfaced that the lengthy press commitments made him uncomfortable:

“There were too many requirements that went against my instincts for character. I’ve been spoiled. I’ve never had to make those compromises. I’ve not met a director yet with one of those films where we go through the script, they say: ‘You know what, fuck this set-piece, let’s focus on the character!’ I understand, but it’s best I don’t do it… I’m not just being difficult. I’m just trying to find what works for me. I don’t want to commit to something and not fulfill those obligations. I enjoy watching those movies. Did you see the rebooted Star Trek? That kid Chris Pine who plays Kirk is fucking genius. I just don’t know if I want to have the experience of being in them. I’ve read some of those scripts and 75 percent is a description of some asteroid going through space.”

So Marvel went back to the drawing board. Leto reportedly pursued the role in the wake of Phoenix’s exit, as did Derrickson’s previous collaborator Ethan Hawke. Jake Gyllenhaal, Ewan McGregor, and Matthew McConaughey were all added to the mix as either actors on tap to meet with Marvel or those Marvel was keen on approaching. But as it turns out, the studio ended up getting its first choice after all.

On October 27, 2014, it was reported that Cumberbatch was not only back in contention, but was in line to take on the role. His casting was made official in December. Marvel had re-approached Cumberbatch in the wake of Phoenix’s exit and when the Star Trek Into Darkness actor showed interest, the studio agreed to push the entire production schedule of Doctor Strange to accommodate Cumberbatch’s prior commitments.

As a result of the new production schedule, Doctor Strange’s release date was pushed from July 2016 to November 2016. Additionally, Derrickson was now able to work on the screenplay himself, and was allowed to bring Cargill onboard to help rework the script—although Spaihts would also return later on to continue working on the screenplay, and even Rick and Morty co-creator Dan Harmon consulted on the film after principal photography wrapped. Kevin Feige explained his involvement:

“He came in, he watched the movie. We are all big fans of his work, clearly. We at Marvel Studios are fans of Community, it’s where we found Joe and Anthony Russo, who came onboard to do Winter Soldier, and of course Civil War, and the upcoming [Avengers] films. So, we’re big fans of that. We’re also fans of his cartoon Rick and Morty, which is about, of course, humor, but I would argue that any given episode of that show has an unbelievably amazing sci-fi concept that could be its own movie. So, really, we just wanted him to watch the movie, and talk to us about it, and give us his opinions on the sci-fi concepts. That was as important to us as any humor that he could add to the movie. And he was very, very gracious in doing that.”

With Cumberbatch secured, Marvel and Derrickson went about assembling what was then the most prestigious Marvel movie cast yet: Tilda Swinton, Rachel McAdams, Chiwetel Ejiofor, Michael Stuhlbarg, and Mads Mikkelsen as villain Kaecilius. Filming finally began in November 2015 in Nepal, before moving to its homebase in the UK.

The film ends SPOLER ALERT with Strange confronting the villainous Dormammu, at which point Strange traps himself in a time loop with Dormammu where the hero dies over and over again, forcing Dormammu to relent. As Spaihts explained how that twist came about, he also indirectly revealed that Kevin Feige was already thinking about the importance of time travel to 2019’s Avengers: Endgame back when they were writing Doctor Strange in 2015: