The first thing to point out, because it's really amazing the more you think about it, it's a miracle that Pixar Animation Studios' 15th feature, Inside Out, functions at all. It's a feature-length metaphor, in which everything we're watching as the story isn't "actually" be happening, possibly not even within the world of the film. Most of the characters are literally concepts rather than psychological actors in their own right. The driving conflict is "there's a ticking clock and we have to get back before it runs out", or basically the third act that's always the most uninteresting part of Pixar movies stretched out to the full length of the 94-minute film

Regardless, it's Pixar's most effective and most moving feature since the six-year-old Up, and while I think the "Pixar's best!" chatter that you can find here and there is premature, it's very easy to see why somebody would want to promote that opinion. Surely, it's the most ambitious film in the studio's history: it's a feature-length metaphor, after all, which isn't something for the squeamish. Specifically, it's a metaphor about the processes of human memory and emotions in a time of extreme stress both environmental (moving to a new city) and biological (doing so at the very earliest years of adolescence), setting up shop in the mind of an 11-year-old girl named Riley (Kaitlyn Dias) and literalising the concepts of cognitive theory as physical spaces for the adventures had by her five core emotions: Joy (Amy Poehler), Sadness (Phyllis Smith), Anger (Lewis Black), Disgust (Mindy Kaling), and Fear (Bill Hader). Who are also literalised, as color-coded humanoids made out of quantum particles that you can just barely see in close-ups as a mottled, almost fuzzy surface of tiny floating spheres.

The actual "what really happened" plot is that Riley has just moved from Minnesota, where she loves her friends and adores playing hockey, to an old rundown building in San Francisco. Picking up on the extreme frustration and stress felt by her father (Kyle MacLachlan), whose business - the reason they moved in the first place - is hitting a potentially fatal snag, and her mother (Diane Lane), helplessly trying to track down their missing moving truck and clearly none too happy about being uprooted herself, Riley tries to force herself to be the same happy-go-lucky child her parents have always praised her for being, but this quickly curdles into a perpetual state of peevishness marked by bursts of terror, and eventually she decides to run away back to Minnesota. And as she does so, she slides into a depressive state where she can barely feel anything at all.

But ah! the way that Inside Out chooses to tell that story is gorgeous and complicated and crazily imaginative: inside the control room of Riley's mind, which has been the domain of the upbeat, bullying Joy for all of recorded history, an accident has sent her and Sadness spiraling into the recesses of Riley's memories, leaving the ill-equipped Anger, Fear, and Disgust to run the show. Meanwhile, Joy and Sadness journey through Riley's headspace, finding her subconscious, her imagination, and the chasm where all of her lost memories are dumped, never to be retrieved again, escorted by the cotton candy-cat-elephant-dolphin hybrid Bing Bong (Richard Kind), Riley's mostly-forgotten imaginary friend. The film presents all of the mercurial and abrupt shifts of personality that accompany being 11 and thrust into a new life as the results of the emotions' desperate attempts to find a solution to their predicament, with everybody (and especially Joy) anxious to get back to the unmixed state when Joy wouldn't let anybody else call the shots. Though with Sadness's shocking, newfound ability to alter the nature of Riley's memories just by touching them, it's clear to us long before the emotions are willing to admit it that Riley's days of unmixed joy are behind her.

The idea that our thoughts and feelings are sentient creatures bumbling around in our heads isn't new, of course: the earliest cinematic version I can name is the 1943 Disney WWII propaganda cartoon Reason and Emotion, and the image of the mind as a person sitting in the body directing it is an ancient one. But Inside Out is as perfect a filmed depiction of that hook as has ever been made, coming up with an expansive, highly creative world of intricately worked-out rules to explore the concepts of cognitive psychology in a simplified, even fabulistic way. It does an extraordinarily good job of establishing its world one piece at a time, so we grasp the basic vocabulary intuitively enough that when the movie starts to use that vocabulary in complicated ways later on, we don't need to have it explained what's going on. Knowing that colors map onto emotions, we can grasp the enormous difference between a day that has produced mostly yellow (Joy) memories and a day that has produced a slurry of green, red, and purple (Disgust, Anger, Fear) memories at a visceral level, both because the colors themselves are unpleasant and toxic all mixed together, but because the film trained us why that's upsetting without having openly told us it was doing so.

Cognitive modeling and inventive visual storytelling aside, Inside Out is simply a great amount of fun to watch. The actors are exemplary: the five core emotions are all obvious but phenomenally on-point casting decisions, especially in the subtle details, like how Poehler isn't just perfect for Joy, but perfect for a specifically bossy, arrogant Joy. And with that handled, the film has already done a huge part of its work, making the emotions appropriately broad, bold personalities to go with the film's searing bright colors and Seussian designs of the spaces inside Riley's head. With those personalities in place, the film can go about the business of mixing them around and working not just as a fun story of two mismatched characters on a journey, but, increasingly, as a deeply effective study of emotions jockeying for prominence, and learning the hard truth that feeling sad isn't always inappropriate and should be embraced when it's the right time for it. Which is a lesson that's not just bold for a nominal children's movie (though not since Ratatouille has Pixar made a movie that strikes me as more geared towards adults), but bold for anything made in American cinema. It's one of the ways that Inside Out feels like Pixar's very own Studio Ghibli film, more emotionally sophisticated and trusting of its audience than even the very best of what we'd normally expect from corporate family filmmaking.

It's also one of the ways that Inside Out is clearly the third film to be directed by Pete Docter, whose two previous films - Monsters, Inc. and Up - already marked him out as the feelingest of Pixar's director stable. His balance of goofy comedy and dumbfounding heartbreak is excellent here, as it would almost have to be; I'll confess that I was promised more robust, devastating tears than I got (the opening montage and scrapbook scenes in Up are both harder-hitting to my mind, as is the incomparable finale of Toy Story 3), but none of Inside Out's feints toward tear-jerking, nor its dumbest, most stereotyped jokes feel at all unearned or unconsidered. It tries to cover the whole range of feelings and it largely gets there.

It has a few rough patches, undoubtedly. Docter and his co-writers never came up with a really interesting idea for Disgust, who feels by far the least consequential of the core emotions, and outside of it main themes, Michael Giacchino's score is disappointingly rote, given that some of his career-best work has happened in Pixar films. And there are other nitpicks and niggles her and there. But the grandness of the film's ambitions and its ingenuity in realising those amibitions, its sheer cleverness and sophistication as a most unique kind of character study, these things eradicate any nitpicks and render niggles the nastiest kind of pettiness. This is at most only a hair shy of top-tier Pixar, and not just the kind of aesthetically adventurous storytelling that all animation should aspire to, it's what all of mainstream American cinema should want to be - funny and meaningfully sad, deeply thoughtful about its world and story.