If you’re an ancient wizard responsible for keeping the demons of Pride, Envy, Greed, Anger, Sloth, Gluttony and Lust in check, and your power is waning and you have to pass on your mantle to a young successor, it’s a good idea to prioritize, above all, that your chosen champion be pure of heart.

I mean, purity of heart alone isn’t enough, but then your gift goes a long way in other departments, in principle.

A champion should also be wise, but the wisdom of Solomon is among the gifts you will give him. And he’ll need to be strong, but the strength of Hercules is also in your gift — along with the stamina of Atlas, the power of Zeus, the courage of Achilles and the speed of Mercury.

If you couldn’t give him those things, your name wouldn’t be Shazam. Who would come up with such a name, except as an acronym?

All of this is well-known to some, I guess. But this seems to be a new wrinkle: What about all the potential champions you examined who turned out not to be pure of heart? Have you considered the possible effects of peremptory rejection for unworthiness on the unworthy and the paths that might start them on?

What if one of them became the problem your hypothetical champion had to oppose? What if you wound up creating the problem before coming up with the solution, and you were forced to settle for a champion whose purity of heart was less total than you’d like?

Shazam!, directed by David F. Sandberg, is about all of this, and, of course, much more.

It’s a little bit about the Seven Deadly Sins and a lot about how a 14-year-old boy would react if he were suddenly bequeathed with superpowers beyond imagining and also an Adonis-like adult physique in a bright red super-suit.

It’s about the deep wounds that children suffer when their parents aren’t anywhere close to what they should be and also about the hard work of creating a safe and nurturing home for a large and varied family, in this case a foster family.

It’s goofy, often quite funny, sometimes touching, and occasionally a bit darker or nastier than I expected from a superhero movie that seems to want to skew younger than most.

Along with last year’s bonkers Aquaman, Shazam! is out to exorcise the cynical, grimdark spirit of Zack Snyder’s foundation-laying DC films, Man of Steel and Batman v Superman.

Asher Angel plays Billy Batson, the boy who will be given a magic word that transforms him into an adult superhero (Zachary Levi) who used to be called Captain Marvel (long story).

A homeless orphan in the original comics, he’s conceived here as a longtime foster kid consumed with finding the mother he’s convinced is still out there, whom he lost at a young age after becoming accidentally separated from her in a crowd.

Billy has run away from or been kicked out of any number of group homes and foster homes, but with Victor and Rosa Vasquez (Cooper Andrews and Marta Milans) he seems to have landed on his feet more than he knows.

Cheerfully uncool, deeply committed and fully awesome, the Vasquezes have turned their sprawling early 20th-century Philadelphia house into a chaotic home for five — now six — foster kids of various ages, ethnicities and temperaments.

Billy’s new roommate is Freddy Freeman (Jack Dylan Grazer), a wisecracking superhero geek who walks with an elbow crutch. Other foster siblings include a sweet young black girl named Darla (Faithe Herman), a young Asian computer whiz named Eugene (Ian Chen), a sensitive, heavyset Latino young man named Pedro (Jovan Armand) and a responsible college-age white woman named Mary (Grace Fulton).

The diversity of skin tones and body types, including Freddy’s disability and Pedro’s stoutness, rooted in comics stories, is still striking in an action blockbuster, but Shazam! handles it with admirable lightness. (There are also possible gestures toward other types of diversity: Pedro has a line in passing that may imply that he’s gay, and Walter Chaw notes that he may be autistic as well.)

The Vasquez home is the sort of place where family dinner is preceded by an unconventional grace before meals in which, rather than holding hands, family members form a team hand stack over the table at the phrase “All hands on deck” and Victor offers a jokey but not insincere rhyming prayer such as this: “Thank you for this family / Thank you for this day / Thank you for this food / Even if it’s not steak filet.”

The story is set around Christmastime, and the Vasquezes have a light-up Nativity display on their lawn, with Magi and a Holy Family. (Another house Billy visits looking for his birth mother also has a lawn Nativity display, making Shazam! more reason-for-the-season-y than a lot of so-called Christmas movies.)

This kind of background religiosity has become vanishingly rare in this kind of movie. Fantasy spirituality has an occasional role in the Marvel Cinematic Universe, but, other than a church funeral in Captain America: Civil War, I struggle to think of signs of ordinary real-world religious faith in the MCU.)

Christmas magic may have a special meaning for the wizard Shazam (Djimon Hounsou). Perhaps his home, the Rock of Eternity — a mystic temple or something somewhere in time and space where he guards the stone likenesses of the Seven Deadly Sins, in which the actual demons are trapped — is somehow closer to Earth at Christmastime.

At any rate, the movie opens at Christmastime in 1974 with Shazam reaching out to a young boy who might be Billy, except that he’s not. (He even says “Holy moly,” Billy / Captain Marvel’s catchphrase going back to the 1940s.)

