PARK CITY, Utah — Mindy’s latest project is her best so far.

That’s Mindy Kaling, the actress known for her work on “The Office, and “Oceans 8,” and the creator of the TV shows “Champions” and “The Mindy Project.” Her first feature film as both a writer and leading actress, “Late Night” has already made bank here at Sundance where it premiered Friday. Amazon has purchased the US distribution rights for $13 million — a new record for the festival.

The streaming platform, which also picked up “The Big Sick” from Sundance in 2017, will make a good home for Kaling’s comedy. It’s a charming, intelligent movie with a lot of heart and, naturally, some killer jokes.

“Late Night” joins the ranks of fictional depictions of network TV productions — “The Larry Sanders Show,” “30 Rock,” “Studio 60 on the Sunset Strip” — but Kaling shrewdly crumples up that old formula and starts fresh. This time, the host is not only a longstanding TV vet, but a woman: Catherine Newberry, acidically played by Emma Thompson.

Newberry bears no resemblance to any real-life major woman talk show host, such as Joan Rivers or Chelsea Handler, but is a uniquely prickly creation. The stiff Brit is obsessed with hifalutin content on her decades-old show called “Tonight,” preferring to have Dianne Feinstein sit on her couch than some ditzy YouTuber. She doesn’t do sex or political jokes and abhors social media. Suffice it to say, 2019 is not her year.

When one of her male employees insists to her, “you hate women,” she becomes determined to prove him wrong. Her solution: Hire a woman to join her all-male writing staff. “Find me one that’s worth keeping,” she barks. “Would a gay guy work?” her coworker, played by Denis O’Hare, replies.

That “diversity hire” turns out to be Molly (Kaling), an Indian-American who has no TV experience and whose last job was at a chemical plant. She’s bubbly, awkward and aggressively earnest, which is cloying to the room full of men she works with. “It can be a very masculine environment,” O’Hare’s character warns her. “Oh, well, I saw most of the writers. I’m not worried about masculinity,” Molly shoots back.

The funniest of those not-traditionally-manly men is John Early, whose social bluntness and wild inflections deserve their own movie.

Initially marginalized, Molly becomes a vital member of the “Tonight” team when Catherine discovers she’s going to be replaced as host with a younger, Tucker Max-esque gross-out comic. Molly’s fresh perspective — and a few viral videos — could save the show.

Early word on the film was that it would be the “Devil Wears Prada” of late night TV. Well, it’s not. Kaling’s script is much more complex, addressing tricky issues such as sexism, ageism and racial prejudice in her disarmingly light and sneaky way. The writer also has a special ability to write about these topics from multiple, sympathetic perspectives. It’s always a conversation and never a lecture.

There are a couple characters here who are overly large: A flirty writer named Charlie who Molly has a misguided fling with, and an abrasive new female network executive, who openly loathes Catherine. Their scenes strain credulity and undermine the nuance of this otherwise lovely comedy, directed by Nisha Ganatra.

Kaling and Thompson, for the most part, embody the personas you know and love them for. Kaling is perfectly imperfect, lovably fumbling around and shooting off jokes so fast you almost miss them. And Thompson, at this stage in her career, tends to be an unforgiving boss type. But there was one, transcendent scene of her’s that comes as a total surprise.

In the middle of the film, Catherine finds herself on the stage of Theatre 80 St. Mark’s off-Broadway, doing her first stand-up set in years in front of a young audience that’s more accustomed to alternative comedy and extreme openness than Johnny Carson’s joke book. Crickets. And then, in a lightbulb moment, she starts candidly talking about the absurdity of her life and the pain of being fired. And it kills. Catherine doesn’t have to pretend to be young, she just needs to be genuinely herself.

From our seats, that set is legitimately hilarious, like real stand-up. For Thompson of “Much Ado About Nothing” and “Sense and Sensibility” to make us believe that she’s a bona fide New York stand-up comedian is a true feat.