In 1943, Disney released an eight-minute film titled Reason and Emotion. The film personified the ability to think and the ability to feel as, respectively, a bespectacled, suit-wearing prig and an impulsive, lascivious caveman. “Within the mind of each of us,” intoned the narrator, “these two wage a ceaseless battle” for control of the (in the film, quite literal) mental steering wheel.

Sixty-six years later, when the animator, screenwriter, and director Pete Docter started planning Inside Out, his own film personifying the workings of the human mind, Reason and Emotion was one of the first references he consulted. He’d seen it before, as a cartoon-besotted child, and he remembered admiring its comic boldness. Watching the film again in 2009, however, he saw its limitations.

“It’s actually a propaganda film,” Docter told me during my recent visit to his office at Pixar Animation Studios, in Emeryville, California, across the bay from San Francisco. The room was dimly lit and crowded with whiskey bottles, bags of candy, and memorabilia: a Texas Avery Animation Award; a framed Buster Keaton stamp; a clay model of Kevin, the flightless bird from Up, the second feature film Docter directed. “The basic message was”—here Docter put on a stern voice and furrowed his enormous brow (his colleagues like to sketch him as a sunnier version of Frankenstein’s monster)—“Don’t let Hitler control you with fear!”

Reason and Emotion portrayed humans as automatons, and denigrated feelings as primitive and threatening. Docter knew that he wanted his own exploration of the human mind to put emotions front and center, and to treat them with more nuance. “More nuance” may, in fact, be a radical understatement. Inside Out, Docter’s third Pixar feature and arguably the company’s most ambitious film to date, is as bright and colorful as a Day-Glo pinball machine. But it is also as high-concept, narratively ornate, and psychologically intricate as a Christopher Nolan film—Inception by way of Fantasia.

The movie, which comes out in June, tells two continuously interacting stories. The first story concerns the real-world experiences of an 11-year-old girl, Riley Anderson, who moves with her parents from Minnesota to San Francisco. (Docter is himself a transplant from Minnesota.) The second, interrelated story involves Riley’s five primary emotions: Joy, Sadness, Anger, Fear, and Disgust. They cope with Riley’s travails, and, in a sequence of plot points too elaborate to summarize, two of them (Joy and Sadness) undertake a cathartic voyage through a series of psychological locales, among them Long-Term Memory (described by Sadness as “an endless warren of corridors and shelves”), Dream Production (something like the Paramount lot), Imaginationland, and Abstract Thought.

“The idea was just this concept I had,” Docter told me. “My initial pitch to John”—John Lasseter, Pixar’s co-founder and chief creative officer—“was, You’re in a classroom, you see a kid, and the teacher asks a question. You see the kid almost raise her hand. Then all of a sudden—whoosh!—we zip into the kid’s head, and inside are her emotions.” Her emotions vie for influence. “Optimism says, ‘Oh, we know the answer. Raise your hand!’ Fear says, ‘What’re you, nuts? They laughed at that other kid. They’re gonna mock us right out of class!’ I wanted to dramatize the struggle in making a simple decision: Should I raise my hand or not?

I asked Docter which emotions he’d proposed at the outset. He pursed his lips, thinking back. In addition to fear and optimism, he recalled, he’d suggested anger. “Then I sort of waved my hands and said, ‘And there are some others that I don’t know right now!’ ”

He soon realized that there were a lot of other things he didn’t know. Like how to define emotion—how to distinguish an emotion from, say, a reaction, an impulse, or a state of mind. “All of a sudden I had this big list of questions: What are emotions, anyway? How many are there? How do they work? Where do they live?” And he had still-larger questions: “What is the mind like? Is it like a computer? Is it like a ship, where there’s the captain’s quarters and the machine room? Is it like a theater, where there’s a backstage and an onstage and an audience?” Some of Docter’s colleagues were quick to see what a minefield he was walking into. When Brad Bird, the director of The Incredibles and Ratatouille, heard Docter’s pitch, he told him, “It’s a great idea. I’m glad you’re doing it.”

Fortunately for Docter, Pixar is an uncommonly patient employer, and as he and his team hashed out a viable story, they were also able to hash out the science undergirding that story. They consulted neuroscientists, psychiatrists, developmental psychologists, and brain imagers. The goal was to make certain that the mental landscape they were creating was as believable as possible, within the bounds of artistic and comedic demands.