Christmas is also when the wizard receives an unexpected visit many years later from a man who has been looking for him for a long time. Dr. Silvana (Mark Strong) has been obsessed from childhood with the demonic power kept under lock and key at the Rock of Eternity, and it’s sort of Shazam’s fault.

This search is connected with one of the movie’s dumbest and worst moments. Like a UFO researcher examining reported abductees, Silvana is trying to find clues to locating the Rock of Eternity by interviewing people who had the same experience he did.

Fine. Except, instead of leading the investigation, Silvana plays the role of benefactor, funding a research scientist played by Lotta Losten, who thinks she’s investigating mass delusion. This is ridiculous, given what Losten’s character knows — and then (spoiler) the film disposes of her character in a needlessly cruel and grotesque way.

At any rate, when Silvana finally succeeds, the wizard Shazam has run out of time — so when he turns to Billy (still at Christmastime), he’s no longer able to be as choosy as he’d like.

Fortunately, Billy is basically goodhearted, if not exactly pure of heart. Some of the best and funniest sequences involve Freddy and Billy, now inhabiting the pumped-up, 6-foot-3 body of the new Shazam, trying to work out exactly what his superpowers are — sometimes in the middle of actually thwarting a crime. Naturally Freddy not only videos these episodes but also uploads them, where they become a viral sensation.

Shazam’s first public appearances are also widely caught on a great many camera phones. This is so prominent in one sequence that, when something goes disastrously wrong while he’s showing off to a crowd, I expected a reckoning involving critics pointing out the new superhero’s recklessness. This never happens, though. It’s a missed opportunity to highlight the long-term pitfalls of living online, especially when you’re still figuring out who you are.

That’s especially the case given some of their dumber decisions. Stopping at a convenience store to purchase beer (a transgressive act that turns out, with gratifying promptness, to be its own punishment) is one thing; robbing an ATM and a Coke machine is another.

Then there’s Shazam’s visit to a strip club, an experience that, for a man with a 14-year-old brain, he responds to with curious non-prurience. (Everyone was “so nice,” Shazam enthuses to Freddy, who is more interested in hearing about “boobies.” Another character later expresses appropriate disgust at the strip club, but Freddy is more enthusiastic than ever.)

At any rate, it’s all fun and games until a scary supervillain shows up who seems to know all about you and the powers you’re still figuring out, and who has a crew of scary demons at his beck and call to boot. Like Violet and Dash in The Incredibles, Billy must grow up in a hurry not only to survive a threat he’s not prepared to deal with, but also to protect those he loves.

Yet those he loves are not, as in so many superhero movies, only a liability. Like The Incredibles, there is a comic-book mythologization of family itself; our strength lies not only in who we are as individuals but where we come from and those who love us.

At the same time, this isn’t a simplistic Ode to Family, like a Fast and Furious or Spy Kids sequel. Shazam! is almost painfully aware of the lasting effects of parental failure and abuse.

It’s also pretty sloppy and dimwitted, especially about the story’s religious underpinnings. The Seven Deadly Sins have always had a role in Shazam! mythology, but here they’re just generic CGI monsters with very little connection to the vices whose names they bear.

A man whose world is defined by wealth is devoured by Greed, and there’s a crucial twist connected to the sin that has the tightest grip on the villain’s soul, but that’s about it. Consider: This is a movie that contains both a literal demon called Lust and also jokes about teenaged boys and a strip club, and apparently no one involved saw a connection.

Supposedly the Seven Deadlies were unleashed upon the world when a previous champion bequeathed with the powers of Shazam, chosen by the wizard council before they learned the importance of purity of heart, used his powers for revenge. (That would be a character called Black Adam, unseen in this movie but set to be played by Dwayne Johnson in the future.)

Now, though, the Seven Deadlies are locked up in their stone prisons — yet people still commit those sins, so what exactly does that mean? Did people not commit them before the champion’s heinous act?

Perhaps it’s too much to ask for a degree of coherence from a movie about a character said to have the wisdom that Solomon received from the God of the Hebrews and also attributes inherited from Hercules, Atlas, Zeus and so forth.

Speaking of which, does the wisdom ever kick in? There are jokes about Freddy surreptitiously testing Shazam for super-intelligence, but not much sign of actual wisdom, unless perhaps it emerges in the very end. If the writers don’t pay more attention to this attribute in our hero’s next film, I’m going to start calling him Hazam.

Deacon Steven D. Greydanus is the Register’s film critic and creator of Decent Films.
He is a permanent deacon in the Archdiocese of Newark, New Jersey.

Caveat Spectator: Much comic-book violence and a few gruesome images; brief sexual humor and very brief underage drinking; at least one profanity and some cursing and crude language. Teens and up.