This Chinese period martial-arts mystery epic might not quite deserve the accolade of being inspired lunacy, but Tsui Hark’s “Detective Dee and the Mystery of the Phantom Flame” is at least lunacy that’s a lot of fun.

Spectacular and spectacularly goofy, the movie’s set at the close of the seventh century, when cruel Wu Zetian (Canina Lau) is about to ascend the throne as China’s first empress. As the lavish preparations for her coronation—including a skyscraper-sized Buddha—are being finished, the festivities are marred by the murders of a couple of her officials. And not by normal means: they spontaneously combust and burn gruesomely to death.

In order to solve the crimes, Wu Zetian orders amazing Detective Dee (Andy Lau) released from the prison she locked him in eight years earlier. He’s joined—and sometimes opposed—by two others, the empress-to-be’s closest confidante Jing’er (Li Bingbing) and judicial investigator Pei Donglai (Deng Chao), both of whom are as adept in martial arts as Dee is.

The story is really nothing more than a chain of ridiculous, overblown set-pieces that include lots of wildly balletic fights and campy face-offs, juiced up with special effects that include not only those cool death burns but facial transformations aplenty, and even shape-shifting of a broader sort. The whodunnit part of things is frankly a bit of a letdown, but the howdunnit element—which involves some specially weaponized beetles—is amusing enough. The ending, which seems to suggest a duty to obey authority, however perverted, probably plays better in China than it will here, if anybody’s really interested in trying to draw morals from such nonsense.

Acting is of little consequence in this sort of thing, but Andy Lau, Li and Deng are all up to the physical demands, and Carina Lau certainly strikes imperious poses as the future empress. The rest of the cast do what’s asked of them.

What really matters, though, is the physical production, which is as bright, vivid and crammed with eye-popping bits of business as one could hope for. The images, with their vast vistas and imposing structures, are like comic book panels brought to life, and the widescreen cinematography by Chan Chi-ying and Chan Chor-keung is awash in color. Even if you find the story ludicrous, the visuals will keep your eyes occupied—if not your mind.

“Detective Dee” is a wild, absurd ride. But if you approach it with the right attitude, an absurdly enjoyable one.