Booksmart is a remarkably assured directorial debut for actress Olivia Wilde, but it’s far, far more than that. Using the template for countless high school comedies that have come before it, filling in those well-drawn lines with a much-needed freshness, and then defiantly coloring outside those lines, Booksmart takes all that has made the genre a lasting staple and pushes it in a vital new direction. Along the way, its stars, Beanie Feldstein and Kaitlyn Dever, deliver performances that continuously surprise with both playful flair and genuine empathy. The result is an open-throated and completely authentic glimpse into the lives of young people on the verge who are seeking new horizons while questioning the foundations that have made them who they are.

Molly (Feldstein) and Amy (Dever) have been friends throughout high school, where they’ve eschewed partying and personal lives in order to devote their time and energy to schoolwork, counting on academic success to get them into their top choice colleges. For Molly, Yale beckons. For Amy, Columbia calls (after a planned summer trip to teach Botswanan women to make their own tampons). The two are what many would call “nerds,” though from the film’s start, it’s clear that this isn’t a story of bullied outcasts. Molly and Amy appear to have chosen to alienate themselves. The truth is that they look down on their fellow classmates, and pity the fact that no one else seems to realize that you can’t have fun and achieve success.

So when these upstarts discover, days before graduation, that their classmates have actually struck good balances between schoolwork and social lives and are also going to revered colleges or jobs, Molly and Amy are thrown into a self-doubting tailspin. If these dullards can get into Ivy League schools without having buried their noses solely in school books, the social hierarchy on which Molly and Amy have built their beliefs is a fallacy. So there’s only one remedy: Before they graduate, Molly and Amy need to party. Hard.

The remainder of Booksmart follows these young women as they riotously pursue this new goal, and each scene piles on wacky set pieces, fierce zingers, and plenty of foul-mouthed fun. Feldstein and Dever are agile comedic performers, and Wilde has surrounded them with both newer faces embodying the fully fleshed-out and yearning teenaged characters, as well as familiar and beloved comedians like Jason Sudeikis, Lisa Kudrow, Will Forte, and Jessica Williams playing the hilariously pitch-perfect and unsure adults.

Even with its wavering characters, Booksmart is itself continuously confident. It delights in undermining and flipping expectations. Even the familiar angst is in a different key than other films of its genre. Tropes that would be played for pathos in past stories are presented as accepted givens. Varieties of sexualities are appreciated and celebrated, without making their existence or exploration the main event.

With so much going for it, the film’s one shortcoming is the fact that the majority of the school appears to be white and apparently rather affluent, a feature that might have been examined in order to give voice to a larger variety of racial and class experiences and add a needed layer. In a film this intelligent, dissecting privilege might have taken it to an even more lasting level.

But, even though it doesn’t plumb every depth it could, Booksmart is a triumph. It continuously surprises, even when it’s not shocking (which it often is). The high school ecosystem it highlights is one in which angst and tentative hope are shared all around, from the jocks to the nerds to the freaks to the teachers, and this shared insecurity both builds connection between the disparate characters and suggests that there is a possible world in which these different people can happily co-exist, each offering their gifts and admitting their weaknesses. It’s a startlingly sincere message mixed in with the rest of the sarcastic, bombastic shenanigans, but it works, and even feels oddly spiritual. What might happen if everyone openly admitted they want to be loved and respected, but have no idea how to actually achieve it on their own? Booksmart asks this simply profound question with every snarky one-liner.