From the "Dr. Strangelove"-style irony of its credit sequence, in which sketches of weaponry through the ages are juxtaposed with Ella Fitzgerald singing "You Took Advantage of Me," you know that "Real Genius" will be more than the teen sex comedy it might have been, and you're not disappointed. Fabulously acted and written with zing and zong, it's one of the few enjoyable movies of the summer.

That opening sequence deftly introduces the movie's themes: a bunch of kids at a Caltech-style school, real geniuses all, are being exploited by a corrupt professor named Jerry Hathaway (William Atherton); they think they're pursuing pure research, but they're really helping to design a "death ray" for the CIA. Hathaway's research team has stalled -- his prize pupil, Chris Knight (Val Kilmer) has wigged out and quit studying -- so he recruits a new whiz kid right out of high school, 15-year-old Mitch Taylor (Gabe Jarret).

As the story progresses, Mitch discovers there's more to life than studying, Chris discovers there's more to life than not studying, and Hathaway gets his comeuppance. The structure of the movie, in other words, is its weakest element. The original script was written by Neal Israel and Pat Proft, who churn out formula teen comedies like an endless stream of Cheez Whiz, and it shows. For example, instead of starting with the charisma Hathaway might hold for these kids, or with a sense that he might have been one of the "real geniuses" himself once upon a time, then slowly unveiling his villainy, the movie just registers him as The Villain as soon as he appears, and Atherton plays him that way. There's no movement in his character, no suspense in the story.

But the script was extensively rewritten, first by Lowell Ganz and Babaloo Mandel ("Splash"), later by director Martha Coolidge and Peter Torokvei (of "SCTV"), at which point, presumably, "Real Genius" lost many penis jokes (many others, unfortunately, remain) and gained its warmth, depth and wit. It begins with a droll parody of a Pentagon briefing film and some sharp satire of the CIA; throughout, the movie is a stalactite cave of sharp, offbeat lines. More importantly, it takes the time to slowly work its gags, most of which stem from the brilliant pranks these whiz kids conjure. One of them, for example, figures out a way to turn the dormitory hallway into an ice-skating rink; when Chris asks how he did it, he replies coolly, "I tell you and then you tell, and then we're in the middle of an ice age."

The problem these kids have is that their minds run too fast for ordinary life, and Coolidge's scattered editing style makes the movie a metaphor for that. The jokes flit by you before you think to laugh -- you see the world through a prodigy's eyes. And an artist's. "Real Genius" looks beautiful, shot by the peerless Vilmos Zsigmond. The dank browns and blacks of the interiors are relieved only by a pale, high-tech blue, while the landscapes have a post card's vividness.

The background of "Real Genius" is dotted with indelible eccentrics. As the burned-out Laslo Hollyfeld, Jonathan Gries wanders through the halls like an ambulatory willow tree; Michelle Meyrink does a classic turn as a neurotic so wired she fills her hours knitting sweaters and sanding her floors -- even when she's standing still, her glances and gestures explode from her, like shrapnel. These caricatures are anchored by Jarret, a slight young actor with a large flat nose and wise little eyes. Jarret plays with small, detailed effects and a lot of heart -- he knows that he's on the screen often enough that he can do little each time he appears. And what a pleasure to see an ordinary kid played by someone who looks like an ordinary kid!

The movie, though, is Val Kilmer's. With his hair swirling above his ears like pasta thrown at the wall, the way his big mouth jumps out in a smile, Kilmer sits on the cusp between great-looking and weird-looking. He walks through "Real Genius" with a kind of spread-out swagger, cackling profusely, defying everyone with one-liners -- he's got a kind of Bugs Bunny quality (he even asks Hathaway, "What's up, Doc?").

We've seen the wiseguy-in-command before, though; what makes Kilmer's Chris so endearing is how he shows us the chinks in the bravado, the little awkwardnesses -- the ways in which he's not a mad scientist, but a kid playing at mad scientist. He's boxed in by the system, and kids like this really are boxed in by the system. Coolidge has gotten onto something here, and the pity is that the story she's stuck with never gets her any deeper into it.