Ever since the battle royale for ratings that occurred between David Letterman and Jay Leno in the 1990s through 2015, late-night comedy talk shows have established a gossip-fueled niche in the minds of American TV viewers.

The new movie “Late Night”— starring Emma Thompson in a terrific, multi-layered performance as a female talk show host in danger of losing her job to ageism and creative laziness, and Mindy Kaling of “The Office” fame as a young woman writer who inspires her to revive her creative spirit— offers a funny, insightful and surprisingly touching look at that world.

The movie follows a young Indian-American woman named Molly (Kaling), who works as a quality control inspector at a chemical plant in Pennsylvania but dreams of working in the comedy business. When longtime late-night host Katherine Newbury (Thompson) learns that her ratings are collapsing since she’s out of touch with the current zeitgeist and she has only one year left to be on her major TV network, she puts out word to hire a “diverse” writer.

Molly lands an interview through an incredibly clever tactic and wins the job because she’s the only female who applied. The rest of the writing staff are white men, who resent her presence immediately for having no comedy background and being an obvious case of de facto affirmative action.

At first, Molly fires back wisecracks in reply to their resentment, and is filled with politically correct self-pity, wishing the world would open before her just for being a “woman of color.” But eventually, she realizes that just as Katherine fought her way to success nearly 30 years ago, she too has to prove herself, work hard and truly be funny on the job.

She also saves Katherine at a press event that is going disastrously, by presenting herself as a bold move by Katherine. As she and her boss become friends, Katherine learns to take comedic chances again and find her spark while Molly learns that nothing comes free in life.

But crisis hits when a disgruntled rival reveals that Katherine engaged in a one-night fling with her male head writer three years before. The news humiliates her and devastates her Parkinson’s-stricken husband (Lithgow), forcing her to make the biggest decisions of her life and career.

“Late Night” is an extremely well-written and engaging dramedy that is rated R for relatively mild foul language, but otherwise maintains a sweet innocence. The film’s smart script (by Kaling herself) offers some surprising takes on the lack of diversity in late-night talk show writers’ rooms, which are often overrun strictly by white men.

“Late Night” – starring Emma Thompson and Mindy Kaling

What’s refreshing about Kaling’s take on the issue is that she finds a way to show the men as more than just jerky stereotypes while also showing Molly as a person who needs to step up her creativity and show them a better way with her actions rather than just her words.

Kaling is also a fun comic foil for Thompson’s Katherine, bringing her youthful charm and naivete against the veteran host’s world-weariness and inner sadness. One of the film’s strongest suits lies in the way it weaves together the famous optics of other real-life stars – Katherine wears suits and a hairdo like Ellen DeGeneres, and her show’s title logo is copied from that of Stephen Colbert’s CBS show – to make viewers feel that Katherine very well could be a formidable real-life figure.

The movie does feature some PC comments by Molly about her status as a “woman of color” and complaints against “white male” privilege, but in the world of late-night comedy, this truly is a staffing issue among writers. To its great credit, Kaling (who wrote the script as well as playing Molly) also shows that Molly takes her embittered attitude too far and has to learn to prove herself as a legitimate talent.

The one glaringly bad aspect of the movie comes when Molly writes a joke slamming Republican lawmakers who seek to defund Planned Parenthood. The joke is debated for a couple of minutes of the movie’s running time, with some of the male writers saying it’s too controversial, but Katherine agrees to use it.

Then Katherine skips the joke to Molly’s chagrin, eventually coming around to using it as a sign of her reborn fire and “courage.” While this takes up five minutes or so of the running time, the overall movie is completely politics-free, sex and nudity-free and surprisingly clean for an R-rated movie.

The movie has extremely funny moments with the writing-staff banter and the comedy stunts that Molly convinces the newly invigorated Katherine to perform for her show. But mostly this is a touching story of finding your place in the world on the one hand with Molly, and finding your drive and passion for life after losing it for Katherine.

In a summer filled with special effects-driven action spectacles and endless sequels and reboots, “Late Night” provides a fresh take on lovable characters and helps add a dose of humanity to the season.