Circumstances in Docter’s own life gave the effort personal meaning. When he began Inside Out, his daughter, Elie, was 11, and beginning a painful transition to adolescence. Her natural childhood exuberance, Docter said, “kind of took a vacation.” Overnight, or so it seemed to him and his wife, she became morose, reclusive, distant, moody. Watching her brought back powerful memories of Docter’s own adolescent awkwardness and alienation. “I didn’t find a tribe for a very long time,” he told me. “I was off by myself a lot.” Not until years later—after he went to CalArts to study character animation, and even more so after he was hired by Pixar, in 1990, as the studio’s third animator—did he feel he was in his element. “So when I watched my daughter go through that,” he said, “I was like, Oh, crap.” He also found himself wondering, like so many parents on the receiving end of an adolescent’s hard stare, just what in tarnation was going on in there.

In the movie, “in there” takes the form of a sleekly apportioned headquarters—a sort of psychic Space Needle—overlooking the vast terrain of Riley’s mind, where the color-coded Joy (yellow), Sadness (blue), Anger (red), Fear (purple), and Disgust (green) influence and are influenced by Riley’s actions in the real, physical world. They observe her struggles and her successes, call up her memories, keep watch over her dreams, and contend, sometimes fractiously, for control. (Fear: “All right! We did not die today. I’d call that an unqualified success!”) Docter, who has also done voice work for Pixar, playfully impersonated for me some of the other emotional candidates he and his collaborators considered. There was Pride (Docter raises his nose in the air: “You know, like Thurston Howell III”), Schadenfreude (in a pinched German tenor: “Oh, zat’s your pain? I could just scream vith joy”), Ennui (Joy: “Hey, we’re gonna have a great day! You okay with that, Ennui?” Ennui: “Eh”). Other contenders included Awe, Surprise, Shame, Embarrassment, and Contempt. No small part of making the movie, Docter said, was figuring out which emotions to keep and which to jettison.

He pared down the possibilities with the help of two psychologists: Paul Ekman, whose pioneering work on facial expressions inspired the Fox series Lie to Me, and Ekman’s protégé Dacher Keltner, of UC Berkeley. Ekman and Keltner are leaders in what is known as “basic emotion theory,” arguably the dominant theory in the study of emotions. The theory, which has its roots in Charles Darwin’s The Expression of the Emotions in Man and Animals, posits that certain emotions are universal, evolutionarily determined, and functionally discrete. Keltner told me that he was deeply impressed by Docter’s team. He’d assumed they’d have relatively narrow questions (“What shade of green should Disgust be?”). Instead, he found himself in an ongoing conversation about the relationship between emotion and consciousness, the tensions among different emotions, and how emotions live on in memory.

Keltner also said he believed that Inside Out—which he and Ekman had recently seen—could change cultural notions of emotion for the better. Last year, after Docter previewed the movie, Variety predicted that it “could eventually prove to be as revolutionary as Dante’s ‘Divine Comedy,’ which so vividly described the Italian poet’s vision of heaven and hell that it has shaped the public’s image of both ever since.” This sounds like wild overstatement until you consider that the Divine Comedy’s initial audience was in the thousands, while Inside Out’s will number in the millions, most of them impressionable children.

Keltner pointed out the prevailing Western metaphors for emotions have been mostly negative: they’re wild animals or diseases, they’re uncontrollable forces, they can make you crazy. “Now here comes a movie that says, ‘No, emotions have an important role to play,’ ” he said. “ ‘They help us adapt and serve our well-being.’ ” More specifically, Inside Out suggests that even negative emotions have an important purpose. The movie’s central narrative involves Joy’s increasing awareness that Sadness is far more than a pessimistic schlub: She’s vital, even salutary. Riley needs her.

Docter doesn’t make any grand therapeutic claims for the film, but he does like to tell the story of a screening he arranged for the children of the movie’s production crew. The next day, one of his technical directors approached him. The man’s son had been taking swimming lessons, and had been too scared to jump off the diving board. Every day he’d climb the ladder, only to climb back down. After seeing Inside Out, he finally jumped. The movie had given him the idea that if he didn’t like what an emotion had to say, he didn’t have to listen to it. Docter says he hopes that other kids will have a similar experience upon seeing the movie—that they’ll think, maybe for the first time, “Just because I’m angry doesn’t mean I have to act on it, or that I’m controlled by my emotions. My feelings are separate from what I am.”